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  MooseEnum adaptivity("h=0 p=1 hp=2", "h");
47  params.addParam<MooseEnum>(
48  "adaptivity_type", adaptivity, "Select between h, p or hp mesh adaptivity");
49  return params;
50 }
51 }
52 
55 {
57  params.addClassDescription("Action for defining adaptivity parameters.");
58  params.addParam<MarkerName>("marker",
59  "The name of the Marker to use to actually adapt the mesh.");
60  params.addParam<unsigned int>(
61  "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
62  params.addParam<MarkerName>(
63  "initial_marker",
64  "The name of the Marker to use to adapt the mesh during initial refinement.");
65  params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity");
66  return params;
67 }
68 
70  : Action(params)
71 {
72 }
73 
74 void
76 {
77  // Here we are going to mostly mimic the default ghosting in libmesh
78  // By default libmesh adds:
79  // 1) GhostPointNeighbors on the mesh
80  // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
81  // gets added to the mesh at the time a new System is added
82  // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
83  // the mesh at the time a new System is added
84  //
85  // What we will do differently is:
86  // - The 3rd ghosting functor adds nothing so we will not add it at all
87 
88  if (_current_task == "add_algebraic_rm")
89  {
90  auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
91 
92  rm_params.set<std::string>("for_whom") = "Adaptivity";
93  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
94  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
96 
97  if (rm_params.areAllRequiredParamsValid())
98  {
99  auto rm_obj = _factory.create<RelationshipManager>(
100  "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params);
101 
102  // Delete the resources created on behalf of the RM if it ends up not being added to the
103  // App.
104  if (!_app.addRelationshipManager(rm_obj))
106  }
107  else
108  mooseError("Invalid initialization of ElementSideNeighborLayers");
109  }
110 
111  else if (_current_task == "add_geometric_rm")
112  {
113  auto rm_params = _factory.getValidParams("ElementPointNeighborLayers");
114 
115  rm_params.set<std::string>("for_whom") = "Adaptivity";
116  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
117  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
119 
120  if (rm_params.areAllRequiredParamsValid())
121  {
122  auto rm_obj = _factory.create<RelationshipManager>(
123  "ElementPointNeighborLayers", "adaptivity_geometric_ghosting", rm_params);
124 
125  // Delete the resources created on behalf of the RM if it ends up not being added to the
126  // App.
127  if (!_app.addRelationshipManager(rm_obj))
129  }
130  else
131  mooseError("Invalid initialization of ElementPointNeighborLayers");
132  }
133 
134  else if (_current_task == "set_adaptivity_options")
135  {
136  Adaptivity & adapt = _problem->adaptivity();
137 
138  if (isParamValid("marker"))
139  adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
140  if (isParamValid("initial_marker"))
141  adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
142 
143  adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
144 
145  adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
146 
147  adapt.init(getParam<unsigned int>("steps"),
148  getParam<unsigned int>("initial_steps"),
149  getParam<MooseEnum>("adaptivity_type").getEnum<AdaptivityType>());
150  adapt.setUseNewSystem();
151 
152  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
153  adapt.setInterval(getParam<unsigned int>("interval"));
154 
155  adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
156  }
157 }
static InputParameters validParams()
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:248
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:1012
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:145
Factory & _factory
The Factory associated with the MooseApp.
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:132
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:142
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:365
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 setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:238
void setUseNewSystem()
Tells this object we&#39;re using the "new" adaptivity system.
Definition: Adaptivity.C:372
Base class for actions.
Definition: Action.h:34
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:2718
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:93
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:172
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:385
void init(const unsigned int steps, const unsigned int initial_steps, const AdaptivityType adaptivity_type)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:60
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:156
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:174
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:61
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:281
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:178
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:209
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:378
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:384
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...