www.mooseframework.org
MaterialPropertyStorage.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "Moose.h"
13 #include "HashMap.h"
14 #include "DataIO.h"
15 #include "MaterialProperty.h"
16 
17 // Forward declarations
18 class Material;
19 class MaterialData;
20 class QpMap;
21 
22 // libMesh forward declarations
23 namespace libMesh
24 {
25 class QBase;
26 class Elem;
27 }
28 
35 {
36 public:
38  virtual ~MaterialPropertyStorage();
39 
40  void releaseProperties();
41 
78  void prolongStatefulProps(const std::vector<std::vector<QpMap>> & refinement_map,
79  const QBase & qrule,
80  const QBase & qrule_face,
81  MaterialPropertyStorage & parent_material_props,
82  MaterialData & child_material_data,
83  const Elem & elem,
84  const int input_parent_side,
85  const int input_child,
86  const int input_child_side);
87 
100  void restrictStatefulProps(const std::vector<std::pair<unsigned int, QpMap>> & coarsening_map,
101  const std::vector<const Elem *> & coarsened_element_children,
102  const QBase & qrule,
103  const QBase & qrule_face,
104  MaterialData & material_data,
105  const Elem & elem,
106  int input_side = -1);
107 
116  void initStatefulProps(MaterialData & material_data,
117  const std::vector<std::shared_ptr<Material>> & mats,
118  unsigned int n_qpoints,
119  const Elem & elem,
120  unsigned int side = 0);
121 
129  void shift(const FEProblemBase & fe_problem);
130 
144  void copy(MaterialData & material_data,
145  const Elem & elem_to,
146  const Elem & elem_from,
147  unsigned int side,
148  unsigned int n_qpoints);
149 
157  void swap(MaterialData & material_data, const Elem & elem, unsigned int side);
158 
166  void swapBack(MaterialData & material_data, const Elem & elem, unsigned int side);
167 
172 
176  bool hasOlderProperties() const { return _has_older_prop; }
177 
179 
184  {
185  return *_props_elem;
186  }
188  {
189  return *_props_elem_old;
190  }
192  {
193  return *_props_elem_older;
194  }
196  {
197  return *_props_elem;
198  }
200  {
201  return *_props_elem_old;
202  }
204  {
205  return *_props_elem_older;
206  }
207  MaterialProperties & props(const Elem * elem, unsigned int side)
208  {
209  return (*_props_elem)[elem][side];
210  }
211  MaterialProperties & propsOld(const Elem * elem, unsigned int side)
212  {
213  return (*_props_elem_old)[elem][side];
214  }
215  MaterialProperties & propsOlder(const Elem * elem, unsigned int side)
216  {
217  return (*_props_elem_older)[elem][side];
218  }
220 
221  bool hasProperty(const std::string & prop_name) const;
222 
225  unsigned int addProperty(const std::string & prop_name);
226  unsigned int addPropertyOld(const std::string & prop_name);
227  unsigned int addPropertyOlder(const std::string & prop_name);
228 
229  std::vector<unsigned int> & statefulProps() { return _stateful_prop_id_to_prop_id; }
230  const std::map<unsigned int, std::string> statefulPropNames() const { return _prop_names; }
231 
234  unsigned int getPropertyId(const std::string & prop_name);
235 
236  unsigned int retrievePropertyId(const std::string & prop_name) const;
237 
238  bool isStatefulProp(const std::string & prop_name) const
239  {
240  return _prop_names.count(retrievePropertyId(prop_name)) > 0;
241  }
242 
243 protected:
244  // indexing: [element][side]->material_properties
245  std::unique_ptr<HashMap<const Elem *, HashMap<unsigned int, MaterialProperties>>> _props_elem;
246  std::unique_ptr<HashMap<const Elem *, HashMap<unsigned int, MaterialProperties>>> _props_elem_old;
247  std::unique_ptr<HashMap<const Elem *, HashMap<unsigned int, MaterialProperties>>>
249 
253  static std::map<std::string, unsigned int> _prop_ids;
254 
260 
266 
268  std::map<unsigned int, std::string> _prop_names;
270  std::vector<unsigned int> _stateful_prop_id_to_prop_id;
271 
272  void sizeProps(MaterialProperties & mp, unsigned int size);
273 
274 private:
277  void initProps(MaterialData & material_data,
278  const Elem & elem,
279  unsigned int side,
280  unsigned int n_qpoints);
281 };
282 
283 template <>
284 inline void
285 dataStore(std::ostream & stream, MaterialPropertyStorage & storage, void * context)
286 {
287  dataStore(stream, storage.props(), context);
288  dataStore(stream, storage.propsOld(), context);
289 
290  if (storage.hasOlderProperties())
291  dataStore(stream, storage.propsOlder(), context);
292 }
293 
294 template <>
295 inline void
296 dataLoad(std::istream & stream, MaterialPropertyStorage & storage, void * context)
297 {
298  dataLoad(stream, storage.props(), context);
299  dataLoad(stream, storage.propsOld(), context);
300 
301  if (storage.hasOlderProperties())
302  dataLoad(stream, storage.propsOlder(), context);
303 }
304 
std::unique_ptr< HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > > _props_elem
void prolongStatefulProps(const std::vector< std::vector< QpMap >> &refinement_map, const QBase &qrule, const QBase &qrule_face, MaterialPropertyStorage &parent_material_props, MaterialData &child_material_data, const Elem &elem, const int input_parent_side, const int input_child, const int input_child_side)
Creates storage for newly created elements from mesh Adaptivity.
bool _has_stateful_props
Whether or not we have stateful properties.
MaterialProperties & propsOld(const Elem *elem, unsigned int side)
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Definition: HashMap.h:18
unsigned int addProperty(const std::string &prop_name)
The addProperty functions are idempotent - calling multiple times with the same name will provide the...
void initStatefulProps(MaterialData &material_data, const std::vector< std::shared_ptr< Material >> &mats, unsigned int n_qpoints, const Elem &elem, unsigned int side=0)
Initialize stateful material properties.
Container for storing material properties.
unsigned int addPropertyOld(const std::string &prop_name)
HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & propsOld()
Stores the stateful material properties computed by materials.
std::vector< unsigned int > _stateful_prop_id_to_prop_id
the vector of stateful property ids (the vector index is the map to stateful prop_id) ...
Helper object for holding qp mapping info.
Definition: MooseMesh.h:55
void sizeProps(MaterialProperties &mp, unsigned int size)
MaterialProperties & props(const Elem *elem, unsigned int side)
unsigned int addPropertyOlder(const std::string &prop_name)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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.
const HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & propsOlder() const
void dataStore(std::ostream &stream, MaterialPropertyStorage &storage, void *context)
MaterialProperties & propsOlder(const Elem *elem, unsigned int side)
const std::map< unsigned int, std::string > statefulPropNames() const
std::unique_ptr< HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > > _props_elem_old
void shift(const FEProblemBase &fe_problem)
Shift the material properties in time.
void initProps(MaterialData &material_data, const Elem &elem, unsigned int side, unsigned int n_qpoints)
Initializes hashmap entries for element and side to proper qpoint and property count sizes...
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...
HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & propsOlder()
void swap(MaterialData &material_data, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialData and MaterialPropertyStorage Thread safe...
static std::map< std::string, unsigned int > _prop_ids
mapping from property name to property ID NOTE: this is static so the property numbering is global wi...
std::map< unsigned int, std::string > _prop_names
mapping from property ID to property name
const HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & propsOld() const
Materials compute MaterialProperties.
Definition: Material.h:46
void swapBack(MaterialData &material_data, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialPropertyStorage and MaterialDat Thread safe...
unsigned int retrievePropertyId(const std::string &prop_name) const
HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & props()
Access methods to the stored material property data.
bool hasProperty(const std::string &prop_name) const
bool _has_older_prop
True if any material requires older properties to be computed.
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:27
void restrictStatefulProps(const std::vector< std::pair< unsigned int, QpMap >> &coarsening_map, const std::vector< const Elem *> &coarsened_element_children, const QBase &qrule, const QBase &qrule_face, MaterialData &material_data, const Elem &elem, int input_side=-1)
Creates storage for newly created elements from mesh Adaptivity.
const HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > & props() const
std::unique_ptr< HashMap< const Elem *, HashMap< unsigned int, MaterialProperties > > > _props_elem_older
std::vector< unsigned int > & statefulProps()
bool isStatefulProp(const std::string &prop_name) const
void dataLoad(std::istream &stream, MaterialPropertyStorage &storage, void *context)