https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | List of all members
MaterialPropertyBase< T, is_ad > Class Template Reference

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

#include <MaterialProperty.h>

Inheritance diagram for MaterialPropertyBase< T, is_ad >:
[legend]

Public Types

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

Public Member Functions

 MaterialPropertyBase (const PropertyValue::id_type id)
 
bool isAD () const override final
 
const MooseArray< Moose::GenericType< T, is_ad > > & get () const
 
MooseArray< Moose::GenericType< 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
 
Moose::GenericType< T, is_ad > & operator[] (const unsigned int i)
 Get element i out of the array as a writeable reference. More...
 
const Moose::GenericType< 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< Moose::GenericType< T, is_ad > > _value
 Stored parameter value. More...
 
const id_type _id
 The material property ID. More...
 

Private Member Functions

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

Detailed Description

template<typename T, bool is_ad>
class MaterialPropertyBase< T, is_ad >

Concrete definition of a parameter value for a specified type.

Definition at line 109 of file MaterialProperty.h.

Member Typedef Documentation

◆ id_type

typedef unsigned int PropertyValue::id_type
inherited

The type for a material property ID.

Definition at line 41 of file MaterialProperty.h.

◆ value_type

template<typename T, bool is_ad>
typedef Moose::GenericType<T, is_ad> MaterialPropertyBase< T, is_ad >::value_type

Definition at line 112 of file MaterialProperty.h.

Constructor & Destructor Documentation

◆ MaterialPropertyBase() [1/2]

template<typename T, bool is_ad>
MaterialPropertyBase< T, is_ad >::MaterialPropertyBase ( const PropertyValue::id_type  id)
inline

Definition at line 114 of file MaterialProperty.h.

114 : PropertyValue(id) {}
PropertyValue(const id_type id)

◆ MaterialPropertyBase() [2/2]

template<typename T, bool is_ad>
MaterialPropertyBase< T, is_ad >::MaterialPropertyBase ( const MaterialPropertyBase< T, is_ad > &  )
inlineprivate

private copy constructor to avoid shallow copying of material properties

Definition at line 186 of file MaterialProperty.h.

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

Member Function Documentation

◆ clone()

template<typename T , bool is_ad>
std::unique_ptr< PropertyValue > MaterialPropertyBase< T, is_ad >::clone ( const std::size_t  size) const
finaloverridevirtual
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 333 of file MaterialProperty.h.

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

◆ get()

template<typename T, bool is_ad>
const MooseArray<Moose::GenericType<T, is_ad> >& MaterialPropertyBase< T, is_ad >::get ( ) const
inline
Returns
a read-only reference to the parameter value.

Definition at line 121 of file MaterialProperty.h.

121 { return _value; }
MooseArray< Moose::GenericType< 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 55 of file MaterialProperty.h.

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

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

◆ isAD()

template<typename T, bool is_ad>
bool MaterialPropertyBase< T, is_ad >::isAD ( ) const
inlinefinaloverridevirtual

Implements PropertyValue.

Definition at line 116 of file MaterialProperty.h.

116 { return is_ad; }

◆ load()

template<typename T , bool is_ad>
void MaterialPropertyBase< T, is_ad >::load ( std::istream &  stream)
inlinefinaloverridevirtual

Load the property from a binary stream.

Implements PropertyValue.

Definition at line 281 of file MaterialProperty.h.

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

◆ operator=()

template<typename T, bool is_ad>
MaterialPropertyBase<T, is_ad>& MaterialPropertyBase< T, is_ad >::operator= ( const MaterialPropertyBase< T, is_ad > &  )
inlineprivate

private assignment operator to avoid shallow copying of material properties

Definition at line 192 of file MaterialProperty.h.

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

◆ operator[]() [1/2]

template<typename T, bool is_ad>
Moose::GenericType<T, is_ad>& MaterialPropertyBase< T, is_ad >::operator[] ( const unsigned int  i)
inline

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

Definition at line 143 of file MaterialProperty.h.

143 { return _value[i]; }
MooseArray< Moose::GenericType< T, is_ad > > _value
Stored parameter value.

◆ operator[]() [2/2]

template<typename T, bool is_ad>
const Moose::GenericType<T, is_ad>& MaterialPropertyBase< T, is_ad >::operator[] ( const unsigned int  i) const
inline

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

Definition at line 148 of file MaterialProperty.h.

148 { return _value[i]; }
MooseArray< Moose::GenericType< T, is_ad > > _value
Stored parameter value.

◆ qpCopy()

template<typename T , bool is_ad>
void MaterialPropertyBase< T, is_ad >::qpCopy ( const unsigned int  to_qp,
const PropertyValue rhs,
const unsigned int  from_qp 
)
inlinefinaloverridevirtual

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

260 {
261  // If we're the same
262  if (rhs.isAD() == is_ad)
263  _value[to_qp] =
265  else
267  _value[to_qp],
268  (*libMesh::cast_ptr<const MaterialPropertyBase<T, !is_ad> *>(&rhs))[from_qp]);
269 }
Tnew cast_ptr(Told *oldvar)
MooseArray< Moose::GenericType< 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()

template<typename T , bool is_ad>
void MaterialPropertyBase< T, is_ad >::resize ( const std::size_t  size)
inlinefinaloverridevirtual

Resizes the property to the size n.

Implements PropertyValue.

Definition at line 250 of file MaterialProperty.h.

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

◆ set()

template<typename T, bool is_ad>
MooseArray<Moose::GenericType<T, is_ad> >& MaterialPropertyBase< T, is_ad >::set ( )
inline
Returns
a writable reference to the parameter value.

Definition at line 126 of file MaterialProperty.h.

126 { return _value; }
MooseArray< Moose::GenericType< T, is_ad > > _value
Stored parameter value.

◆ size()

template<typename T, bool is_ad>
virtual unsigned int MaterialPropertyBase< T, is_ad >::size ( ) const
inlinefinaloverridevirtual

Implements PropertyValue.

Definition at line 138 of file MaterialProperty.h.

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

◆ store()

template<typename T , bool is_ad>
void MaterialPropertyBase< T, is_ad >::store ( std::ostream &  stream)
inlinefinaloverridevirtual

Store the property into a binary stream.

Implements PropertyValue.

Definition at line 273 of file MaterialProperty.h.

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

◆ swap()

template<typename T , bool is_ad>
void MaterialPropertyBase< T, is_ad >::swap ( PropertyValue rhs)
inlinefinaloverridevirtual

Implements PropertyValue.

Definition at line 289 of file MaterialProperty.h.

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

template<typename T , bool is_ad>
const std::string & MaterialPropertyBase< T, is_ad >::type ( ) const
inlinefinaloverridevirtual

String identifying the type of parameter stored.

Implements PropertyValue.

Definition at line 242 of file MaterialProperty.h.

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

◆ typeID()

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

Implements PropertyValue.

Definition at line 325 of file MaterialProperty.h.

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

Member Data Documentation

◆ _id

const id_type PropertyValue::_id
protectedinherited

The material property ID.

Definition at line 101 of file MaterialProperty.h.

Referenced by PropertyValue::id().

◆ _value

template<typename T, bool is_ad>
MooseArray<Moose::GenericType<T, is_ad> > MaterialPropertyBase< T, is_ad >::_value
protected

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


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