www.mooseframework.org
MaterialData.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 MATERIALDATA_H
16 #define MATERIALDATA_H
17 
18 #include "Moose.h"
19 #include "MaterialProperty.h"
21 
22 // libMesh
23 #include "libmesh/elem.h"
24 
25 #include <vector>
26 
27 class Material;
28 
34 {
35 public:
37  virtual ~MaterialData();
38 
42  void release();
43 
47  void resize(unsigned int n_qpoints);
48 
53  unsigned int nQPoints();
54 
61  template <typename T>
62  MaterialProperty<T> & declareProperty(const std::string & prop_name);
63 
67  template <typename T>
68  MaterialProperty<T> & declarePropertyOld(const std::string & prop_name);
69 
73  template <typename T>
74  MaterialProperty<T> & declarePropertyOlder(const std::string & prop_name);
75 
77  void copy(const Elem & elem_to, const Elem & elem_from, unsigned int side);
78 
80  void swap(const Elem & elem, unsigned int side = 0);
81 
83  void reinit(const std::vector<std::shared_ptr<Material>> & mats);
84 
86  void reset(const std::vector<std::shared_ptr<Material>> & mats);
87 
89  void swapBack(const Elem & elem, unsigned int side = 0);
90 
92 
101 
104  template <typename T>
105  bool haveProperty(const std::string & prop_name) const;
106 
108 
114  template <typename T>
115  MaterialProperty<T> & getProperty(const std::string & prop_name);
116  template <typename T>
117  MaterialProperty<T> & getPropertyOld(const std::string & prop_name);
118  template <typename T>
119  MaterialProperty<T> & getPropertyOlder(const std::string & prop_name);
121 
125  bool isSwapped();
126 
131 
139  unsigned int getPropertyId(const std::string & prop_name) const
140  {
141  return _storage.getPropertyId(prop_name);
142  }
143 
144 protected:
147 
149  unsigned int _n_qpoints;
150 
157 
163  template <typename T>
164  void resizeProps(unsigned int size);
165 
167  bool _swapped;
168 
169 private:
170  template <typename T>
172  declareHelper(MaterialProperties & props, const std::string & prop_name, unsigned int prop_id);
173 };
174 
175 template <typename T>
176 inline bool
177 MaterialData::haveProperty(const std::string & prop_name) const
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 }
189 
190 template <typename T>
191 void
192 MaterialData::resizeProps(unsigned int size)
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 }
209 
210 template <typename T>
212 MaterialData::declareProperty(const std::string & prop_name)
213 {
214  return declareHelper<T>(_props, prop_name, _storage.addProperty(prop_name));
215 }
216 
217 template <typename T>
219 MaterialData::declarePropertyOld(const std::string & prop_name)
220 {
221  // TODO: add mooseDeprecated("'declarePropertyOld' is deprecated an no longer necessary");
222  return getPropertyOld<T>(prop_name);
223 }
224 
225 template <typename T>
227 MaterialData::declarePropertyOlder(const std::string & prop_name)
228 {
229  // TODO: add mooseDeprecated("'declarePropertyOlder' is deprecated an no longer necessary");
230  return getPropertyOlder<T>(prop_name);
231 }
232 
233 template <typename T>
236  const std::string & libmesh_dbg_var(prop_name),
237  unsigned int prop_id)
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 }
244 
245 template <typename T>
247 MaterialData::getProperty(const std::string & name)
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 }
256 
257 template <typename T>
259 MaterialData::getPropertyOld(const std::string & name)
260 {
261  return declareHelper<T>(_props_old, name, _storage.addPropertyOld(name));
262 }
263 
264 template <typename T>
266 MaterialData::getPropertyOlder(const std::string & name)
267 {
268  return declareHelper<T>(_props_older, name, _storage.addPropertyOlder(name));
269 }
270 
271 #endif /* MATERIALDATA_H */
void resizeProps(unsigned int size)
Resizes the number of properties to the specified size (including stateful old and older properties...
Definition: MaterialData.h:192
virtual ~MaterialData()
Definition: MaterialData.C:23
void release()
Calls the destroy() methods for the properties currently stored.
Definition: MaterialData.C:26
MaterialProperty< T > & getPropertyOlder(const std::string &prop_name)
Definition: MaterialData.h:266
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.
Definition: MaterialData.C:79
unsigned int addProperty(const std::string &prop_name)
The addProperty functions are idempotent - calling multiple times with the same name will provide the...
void swapBack(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
Definition: MaterialData.C:86
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:146
Container for storing material properties.
unsigned int addPropertyOld(const std::string &prop_name)
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
Stores the stateful material properties computed by materials.
MaterialProperties _props_old
Definition: MaterialData.h:154
MaterialProperties _props_older
Definition: MaterialData.h:155
MaterialProperty< T > & declareProperty(const std::string &prop_name)
Declare the Real valued property named "name".
Definition: MaterialData.h:212
unsigned int addPropertyOlder(const std::string &prop_name)
MaterialProperty< T > & declareHelper(MaterialProperties &props, const std::string &prop_name, unsigned int prop_id)
MaterialProperty< T > & declarePropertyOlder(const std::string &prop_name)
Declare the Real valued property named prop_name.
Definition: MaterialData.h:227
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:149
bool isSwapped()
Returns true if the stateful material is in a swapped state.
Definition: MaterialData.C:96
MaterialProperties & propsOld()
Definition: MaterialData.h:98
MaterialProperty< T > & declarePropertyOld(const std::string &prop_name)
Declare the Real valued property prop_name.
Definition: MaterialData.h:219
MaterialProperties & propsOlder()
Definition: MaterialData.h:99
void copy(const Elem &elem_to, const Elem &elem_from, unsigned int side)
copy material properties from one element to another
Definition: MaterialData.C:56
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...
MaterialProperties _props
Definition: MaterialData.h:153
MaterialProperty< T > & getProperty(const std::string &prop_name)
Methods for retieving a MaterialProperty object.
Definition: MaterialData.h:247
Materials compute MaterialProperties.
Definition: Material.h:53
bool hasProperty(const std::string &prop_name) const
MaterialData(MaterialPropertyStorage &storage)
Definition: MaterialData.C:18
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.h:139
const MaterialPropertyStorage & getMaterialPropertyStorage() const
Provide read-only access to the underlying MaterialPropertyStorage object.
Definition: MaterialData.h:130
void swap(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
Definition: MaterialData.C:62
PetscInt n
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:167
Concrete definition of a parameter value for a specified type.
unsigned int nQPoints()
Returns the number of quadrature points the material properties support/hold.
Definition: MaterialData.C:50
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:33
MaterialProperty< T > & getPropertyOld(const std::string &prop_name)
Definition: MaterialData.h:259
bool haveProperty(const std::string &prop_name) const
Returns true if the property exists - defined by any material (i.e.
Definition: MaterialData.h:177
MaterialProperties & props()
Methods for retrieving MaterialProperties object.
Definition: MaterialData.h:97
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
Definition: MaterialData.C:34
void reinit(const std::vector< std::shared_ptr< Material >> &mats)
Reinit material properties for given element (and possible side)
Definition: MaterialData.C:72