https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CreateDisplacedProblemAction.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
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
18registerMooseAction("MooseApp", CreateDisplacedProblemAction, "init_displaced_problem");
19registerMooseAction("MooseApp", CreateDisplacedProblemAction, "add_geometric_rm");
20registerMooseAction("MooseApp", CreateDisplacedProblemAction, "add_algebraic_rm");
21registerMooseAction("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
48
49void
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
87void
93
94void
100
101void
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())
131 "We should be adding geometric rms so early that we haven't set our MeshBase yet");
132
133 _mesh->allowRemoteElementRemoval(false);
134 mooseAssert(!_displaced_mesh, "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->solverSys(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 geometric 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}
registerMooseAction("MooseApp", CreateDisplacedProblemAction, "init_displaced_problem")
Base class for actions.
Definition Action.h:38
std::shared_ptr< MooseMesh > & _mesh
Definition Action.h:174
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition Action.h:175
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
void addProxyAlgebraicRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies algebraic ghosting from->to.
void addProxyRelationshipManagers(SystemBase &to, SystemBase &from, Moose::RelationshipManagerType rm_type, std::string type)
Generic adder of ProxyRelationshipManagers.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void addProxyGeometricRelationshipManagers(SystemBase &to, SystemBase &from)
Sets up a ProxyRelationshipManager that copies geometric ghosting from->to.
CreateDisplacedProblemAction(const InputParameters &parameters)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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)
Definition Factory.C:142
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
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:156
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition MooseApp.C:2991
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
Factory & _factory
The Factory associated with the MooseApp.
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
Base class for a system (of equations)
Definition SystemBase.h:87
SubProblem & subproblem()
Definition SystemBase.h:102
MooseMesh & mesh()
Definition SystemBase.h:100
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
const std::string & name() const
RelationshipManagerType
Main types of Relationship Managers.