www.mooseframework.org
MaterialData.C
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 #include "MaterialData.h"
11 #include "Material.h"
13 #include "MaterialBase.h"
14 
16  : _storage(storage), _tid(tid), _n_qpoints(0), _swapped(false), _resize_only_if_smaller(false)
17 {
18 }
19 
20 void
21 MaterialData::resize(unsigned int n_qpoints)
22 {
23  if (n_qpoints == nQPoints())
24  return;
25 
26  if (_resize_only_if_smaller && n_qpoints < nQPoints())
27  return;
28 
29  for (const auto state : _storage.stateIndexRange())
30  props(state).resizeItems(n_qpoints, {});
31  _n_qpoints = n_qpoints;
32 }
33 
34 void
35 MaterialData::copy(const Elem & elem_to, const Elem & elem_from, unsigned int side)
36 {
37  _storage.copy(_tid, &elem_to, &elem_from, side, nQPoints());
38 }
39 
40 void
41 MaterialData::swap(const Elem & elem, unsigned int side /* = 0*/)
42 {
44  return;
45 
46  _storage.swap(_tid, elem, side);
47  _swapped = true;
48 }
49 
50 void
51 MaterialData::reset(const std::vector<std::shared_ptr<MaterialBase>> & mats)
52 {
53  for (const auto & mat : mats)
54  mat->resetProperties();
55 }
56 
57 void
58 MaterialData::swapBack(const Elem & elem, unsigned int side /* = 0*/)
59 {
61  {
62  _storage.swapBack(_tid, elem, side);
63  _swapped = false;
64  }
65 }
66 
67 void
68 MaterialData::mooseErrorHelper(const MooseObject & object, const std::string_view & error)
69 {
70  object.mooseError(error);
71 }
72 
73 bool
74 MaterialData::hasProperty(const std::string & prop_name) const
75 {
76  return _storage.hasProperty(prop_name);
77 }
78 
79 unsigned int
80 MaterialData::getPropertyId(const std::string & prop_name) const
81 {
82  return _storage.getMaterialPropertyRegistry().getID(prop_name);
83 }
84 
85 void
86 MaterialData::eraseProperty(const Elem * elem)
87 {
88  _storage.eraseProperty(elem);
89 }
90 
91 unsigned int
92 MaterialData::addPropertyHelper(const std::string & prop_name,
93  const std::type_info & type,
94  const unsigned int state,
95  const MaterialBase * const declarer)
96 {
97  return _storage.addProperty(prop_name, type, state, declarer);
98 }
99 
100 const MaterialBase &
102 {
103  const auto declarer = dynamic_cast<const MaterialBase *>(&requestor);
104  mooseAssert(declarer, "Not a MaterialBase");
105  return *declarer;
106 }
107 
108 unsigned int
109 MaterialData::getMaxStateRequested(const unsigned int prop_id) const
110 {
111  return _storage.getPropRecord(prop_id).state;
112 }
bool isSwapped() const
Returns true if the stateful material is in a swapped state.
Definition: MaterialData.h:135
bool hasProperty(const std::string &prop_name) const
Definition: MaterialData.C:74
const MaterialBase & castRequestorToDeclarer(const MooseObject &requestor) const
Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated) ...
Definition: MaterialData.C:101
void swapBack(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
Definition: MaterialData.C:58
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from internal data structures Use this when elements ...
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:198
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:231
Stores the stateful material properties computed by materials.
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.C:80
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
IntRange< unsigned int > stateIndexRange() const
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from MaterialPropertyStorage data structures Use this...
Definition: MaterialData.C:86
MaterialData(MaterialPropertyStorage &storage, const THREAD_ID tid)
Definition: MaterialData.C:15
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:204
unsigned int addPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
Definition: MaterialData.C:92
void resizeItems(const std::size_t n_qpoints, const WriteKey)
Resize items in this array, i.e.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
void swapBack(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialPropertyStorage and MaterialDat Thread safe...
void copy(const Elem &elem_to, const Elem &elem_from, unsigned int side)
copy material properties from one element to another
Definition: MaterialData.C:35
unsigned int addProperty(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
Adds a property with the name prop_name, type type, and state state (0 = current, 1 = old...
const MaterialProperties & props(const unsigned int state=0) const
Definition: MaterialData.h:238
unsigned int state
The max state requrested for this property (0 = current, 1 = old, ...)
unsigned int getMaxStateRequested(const unsigned int prop_id) const
maximum state id requested for a property
Definition: MaterialData.C:109
void reset(const std::vector< std::shared_ptr< MaterialBase >> &mats)
Calls the reset method of Materials to ensure that they are in a proper state.
Definition: MaterialData.C:51
void swap(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
Definition: MaterialData.C:41
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:227
bool hasProperty(const std::string &prop_name) const
unsigned int getID(const std::string &name) const
static void mooseErrorHelper(const MooseObject &object, const std::string_view &error)
Definition: MaterialData.C:68
unsigned int nQPoints() const
Returns the number of quadrature points the material properties support/hold.
Definition: MaterialData.h:50
void swap(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialData and MaterialPropertyStorage Thread safe...
void copy(const THREAD_ID tid, 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 PropRecord & getPropRecord(const unsigned int id) const
Get the property record associated with the material with id id.
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:60
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
Definition: MaterialData.C:21
unsigned int THREAD_ID
Definition: MooseTypes.h:198
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:201