www.mooseframework.org
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
MaterialProperty< T > Class Template Reference

Concrete definition of a parameter value for a specified type. More...

#include <DerivativeMaterialInterface.h>

Inheritance diagram for MaterialProperty< T >:
[legend]

Public Member Functions

 MaterialProperty (bool use_ad=false)
 Explicitly declare a public constructor because we made the copy constructor private. More...
 
virtual ~MaterialProperty ()
 
const std::vector< MooseADWrapper< T > > & get () const
 
std::vector< MooseADWrapper< T > > & set ()
 
virtual std::string type () override
 String identifying the type of parameter stored. More...
 
virtual PropertyValueinit (int size) override
 Clone this value. More...
 
virtual void resize (int n) override
 Resizes the property to the size n. More...
 
virtual unsigned int size () const override
 
T & operator[] (const unsigned int i)
 Get element i out of the array as a writeable reference. More...
 
const T & operator[] (const unsigned int i) const
 Get element i out of the array as a ready-only reference. More...
 
virtual void swap (PropertyValue *rhs) override
 
virtual void qpCopy (const unsigned int to_qp, PropertyValue *rhs, const unsigned int from_qp) override
 Copy the value of a Property from one specific to a specific qp in this Property. More...
 
virtual void store (std::ostream &stream) override
 Store the property into a binary stream. More...
 
virtual void load (std::istream &stream) override
 Load the property from a binary stream. More...
 
void copyDualNumberToValue (const unsigned int i) override
 copy the value portion (not the derivatives) of the DualNumber<Real> version of the material property to the Real version for the specified quadrature point More...
 
void markAD (bool use_ad) override
 Mark whether this property is in AD mode. This method is necessary for switching the state after swapping material properties during stateful material calculations. More...
 

Protected Attributes

bool _use_ad
 Whether this property was declared as AD. More...
 
std::vector< MooseADWrapper< T > > _value
 Stored parameter value. More...
 

Private Member Functions

 MaterialProperty (const MaterialProperty< T > &)
 private copy constructor to avoid shallow copying of material properties More...
 
MaterialProperty< T > & operator= (const MaterialProperty< T > &)
 private assignment operator to avoid shallow copying of material properties More...
 

Detailed Description

template<typename T>
class MaterialProperty< T >

Concrete definition of a parameter value for a specified type.

Definition at line 25 of file DerivativeMaterialInterface.h.

Constructor & Destructor Documentation

◆ MaterialProperty() [1/2]

template<typename T>
MaterialProperty< T >::MaterialProperty ( bool  use_ad = false)
inline

Explicitly declare a public constructor because we made the copy constructor private.

Definition at line 105 of file MaterialProperty.h.

105  : PropertyValue(), _use_ad(use_ad)
106  { /* */
107  }

◆ ~MaterialProperty()

template<typename T>
virtual MaterialProperty< T >::~MaterialProperty ( )
inlinevirtual

Definition at line 109 of file MaterialProperty.h.

109 {}

◆ MaterialProperty() [2/2]

template<typename T>
MaterialProperty< T >::MaterialProperty ( const MaterialProperty< T > &  )
inlineprivate

private copy constructor to avoid shallow copying of material properties

Definition at line 183 of file MaterialProperty.h.

184  {
185  mooseError("Material properties must be assigned to references (missing '&')");
186  }

Member Function Documentation

◆ copyDualNumberToValue()

template<typename T>
void MaterialProperty< T >::copyDualNumberToValue ( const unsigned int  i)
inlineoverridevirtual

copy the value portion (not the derivatives) of the DualNumber<Real> version of the material property to the Real version for the specified quadrature point

Implements PropertyValue.

Definition at line 177 of file MaterialProperty.h.

177 { _value[i].synchronizeToVal(); }

◆ get()

template<typename T>
const std::vector<MooseADWrapper<T> >& MaterialProperty< T >::get ( ) const
inline
Returns
a read-only reference to the parameter value.

Definition at line 114 of file MaterialProperty.h.

114 { return _value; }

◆ init()

template<typename T >
PropertyValue * MaterialProperty< T >::init ( int  size)
inlineoverridevirtual

Clone this value.

Useful in copy-construction.

Implements PropertyValue.

Definition at line 220 of file MaterialProperty.h.

221 {
222  return _init_helper(size, this, static_cast<T *>(0), _use_ad);
223 }

◆ load()

template<typename T >
void MaterialProperty< T >::load ( std::istream &  stream)
inlineoverridevirtual

Load the property from a binary stream.

Implements PropertyValue.

Definition at line 265 of file MaterialProperty.h.

266 {
267  for (unsigned int i = 0; i < size(); i++)
268  loadHelper(stream, _value[i], NULL);
269 }

◆ markAD()

template<typename T >
void MaterialProperty< T >::markAD ( bool  use_ad)
inlineoverridevirtual

Mark whether this property is in AD mode. This method is necessary for switching the state after swapping material properties during stateful material calculations.

Implements PropertyValue.

Definition at line 206 of file MaterialProperty.h.

207 {
208  _use_ad = use_ad;
209 }

◆ operator=()

template<typename T>
MaterialProperty<T>& MaterialProperty< T >::operator= ( const MaterialProperty< T > &  )
inlineprivate

private assignment operator to avoid shallow copying of material properties

Definition at line 189 of file MaterialProperty.h.

190  {
191  mooseError("Material properties must be assigned to references (missing '&')");
192  }

◆ operator[]() [1/2]

template<typename T>
T& MaterialProperty< T >::operator[] ( const unsigned int  i)
inline

Get element i out of the array as a writeable reference.

Definition at line 141 of file MaterialProperty.h.

141 { return _value[i].value(); }

◆ operator[]() [2/2]

template<typename T>
const T& MaterialProperty< T >::operator[] ( const unsigned int  i) const
inline

Get element i out of the array as a ready-only reference.

Definition at line 146 of file MaterialProperty.h.

146 { return _value[i].value(); }

◆ qpCopy()

template<typename T >
void MaterialProperty< T >::qpCopy ( const unsigned int  to_qp,
PropertyValue rhs,
const unsigned int  from_qp 
)
inlineoverridevirtual

Copy the value of a Property from one specific to a specific qp in this Property.

Parameters
to_qpThe quadrature point in this Property that you want to copy to.
rhsThe Property you want to copy from.
from_qpThe quadrature point in rhs you want to copy from.

Implements PropertyValue.

Definition at line 247 of file MaterialProperty.h.

250 {
251  mooseAssert(rhs != NULL, "Assigning NULL?");
252  _value[to_qp] = cast_ptr<const MaterialProperty<T> *>(rhs)->_value[from_qp];
253 }

◆ resize()

template<typename T >
void MaterialProperty< T >::resize ( int  n)
inlineoverridevirtual

Resizes the property to the size n.

Implements PropertyValue.

Definition at line 227 of file MaterialProperty.h.

228 {
229  auto diff = n - static_cast<int>(_value.size());
230  if (diff < 0)
231  _value.erase(_value.end() + diff, _value.end());
232  else
233  for (decltype(diff) i = 0; i < diff; ++i)
234  _value.emplace_back(MooseADWrapper<T>());
235 }

Referenced by _init_helper(), MaterialPropertyInterface::getZeroMaterialProperty(), and MaterialBase::getZeroMaterialProperty().

◆ set()

template<typename T>
std::vector<MooseADWrapper<T> >& MaterialProperty< T >::set ( )
inline
Returns
a writable reference to the parameter value.

Definition at line 119 of file MaterialProperty.h.

119 { return _value; }

◆ size()

template<typename T>
virtual unsigned int MaterialProperty< T >::size ( ) const
inlineoverridevirtual

◆ store()

template<typename T >
void MaterialProperty< T >::store ( std::ostream &  stream)
inlineoverridevirtual

Store the property into a binary stream.

Implements PropertyValue.

Definition at line 257 of file MaterialProperty.h.

258 {
259  for (unsigned int i = 0; i < size(); i++)
260  storeHelper(stream, _value[i], NULL);
261 }

◆ swap()

template<typename T >
void MaterialProperty< T >::swap ( PropertyValue rhs)
inlineoverridevirtual

Implements PropertyValue.

Definition at line 239 of file MaterialProperty.h.

240 {
241  mooseAssert(rhs != NULL, "Assigning NULL?");
242  _value.swap(cast_ptr<MaterialProperty<T> *>(rhs)->_value);
243 }

◆ type()

template<typename T >
std::string MaterialProperty< T >::type ( )
inlineoverridevirtual

String identifying the type of parameter stored.

Implements PropertyValue.

Definition at line 213 of file MaterialProperty.h.

214 {
215  return typeid(T).name();
216 }

Member Data Documentation

◆ _use_ad

template<typename T>
bool MaterialProperty< T >::_use_ad
protected

Whether this property was declared as AD.

Definition at line 196 of file MaterialProperty.h.

◆ _value

template<typename T>
std::vector<MooseADWrapper<T> > MaterialProperty< T >::_value
protected

The documentation for this class was generated from the following files:
MaterialProperty::size
virtual unsigned int size() const override
Definition: MaterialProperty.h:136
loadHelper
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:798
MooseADWrapper
Definition: MooseADWrapper.h:28
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
PropertyValue
Abstract definition of a property value.
Definition: MaterialProperty.h:34
_init_helper
PropertyValue * _init_helper(int size, PropertyValue *prop, const P *the_type, bool use_ad)
Scalar Init helper routine so that specialization isn't needed for basic scalar MaterialProperty type...
Definition: MaterialProperty.h:358
MaterialProperty
Concrete definition of a parameter value for a specified type.
Definition: DerivativeMaterialInterface.h:25
storeHelper
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:734
MaterialProperty::_use_ad
bool _use_ad
Whether this property was declared as AD.
Definition: MaterialProperty.h:196
MaterialProperty::_value
std::vector< MooseADWrapper< T > > _value
Stored parameter value.
Definition: MaterialProperty.h:198
n
PetscInt n
Definition: PetscDMMoose.C:1504