https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | List of all members
MaterialProperty< T > Class Template Reference

#include <MaterialProperty.h>

Inheritance diagram for MaterialProperty< T >:
[legend]

Public Types

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

Public Member Functions

 MaterialProperty (const PropertyValue::id_type id=PropertyValue::invalid_property_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.
 
virtual void resize (const std::size_t size) override final
 Resizes the property to the size n.
 
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.
 
const Moose::GenericType< T, is_ad > & operator[] (const unsigned int i) const
 Get element i out of the array as a ready-only reference.
 
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.
 
virtual void store (std::ostream &stream) override final
 Store the property into a binary stream.
 
virtual void load (std::istream &stream) override final
 Load the property from a binary stream.
 
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.
 

Protected Attributes

MooseArray< Moose::GenericType< T, is_ad > > _value
 Stored parameter value.
 
const id_type _id
 The material property ID.
 

Private Member Functions

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

Detailed Description

template<typename T>
class MaterialProperty< T >

Definition at line 340 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

typedef Moose::GenericType<T, is_ad> MaterialPropertyBase< T, is_ad >::value_type
inherited

Definition at line 112 of file MaterialProperty.h.

Constructor & Destructor Documentation

◆ MaterialProperty() [1/2]

Definition at line 343 of file MaterialProperty.h.

345 {
346 }
Concrete definition of a parameter value for a specified type.

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

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

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

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

◆ get()

const MooseArray< Moose::GenericType< T, is_ad > > & MaterialPropertyBase< T, is_ad >::get ( ) const
inlineinherited
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.

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

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

◆ isAD()

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

Implements PropertyValue.

Definition at line 116 of file MaterialProperty.h.

116{ 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 169 of file MaterialProperty.h.

282{
283 for (const auto i : index_range(_value))
284 loadHelper(stream, _value[i], nullptr);
285}
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition DataIO.h:1081
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 356 of file MaterialProperty.h.

357 {
358 mooseError("Material properties must be assigned to references (missing '&')");
359 }

◆ operator[]() [1/2]

Moose::GenericType< 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 143 of file MaterialProperty.h.

143{ return _value[i]; }

◆ operator[]() [2/2]

const Moose::GenericType< 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 148 of file MaterialProperty.h.

148{ return _value[i]; }

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

260{
261 // If we're the same
262 if (rhs.isAD() == is_ad)
263 _value[to_qp] =
264 libMesh::cast_ptr<const MaterialPropertyBase<T, is_ad> *>(&rhs)->_value[from_qp];
265 else
267 _value[to_qp],
268 (*libMesh::cast_ptr<const MaterialPropertyBase<T, !is_ad> *>(&rhs))[from_qp]);
269}
virtual bool isAD() const =0
Tnew cast_ptr(Told *oldvar)
void rawValueEqualityHelper(T1 &out, const T2 &in)

◆ 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 136 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.

◆ set()

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

Definition at line 126 of file MaterialProperty.h.

126{ return _value; }

◆ size()

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

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

◆ store()

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

Store the property into a binary stream.

Implements PropertyValue.

Definition at line 164 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:989

◆ swap()

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

Implements PropertyValue.

Definition at line 171 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 = libMesh::cast_ptr<MaterialPropertyBase<T, !is_ad> *>(&rhs);
315
316 this->resize(different_type_prop->size());
317 for (const auto qp : make_range(this->size()))
318 moose::internal::rawValueEqualityHelper(this->_value[qp], (*different_type_prop)[qp]);
319}
const std::type_info & typeID() const override final
void swap(MooseArray &rhs)
Swap memory in this object with the 'rhs' object.
Definition MooseArray.h:286
virtual const std::type_info & typeID() const =0
IntRange< T > make_range(T beg, T end)

◆ type()

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

String identifying the type of parameter stored.

Implements PropertyValue.

Definition at line 131 of file MaterialProperty.h.

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

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

324{
325 static const auto & info = typeid(T);
326 return info;
327}
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

MooseArray<Moose::GenericType<T, is_ad> > MaterialPropertyBase< T, is_ad >::_value
protectedinherited

Stored parameter value.

Definition at line 199 of file MaterialProperty.h.

◆ invalid_property_id

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

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 files: