www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
MaterialData Class Reference

Proxy for accessing MaterialPropertyStorage. More...

#include <MaterialData.h>

Public Member Functions

 MaterialData (MaterialPropertyStorage &storage)
 
virtual ~MaterialData ()
 
void release ()
 Calls the destroy() methods for the properties currently stored. More...
 
void resize (unsigned int n_qpoints)
 Resize the data to hold properties for n_qpoints quadrature points. More...
 
unsigned int nQPoints ()
 Returns the number of quadrature points the material properties support/hold. More...
 
template<typename T >
MaterialProperty< T > & declareProperty (const std::string &prop_name)
 Declare the Real valued property named "name". More...
 
template<typename T >
MaterialProperty< T > & declarePropertyOld (const std::string &prop_name)
 Declare the Real valued property prop_name. More...
 
template<typename T >
MaterialProperty< T > & declarePropertyOlder (const std::string &prop_name)
 Declare the Real valued property named prop_name. More...
 
void copy (const Elem &elem_to, const Elem &elem_from, unsigned int side)
 copy material properties from one element to another More...
 
void swap (const Elem &elem, unsigned int side=0)
 material properties for given element (and possible side) More...
 
void reinit (const std::vector< std::shared_ptr< Material >> &mats)
 Reinit material properties for given element (and possible side) More...
 
void reset (const std::vector< std::shared_ptr< Material >> &mats)
 Calls the reset method of Materials to ensure that they are in a proper state. More...
 
void swapBack (const Elem &elem, unsigned int side=0)
 material properties for given element (and possible side) More...
 
template<typename T >
bool haveProperty (const std::string &prop_name) const
 Returns true if the property exists - defined by any material (i.e. More...
 
bool isSwapped ()
 Returns true if the stateful material is in a swapped state. More...
 
const MaterialPropertyStoragegetMaterialPropertyStorage () const
 Provide read-only access to the underlying MaterialPropertyStorage object. More...
 
unsigned int getPropertyId (const std::string &prop_name) const
 Wrapper for MaterialStorage::getPropertyId. More...
 
template<typename T >
MaterialProperty< T > & declareHelper (MaterialProperties &props, const std::string &libmesh_dbg_var(prop_name), unsigned int prop_id)
 
MaterialPropertiesprops ()
 Methods for retrieving MaterialProperties object. More...
 
MaterialPropertiespropsOld ()
 
MaterialPropertiespropsOlder ()
 
template<typename T >
MaterialProperty< T > & getProperty (const std::string &prop_name)
 Methods for retieving a MaterialProperty object. More...
 
template<typename T >
MaterialProperty< T > & getPropertyOld (const std::string &prop_name)
 
template<typename T >
MaterialProperty< T > & getPropertyOlder (const std::string &prop_name)
 

Protected Member Functions

template<typename T >
void resizeProps (unsigned int size)
 Resizes the number of properties to the specified size (including stateful old and older properties. More...
 

Protected Attributes

MaterialPropertyStorage_storage
 Reference to the MaterialStorage class. More...
 
unsigned int _n_qpoints
 Number of quadrature points. More...
 
bool _swapped
 Status of storage swapping (calling swap sets this to true; swapBack sets it to false) More...
 
MaterialProperties _props
 
MaterialProperties _props_old
 
MaterialProperties _props_older
 

Private Member Functions

template<typename T >
MaterialProperty< T > & declareHelper (MaterialProperties &props, const std::string &prop_name, unsigned int prop_id)
 

Detailed Description

Proxy for accessing MaterialPropertyStorage.

MaterialData stores the values associated with a particular material object

Definition at line 33 of file MaterialData.h.

Constructor & Destructor Documentation

MaterialData::MaterialData ( MaterialPropertyStorage storage)

Definition at line 18 of file MaterialData.C.

19  : _storage(storage), _n_qpoints(0), _swapped(false)
20 {
21 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:149
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:167
MaterialData::~MaterialData ( )
virtual

Definition at line 23 of file MaterialData.C.

23 { release(); }
void release()
Calls the destroy() methods for the properties currently stored.
Definition: MaterialData.C:26

Member Function Documentation

void MaterialData::copy ( const Elem &  elem_to,
const Elem &  elem_from,
unsigned int  side 
)

copy material properties from one element to another

Definition at line 56 of file MaterialData.C.

57 {
58  _storage.copy(*this, elem_to, elem_from, side, _n_qpoints);
59 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
void copy(MaterialData &material_data, const Elem &elem_to, const Elem &elem_from, unsigned int side, unsigned int n_qpoints)
Copy material properties from elem_from to elem_to.
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:149
template<typename T >
MaterialProperty<T>& MaterialData::declareHelper ( MaterialProperties props,
const std::string &  prop_name,
unsigned int  prop_id 
)
private
template<typename T >
MaterialProperty<T>& MaterialData::declareHelper ( MaterialProperties props,
const std::string &  libmesh_dbg_varprop_name,
unsigned int  prop_id 
)

Definition at line 235 of file MaterialData.h.

238 {
239  resizeProps<T>(prop_id);
240  auto prop = dynamic_cast<MaterialProperty<T> *>(props[prop_id]);
241  mooseAssert(prop != nullptr, "Internal error in declaring material property: " + prop_name);
242  return *prop;
243 }
Concrete definition of a parameter value for a specified type.
template<typename T >
MaterialProperty< T > & MaterialData::declareProperty ( const std::string &  prop_name)

Declare the Real valued property named "name".

Calling any of the declareProperty functions multiple times with the same property name is okay and will result in a single identical reference returned every time.

Definition at line 212 of file MaterialData.h.

213 {
214  return declareHelper<T>(_props, prop_name, _storage.addProperty(prop_name));
215 }
unsigned int addProperty(const std::string &prop_name)
The addProperty functions are idempotent - calling multiple times with the same name will provide the...
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
MaterialProperties _props
Definition: MaterialData.h:153
template<typename T >
MaterialProperty< T > & MaterialData::declarePropertyOld ( const std::string &  prop_name)

Declare the Real valued property prop_name.

Definition at line 219 of file MaterialData.h.

220 {
221  // TODO: add mooseDeprecated("'declarePropertyOld' is deprecated an no longer necessary");
222  return getPropertyOld<T>(prop_name);
223 }
template<typename T >
MaterialProperty< T > & MaterialData::declarePropertyOlder ( const std::string &  prop_name)

Declare the Real valued property named prop_name.

Definition at line 227 of file MaterialData.h.

228 {
229  // TODO: add mooseDeprecated("'declarePropertyOlder' is deprecated an no longer necessary");
230  return getPropertyOlder<T>(prop_name);
231 }
const MaterialPropertyStorage& MaterialData::getMaterialPropertyStorage ( ) const
inline

Provide read-only access to the underlying MaterialPropertyStorage object.

Definition at line 130 of file MaterialData.h.

130 { return _storage; }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
template<typename T >
MaterialProperty< T > & MaterialData::getProperty ( const std::string &  prop_name)

Methods for retieving a MaterialProperty object.

Template Parameters
TThe type of the property
Parameters
prop_nameThe name of the property
Returns
The property for the supplied type and name

Definition at line 247 of file MaterialData.h.

Referenced by propsOlder().

248 {
249  auto prop_id = getPropertyId(name);
250  resizeProps<T>(prop_id);
251  auto prop = dynamic_cast<MaterialProperty<T> *>(_props[prop_id]);
252  if (!prop)
253  mooseError("Material has no property named: " + name);
254  return *prop;
255 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MaterialProperties _props
Definition: MaterialData.h:153
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.h:139
Concrete definition of a parameter value for a specified type.
unsigned int MaterialData::getPropertyId ( const std::string &  prop_name) const
inline

Wrapper for MaterialStorage::getPropertyId.

Allows classes with a MaterialData object (i.e. MaterialPropertyInterface) to access material property IDs.

Parameters
prop_nameThe name of the material property
Returns
An unsigned int corresponding to the property ID of the passed in prop_name

Definition at line 139 of file MaterialData.h.

Referenced by getProperty(), and haveProperty().

140  {
141  return _storage.getPropertyId(prop_name);
142  }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
unsigned int getPropertyId(const std::string &prop_name)
Returns the property ID for the given prop_name, adding the property and creating a new ID if it hasn...
template<typename T >
MaterialProperty< T > & MaterialData::getPropertyOld ( const std::string &  prop_name)

Definition at line 259 of file MaterialData.h.

Referenced by propsOlder().

260 {
261  return declareHelper<T>(_props_old, name, _storage.addPropertyOld(name));
262 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
unsigned int addPropertyOld(const std::string &prop_name)
MaterialProperties _props_old
Definition: MaterialData.h:154
template<typename T >
MaterialProperty< T > & MaterialData::getPropertyOlder ( const std::string &  prop_name)

Definition at line 266 of file MaterialData.h.

Referenced by propsOlder().

267 {
268  return declareHelper<T>(_props_older, name, _storage.addPropertyOlder(name));
269 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
MaterialProperties _props_older
Definition: MaterialData.h:155
unsigned int addPropertyOlder(const std::string &prop_name)
template<typename T >
bool MaterialData::haveProperty ( const std::string &  prop_name) const
inline

Returns true if the property exists - defined by any material (i.e.

not necessarily just this one).

Definition at line 177 of file MaterialData.h.

Referenced by propsOlder().

178 {
179  if (!_storage.hasProperty(prop_name))
180  return false;
181 
182  unsigned int prop_id = getPropertyId(prop_name);
183  if (prop_id >= _props.size())
184  return false; // the property id exists, but the property was not created in this instance of
185  // the material type
186 
187  return dynamic_cast<const MaterialProperty<T> *>(_props[prop_id]) != nullptr;
188 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
MaterialProperties _props
Definition: MaterialData.h:153
bool hasProperty(const std::string &prop_name) const
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.h:139
Concrete definition of a parameter value for a specified type.
bool MaterialData::isSwapped ( )

Returns true if the stateful material is in a swapped state.

Definition at line 96 of file MaterialData.C.

Referenced by propsOlder().

97 {
98  return _swapped;
99 }
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:167
unsigned int MaterialData::nQPoints ( )

Returns the number of quadrature points the material properties support/hold.

Definition at line 50 of file MaterialData.C.

51 {
52  return _n_qpoints;
53 }
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:149
MaterialProperties& MaterialData::props ( )
inline

Methods for retrieving MaterialProperties object.

These functions should NEVER be used to modify the sizes of the MaterialProperties objects.

Definition at line 97 of file MaterialData.h.

Referenced by MaterialPropertyStorage::initProps(), MaterialPropertyStorage::swap(), and MaterialPropertyStorage::swapBack().

97 { return _props; }
MaterialProperties _props
Definition: MaterialData.h:153
MaterialProperties& MaterialData::propsOld ( )
inline
MaterialProperties& MaterialData::propsOlder ( )
inline
void MaterialData::reinit ( const std::vector< std::shared_ptr< Material >> &  mats)

Reinit material properties for given element (and possible side)

Definition at line 72 of file MaterialData.C.

73 {
74  for (const auto & mat : mats)
75  mat->computeProperties();
76 }
void MaterialData::release ( )

Calls the destroy() methods for the properties currently stored.

Definition at line 26 of file MaterialData.C.

Referenced by ~MaterialData().

27 {
28  _props.destroy();
31 }
MaterialProperties _props_old
Definition: MaterialData.h:154
MaterialProperties _props_older
Definition: MaterialData.h:155
MaterialProperties _props
Definition: MaterialData.h:153
void destroy()
Deallocates the memory.
void MaterialData::reset ( const std::vector< std::shared_ptr< Material >> &  mats)

Calls the reset method of Materials to ensure that they are in a proper state.

Definition at line 79 of file MaterialData.C.

80 {
81  for (const auto & mat : mats)
82  mat->resetProperties();
83 }
void MaterialData::resize ( unsigned int  n_qpoints)

Resize the data to hold properties for n_qpoints quadrature points.

Definition at line 34 of file MaterialData.C.

Referenced by MaterialPropertyStorage::initProps(), and MaterialPropertyStorage::prolongStatefulProps().

35 {
36  if (n_qpoints == _n_qpoints)
37  return;
38 
39  _props.resizeItems(n_qpoints);
40  // if there are stateful material properties in the system, also resize
41  // storage for old and older material properties
43  _props_old.resizeItems(n_qpoints);
45  _props_older.resizeItems(n_qpoints);
46  _n_qpoints = n_qpoints;
47 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
MaterialProperties _props_old
Definition: MaterialData.h:154
MaterialProperties _props_older
Definition: MaterialData.h:155
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:149
void resizeItems(unsigned int n_qpoints)
Resize items in this array, i.e.
MaterialProperties _props
Definition: MaterialData.h:153
template<typename T >
void MaterialData::resizeProps ( unsigned int  size)
protected

Resizes the number of properties to the specified size (including stateful old and older properties.

Newly added elements are set to default-constructed material properties.

Definition at line 192 of file MaterialData.h.

193 {
194  auto n = size + 1;
195  if (_props.size() < n)
196  _props.resize(n, nullptr);
197  if (_props_old.size() < n)
198  _props_old.resize(n, nullptr);
199  if (_props_older.size() < n)
200  _props_older.resize(n, nullptr);
201 
202  if (_props[size] == nullptr)
203  _props[size] = new MaterialProperty<T>;
204  if (_props_old[size] == nullptr)
205  _props_old[size] = new MaterialProperty<T>;
206  if (_props_older[size] == nullptr)
207  _props_older[size] = new MaterialProperty<T>;
208 }
MaterialProperties _props_old
Definition: MaterialData.h:154
MaterialProperties _props_older
Definition: MaterialData.h:155
MaterialProperties _props
Definition: MaterialData.h:153
PetscInt n
Concrete definition of a parameter value for a specified type.
void MaterialData::swap ( const Elem &  elem,
unsigned int  side = 0 
)

material properties for given element (and possible side)

Definition at line 62 of file MaterialData.C.

63 {
65  return;
66 
67  _storage.swap(*this, elem, side);
68  _swapped = true;
69 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
void swap(MaterialData &material_data, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialData and MaterialPropertyStorage Thread safe...
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:167
void MaterialData::swapBack ( const Elem &  elem,
unsigned int  side = 0 
)

material properties for given element (and possible side)

Definition at line 86 of file MaterialData.C.

87 {
89  {
90  _storage.swapBack(*this, elem, side);
91  _swapped = false;
92  }
93 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
void swapBack(MaterialData &material_data, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialPropertyStorage and MaterialDat Thread safe...
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:167

Member Data Documentation

unsigned int MaterialData::_n_qpoints
protected

Number of quadrature points.

Definition at line 149 of file MaterialData.h.

Referenced by copy(), nQPoints(), and resize().

MaterialProperties MaterialData::_props
protected

Holds material properties for currently selected element (and possibly a side), they are being copied from _storage

Definition at line 153 of file MaterialData.h.

Referenced by declareProperty(), getProperty(), haveProperty(), props(), release(), resize(), and resizeProps().

MaterialProperties MaterialData::_props_old
protected

Definition at line 154 of file MaterialData.h.

Referenced by getPropertyOld(), propsOld(), release(), resize(), and resizeProps().

MaterialProperties MaterialData::_props_older
protected

Definition at line 155 of file MaterialData.h.

Referenced by getPropertyOlder(), propsOlder(), release(), resize(), and resizeProps().

MaterialPropertyStorage& MaterialData::_storage
protected

Reference to the MaterialStorage class.

Definition at line 146 of file MaterialData.h.

Referenced by copy(), declareProperty(), getMaterialPropertyStorage(), getPropertyId(), getPropertyOld(), getPropertyOlder(), haveProperty(), resize(), swap(), and swapBack().

bool MaterialData::_swapped
protected

Status of storage swapping (calling swap sets this to true; swapBack sets it to false)

Definition at line 167 of file MaterialData.h.

Referenced by isSwapped(), swap(), and swapBack().


The documentation for this class was generated from the following files: