24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/tensor_value.h" 26 #include "libmesh/vector_value.h" 27 #include "libmesh/int_range.h" 29 #include "metaphysicl/raw_type.h" 61 virtual const std::string &
type()
const = 0;
66 virtual std::unique_ptr<PropertyValue>
clone(
const std::size_t)
const = 0;
68 virtual unsigned int size()
const = 0;
73 virtual void resize(
const std::size_t
size) = 0;
77 virtual bool isAD()
const = 0;
89 qpCopy(
const unsigned int to_qp,
const PropertyValue & rhs,
const unsigned int from_qp) = 0;
92 virtual void store(std::ostream & stream) = 0;
93 virtual void load(std::istream & stream) = 0;
98 virtual const std::type_info &
typeID()
const = 0;
109 template <
typename T,
bool is_ad>
117 bool isAD() const override final {
return is_ad; }
132 virtual const std::string &
type() const override final;
158 virtual void qpCopy(
const unsigned int to_qp,
160 const unsigned int from_qp)
override final;
165 virtual void store(std::ostream & stream)
override final;
170 virtual void load(std::istream & stream)
override final;
174 const std::type_info &
typeID() const override final;
189 mooseError(
"Material properties must be assigned to references (missing '&')");
195 mooseError(
"Material properties must be assigned to references (missing '&')");
203 template <
typename T>
205 template <
typename T>
215 template <
typename T1,
typename T2>
222 template <
typename T1,
typename T2>
226 out.resize(in.size());
227 for (MooseIndex(in) i = 0; i < in.size(); ++i)
231 template <
typename T1,
typename T2, std::
size_t N>
235 for (MooseIndex(in) i = 0; i < in.size(); ++i)
241 template <
typename T,
bool is_ad>
242 inline const std::string &
245 static const std::string type_name = MooseUtils::prettyCppType<T>();
249 template <
typename T,
bool is_ad>
253 _value.template resize<
true>(size);
256 template <
typename T,
bool is_ad>
260 const unsigned int from_qp)
263 if (rhs.
isAD() == is_ad)
270 template <
typename T,
bool is_ad>
278 template <
typename T,
bool is_ad>
286 template <
typename T,
bool is_ad>
290 mooseAssert(this->
id() == rhs.
id(),
"Inconsistent properties");
291 mooseAssert(this->typeID() == rhs.
typeID(),
"Inconsistent types");
294 if (rhs.
isAD() == is_ad)
296 mooseAssert(
dynamic_cast<decltype(this)
>(&rhs),
"Expected same type is not the same");
297 this->_value.swap(
cast_ptr<decltype(
this)>(&rhs)->_value);
314 mooseAssert(different_type_prop,
315 "Wrong material property type T in MaterialPropertyBase<T, is_ad>::swap");
317 this->resize(different_type_prop->size());
318 for (
const auto qp :
make_range(this->size()))
322 template <
typename T,
bool is_ad>
323 inline const std::type_info &
326 static const auto &
info =
typeid(T);
330 template <
typename T,
bool is_ad>
331 std::unique_ptr<PropertyValue>
334 auto prop = std::make_unique<MaterialProperty<T>>(this->id());
340 template <
typename T>
353 mooseError(
"Material properties must be assigned to references (missing '&')");
359 mooseError(
"Material properties must be assigned to references (missing '&')");
363 template <
typename T>
378 mooseError(
"Material properties must be assigned to references (missing '&')");
384 mooseError(
"Material properties must be assigned to references (missing '&')");
413 value->resize(n_qpoints);
427 template <
typename T,
bool is_ad>
433 template <
typename T>
439 template <
typename T,
bool is_ad>
451 template <
class M,
typename T,
bool is_ad>
459 template <
typename T,
bool is_ad>
479 "Attempting to access an optional material property that was not provided by any material " 480 "class. Make sure to check optional material properties before using them.");
485 unsigned int size()
const {
return (*_pointer).size(); }
511 template <
typename T>
513 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
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)
void setPointer(const std::size_t i, std::unique_ptr< PropertyValue > &&ptr, const WriteKey)
bool isAD() const override final
const MooseADWrapper< T, is_ad > & operator[](const unsigned int i) const
pass through operator[] to provide a similar API as MaterialProperty
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)
MooseADWrapper< T, is_ad > value_type
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
virtual const std::type_info & typeID() const =0
Abstract definition of a property value.
MooseArray< MooseADWrapper< T, is_ad > > _value
Stored parameter value.
const MooseADWrapper< 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 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.
typename MooseADWrapperStruct< T, is_ad >::type MooseADWrapper
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
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
MooseADWrapper< T, is_ad > & operator[](const unsigned int i)
Get element i out of the array as a writeable reference.
const std::type_info & typeID() const override final
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
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.