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 : // MOOSE includes
11 : #include "MaterialPropertyInterface.h"
12 : #include "MooseApp.h"
13 : #include "MaterialBase.h"
14 : #include "FEProblemBase.h"
15 :
16 : const std::string MaterialPropertyInterface::_interpolated_old = "_interpolated_old";
17 : const std::string MaterialPropertyInterface::_interpolated_older = "_interpolated_older";
18 :
19 : InputParameters
20 16672671 : MaterialPropertyInterface::validParams()
21 : {
22 16672671 : InputParameters params = emptyInputParameters();
23 33345342 : params.addPrivateParam<Moose::MaterialDataType>(
24 : "_material_data_type"); // optionally force the type of MaterialData to utilize
25 66690684 : params.addParam<MaterialPropertyName>("prop_getter_suffix",
26 : "",
27 : "An optional suffix parameter that can be appended to any "
28 : "attempt to retrieve/get material properties. The suffix "
29 : "will be prepended with a '_' character.");
30 50018013 : params.addParam<bool>(
31 : "use_interpolated_state",
32 33345342 : false,
33 : "For the old and older state use projected material properties interpolated at the "
34 : "quadrature points. To set up projection use the ProjectedStatefulMaterialStorageAction.");
35 50018013 : params.addParamNamesToGroup("use_interpolated_state prop_getter_suffix",
36 : "Material property retrieval");
37 :
38 16672671 : return params;
39 0 : }
40 :
41 : namespace moose
42 : {
43 : namespace internal
44 : {
45 : bool
46 653728 : boundaryRestricted(const std::set<BoundaryID> & boundary_ids)
47 : {
48 653728 : return !boundary_ids.empty() && BoundaryRestrictable::restricted(boundary_ids);
49 : }
50 : }
51 : }
52 :
53 350582 : MaterialPropertyInterface::MaterialPropertyInterface(const MooseObject * moose_object,
54 : const std::set<SubdomainID> & block_ids,
55 350582 : const std::set<BoundaryID> & boundary_ids)
56 350582 : : _mi_moose_object(*moose_object),
57 701164 : _mi_params(_mi_moose_object.parameters()),
58 350582 : _mi_name(moose_object->name()),
59 701164 : _mi_moose_object_name(_mi_moose_object.getBase(), _mi_name, "::"),
60 1402328 : _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
61 1402328 : _mi_subproblem(*_mi_params.getCheckedPointerParam<SubProblem *>("_subproblem")),
62 350582 : _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
63 : #ifdef MOOSE_KOKKOS_ENABLED
64 242749 : _is_kokkos_object(_mi_moose_object.isKokkosObject({})),
65 : #else
66 107833 : _is_kokkos_object(false),
67 : #endif
68 350582 : _material_data_type(getMaterialDataType(boundary_ids)),
69 350582 : _material_data(
70 : #ifdef MOOSE_KOKKOS_ENABLED
71 242749 : _is_kokkos_object
72 242749 : ? _mi_feproblem.getKokkosMaterialData(_material_data_type, moose_object)
73 : :
74 : #endif
75 348130 : _mi_feproblem.getMaterialData(_material_data_type, _mi_tid, moose_object)),
76 350582 : _stateful_allowed(true),
77 350582 : _get_material_property_called(false),
78 350582 : _get_suffix(_mi_params.get<MaterialPropertyName>("prop_getter_suffix")),
79 350582 : _use_interpolated_state(_mi_params.get<bool>("use_interpolated_state")),
80 350582 : _mi_boundary_restricted(moose::internal::boundaryRestricted(boundary_ids)),
81 350582 : _mi_block_ids(block_ids),
82 1051746 : _mi_boundary_ids(boundary_ids)
83 : {
84 350582 : moose_object->getMooseApp().registerInterfaceObject(*this);
85 350582 : }
86 :
87 : #ifdef MOOSE_KOKKOS_ENABLED
88 107978 : MaterialPropertyInterface::MaterialPropertyInterface(const MaterialPropertyInterface & object,
89 107978 : const Moose::Kokkos::FunctorCopy &)
90 107978 : : _mi_moose_object(object._mi_moose_object),
91 107978 : _mi_params(object._mi_params),
92 107978 : _mi_name(object._mi_name),
93 107978 : _mi_moose_object_name(object._mi_moose_object_name),
94 107978 : _mi_feproblem(object._mi_feproblem),
95 107978 : _mi_subproblem(object._mi_subproblem),
96 107978 : _mi_tid(object._mi_tid),
97 107978 : _is_kokkos_object(object._is_kokkos_object),
98 107978 : _material_data_type(object._material_data_type),
99 107978 : _material_data(object._material_data),
100 107978 : _stateful_allowed(object._stateful_allowed),
101 107978 : _get_material_property_called(object._get_material_property_called),
102 107978 : _get_suffix(object._get_suffix),
103 107978 : _use_interpolated_state(object._use_interpolated_state),
104 107978 : _mi_boundary_restricted(object._mi_boundary_restricted),
105 107978 : _mi_block_ids(object._mi_block_ids),
106 323934 : _mi_boundary_ids(object._mi_boundary_ids)
107 : {
108 107978 : }
109 : #endif
110 :
111 : MaterialPropertyName
112 84250 : MaterialPropertyInterface::getMaterialPropertyName(const std::string & name) const
113 : {
114 84250 : if (_mi_params.have_parameter<MaterialPropertyName>(name) && _mi_params.isParamValid(name))
115 66279 : return _mi_params.get<MaterialPropertyName>(name);
116 17971 : return name;
117 : }
118 :
119 : std::set<SubdomainID>
120 0 : MaterialPropertyInterface::getMaterialPropertyBlocks(const std::string & name)
121 : {
122 0 : return _mi_feproblem.getMaterialPropertyBlocks(name);
123 : }
124 :
125 : std::vector<SubdomainName>
126 8 : MaterialPropertyInterface::getMaterialPropertyBlockNames(const std::string & name)
127 : {
128 8 : return _mi_feproblem.getMaterialPropertyBlockNames(name);
129 : }
130 :
131 : std::set<BoundaryID>
132 0 : MaterialPropertyInterface::getMaterialPropertyBoundaryIDs(const std::string & name)
133 : {
134 0 : return _mi_feproblem.getMaterialPropertyBoundaryIDs(name);
135 : }
136 :
137 : std::vector<BoundaryName>
138 8 : MaterialPropertyInterface::getMaterialPropertyBoundaryNames(const std::string & name)
139 : {
140 8 : return _mi_feproblem.getMaterialPropertyBoundaryNames(name);
141 : }
142 :
143 : unsigned int
144 2077 : MaterialPropertyInterface::getMaxQps() const
145 : {
146 2077 : return _mi_feproblem.getMaxQps();
147 : }
148 :
149 : void
150 51148 : MaterialPropertyInterface::addConsumedPropertyName(const MooseObjectName & obj_name,
151 : const std::string & prop_name)
152 : {
153 51148 : return _mi_feproblem.addConsumedPropertyName(obj_name, prop_name);
154 : }
155 :
156 : void
157 50694 : MaterialPropertyInterface::checkMaterialProperty(const std::string & name, const unsigned int state)
158 : {
159 50694 : if (state == 0)
160 : {
161 : // If the material property is boundary restrictable, add to the list of materials to check
162 48142 : if (_mi_boundary_restricted)
163 10214 : for (const auto & bnd_id : _mi_boundary_ids)
164 6329 : _mi_feproblem.storeBoundaryDelayedCheckMatProp(_mi_name, bnd_id, name);
165 :
166 : // The default is to assume block restrictions
167 : else
168 90650 : for (const auto & blk_ids : _mi_block_ids)
169 46393 : _mi_feproblem.storeSubdomainDelayedCheckMatProp(_mi_name, blk_ids, name);
170 : }
171 50694 : }
172 :
173 : void
174 56620 : MaterialPropertyInterface::markMatPropRequested(const std::string & name)
175 : {
176 56620 : _mi_feproblem.markMatPropRequested(name);
177 56620 : }
178 :
179 : void
180 1998 : MaterialPropertyInterface::statefulPropertiesAllowed(bool stateful_allowed)
181 : {
182 1998 : _stateful_allowed = stateful_allowed;
183 1998 : }
184 :
185 : void
186 268 : MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
187 : std::shared_ptr<MaterialBase> discrete)
188 : {
189 : // Check block compatibility
190 268 : if (!discrete->hasBlocks(_mi_block_ids))
191 : {
192 4 : std::ostringstream oss;
193 4 : oss << "Incompatible material and object blocks:";
194 :
195 12 : oss << "\n " << discrete->parameters().paramLocationPrefix("block")
196 8 : << " material defined on blocks ";
197 8 : for (const auto & sbd_id : discrete->blockIDs())
198 4 : oss << sbd_id << ", ";
199 :
200 8 : oss << "\n " << _mi_params.paramLocationPrefix("block")
201 8 : << " object needs material on blocks ";
202 12 : for (const auto & block_id : _mi_block_ids)
203 8 : oss << block_id << ", ";
204 :
205 4 : mooseError(oss.str());
206 0 : }
207 :
208 : // Check boundary compatibility
209 264 : if (!discrete->hasBoundary(_mi_boundary_ids))
210 : {
211 4 : std::ostringstream oss;
212 4 : oss << "Incompatible material and object boundaries:";
213 :
214 12 : oss << "\n " << discrete->parameters().paramLocationPrefix("boundary")
215 8 : << " material defined on boundaries ";
216 8 : for (const auto & bnd_id : discrete->boundaryIDs())
217 4 : oss << bnd_id << ", ";
218 :
219 8 : oss << "\n " << _mi_params.paramLocationPrefix("boundary")
220 8 : << " object needs material on boundaries ";
221 12 : for (const auto & bnd_id : _mi_boundary_ids)
222 8 : oss << bnd_id << ", ";
223 :
224 4 : mooseError(oss.str());
225 0 : }
226 260 : }
227 :
228 : MaterialBase &
229 0 : MaterialPropertyInterface::getMaterial(const std::string & name)
230 : {
231 0 : return getMaterialByName(_mi_params.get<MaterialName>(name));
232 : }
233 :
234 : MaterialBase &
235 276 : MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
236 : {
237 : std::shared_ptr<MaterialBase> discrete =
238 276 : _mi_feproblem.getMaterial(name, _material_data_type, _mi_tid, no_warn);
239 :
240 268 : checkBlockAndBoundaryCompatibility(discrete);
241 520 : return *discrete;
242 260 : }
243 :
244 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
245 2688 : MaterialPropertyInterface::buildRequiredMaterials(bool allow_stateful)
246 : {
247 2688 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>> required_mats;
248 2688 : const auto & mwh = _mi_feproblem.getMaterialWarehouse();
249 5376 : for (const auto id : _mi_block_ids)
250 : {
251 2688 : const auto & mats = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
252 2688 : std::array<const MaterialPropertyInterface *, 1> consumers = {{this}};
253 : const auto block_required =
254 2688 : MaterialBase::buildRequiredMaterials(consumers, mats, allow_stateful);
255 5376 : required_mats[id].insert(
256 2688 : required_mats[id].begin(), block_required.begin(), block_required.end());
257 2688 : }
258 2688 : return required_mats;
259 0 : }
260 :
261 : void
262 56620 : MaterialPropertyInterface::checkExecutionStage()
263 : {
264 56620 : if (_mi_feproblem.startedInitialSetup())
265 0 : mooseError("Material properties must be retrieved during object construction. This is a code "
266 : "problem.");
267 56620 : }
268 :
269 : void
270 309390 : MaterialPropertyInterface::resolveOptionalProperties()
271 : {
272 310374 : for (auto & proxy : _optional_property_proxies)
273 984 : proxy->resolve(*this);
274 309390 : }
275 :
276 : Moose::MaterialDataType
277 350582 : MaterialPropertyInterface::getMaterialDataType(const std::set<BoundaryID> & boundary_ids) const
278 : {
279 1051746 : if (_mi_params.isParamValid("_material_data_type"))
280 47436 : return _mi_params.get<Moose::MaterialDataType>("_material_data_type");
281 303146 : if (moose::internal::boundaryRestricted(boundary_ids))
282 21467 : return Moose::BOUNDARY_MATERIAL_DATA;
283 281679 : return Moose::BLOCK_MATERIAL_DATA;
284 : }
|