www.mooseframework.org
MaterialPropertyInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "Material.h"
14 
15 template <>
18 {
21  "_material_data_type"); // optionally force the type of MaterialData to utilize
22  return params;
23 }
24 
26  const std::set<SubdomainID> & block_ids,
27  const std::set<BoundaryID> & boundary_ids)
28  : _mi_params(moose_object->parameters()),
29  _mi_name(_mi_params.get<std::string>("_object_name")),
30  _mi_feproblem(*_mi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
31  _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
32  _stateful_allowed(true),
33  _get_material_property_called(false),
34  _mi_boundary_restricted(!boundary_ids.empty() &&
35  BoundaryRestrictable::restricted(boundary_ids)),
36  _mi_block_ids(block_ids),
37  _mi_boundary_ids(boundary_ids)
38 {
39 
40  // Set the MaterialDataType flag
41  if (_mi_params.isParamValid("_material_data_type"))
42  _material_data_type = _mi_params.get<Moose::MaterialDataType>("_material_data_type");
43 
44  else if (_mi_boundary_restricted)
46 
47  else
49 
52 }
53 
54 std::string
56 {
57  if (_mi_params.have_parameter<MaterialPropertyName>(name))
58  return _mi_params.get<MaterialPropertyName>(name);
59  else
60  return name;
61 }
62 
63 template <>
66 {
67  std::istringstream ss(name);
68  Real real_value;
69 
70  // check if the string parsed cleanly into a Real number
71  if (ss >> real_value && ss.eof())
72  {
73  _default_real_properties.emplace_back(libmesh_make_unique<MaterialProperty<Real>>());
74  auto & default_property = _default_real_properties.back();
75 
76  // resize to accomodate maximum number obf qpoints
77  auto nqp = _mi_feproblem.getMaxQps();
78  default_property->resize(nqp);
79 
80  // set values for all qpoints to the given default
81  for (decltype(nqp) qp = 0; qp < nqp; ++qp)
82  (*default_property)[qp] = real_value;
83 
84  // return the raw pointer inside the shared pointer
85  return default_property.get();
86  }
87 
88  return nullptr;
89 }
90 
91 template <>
94 {
95  std::istringstream ss(name);
96  Real real_value;
97 
98  // check if the string parsed cleanly into a Real number
99  if (ss >> real_value && ss.eof())
100  {
101  _default_ad_real_properties.emplace_back(
102  libmesh_make_unique<ADMaterialPropertyObject<Real>>(true));
103  auto & default_property = _default_ad_real_properties.back();
104 
105  // resize to accomodate maximum number obf qpoints
106  auto nqp = _mi_feproblem.getMaxQps();
107  default_property->resize(nqp);
108 
109  // set values for all qpoints to the given default
110  for (decltype(nqp) qp = 0; qp < nqp; ++qp)
111  {
112  // This sets the dual number member of the MooseADWrapper for Jacobian calculations
113  (*default_property)[qp] = real_value;
114  // This sets the value member of the MooseADWrapper for residual calculations
115  default_property->set()[qp].value() = real_value;
116  }
117 
118  // return the raw pointer inside the shared pointer
119  return default_property.get();
120  }
121 
122  return nullptr;
123 }
124 
125 template <>
128 {
129  std::istringstream ss(name);
130  Real real_value;
131 
132  // check if the string parsed cleanly into a Real number
133  if (ss >> real_value && ss.eof())
134  {
136  libmesh_make_unique<ADMaterialPropertyObject<RealVectorValue>>());
137  auto & default_property = _default_ad_real_vector_properties.back();
138 
139  // resize to accomodate maximum number obf qpoints
140  auto nqp = _mi_feproblem.getMaxQps();
141  default_property->resize(nqp);
142 
143  // set values for all qpoints to the given default
144  for (decltype(nqp) qp = 0; qp < nqp; ++qp)
145  (*default_property)[qp] = real_value;
146 
147  // return the raw pointer inside the shared pointer
148  return default_property.get();
149  }
150 
151  return nullptr;
152 }
153 
154 std::set<SubdomainID>
156 {
158 }
159 
160 std::vector<SubdomainName>
162 {
164 }
165 
166 std::set<BoundaryID>
168 {
170 }
171 
172 std::vector<BoundaryName>
174 {
176 }
177 
178 void
180 {
181  // If the material property is boundary restrictable, add to the list of materials to check
183  for (const auto & bnd_id : _mi_boundary_ids)
185 
186  // The default is to assume block restrictions
187  else
188  for (const auto & blk_ids : _mi_block_ids)
190 }
191 
192 void
194 {
196 }
197 
198 void
200 {
201  _stateful_allowed = stateful_allowed;
202 }
203 
204 Material &
205 MaterialPropertyInterface::getMaterial(const std::string & name)
206 {
207  return getMaterialByName(_mi_params.get<MaterialName>(name));
208 }
209 
210 void
212 {
213  // Check block compatibility
214  if (!discrete->hasBlocks(_mi_block_ids))
215  {
216  std::ostringstream oss;
217  oss << "The Material object '" << discrete->name()
218  << "' is defined on blocks that are incompatible with the retrieving object '" << _mi_name
219  << "':\n";
220  oss << " " << discrete->name();
221  for (const auto & sbd_id : discrete->blockIDs())
222  oss << " " << sbd_id;
223  oss << "\n";
224  oss << " " << _mi_name;
225  for (const auto & block_id : _mi_block_ids)
226  oss << " " << block_id;
227  oss << "\n";
228  mooseError(oss.str());
229  }
230 
231  // Check boundary compatibility
232  if (!discrete->hasBoundary(_mi_boundary_ids))
233  {
234  std::ostringstream oss;
235  oss << "The Material object '" << discrete->name()
236  << "' is defined on boundaries that are incompatible with the retrieving object '"
237  << _mi_name << "':\n";
238  oss << " " << discrete->name();
239  for (const auto & bnd_id : discrete->boundaryIDs())
240  oss << " " << bnd_id;
241  oss << "\n";
242  oss << " " << _mi_name;
243  for (const auto & bnd_id : _mi_boundary_ids)
244  oss << " " << bnd_id;
245  oss << "\n";
246  mooseError(oss.str());
247  }
248 }
249 
250 Material &
251 MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
252 {
253  std::shared_ptr<Material> discrete =
256  return *discrete;
257 }
258 
259 template <ComputeStage compute_stage>
260 Material &
261 MaterialPropertyInterface::getMaterial(const std::string & name)
262 {
263  return getMaterialByName<compute_stage>(_mi_params.get<MaterialName>(name));
264 }
265 
266 template <>
267 Material &
268 MaterialPropertyInterface::getMaterialByName<RESIDUAL>(const std::string & name, bool no_warn)
269 {
270  const std::string new_name = name + "_residual";
271  return getMaterialByName(new_name, no_warn);
272 }
273 
274 template <>
275 Material &
276 MaterialPropertyInterface::getMaterialByName<JACOBIAN>(const std::string & name, bool no_warn)
277 {
278  const std::string new_name = name + "_jacobian";
279  return getMaterialByName(new_name, no_warn);
280 }
281 
282 template Material & MaterialPropertyInterface::getMaterial<RESIDUAL>(const std::string &);
283 template Material & MaterialPropertyInterface::getMaterial<JACOBIAN>(const std::string &);
284 
285 void
287 {
289  mooseError("Material properties must be retrieved during object construction to ensure correct "
290  "problem integrity validation.");
291 }
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const THREAD_ID _mi_tid
Current threaded it.
void checkBlockAndBoundaryCompatibility(std::shared_ptr< Material > discrete)
Check if block and boundary restrictions of a given material are compatible with the current material...
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:348
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.
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:207
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:430
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:459
std::vector< SubdomainName > getMaterialPropertyBlockNames(const std::string &name)
Retrieve the block names that the material property is defined.
Moose::MaterialDataType _material_data_type
The type of data.
const bool _mi_boundary_restricted
BoundaryRestricted flag.
Material & getMaterial(const std::string &name)
Return a Material reference - usable for computing directly.
std::set< BoundaryID > getMaterialPropertyBoundaryIDs(const std::string &name)
Retrieve the boundary ids that the material property is defined.
std::shared_ptr< Material > getMaterial(std::string name, Moose::MaterialDataType type, THREAD_ID tid=0, bool no_warn=false)
Return a pointer to a Material object.
const MaterialProperty< T > * defaultMaterialProperty(const std::string &name)
Helper function to parse default material property values.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
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:438
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.
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:546
void markMatPropRequested(const std::string &)
A proxy method for _mi_feproblem.markMatPropRequested(name)
std::vector< std::unique_ptr< ADMaterialPropertyObject< Real > > > _default_ad_real_properties
Storage vector for ADMaterialPropertyObject<Real> default objects.
InputParameters emptyInputParameters()
std::vector< std::unique_ptr< MaterialProperty< Real > > > _default_real_properties
Storage vector for MaterialProperty<Real> default objects.
std::string deducePropertyName(const std::string &name)
Small helper to look up a material property name through the input parameter keys.
std::set< SubdomainID > getMaterialPropertyBlocks(const std::string &name)
Retrieve the block ids that the material property is defined.
InputParameters validParams< MaterialPropertyInterface >()
Material & getMaterialByName(const std::string &name, bool no_warn=false)
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const ADMaterialPropertyObject< T > * defaultADMaterialProperty(const std::string &name)
Helper function to parse default material property values.
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:307
const InputParameters & _mi_params
Parameters of the object with this interface.
std::shared_ptr< MaterialData > getMaterialData(Moose::MaterialDataType type, THREAD_ID tid=0)
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
Materials compute MaterialProperties.
Definition: Material.h:46
void checkMaterialProperty(const std::string &name)
A helper method for checking material properties This method was required to avoid a compiler problem...
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:291
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
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:364
std::vector< std::unique_ptr< ADMaterialPropertyObject< RealVectorValue > > > _default_ad_real_vector_properties
Storage vector for ADMaterialPropertyObject<RealVectorValue> default objects.
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
bool _stateful_allowed
True by default.
unsigned int THREAD_ID
Definition: MooseTypes.h:161
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
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