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 : // MOOOSE includes
13 : #include "MaterialBase.h"
14 : #include "Coupleable.h"
15 : #include "MooseEnum.h"
16 : #include "MaterialPropertyInterface.h"
17 : #include "FEProblemBase.h"
18 :
19 : #include <string>
20 :
21 : #define usingMaterialMembers \
22 : usingMaterialBaseMembers; \
23 : usingCoupleableMembers; \
24 : usingMaterialPropertyInterfaceMembers; \
25 : using Material::_q_point; \
26 : using Material::_qrule; \
27 : using Material::_JxW; \
28 : using Material::_current_elem; \
29 : using Material::_current_subdomain_id; \
30 : using Material::_current_side
31 :
32 : /**
33 : * Materials compute MaterialProperties.
34 : */
35 : class Material : public MaterialBase, public Coupleable, public MaterialPropertyInterface
36 : {
37 : public:
38 : static InputParameters validParams();
39 :
40 : Material(const InputParameters & parameters);
41 :
42 : /**
43 : * Gets an element integer for the proper current element with a parameter of
44 : * the object derived from this interface
45 : * Note: This overrides the function in ElementIDInterface to assure derived materials
46 : * call the functions in ElementIDInterface properly.
47 : */
48 78 : virtual const dof_id_type & getElementID(const std::string & id_parameter_name,
49 : unsigned int comp = 0) const override
50 : {
51 78 : return _neighbor ? ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp)
52 78 : : ElementIDInterface::getElementID(id_parameter_name, comp);
53 : }
54 : /**
55 : * Directly calling this function is not needed for materials because the same material has
56 : * three copies for element interior, element side and neighbor side.
57 : */
58 0 : virtual const dof_id_type & getElementIDNeighbor(const std::string & id_parameter_name,
59 : unsigned int comp = 0) const override
60 : {
61 0 : mooseError("Directly calling 'getElementIDNeighbor' is not allowed for materials. Please call "
62 : "'getElementID' instead");
63 : return ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp);
64 : }
65 :
66 : /**
67 : * Gets an element integer for the proper current element with the element integer name
68 : * Note: This overrides the function in ElementIDInterface to assure derived materials
69 : * call the functions in ElementIDInterface properly.
70 : */
71 : virtual const dof_id_type &
72 0 : getElementIDByName(const std::string & id_parameter_name) const override
73 : {
74 0 : return _neighbor ? ElementIDInterface::getElementIDNeighborByName(id_parameter_name)
75 0 : : ElementIDInterface::getElementIDByName(id_parameter_name);
76 : }
77 : /**
78 : * Directly calling this function is not needed for materials because the same material has
79 : * three copies for element interior, element side and neighbor side.
80 : */
81 : virtual const dof_id_type &
82 0 : getElementIDNeighborByName(const std::string & id_parameter_name) const override
83 : {
84 0 : mooseError("Directly calling 'getElementIDNeighborByName' is not allowed for materials. Please "
85 : "call 'getElementIDByName' instead");
86 : return ElementIDInterface::getElementIDNeighborByName(id_parameter_name);
87 : }
88 :
89 : virtual void computeProperties() override;
90 :
91 : ///@{
92 : /**
93 : * Retrieve the property through a given input parameter key with a fallback
94 : * to getting it by name
95 : */
96 : template <typename T, bool is_ad>
97 : const GenericMaterialProperty<T, is_ad> &
98 : getGenericMaterialProperty(const std::string & name, const unsigned int state = 0);
99 : template <typename T>
100 1399 : const MaterialProperty<T> & getMaterialProperty(const std::string & name,
101 : const unsigned int state = 0)
102 : {
103 1399 : return getGenericMaterialProperty<T, false>(name, state);
104 : }
105 : template <typename T>
106 234 : const ADMaterialProperty<T> & getADMaterialProperty(const std::string & name)
107 : {
108 234 : return getGenericMaterialProperty<T, true>(name, 0);
109 : }
110 : template <typename T>
111 2511 : const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name)
112 : {
113 2511 : return getGenericMaterialProperty<T, false>(name, 1);
114 : }
115 : template <typename T>
116 633 : const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name)
117 : {
118 633 : return getGenericMaterialProperty<T, false>(name, 2);
119 : }
120 : ///@}
121 :
122 : ///@{
123 : /**
124 : * Retrieve the property named "name"
125 : */
126 : template <typename T, bool is_ad>
127 : const GenericMaterialProperty<T, is_ad> &
128 : getGenericMaterialPropertyByName(const std::string & name, const unsigned int state = 0);
129 : template <typename T>
130 : const MaterialProperty<T> & getMaterialPropertyByName(const std::string & prop_name,
131 : const unsigned int state = 0)
132 : {
133 : return getGenericMaterialPropertyByName<T, false>(prop_name, state);
134 : }
135 : template <typename T>
136 : const ADMaterialProperty<T> & getADMaterialPropertyByName(const std::string & prop_name)
137 : {
138 : return getGenericMaterialPropertyByName<T, true>(prop_name, 0);
139 : }
140 : template <typename T>
141 468 : const MaterialProperty<T> & getMaterialPropertyOldByName(const std::string & prop_name)
142 : {
143 468 : return getGenericMaterialPropertyByName<T, false>(prop_name, 1);
144 : }
145 : template <typename T>
146 : const MaterialProperty<T> & getMaterialPropertyOlderByName(const std::string & prop_name)
147 : {
148 : return getGenericMaterialPropertyByName<T, false>(prop_name, 2);
149 : }
150 : ///@}
151 :
152 : /**
153 : * Retrieve the discrete material with a given parameter key named "name"
154 : */
155 204 : MaterialBase & getMaterial(const std::string & name)
156 : {
157 204 : return getMaterialByName(parameters().get<MaterialName>(name));
158 : }
159 :
160 : /**
161 : * Retrieve the discrete material named "name".
162 : *
163 : * @param no_warn If true, suppress warning about retrieving the material potentially during its
164 : * calculation. If you don't know what this is/means, then you don't need it.
165 : * @param no_dep Use no_dep = true if no dependency resolution for the material is required. Using
166 : * no_dep = false is useful for discrete materials.
167 : */
168 : MaterialBase &
169 : getMaterialByName(const std::string & name, bool no_warn = false, bool no_dep = false);
170 :
171 : ///@{ Optional material property getters
172 : template <typename T, bool is_ad>
173 : const GenericOptionalMaterialProperty<T, is_ad> &
174 : getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state = 0);
175 : template <typename T>
176 165 : const OptionalMaterialProperty<T> & getOptionalMaterialProperty(const std::string & name,
177 : const unsigned int state = 0)
178 : {
179 165 : return getGenericOptionalMaterialProperty<T, false>(name, state);
180 : }
181 : template <typename T>
182 165 : const OptionalADMaterialProperty<T> & getOptionalADMaterialProperty(const std::string & name)
183 : {
184 165 : return getGenericOptionalMaterialProperty<T, true>(name, 0);
185 : }
186 : template <typename T>
187 165 : const OptionalMaterialProperty<T> & getOptionalMaterialPropertyOld(const std::string & name)
188 : {
189 165 : return getGenericOptionalMaterialProperty<T, false>(name, 1);
190 : }
191 : template <typename T>
192 165 : const OptionalMaterialProperty<T> & getOptionalMaterialPropertyOlder(const std::string & name)
193 : {
194 165 : return getGenericOptionalMaterialProperty<T, false>(name, 2);
195 : }
196 : ///@}
197 :
198 : using MaterialBase::getGenericZeroMaterialProperty;
199 : using MaterialBase::getGenericZeroMaterialPropertyByName;
200 : using MaterialBase::getZeroMaterialProperty;
201 :
202 45 : virtual bool isBoundaryMaterial() const override { return _bnd; }
203 :
204 822902 : virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
205 : {
206 822902 : return MaterialPropertyInterface::getMatPropDependencies();
207 : }
208 : virtual void subdomainSetup() override;
209 :
210 5480827 : CreateMooseEnumClass(ConstantTypeEnum, NONE, ELEMENT, SUBDOMAIN);
211 :
212 7492 : bool ghostable() const override final { return _ghostable; }
213 :
214 : /// resolve all optional properties
215 : virtual void resolveOptionalProperties() override;
216 :
217 : protected:
218 : virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override;
219 :
220 0 : virtual const MaterialData & materialData() const override { return _material_data; }
221 1665676 : virtual MaterialData & materialData() override { return _material_data; }
222 0 : virtual Moose::MaterialDataType materialDataType() override { return _material_data_type; }
223 :
224 13728 : virtual const QBase & qRule() const override { return *_qrule; }
225 :
226 : bool _bnd;
227 : bool _neighbor;
228 :
229 : const MooseArray<Point> & _q_point;
230 : const QBase * const & _qrule;
231 :
232 : const MooseArray<Real> & _JxW;
233 :
234 : const Elem * const & _current_elem;
235 :
236 : const SubdomainID & _current_subdomain_id;
237 :
238 : /// current side of the current element
239 : const unsigned int & _current_side;
240 :
241 : /// Options of the constantness level of the material
242 : const ConstantTypeEnum _constant_option;
243 :
244 : private:
245 : ConstantTypeEnum computeConstantOption();
246 :
247 : /// Whether this material can be computed in a ghosted context. If properties are constant or
248 : /// depend only on finite volume variables, then this material can be computed in a ghosted
249 : /// context. If properties depend on finite element variables, then this material cannot be
250 : /// computed in a ghosted context
251 : bool _ghostable;
252 :
253 : /// optional material properties
254 : std::vector<std::unique_ptr<OptionalMaterialPropertyProxyBase<Material>>>
255 : _optional_property_proxies;
256 : };
257 :
258 : template <typename T, bool is_ad>
259 : const GenericMaterialProperty<T, is_ad> &
260 7270 : Material::getGenericMaterialProperty(const std::string & name, const unsigned int state)
261 : {
262 : // Check if the supplied parameter is a valid input parameter key
263 7270 : const auto prop_name = getMaterialPropertyName(name);
264 :
265 : // Check if it's just a constant.
266 7270 : if (const auto * default_property = defaultGenericMaterialProperty<T, is_ad>(prop_name))
267 156 : return *default_property;
268 :
269 7114 : return getGenericMaterialPropertyByName<T, is_ad>(prop_name, state);
270 7270 : }
271 :
272 : template <typename T, bool is_ad>
273 : const GenericMaterialProperty<T, is_ad> &
274 8050 : Material::getGenericMaterialPropertyByName(const std::string & prop_name_in,
275 : const unsigned int state)
276 : {
277 8050 : if (_use_interpolated_state)
278 : {
279 936 : if (state == 1)
280 468 : return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_old, 0);
281 468 : if (state == 2)
282 0 : return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_older, 0);
283 : }
284 :
285 7582 : MaterialBase::checkExecutionStage();
286 :
287 : // The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
288 : // same memory)
289 15164 : const auto prop_name =
290 7582 : _get_suffix.empty()
291 7582 : ? prop_name_in
292 7582 : : MooseUtils::join(std::vector<std::string>({prop_name_in, _get_suffix}), "_");
293 :
294 7582 : if (state == 0)
295 4210 : _requested_props.insert(prop_name);
296 :
297 : // Do this before so that we register the ID first
298 : auto & prop =
299 7582 : MaterialPropertyInterface::getGenericMaterialPropertyByName<T, is_ad>(prop_name_in, state);
300 :
301 7582 : registerPropName(prop_name, true, state);
302 :
303 7582 : return prop;
304 7582 : }
305 :
306 : template <typename T, bool is_ad>
307 : const GenericOptionalMaterialProperty<T, is_ad> &
308 660 : Material::getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state)
309 : {
310 660 : auto proxy = std::make_unique<OptionalMaterialPropertyProxy<Material, T, is_ad>>(name, state);
311 660 : auto & optional_property = proxy->value();
312 660 : _optional_property_proxies.push_back(std::move(proxy));
313 660 : return optional_property;
314 660 : }
|