www.mooseframework.org
MaterialPropertyInterface.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
17 #include "MooseApp.h"
18 #include "Material.h"
19 
20 template <>
23 {
26  "_material_data_type"); // optionally force the type of MaterialData to utilize
27  return params;
28 }
29 
32 {
33 }
34 
36  const std::set<SubdomainID> & block_ids)
37  : MaterialPropertyInterface(moose_object, block_ids, Moose::EMPTY_BOUNDARY_IDS)
38 {
39 }
40 
42  const std::set<BoundaryID> & boundary_ids)
43  : MaterialPropertyInterface(moose_object, Moose::EMPTY_BLOCK_IDS, boundary_ids)
44 {
45 }
46 
48  const std::set<SubdomainID> & block_ids,
49  const std::set<BoundaryID> & boundary_ids)
50  : _mi_params(moose_object->parameters()),
51  _mi_name(_mi_params.get<std::string>("_object_name")),
52  _mi_feproblem(*_mi_params.get<FEProblemBase *>("_fe_problem_base")),
53  _mi_tid(_mi_params.get<THREAD_ID>("_tid")),
54  _stateful_allowed(true),
56  _mi_boundary_restricted(!boundary_ids.empty() &&
57  BoundaryRestrictable::restricted(boundary_ids)),
58  _mi_block_ids(block_ids),
59  _mi_boundary_ids(boundary_ids)
60 {
61 
62  // Set the MaterialDataType flag
63  if (_mi_params.isParamValid("_material_data_type"))
64  _material_data_type = _mi_params.get<Moose::MaterialDataType>("_material_data_type");
65 
66  else if (_mi_boundary_restricted)
68 
69  else
71 
74 }
75 
76 std::string
78 {
79  if (_mi_params.have_parameter<MaterialPropertyName>(name))
80  return _mi_params.get<MaterialPropertyName>(name);
81  else
82  return name;
83 }
84 
85 template <>
88 {
89  std::istringstream ss(name);
90  Real real_value;
91 
92  // check if the string parsed cleanly into a Real number
93  if (ss >> real_value && ss.eof())
94  {
95  _default_real_properties.emplace_back(libmesh_make_unique<MaterialProperty<Real>>());
96  auto & default_property = _default_real_properties.back();
97 
98  // resize to accomodate maximum number obf qpoints
99  auto nqp = _mi_feproblem.getMaxQps();
100  default_property->resize(nqp);
101 
102  // set values for all qpoints to the given default
103  for (decltype(nqp) qp = 0; qp < nqp; ++qp)
104  (*default_property)[qp] = real_value;
105 
106  // return the raw pointer inside the shared pointer
107  return default_property.get();
108  }
109 
110  return nullptr;
111 }
112 
113 std::set<SubdomainID>
115 {
117 }
118 
119 std::vector<SubdomainName>
121 {
123 }
124 
125 std::set<BoundaryID>
127 {
129 }
130 
131 std::vector<BoundaryName>
133 {
135 }
136 
137 void
139 {
140  // If the material property is boundary restrictable, add to the list of materials to check
142  for (const auto & bnd_id : _mi_boundary_ids)
144 
145  // The default is to assume block restrictions
146  else
147  for (const auto & blk_ids : _mi_block_ids)
149 }
150 
151 void
153 {
155 }
156 
157 void
159 {
160  _stateful_allowed = stateful_allowed;
161 }
162 
163 Material &
164 MaterialPropertyInterface::getMaterial(const std::string & name)
165 {
166  return getMaterialByName(_mi_params.get<MaterialName>(name));
167 }
168 
169 Material &
170 MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
171 {
172  std::shared_ptr<Material> discrete =
174 
175  // Check block compatibility
176  if (!discrete->hasBlocks(_mi_block_ids))
177  {
178  std::ostringstream oss;
179  oss << "The Material object '" << discrete->name()
180  << "' is defined on blocks that are incompatible with the retrieving object '" << _mi_name
181  << "':\n";
182  oss << " " << discrete->name();
183  for (const auto & sbd_id : discrete->blockIDs())
184  oss << " " << sbd_id;
185  oss << "\n";
186  oss << " " << _mi_name;
187  for (const auto & block_id : _mi_block_ids)
188  oss << " " << block_id;
189  oss << "\n";
190  mooseError(oss.str());
191  }
192 
193  // Check boundary compatibility
194  if (!discrete->hasBoundary(_mi_boundary_ids))
195  {
196  std::ostringstream oss;
197  oss << "The Material object '" << discrete->name()
198  << "' is defined on boundaries that are incompatible with the retrieving object '"
199  << _mi_name << "':\n";
200  oss << " " << discrete->name();
201  for (const auto & bnd_id : discrete->boundaryIDs())
202  oss << " " << bnd_id;
203  oss << "\n";
204  oss << " " << _mi_name;
205  for (const auto & bnd_id : _mi_boundary_ids)
206  oss << " " << bnd_id;
207  oss << "\n";
208  mooseError(oss.str());
209  }
210 
211  return *discrete;
212 }
213 
214 void
216 {
218  mooseError("Material properties must be retrieved during object construction to ensure correct "
219  "problem integrity validation.");
220 }
virtual void storeDelayedCheckMatProp(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:244
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const THREAD_ID _mi_tid
Current threaded it.
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:162
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.
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...
Material & getMaterial(const std::string &name)
Return a Material reference - usable for computing directly.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:129
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.
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...
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:275
void markMatPropRequested(const std::string &)
A proxy method for _mi_feproblem.markMatPropRequested(name)
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 >()
unsigned int getMaxQps() const
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
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:36
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:121
MaterialPropertyInterface(const MooseObject *moose_object)
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:53
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:105
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
const std::set< SubdomainID > EMPTY_BLOCK_IDS
Definition: MooseTypes.h:121
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:178
An interface for accessing Materials.
const std::set< BoundaryID > EMPTY_BOUNDARY_IDS
Definition: MooseTypes.h:122
Definition: Moose.h:84
bool _get_material_property_called
Initialized to false.
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:79
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.