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

#include <DerivativeMaterialInterface.h>

Inheritance diagram for MaterialProperty< T >:
[legend]

Public Types

typedef MooseADWrapper< T, is_ad > value_type
 
typedef unsigned int id_type
 The type for a material property ID. More...
 

Public Member Functions

 MaterialProperty (const PropertyValue::id_type id=PropertyValue::invalid_property_id)
 
bool isAD () const override final
 
const MooseArray< MooseADWrapper< T, is_ad > > & get () const
 
MooseArray< MooseADWrapper< T, is_ad > > & set ()
 
virtual const std::string & type () const override final
 String identifying the type of parameter stored. More...
 
virtual void resize (const std::size_t size) override final
 Resizes the property to the size n. More...
 
virtual unsigned int size () const override final
 
MooseADWrapper< T, is_ad > & operator[] (const unsigned int i)
 Get element i out of the array as a writeable reference. More...
 
const MooseADWrapper< T, is_ad > & operator[] (const unsigned int i) const
 Get element i out of the array as a ready-only reference. More...
 
virtual void qpCopy (const unsigned int to_qp, const PropertyValue &rhs, const unsigned int from_qp) override final
 Copy the value of a Property from one specific to a specific qp in this Property. More...
 
virtual void store (std::ostream &stream) override final
 Store the property into a binary stream. More...
 
virtual void load (std::istream &stream) override final
 Load the property from a binary stream. More...
 
virtual void swap (PropertyValue &rhs) override final
 
const std::type_info & typeID () const override final
 
virtual std::unique_ptr< PropertyValueclone (const std::size_t size) const override final
 
id_type id () const
 

Static Public Attributes

static constexpr id_type invalid_property_id = std::numeric_limits<id_type>::max() - 1
 The material property ID for an invalid property We only have this because there are a few cases where folks want to instantiate their own fake materials, and we should at least force them to be consistent. More...
 

Protected Attributes

MooseArray< MooseADWrapper< T, is_ad > > _value
 Stored parameter value. More...
 
const id_type _id
 The material property ID. 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 >

Definition at line 25 of file DerivativeMaterialInterface.h.

Member Typedef Documentation

◆ id_type

typedef unsigned int PropertyValue::id_type
inherited

The type for a material property ID.

Definition at line 42 of file MaterialProperty.h.

◆ value_type

typedef MooseADWrapper<T, is_ad> MaterialPropertyBase< T, is_ad >::value_type
inherited

Definition at line 113 of file MaterialProperty.h.

Constructor & Destructor Documentation

◆ MaterialProperty() [1/2]

Definition at line 344 of file MaterialProperty.h.

◆ 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 351 of file MaterialProperty.h.

352  {
353  mooseError("Material properties must be assigned to references (missing '&')");
354  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284

Member Function Documentation

◆ clone()

std::unique_ptr< PropertyValue > MaterialPropertyBase< T, is_ad >::clone ( const std::size_t  size) const
finaloverridevirtualinherited
Returns
A clone of this property.

Note that this will only ever return a non-AD clone, even if this property is an AD property. This is on purpose; whenever we need clones, it's for older states in which we don't store derivatives beacuse it's too expensive.

Implements PropertyValue.

Definition at line 332 of file MaterialProperty.h.

333 {
334  auto prop = std::make_unique<MaterialProperty<T>>(this->id());
335  if (size)
336  prop->resize(size);
337  return prop;
338 }
virtual unsigned int size() const override final
id_type id() const

◆ get()

const MooseArray<MooseADWrapper<T, is_ad> >& MaterialPropertyBase< T, is_ad >::get ( ) const
inlineinherited
Returns
a read-only reference to the parameter value.

Definition at line 122 of file MaterialProperty.h.

122 { return _value; }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.

◆ id()

id_type PropertyValue::id ( ) const
inlineinherited
Returns
The ID of the underlying material property

Definition at line 56 of file MaterialProperty.h.

Referenced by MaterialPropertyBase< T, false >::swap().

56 { return _id; }
const id_type _id
The material property ID.

◆ isAD()

bool MaterialPropertyBase< T, is_ad >::isAD ( ) const
inlinefinaloverridevirtualinherited

Implements PropertyValue.

Definition at line 117 of file MaterialProperty.h.

117 { return is_ad; }

◆ load()

void MaterialPropertyBase< T, is_ad >::load ( std::istream &  stream)
inlinefinaloverridevirtualinherited

Load the property from a binary stream.

Implements PropertyValue.

Definition at line 280 of file MaterialProperty.h.

281 {
282  for (const auto i : index_range(_value))
283  loadHelper(stream, _value[i], nullptr);
284 }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:881
auto index_range(const T &sizable)

◆ 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 357 of file MaterialProperty.h.

358  {
359  mooseError("Material properties must be assigned to references (missing '&')");
360  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284

◆ operator[]() [1/2]

MooseADWrapper<T, is_ad>& MaterialPropertyBase< T, is_ad >::operator[] ( const unsigned int  i)
inlineinherited

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

Definition at line 144 of file MaterialProperty.h.

144 { return _value[i]; }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.

◆ operator[]() [2/2]

const MooseADWrapper<T, is_ad>& MaterialPropertyBase< T, is_ad >::operator[] ( const unsigned int  i) const
inlineinherited

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

Definition at line 149 of file MaterialProperty.h.

149 { return _value[i]; }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.

◆ qpCopy()

void MaterialPropertyBase< T, is_ad >::qpCopy ( const unsigned int  to_qp,
const PropertyValue rhs,
const unsigned int  from_qp 
)
inlinefinaloverridevirtualinherited

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 258 of file MaterialProperty.h.

261 {
262  // If we're the same
263  if (rhs.isAD() == is_ad)
264  _value[to_qp] = cast_ptr<const MaterialPropertyBase<T, is_ad> *>(&rhs)->_value[from_qp];
265  else
267  _value[to_qp], (*cast_ptr<const MaterialPropertyBase<T, !is_ad> *>(&rhs))[from_qp]);
268 }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
void rawValueEqualityHelper(T1 &out, const T2 &in)
virtual bool isAD() const =0
Concrete definition of a parameter value for a specified type.

◆ resize()

void MaterialPropertyBase< T, is_ad >::resize ( const std::size_t  size)
inlinefinaloverridevirtualinherited

Resizes the property to the size n.

Implements PropertyValue.

Definition at line 251 of file MaterialProperty.h.

252 {
253  _value.template resize</*value_initalize=*/true>(size);
254 }
virtual void resize(const std::size_t size) override final
Resizes the property to the size n.
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
virtual unsigned int size() const override final

◆ set()

MooseArray<MooseADWrapper<T, is_ad> >& MaterialPropertyBase< T, is_ad >::set ( )
inlineinherited
Returns
a writable reference to the parameter value.

Definition at line 127 of file MaterialProperty.h.

127 { return _value; }
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.

◆ size()

virtual unsigned int MaterialPropertyBase< T, is_ad >::size ( ) const
inlinefinaloverridevirtualinherited

Implements PropertyValue.

Definition at line 139 of file MaterialProperty.h.

139 { return _value.size(); }
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.

◆ store()

void MaterialPropertyBase< T, is_ad >::store ( std::ostream &  stream)
inlinefinaloverridevirtualinherited

Store the property into a binary stream.

Implements PropertyValue.

Definition at line 272 of file MaterialProperty.h.

273 {
274  for (const auto i : index_range(_value))
275  storeHelper(stream, _value[i], nullptr);
276 }
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:809
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
auto index_range(const T &sizable)

◆ swap()

void MaterialPropertyBase< T, is_ad >::swap ( PropertyValue rhs)
inlinefinaloverridevirtualinherited

Implements PropertyValue.

Definition at line 288 of file MaterialProperty.h.

289 {
290  mooseAssert(this->id() == rhs.id(), "Inconsistent properties");
291  mooseAssert(this->typeID() == rhs.typeID(), "Inconsistent types");
292 
293  // If we're the same
294  if (rhs.isAD() == is_ad)
295  {
296  mooseAssert(dynamic_cast<decltype(this)>(&rhs), "Expected same type is not the same");
297  this->_value.swap(cast_ptr<decltype(this)>(&rhs)->_value);
298  return;
299  }
300 
301  // We may call this function when doing swap between MaterialData material properties (you can
302  // think of these as the current element properties) and MaterialPropertyStorage material
303  // properties (these are the stateful material properties that we store for *every* element). We
304  // never store ADMaterialProperty in stateful storage (e.g. MaterialPropertyStorage) for memory
305  // resource reasons; instead we keep a regular MaterialProperty version of it. Hence we do have a
306  // need to exchange data between the AD and regular copies which we implement below. The below
307  // is obviously not a swap, for which you cannot identify a giver and receiver. Instead the below
308  // has a clear giver and receiver. The giver is the object passed in as the rhs. The receiver is
309  // *this* object. This directionality, although not conceptually appropriate given the method
310  // name, *is* appropriate to how this method is used in practice. See shallowCopyData and
311  // shallowCopyDataBack in MaterialPropertyStorage.C
312 
313  auto * different_type_prop = dynamic_cast<MaterialPropertyBase<T, !is_ad> *>(&rhs);
314  mooseAssert(different_type_prop,
315  "Wrong material property type T in MaterialPropertyBase<T, is_ad>::swap");
316 
317  this->resize(different_type_prop->size());
318  for (const auto qp : make_range(this->size()))
319  moose::internal::rawValueEqualityHelper(this->_value[qp], (*different_type_prop)[qp]);
320 }
void swap(MooseArray &rhs)
Swap memory in this object with the &#39;rhs&#39; object.
Definition: MooseArray.h:283
virtual void resize(const std::size_t size) override final
Resizes the property to the size n.
virtual const std::type_info & typeID() const =0
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
virtual unsigned int size() const override final
void rawValueEqualityHelper(T1 &out, const T2 &in)
id_type id() const
IntRange< T > make_range(T beg, T end)
virtual bool isAD() const =0
const std::type_info & typeID() const override final
Concrete definition of a parameter value for a specified type.

◆ type()

const std::string & MaterialPropertyBase< T, is_ad >::type ( ) const
inlinefinaloverridevirtualinherited

String identifying the type of parameter stored.

Implements PropertyValue.

Definition at line 243 of file MaterialProperty.h.

244 {
245  static const std::string type_name = MooseUtils::prettyCppType<T>();
246  return type_name;
247 }

◆ typeID()

const std::type_info & MaterialPropertyBase< T, is_ad >::typeID ( ) const
inlinefinaloverridevirtualinherited
Returns
The type_info for the underlying stored type T

Implements PropertyValue.

Definition at line 324 of file MaterialProperty.h.

325 {
326  static const auto & info = typeid(T);
327  return info;
328 }
MPI_Info info

Member Data Documentation

◆ _id

const id_type PropertyValue::_id
protectedinherited

The material property ID.

Definition at line 102 of file MaterialProperty.h.

Referenced by PropertyValue::id().

◆ _value

MooseArray<MooseADWrapper<T, is_ad> > MaterialPropertyBase< T, is_ad >::_value
protectedinherited

Stored parameter value.

Definition at line 200 of file MaterialProperty.h.

◆ invalid_property_id

constexpr id_type PropertyValue::invalid_property_id = std::numeric_limits<id_type>::max() - 1
staticinherited

The material property ID for an invalid property We only have this because there are a few cases where folks want to instantiate their own fake materials, and we should at least force them to be consistent.

Definition at line 51 of file MaterialProperty.h.


The documentation for this class was generated from the following files: