https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SetupMeshCompleteAction.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 "MooseMesh.h"
12#include "Moose.h"
13#include "Adaptivity.h"
14#include "MooseApp.h"
15#include "FEProblemBase.h"
16
17registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh");
18
21 "delete_remote_elements_after_late_geometric_ghosting");
22
23registerMooseAction("MooseApp", SetupMeshCompleteAction, "uniform_refine_mesh");
24
25registerMooseAction("MooseApp", SetupMeshCompleteAction, "setup_mesh_complete");
26
27registerMooseAction("MooseApp", SetupMeshCompleteAction, "post_mesh_prepared");
28
31{
33 params.addClassDescription("Perform operations on the mesh in preparation for a simulation.");
34
35 params.addParam<std::vector<std::string>>(
36 "displacements",
37 "The variables corresponding to the x y z displacements of the mesh. If "
38 "this is provided then the displacements will be taken into account during "
39 "the computation. Creation of the displaced mesh can be suppressed even if "
40 "this is set by setting 'use_displaced_mesh = false'.");
41 params.addParam<bool>(
42 "use_displaced_mesh",
43 true,
44 "Create the displaced mesh if the 'displacements' "
45 "parameter is set. If this is 'false', a displaced mesh will not be created, "
46 "regardless of whether 'displacements' is set.");
47
48 return params;
49}
50
52
53void
55{
56 if (!_mesh)
57 mooseError("No mesh file was supplied and no generation block was provided");
58
59 if (_current_task == "uniform_refine_mesh")
60 {
61 // we don't need to run mesh modifiers *again* after they ran already during the mesh
62 // splitting process
63 // A uniform refinement is helpful for some instances when using a pre-split mesh.
64 // For example, a 'coarse' mesh might completely resolve geometry (also is large)
65 // but does not have enough resolution for the interior. For this scenario,
66 // we pre-split the coarse mesh, and load the pre-split mesh in parallel,
67 // and then do a few levels of uniform refinements to have a fine mesh that
68 // potentially resolves physics features.
69 if (_mesh->isSplit() && _mesh->skipRefineWhenUseSplit())
70 return;
71
72 // uniform refinement has been done on master, so skip
73 if (_app.useMasterMesh())
74 return;
75
82 if (_app.getExodusFileRestart() == false)
83 {
84 if (_app.isRecovering() == false || !_app.isUltimateMaster())
85 {
86 TIME_SECTION("uniformRefine", 2, "Uniformly Refining");
87
88 if (_mesh->uniformRefineLevel())
89 {
90 if (!_mesh->interiorLowerDBlocks().empty() || !_mesh->boundaryLowerDBlocks().empty())
91 mooseError("HFEM does not support mesh uniform refinement currently.");
92
94 // After refinement we need to make sure that all of our MOOSE-specific containers are
95 // up-to-date
96 _mesh->meshChanged();
97 }
98 }
99 }
100 }
101 else if (_current_task == "delete_remote_elements_after_late_geometric_ghosting")
102 {
103 TIME_SECTION("deleteRemoteElems", 2, "Deleting Remote Elements");
104
105 if (_displaced_mesh &&
106 (_mesh->needsRemoteElemDeletion() != _displaced_mesh->needsRemoteElemDeletion()))
107 mooseError("Our reference and displaced meshes are not in sync with respect to whether we "
108 "should delete remote elements.");
109
110 // We currently only trigger the needsRemoteDeletion flag if somebody has requested a late
111 // geometric ghosting functor and/or we have a displaced mesh
112 if (_mesh->needsRemoteElemDeletion())
113 {
114 // Must make sure to create the mortar meshes to build our data structures that ensure we will
115 // keep the correct elements in the mesh around
116 _problem->updateMortarMesh();
117 _mesh->deleteRemoteElements();
118 if (_displaced_mesh)
119 _displaced_mesh->deleteRemoteElements();
120 }
121 }
122 else if (_current_task == "post_mesh_prepared")
123 {
124 // The reference mesh's geometry and topology are finalized by this point, so this is the single
125 // point where the displaced mesh is created: a clone of the finished reference mesh. The
126 // displaced mesh must be an exact copy of the reference mesh, and complete_preparation() (which
127 // may perform partitioning) run separately on two previously-identical meshes can produce
128 // different results (we've seen this even with Metis partitioning), so cloning is the only way
129 // to guarantee the meshes are identical. Mesh preparation, including partitioning, is deferred
130 // until the split_mesh task when splitting a mesh (--split-mesh), so the reference mesh may
131 // still be unprepared here in that case; that's fine because such runs have no displaced mesh
132 // to create either.
133 if (_app.useMasterMesh())
134 {
137 }
138 else if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
139 {
140 TIME_SECTION("constructDisplacedMesh", 2, "Constructing Displaced Mesh");
141
142 mooseAssert(_mesh->prepared(), "The reference mesh should already be fully prepared here");
143 _displaced_mesh = _mesh->safeClone();
144 _displaced_mesh->isDisplaced(true);
145
146 const auto & displacements = getParam<std::vector<std::string>>("displacements");
147 if (displacements.size() < _mesh->dimension())
148 mooseError("Number of displacements must be greater than or equal to the dimension of "
149 "the mesh!");
150 }
151 }
152 else
153 {
154 TIME_SECTION("completeSetupUndisplaced", 2, "Setting Up Undisplaced Mesh");
155 _mesh->prepare();
156 }
157}
registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh")
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
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition Adaptivity.C:301
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.
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition MooseApp.h:866
bool getExodusFileRestart() const
Whether or not we need to use a separate Exodus reader to read the mesh BEFORE we create the mesh.
Definition MooseApp.h:436
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition MooseApp.C:1674
const MooseMesh * masterDisplacedMesh() const
Returns a pointer to the master displaced mesh.
Definition MooseApp.h:881
bool useMasterMesh() const
Returns whether to use the parent app mesh as the mesh for this app.
Definition MooseApp.h:871
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
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
virtual std::unique_ptr< MooseMesh > safeClone() const =0
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer.
static InputParameters validParams()
SetupMeshCompleteAction(const InputParameters &params)
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.