www.mooseframework.org
Material.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
16 #include "Material.h"
17 #include "SubProblem.h"
18 #include "MaterialData.h"
19 #include "Assembly.h"
20 #include "Executioner.h"
21 #include "Transient.h"
22 
23 #include "libmesh/quadrature.h"
24 
25 template <>
28 {
33  params += validParams<RandomInterface>();
35 
36  params.addParam<bool>("use_displaced_mesh",
37  false,
38  "Whether or not this object should use the "
39  "displaced mesh for computation. Note that "
40  "in the case this is true but no "
41  "displacements are provided in the Mesh block "
42  "the undisplaced mesh will still be used.");
43  params.addParam<bool>("compute",
44  true,
45  "When false, MOOSE will not call compute methods on this material. "
46  "The user must call computeProperties() after retrieving the Material "
47  "via MaterialPropertyInterface::getMaterial(). "
48  "Non-computed Materials are not sorted for dependencies.");
49  MooseEnum const_option("NONE=0 ELEMENT=1 SUBDOMAIN=2", "none");
50  params.addParam<MooseEnum>(
51  "constant_on",
52  const_option,
53  "When ELEMENT, MOOSE will only call computeQpProperties() for the 0th "
54  "quadrature point, and then copy that value to the other qps."
55  "When SUBDOMAIN, MOOSE will only call computeSubdomainProperties() for the 0th "
56  "quadrature point, and then copy that value to the other qps. Evaluations on element qps "
57  "will be skipped");
58 
59  // Outputs
60  params += validParams<OutputInterface>();
61  params.set<std::vector<OutputName>>("outputs") = {"none"};
62  params.addParam<std::vector<std::string>>(
63  "output_properties",
64  "List of material properties, from this material, to output (outputs "
65  "must also be defined to an output type)");
66 
67  params.addParamNamesToGroup("outputs output_properties", "Outputs");
68  params.addParamNamesToGroup("use_displaced_mesh constant_on", "Advanced");
69  params.registerBase("Material");
70 
71  return params;
72 }
73 
75  : MooseObject(parameters),
76  BlockRestrictable(this),
77  BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
78  SetupInterface(this),
79  Coupleable(this, false),
81  ScalarCoupleable(this),
82  FunctionInterface(this),
84  UserObjectInterface(this),
85  TransientInterface(this),
86  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
90  Restartable(parameters, "Materials"),
91  ZeroInterface(parameters),
92  MeshChangedInterface(parameters),
93 
94  // The false flag disables the automatic call buildOutputVariableHideList;
95  // for Material objects the hide lists are handled by MaterialOutputAction
96  OutputInterface(parameters, false),
97  RandomInterface(parameters,
98  *parameters.get<FEProblemBase *>("_fe_problem_base"),
99  parameters.get<THREAD_ID>("_tid"),
100  false),
101  _subproblem(*parameters.get<SubProblem *>("_subproblem")),
102  _fe_problem(*parameters.get<FEProblemBase *>("_fe_problem_base")),
103  _tid(parameters.get<THREAD_ID>("_tid")),
104  _assembly(_subproblem.assembly(_tid)),
105  _bnd(_material_data_type != Moose::BLOCK_MATERIAL_DATA),
106  _neighbor(_material_data_type == Moose::NEIGHBOR_MATERIAL_DATA),
107  _qp(std::numeric_limits<unsigned int>::max()),
108  _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
109  _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
110  _coord(_assembly.coordTransformation()),
111  _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
112  _normals(_assembly.normals()),
113  _current_elem(_neighbor ? _assembly.neighbor() : _assembly.elem()),
114  _current_subdomain_id(_neighbor ? _assembly.currentNeighborSubdomainID()
115  : _assembly.currentSubdomainID()),
116  _current_side(_neighbor ? _assembly.neighborSide() : _assembly.side()),
117  _mesh(_subproblem.mesh()),
118  _coord_sys(_assembly.coordSystem()),
119  _compute(getParam<bool>("compute")),
120  _constant_option(getParam<MooseEnum>("constant_on").getEnum<ConstantTypeEnum>()),
121  _has_stateful_property(false)
122 {
123  // Fill in the MooseVariable dependencies
124  const std::vector<MooseVariable *> & coupled_vars = getCoupledMooseVars();
125  for (const auto & var : coupled_vars)
127 }
128 
129 void
130 Material::initStatefulProperties(unsigned int n_points)
131 {
132  for (_qp = 0; _qp < n_points; ++_qp)
134 
135  // checking for statefulness of properties via this loop is necessary
136  // because owned props might have been promoted to stateful by calls to
137  // getMaterialProperty[Old/Older] from other objects. In these cases, this
138  // object won't otherwise know that it owns stateful properties.
139  for (auto & prop : _supplied_props)
140  if (_material_data->getMaterialPropertyStorage().isStatefulProp(prop) &&
142  mooseError(std::string("Material \"") + name() + "\" provides one or more stateful "
143  "properties but initQpStatefulProperties() "
144  "was not overridden in the derived class.");
145 }
146 
147 void
149 {
151 }
152 
153 void
155 {
156  for (const auto & it : _props_to_flags)
157  if (static_cast<int>(it.second) % 2 == 0) // Only Stateful properties declared!
158  mooseError("Material '", name(), "' requests undefined stateful property '", it.first, "'");
159 }
160 
161 void
162 Material::registerPropName(std::string prop_name, bool is_get, Material::Prop_State state)
163 {
164  if (!is_get)
165  {
166  _supplied_props.insert(prop_name);
167  _supplied_prop_ids.insert(_material_data->getPropertyId(prop_name));
168 
169  _props_to_flags[prop_name] |= static_cast<int>(state);
170  if (static_cast<int>(state) % 2 == 0)
171  _has_stateful_property = true;
172  }
173 
174  // Store material properties for block ids
175  for (const auto & block_id : blockIDs())
176  _fe_problem.storeMatPropName(block_id, prop_name);
177 
178  // Store material properties for the boundary ids
179  for (const auto & boundary_id : boundaryIDs())
180  _fe_problem.storeMatPropName(boundary_id, prop_name);
181 }
182 
183 std::set<OutputName>
185 {
186  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
187  return std::set<OutputName>(out.begin(), out.end());
188 }
189 
190 void
192 {
193  if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
194  {
195  unsigned int nqp = _fe_problem.getMaxQps();
196 
197  MaterialProperties & props = _material_data->props();
198  for (const auto & prop_id : _supplied_prop_ids)
199  props[prop_id]->resize(nqp);
200 
201  _qp = 0;
203 
204  for (const auto & prop_id : _supplied_prop_ids)
205  {
206  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
207  props[prop_id]->qpCopy(qp, props[prop_id], 0);
208  }
209  }
210 }
211 
212 void
214 {
215  mooseError("computeSubdomainQpProperties in Material '", name(), "' needs to be implemented");
216 }
217 
218 void
220 {
221  if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
222  return;
223 
224  // If this Material has the _constant_on_elem flag set, we take the
225  // value computed for _qp==0 and use it at all the quadrature points
226  // in the Elem.
227  if (_constant_option == ConstantTypeEnum::ELEMENT)
228  {
229  // Compute MaterialProperty values at the first qp.
230  _qp = 0;
232 
233  // Reference to *all* the MaterialProperties in the MaterialData object, not
234  // just the ones for this Material.
235  MaterialProperties & props = _material_data->props();
236 
237  // Now copy the values computed at qp 0 to all the other qps.
238  for (const auto & prop_id : _supplied_prop_ids)
239  {
240  auto nqp = _qrule->n_points();
241  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
242  props[prop_id]->qpCopy(qp, props[prop_id], 0);
243  }
244  }
245  else
246  {
247  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
249  }
250 }
251 
252 void
254 {
255 }
256 
257 void
259 {
260  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
262 }
263 
264 void
266 {
267  if (!_compute)
268  mooseDoOnce(mooseWarning("You disabled the computation of this (",
269  name(),
270  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
271  "method, this can lead to unintended values being set for material "
272  "property values."));
273 }
274 
275 void
277 {
278  _qp = qp;
280 }
281 
282 void
284 {
286  mooseError("Material properties must be retrieved during material object construction to "
287  "ensure correct dependency resolution.");
288 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
InputParameters validParams< MaterialPropertyInterface >()
std::map< std::string, int > _props_to_flags
Definition: Material.h:281
Interface for objects that need parallel consistent random numbers without patterns over the course o...
bool _has_stateful_property
Definition: Material.h:290
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object.
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
void mooseWarning(Args &&...args) const
Definition: MooseObject.h:89
A class for creating restricted objects.
Definition: Restartable.h:31
virtual void computeQpProperties()
Users must override this method.
Definition: Material.C:253
InputParameters validParams< BlockRestrictable >()
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: Material.C:265
InputParameters validParams< OutputInterface >()
Container for storing material properties.
FEProblemBase & _fe_problem
Definition: Material.h:213
bool _overrides_init_stateful_props
Definition: Material.h:292
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:267
const std::vector< MooseVariable * > & getCoupledMooseVars() const
Get the list of coupled variables.
Definition: Coupleable.h:63
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: Material.h:254
A class to provide an common interface to objects requiring "outputs" option.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addMooseVariableDependency(MooseVariable *var)
Call this function to add the passed in MooseVariable as a variable that this object depends on...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: Material.C:191
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if &#39;compute = fal...
Definition: Material.C:258
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const bool _compute
If False MOOSE does not compute this property.
Definition: Material.h:257
unsigned int _qp
Definition: Material.h:220
Interface for objects that needs transient capabilities.
unsigned int getMaxQps() const
virtual void computeProperties()
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:219
Interface for notifications that the mesh has changed.
void checkStatefulSanity() const
Definition: Material.C:154
InputParameters validParams< RandomInterface >()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
Interface for objects that need to use distributions.
virtual void computeSubdomainProperties()
Evaluate material properties on subdomain.
Definition: Material.C:213
ConstantTypeEnum
Definition: Material.h:259
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
Interface for objects that need to use UserObjects.
virtual void initStatefulProperties(unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: Material.C:130
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
Definition: Material.C:184
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:35
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
void checkExecutionStage()
Check and throw an error if the execution has progerssed past the construction stage.
Definition: Material.C:283
Interface to bring zero values inside objects.
Definition: ZeroInterface.h:35
An interface for accessing Materials.
InputParameters validParams< BoundaryRestrictable >()
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
void registerPropName(std::string prop_name, bool is_get, Prop_State state)
Small helper function to call storeMatPropName.
Definition: Material.C:162
Interface for sorting dependent vectors of objects.
Interface for objects that needs scalar coupling capabilities.
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a Material.
Definition: Material.C:276
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
Definition: Moose.h:84
std::set< std::string > _supplied_props
Set of properties declared.
Definition: Material.h:245
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: Material.C:148
InputParameters validParams< Material >()
Definition: Material.C:27
virtual void storeMatPropName(SubdomainID block_id, const std::string &name)
Adds the given material property to a storage map based on block ids.
Definition: SubProblem.C:220
Interface for objects that need to use functions.
InputParameters validParams< TransientInterface >()
Interface class for classes which interact with Postprocessors.
Material(const InputParameters &parameters)
Definition: Material.C:74
unsigned int THREAD_ID
Definition: MooseTypes.h:79
QBase *& _qrule
Definition: Material.h:222
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.