https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MaterialData.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
20void
21MaterialData::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
34void
35MaterialData::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
40void
41MaterialData::swap(const Elem & elem, unsigned int side /* = 0*/)
42{
44 return;
45
46 _storage.swap(_tid, elem, side);
47 _swapped = true;
48}
49
50void
51MaterialData::reset(const std::vector<std::shared_ptr<MaterialBase>> & mats)
52{
53 for (const auto & mat : mats)
54 mat->resetProperties();
55}
56
57void
58MaterialData::swapBack(const Elem & elem, unsigned int side /* = 0*/)
59{
61 {
62 _storage.swapBack(_tid, elem, side);
63 _swapped = false;
64 }
65}
66
67void
68MaterialData::mooseErrorHelper(const MooseObject & object, const std::string_view & error)
69{
70 object.mooseError(error);
71}
72
73bool
74MaterialData::hasProperty(const std::string & prop_name) const
75{
76 return _storage.hasProperty(prop_name);
77}
78
79unsigned int
80MaterialData::getPropertyId(const std::string & prop_name) const
81{
82 return _storage.getMaterialPropertyRegistry().getID(prop_name);
83}
84
85void
87{
89}
90
91unsigned int
92MaterialData::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
100const MaterialBase &
102{
103 const auto declarer = dynamic_cast<const MaterialBase *>(&requestor);
104 mooseAssert(declarer, "Not a MaterialBase");
105 return *declarer;
106}
107
108unsigned int
109MaterialData::getMaxStateRequested(const unsigned int prop_id) const
110{
111 return _storage.getPropRecord(prop_id).state;
112}
unsigned int THREAD_ID
Definition MooseTypes.h:237
MaterialBases compute MaterialProperties.
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from MaterialPropertyStorage data structures Use this...
static void mooseErrorHelper(const MooseObject &object, const std::string_view &error)
void swapBack(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
bool hasProperty(const std::string &prop_name) const
unsigned int nQPoints() const
Returns the number of quadrature points the material properties support/hold.
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
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.
const THREAD_ID _tid
The thread id.
unsigned int _n_qpoints
Number of quadrature points.
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
unsigned int getMaxStateRequested(const unsigned int prop_id) const
maximum state id requested for a property
void swap(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
const MaterialBase & castRequestorToDeclarer(const MooseObject &requestor) const
Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated)
unsigned int addPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
const MaterialProperties & props(const unsigned int state=0) const
{
void copy(const Elem &elem_to, const Elem &elem_from, unsigned int side)
copy material properties from one element to another
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false)
MaterialData(MaterialPropertyStorage &storage, const THREAD_ID tid)
bool isSwapped() const
Returns true if the stateful material is in a swapped state.
void resizeItems(const std::size_t n_qpoints, const WriteKey)
Resize items in this array, i.e.
unsigned int getID(const std::string &name) const
Stores the stateful material properties computed by materials.
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.
void swapBack(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialPropertyStorage and MaterialDat Thread safe.
void swap(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialData and MaterialPropertyStorage Thread safe.
bool hasProperty(const std::string &prop_name) const
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from internal data structures Use this when elements ...
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 MaterialPropertyRegistry & getMaterialPropertyRegistry() const
const PropRecord & getPropRecord(const unsigned int id) const
Get the property record associated with the material with id id.
libMesh::IntRange< unsigned int > stateIndexRange() const
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
unsigned int state
The max state requrested for this property (0 = current, 1 = old, ...)