https://mooseframework.inl.gov
CavityPressureAction.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 
10 #include "CavityPressureAction.h"
11 #include "Factory.h"
12 #include "FEProblem.h"
13 #include "Conversion.h"
14 
15 registerMooseAction("SolidMechanicsApp", CavityPressureAction, "add_bc");
16 
19 {
21  params.addRequiredParam<std::vector<BoundaryName>>(
22  "boundary", "The list of boundary IDs from the mesh where the pressure will be applied");
23  params.addRequiredParam<std::vector<VariableName>>("displacements",
24  "The nonlinear displacement variables");
25  params.addParam<std::vector<AuxVariableName>>(
26  "save_in", {}, "Auxiliary variables to save the displacement residuals");
27  params.addParam<std::string>("output", "The name to use for the cavity pressure value");
28  params.addParam<bool>(
29  "use_displaced_mesh", true, "Whether to use displaced mesh in the boundary condition");
30  params.addParam<bool>("use_automatic_differentiation",
31  false,
32  "Flag to use automatic differentiation (AD) objects when possible");
33  params.addParam<std::vector<TagName>>("extra_vector_tags",
34  "The extra tags for the vectors this Kernel should fill");
35  params.addParam<std::vector<TagName>>(
36  "absolute_value_vector_tags",
37  "The tags for the vectors this residual object should fill with the "
38  "absolute value of the residual contribution");
39  params.addClassDescription("Action to setup cavity pressure boundary condition");
40  return params;
41 }
42 
44  : Action(params), _use_ad(getParam<bool>("use_automatic_differentiation"))
45 {
46 }
47 
48 void
50 {
51  auto displacements = getParam<std::vector<VariableName>>("displacements");
52  auto save_in = getParam<std::vector<AuxVariableName>>("save_in");
53 
54  unsigned int ndisp = displacements.size();
55  if (save_in.size() > 0 && save_in.size() != ndisp)
56  mooseError("Number of save_in variables should equal to the number of displacement variables ",
57  ndisp);
58 
59  std::string ad_prepend = "";
60  if (_use_ad)
61  ad_prepend = "AD";
62 
63  std::string kernel_name = ad_prepend + "Pressure";
64 
65  InputParameters params = _factory.getValidParams(kernel_name);
66  params.applyParameters(parameters());
67 
68  params.set<PostprocessorName>("postprocessor") =
69  isParamValid("output") ? getParam<std::string>("output") : _name;
70 
71  for (unsigned int i = 0; i < ndisp; ++i)
72  {
73  params.set<NonlinearVariableName>("variable") = displacements[i];
74  if (!save_in.empty())
75  params.set<std::vector<AuxVariableName>>("save_in") = {save_in[i]};
76  std::string unique_kernel_name = _name + "_" + Moose::stringify(i);
77 
78  _problem->addBoundaryCondition(kernel_name, unique_kernel_name, params);
79  }
80 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
CavityPressureAction(const InputParameters &params)
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Factory & _factory
static InputParameters validParams()
registerMooseAction("SolidMechanicsApp", CavityPressureAction, "add_bc")
std::string stringify(const T &t)
const std::string _name
const bool _use_ad
Flag to use automatic differentiation where possible.
virtual void act() override
static InputParameters validParams()
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const