12#include "metaphysicl/raw_type.h"
22 params.
addClassDescription(
"Converts functor to non-AD and AD regular material properties");
23 params.
addParam<std::vector<MooseFunctorName>>(
24 "functors_in", {},
"The names of the functors to convert to regular material properties");
25 params.
addParam<std::vector<MaterialPropertyName>>(
26 "ad_props_out", {},
"The names of the output AD properties");
27 params.
addParam<std::vector<MaterialPropertyName>>(
28 "reg_props_out", {},
"The names of the output regular properties");
35 _num_functors_to_convert(getParam<
std::vector<MooseFunctorName>>(
"functors_in").size())
37 const auto & functors_in = getParam<std::vector<MooseFunctorName>>(
"functors_in");
38 const auto & reg_props_out = getParam<std::vector<MaterialPropertyName>>(
"reg_props_out");
39 const auto & ad_props_out = getParam<std::vector<MaterialPropertyName>>(
"ad_props_out");
41 if (reg_props_out.size() && ad_props_out.size())
43 "We dont support converting functors to both regular and AD "
44 "material properties in "
45 "a single instance of '",
47 "'. Please create two instances, one for regular and one for AD.");
49 if ((reg_props_out.size() && (functors_in.size() != reg_props_out.size())) ||
50 (ad_props_out.size() && (functors_in.size() != ad_props_out.size())))
53 "The number of output properties must match the number of input functors, which is " +
54 std::to_string(functors_in.size()));
63 for (
const auto i : index_range(ad_props_out))
66 for (
const auto i : index_range(reg_props_out))
74 computeQpProperties();
83 unsigned int qp_used = (_constant_option == ConstantTypeEnum::NONE) ? _qp : 0;
89 _current_elem, _current_side, qp_used, _qrule, _q_point[_qp]};
90 for (
const auto i : index_range(_ad_props_out))
91 (*_ad_props_out[i])[_qp] = (*_functors_in[i])(side_arg, state);
93 for (
const auto i : index_range(_reg_props_out))
98 const Elem * elem = _neighbor ? _current_elem->neighbor_ptr(_current_side) : _current_elem;
99 mooseAssert(elem,
"We should have an element");
101 for (
const auto i : index_range(_ad_props_out))
102 (*_ad_props_out[i])[_qp] = (*_functors_in[i])(elem_arg, state);
104 for (
const auto i : index_range(_reg_props_out))
registerMooseObject("MooseApp", MaterialFunctorConverter)
const Moose::Functor< T > & getFunctor(const std::string &name)
Retrieves a functor from the subproblem.
This material converts functor to regular (AD or not) material properties.
static InputParameters validParams()
std::vector< MaterialProperty< T > * > _reg_props_out
Regular material properties to create.
MaterialFunctorConverterTempl(const InputParameters ¶meters)
std::vector< const Moose::Functor< Moose::GenericType< T, true > > * > _functors_in
Incoming functors to convert. We up-convert non-AD functors to AD functors to ease implementation.
virtual void computeQpProperties() override
Users must override this method.
void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
std::vector< ADMaterialProperty< T > * > _ad_props_out
AD material properties to create.
const std::size_t _num_functors_to_convert
Number of material properties to create.
Materials compute MaterialProperties.
static InputParameters validParams()
const std::string & type() const
Get the type of this class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
Argument for requesting functor evaluation at a quadrature point location in an element.
Argument for requesting functor evaluation at quadrature point locations on an element side.