19#include "libmesh/fe.h"
20#include "libmesh/string_to_enum.h"
31 "Action for setting up the necessary objects for debugging material property derivatives.");
32 params.
addParam<std::vector<VariableName>>(
"args",
33 "Variables the tested material property depends on.");
35 "prop_name",
"Name of the material property to test the derivatives of.");
36 MooseEnum prop_type_enum(
"Real RankTwoTensor RankFourTensor");
38 "prop_type", prop_type_enum,
"Type of the material property to test the derivatives of.");
40 "derivative_order", 0,
"Highest order derivative to test derivatives of.");
46 _args(getParam<
std::vector<VariableName>>(
"args")),
47 _prop_name(getParam<MaterialPropertyName>(
"prop_name")),
49 _derivative_order(getParam<unsigned
int>(
"derivative_order")),
53 std::vector<std::vector<std::vector<SymbolName>>> derivative_table(_derivative_order + 1);
56 derivative_table[0] = {{}};
59 for (
unsigned int n = 1; n <= _derivative_order; ++n)
60 for (
const auto & function : derivative_table[n - 1])
61 for (const auto & var : _args)
64 auto derivative = std::vector<SymbolName>(function);
65 derivative.push_back(var);
68 derivative_table[n].push_back(derivative);
70 std::make_pair(derivativePropertyName(_prop_name, derivative), derivative));
78 const std::string order =
_second ?
"SECOND" :
"FIRST";
79 const std::string family(
"LAGRANGE");
80 const auto type =
"MooseVariable";
94 _problem->addVariable(
type,
"var_" + derivative.first, params);
98 for (
unsigned int i = 0; i < 3; ++i)
99 for (
unsigned int j = 0; j < 3; ++j)
107 for (
unsigned int i = 0; i < 3; ++i)
108 for (
unsigned int j = 0; j < 3; ++j)
109 for (
unsigned int k = 0; k < 3; ++k)
110 for (
unsigned int l = 0; l < 3; ++l)
130 params.
set<std::vector<VariableName>>(
"coupled_variables") =
_args;
131 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
132 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
133 params.set<NonlinearVariableName>(
"variable") =
"var_" + derivative.first;
134 _problem->addKernel(
"MaterialDerivativeTestKernel",
"kernel_" + derivative.first, params);
141 params.
set<std::vector<VariableName>>(
"coupled_variables") =
_args;
142 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
143 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
144 for (
unsigned int i = 0; i < 3; ++i)
145 for (
unsigned int j = 0; j < 3; ++j)
149 params.set<NonlinearVariableName>(
"variable") =
"var_" + suffix;
150 params.set<
unsigned int>(
"i") = i;
151 params.set<
unsigned int>(
"j") = j;
153 "MaterialDerivativeRankTwoTestKernel",
"kernel_" + suffix, params);
161 params.
set<std::vector<VariableName>>(
"coupled_variables") =
_args;
162 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
163 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
164 for (
unsigned int i = 0; i < 3; ++i)
165 for (
unsigned int j = 0; j < 3; ++j)
166 for (
unsigned int k = 0; k < 3; ++k)
167 for (
unsigned int l = 0; l < 3; ++l)
172 params.set<NonlinearVariableName>(
"variable") =
"var_" + suffix;
173 params.set<
unsigned int>(
"i") = i;
174 params.set<
unsigned int>(
"j") = j;
175 params.set<
unsigned int>(
"k") = k;
176 params.set<
unsigned int>(
"l") = l;
178 "MaterialDerivativeRankFourTestKernel",
"kernel_" + suffix, params);
192 auto & row = params.
set<std::vector<NonlinearVariableName>>(
"off_diag_row");
193 auto & col = params.set<std::vector<NonlinearVariableName>>(
"off_diag_column");
200 for (
auto & arg :
_args)
202 row.push_back(
"var_" + derivative.first);
208 for (
unsigned int i = 0; i < 3; ++i)
209 for (
unsigned int j = 0; j < 3; ++j)
210 for (
auto & arg :
_args)
219 for (
unsigned int i = 0; i < 3; ++i)
220 for (
unsigned int j = 0; j < 3; ++j)
221 for (
unsigned int k = 0; k < 3; ++k)
222 for (
unsigned int l = 0; l < 3; ++l)
223 for (
auto & arg :
_args)
239 std::shared_ptr<MoosePreconditioner> pc =
242 _problem->getNonlinearSystemBase(0).setPreconditioner(pc);
245 mooseError(
"_problem.get() returned nullptr");
registerMooseAction("CombinedTestApp", MaterialDerivativeTestAction, "add_variable")
for(PetscInt i=0;i< nvars;++i)
void ErrorVector unsigned int
static InputParameters validParams()
std::shared_ptr< FEProblemBase > & _problem
const std::string & _current_task
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
InputParameters getValidParams(const std::string &name) const
Sets up variables and Kernels to test the derivatives of material properties via the Jacobian checker...
std::map< MaterialPropertyName, std::vector< SymbolName > > _derivatives
every derivative given by a list of variables to derive w.r.t
static InputParameters validParams()
enum MaterialDerivativeTestAction::PropTypeEnum _prop_type
virtual void act() override
std::vector< VariableName > _args
MaterialDerivativeTestAction(const InputParameters ¶meters)
MaterialPropertyName _prop_name
const std::string & type() const
void mooseError(Args &&... args) const
std::string stringify(const T &t)