www.mooseframework.org
SetupMeshCompleteAction.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 "MooseMesh.h"
12 #include "Moose.h"
13 #include "Adaptivity.h"
14 #include "MooseApp.h"
15 #include "FEProblemBase.h"
16 
17 registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh");
18 
19 registerMooseAction("MooseApp",
21  "delete_remote_elements_after_late_geometric_ghosting");
22 
23 registerMooseAction("MooseApp", SetupMeshCompleteAction, "uniform_refine_mesh");
24 
25 registerMooseAction("MooseApp", SetupMeshCompleteAction, "setup_mesh_complete");
26 
29 {
31  params.addClassDescription("Perform operations on the mesh in preparation for a simulation.");
32  return params;
33 }
34 
36 
37 void
39 {
40  if (!_mesh)
41  mooseError("No mesh file was supplied and no generation block was provided");
42 
43  if (_current_task == "uniform_refine_mesh")
44  {
45  // we don't need to run mesh modifiers *again* after they ran already during the mesh
46  // splitting process
47  // A uniform refinement is helpful for some instances when using a pre-split mesh.
48  // For example, a 'coarse' mesh might completely resolve geometry (also is large)
49  // but does not have enough resolution for the interior. For this scenario,
50  // we pre-split the coarse mesh, and load the pre-split mesh in parallel,
51  // and then do a few levels of uniform refinements to have a fine mesh that
52  // potentially resolves physics features.
53  if (_mesh->isSplit() && _mesh->skipRefineWhenUseSplit())
54  return;
55 
56  // uniform refinement has been done on master, so skip
57  if (_app.masterMesh())
58  return;
59 
66  if (_app.getExodusFileRestart() == false)
67  {
68  if (_app.isRecovering() == false || !_app.isUltimateMaster())
69  {
70  TIME_SECTION("uniformRefine", 2, "Uniformly Refining");
71 
72  if (_mesh->uniformRefineLevel())
73  {
74  if (_mesh->meshSubdomains().count(Moose::INTERNAL_SIDE_LOWERD_ID) ||
75  _mesh->meshSubdomains().count(Moose::BOUNDARY_SIDE_LOWERD_ID))
76  mooseError("HFEM does not support mesh uniform refinement currently.");
77 
79  // After refinement we need to make sure that all of our MOOSE-specific containers are
80  // up-to-date
81  _mesh->update();
82 
83  if (_displaced_mesh)
84  {
86  // After refinement we need to make sure that all of our MOOSE-specific containers are
87  // up-to-date
88  _displaced_mesh->update();
89  }
90  }
91  }
92  }
93  }
94  else if (_current_task == "delete_remote_elements_after_late_geometric_ghosting")
95  {
96  TIME_SECTION("deleteRemoteElems", 2, "Deleting Remote Elements");
97 
98  if (_displaced_mesh &&
99  (_mesh->needsRemoteElemDeletion() != _displaced_mesh->needsRemoteElemDeletion()))
100  mooseError("Our reference and displaced meshes are not in sync with respect to whether we "
101  "should delete remote elements.");
102 
103  // We currently only trigger the needsRemoteDeletion flag if somebody has requested a late
104  // geometric ghosting functor and/or we have a displaced mesh
105  if (_mesh->needsRemoteElemDeletion())
106  {
107  // Must make sure to create the mortar meshes to build our data structures that ensure we will
108  // keep the correct elements in the mesh around
109  _problem->updateMortarMesh();
110  _mesh->deleteRemoteElements();
111  if (_displaced_mesh)
112  _displaced_mesh->deleteRemoteElements();
113  }
114  }
115  else
116  {
117  // Prepare the mesh (may occur multiple times)
118  bool prepare_for_use_called_on_undisplaced = false;
119  {
120  TIME_SECTION("completeSetupUndisplaced", 2, "Setting Up Undisplaced Mesh");
121  prepare_for_use_called_on_undisplaced = _mesh->prepare(/*mesh_to_clone=*/nullptr);
122  }
123 
124  if (_displaced_mesh)
125  {
126  TIME_SECTION("completeSetupDisplaced", 2, "Setting Up Displaced Mesh");
127  // If the reference mesh was prepared, then we must prepare also
128  _displaced_mesh->prepare(
129  /*mesh_to_clone=*/prepare_for_use_called_on_undisplaced ? &_mesh->getMesh() : nullptr);
130  }
131  }
132 }
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:805
SetupMeshCompleteAction(const InputParameters &params)
registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh")
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition: Adaptivity.C:266
static InputParameters validParams()
const SubdomainID BOUNDARY_SIDE_LOWERD_ID
Definition: MooseTypes.C:21
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for actions.
Definition: Action.h:38
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:425
static InputParameters validParams()
Definition: Action.C:24
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:176
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:173
const MooseMesh * masterMesh() const
Returns a pointer to the master mesh.
Definition: MooseApp.h:810
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:175
const SubdomainID INTERNAL_SIDE_LOWERD_ID
Definition: MooseTypes.C:20
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:179
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:1161