https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
16registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options");
17registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_geometric_rm");
18registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_algebraic_rm");
19
20namespace 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.addDeprecatedParam<Real>(
35 "start_time",
36 -std::numeric_limits<Real>::max(),
37 "The time that adaptivity will be active after.",
38 "'start_time' will be deprecated in the future. You can get identical behavior by using the "
39 "Controls system to set 'enable'.");
40 params.addDeprecatedParam<Real>(
41 "stop_time",
42 std::numeric_limits<Real>::max(),
43 "The time after which adaptivity will no longer be active.",
44 "'stop_time' will be deprecated in the future. You can get identical behavior by using the "
45 "Controls system to set 'enable'.");
46 params.addParam<bool>("enable", true, "Whether adaptivity should be enabled.");
47 params.declareControllable("enable");
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 MooseEnum adaptivity("h=0 p=1 hp=2", "h");
55 params.addParam<MooseEnum>(
56 "adaptivity_type", adaptivity, "Select between h, p or hp mesh adaptivity");
57 return params;
58}
59}
60
63{
65 params.addClassDescription("Action for defining adaptivity parameters.");
66 params.addParam<MarkerName>("marker",
67 "The name of the Marker to use to actually adapt the mesh.");
68 params.addParam<unsigned int>(
69 "initial_steps", 0, "The number of adaptive steps to do based on the initial condition.");
70 params.addParam<MarkerName>(
71 "initial_marker",
72 "The name of the Marker to use to adapt the mesh during initial refinement.");
73 params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity");
74 return params;
75}
76
81
82void
84{
85 // Here we are going to mostly mimic the default ghosting in libmesh
86 // By default libmesh adds:
87 // 1) GhostPointNeighbors on the mesh
88 // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also
89 // gets added to the mesh at the time a new System is added
90 // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to
91 // the mesh at the time a new System is added
92 //
93 // What we will do differently is:
94 // - The 3rd ghosting functor adds nothing so we will not add it at all
95
96 if (_current_task == "add_algebraic_rm")
97 {
98 auto rm_params = _factory.getValidParams("ElementSideNeighborLayers");
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 "ElementSideNeighborLayers", "adaptivity_algebraic_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 ElementSideNeighborLayers");
117 }
118
119 else if (_current_task == "add_geometric_rm")
120 {
121 auto rm_params = _factory.getValidParams("ElementPointNeighborLayers");
122
123 rm_params.set<std::string>("for_whom") = "Adaptivity";
124 rm_params.set<MooseMesh *>("mesh") = _mesh.get();
125 rm_params.set<Moose::RelationshipManagerType>("rm_type") =
127
128 if (rm_params.areAllRequiredParamsValid())
129 {
130 auto rm_obj = _factory.create<RelationshipManager>(
131 "ElementPointNeighborLayers", "adaptivity_geometric_ghosting", rm_params);
132
133 // Delete the resources created on behalf of the RM if it ends up not being added to the
134 // App.
135 if (!_app.addRelationshipManager(rm_obj))
137 }
138 else
139 mooseError("Invalid initialization of ElementPointNeighborLayers");
140 }
141
142 else if (_current_task == "set_adaptivity_options")
143 {
144 Adaptivity & adapt = _problem->adaptivity();
145
146 if (isParamValid("marker"))
147 adapt.setMarkerVariableName(getParam<MarkerName>("marker"));
148 if (isParamValid("initial_marker"))
149 adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker"));
150
151 adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step"));
152
153 adapt.setMaxHLevel(getParam<unsigned int>("max_h_level"));
154
155 adapt.init(getParam<unsigned int>("steps"),
156 getParam<unsigned int>("initial_steps"),
157 getParam<MooseEnum>("adaptivity_type").getEnum<AdaptivityType>());
158 adapt.setUseNewSystem();
159
160 adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
161 adapt.setAdaptivityControlFlag(&getParam<bool>("enable"));
162 adapt.setInterval(getParam<unsigned int>("interval"));
163
164 adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles"));
165 }
166}
registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options")
Base class for actions.
Definition Action.h:38
std::shared_ptr< MooseMesh > & _mesh
Definition Action.h:174
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
Takes care of everything related to mesh adaptivity.
Definition Adaptivity.h:64
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:59
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
Definition Adaptivity.C:380
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition Adaptivity.C:366
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition Adaptivity.h:255
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:386
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition Adaptivity.h:132
void setAdaptivityControlFlag(const bool *adapt_control_flag)
Sets the boolean control flag to enable / disable adaptivity.
Definition Adaptivity.C:373
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:392
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition Adaptivity.h:145
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition Adaptivity.h:245
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
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
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
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
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...
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.
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition MooseApp.C:2996
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:271
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
Factory & _factory
The Factory associated with the MooseApp.
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
SetAdaptivityOptionsAction(const InputParameters &params)
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
static InputParameters validParams()
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
RelationshipManagerType
Main types of Relationship Managers.
InputParameters commonAdaptivityParams()