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

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

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

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) {}
Abstract definition of a property value.

◆ 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:311

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

330{
331 auto prop = std::make_unique<MaterialProperty<T>>(this->id());
332 if (size)
333 prop->resize(size);
334 return prop;
335}
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.

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

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

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

280{
281 for (const auto i : index_range(_value))
282 dataLoad(stream, _value[i], nullptr);
283}
void dataLoad(std::istream &stream, PropertyValue &p, void *context)
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 }

◆ 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]; }

◆ 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]; }

◆ 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] = cast_ptr<const MaterialPropertyBase<T, is_ad> *>(&rhs)->_value[from_qp];
264 else
266 _value[to_qp], (*cast_ptr<const MaterialPropertyBase<T, !is_ad> *>(&rhs))[from_qp]);
267}
Concrete definition of a parameter value for a specified type.
virtual bool isAD() const =0
void rawValueEqualityHelper(T1 &out, const T2 &in)

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

◆ 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; }

◆ 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

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

272{
273 for (const auto i : index_range(_value))
274 dataStore(stream, _value[i], nullptr);
275}
void dataStore(std::ostream &stream, PropertyValue &p, void *context)

◆ swap()

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

Implements PropertyValue.

Definition at line 287 of file MaterialProperty.h.

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

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

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