https://mooseframework.inl.gov
CommonSolidMechanicsAction.C
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 
12 #include "ActionWarehouse.h"
13 #include "FEProblemBase.h"
14 #include "Factory.h"
15 
16 registerMooseAction("SolidMechanicsApp", CommonSolidMechanicsAction, "meta_action");
17 
18 registerMooseAction("SolidMechanicsApp", CommonSolidMechanicsAction, "add_variable");
19 
22 {
24  params.addClassDescription("Store common solid mechanics parameters");
25  return params;
26 }
27 
29  : Action(parameters)
30 {
31 }
32 
33 void
35 {
36 
37  // check if sub-blocks block are found which will use the common parameters
39  if (actions.size() == 0)
40  mooseWarning("Common parameters are supplied, but not used in ", parameters().blockLocation());
41 
42  // Add disp-variables
43  if (_current_task == "add_variable")
44  {
45  // We set these variables first with the "common" (not nested) level parameters
46  bool do_add_variables = getParam<bool>("add_variables");
47  auto displacement_variables = getParam<std::vector<VariableName>>("displacements");
48  bool add_variables_block_restricted = true;
49  std::set<SubdomainName> add_variables_blocks;
50  bool scaling_set = isParamValid("scaling");
51  Real scaling_value = (scaling_set) ? getParam<Real>("scaling") : 1.0;
52 
53  // Check all nested sub-actions and update the variables keeping track of each selection
54  for (const auto & action : actions)
55  {
56  if (action->getParam<bool>("add_variables"))
57  {
58  // this sub-action wants the disp-variables added.
59  do_add_variables = true;
60  const auto v = action->getParam<std::vector<VariableName>>("displacements");
61  if (v.size() > 0)
62  {
63  if (displacement_variables.size() == 0)
64  displacement_variables.insert(displacement_variables.end(), v.begin(), v.end());
65  else if (displacement_variables != v)
66  paramError("displacements",
67  "The vector of displacement variables of the actions differ.");
68  }
69 
70  // with block-restriction?
71  if (add_variables_block_restricted && action->isParamValid("block") &&
72  action->getParam<std::vector<SubdomainName>>("block").size())
73  {
74  auto action_blocks = action->getParam<std::vector<SubdomainName>>("block");
75  mooseAssert(action_blocks.size(), "Block restriction must not be empty");
76  add_variables_blocks.insert(action_blocks.cbegin(), action_blocks.cend());
77  }
78  else
79  add_variables_block_restricted = false;
80 
81  // scaling?
82  if (action->getParam<bool>("add_variables") && action->isParamValid("scaling"))
83  {
84  const auto scaling = action->getParam<Real>("scaling");
85 
86  // sanity-check
87  if (scaling_set && scaling_value != scaling)
88  paramError("scaling", "The scaling parameter of the actions differ.");
89 
90  // set local scaling variables
91  scaling_set = true;
92  scaling_value = scaling;
93  }
94  }
95  }
96 
97  // add the disp-variables, if desired
98  if (do_add_variables)
99  {
100  auto params = _factory.getValidParams("MooseVariable");
101  // determine necessary order
102  const bool second = _problem->mesh().hasSecondOrderElements();
103 
104  params.set<MooseEnum>("order") = second ? "SECOND" : "FIRST";
105  params.set<MooseEnum>("family") = "LAGRANGE";
106  if (add_variables_block_restricted && add_variables_blocks.size() > 0)
107  {
108  std::vector<SubdomainName> blks(add_variables_blocks.begin(), add_variables_blocks.end());
109  params.set<std::vector<SubdomainName>>("block") = blks;
110  }
111  if (scaling_set && scaling_value != 1)
112  params.set<std::vector<Real>>("scaling") = {scaling_value};
113 
114  // Loop through the displacement variables
115  const auto n = displacement_variables.size();
116  if (n == 0)
117  paramError("displacements", "The vector of displacement variables is not set.");
118  if (n != _problem->mesh().dimension())
119  paramError("displacements",
120  "The number of displacement variables differs from the number of dimensions of "
121  "the mesh.");
122 
123  for (const auto & disp : displacement_variables)
124  // Create displacement variables
125  _problem->addVariable("MooseVariable", disp, params);
126  }
127  }
128 }
ActionWarehouse & _awh
InputParameters getValidParams(const std::string &name) const
Store common tensor mechanics parameters.
void mooseWarning(Args &&... args) const
bool isParamValid(const std::string &name) const
Factory & _factory
CommonSolidMechanicsAction(const InputParameters &parameters)
const std::string & _current_task
void paramError(const std::string &param, Args... args) const
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
registerMooseAction("SolidMechanicsApp", CommonSolidMechanicsAction, "meta_action")
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
std::string blockLocation() const
std::vector< const T *> getActions()