https://mooseframework.inl.gov
SetAdaptivityOptionsAction.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 "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 
20 namespace Moose
21 {
24 {
26  params.addParam<unsigned int>(
27  "steps", 0, "The number of adaptive steps to use when doing a Steady simulation.");
28  params.addRangeCheckedParam<unsigned int>(
29  "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase");
30  params.addParam<unsigned int>(
31  "max_h_level",
32  0,
33  "Maximum number of times a single element can be refined. If 0 then infinite.");
34  params.addParam<Real>("start_time",
36  "The time that adaptivity will be active after.");
37  params.addParam<Real>("stop_time",
39  "The time after which adaptivity will no longer be active.");
40  params.addParam<unsigned int>(
41  "cycles_per_step",
42  1,
43  "The number of adaptive steps to use when on each timestep during a Transient simulation.");
44  params.addParam<bool>(
45  "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles");
46  params.addParam<bool>("switch_h_to_p_refinement", false, "True to perform p-refinement");
47  return params;
48 }
49 }
50 
53 {
55  params.addClassDescription("Action for defining adaptivity parameters.");
56  params.addParam<MarkerName>("marker",
57  "The name of the Marker to use to actually adapt the mesh.");
58  params.addParam<unsigned int>(
59  "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
60  params.addParam<MarkerName>(
61  "initial_marker",
62  "The name of the Marker to use to adapt the mesh during initial refinement.");
63  params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity");
64  return params;
65 }
66 
68  : Action(params)
69 {
70 }
71 
72 void
74 {
75  // Here we are going to mostly mimic the default ghosting in libmesh
76  // By default libmesh adds:
77  // 1) GhostPointNeighbors on the mesh
78  // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
79  // gets added to the mesh at the time a new System is added
80  // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
81  // the mesh at the time a new System is added
82  //
83  // What we will do differently is:
84  // - The 3rd ghosting functor adds nothing so we will not add it at all
85 
86  if (_current_task == "add_algebraic_rm")
87  {
88  auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
89 
90  rm_params.set<std::string>("for_whom") = "Adaptivity";
91  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
92  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
94 
95  if (rm_params.areAllRequiredParamsValid())
96  {
97  auto rm_obj = _factory.create<RelationshipManager>(
98  "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params);
99 
100  // Delete the resources created on behalf of the RM if it ends up not being added to the
101  // App.
102  if (!_app.addRelationshipManager(rm_obj))
104  }
105  else
106  mooseError("Invalid initialization of ElementSideNeighborLayers");
107  }
108 
109  else if (_current_task == "add_geometric_rm")
110  {
111  auto rm_params = _factory.getValidParams("ElementPointNeighborLayers");
112 
113  rm_params.set<std::string>("for_whom") = "Adaptivity";
114  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
115  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
117 
118  if (rm_params.areAllRequiredParamsValid())
119  {
120  auto rm_obj = _factory.create<RelationshipManager>(
121  "ElementPointNeighborLayers", "adaptivity_geometric_ghosting", rm_params);
122 
123  // Delete the resources created on behalf of the RM if it ends up not being added to the
124  // App.
125  if (!_app.addRelationshipManager(rm_obj))
127  }
128  else
129  mooseError("Invalid initialization of ElementPointNeighborLayers");
130  }
131 
132  else if (_current_task == "set_adaptivity_options")
133  {
134  Adaptivity & adapt = _problem->adaptivity();
135 
136  if (isParamValid("marker"))
137  adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
138  if (isParamValid("initial_marker"))
139  adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
140 
141  adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
142 
143  adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
144 
145  adapt.init(getParam<unsigned int>("steps"),
146  getParam<unsigned int>("initial_steps"),
147  getParam<bool>("switch_h_to_p_refinement"));
148  adapt.setUseNewSystem();
149 
150  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
151  adapt.setInterval(getParam<unsigned int>("interval"));
152 
153  adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
154  }
155 }
static InputParameters validParams()
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:234
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:964
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:131
Factory & _factory
The Factory associated with the MooseApp.
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:118
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:111
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:338
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void init(const unsigned int steps, const unsigned int initial_steps, const bool p_refinement)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:59
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:224
void setUseNewSystem()
Tells this object we&#39;re using the "new" adaptivity system.
Definition: Adaptivity.C:345
Base class for actions.
Definition: Action.h:33
auto max(const L &left, const R &right)
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:3024
static InputParameters validParams()
Definition: Action.C:26
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:165
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
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:127
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:167
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:49
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options")
InputParameters commonAdaptivityParams()
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:267
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:171
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...
SetAdaptivityOptionsAction(const InputParameters &params)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
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:351
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:357
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...