https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CompileTimeDerivativesMaterial.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "Material.h"
16
25template <int N, bool is_ad = false, int MaxD = 3>
27{
28public:
30 const std::array<std::string, N> variables);
32
33protected:
39 template <typename T>
40 void evaluate(const T & F);
41
42 const MaterialPropertyName _F_name;
44
48 std::array<VariableName, N> _var_name;
49
53 std::array<GenericMaterialProperty<Real, is_ad> *,
54 CompileTimeDerivativesMaterialInternal::total_derivatives<MaxD, N>()>
56
64 GenericVariableValue<is_ad>>(std::make_index_sequence<N>{}))::type _refs;
65
66private:
67 template <std::size_t... Ns>
68 auto makeRefsTuple(const std::array<std::string, N> & variables,
69 const unsigned int & qp,
70 std::index_sequence<Ns...>)
71 {
72 return std::make_tuple(
73 CompileTimeDerivatives::makeRef<Ns>(coupledGenericValue<is_ad>(variables[Ns]), qp)...);
74 }
75
76 template <std::size_t I>
77 constexpr void loopDeclareProperties(std::index_sequence<>)
78 {
79 }
80 template <std::size_t I, std::size_t first, std::size_t... tail>
81 constexpr void loopDeclareProperties(std::index_sequence<first, tail...> int_seq)
82 {
84 if constexpr (is_sorted(int_seq))
85 {
86 _prop_dF[I] = &declarePropertyDerivative<Real, is_ad>(
87 _F_name, std::vector<VariableName>{_var_name[first], _var_name[tail]...});
88 loopDeclareProperties<I + 1>(details::increment<N>(int_seq));
89 }
90 else
91 loopDeclareProperties<I>(details::increment<N>(int_seq));
92 }
93
98 {
100 loopDeclareProperties<0>(zeroes<MaxD>());
101 }
102
103 template <std::size_t I, typename T>
104 constexpr void loopEvaluate(const T &, std::index_sequence<>)
105 {
106 }
107 template <std::size_t I, typename T, std::size_t first, std::size_t... tail>
108 constexpr void loopEvaluate(const T & expression, std::index_sequence<first, tail...> int_seq)
109 {
111 if constexpr (is_sorted(int_seq))
112 {
113 (*_prop_dF[I])[_qp] = take_derivatives(expression, int_seq)();
114 loopEvaluate<I + 1>(expression, details::increment<N>(int_seq));
115 }
116 else
117 loopEvaluate<I>(expression, details::increment<N>(int_seq));
118 }
119};
120
121template <int N, bool is_ad, int MaxD>
124{
126 params.addRequiredParam<MaterialPropertyName>("property_name",
127 "Name of the parsed material property");
128 return params;
129}
130
131template <int N, bool is_ad, int MaxD>
133 const InputParameters & params, const std::array<std::string, N> variables)
135 _F_name(getParam<MaterialPropertyName>("property_name")),
136 _prop_F(declareGenericProperty<Real, is_ad>(_F_name)),
137 _refs(makeRefsTuple(variables, _qp, std::make_index_sequence<N>{}))
138{
139 // get the names of all coupled variables
140 for (const auto i : make_range(N))
141 _var_name[i] = coupledName(variables[i]);
142
143 // declare all material properties
144 declareProperties();
145}
146
147template <int N, bool is_ad, int MaxD>
148template <typename T>
149void
151{
152 _prop_F[_qp] = F();
154 loopEvaluate<0>(F, zeroes<MaxD>());
155}
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
Moose::GenericType< VariableValue, is_ad > GenericVariableValue
Definition MooseTypes.h:712
Material class to set up an expression and its derivatives built at compile time using the CompileTim...
void declareProperties()
Entry point for the compile time loop that declares all derivative material properties.
std::array< GenericMaterialProperty< Real, is_ad > *, CompileTimeDerivativesMaterialInternal::total_derivatives< MaxD, N >()> _prop_dF
A serialized list of material properties for all derivatives up to and including order MaxD.
auto makeRefsTuple(const std::array< std::string, N > &variables, const unsigned int &qp, std::index_sequence< Ns... >)
constexpr void loopEvaluate(const T &expression, std::index_sequence< first, tail... > int_seq)
constexpr void loopDeclareProperties(std::index_sequence<>)
void evaluate(const T &F)
Entry point for the compile time loop that evaluates all derivatives and assigns them to their respec...
constexpr void loopDeclareProperties(std::index_sequence< first, tail... > int_seq)
decltype(CompileTimeDerivativesMaterialInternal::make_tuple_array< GenericVariableValue< is_ad > >(std::make_index_sequence< N >{})) ::type _refs
Set up a tuple with one entry per coupled variable (each entry with an increment).
std::array< VariableName, N > _var_name
The names of the coupled variables.
CompileTimeDerivativesMaterial(const InputParameters &params, const std::array< std::string, N > variables)
constexpr void loopEvaluate(const T &, std::index_sequence<>)
GenericMaterialProperty< Real, is_ad > & _prop_F
Interface class ("Veneer") to provide generator methods for derivative material property names.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
unsigned int _qp
Materials compute MaterialProperties.
Definition Material.h:36
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
constexpr auto make_tuple_array(std::index_sequence< Ns... >)
Create a tuple with sizeof...(Ns) entries, containing CTArrayRefs with tags given by the Ns....