www.mooseframework.org
SetAdaptivityOptionsAction.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 "FEProblem.h"
12 #include "RelationshipManager.h"
13 
14 #include "libmesh/fe.h"
15 
16 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options");
17 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_geometric_rm");
18 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_algebraic_rm");
19 
21 
24 {
26  params.addClassDescription("Action for defining adaptivity parameters.");
27  params.addParam<MarkerName>("marker",
28  "The name of the Marker to use to actually adapt the mesh.");
29  params.addParam<unsigned int>(
30  "steps", 0, "The number of adaptive steps to use when doing a Steady simulation.");
31  params.addParam<unsigned int>(
32  "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
33  params.addRangeCheckedParam<unsigned int>(
34  "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase");
35  params.addParam<MarkerName>(
36  "initial_marker",
37  "The name of the Marker to use to adapt the mesh during initial refinement.");
38  params.addParam<unsigned int>(
39  "max_h_level",
40  0,
41  "Maximum number of times a single element can be refined. If 0 then infinite.");
42  params.addParam<Real>("start_time",
43  -std::numeric_limits<Real>::max(),
44  "The time that adaptivity will be active after.");
45  params.addParam<Real>("stop_time",
46  std::numeric_limits<Real>::max(),
47  "The time after which adaptivity will no longer be active.");
48  params.addParam<unsigned int>(
49  "cycles_per_step",
50  1,
51  "The number of adaptive steps to use when on each timestep during a Transient simulation.");
52  params.addParam<bool>(
53  "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles");
54  return params;
55 }
56 
58 
59 void
61 {
62  // Here we are going to mostly mimic the default ghosting in libmesh
63  // By default libmesh adds:
64  // 1) GhostPointNeighbors on the mesh
65  // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
66  // gets added to the mesh at the time a new System is added
67  // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
68  // the mesh at the time a new System is added
69  //
70  // What we will do differently is:
71  // - The 3rd ghosting functor adds nothing so we will not add it at all
72 
73  if (_current_task == "add_algebraic_rm")
74  {
75  auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
76 
77  rm_params.set<std::string>("for_whom") = "Adaptivity";
78  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
79  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
81 
82  if (rm_params.areAllRequiredParamsValid())
83  {
84  auto rm_obj = _factory.create<RelationshipManager>(
85  "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params);
86 
87  // Delete the resources created on behalf of the RM if it ends up not being added to the
88  // App.
89  if (!_app.addRelationshipManager(rm_obj))
91  }
92  else
93  mooseError("Invalid initialization of ElementSideNeighborLayers");
94  }
95 
96  else if (_current_task == "add_geometric_rm")
97  {
98  auto rm_params = _factory.getValidParams("MooseGhostPointNeighbors");
99 
100  rm_params.set<std::string>("for_whom") = "Adaptivity";
101  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
102  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
104 
105  if (rm_params.areAllRequiredParamsValid())
106  {
107  auto rm_obj = _factory.create<RelationshipManager>(
108  "MooseGhostPointNeighbors", "adaptivity_geometric_ghosting", rm_params);
109 
110  // Delete the resources created on behalf of the RM if it ends up not being added to the
111  // App.
112  if (!_app.addRelationshipManager(rm_obj))
114  }
115  else
116  mooseError("Invalid initialization of MooseGhostPointNeighbors");
117  }
118 
119  else if (_current_task == "set_adaptivity_options")
120  {
121  Adaptivity & adapt = _problem->adaptivity();
122 
123  if (isParamValid("marker"))
124  adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
125  if (isParamValid("initial_marker"))
126  adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
127 
128  adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
129 
130  adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
131 
132  adapt.init(getParam<unsigned int>("steps"), getParam<unsigned int>("initial_steps"));
133  adapt.setUseNewSystem();
134 
135  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
136  adapt.setInterval(getParam<unsigned int>("interval"));
137 
138  adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
139  }
140 }
Action::_app
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:213
Factory::create
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, 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:93
Factory::getValidParams
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
FEProblem.h
Action::_current_task
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:240
Moose::RelationshipManagerType::GEOMETRIC
Adaptivity::setInterval
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:225
SetAdaptivityOptionsAction.h
Adaptivity::setMaxHLevel
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:215
SetAdaptivityOptionsAction
Definition: SetAdaptivityOptionsAction.h:19
Adaptivity::init
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:61
InputParameters::addParam
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.
Definition: InputParameters.h:1198
Adaptivity
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:48
Adaptivity::setRecomputeMarkersFlag
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:129
Adaptivity::setCyclesPerStep
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:116
SetAdaptivityOptionsAction::act
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Definition: SetAdaptivityOptionsAction.C:60
Action
Base class for actions.
Definition: Action.h:39
Action::_problem
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:246
Moose::RelationshipManagerType::ALGEBRAIC
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
InputParameters::set
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Definition: InputParameters.h:987
Action::_factory
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:216
Adaptivity::setTimeActive
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:259
Moose::RelationshipManagerType
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:852
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
Action::isParamValid
bool isParamValid(const std::string &name) const
Definition: Action.h:144
Adaptivity::setUseNewSystem
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
Definition: Adaptivity.C:266
InputParameters::addRangeCheckedParam
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
Definition: InputParameters.h:1245
SetAdaptivityOptionsAction::validParams
static InputParameters validParams()
Definition: SetAdaptivityOptionsAction.C:23
RelationshipManager
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
Definition: RelationshipManager.h:31
Adaptivity::setInitialMarkerVariableName
void setInitialMarkerVariableName(std::string marker_field)
Sets the name of the field variable to actually use to flag elements for initial refinement / coarsen...
Definition: Adaptivity.C:278
RelationshipManager.h
MooseApp::addRelationshipManager
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:1860
defineLegacyParams
defineLegacyParams(SetAdaptivityOptionsAction)
MooseMesh
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
SetAdaptivityOptionsAction::SetAdaptivityOptionsAction
SetAdaptivityOptionsAction(InputParameters params)
Definition: SetAdaptivityOptionsAction.C:57
Action::_mesh
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:242
Adaptivity::setMarkerVariableName
void setMarkerVariableName(std::string marker_field)
Sets the name of the field variable to actually use to flag elements for refinement / coarsening.
Definition: Adaptivity.C:272
Action::validParams
static InputParameters validParams()
Definition: Action.C:23
Factory::releaseSharedObjects
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:172
registerMooseAction
registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options")