Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "KokkosNodalKernel.h" 13 : 14 : template <typename Derived> 15 : class KokkosBoundNodalKernel : public Moose::Kokkos::NodalKernel 16 : { 17 : public: 18 : static InputParameters validParams(); 19 : 20 : KokkosBoundNodalKernel(const InputParameters & parameters); 21 : 22 : KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const; 23 : KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int qp, AssemblyDatum & datum) const; 24 : KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar, 25 : const unsigned int qp, 26 : AssemblyDatum & datum) const; 27 : 28 : protected: 29 : /// The number of the coupled variable 30 : const unsigned int _v_var; 31 : 32 : /// The value of the coupled variable 33 : const Moose::Kokkos::VariableValue _v; 34 : 35 : private: 36 : KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const; 37 : 38 : /// Boundaries on which we should not execute this object 39 : Moose::Kokkos::Array<ContiguousBoundaryID> _bnd_ids; 40 : }; 41 : 42 : template <typename Derived> 43 : InputParameters 44 18624 : KokkosBoundNodalKernel<Derived>::validParams() 45 : { 46 18624 : InputParameters params = NodalKernel::validParams(); 47 74496 : params.addRequiredCoupledVar( 48 : "v", "The coupled variable we require to be greater than the lower bound"); 49 55872 : params.addParam<std::vector<BoundaryName>>( 50 : "exclude_boundaries", 51 : {}, 52 : "Boundaries on which not to execute the nodal kernel. This can be useful for avoiding " 53 : "singuarility in the matrix in case a constraint is active in the same place that a " 54 : "Dirichlet BC is set"); 55 18624 : return params; 56 0 : } 57 : 58 : template <typename Derived> 59 144 : KokkosBoundNodalKernel<Derived>::KokkosBoundNodalKernel(const InputParameters & parameters) 60 320 : : NodalKernel(parameters), _v_var(coupled("v")), _v(kokkosCoupledNodalValue("v")) 61 : { 62 80 : if (_var.number() == _v_var) 63 0 : paramError("v", "Coupled variable needs to be different from 'variable'"); 64 : 65 80 : std::set<ContiguousBoundaryID> bnd_ids; 66 : 67 160 : const auto & bnd_names = getParam<std::vector<BoundaryName>>("exclude_boundaries"); 68 240 : for (const auto & bnd_id : _mesh.getBoundaryIDs(bnd_names)) 69 160 : bnd_ids.insert(kokkosMesh().getContiguousBoundaryID(bnd_id)); 70 : 71 80 : _bnd_ids = bnd_ids; 72 80 : } 73 : 74 : template <typename Derived> 75 : KOKKOS_FUNCTION bool 76 334110 : KokkosBoundNodalKernel<Derived>::skipOnBoundary(const ContiguousNodeID node) const 77 : { 78 991080 : for (dof_id_type b = 0; b < _bnd_ids.size(); ++b) 79 664470 : if (kokkosMesh().isBoundaryNode(node, _bnd_ids[b])) 80 7500 : return true; 81 : 82 326610 : return false; 83 : } 84 : 85 : template <typename Derived> 86 : KOKKOS_FUNCTION Real 87 117744 : KokkosBoundNodalKernel<Derived>::computeQpResidual(const unsigned int qp, 88 : AssemblyDatum & datum) const 89 : { 90 117744 : if (skipOnBoundary(datum.node())) 91 2688 : return _u(datum, qp); 92 : 93 115056 : return static_cast<const Derived *>(this)->getResidual(qp, datum); 94 : } 95 : 96 : template <typename Derived> 97 : KOKKOS_FUNCTION Real 98 91816 : KokkosBoundNodalKernel<Derived>::computeQpJacobian(const unsigned int qp, 99 : AssemblyDatum & datum) const 100 : { 101 91816 : if (skipOnBoundary(datum.node())) 102 2032 : return 1; 103 : 104 89784 : return static_cast<const Derived *>(this)->getJacobian(qp, datum); 105 : } 106 : 107 : template <typename Derived> 108 : KOKKOS_FUNCTION Real 109 124550 : KokkosBoundNodalKernel<Derived>::computeQpOffDiagJacobian(const unsigned int jvar, 110 : const unsigned int qp, 111 : AssemblyDatum & datum) const 112 : { 113 124550 : if (skipOnBoundary(datum.node())) 114 2780 : return 0; 115 : 116 121770 : return static_cast<const Derived *>(this)->getOffDiagJacobian(jvar, qp, datum); 117 : }