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 
20 template <>
23 {
25  params.addParam<MarkerName>("marker",
26  "The name of the Marker to use to actually adapt the mesh.");
27  params.addParam<unsigned int>(
28  "steps", 0, "The number of adaptive steps to use when doing a Steady simulation.");
29  params.addParam<unsigned int>(
30  "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
31  params.addParam<MarkerName>(
32  "initial_marker",
33  "The name of the Marker to use to adapt the mesh during initial refinement.");
34  params.addParam<unsigned int>(
35  "max_h_level",
36  0,
37  "Maximum number of times a single element can be refined. If 0 then infinite.");
38  params.addParam<Real>("start_time",
39  -std::numeric_limits<Real>::max(),
40  "The time that adaptivity will be active after.");
41  params.addParam<Real>("stop_time",
42  std::numeric_limits<Real>::max(),
43  "The time after which adaptivity will no longer be active.");
44  params.addParam<unsigned int>(
45  "cycles_per_step",
46  1,
47  "The number of adaptive steps to use when on each timestep during a Transient simulation.");
48  params.addParam<bool>(
49  "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles");
50  return params;
51 }
52 
54 
55 void
57 {
58  // Here we are going to mostly mimic the default ghosting in libmesh
59  // By default libmesh adds:
60  // 1) GhostPointNeighbors on the mesh
61  // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
62  // gets added to the mesh at the time a new System is added
63  // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
64  // the mesh at the time a new System is added
65  //
66  // What we will do differently is:
67  // - The 3rd ghosting functor adds nothing so we will not add it at all
68 
69  if (_current_task == "add_algebraic_rm")
70  {
71  auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
72 
73  rm_params.set<std::string>("for_whom") = "Adaptivity";
74  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
75  rm_params.set<Moose::RelationshipManagerType>("rm_type") =
77 
78  if (rm_params.areAllRequiredParamsValid())
79  {
80  auto rm_obj = _factory.create<RelationshipManager>(
81  "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params);
82 
83  // Delete the resources created on behalf of the RM if it ends up not being added to the
84  // App.
85  if (!_app.addRelationshipManager(rm_obj))
87  }
88  else
89  mooseError("Invalid initialization of ElementSideNeighborLayers");
90  }
91 
92  else if (_current_task == "add_geometric_rm")
93  {
94  auto rm_params = _factory.getValidParams("MooseGhostPointNeighbors");
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  "MooseGhostPointNeighbors", "adaptivity_geometric_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 MooseGhostPointNeighbors");
113  }
114 
115  else if (_current_task == "set_adaptivity_options")
116  {
117  Adaptivity & adapt = _problem->adaptivity();
118 
119  if (isParamValid("marker"))
120  adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
121  if (isParamValid("initial_marker"))
122  adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
123 
124  adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
125 
126  adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
127 
128  adapt.init(getParam<unsigned int>("steps"), getParam<unsigned int>("initial_steps"));
129  adapt.setUseNewSystem();
130 
131  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
132 
133  adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
134  }
135 }
bool isParamValid(const std::string &name) const
Definition: Action.h:115
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:87
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
InputParameters validParams< SetAdaptivityOptionsAction >()
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:125
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:112
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:59
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:254
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:186
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:211
void setUseNewSystem()
Tells this object we&#39;re using the "new" adaptivity system.
Definition: Adaptivity.C:261
Base class for actions.
Definition: Action.h:35
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:1692
SetAdaptivityOptionsAction(InputParameters params)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:210
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:166
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:212
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:46
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options")
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
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...
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:267
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
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:273
InputParameters validParams< Action >()
Definition: Action.C:22