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 3980312 : MaterialPropertyInterface::validParams()
21 : {
22 3980312 : InputParameters params = emptyInputParameters();
23 7960624 : params.addPrivateParam<Moose::MaterialDataType>(
24 : "_material_data_type"); // optionally force the type of MaterialData to utilize
25 15921248 : 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 11940936 : params.addParam<bool>(
31 : "use_interpolated_state",
32 7960624 : 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 11940936 : params.addParamNamesToGroup("use_interpolated_state prop_getter_suffix",
36 : "Material property retrieval");
37 :
38 3980312 : return params;
39 0 : }
40 :
41 : namespace moose
42 : {
43 : namespace internal
44 : {
45 : bool
46 611871 : boundaryRestricted(const std::set<BoundaryID> & boundary_ids)
47 : {
48 611871 : return !boundary_ids.empty() && BoundaryRestrictable::restricted(boundary_ids);
49 : }
50 : }
51 : }
52 :
53 327850 : MaterialPropertyInterface::MaterialPropertyInterface(const MooseObject * moose_object,
54 : const std::set<SubdomainID> & block_ids,
55 327850 : const std::set<BoundaryID> & boundary_ids)
56 327850 : : _mi_moose_object(*moose_object),
57 655700 : _mi_params(_mi_moose_object.parameters()),
58 327850 : _mi_name(moose_object->name()),
59 655700 : _mi_moose_object_name(_mi_moose_object.getBase(), _mi_name, "::"),
60 1311400 : _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
61 1311400 : _mi_subproblem(*_mi_params.getCheckedPointerParam<SubProblem *>("_subproblem")),
62 327850 : _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
63 : #ifdef MOOSE_KOKKOS_ENABLED
64 250584 : _is_kokkos_object(_mi_moose_object.isKokkosObject()),
65 : #endif
66 327850 : _material_data_type(getMaterialDataType(boundary_ids)),
67 327850 : _material_data(
68 : #ifdef MOOSE_KOKKOS_ENABLED
69 250584 : _is_kokkos_object
70 250584 : ? _mi_feproblem.getKokkosMaterialData(_material_data_type, moose_object)
71 : :
72 : #endif
73 319801 : _mi_feproblem.getMaterialData(_material_data_type, _mi_tid, moose_object)),
74 327850 : _stateful_allowed(true),
75 327850 : _get_material_property_called(false),
76 327850 : _get_suffix(_mi_params.get<MaterialPropertyName>("prop_getter_suffix")),
77 327850 : _use_interpolated_state(_mi_params.get<bool>("use_interpolated_state")),
78 327850 : _mi_boundary_restricted(moose::internal::boundaryRestricted(boundary_ids)),
79 327850 : _mi_block_ids(block_ids),
80 983550 : _mi_boundary_ids(boundary_ids)
81 : {
82 327850 : moose_object->getMooseApp().registerInterfaceObject(*this);
83 327850 : }
84 :
85 : #ifdef MOOSE_KOKKOS_ENABLED
86 301096 : MaterialPropertyInterface::MaterialPropertyInterface(const MaterialPropertyInterface & object,
87 301096 : const Moose::Kokkos::FunctorCopy &)
88 301096 : : _mi_moose_object(object._mi_moose_object),
89 301096 : _mi_params(object._mi_params),
90 301096 : _mi_name(object._mi_name),
91 301096 : _mi_moose_object_name(object._mi_moose_object_name),
92 301096 : _mi_feproblem(object._mi_feproblem),
93 301096 : _mi_subproblem(object._mi_subproblem),
94 301096 : _mi_tid(object._mi_tid),
95 301096 : _is_kokkos_object(object._is_kokkos_object),
96 301096 : _material_data_type(object._material_data_type),
97 301096 : _material_data(object._material_data),
98 301096 : _stateful_allowed(object._stateful_allowed),
99 301096 : _get_material_property_called(object._get_material_property_called),
100 301096 : _get_suffix(object._get_suffix),
101 301096 : _use_interpolated_state(object._use_interpolated_state),
102 301096 : _mi_boundary_restricted(object._mi_boundary_restricted),
103 301096 : _mi_block_ids(object._mi_block_ids),
104 903288 : _mi_boundary_ids(object._mi_boundary_ids)
105 : {
106 301096 : }
107 : #endif
108 :
109 : MaterialPropertyName
110 79460 : MaterialPropertyInterface::getMaterialPropertyName(const std::string & name) const
111 : {
112 79460 : if (_mi_params.have_parameter<MaterialPropertyName>(name) && _mi_params.isParamValid(name))
113 62513 : return _mi_params.get<MaterialPropertyName>(name);
114 16947 : return name;
115 : }
116 :
117 : std::set<SubdomainID>
118 17 : MaterialPropertyInterface::getMaterialPropertyBlocks(const std::string & name)
119 : {
120 17 : return _mi_feproblem.getMaterialPropertyBlocks(name);
121 : }
122 :
123 : std::vector<SubdomainName>
124 6 : MaterialPropertyInterface::getMaterialPropertyBlockNames(const std::string & name)
125 : {
126 6 : return _mi_feproblem.getMaterialPropertyBlockNames(name);
127 : }
128 :
129 : std::set<BoundaryID>
130 0 : MaterialPropertyInterface::getMaterialPropertyBoundaryIDs(const std::string & name)
131 : {
132 0 : return _mi_feproblem.getMaterialPropertyBoundaryIDs(name);
133 : }
134 :
135 : std::vector<BoundaryName>
136 6 : MaterialPropertyInterface::getMaterialPropertyBoundaryNames(const std::string & name)
137 : {
138 6 : return _mi_feproblem.getMaterialPropertyBoundaryNames(name);
139 : }
140 :
141 : unsigned int
142 1951 : MaterialPropertyInterface::getMaxQps() const
143 : {
144 1951 : return _mi_feproblem.getMaxQps();
145 : }
146 :
147 : void
148 49371 : MaterialPropertyInterface::addConsumedPropertyName(const MooseObjectName & obj_name,
149 : const std::string & prop_name)
150 : {
151 49371 : return _mi_feproblem.addConsumedPropertyName(obj_name, prop_name);
152 : }
153 :
154 : void
155 48951 : MaterialPropertyInterface::checkMaterialProperty(const std::string & name, const unsigned int state)
156 : {
157 48951 : if (state == 0)
158 : {
159 : // If the material property is boundary restrictable, add to the list of materials to check
160 46490 : if (_mi_boundary_restricted)
161 8542 : for (const auto & bnd_id : _mi_boundary_ids)
162 5056 : _mi_feproblem.storeBoundaryDelayedCheckMatProp(_mi_name, bnd_id, name);
163 :
164 : // The default is to assume block restrictions
165 : else
166 88247 : for (const auto & blk_ids : _mi_block_ids)
167 45243 : _mi_feproblem.storeSubdomainDelayedCheckMatProp(_mi_name, blk_ids, name);
168 : }
169 48951 : }
170 :
171 : void
172 54650 : MaterialPropertyInterface::markMatPropRequested(const std::string & name)
173 : {
174 54650 : _mi_feproblem.markMatPropRequested(name);
175 54650 : }
176 :
177 : void
178 1908 : MaterialPropertyInterface::statefulPropertiesAllowed(bool stateful_allowed)
179 : {
180 1908 : _stateful_allowed = stateful_allowed;
181 1908 : }
182 :
183 : void
184 246 : MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
185 : std::shared_ptr<MaterialBase> discrete)
186 : {
187 : // Check block compatibility
188 246 : if (!discrete->hasBlocks(_mi_block_ids))
189 : {
190 3 : std::ostringstream oss;
191 3 : oss << "Incompatible material and object blocks:";
192 :
193 9 : oss << "\n " << discrete->parameters().paramLocationPrefix("block")
194 6 : << " material defined on blocks ";
195 6 : for (const auto & sbd_id : discrete->blockIDs())
196 3 : oss << sbd_id << ", ";
197 :
198 6 : oss << "\n " << _mi_params.paramLocationPrefix("block")
199 6 : << " object needs material on blocks ";
200 9 : for (const auto & block_id : _mi_block_ids)
201 6 : oss << block_id << ", ";
202 :
203 3 : mooseError(oss.str());
204 0 : }
205 :
206 : // Check boundary compatibility
207 243 : if (!discrete->hasBoundary(_mi_boundary_ids))
208 : {
209 3 : std::ostringstream oss;
210 3 : oss << "Incompatible material and object boundaries:";
211 :
212 9 : oss << "\n " << discrete->parameters().paramLocationPrefix("boundary")
213 6 : << " material defined on boundaries ";
214 6 : for (const auto & bnd_id : discrete->boundaryIDs())
215 3 : oss << bnd_id << ", ";
216 :
217 6 : oss << "\n " << _mi_params.paramLocationPrefix("boundary")
218 6 : << " object needs material on boundaries ";
219 9 : for (const auto & bnd_id : _mi_boundary_ids)
220 6 : oss << bnd_id << ", ";
221 :
222 3 : mooseError(oss.str());
223 0 : }
224 240 : }
225 :
226 : MaterialBase &
227 0 : MaterialPropertyInterface::getMaterial(const std::string & name)
228 : {
229 0 : return getMaterialByName(_mi_params.get<MaterialName>(name));
230 : }
231 :
232 : MaterialBase &
233 252 : MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
234 : {
235 : std::shared_ptr<MaterialBase> discrete =
236 252 : _mi_feproblem.getMaterial(name, _material_data_type, _mi_tid, no_warn);
237 :
238 246 : checkBlockAndBoundaryCompatibility(discrete);
239 480 : return *discrete;
240 240 : }
241 :
242 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
243 2496 : MaterialPropertyInterface::buildRequiredMaterials(bool allow_stateful)
244 : {
245 2496 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>> required_mats;
246 2496 : const auto & mwh = _mi_feproblem.getMaterialWarehouse();
247 4992 : for (const auto id : _mi_block_ids)
248 : {
249 2496 : const auto & mats = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
250 2496 : std::array<const MaterialPropertyInterface *, 1> consumers = {{this}};
251 : const auto block_required =
252 2496 : MaterialBase::buildRequiredMaterials(consumers, mats, allow_stateful);
253 4992 : required_mats[id].insert(
254 2496 : required_mats[id].begin(), block_required.begin(), block_required.end());
255 2496 : }
256 2496 : return required_mats;
257 0 : }
258 :
259 : void
260 54650 : MaterialPropertyInterface::checkExecutionStage()
261 : {
262 54650 : if (_mi_feproblem.startedInitialSetup())
263 0 : mooseError("Material properties must be retrieved during object construction. This is a code "
264 : "problem.");
265 54650 : }
266 :
267 : void
268 290580 : MaterialPropertyInterface::resolveOptionalProperties()
269 : {
270 291486 : for (auto & proxy : _optional_property_proxies)
271 906 : proxy->resolve(*this);
272 290580 : }
273 :
274 : Moose::MaterialDataType
275 327850 : MaterialPropertyInterface::getMaterialDataType(const std::set<BoundaryID> & boundary_ids) const
276 : {
277 983550 : if (_mi_params.isParamValid("_material_data_type"))
278 43829 : return _mi_params.get<Moose::MaterialDataType>("_material_data_type");
279 284021 : if (moose::internal::boundaryRestricted(boundary_ids))
280 20361 : return Moose::BOUNDARY_MATERIAL_DATA;
281 263660 : return Moose::BLOCK_MATERIAL_DATA;
282 : }
|