https://mooseframework.inl.gov
KokkosBoundNodalKernel.h
Go to the documentation of this file.
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>
16 {
18 
19 public:
21 
23 
24  KOKKOS_FUNCTION Real computeQpResidual(const ContiguousNodeID node) const;
25  KOKKOS_FUNCTION Real computeQpJacobian(const ContiguousNodeID node) const;
26  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar,
27  const ContiguousNodeID node) const;
28 
29 protected:
31  const unsigned int _v_var;
32 
35 
36 private:
37  KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const;
38 
41 };
42 
43 template <typename Derived>
46 {
48  params.addRequiredCoupledVar(
49  "v", "The coupled variable we require to be greater than the lower bound");
50  params.addParam<std::vector<BoundaryName>>(
51  "exclude_boundaries",
52  {},
53  "Boundaries on which not to execute the nodal kernel. This can be useful for avoiding "
54  "singuarility in the matrix in case a constraint is active in the same place that a "
55  "Dirichlet BC is set");
56  return params;
57 }
58 
59 template <typename Derived>
61  : Moose::Kokkos::NodalKernel<Derived>(parameters),
62  _v_var(this->coupled("v")),
63  _v(this->kokkosCoupledNodalValue("v"))
64 {
65  if (_var.number() == _v_var)
66  this->paramError("v", "Coupled variable needs to be different from 'variable'");
67 
68  std::set<ContiguousBoundaryID> bnd_ids;
69 
70  const auto & bnd_names = this->template getParam<std::vector<BoundaryName>>("exclude_boundaries");
71  for (const auto & bnd_id : this->_mesh.getBoundaryIDs(bnd_names))
72  bnd_ids.insert(this->kokkosMesh().getContiguousBoundaryID(bnd_id));
73 
74  _bnd_ids = bnd_ids;
75 }
76 
77 template <typename Derived>
78 KOKKOS_FUNCTION bool
80 {
81  for (dof_id_type b = 0; b < _bnd_ids.size(); ++b)
82  if (this->kokkosMesh().isBoundaryNode(node, _bnd_ids[b]))
83  return true;
84 
85  return false;
86 }
87 
88 template <typename Derived>
89 KOKKOS_FUNCTION Real
91 {
92  if (skipOnBoundary(node))
93  return _u(node);
94 
95  return static_cast<const Derived *>(this)->getResidual(node);
96 }
97 
98 template <typename Derived>
99 KOKKOS_FUNCTION Real
101 {
102  if (skipOnBoundary(node))
103  return 1;
104 
105  return static_cast<const Derived *>(this)->getJacobian(node);
106 }
107 
108 template <typename Derived>
109 KOKKOS_FUNCTION Real
111  const ContiguousNodeID node) const
112 {
113  if (skipOnBoundary(node))
114  return 0;
115 
116  return static_cast<const Derived *>(this)->getOffDiagJacobian(jvar, node);
117 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:439
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar, const ContiguousNodeID node) const
unsigned int number() const
Get variable number coming from libMesh.
usingKokkosNodalKernelMembers(Derived)
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
Moose::Kokkos::Array< ContiguousBoundaryID > _bnd_ids
Boundaries on which we should not execute this object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
The base class for a user to derive their own Kokkos nodal kernels.
MooseVariableFieldBase & _var
Reference of the MOOSE variable.
KOKKOS_FUNCTION Real computeQpJacobian(const ContiguousNodeID node) const
static InputParameters validParams()
dof_id_type ContiguousNodeID
Definition: KokkosMesh.h:21
KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const
KOKKOS_FUNCTION Real computeQpResidual(const ContiguousNodeID node) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
const unsigned int _v_var
The number of the coupled variable.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KokkosBoundNodalKernel(const InputParameters &parameters)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
const Moose::Kokkos::VariableNodalValue _v
The value of the coupled variable.
Base class for creating nodal kernels with hand-coded Jacobians.
Definition: NodalKernel.h:17
uint8_t dof_id_type