www.mooseframework.org
MaterialPropertyInterface.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 MATERIALPROPERTYINTERFACE_H
16 #define MATERIALPROPERTYINTERFACE_H
17 
18 // MOOSE includes
19 #include "FEProblemBase.h"
20 #include "MooseTypes.h"
21 #include "MaterialProperty.h"
22 #include "MaterialData.h"
23 
24 // Forward declarations
25 class InputParameters;
27 class MooseObject;
28 
29 template <typename T>
31 
32 template <>
34 
46 {
47 public:
48  MaterialPropertyInterface(const MooseObject * moose_object);
49  MaterialPropertyInterface(const MooseObject * moose_object,
50  const std::set<SubdomainID> & block_ids);
51  MaterialPropertyInterface(const MooseObject * moose_object,
52  const std::set<BoundaryID> & boundary_ids);
53  MaterialPropertyInterface(const MooseObject * moose_object,
54  const std::set<SubdomainID> & block_ids,
55  const std::set<BoundaryID> & boundary_ids);
56 
58 
66  template <typename T>
67  const MaterialProperty<T> & getMaterialProperty(const std::string & name);
68  template <typename T>
69  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
70  template <typename T>
71  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
73 
75 
81  template <typename T>
82  const MaterialProperty<T> & getMaterialPropertyByName(const MaterialPropertyName & name);
83  template <typename T>
84  const MaterialProperty<T> & getMaterialPropertyOldByName(const MaterialPropertyName & name);
85  template <typename T>
86  const MaterialProperty<T> & getMaterialPropertyOlderByName(const MaterialPropertyName & name);
88 
99  template <typename T>
100  std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>
101  getBlockMaterialProperty(const MaterialPropertyName & name);
102 
107  template <typename T>
108  const MaterialProperty<T> & getZeroMaterialProperty(const std::string & prop_name);
109 
115  std::set<SubdomainID> getMaterialPropertyBlocks(const std::string & name);
116 
122  std::vector<SubdomainName> getMaterialPropertyBlockNames(const std::string & name);
123 
129  std::set<BoundaryID> getMaterialPropertyBoundaryIDs(const std::string & name);
130 
136  std::vector<BoundaryName> getMaterialPropertyBoundaryNames(const std::string & name);
137 
139 
147  Material & getMaterial(const std::string & name);
148  Material & getMaterialByName(const std::string & name, bool no_warn = false);
150 
152 
157  template <typename T>
158  bool hasMaterialProperty(const std::string & name);
159  template <typename T>
160  bool hasMaterialPropertyByName(const std::string & name);
162 
168  void statefulPropertiesAllowed(bool);
169 
174 
181  const std::set<unsigned int> & getMatPropDependencies() const
182  {
184  }
185 
186 protected:
189 
191  const std::string _mi_name;
192 
195 
197  std::shared_ptr<MaterialData> _material_data;
198 
201 
204 
210  void checkMaterialProperty(const std::string & name);
211 
215  void markMatPropRequested(const std::string &);
216 
220  std::string deducePropertyName(const std::string & name);
221 
226  template <typename T>
227  const MaterialProperty<T> * defaultMaterialProperty(const std::string & name);
228 
234 
241 
243  std::vector<std::unique_ptr<MaterialProperty<Real>>> _default_real_properties;
244 
246  std::set<unsigned int> _material_property_dependencies;
247 
248 private:
250  void checkExecutionStage();
251 
254 
256  const std::set<SubdomainID> & _mi_block_ids;
257 
259  const std::set<BoundaryID> & _mi_boundary_ids;
260 };
261 
267 template <typename T>
268 inline void
270 {
276  v = 0;
277 }
278 template <typename T>
279 inline void
281 {
282  mooseError("Cannot use pointer types for MaterialProperty derivatives.");
283 }
284 
285 template <typename T>
286 const MaterialProperty<T> &
288 {
289  // Check if the supplied parameter is a valid input parameter key
290  std::string prop_name = deducePropertyName(name);
291 
292  // Check if it's just a constant
293  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
294  if (default_property)
295  return *default_property;
296 
297  return getMaterialPropertyByName<T>(prop_name);
298 }
299 
300 template <typename T>
301 const MaterialProperty<T> &
303 {
304  if (!_stateful_allowed)
305  mooseError("Stateful material properties not allowed for this object."
306  " Old property for \"",
307  name,
308  "\" was requested.");
309 
310  // Check if the supplied parameter is a valid input parameter key
311  std::string prop_name = deducePropertyName(name);
312 
313  // Check if it's just a constant
314  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
315  if (default_property)
316  return *default_property;
317 
318  return getMaterialPropertyOldByName<T>(prop_name);
319 }
320 
321 template <typename T>
322 const MaterialProperty<T> &
324 {
325  if (!_stateful_allowed)
326  mooseError("Stateful material properties not allowed for this object."
327  " Older property for \"",
328  name,
329  "\" was requested.");
330 
331  // Check if the supplied parameter is a valid input parameter key
332  std::string prop_name = deducePropertyName(name);
333 
334  // Check if it's just a constant
335  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
336  if (default_property)
337  return *default_property;
338 
339  return getMaterialPropertyOlderByName<T>(prop_name);
340 }
341 
342 // General version for types that do not accept default values
343 template <typename T>
344 const MaterialProperty<T> *
346 {
347  return NULL;
348 }
349 
350 // Forward declare explicit specializations
351 template <>
354 
355 template <typename T>
356 const MaterialProperty<T> &
358 {
360  checkMaterialProperty(name);
361 
362  // mark property as requested
363  markMatPropRequested(name);
364 
365  // Update the boolean flag.
367 
368  _material_property_dependencies.insert(_material_data->getPropertyId(name));
369 
370  return _material_data->getProperty<T>(name);
371 }
372 
373 template <typename T>
374 const MaterialProperty<T> &
376 {
377  if (!_stateful_allowed)
378  mooseError("Stateful material properties not allowed for this object."
379  " Old property for \"",
380  name,
381  "\" was requested.");
382 
383  // mark property as requested
384  markMatPropRequested(name);
385 
386  _material_property_dependencies.insert(_material_data->getPropertyId(name));
387 
388  return _material_data->getPropertyOld<T>(name);
389 }
390 
391 template <typename T>
392 const MaterialProperty<T> &
394 {
395  if (!_stateful_allowed)
396  mooseError("Stateful material properties not allowed for this object."
397  " Older property for \"",
398  name,
399  "\" was requested.");
400 
401  // mark property as requested
402  markMatPropRequested(name);
403 
404  _material_property_dependencies.insert(_material_data->getPropertyId(name));
405 
406  return _material_data->getPropertyOlder<T>(name);
407 }
408 
409 template <typename T>
410 std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>
411 MaterialPropertyInterface::getBlockMaterialProperty(const MaterialPropertyName & name)
412 {
413  if (_mi_block_ids.empty())
414  mooseError("getBlockMaterialProperty must be called by a block restrictable object");
415 
416  if (!hasMaterialPropertyByName<T>(name))
417  return std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>(NULL,
418  std::set<SubdomainID>());
419 
420  _material_property_dependencies.insert(_material_data->getPropertyId(name));
421 
422  return std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>(
423  &_material_data->getProperty<T>(name), _mi_feproblem.getMaterialPropertyBlocks(name));
424 }
425 
426 template <typename T>
427 bool
429 {
430  // Check if the supplied parameter is a valid input parameter key
431  std::string prop_name = deducePropertyName(name);
432  return _material_data->haveProperty<T>(prop_name);
433 }
434 
435 template <typename T>
436 bool
438 {
439  return _material_data->haveProperty<T>(name);
440 }
441 
442 template <typename T>
443 const MaterialProperty<T> &
444 MaterialPropertyInterface::getZeroMaterialProperty(const std::string & /*prop_name*/)
445 {
446  // static zero property storage
447  static MaterialProperty<T> zero;
448 
449  // resize to accomodate maximum number of qpoints
450  // (in multiapp scenarios getMaxQps can return different values in each app; we need the max)
451  unsigned int nqp = _mi_feproblem.getMaxQps();
452  if (nqp > zero.size())
453  zero.resize(nqp);
454 
455  // set values for all qpoints to zero
456  for (unsigned int qp = 0; qp < nqp; ++qp)
457  mooseSetToZero<T>(zero[qp]);
458 
459  return zero;
460 }
461 
462 #endif // MATERIALPROPERTYINTERFACE_H
InputParameters validParams< MaterialPropertyInterface >()
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const THREAD_ID _mi_tid
Current threaded it.
const MaterialProperty< T > & getMaterialProperty(const std::string &name)
Retrieve reference to material property or one of it&#39;s old or older values.
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.
InputParameters validParams()
bool hasMaterialPropertyByName(const std::string &name)
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
std::pair< const MaterialProperty< T > *, std::set< SubdomainID > > getBlockMaterialProperty(const MaterialPropertyName &name)
Retrieve pointer to a material property with the mesh blocks where it is defined The name required by...
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.
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...
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.
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...
virtual void resize(int n)
Resizes the property to the size n.
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.
bool getMaterialPropertyCalled() const
Returns true if getMaterialProperty() has been called, false otherwise.
std::set< unsigned int > _material_property_dependencies
The set of material properties (as given by their IDs) that this object depends on.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const MaterialProperty< T > & getMaterialPropertyOlderByName(const MaterialPropertyName &name)
void markMatPropRequested(const std::string &)
A proxy method for _mi_feproblem.markMatPropRequested(name)
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.
unsigned int getMaxQps() const
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
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
MaterialPropertyInterface(const MooseObject *moose_object)
const InputParameters & _mi_params
Parameters of the object with this interface.
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Materials compute MaterialProperties.
Definition: Material.h:53
bool hasMaterialProperty(const std::string &name)
Check if the material property exists.
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:114
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
An interface for accessing Materials.
const std::set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
Concrete definition of a parameter value for a specified type.
const MaterialProperty< T > & getMaterialPropertyOldByName(const MaterialPropertyName &name)
unsigned int size() const
const MaterialProperty< T > & getMaterialPropertyByName(const MaterialPropertyName &name)
Retrieve reference to material property or its old or older value The name required by this method is...
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