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 registerMooseAction("MooseApp", CreateDisplacedProblemAction, "add_coupling_rm");
22 
25 {
27  params.addClassDescription("Create a Problem object that utilizes displacements.");
28  params.addParam<std::vector<std::string>>(
29  "displacements",
30  "The variables corresponding to the x y z displacements of the mesh. If "
31  "this is provided then the displacements will be taken into account during "
32  "the computation. Creation of the displaced mesh can be suppressed even if "
33  "this is set by setting 'use_displaced_mesh = false'.");
34  params.addParam<bool>(
35  "use_displaced_mesh",
36  true,
37  "Create the displaced mesh if the 'displacements' "
38  "parameter is set. If this is 'false', a displaced mesh will not be created, "
39  "regardless of whether 'displacements' is set.");
40 
41  return params;
42 }
43 
45  : Action(parameters)
46 {
47 }
48 
49 void
51  SystemBase & from,
53  std::string type)
54 {
55  // We do not need to create a geometric proxy RM. There are two reasons:
56  // 1. Based on the old logic, a 'attach_geometric_early=false' geometric RM
57  // never be attached to libMesh side
58  // 2. There is always an algebraic version of this RM.
60  return;
61 
62  auto rm_params = _factory.getValidParams("ProxyRelationshipManager");
63 
64  rm_params.set<bool>("attach_geometric_early") = false;
65  rm_params.set<MooseMesh *>("mesh") = &to.mesh();
66  rm_params.set<System *>("other_system") = &from.system();
67  rm_params.set<std::string>("for_whom") = "DisplacedMesh";
68  rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
69 
70  rm_params.set<bool>("use_displaced_mesh") = to.subproblem().name() == "DisplacedProblem";
71 
72  if (rm_params.areAllRequiredParamsValid())
73  {
74  auto rm_obj = _factory.create<RelationshipManager>(
75  "ProxyRelationshipManager",
76  to.subproblem().name() + "<-" + from.subproblem().name() + "_" + from.system().name() +
77  "_" + type + "_proxy",
78  rm_params);
79 
80  if (!_app.addRelationshipManager(rm_obj))
82  }
83  else
84  mooseError("Invalid initialization of ProxyRelationshipManager");
85 }
86 
87 void
89  SystemBase & from)
90 {
92 }
93 
94 void
96  SystemBase & from)
97 {
99 }
100 
101 void
103 {
104  if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
105  {
106  if (_current_task == "init_displaced_problem")
107  {
108  if (!_displaced_mesh)
109  mooseError("displacements were set but a displaced mesh wasn't created!");
110 
111  // Define the parameters
112  InputParameters object_params = _factory.getValidParams("DisplacedProblem");
113  object_params.set<std::vector<std::string>>("displacements") =
114  getParam<std::vector<std::string>>("displacements");
115  object_params.set<MooseMesh *>("mesh") = _displaced_mesh.get();
116  object_params.set<FEProblemBase *>("_fe_problem_base") = _problem.get();
117  object_params.set<bool>("default_ghosting") = _problem->defaultGhosting();
118 
119  // Create the object
120  std::shared_ptr<DisplacedProblem> disp_problem =
121  _factory.create<DisplacedProblem>("DisplacedProblem", "DisplacedProblem", object_params);
122 
123  // Add the Displaced Problem to FEProblemBase
124  _problem->addDisplacedProblem(disp_problem);
125  }
126 
127  if (_current_task == "add_geometric_rm")
128  {
129  if (_mesh->getMeshPtr())
130  mooseError(
131  "We should be adding geometric rms so early that we haven't set our MeshBase yet");
132 
133  _mesh->allowRemoteElementRemoval(false);
134  // Displaced mesh should not exist yet
135  }
136 
137  if (_current_task == "add_algebraic_rm")
138  {
139  if (!_displaced_mesh)
140  mooseError("We should have created a displaced mesh by now");
141 
142  auto displaced_problem_ptr = _problem->getDisplacedProblem();
143 
144  for (const auto i : make_range(_problem->numNonlinearSystems()))
145  {
146  auto & undisplaced_nl = _problem->getNonlinearSystemBase(i);
147  auto & displaced_nl = displaced_problem_ptr->nlSys(i);
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 
154  auto & undisplaced_aux = _problem->getAuxiliarySystem();
155  auto & displaced_aux = displaced_problem_ptr->auxSys();
156 
157  // Note that there is no reason to copy coupling factors back and forth because the displaced
158  // systems do not have their own matrices (they are constructed with their libMesh::System of
159  // type TransientExplicitSystem)
160 
161  // Note the "to" system doesn't actually matter much - the GF will
162  // get added to both systems on the receiving side
163  addProxyAlgebraicRelationshipManagers(undisplaced_aux, displaced_aux);
164  addProxyAlgebraicRelationshipManagers(displaced_aux, undisplaced_aux);
165 
166  // Add geoemtric ghosting (which only acts through the mesh) through the single auxiliary
167  // system as opposed to duplicating the effort through potentially multiple nonlinear systems
168  addProxyGeometricRelationshipManagers(undisplaced_aux, displaced_aux);
169  addProxyGeometricRelationshipManagers(displaced_aux, undisplaced_aux);
170 
171  // When adding the geometric relationship mangers we told the mesh not to allow remote element
172  // removal during the initial MeshBase::prepare_for_use call. Verify that we did indeed tell
173  // the mesh that
174  if (_mesh->allowRemoteElementRemoval() || _displaced_mesh->allowRemoteElementRemoval())
175  mooseError("We should not have been allowing remote element deletion prior to the addition "
176  "of late geometric ghosting functors");
177  }
178  }
179 }
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:876
void addProxyAlgebraicRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies algebraic ghosting from->to.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const 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:86
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:67
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for a system (of equations)
Definition: SystemBase.h:84
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
registerMooseAction("MooseApp", CreateDisplacedProblemAction, "init_displaced_problem")
Base class for actions.
Definition: Action.h:38
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Factory & _factory
The Factory associated with the MooseApp.
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:2348
static InputParameters validParams()
Definition: Action.C:23
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:148
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
void addProxyGeometricRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies geometric ghosting from->to.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:50
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:145
virtual SubProblem & subproblem()
Definition: SystemBase.h:98
virtual System & system()=0
Get the reference to the libMesh system.
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:69
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:164
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:147
CreateDisplacedProblemAction(const InputParameters &parameters)
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
void addProxyRelationshipManagers(SystemBase &to, SystemBase &from, Moose::RelationshipManagerType rm_type, std::string type)
Generic adder of ProxyRelationshipManagers.
virtual MooseMesh & mesh()
Definition: SystemBase.h:96
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:151
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...