23#include "libmesh/libmesh_common.h"
24#include "libmesh/tensor_value.h"
25#include "libmesh/vector_value.h"
26#include "libmesh/int_range.h"
28#include "metaphysicl/raw_type.h"
60 virtual const std::string &
type()
const = 0;
65 virtual std::unique_ptr<PropertyValue>
clone(
const std::size_t)
const = 0;
67 virtual unsigned int size()
const = 0;
76 virtual bool isAD()
const = 0;
91 virtual void store(std::ostream & stream) = 0;
92 virtual void load(std::istream & stream) = 0;
97 virtual const std::type_info &
typeID()
const = 0;
108template <
typename T,
bool is_ad>
116 bool isAD() const override final {
return is_ad; }
131 virtual const std::string &
type() const override final;
157 virtual void qpCopy(
const unsigned int to_qp,
159 const unsigned int from_qp)
override final;
164 virtual void store(std::ostream & stream)
override final;
169 virtual void load(std::istream & stream)
override final;
173 const std::type_info &
typeID() const override final;
188 mooseError(
"Material properties must be assigned to references (missing '&')");
194 mooseError(
"Material properties must be assigned to references (missing '&')");
214template <
typename T1,
typename T2>
221template <
typename T1,
typename T2>
225 out.resize(in.size());
226 for (MooseIndex(in) i = 0; i < in.size(); ++i)
230template <
typename T1,
typename T2, std::
size_t N>
234 for (MooseIndex(in) i = 0; i < in.size(); ++i)
240template <
typename T,
bool is_ad>
241inline const std::string &
244 static const std::string type_name = MooseUtils::prettyCppType<T>();
248template <
typename T,
bool is_ad>
252 _value.template resize<
true>(size);
255template <
typename T,
bool is_ad>
259 const unsigned int from_qp)
262 if (rhs.
isAD() == is_ad)
264 libMesh::cast_ptr<const MaterialPropertyBase<T, is_ad> *>(&rhs)->_value[from_qp];
271template <
typename T,
bool is_ad>
275 for (
const auto i : index_range(_value))
279template <
typename T,
bool is_ad>
283 for (
const auto i : index_range(_value))
287template <
typename T,
bool is_ad>
291 mooseAssert(this->
id() == rhs.
id(),
"Inconsistent properties");
292 mooseAssert(this->typeID() == rhs.
typeID(),
"Inconsistent types");
295 if (rhs.
isAD() == is_ad)
297 mooseAssert(
dynamic_cast<decltype(this)
>(&rhs),
"Expected same type is not the same");
314 auto * different_type_prop = libMesh::cast_ptr<MaterialPropertyBase<T, !is_ad> *>(&rhs);
316 this->resize(different_type_prop->size());
317 for (
const auto qp : make_range(this->size()))
321template <
typename T,
bool is_ad>
322inline const std::type_info &
325 static const auto & info =
typeid(T);
329template <
typename T,
bool is_ad>
330std::unique_ptr<PropertyValue>
333 auto prop = std::make_unique<MaterialProperty<T>>(this->id());
352 mooseError(
"Material properties must be assigned to references (missing '&')");
358 mooseError(
"Material properties must be assigned to references (missing '&')");
377 mooseError(
"Material properties must be assigned to references (missing '&')");
383 mooseError(
"Material properties must be assigned to references (missing '&')");
410 for (
const auto i : index_range(*
this))
412 value->resize(n_qpoints);
426template <
typename T,
bool is_ad>
438template <
typename T,
bool is_ad>
450template <
class M,
typename T,
bool is_ad>
458template <
typename T,
bool is_ad>
478 "Attempting to access an optional material property that was not provided by any material "
479 "class. Make sure to check optional material properties before using them.");
484 unsigned int size()
const {
return (*_pointer).size(); }
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
void dataLoad(std::istream &stream, PropertyValue &p, void *context)
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
void dataStore(std::ostream &stream, PropertyValue &p, void *context)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
ADMaterialProperty< T > & operator=(const ADMaterialProperty< T > &)
private assignment operator to avoid shallow copying of material properties
ADMaterialProperty(const ADMaterialProperty< T > &)
private copy constructor to avoid shallow copying of material properties
ADMaterialProperty(const PropertyValue::id_type id=PropertyValue::invalid_property_id)
Base class to facilitate storage using unique pointers.
virtual ~GenericOptionalMaterialPropertyBase()
Wrapper around a material property pointer.
GenericMaterialProperty< T, is_ad > P
const P * get() const
get a pointer to the underlying property (only do this in initialSetup or later)
unsigned int size() const
pass through size calls
void set(const P *pointer)
setting the pointer is only permitted through the optional material proxy system
GenericOptionalMaterialProperty & operator=(const GenericOptionalMaterialProperty< T, is_ad > &)=delete
no copy assignment is permitted
const Moose::GenericType< T, is_ad > & operator[](const unsigned int i) const
pass through operator[] to provide a similar API as MaterialProperty
GenericOptionalMaterialProperty(const GenericOptionalMaterialProperty< T, is_ad > &)=delete
no copy construction is permitted
GenericOptionalMaterialProperty(const P *pointer)
GenericOptionalMaterialProperty()
the default constructor is only called from the friend class
Proxy for accessing MaterialPropertyStorage.
friend void dataLoad(std::istream &, MaterialPropertyStorage &, void *)
WriteKey(const WriteKey &)
void resizeItems(const std::size_t n_qpoints, const WriteKey)
Resize items in this array, i.e.
void setPointer(const std::size_t i, std::unique_ptr< PropertyValue > &&ptr, const WriteKey)
void resize(const std::size_t size, const WriteKey)
Concrete definition of a parameter value for a specified type.
const MooseArray< Moose::GenericType< T, is_ad > > & get() const
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.
MooseArray< Moose::GenericType< T, is_ad > > _value
Stored parameter value.
MooseArray< Moose::GenericType< T, is_ad > > & set()
const std::type_info & typeID() const override final
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.
bool isAD() const override final
virtual void load(std::istream &stream) override final
Load the property from a binary stream.
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 const std::string & type() const override final
String identifying the type of parameter stored.
MaterialPropertyBase(const PropertyValue::id_type id)
virtual void store(std::ostream &stream) override final
Store the property into a binary stream.
virtual std::unique_ptr< PropertyValue > clone(const std::size_t size) const override final
MaterialPropertyBase< T, is_ad > & operator=(const MaterialPropertyBase< T, is_ad > &)
private assignment operator to avoid shallow copying of material properties
Moose::GenericType< T, is_ad > value_type
virtual void swap(PropertyValue &rhs) override final
virtual void resize(const std::size_t size) override final
Resizes the property to the size n.
An interface for accessing Materials.
Stores the stateful material properties computed by materials.
MaterialProperty< T > & operator=(const MaterialProperty< T > &)
private assignment operator to avoid shallow copying of material properties
MaterialProperty(const MaterialProperty< T > &)
private copy constructor to avoid shallow copying of material properties
MaterialProperty(const PropertyValue::id_type id=PropertyValue::invalid_property_id)
Materials compute MaterialProperties.
unsigned int size() const
The number of elements that can currently be stored in the array.
Abstract definition of a property value.
virtual bool isAD() const =0
virtual void store(std::ostream &stream)=0
static constexpr id_type invalid_property_id
The material property ID for an invalid property We only have this because there are a few cases wher...
unsigned int id_type
The type for a material property ID.
const id_type _id
The material property ID.
virtual const std::string & type() const =0
String identifying the type of parameter stored.
PropertyValue(const id_type id)
virtual void load(std::istream &stream)=0
virtual const std::type_info & typeID() const =0
virtual unsigned int size() const =0
virtual std::unique_ptr< PropertyValue > clone(const std::size_t) const =0
Clone this value.
virtual void qpCopy(const unsigned int to_qp, const PropertyValue &rhs, const unsigned int from_qp)=0
Copy the value of a Property from one specific to a specific qp in this Property.
virtual void resize(const std::size_t size)=0
Resizes the property to the size n.
virtual void swap(PropertyValue &rhs)=0
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
const PropertyValue * queryValue(const std::size_t i) const
void resize(const std::size_t size)
Resizes the underlying vector.
void setPointer(const std::size_t i, std::unique_ptr< T > &&ptr)
Sets the underlying unique_ptr at index i to ptr.
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
Tnew cast_ptr(Told *oldvar)
void rawValueEqualityHelper(T1 &out, const T2 &in)
ADMaterialProperty< T > type
MaterialProperty< T > type