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 : // initQpStatefulProperties() and computeQpProperties() are intentionally hidden
13 : // but some compilers generate ugly warnings
14 :
15 : #if defined(__clang__)
16 : #pragma clang diagnostic push
17 : #pragma clang diagnostic ignored "-Woverloaded-virtual"
18 : #elif defined(__GNUC__) || defined(__GNUG__)
19 : #pragma GCC diagnostic push
20 : #pragma GCC diagnostic ignored "-Woverloaded-virtual"
21 : #endif
22 :
23 : #include "KokkosMaterialBase.h"
24 : #include "KokkosDatum.h"
25 :
26 : #include "Coupleable.h"
27 : #include "MaterialPropertyInterface.h"
28 :
29 : namespace Moose
30 : {
31 : namespace Kokkos
32 : {
33 :
34 : /**
35 : * The base class for a user to derive their own Kokkos materials.
36 : *
37 : * The user should define initQpStatefulProperties() and computeQpProperties() as inlined public
38 : * methods in their derived class (not virtual override). The signature of computeQpProperties()
39 : * expected to be defined in the derived class is as follows:
40 : *
41 : * @param qp The local quadrature point index
42 : * @param datum The Datum object of the current thread
43 : *
44 : * KOKKOS_FUNCTION void computeQpProperties(const unsigned int qp, Datum & datum) const;
45 : *
46 : * The signature of initQpStatefulProperties() can be found in the code below, and its definition in
47 : * the derived class is optional. If it is defined in the derived class, it will hide the default
48 : * definition in the base class.
49 : */
50 : class Material : public MaterialBase, public Coupleable, public MaterialPropertyInterface
51 : {
52 : public:
53 : static InputParameters validParams();
54 :
55 : /**
56 : * Constructor
57 : */
58 : Material(const InputParameters & parameters);
59 :
60 : /**
61 : * Copy constructor for parallel dispatch
62 : */
63 : Material(const Material & object);
64 :
65 : /**
66 : * Dispatch stateful material property initialization
67 : */
68 : virtual void initStatefulProperties(unsigned int) override;
69 : /**
70 : * Dispatch material property evaluation
71 : */
72 : virtual void computeProperties() override;
73 :
74 : /**
75 : * Default methods to prevent compile errors even when these methods were not defined in the
76 : * derived class
77 : */
78 : ///@{
79 : /**
80 : * Initialize stateful material properties on a quadrature point
81 : * @param qp The local quadrature point index
82 : * @param datum The Datum object of the current thread
83 : */
84 0 : KOKKOS_FUNCTION void initQpStatefulProperties(const unsigned int /* qp */,
85 : Datum & /* datum */) const
86 : {
87 0 : }
88 : /**
89 : * Get the function pointer of the default initQpStatefulProperties()
90 : * @returns The function pointer
91 : */
92 1575327 : static auto defaultInitStateful() { return &Material::initQpStatefulProperties; }
93 : ///@}
94 :
95 : /**
96 : * The parallel computation entry functions called by Kokkos
97 : */
98 : ///@{
99 : template <typename Derived>
100 : KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived & material) const;
101 : template <typename Derived>
102 : KOKKOS_FUNCTION void operator()(SideInit, const ThreadID tid, const Derived & material) const;
103 : template <typename Derived>
104 : KOKKOS_FUNCTION void operator()(NeighborInit, const ThreadID tid, const Derived & material) const;
105 : template <typename Derived>
106 : KOKKOS_FUNCTION void
107 : operator()(ElementCompute, const ThreadID tid, const Derived & material) const;
108 : template <typename Derived>
109 : KOKKOS_FUNCTION void operator()(SideCompute, const ThreadID tid, const Derived & material) const;
110 : template <typename Derived>
111 : KOKKOS_FUNCTION void
112 : operator()(NeighborCompute, const ThreadID tid, const Derived & material) const;
113 : ///@}
114 :
115 : protected:
116 : /**
117 : * Override of the MaterialPropertyInterface function to perform additional checks and add
118 : * dependencies
119 : */
120 : void getKokkosMaterialPropertyHook(const std::string & prop_name_in,
121 : const unsigned int state) override final;
122 :
123 871 : virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override
124 : {
125 : // Avoid performing duplicate checks for triple block/face/neighbor materials
126 871 : if (boundaryRestricted() || !_bnd)
127 299 : MaterialPropertyInterface::checkMaterialProperty(name, state);
128 871 : }
129 :
130 1027 : virtual bool isBoundaryMaterial() const override { return _bnd; }
131 :
132 17413 : virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
133 : {
134 17413 : return MaterialPropertyInterface::getMatPropDependencies();
135 : }
136 :
137 1644 : virtual const MaterialData & materialData() const override { return _material_data; }
138 2048 : virtual MaterialData & materialData() override { return _material_data; }
139 838 : virtual MaterialDataType materialDataType() override { return _material_data_type; }
140 :
141 : /**
142 : * Flag whether the material is on faces
143 : */
144 : const bool _bnd;
145 : /**
146 : * Flag whether the material is on neighbor faces
147 : */
148 : const bool _neighbor;
149 :
150 : private:
151 : /**
152 : * Dummy members unused for Kokkos materials
153 : */
154 : ///@{
155 : const QBase * const & _qrule;
156 0 : virtual const QBase & qRule() const override { return *_qrule; }
157 : ///@}
158 : };
159 :
160 : template <typename Derived>
161 : KOKKOS_FUNCTION void
162 16504 : Material::operator()(ElementInit, const ThreadID tid, const Derived & material) const
163 : {
164 16504 : auto elem = kokkosElementID(tid);
165 :
166 16504 : Datum datum(elem, libMesh::invalid_uint, kokkosAssembly(), kokkosSystems());
167 :
168 106236 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
169 : {
170 89732 : datum.reinit();
171 89732 : material.initQpStatefulProperties(qp, datum);
172 : }
173 16504 : }
174 :
175 : template <typename Derived>
176 : KOKKOS_FUNCTION void
177 410 : Material::operator()(SideInit, const ThreadID tid, const Derived & material) const
178 : {
179 410 : auto [elem, side] = kokkosElementSideID(tid);
180 :
181 410 : Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
182 :
183 1520 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
184 : {
185 1110 : datum.reinit();
186 1110 : material.initQpStatefulProperties(qp, datum);
187 : }
188 410 : }
189 :
190 : template <typename Derived>
191 : KOKKOS_FUNCTION void
192 290 : Material::operator()(NeighborInit, const ThreadID tid, const Derived & material) const
193 : {
194 290 : auto [elem, side] = kokkosElementSideID(tid);
195 :
196 290 : Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
197 :
198 1160 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
199 : {
200 870 : datum.reinit();
201 870 : material.initQpStatefulProperties(qp, datum);
202 : }
203 290 : }
204 :
205 : template <typename Derived>
206 : KOKKOS_FUNCTION void
207 863252 : Material::operator()(ElementCompute, const ThreadID tid, const Derived & material) const
208 : {
209 863252 : auto elem = kokkosElementID(tid);
210 :
211 863252 : Datum datum(elem, libMesh::invalid_uint, kokkosAssembly(), kokkosSystems());
212 :
213 6439568 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
214 : {
215 5576316 : datum.reinit();
216 5576316 : material.computeQpProperties(qp, datum);
217 : }
218 863252 : }
219 :
220 : template <typename Derived>
221 : KOKKOS_FUNCTION void
222 40830 : Material::operator()(SideCompute, const ThreadID tid, const Derived & material) const
223 : {
224 40830 : auto [elem, side] = kokkosElementSideID(tid);
225 :
226 40830 : Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
227 :
228 152960 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
229 : {
230 112130 : datum.reinit();
231 112130 : material.computeQpProperties(qp, datum);
232 : }
233 40830 : }
234 :
235 : template <typename Derived>
236 : KOKKOS_FUNCTION void
237 35650 : Material::operator()(NeighborCompute, const ThreadID tid, const Derived & material) const
238 : {
239 35650 : auto [elem, side] = kokkosElementSideID(tid);
240 :
241 35650 : Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
242 :
243 137420 : for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
244 : {
245 101770 : datum.reinit();
246 101770 : material.computeQpProperties(qp, datum);
247 : }
248 35650 : }
249 :
250 : } // namespace Kokkos
251 : } // namespace Moose
|