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 #include "AddVariableAction.h"
14 
15 #include "libmesh/fe.h"
16 
17 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options");
18 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_geometric_rm");
19 registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_algebraic_rm");
20 
21 namespace Moose
22 {
25 {
27  params.addParam<unsigned int>(
28  "steps", 0, "The number of adaptive steps to use when doing a Steady simulation.");
29  params.addRangeCheckedParam<unsigned int>(
30  "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase");
31  params.addParam<unsigned int>(
32  "max_h_level",
33  0,
34  "Maximum number of times a single element can be refined. If 0 then infinite.");
35  params.addParam<Real>("start_time",
37  "The time that adaptivity will be active after.");
38  params.addParam<Real>("stop_time",
40  "The time after which adaptivity will no longer be active.");
41  params.addParam<unsigned int>(
42  "cycles_per_step",
43  1,
44  "The number of adaptive steps to use when on each timestep during a Transient simulation.");
45  params.addParam<bool>(
46  "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles");
47  params.addParam<bool>("switch_h_to_p_refinement", false, "True to perform p-refinement");
48  const auto families_enum = AddVariableAction::getNonlinearVariableFamilies();
49  MultiMooseEnum disable_p_refinement_for_families(families_enum.getRawNames());
50  params.addParam<MultiMooseEnum>("disable_p_refinement_for_families",
51  disable_p_refinement_for_families,
52  "What families we should disable p-refinement for.");
53  return params;
54 }
55 }
56 
59 {
61  params.addClassDescription("Action for defining adaptivity parameters.");
62  params.addParam<MarkerName>("marker",
63  "The name of the Marker to use to actually adapt the mesh.");
64  params.addParam<unsigned int>(
65  "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
66  params.addParam<MarkerName>(
67  "initial_marker",
68  "The name of the Marker to use to adapt the mesh during initial refinement.");
69  params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity");
70  return params;
71 }
72 
74  : Action(params)
75 {
76 }
77 
78 void
80 {
81  // Here we are going to mostly mimic the default ghosting in libmesh
82  // By default libmesh adds:
83  // 1) GhostPointNeighbors on the mesh
84  // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
85  // gets added to the mesh at the time a new System is added
86  // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
87  // the mesh at the time a new System is added
88  //
89  // What we will do differently is:
90  // - The 3rd ghosting functor adds nothing so we will not add it at all
91 
92  if (_current_task == "add_algebraic_rm")
93  {
94  auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
95 
96  rm_params.set<std::string>("for_whom") = "Adaptivity";
97  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
98  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
100 
101  if (rm_params.areAllRequiredParamsValid())
102  {
103  auto rm_obj = _factory.create<RelationshipManager>(
104  "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params);
105 
106  // Delete the resources created on behalf of the RM if it ends up not being added to the
107  // App.
108  if (!_app.addRelationshipManager(rm_obj))
110  }
111  else
112  mooseError("Invalid initialization of ElementSideNeighborLayers");
113  }
114 
115  else if (_current_task == "add_geometric_rm")
116  {
117  auto rm_params = _factory.getValidParams("ElementPointNeighborLayers");
118 
119  rm_params.set<std::string>("for_whom") = "Adaptivity";
120  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
121  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
123 
124  if (rm_params.areAllRequiredParamsValid())
125  {
126  auto rm_obj = _factory.create<RelationshipManager>(
127  "ElementPointNeighborLayers", "adaptivity_geometric_ghosting", rm_params);
128 
129  // Delete the resources created on behalf of the RM if it ends up not being added to the
130  // App.
131  if (!_app.addRelationshipManager(rm_obj))
133  }
134  else
135  mooseError("Invalid initialization of ElementPointNeighborLayers");
136  }
137 
138  else if (_current_task == "set_adaptivity_options")
139  {
140  Adaptivity & adapt = _problem->adaptivity();
141 
142  if (isParamValid("marker"))
143  adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
144  if (isParamValid("initial_marker"))
145  adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
146 
147  adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
148 
149  adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
150 
151  adapt.init(getParam<unsigned int>("steps"), getParam<unsigned int>("initial_steps"));
152  adapt.setUseNewSystem();
153 
154  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
155  adapt.setInterval(getParam<unsigned int>("interval"));
156 
157  adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
158  if (getParam<bool>("switch_h_to_p_refinement"))
159  {
160  auto disable_p_refinement_for_families =
161  getParam<MultiMooseEnum>("disable_p_refinement_for_families");
162  if (!isParamSetByUser("disable_p_refinement_for_families"))
163  // If the user has not set this parameter we will set a logicial default
164  disable_p_refinement_for_families =
165  "LAGRANGE NEDELEC_ONE RAVIART_THOMAS LAGRANGE_VEC CLOUGH BERNSTEIN RATIONAL_BERNSTEIN";
166  adapt.doingPRefinement(true, disable_p_refinement_for_families);
167  }
168  }
169 }
static InputParameters validParams()
void doingPRefinement(bool doing_p_refinement, const MultiMooseEnum &disable_p_refinement_for_families)
Indicate whether the kind of adaptivity we&#39;re doing is p-refinement.
Definition: Adaptivity.C:390
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:876
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:130
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:117
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:57
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:110
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:329
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:67
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:224
void setUseNewSystem()
Tells this object we&#39;re using the "new" adaptivity system.
Definition: Adaptivity.C:336
Base class for actions.
Definition: Action.h:38
static MooseEnum getNonlinearVariableFamilies()
Get the possible variable families.
auto max(const L &left, const R &right)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Factory & _factory
The Factory associated with the MooseApp.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:2342
static InputParameters validParams()
Definition: Action.C:24
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:173
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
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:126
bool isParamSetByUser(const std::string &nm) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:175
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.
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
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...
SetAdaptivityOptionsAction(const InputParameters &params)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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:342
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:348
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...