https://mooseframework.inl.gov
MaterialPropertyInterface.C
Go to the documentation of this file.
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
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 
21 {
24  "_material_data_type"); // optionally force the type of MaterialData to utilize
25  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  params.addParam<bool>(
31  "use_interpolated_state",
32  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  params.addParamNamesToGroup("use_interpolated_state prop_getter_suffix",
36  "Material property retrieval");
37 
38  return params;
39 }
40 
41 namespace moose
42 {
43 namespace internal
44 {
45 bool
46 boundaryRestricted(const std::set<BoundaryID> & boundary_ids)
47 {
48  return !boundary_ids.empty() && BoundaryRestrictable::restricted(boundary_ids);
49 }
50 }
51 }
52 
54  const std::set<SubdomainID> & block_ids,
55  const std::set<BoundaryID> & boundary_ids)
56  : _mi_moose_object(*moose_object),
57  _mi_params(_mi_moose_object.parameters()),
58  _mi_name(moose_object->name()),
59  _mi_moose_object_name(_mi_moose_object.getBase(), _mi_name, "::"),
60  _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
61  _mi_subproblem(*_mi_params.getCheckedPointerParam<SubProblem *>("_subproblem")),
62  _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
63 #ifdef MOOSE_KOKKOS_ENABLED
64  _is_kokkos_object(_mi_moose_object.isKokkosObject({})),
65 #else
66  _is_kokkos_object(false),
67 #endif
68  _material_data_type(getMaterialDataType(boundary_ids)),
69  _material_data(
70 #ifdef MOOSE_KOKKOS_ENABLED
71  _is_kokkos_object
72  ? _mi_feproblem.getKokkosMaterialData(_material_data_type, moose_object)
73  :
74 #endif
75  _mi_feproblem.getMaterialData(_material_data_type, _mi_tid, moose_object)),
76  _stateful_allowed(true),
77  _get_material_property_called(false),
78  _get_suffix(_mi_params.get<MaterialPropertyName>("prop_getter_suffix")),
79  _use_interpolated_state(_mi_params.get<bool>("use_interpolated_state")),
80  _mi_boundary_restricted(moose::internal::boundaryRestricted(boundary_ids)),
81  _mi_block_ids(block_ids),
82  _mi_boundary_ids(boundary_ids)
83 {
84  moose_object->getMooseApp().registerInterfaceObject(*this);
85 }
86 
87 #ifdef MOOSE_KOKKOS_ENABLED
90  : _mi_moose_object(object._mi_moose_object),
91  _mi_params(object._mi_params),
92  _mi_name(object._mi_name),
93  _mi_moose_object_name(object._mi_moose_object_name),
94  _mi_feproblem(object._mi_feproblem),
95  _mi_subproblem(object._mi_subproblem),
96  _mi_tid(object._mi_tid),
97  _is_kokkos_object(object._is_kokkos_object),
98  _material_data_type(object._material_data_type),
99  _material_data(object._material_data),
100  _stateful_allowed(object._stateful_allowed),
101  _get_material_property_called(object._get_material_property_called),
102  _get_suffix(object._get_suffix),
103  _use_interpolated_state(object._use_interpolated_state),
104  _mi_boundary_restricted(object._mi_boundary_restricted),
105  _mi_block_ids(object._mi_block_ids),
106  _mi_boundary_ids(object._mi_boundary_ids)
107 {
108 }
109 #endif
110 
111 MaterialPropertyName
113 {
114  if (_mi_params.have_parameter<MaterialPropertyName>(name) && _mi_params.isParamValid(name))
115  return _mi_params.get<MaterialPropertyName>(name);
116  return name;
117 }
118 
119 std::set<SubdomainID>
121 {
123 }
124 
125 std::vector<SubdomainName>
127 {
129 }
130 
131 std::set<BoundaryID>
133 {
135 }
136 
137 std::vector<BoundaryName>
139 {
141 }
142 
143 unsigned int
145 {
146  return _mi_feproblem.getMaxQps();
147 }
148 
149 void
151  const std::string & prop_name)
152 {
153  return _mi_feproblem.addConsumedPropertyName(obj_name, prop_name);
154 }
155 
156 void
157 MaterialPropertyInterface::checkMaterialProperty(const std::string & name, const unsigned int state)
158 {
159  if (state == 0)
160  {
161  // If the material property is boundary restrictable, add to the list of materials to check
163  for (const auto & bnd_id : _mi_boundary_ids)
165 
166  // The default is to assume block restrictions
167  else
168  for (const auto & blk_ids : _mi_block_ids)
170  }
171 }
172 
173 void
175 {
177 }
178 
179 void
181 {
182  _stateful_allowed = stateful_allowed;
183 }
184 
185 void
187  std::shared_ptr<MaterialBase> discrete)
188 {
189  // Check block compatibility
190  if (!discrete->hasBlocks(_mi_block_ids))
191  {
192  std::ostringstream oss;
193  oss << "Incompatible material and object blocks:";
194 
195  oss << "\n " << discrete->parameters().paramLocationPrefix("block")
196  << " material defined on blocks ";
197  for (const auto & sbd_id : discrete->blockIDs())
198  oss << sbd_id << ", ";
199 
200  oss << "\n " << _mi_params.paramLocationPrefix("block")
201  << " object needs material on blocks ";
202  for (const auto & block_id : _mi_block_ids)
203  oss << block_id << ", ";
204 
205  mooseError(oss.str());
206  }
207 
208  // Check boundary compatibility
209  if (!discrete->hasBoundary(_mi_boundary_ids))
210  {
211  std::ostringstream oss;
212  oss << "Incompatible material and object boundaries:";
213 
214  oss << "\n " << discrete->parameters().paramLocationPrefix("boundary")
215  << " material defined on boundaries ";
216  for (const auto & bnd_id : discrete->boundaryIDs())
217  oss << bnd_id << ", ";
218 
219  oss << "\n " << _mi_params.paramLocationPrefix("boundary")
220  << " object needs material on boundaries ";
221  for (const auto & bnd_id : _mi_boundary_ids)
222  oss << bnd_id << ", ";
223 
224  mooseError(oss.str());
225  }
226 }
227 
228 MaterialBase &
229 MaterialPropertyInterface::getMaterial(const std::string & name)
230 {
231  return getMaterialByName(_mi_params.get<MaterialName>(name));
232 }
233 
234 MaterialBase &
235 MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
236 {
237  std::shared_ptr<MaterialBase> discrete =
239 
241  return *discrete;
242 }
243 
244 std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
246 {
247  std::unordered_map<SubdomainID, std::vector<MaterialBase *>> required_mats;
248  const auto & mwh = _mi_feproblem.getMaterialWarehouse();
249  for (const auto id : _mi_block_ids)
250  {
251  const auto & mats = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
252  std::array<const MaterialPropertyInterface *, 1> consumers = {{this}};
253  const auto block_required =
254  MaterialBase::buildRequiredMaterials(consumers, mats, allow_stateful);
255  required_mats[id].insert(
256  required_mats[id].begin(), block_required.begin(), block_required.end());
257  }
258  return required_mats;
259 }
260 
261 void
263 {
265  mooseError("Material properties must be retrieved during object construction. This is a code "
266  "problem.");
267 }
268 
269 void
271 {
272  for (auto & proxy : _optional_property_proxies)
273  proxy->resolve(*this);
274 }
275 
277 MaterialPropertyInterface::getMaterialDataType(const std::set<BoundaryID> & boundary_ids) const
278 {
279  if (_mi_params.isParamValid("_material_data_type"))
280  return _mi_params.get<Moose::MaterialDataType>("_material_data_type");
281  if (moose::internal::boundaryRestricted(boundary_ids))
284 }
std::string name(const ElemQuality q)
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const THREAD_ID _mi_tid
Current threaded it.
virtual void resolveOptionalProperties()
resolve all optional properties
static const std::string _interpolated_old
name suffixes for interpolated old and older properties
virtual void checkMaterialProperty(const std::string &name, const unsigned int state)
A helper method for checking material properties This method was required to avoid a compiler problem...
virtual std::set< BoundaryID > getMaterialPropertyBoundaryIDs(const std::string &prop_name)
Get a vector containing the block ids the material property is defined on.
Definition: SubProblem.C:525
const std::set< SubdomainID > & _mi_block_ids
Storage for the block ids created by BlockRestrictable.
std::vector< BoundaryName > getMaterialPropertyBoundaryNames(const std::string &name)
Retrieve the boundary namess that the material property is defined.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
MaterialPropertyInterface(const MooseObject *moose_object, const std::set< SubdomainID > &block_ids, const std::set< BoundaryID > &boundary_ids)
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void addConsumedPropertyName(const MooseObjectName &obj_name, const std::string &prop_name)
Helper for tracking the object that is consuming a property for MaterialPropertyDebugOutput.
Definition: SubProblem.C:736
virtual void storeSubdomainDelayedCheckMatProp(const std::string &requestor, SubdomainID block_id, const std::string &name)
Adds to a map based on block ids of material properties to validate.
Definition: SubProblem.C:607
static const std::string _interpolated_older
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1133
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:692
std::vector< SubdomainName > getMaterialPropertyBlockNames(const std::string &name)
Retrieve the block names that the material property is defined.
const bool _mi_boundary_restricted
BoundaryRestricted flag.
std::set< BoundaryID > getMaterialPropertyBoundaryIDs(const std::string &name)
Retrieve the boundary ids that the material property is defined.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void storeBoundaryDelayedCheckMatProp(const std::string &requestor, BoundaryID boundary_id, const std::string &name)
Adds to a map based on boundary ids of material properties to validate.
Definition: SubProblem.C:615
static InputParameters validParams()
const std::set< BoundaryID > & _mi_boundary_ids
Storage for the boundary ids created by BoundaryRestrictable.
const std::string _mi_name
The name of the object that this interface belongs to.
const MaterialWarehouse & getMaterialWarehouse() const
MaterialPropertyName getMaterialPropertyName(const std::string &name) const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void markMatPropRequested(const std::string &)
Helper method for adding a material property name to the _material_property_requested set...
Definition: SubProblem.C:724
void markMatPropRequested(const std::string &)
A proxy method for _mi_feproblem.markMatPropRequested(name)
InputParameters emptyInputParameters()
std::set< SubdomainID > getMaterialPropertyBlocks(const std::string &name)
Retrieve the block ids that the material property is defined.
static bool restricted(const std::set< BoundaryID > &ids)
Helper for determining if the object is boundary restricted.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:27
Moose::MaterialDataType getMaterialDataType(const std::set< BoundaryID > &boundary_ids) const
virtual std::vector< SubdomainName > getMaterialPropertyBlockNames(const std::string &prop_name)
Get a vector of block id equivalences that the material property is defined on.
Definition: SubProblem.C:489
const InputParameters & _mi_params
Parameters of the object with this interface.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
virtual std::set< SubdomainID > getMaterialPropertyBlocks(const std::string &prop_name)
Get a vector containing the block ids the material property is defined on.
Definition: SubProblem.C:473
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false)
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
virtual std::vector< BoundaryName > getMaterialPropertyBoundaryNames(const std::string &prop_name)
Get a vector of block id equivalences that the material property is defined on.
Definition: SubProblem.C:541
std::shared_ptr< MaterialBase > getMaterial(std::string name, Moose::MaterialDataType type, const THREAD_ID tid=0, bool no_warn=false)
Return a pointer to a MaterialBase object.
An interface for accessing Materials.
static std::deque< MaterialBase * > buildRequiredMaterials(const Consumers &mat_consumers, const std::vector< std::shared_ptr< MaterialBase >> &mats, const bool allow_stateful)
Build the materials required by a set of consumer objects.
Definition: MaterialBase.h:535
std::string paramLocationPrefix(const std::string &param) const
Returns a prefix containing the parameter name and location (if available)
void addConsumedPropertyName(const MooseObjectName &obj_name, const std::string &prop_name)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::vector< std::unique_ptr< OptionalMaterialPropertyProxyBase< MaterialPropertyInterface > > > _optional_property_proxies
optional material properties
void checkBlockAndBoundaryCompatibility(std::shared_ptr< MaterialBase > discrete)
Check if block and boundary restrictions of a given material are compatible with the current material...
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
const Moose::MaterialDataType _material_data_type
The type of data.
bool _stateful_allowed
True by default.
A class for storing the names of MooseObject by tag and object name.
MaterialBase & getMaterial(const std::string &name)
Return a MaterialBase reference - usable for computing directly.
bool boundaryRestricted(const std::set< BoundaryID > &boundary_ids)
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
unsigned int THREAD_ID
Definition: MooseTypes.h:209
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
std::unordered_map< SubdomainID, std::vector< MaterialBase * > > buildRequiredMaterials(bool allow_stateful=true)
get a map of MaterialBase pointers for all material objects that this object depends on for each bloc...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
unsigned int getMaxQps() const