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 {
17 public:
19 
21 
22  KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, ResidualDatum & datum) const;
23  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int qp, ResidualDatum & datum) const;
24  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar,
25  const unsigned int qp,
26  ResidualDatum & datum) const;
27 
28 protected:
30  const unsigned int _v_var;
31 
34 
35 private:
36  KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const;
37 
40 };
41 
42 template <typename Derived>
45 {
47  params.addRequiredCoupledVar(
48  "v", "The coupled variable we require to be greater than the lower bound");
49  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  return params;
56 }
57 
58 template <typename Derived>
60  : NodalKernel(parameters), _v_var(coupled("v")), _v(kokkosCoupledNodalValue("v"))
61 {
62  if (_var.number() == _v_var)
63  paramError("v", "Coupled variable needs to be different from 'variable'");
64 
65  std::set<ContiguousBoundaryID> bnd_ids;
66 
67  const auto & bnd_names = getParam<std::vector<BoundaryName>>("exclude_boundaries");
68  for (const auto & bnd_id : _mesh.getBoundaryIDs(bnd_names))
69  bnd_ids.insert(kokkosMesh().getContiguousBoundaryID(bnd_id));
70 
71  _bnd_ids = bnd_ids;
72 }
73 
74 template <typename Derived>
75 KOKKOS_FUNCTION bool
77 {
78  for (dof_id_type b = 0; b < _bnd_ids.size(); ++b)
79  if (kokkosMesh().isBoundaryNode(node, _bnd_ids[b]))
80  return true;
81 
82  return false;
83 }
84 
85 template <typename Derived>
86 KOKKOS_FUNCTION Real
88  ResidualDatum & datum) const
89 {
90  if (skipOnBoundary(datum.node()))
91  return _u(datum, qp);
92 
93  return static_cast<const Derived *>(this)->getResidual(qp, datum);
94 }
95 
96 template <typename Derived>
97 KOKKOS_FUNCTION Real
99  ResidualDatum & datum) const
100 {
101  if (skipOnBoundary(datum.node()))
102  return 1;
103 
104  return static_cast<const Derived *>(this)->getJacobian(qp, datum);
105 }
106 
107 template <typename Derived>
108 KOKKOS_FUNCTION Real
110  const unsigned int qp,
111  ResidualDatum & datum) const
112 {
113  if (skipOnBoundary(datum.node()))
114  return 0;
115 
116  return static_cast<const Derived *>(this)->getOffDiagJacobian(jvar, qp, datum);
117 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
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
unsigned int number() const
Get variable number coming from libMesh.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, ResidualDatum &datum) const
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar, const unsigned int qp, ResidualDatum &datum) const
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.
static InputParameters validParams()
dof_id_type ContiguousNodeID
Definition: KokkosMesh.h:21
KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int qp, ResidualDatum &datum) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition: KokkosMesh.h:360
KOKKOS_FUNCTION ContiguousNodeID node() const
Get the contiguous node ID.
Definition: KokkosDatum.h:95
const unsigned int _v_var
The number of the coupled variable.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Moose::Kokkos::VariableValue _v
The value of the coupled variable.
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...
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. ...
The Kokkos wrapper classes for MOOSE-like variable value access.
static InputParameters validParams()
Class constructor.
Definition: NodalKernel.C:18
Base class for creating nodal kernels with hand-coded Jacobians.
Definition: NodalKernel.h:17
The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual object...
Definition: KokkosDatum.h:245
uint8_t dof_id_type