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 15547882 : MaterialPropertyInterface::validParams()
21 : {
22 15547882 : InputParameters params = emptyInputParameters();
23 15547882 : params.addPrivateParam<Moose::MaterialDataType>(
24 : "_material_data_type"); // optionally force the type of MaterialData to utilize
25 15547882 : 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 46643646 : params.addParam<bool>(
31 : "use_interpolated_state",
32 31095764 : 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 15547882 : params.addParamNamesToGroup("use_interpolated_state prop_getter_suffix",
36 : "Material property retrieval");
37 :
38 15547882 : return params;
39 0 : }
40 :
41 : namespace moose
42 : {
43 : namespace internal
44 : {
45 : bool
46 590337 : boundaryRestricted(const std::set<BoundaryID> & boundary_ids)
47 : {
48 590337 : return !boundary_ids.empty() && BoundaryRestrictable::restricted(boundary_ids);
49 : }
50 : }
51 : }
52 :
53 316451 : MaterialPropertyInterface::MaterialPropertyInterface(const MooseObject * moose_object,
54 : const std::set<SubdomainID> & block_ids,
55 316451 : const std::set<BoundaryID> & boundary_ids)
56 316451 : : _mi_moose_object(*moose_object),
57 632902 : _mi_params(_mi_moose_object.parameters()),
58 316451 : _mi_name(_mi_params.get<std::string>("_object_name")),
59 316451 : _mi_moose_object_name(_mi_params.get<std::string>("_moose_base"), _mi_name, "::"),
60 316451 : _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
61 316451 : _mi_subproblem(*_mi_params.getCheckedPointerParam<SubProblem *>("_subproblem")),
62 316451 : _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
63 316451 : _material_data_type(getMaterialDataType(boundary_ids)),
64 316451 : _material_data(_mi_feproblem.getMaterialData(_material_data_type, _mi_tid)),
65 316451 : _stateful_allowed(true),
66 316451 : _get_material_property_called(false),
67 316451 : _get_suffix(_mi_params.get<MaterialPropertyName>("prop_getter_suffix")),
68 316451 : _use_interpolated_state(_mi_params.get<bool>("use_interpolated_state")),
69 316451 : _mi_boundary_restricted(moose::internal::boundaryRestricted(boundary_ids)),
70 316451 : _mi_block_ids(block_ids),
71 949353 : _mi_boundary_ids(boundary_ids)
72 : {
73 316451 : moose_object->getMooseApp().registerInterfaceObject(*this);
74 316451 : }
75 :
76 : MaterialPropertyName
77 76156 : MaterialPropertyInterface::getMaterialPropertyName(const std::string & name) const
78 : {
79 76156 : if (_mi_params.have_parameter<MaterialPropertyName>(name) && _mi_params.isParamValid(name))
80 61048 : return _mi_params.get<MaterialPropertyName>(name);
81 15108 : return name;
82 : }
83 :
84 : std::set<SubdomainID>
85 0 : MaterialPropertyInterface::getMaterialPropertyBlocks(const std::string & name)
86 : {
87 0 : return _mi_feproblem.getMaterialPropertyBlocks(name);
88 : }
89 :
90 : std::vector<SubdomainName>
91 8 : MaterialPropertyInterface::getMaterialPropertyBlockNames(const std::string & name)
92 : {
93 8 : return _mi_feproblem.getMaterialPropertyBlockNames(name);
94 : }
95 :
96 : std::set<BoundaryID>
97 0 : MaterialPropertyInterface::getMaterialPropertyBoundaryIDs(const std::string & name)
98 : {
99 0 : return _mi_feproblem.getMaterialPropertyBoundaryIDs(name);
100 : }
101 :
102 : std::vector<BoundaryName>
103 8 : MaterialPropertyInterface::getMaterialPropertyBoundaryNames(const std::string & name)
104 : {
105 8 : return _mi_feproblem.getMaterialPropertyBoundaryNames(name);
106 : }
107 :
108 : unsigned int
109 2768 : MaterialPropertyInterface::getMaxQps() const
110 : {
111 2768 : return _mi_feproblem.getMaxQps();
112 : }
113 :
114 : void
115 47051 : MaterialPropertyInterface::addConsumedPropertyName(const MooseObjectName & obj_name,
116 : const std::string & prop_name)
117 : {
118 47051 : return _mi_feproblem.addConsumedPropertyName(obj_name, prop_name);
119 : }
120 :
121 : void
122 46433 : MaterialPropertyInterface::checkMaterialProperty(const std::string & name, const unsigned int state)
123 : {
124 46433 : if (state == 0)
125 : {
126 : // If the material property is boundary restrictable, add to the list of materials to check
127 44335 : if (_mi_boundary_restricted)
128 9358 : for (const auto & bnd_id : _mi_boundary_ids)
129 5855 : _mi_feproblem.storeBoundaryDelayedCheckMatProp(_mi_name, bnd_id, name);
130 :
131 : // The default is to assume block restrictions
132 : else
133 83549 : for (const auto & blk_ids : _mi_block_ids)
134 42717 : _mi_feproblem.storeSubdomainDelayedCheckMatProp(_mi_name, blk_ids, name);
135 : }
136 46433 : }
137 :
138 : void
139 51401 : MaterialPropertyInterface::markMatPropRequested(const std::string & name)
140 : {
141 51401 : _mi_feproblem.markMatPropRequested(name);
142 51401 : }
143 :
144 : void
145 1900 : MaterialPropertyInterface::statefulPropertiesAllowed(bool stateful_allowed)
146 : {
147 1900 : _stateful_allowed = stateful_allowed;
148 1900 : }
149 :
150 : void
151 250 : MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
152 : std::shared_ptr<MaterialBase> discrete)
153 : {
154 : // Check block compatibility
155 250 : if (!discrete->hasBlocks(_mi_block_ids))
156 : {
157 4 : std::ostringstream oss;
158 4 : oss << "Incompatible material and object blocks:";
159 :
160 8 : oss << "\n " << paramErrorPrefix(discrete->parameters(), "block")
161 8 : << " material defined on blocks ";
162 8 : for (const auto & sbd_id : discrete->blockIDs())
163 4 : oss << sbd_id << ", ";
164 :
165 4 : oss << "\n " << paramErrorPrefix(_mi_params, "block") << " object needs material on blocks ";
166 12 : for (const auto & block_id : _mi_block_ids)
167 8 : oss << block_id << ", ";
168 :
169 4 : mooseError(oss.str());
170 0 : }
171 :
172 : // Check boundary compatibility
173 246 : if (!discrete->hasBoundary(_mi_boundary_ids))
174 : {
175 4 : std::ostringstream oss;
176 4 : oss << "Incompatible material and object boundaries:";
177 :
178 8 : oss << "\n " << paramErrorPrefix(discrete->parameters(), "boundary")
179 8 : << " material defined on boundaries ";
180 8 : for (const auto & bnd_id : discrete->boundaryIDs())
181 4 : oss << bnd_id << ", ";
182 :
183 8 : oss << "\n " << paramErrorPrefix(_mi_params, "boundary")
184 8 : << " object needs material on boundaries ";
185 12 : for (const auto & bnd_id : _mi_boundary_ids)
186 8 : oss << bnd_id << ", ";
187 :
188 4 : mooseError(oss.str());
189 0 : }
190 242 : }
191 :
192 : MaterialBase &
193 0 : MaterialPropertyInterface::getMaterial(const std::string & name)
194 : {
195 0 : return getMaterialByName(_mi_params.get<MaterialName>(name));
196 : }
197 :
198 : MaterialBase &
199 258 : MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
200 : {
201 : std::shared_ptr<MaterialBase> discrete =
202 258 : _mi_feproblem.getMaterial(name, _material_data_type, _mi_tid, no_warn);
203 :
204 250 : checkBlockAndBoundaryCompatibility(discrete);
205 484 : return *discrete;
206 242 : }
207 :
208 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
209 2496 : MaterialPropertyInterface::buildRequiredMaterials(bool allow_stateful)
210 : {
211 2496 : std::unordered_map<SubdomainID, std::vector<MaterialBase *>> required_mats;
212 2496 : const auto & mwh = _mi_feproblem.getMaterialWarehouse();
213 4992 : for (const auto id : _mi_block_ids)
214 : {
215 2496 : const auto & mats = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
216 2496 : std::array<const MaterialPropertyInterface *, 1> consumers = {{this}};
217 : const auto block_required =
218 2496 : MaterialBase::buildRequiredMaterials(consumers, mats, allow_stateful);
219 4992 : required_mats[id].insert(
220 2496 : required_mats[id].begin(), block_required.begin(), block_required.end());
221 2496 : }
222 2496 : return required_mats;
223 0 : }
224 :
225 : void
226 51401 : MaterialPropertyInterface::checkExecutionStage()
227 : {
228 51401 : if (_mi_feproblem.startedInitialSetup())
229 0 : mooseError("Material properties must be retrieved during object construction. This is a code "
230 : "problem.");
231 51401 : }
232 :
233 : void
234 279834 : MaterialPropertyInterface::resolveOptionalProperties()
235 : {
236 280752 : for (auto & proxy : _optional_property_proxies)
237 918 : proxy->resolve(*this);
238 279834 : }
239 :
240 : Moose::MaterialDataType
241 316451 : MaterialPropertyInterface::getMaterialDataType(const std::set<BoundaryID> & boundary_ids) const
242 : {
243 316451 : if (_mi_params.isParamValid("_material_data_type"))
244 42565 : return _mi_params.get<Moose::MaterialDataType>("_material_data_type");
245 273886 : if (moose::internal::boundaryRestricted(boundary_ids))
246 19907 : return Moose::BOUNDARY_MATERIAL_DATA;
247 253979 : return Moose::BLOCK_MATERIAL_DATA;
248 : }
|