www.mooseframework.org
DisplacementGradientsAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 #include "Factory.h"
9 #include "FEProblem.h"
10 
11 #include "libmesh/string_to_enum.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<Action>();
18  params.addClassDescription("Set up variables, kernels, and materials for a the displacement "
19  "gradients and their elastic free energy derivatives for non-split "
20  "Cahn-Hilliard problems.");
21  params.addRequiredParam<std::vector<VariableName>>("displacements",
22  "Vector of displacement variables");
23  params.addRequiredParam<std::vector<VariableName>>("displacement_gradients",
24  "Vector of displacement gradient variables");
25  params.addParam<Real>(
26  "scaling", 1.0, "Specifies a scaling factor to apply to the displacement gradient variables");
27  return params;
28 }
29 
31  : Action(params),
32  _displacements(getParam<std::vector<VariableName>>("displacements")),
33  _displacement_gradients(getParam<std::vector<VariableName>>("displacement_gradients"))
34 {
35 }
36 
37 void
39 {
40  unsigned int ngrad = _displacement_gradients.size();
41 
42  if (_current_task == "add_variable")
43  {
44  // Loop through the gij variables
45  Real scaling = getParam<Real>("scaling");
46  for (unsigned int i = 0; i < ngrad; ++i)
47  {
48  // Create displacement gradient variables
49  _problem->addVariable(_displacement_gradients[i],
50  FEType(Utility::string_to_enum<Order>("FIRST"),
51  Utility::string_to_enum<FEFamily>("LAGRANGE")),
52  scaling);
53  }
54  }
55  else if (_current_task == "add_material")
56  {
57  InputParameters params = _factory.getValidParams("StrainGradDispDerivatives");
58  params.set<std::vector<VariableName>>("displacement_gradients") = _displacement_gradients;
59  params.set<std::vector<SubdomainName>>("block") = {"0"}; // TODO: add parameter for this
60  _problem->addMaterial("StrainGradDispDerivatives", "strain_grad_disp_derivatives", params);
61  }
62  else if (_current_task == "add_kernel")
63  {
64  unsigned int ndisp = _displacements.size();
65  if (ndisp * ndisp != ngrad)
66  mooseError("Number of displacement gradient variables must be the square of the number of "
67  "displacement variables.");
68 
69  // Loop through the displacements
70  unsigned int i = 0;
71  for (unsigned int j = 0; j < ndisp; ++j)
72  for (unsigned int k = 0; k < ndisp; ++k)
73  {
74  InputParameters params = _factory.getValidParams("GradientComponent");
75  params.set<NonlinearVariableName>("variable") = _displacement_gradients[i];
76  params.set<std::vector<VariableName>>("v") = {_displacements[j]};
77  params.set<unsigned int>("component") = k;
78  _problem->addKernel(
79  "GradientComponent", _displacement_gradients[i] + "_grad_kernel", params);
80  ++i;
81  }
82  }
83  else
84  mooseError("Internal error.");
85 }
DisplacementGradientsAction(const InputParameters &params)
InputParameters validParams< DisplacementGradientsAction >()
std::vector< VariableName > _displacements
std::vector< VariableName > _displacement_gradients