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;
72 virtual void resize(
const std::size_t
size) = 0;
76 virtual bool isAD()
const = 0;
88 qpCopy(
const unsigned int to_qp,
const PropertyValue & rhs,
const unsigned int from_qp) = 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;
108 template <
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 '&')");
202 template <
typename T>
204 template <
typename T>
214 template <
typename T1,
typename T2>
221 template <
typename T1,
typename T2>
225 out.resize(in.size());
226 for (MooseIndex(in) i = 0; i < in.size(); ++i)
230 template <
typename T1,
typename T2, std::
size_t N>
234 for (MooseIndex(in) i = 0; i < in.size(); ++i)
240 template <
typename T,
bool is_ad>
241 inline const std::string &
244 static const std::string type_name = MooseUtils::prettyCppType<T>();
248 template <
typename T,
bool is_ad>
252 _value.template resize<
true>(size);
255 template <
typename T,
bool is_ad>
259 const unsigned int from_qp)
262 if (rhs.
isAD() == is_ad)
271 template <
typename T,
bool is_ad>
279 template <
typename T,
bool is_ad>
287 template <
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");
315 mooseAssert(different_type_prop,
316 "Wrong material property type T in MaterialPropertyBase<T, is_ad>::swap");
318 this->resize(different_type_prop->size());
319 for (
const auto qp :
make_range(this->size()))
323 template <
typename T,
bool is_ad>
324 inline const std::type_info &
327 static const auto &
info =
typeid(T);
331 template <
typename T,
bool is_ad>
332 std::unique_ptr<PropertyValue>
335 auto prop = std::make_unique<MaterialProperty<T>>(this->id());
341 template <
typename T>
354 mooseError(
"Material properties must be assigned to references (missing '&')");
360 mooseError(
"Material properties must be assigned to references (missing '&')");
364 template <
typename T>
379 mooseError(
"Material properties must be assigned to references (missing '&')");
385 mooseError(
"Material properties must be assigned to references (missing '&')");
414 value->resize(n_qpoints);
428 template <
typename T,
bool is_ad>
434 template <
typename T>
440 template <
typename T,
bool is_ad>
452 template <
class M,
typename T,
bool is_ad>
460 template <
typename T,
bool is_ad>
480 "Attempting to access an optional material property that was not provided by any material " 481 "class. Make sure to check optional material properties before using them.");
486 unsigned int size()
const {
return (*_pointer).size(); }
512 template <
typename T>
514 template <
typename T>
virtual void store(std::ostream &stream) override final
Store the property into a binary stream.
GenericOptionalMaterialProperty & operator=(const GenericOptionalMaterialProperty< T, is_ad > &)=delete
no copy assignment is permitted
virtual const std::string & type() const override final
String identifying the type of parameter stored.
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. ...
MaterialProperty(const PropertyValue::id_type id=PropertyValue::invalid_property_id)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
MaterialProperty(const MaterialProperty< T > &)
private copy constructor to avoid shallow copying of material properties
GenericOptionalMaterialProperty()
the default constructor is only called from the friend class
MaterialPropertyBase(const PropertyValue::id_type id)
virtual void resize(const std::size_t size)=0
Resizes the property to the size n.
ADMaterialProperty(const PropertyValue::id_type id=PropertyValue::invalid_property_id)
Tnew cast_ptr(Told *oldvar)
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
Stores the stateful material properties computed by materials.
unsigned int id_type
The type for a material property ID.
void dataStore(std::ostream &stream, PropertyValue &p, void *context)
WriteKey(const WriteKey &)
GenericMaterialProperty< T, is_ad > P
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 std::unique_ptr< PropertyValue > clone(const std::size_t) const =0
Clone this value.
virtual ~GenericOptionalMaterialPropertyBase()
void setPointer(const std::size_t i, std::unique_ptr< T > &&ptr)
Sets the underlying unique_ptr at index i to ptr.
void resize(const std::size_t size, const WriteKey)
const Moose::GenericType< T, is_ad > & operator[](const unsigned int i) const
pass through operator[] to provide a similar API as MaterialProperty
void setPointer(const std::size_t i, std::unique_ptr< PropertyValue > &&ptr, const WriteKey)
bool isAD() const override final
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
virtual void resize(const std::size_t size) override final
Resizes the property to the size n.
auto max(const L &left, const R &right)
void resize(const std::size_t size)
Resizes the underlying vector.
GenericOptionalMaterialProperty(const P *pointer)
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
virtual void swap(PropertyValue &rhs)=0
Wrapper around a material property pointer.
MaterialProperty< T > type
unsigned int size() const
The number of elements that can currently be stored in the array.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void resizeItems(const std::size_t n_qpoints, const WriteKey)
Resize items in this array, i.e.
const PropertyValue * queryValue(const std::size_t i) const
virtual unsigned int size() const =0
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
Moose::GenericType< T, is_ad > value_type
virtual const std::type_info & typeID() const =0
Abstract definition of a property value.
virtual std::unique_ptr< PropertyValue > clone(const std::size_t size) const override final
unsigned int size() const
pass through size calls
virtual unsigned int size() const override final
Materials compute MaterialProperties.
ADMaterialProperty(const ADMaterialProperty< T > &)
private copy constructor to avoid shallow copying of material properties
virtual void load(std::istream &stream) override final
Load the property from a binary stream.
MaterialPropertyBase< T, is_ad > & operator=(const MaterialPropertyBase< T, is_ad > &)
private assignment operator to avoid shallow copying of material properties
virtual void store(std::ostream &stream)=0
MooseArray< Moose::GenericType< T, is_ad > > _value
Stored parameter value.
An interface for accessing Materials.
void rawValueEqualityHelper(T1 &out, const T2 &in)
ADMaterialProperty< T > & operator=(const ADMaterialProperty< T > &)
private assignment operator to avoid shallow copying of material properties
IntRange< T > make_range(T beg, T end)
virtual void load(std::istream &stream)=0
friend void dataLoad(std::istream &, MaterialPropertyStorage &, void *)
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...
Proxy for accessing MaterialPropertyStorage.
virtual bool isAD() const =0
virtual const std::string & type() const =0
String identifying the type of parameter stored.
MaterialProperty< T > & operator=(const MaterialProperty< T > &)
private assignment operator to avoid shallow copying of material properties
void dataLoad(std::istream &stream, PropertyValue &p, void *context)
Base class to facilitate storage using unique pointers.
virtual void swap(PropertyValue &rhs) override final
const std::type_info & typeID() const override final
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Moose::GenericType< T, is_ad > & operator[](const unsigned int i)
Get element i out of the array as a writeable reference.
auto index_range(const T &sizable)
Concrete definition of a parameter value for a specified type.
PropertyValue(const id_type id)
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. ...
ADMaterialProperty< T > type
const id_type _id
The material property ID.