Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://www.mooseframework.org
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 "KokkosNodalBCBase.h"
13 :
14 : namespace Moose
15 : {
16 : namespace Kokkos
17 : {
18 :
19 : /**
20 : * The base class for a user to derive their own Kokkos nodal boundary conditions.
21 : *
22 : * The user should define computeQpResidual(), computeQpJacobian(), and computeQpOffDiagJacobian()
23 : * as inlined public methods in their derived class (not virtual override). The signature of
24 : * computeQpResidual() expected to be defined in the derived class is as follows:
25 : *
26 : * @param qp The dummy quadrature point index (= 0)
27 : * @param datum The AssemblyDatum object of the current thread
28 : * @returns The residual contribution
29 : *
30 : * KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
31 : *
32 : * The signatures of computeQpJacobian() and computeOffDiagQpJacobian() can be found in the code
33 : * below, and their definition in the derived class is optional. If they are defined in the derived
34 : * class, they will hide the default definitions in the base class.
35 : */
36 : class NodalBC : public NodalBCBase
37 : {
38 : public:
39 : static InputParameters validParams();
40 :
41 : /**
42 : * Constructor
43 : */
44 : NodalBC(const InputParameters & parameters);
45 :
46 : /**
47 : * Dispatch residual calculation
48 : */
49 : virtual void computeResidual() override;
50 : /**
51 : * Dispatch diagonal and off-diagonal Jacobian calculation
52 : */
53 : virtual void computeJacobian() override;
54 :
55 : /**
56 : * Default methods to prevent compile errors even when these methods were not defined in the
57 : * derived class
58 : */
59 : ///@{
60 : /**
61 : * Compute diagonal Jacobian contribution on a node
62 : * @param qp The dummy quadrature point index (= 0)
63 : * @param datum The AssemblyDatum object of the current thread
64 : * @returns The diagonal Jacobian contribution
65 : */
66 47174 : KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
67 : AssemblyDatum & /* datum */) const
68 : {
69 47174 : return 1;
70 : }
71 : /**
72 : * Compute off-diagonal Jacobian contribution on a node
73 : * @param jvar The variable number for column
74 : * @param qp The dummy quadrature point index (= 0)
75 : * @param datum The AssemblyDatum object of the current thread
76 : * @returns The off-diagonal Jacobian contribution
77 : */
78 0 : KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
79 : const unsigned int /* qp */,
80 : AssemblyDatum & /* datum */) const
81 : {
82 0 : return 0;
83 : }
84 : /**
85 : * Get the function pointer of the default computeQpJacobian()
86 : * @returns The function pointer
87 : */
88 112766 : static auto defaultJacobian() { return &NodalBC::computeQpJacobian; }
89 : /**
90 : * Get the function pointer of the default computeQpOffDiagJacobian()
91 : * @returns The function pointer
92 : */
93 112766 : static auto defaultOffDiagJacobian() { return &NodalBC::computeQpOffDiagJacobian; }
94 : ///@}
95 :
96 : /**
97 : * The parallel computation entry functions called by Kokkos
98 : */
99 : ///@{
100 : template <typename Derived>
101 : KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
102 : template <typename Derived>
103 : KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
104 : template <typename Derived>
105 : KOKKOS_FUNCTION void
106 : operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
107 : ///@}
108 :
109 : protected:
110 : /**
111 : * Current solution at nodes
112 : */
113 : const VariableValue _u;
114 : };
115 :
116 : template <typename Derived>
117 : KOKKOS_FUNCTION void
118 331136 : NodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
119 : {
120 331136 : auto node = kokkosBoundaryNodeID(tid);
121 331136 : auto & sys = kokkosSystem(_kokkos_var.sys());
122 :
123 331136 : if (!sys.isNodalDefined(node, _kokkos_var.var()))
124 0 : return;
125 :
126 331136 : AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
127 :
128 331136 : Real local_re = bc.computeQpResidual(0, datum);
129 :
130 331136 : accumulateTaggedNodalResidual(false, local_re, node);
131 : }
132 :
133 : template <typename Derived>
134 : KOKKOS_FUNCTION void
135 47570 : NodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
136 : {
137 47570 : auto node = kokkosBoundaryNodeID(tid);
138 47570 : auto & sys = kokkosSystem(_kokkos_var.sys());
139 :
140 47570 : if (!sys.isNodalDefined(node, _kokkos_var.var()))
141 0 : return;
142 :
143 47570 : AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
144 :
145 47570 : Real local_ke = bc.computeQpJacobian(0, datum);
146 :
147 : // This initializes the row to zero except the diagonal
148 47570 : accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var());
149 : }
150 :
151 : template <typename Derived>
152 : KOKKOS_FUNCTION void
153 414 : NodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
154 : {
155 414 : auto node = kokkosBoundaryNodeID(_thread(tid, 1));
156 414 : auto & sys = kokkosSystem(_kokkos_var.sys());
157 414 : auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
158 :
159 414 : if (!sys.isNodalDefined(node, _kokkos_var.var()))
160 0 : return;
161 :
162 414 : AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
163 :
164 414 : Real local_ke = bc.computeQpOffDiagJacobian(jvar, 0, datum);
165 :
166 414 : accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
167 : }
168 :
169 : } // namespace Kokkos
170 : } // namespace Moose
|