www.mooseframework.org
CreateDisplacedProblemAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 #include "MooseApp.h"
12 #include "FEProblem.h"
13 #include "DisplacedProblem.h"
14 #include "NonlinearSystem.h"
15 #include "AuxiliarySystem.h"
16 #include "RelationshipManager.h"
17 
18 registerMooseAction("MooseApp", CreateDisplacedProblemAction, "init_displaced_problem");
19 registerMooseAction("MooseApp", CreateDisplacedProblemAction, "add_geometric_rm");
20 registerMooseAction("MooseApp", CreateDisplacedProblemAction, "add_algebraic_rm");
21 
22 template <>
25 {
27  params.addParam<std::vector<std::string>>(
28  "displacements",
29  "The variables corresponding to the x y z displacements of the mesh. If "
30  "this is provided then the displacements will be taken into account during "
31  "the computation. Creation of the displaced mesh can be suppressed even if "
32  "this is set by setting 'use_displaced_mesh = false'.");
33  params.addParam<bool>(
34  "use_displaced_mesh",
35  true,
36  "Create the displaced mesh if the 'displacements' "
37  "parameter is set. If this is 'false', a displaced mesh will not be created, "
38  "regardless of whether 'displacements' is set.");
39 
40  return params;
41 }
42 
44  : Action(parameters)
45 {
46 }
47 
48 void
50  SystemBase & from)
51 {
52  auto rm_params = _factory.getValidParams("ProxyRelationshipManager");
53 
54  rm_params.set<bool>("attach_geometric_early") = false;
55  rm_params.set<MooseMesh *>("mesh") = &to.mesh();
56  rm_params.set<System *>("other_system") = &from.system();
57  rm_params.set<std::string>("for_whom") = "DisplacedMesh";
58  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
60 
61  rm_params.set<bool>("use_displaced_mesh") = to.subproblem().name() == "DisplacedProblem";
62 
63  if (rm_params.areAllRequiredParamsValid())
64  {
65  auto rm_obj = _factory.create<RelationshipManager>(
66  "ProxyRelationshipManager",
67  to.subproblem().name() + "<-" + from.subproblem().name() + "_" + from.system().name() +
68  "_algebraic_proxy",
69  rm_params);
70 
71  if (!_app.addRelationshipManager(rm_obj))
73  }
74  else
75  mooseError("Invalid initialization of ElementSideNeighborLayers");
76 }
77 
78 void
80  SystemBase & from)
81 {
82  auto rm_params = _factory.getValidParams("ProxyRelationshipManager");
83 
84  rm_params.set<bool>("attach_geometric_early") = false;
85  rm_params.set<MooseMesh *>("mesh") = &to.mesh();
86  rm_params.set<System *>("other_system") = &from.system();
87  rm_params.set<std::string>("for_whom") = "DisplacedMesh";
88  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
90 
91  rm_params.set<bool>("use_displaced_mesh") = to.subproblem().name() == "DisplacedProblem";
92 
93  if (rm_params.areAllRequiredParamsValid())
94  {
95  auto rm_obj = _factory.create<RelationshipManager>(
96  "ProxyRelationshipManager",
97  to.subproblem().name() + "<-" + from.subproblem().name() + "_" + from.system().name() +
98  "_geometric_proxy",
99  rm_params);
100 
101  if (!_app.addRelationshipManager(rm_obj))
103  }
104  else
105  mooseError("Invalid initialization of ElementSideNeighborLayers");
106 }
107 
108 void
110 {
111  if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
112  {
113  if (_current_task == "init_displaced_problem")
114  {
115  if (!_displaced_mesh)
116  mooseError("displacements were set but a displaced mesh wasn't created!");
117 
118  // Define the parameters
119  InputParameters object_params = _factory.getValidParams("DisplacedProblem");
120  object_params.set<std::vector<std::string>>("displacements") =
121  getParam<std::vector<std::string>>("displacements");
122  object_params.set<MooseMesh *>("mesh") = _displaced_mesh.get();
123  object_params.set<FEProblemBase *>("_fe_problem_base") = _problem.get();
124 
125  // Create the object
126  std::shared_ptr<DisplacedProblem> disp_problem =
127  _factory.create<DisplacedProblem>("DisplacedProblem", "DisplacedProblem", object_params);
128 
129  // Add the Displaced Problem to FEProblemBase
130  _problem->addDisplacedProblem(disp_problem);
131  }
132 
133  if (_current_task == "add_geometric_rm")
134  // We can't do anything at this time because the systems haven't been created
135  // but we do need to tell the mesh to hang onto extra elements just in case
136  _mesh->getMesh().allow_remote_element_removal(false);
137 
138  if (_current_task == "add_algebraic_rm")
139  {
140  auto & undisplaced_nl = _problem->getNonlinearSystemBase();
141  auto & undisplaced_aux = _problem->getAuxiliarySystem();
142 
143  auto displaced_problem_ptr = _problem->getDisplacedProblem();
144 
145  auto & displaced_nl = displaced_problem_ptr->nlSys();
146  auto & displaced_aux = displaced_problem_ptr->auxSys();
147 
148  // Note the "to" system doesn't actually matter much - the GF will
149  // get added to both systems on the receiving side
150  addProxyAlgebraicRelationshipManagers(undisplaced_nl, displaced_nl);
151  addProxyAlgebraicRelationshipManagers(displaced_nl, undisplaced_nl);
152 
153  addProxyAlgebraicRelationshipManagers(undisplaced_aux, displaced_aux);
154  addProxyAlgebraicRelationshipManagers(displaced_aux, undisplaced_aux);
155 
156  addProxyGeometricRelationshipManagers(undisplaced_nl, displaced_nl);
157  addProxyGeometricRelationshipManagers(displaced_nl, undisplaced_nl);
158 
159  // When adding the geometric relationship mangers we told the mesh not to allow remote element
160  // removal during the initial MeshBase::prepare_for_use call. If we're using a distributed
161  // mesh we need to make sure we now allow remote element removal and then delete the remote
162  // elmeents after the EquationSystems init
163  if (_mesh->isDistributedMesh())
164  {
165  _mesh->needsRemoteElemDeletion(true);
166  if (_displaced_mesh)
167  _displaced_mesh->needsRemoteElemDeletion(true);
168  }
169  }
170  }
171 }
bool isParamValid(const std::string &name) const
Definition: Action.h:115
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:87
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
void addProxyAlgebraicRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies algebraic ghosting from->to.
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: Action.h:224
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:186
Base class for a system (of equations)
Definition: SystemBase.h:92
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
registerMooseAction("MooseApp", CreateDisplacedProblemAction, "init_displaced_problem")
Base class for actions.
Definition: Action.h:35
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:1692
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:213
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
void addProxyGeometricRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies geometric ghosting from->to.
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:210
virtual SubProblem & subproblem()
Definition: SystemBase.h:105
virtual System & system()=0
Get the reference to the libMesh system.
void releaseSharedObjects(const MooseObject &moose_object, THREAD_ID tid=0)
Releases any shared resources created as a side effect of creating an object through the Factory::cre...
Definition: Factory.C:166
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:212
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
virtual MooseMesh & mesh()
Definition: SystemBase.h:103
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
InputParameters validParams< CreateDisplacedProblemAction >()
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
InputParameters validParams< Action >()
Definition: Action.C:22
CreateDisplacedProblemAction(InputParameters parameters)