19 #include "libmesh/fe.h" 20 #include "libmesh/string_to_enum.h" 33 "Action for setting up the necessary objects for debugging material property derivatives.");
34 params.
addParam<std::vector<VariableName>>(
"args",
35 "Variables the tested material property depends on.");
37 "prop_name",
"Name of the material property to test the derivatives of.");
38 MooseEnum prop_type_enum(
"Real RankTwoTensor RankFourTensor");
40 "prop_type", prop_type_enum,
"Type of the material property to test the derivatives of.");
42 "derivative_order", 0,
"Highest order derivative to test derivatives of.");
48 _args(getParam<
std::vector<VariableName>>(
"args")),
49 _prop_name(getParam<MaterialPropertyName>(
"prop_name")),
51 _derivative_order(getParam<unsigned
int>(
"derivative_order")),
55 std::vector<std::vector<std::vector<SymbolName>>> derivative_table(_derivative_order + 1);
58 derivative_table[0] = {{}};
61 for (
unsigned int n = 1; n <= _derivative_order; ++n)
62 for (
const auto &
function : derivative_table[n - 1])
63 for (
const auto & var : _args)
66 auto derivative = std::vector<SymbolName>(
function);
70 derivative_table[n].push_back(derivative);
72 std::make_pair(derivativePropertyName(_prop_name, derivative), derivative));
80 const std::string order =
_second ?
"SECOND" :
"FIRST";
81 const std::string family(
"LAGRANGE");
82 const auto type =
"MooseVariable";
96 _problem->addVariable(
type,
"var_" + derivative.first, params);
100 for (
unsigned int i = 0; i < 3; ++i)
101 for (
unsigned int j = 0; j < 3; ++j)
109 for (
unsigned int i = 0; i < 3; ++i)
110 for (
unsigned int j = 0; j < 3; ++j)
111 for (
unsigned int k = 0; k < 3; ++k)
112 for (
unsigned int l = 0; l < 3; ++l)
132 params.
set<std::vector<VariableName>>(
"args") =
_args;
133 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
134 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
135 params.set<NonlinearVariableName>(
"variable") =
"var_" + derivative.first;
136 _problem->addKernel(
"MaterialDerivativeTestKernel",
"kernel_" + derivative.first, params);
143 params.
set<std::vector<VariableName>>(
"args") =
_args;
144 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
145 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
146 for (
unsigned int i = 0; i < 3; ++i)
147 for (
unsigned int j = 0; j < 3; ++j)
151 params.set<NonlinearVariableName>(
"variable") =
"var_" + suffix;
152 params.set<
unsigned int>(
"i") = i;
153 params.set<
unsigned int>(
"j") = j;
155 "MaterialDerivativeRankTwoTestKernel",
"kernel_" + suffix, params);
163 params.
set<std::vector<VariableName>>(
"args") =
_args;
164 params.set<std::vector<SymbolName>>(
"derivative") = derivative.second;
165 params.set<MaterialPropertyName>(
"material_property") =
_prop_name;
166 for (
unsigned int i = 0; i < 3; ++i)
167 for (
unsigned int j = 0; j < 3; ++j)
168 for (
unsigned int k = 0; k < 3; ++k)
169 for (
unsigned int l = 0; l < 3; ++l)
174 params.set<NonlinearVariableName>(
"variable") =
"var_" + suffix;
175 params.set<
unsigned int>(
"i") = i;
176 params.set<
unsigned int>(
"j") = j;
177 params.set<
unsigned int>(
"k") = k;
178 params.set<
unsigned int>(
"l") = l;
180 "MaterialDerivativeRankFourTestKernel",
"kernel_" + suffix, params);
194 auto & row = params.
set<std::vector<NonlinearVariableName>>(
"off_diag_row");
195 auto & col = params.set<std::vector<NonlinearVariableName>>(
"off_diag_column");
202 for (
auto & arg :
_args)
204 row.push_back(
"var_" + derivative.first);
210 for (
unsigned int i = 0; i < 3; ++i)
211 for (
unsigned int j = 0; j < 3; ++j)
212 for (
auto & arg :
_args)
221 for (
unsigned int i = 0; i < 3; ++i)
222 for (
unsigned int j = 0; j < 3; ++j)
223 for (
unsigned int k = 0; k < 3; ++k)
224 for (
unsigned int l = 0; l < 3; ++l)
225 for (
auto & arg :
_args)
241 std::shared_ptr<MoosePreconditioner> pc =
244 _problem->getNonlinearSystemBase(0).setPreconditioner(pc);
247 mooseError(
"_problem.get() returned nullptr");
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
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
Get valid parameters for the object.
registerMooseAction("MooseApp", MaterialDerivativeTestAction, "add_variable")
Base class for MOOSE preconditioners.
Factory & _factory
The Factory associated with the MooseApp.
static InputParameters validParams()
static InputParameters validParams()
const std::string & type() const
Get the type of this class.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
const std::string & _current_task
The current action (even though we have separate instances for each action)
std::string stringify(const T &t)
conversion to string
std::vector< VariableName > _args
MaterialDerivativeTestAction(const InputParameters ¶meters)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
MaterialPropertyName _prop_name
enum MaterialDerivativeTestAction::PropTypeEnum _prop_type
void ErrorVector unsigned int
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.