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
17#include "libmesh/periodic_boundaries.h"
18
19registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh");
20
23 "delete_remote_elements_after_late_geometric_ghosting");
24
25registerMooseAction("MooseApp", SetupMeshCompleteAction, "uniform_refine_mesh");
26
27registerMooseAction("MooseApp", SetupMeshCompleteAction, "setup_mesh_complete");
28
29registerMooseAction("MooseApp", SetupMeshCompleteAction, "post_mesh_prepared");
30
33{
35 params.addClassDescription("Perform operations on the mesh in preparation for a simulation.");
36
37 params.addParam<std::vector<std::string>>(
38 "displacements",
39 "The variables corresponding to the x y z displacements of the mesh. If "
40 "this is provided then the displacements will be taken into account during "
41 "the computation. Creation of the displaced mesh can be suppressed even if "
42 "this is set by setting 'use_displaced_mesh = false'.");
43 params.addParam<bool>(
44 "use_displaced_mesh",
45 true,
46 "Create the displaced mesh if the 'displacements' "
47 "parameter is set. If this is 'false', a displaced mesh will not be created, "
48 "regardless of whether 'displacements' is set.");
49
50 return params;
51}
52
54
55void
57{
58 if (!_mesh)
59 mooseError("No mesh file was supplied and no generation block was provided");
60
61 if (_current_task == "uniform_refine_mesh")
62 {
63 // we don't need to run mesh modifiers *again* after they ran already during the mesh
64 // splitting process
65 // A uniform refinement is helpful for some instances when using a pre-split mesh.
66 // For example, a 'coarse' mesh might completely resolve geometry (also is large)
67 // but does not have enough resolution for the interior. For this scenario,
68 // we pre-split the coarse mesh, and load the pre-split mesh in parallel,
69 // and then do a few levels of uniform refinements to have a fine mesh that
70 // potentially resolves physics features.
71 if (_mesh->isSplit() && _mesh->skipRefineWhenUseSplit())
72 return;
73
74 // uniform refinement has been done on master, so skip
75 if (_app.useMasterMesh())
76 return;
77
84 if (_app.getExodusFileRestart() == false)
85 {
86 if (_app.isRecovering() == false || !_app.isUltimateMaster())
87 {
88 TIME_SECTION("uniformRefine", 2, "Uniformly Refining");
89
90 if (_mesh->uniformRefineLevel())
91 {
92 if (!_mesh->interiorLowerDBlocks().empty() || !_mesh->boundaryLowerDBlocks().empty())
93 mooseError("HFEM does not support mesh uniform refinement currently.");
94
96 // After refinement we need to make sure that all of our MOOSE-specific containers are
97 // up-to-date
98 _mesh->meshChanged();
99 }
100 }
101 }
102 }
103 else if (_current_task == "delete_remote_elements_after_late_geometric_ghosting")
104 {
105 TIME_SECTION("deleteRemoteElems", 2, "Deleting Remote Elements");
106
107 if (_displaced_mesh &&
108 (_mesh->needsRemoteElemDeletion() != _displaced_mesh->needsRemoteElemDeletion()))
109 mooseError("Our reference and displaced meshes are not in sync with respect to whether we "
110 "should delete remote elements.");
111
112 // We currently only trigger the needsRemoteDeletion flag if somebody has requested a late
113 // geometric ghosting functor and/or we have a displaced mesh
114 if (_mesh->needsRemoteElemDeletion())
115 {
116 // Must make sure to create the mortar meshes to build our data structures that ensure we will
117 // keep the correct elements in the mesh around
118 _problem->updateMortarMesh();
119 _mesh->deleteRemoteElements();
120 if (_displaced_mesh)
121 _displaced_mesh->deleteRemoteElements();
122 }
123 }
124 else if (_current_task == "post_mesh_prepared")
125 {
126 // The reference mesh's geometry and topology are finalized by this point, so this is the single
127 // point where the displaced mesh is created: a clone of the finished reference mesh. The
128 // displaced mesh must be an exact copy of the reference mesh, and complete_preparation() (which
129 // may perform partitioning) run separately on two previously-identical meshes can produce
130 // different results (we've seen this even with Metis partitioning), so cloning is the only way
131 // to guarantee the meshes are identical. Mesh preparation, including partitioning, is deferred
132 // until the split_mesh task when splitting a mesh (--split-mesh), so the reference mesh may
133 // still be unprepared here in that case; that's fine because such runs have no displaced mesh
134 // to create either.
135 if (_app.useMasterMesh())
136 {
139 }
140 else if (isParamValid("displacements") && getParam<bool>("use_displaced_mesh"))
141 {
142 TIME_SECTION("constructDisplacedMesh", 2, "Constructing Displaced Mesh");
143
144 // libMesh finds the neighbor across a disjoint neighbor boundary pair by matching side
145 // positions, which fails on a displaced mesh once the two sides have moved apart
146 if (const auto * pairs = _mesh->getMesh().get_disjoint_neighbor_boundary_pairs();
147 pairs && !pairs->empty())
148 paramError("displacements",
149 "A displaced mesh cannot be used with a mesh that has disjoint neighbor "
150 "boundary pairs, such as those created by BreakMeshByBlockGenerator. Set "
151 "'use_displaced_mesh = false' in the [Mesh] block and use the Lagrangian "
152 "solid mechanics kernels ('new_system = true'), or use the mortar-based "
153 "cohesive zone model, which does not rely on pairing elements through the "
154 "disjoint neighbor machinery.");
155
156 mooseAssert(_mesh->prepared(), "The reference mesh should already be fully prepared here");
157 _displaced_mesh = _mesh->safeClone();
158 _displaced_mesh->isDisplaced(true);
159
160 const auto & displacements = getParam<std::vector<std::string>>("displacements");
161 if (displacements.size() < _mesh->dimension())
162 mooseError("Number of displacements must be greater than or equal to the dimension of "
163 "the mesh!");
164 }
165 }
166 else
167 {
168 TIME_SECTION("completeSetupUndisplaced", 2, "Setting Up Undisplaced Mesh");
169 _mesh->prepare();
170 }
171}
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:870
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:440
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition MooseApp.C:1678
const MooseMesh * masterDisplacedMesh() const
Returns a pointer to the master displaced mesh.
Definition MooseApp.h:885
bool useMasterMesh() const
Returns whether to use the parent app mesh as the mesh for this app.
Definition MooseApp.h:875
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
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.