www.mooseframework.org
Material.h
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 #ifndef MATERIAL_H
16 #define MATERIAL_H
17 
18 // MOOOSE includes
19 #include "MooseObject.h"
20 #include "BlockRestrictable.h"
21 #include "BoundaryRestrictable.h"
22 #include "SetupInterface.h"
23 #include "Coupleable.h"
25 #include "ScalarCoupleable.h"
26 #include "FunctionInterface.h"
27 #include "DistributionInterface.h"
28 #include "UserObjectInterface.h"
29 #include "TransientInterface.h"
31 #include "PostprocessorInterface.h"
34 #include "Restartable.h"
35 #include "ZeroInterface.h"
36 #include "MeshChangedInterface.h"
37 #include "OutputInterface.h"
38 #include "RandomInterface.h"
39 #include "MaterialProperty.h"
40 
41 // forward declarations
42 class Material;
43 class MooseMesh;
44 class MaterialData;
45 class SubProblem;
46 
47 template <>
49 
53 class Material : public MooseObject,
54  public BlockRestrictable,
55  public BoundaryRestrictable,
56  public SetupInterface,
57  public Coupleable,
59  public ScalarCoupleable,
60  public FunctionInterface,
61  public DistributionInterface,
62  public UserObjectInterface,
63  public TransientInterface,
68  public Restartable,
69  public ZeroInterface,
70  public MeshChangedInterface,
71  public OutputInterface,
72  public RandomInterface
73 {
74 public:
76 
80  virtual void initStatefulProperties(unsigned int n_points);
81 
85  virtual void computeProperties();
86 
93  virtual void resetProperties();
94 
102  virtual void computePropertiesAtQp(unsigned int qp);
103 
105 
109  template <typename T>
110  const MaterialProperty<T> & getMaterialProperty(const std::string & name);
111  template <typename T>
112  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
113  template <typename T>
114  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
116 
118 
121  template <typename T>
122  const MaterialProperty<T> & getMaterialPropertyByName(const std::string & prop_name);
123  template <typename T>
124  const MaterialProperty<T> & getMaterialPropertyOldByName(const std::string & prop_name);
125  template <typename T>
126  const MaterialProperty<T> & getMaterialPropertyOlderByName(const std::string & prop_name);
128 
130 
133  template <typename T>
134  MaterialProperty<T> & declareProperty(const std::string & prop_name);
135  template <typename T>
136  MaterialProperty<T> & declarePropertyOld(const std::string & prop_name);
137  template <typename T>
138  MaterialProperty<T> & declarePropertyOlder(const std::string & prop_name);
140 
145  template <typename T>
146  const MaterialProperty<T> & getZeroMaterialProperty(const std::string & prop_name);
147 
152  virtual const std::set<std::string> & getRequestedItems() override { return _requested_props; }
153 
158  virtual const std::set<std::string> & getSuppliedItems() override { return _supplied_props; }
159 
160  void checkStatefulSanity() const;
161 
166  std::set<OutputName> getOutputs();
167 
171  bool isBoundaryMaterial() const { return _bnd; }
172 
176  virtual void subdomainSetup() override;
177 
178 protected:
182  virtual void computeSubdomainProperties();
183 
187  virtual void computeQpProperties();
188 
198  virtual void resetQpProperties();
199 
209  virtual void initQpStatefulProperties();
210 
212 
216 
217  bool _bnd;
218  bool _neighbor;
219 
220  unsigned int _qp;
221 
222  QBase *& _qrule;
228 
229  const Elem *& _current_elem;
230 
232 
234  unsigned int & _current_side;
235 
237 
240 
242  std::set<std::string> _requested_props;
243 
245  std::set<std::string> _supplied_props;
246 
254  std::set<unsigned int> _supplied_prop_ids;
255 
257  const bool _compute;
258 
260  {
264  };
265 
268 
270  {
273  };
274 
276  {
277  CURRENT = 0x1,
278  OLD = 0x2,
279  OLDER = 0x4
280  };
281  std::map<std::string, int> _props_to_flags;
282 
283 private:
285  void registerPropName(std::string prop_name, bool is_get, Prop_State state);
286 
288  void checkExecutionStage();
289 
291 
293 };
294 
295 template <typename T>
296 const MaterialProperty<T> &
298 {
299  // Check if the supplied parameter is a valid imput parameter key
300  std::string prop_name = deducePropertyName(name);
301 
302  // Check if it's just a constant.
303  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
304  if (default_property)
305  return *default_property;
306 
307  return getMaterialPropertyByName<T>(prop_name);
308 }
309 
310 template <typename T>
311 const MaterialProperty<T> &
313 {
314  // Check if the supplied parameter is a valid imput parameter key
315  std::string prop_name = deducePropertyName(name);
316 
317  // Check if it's just a constant.
318  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
319  if (default_property)
320  return *default_property;
321 
322  return getMaterialPropertyOldByName<T>(prop_name);
323 }
324 
325 template <typename T>
326 const MaterialProperty<T> &
328 {
329  // Check if the supplied parameter is a valid imput parameter key
330  std::string prop_name = deducePropertyName(name);
331 
332  // Check if it's just a constant.
333  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
334  if (default_property)
335  return *default_property;
336 
337  return getMaterialPropertyOlderByName<T>(prop_name);
338 }
339 
340 template <typename T>
341 const MaterialProperty<T> &
342 Material::getMaterialPropertyByName(const std::string & prop_name)
343 {
345  // The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
346  // same memory)
347  _requested_props.insert(prop_name);
348  registerPropName(prop_name, true, Material::CURRENT);
349  return MaterialPropertyInterface::getMaterialPropertyByName<T>(prop_name);
350 }
351 
352 template <typename T>
353 const MaterialProperty<T> &
354 Material::getMaterialPropertyOldByName(const std::string & prop_name)
355 {
356  registerPropName(prop_name, true, Material::OLD);
357  return MaterialPropertyInterface::getMaterialPropertyOldByName<T>(prop_name);
358 }
359 
360 template <typename T>
361 const MaterialProperty<T> &
362 Material::getMaterialPropertyOlderByName(const std::string & prop_name)
363 {
364  registerPropName(prop_name, true, Material::OLDER);
365  return MaterialPropertyInterface::getMaterialPropertyOlderByName<T>(prop_name);
366 }
367 
368 template <typename T>
370 Material::declareProperty(const std::string & prop_name)
371 {
372  registerPropName(prop_name, false, Material::CURRENT);
373  return _material_data->declareProperty<T>(prop_name);
374 }
375 
376 template <typename T>
378 Material::declarePropertyOld(const std::string & prop_name)
379 {
380  mooseDoOnce(
381  mooseDeprecated("declarePropertyOld is deprecated and not needed anymore.\nUse "
382  "getMaterialPropertyOld (only) if a reference is required in this class."));
383  registerPropName(prop_name, false, Material::OLD);
384  return _material_data->declarePropertyOld<T>(prop_name);
385 }
386 
387 template <typename T>
389 Material::declarePropertyOlder(const std::string & prop_name)
390 {
391  mooseDoOnce(
392  mooseDeprecated("declarePropertyOlder is deprecated and not needed anymore. Use "
393  "getMaterialPropertyOlder (only) if a reference is required in this class."));
394  registerPropName(prop_name, false, Material::OLDER);
395  return _material_data->declarePropertyOlder<T>(prop_name);
396 }
397 
398 template <typename T>
399 const MaterialProperty<T> &
400 Material::getZeroMaterialProperty(const std::string & prop_name)
401 {
403  MaterialProperty<T> & preload_with_zero = _material_data->getProperty<T>(prop_name);
404 
405  _requested_props.insert(prop_name);
406  registerPropName(prop_name, true, Material::CURRENT);
408 
409  // Register this material on these blocks and boundaries as a zero property with relaxed
410  // consistency checking
411  for (std::set<SubdomainID>::const_iterator it = blockIDs().begin(); it != blockIDs().end(); ++it)
412  _fe_problem.storeZeroMatProp(*it, prop_name);
413  for (std::set<BoundaryID>::const_iterator it = boundaryIDs().begin(); it != boundaryIDs().end();
414  ++it)
415  _fe_problem.storeZeroMatProp(*it, prop_name);
416 
417  // set values for all qpoints to zero
418  // (in multiapp scenarios getMaxQps can return different values in each app; we need the max)
419  unsigned int nqp = _mi_feproblem.getMaxQps();
420  if (nqp > preload_with_zero.size())
421  preload_with_zero.resize(nqp);
422  for (unsigned int qp = 0; qp < nqp; ++qp)
423  mooseSetToZero<T>(preload_with_zero[qp]);
424 
425  return preload_with_zero;
426 }
427 
428 #endif // MATERIAL_H
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
const MooseArray< Point > & _q_point
Definition: Material.h:225
std::map< std::string, int > _props_to_flags
Definition: Material.h:281
SubProblem & _subproblem
Definition: Material.h:211
Interface for objects that need parallel consistent random numbers without patterns over the course o...
const MaterialProperty< T > & getZeroMaterialProperty(const std::string &prop_name)
Return a material property that is initialized to zero by default and does not need to (but can) be d...
Definition: Material.h:400
bool _has_stateful_property
Definition: Material.h:290
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object.
unsigned int & _current_side
current side of the current element
Definition: Material.h:234
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
A class for creating restricted objects.
Definition: Restartable.h:31
const MaterialProperty< T > & getMaterialPropertyOlderByName(const std::string &prop_name)
Definition: Material.h:362
Keeps track of stuff related to assembling.
Definition: Assembly.h:63
virtual void computeQpProperties()
Users must override this method.
Definition: Material.C:253
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: Material.C:265
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
FEProblemBase & _fe_problem
Definition: Material.h:213
bool _overrides_init_stateful_props
Definition: Material.h:292
const Elem *& _current_elem
Definition: Material.h:229
const MaterialProperty< T > & getMaterialPropertyOldByName(const std::string &prop_name)
Definition: Material.h:354
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:267
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.
const MooseArray< Real > & _JxW
Definition: Material.h:223
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 resize(int n)
Resizes the property to the size n.
std::set< std::string > _requested_props
Set of properties accessed via get method.
Definition: Material.h:242
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.
virtual void markMatPropRequested(const std::string &)
Helper method for adding a material property name to the _material_property_requested set...
Definition: SubProblem.C:284
MaterialProperty< T > & declarePropertyOlder(const std::string &prop_name)
Definition: Material.h:389
const bool _compute
If False MOOSE does not compute this property.
Definition: Material.h:257
unsigned int _qp
Definition: Material.h:220
virtual void storeZeroMatProp(SubdomainID block_id, const MaterialPropertyName &name)
Adds to a map based on block ids of material properties for which a zero value can be returned...
Definition: SubProblem.C:241
std::string deducePropertyName(const std::string &name)
Small helper to look up a material property name through the input parameter keys.
Interface for objects that needs transient capabilities.
bool _bnd
Definition: Material.h:217
unsigned int getMaxQps() const
THREAD_ID _tid
Definition: Material.h:214
virtual void computeProperties()
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:219
Interface for notifications that the mesh has changed.
virtual const std::set< std::string > & getSuppliedItems() override
Return a set of properties accessed with declareProperty.
Definition: Material.h:158
MaterialProperty< T > & declarePropertyOld(const std::string &prop_name)
Definition: Material.h:378
void checkStatefulSanity() const
Definition: Material.C:154
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
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
Interface for objects that need to use UserObjects.
bool _neighbor
Definition: Material.h:218
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: Material.h:327
virtual void initStatefulProperties(unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: Material.C:130
CoordinateSystemType
Definition: MooseTypes.h:212
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
Materials compute MaterialProperties.
Definition: Material.h:53
virtual const std::set< std::string > & getRequestedItems() override
Return a set of properties accessed with getMaterialProperty.
Definition: Material.h:152
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
Definition: Material.C:184
void mooseDeprecated(Args &&...args) const
Definition: MooseObject.h:95
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.
Concrete definition of a parameter value for a specified type.
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
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.
unsigned int size() const
MooseMesh & _mesh
Definition: Material.h:236
MaterialProperty< T > & declareProperty(const std::string &prop_name)
Declare the property named "name".
Definition: Material.h:370
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a Material.
Definition: Material.C:276
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:33
const MooseArray< Real > & _coord
Definition: Material.h:224
Assembly & _assembly
Definition: Material.h:215
const Moose::CoordinateSystemType & _coord_sys
Coordinate system.
Definition: Material.h:239
const SubdomainID & _current_subdomain_id
Definition: Material.h:231
InputParameters validParams< Material >()
Definition: Material.C:27
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
const MooseArray< Point > & _normals
normals at quadrature points (valid only in boundary materials)
Definition: Material.h:227
const MaterialProperty< T > & getMaterialProperty(const std::string &name)
Retrieve the property through a given input parameter key with a fallback to getting it by name...
Definition: Material.h:297
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: Material.h:312
QP_Data_Type
Definition: Material.h:269
Interface for objects that need to use functions.
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
bool isBoundaryMaterial() const
Returns true of the MaterialData type is not associated with volume data.
Definition: Material.h:171
const MaterialProperty< T > & getMaterialPropertyByName(const std::string &prop_name)
Retrieve the property named "name".
Definition: Material.h:342