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 331 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()

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 281 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 , 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] =
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}
Concrete definition of a parameter value for a specified type.
virtual bool isAD() const =0
Tnew cast_ptr(Told *oldvar)
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 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:989

◆ 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 = 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()

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

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: