www.mooseframework.org
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Adaptivity Class Reference

Takes care of everything related to mesh adaptivity. More...

#include <Adaptivity.h>

Inheritance diagram for Adaptivity:
[legend]

Public Member Functions

 Adaptivity (FEProblemBase &subproblem)
 
virtual ~Adaptivity ()
 
void init (unsigned int steps, unsigned int initial_steps)
 Initialize and turn on adaptivity for the simulation. More...
 
template<typename T >
void setParam (const std::string &param_name, const T &param_value)
 Set adaptivity parameter. More...
 
void setErrorEstimator (const MooseEnum &error_estimator_name)
 Set the error estimator. More...
 
void setErrorNorm (SystemNorm &sys_norm)
 Set the error norm (FIXME: improve description) More...
 
void setPrintMeshChanged (bool state=true)
 
unsigned int getInitialSteps () const
 Pull out the number of initial steps previously set by calling init() More...
 
unsigned int getSteps () const
 Pull out the number of steps previously set by calling init() More...
 
unsigned int getCyclesPerStep () const
 Pull out the number of cycles_per_step previously set through the AdaptivityAction. More...
 
void setCyclesPerStep (const unsigned int &num)
 Set the number of cycles_per_step. More...
 
bool getRecomputeMarkersFlag () const
 Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction. More...
 
void setRecomputeMarkersFlag (const bool flag)
 Set the flag to recompute markers during adaptivity cycles. More...
 
bool adaptMesh (std::string marker_name=std::string())
 Adapts the mesh based on the error estimator used. More...
 
bool initialAdaptMesh ()
 Used during initial adaptivity. More...
 
void uniformRefineWithProjection ()
 Performs uniform refinement on the meshes in the current object. More...
 
void setAdaptivityOn (bool state)
 Allow adaptivity to be toggled programatically. More...
 
bool isOn ()
 Is adaptivity on? More...
 
bool isInitialized ()
 Returns whether or not Adaptivity::init() has ran. More...
 
void setTimeActive (Real start_time, Real stop_time)
 Sets the time when the adaptivity is active. More...
 
void setUseNewSystem ()
 Tells this object we're using the "new" adaptivity system. More...
 
void setMarkerVariableName (std::string marker_field)
 Sets the name of the field variable to actually use to flag elements for refinement / coarsening. More...
 
void setInitialMarkerVariableName (std::string marker_field)
 Sets the name of the field variable to actually use to flag elements for initial refinement / coarsening. More...
 
void setMaxHLevel (unsigned int level)
 Set the maximum refinement level (for the new Adaptivity system). More...
 
unsigned int getMaxHLevel ()
 Return the maximum h-level. More...
 
void setInterval (unsigned int interval)
 Set the interval (number of timesteps) between refinement steps. More...
 
ErrorVector & getErrorVector (const std::string &indicator_field)
 Get an ErrorVector that will be filled up with values corresponding to the indicator field name passed in. More...
 
void updateErrorVectors ()
 Update the ErrorVectors that have been requested through calls to getErrorVector(). More...
 
bool isAdaptivityDue ()
 Query if an adaptivity step should be performed at the current time / time step. More...
 

Static Public Member Functions

static void uniformRefine (MooseMesh *mesh)
 Performs uniform refinement of the passed Mesh object. More...
 

Public Attributes

const ConsoleStream _console
 An instance of helper class to write streams to the Console objects. More...
 

Protected Member Functions

PerfID registerTimedSection (const std::string &section_name, const unsigned int level)
 Call to register a named section for timing. More...
 

Protected Attributes

FEProblemBase_subproblem
 
MooseMesh_mesh
 
bool _mesh_refinement_on
 on/off flag reporting if the adaptivity is being used More...
 
bool _initialized
 on/off flag reporting if the adaptivity system has been initialized More...
 
std::unique_ptr< MeshRefinement > _mesh_refinement
 A mesh refinement object to be used either with initial refinement or with Adaptivity. More...
 
std::unique_ptr< ErrorEstimator > _error_estimator
 Error estimator to be used by the apps. More...
 
std::unique_ptr< ErrorVector > _error
 Error vector for use with the error estimator. More...
 
std::shared_ptr< DisplacedProblem_displaced_problem
 
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
 A mesh refinement object for displaced mesh. More...
 
unsigned int _initial_steps
 the number of adaptivity steps to do at the beginning of simulation More...
 
unsigned int _steps
 steps of adaptivity to perform More...
 
bool _print_mesh_changed
 True if we want to print out info when mesh has changed. More...
 
Real & _t
 Time. More...
 
int & _step
 Time Step. More...
 
unsigned int _interval
 intreval between adaptivity runs More...
 
Real _start_time
 When adaptivity start. More...
 
Real _stop_time
 When adaptivity stops. More...
 
unsigned int _cycles_per_step
 The number of adaptivity cycles per step. More...
 
bool _use_new_system
 Whether or not to use the "new" adaptivity system. More...
 
std::string _marker_variable_name
 Name of the marker variable if using the new adaptivity system. More...
 
std::string _initial_marker_variable_name
 Name of the initial marker variable if using the new adaptivity system. More...
 
unsigned int _max_h_level
 The maximum number of refinement levels. More...
 
bool _recompute_markers_during_cycles
 Whether or not to recompute markers during adaptivity cycles. More...
 
std::map< std::string, std::unique_ptr< ErrorVector > > _indicator_field_to_error_vector
 Stores pointers to ErrorVectors associated with indicator field names. More...
 
PerfID _adapt_mesh_timer
 Timers. More...
 
PerfID _uniform_refine_timer
 
PerfID _uniform_refine_with_projection
 
PerfID _update_error_vectors
 
const InputParameters_pg_params
 Params. More...
 
PerfGraph_perf_graph
 The performance graph to add to. More...
 
std::string _prefix
 A prefix to use for all sections. More...
 

Detailed Description

Takes care of everything related to mesh adaptivity.

Definition at line 47 of file Adaptivity.h.

Constructor & Destructor Documentation

◆ Adaptivity()

Adaptivity::Adaptivity ( FEProblemBase subproblem)

Definition at line 30 of file Adaptivity.C.

31  : ConsoleStreamInterface(subproblem.getMooseApp()),
32  PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "Adaptivity"),
33  _subproblem(subproblem),
35  _mesh_refinement_on(false),
36  _initialized(false),
37  _initial_steps(0),
38  _steps(0),
39  _print_mesh_changed(false),
40  _t(_subproblem.time()),
42  _interval(1),
43  _start_time(-std::numeric_limits<Real>::max()),
44  _stop_time(std::numeric_limits<Real>::max()),
46  _use_new_system(false),
47  _max_h_level(0),
49  _adapt_mesh_timer(registerTimedSection("adaptMesh", 3)),
50  _uniform_refine_timer(registerTimedSection("uniformRefine", 2)),
51  _uniform_refine_with_projection(registerTimedSection("uniformRefineWithProjection", 2)),
52  _update_error_vectors(registerTimedSection("updateErrorVectors", 5))
53 {
54 }
PerfID registerTimedSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:281
virtual Real & time() const
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:251
PerfID _uniform_refine_with_projection
Definition: Adaptivity.h:306
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:298
PerfID _uniform_refine_timer
Definition: Adaptivity.h:305
PerfID _adapt_mesh_timer
Timers.
Definition: Adaptivity.h:304
MooseMesh & _mesh
Definition: Adaptivity.h:246
Real & _t
Time.
Definition: Adaptivity.h:273
FEProblemBase & _subproblem
Definition: Adaptivity.h:245
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:270
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:249
ConsoleStreamInterface(MooseApp &app)
A class for providing a helper stream object for writting message to all the Output objects...
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:267
virtual int & timeStep() const
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:265
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:286
PerfID _update_error_vectors
Definition: Adaptivity.h:307
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:277
virtual MooseMesh & mesh() override
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:283
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:279
int & _step
Time Step.
Definition: Adaptivity.h:275
MooseApp & getMooseApp() const
Get the MooseApp this object is associated with.
Definition: MooseObject.h:86
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:295
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:97

◆ ~Adaptivity()

Adaptivity::~Adaptivity ( )
virtual

Definition at line 56 of file Adaptivity.C.

56 {}

Member Function Documentation

◆ adaptMesh()

bool Adaptivity::adaptMesh ( std::string  marker_name = std::string())

Adapts the mesh based on the error estimator used.

Returns
a boolean that indicates whether the mesh was changed

Definition at line 125 of file Adaptivity.C.

Referenced by FEProblemBase::adaptMesh(), and initialAdaptMesh().

126 {
127  TIME_SECTION(_adapt_mesh_timer);
128 
129  // If the marker name is supplied, use it. Otherwise, use the one in _marker_variable_name
130  if (marker_name.empty())
131  marker_name = _marker_variable_name;
132 
133  bool mesh_changed = false;
134 
135  if (_use_new_system)
136  {
137  if (!marker_name.empty()) // Only flag if a marker variable name has been set
138  {
139  _mesh_refinement->clean_refinement_flags();
140 
141  std::vector<Number> serialized_solution;
143  _subproblem.getAuxiliarySystem().solution().localize(serialized_solution);
144 
145  FlagElementsThread fet(_subproblem, serialized_solution, _max_h_level, marker_name);
146  ConstElemRange all_elems(_subproblem.mesh().getMesh().active_elements_begin(),
147  _subproblem.mesh().getMesh().active_elements_end(),
148  1);
149  Threads::parallel_reduce(all_elems, fet);
151  }
152  }
153  else
154  {
155  // Compute the error for each active element
157 
158  // Flag elements to be refined and coarsened
159  _mesh_refinement->flag_elements_by_error_fraction(*_error);
160 
161  if (_displaced_problem)
162  // Reuse the error vector and refine the displaced mesh
163  _displaced_mesh_refinement->flag_elements_by_error_fraction(*_error);
164  }
165 
166  // If the DisplacedProblem is active, undisplace the DisplacedMesh
167  // in preparation for refinement. We can't safely refine the
168  // DisplacedMesh directly, since the Hilbert keys computed on the
169  // inconsistenly-displaced Mesh are different on different
170  // processors, leading to inconsistent Hilbert keys. We must do
171  // this before the undisplaced Mesh is refined, so that the
172  // element and node numbering is still consistent.
173  if (_displaced_problem)
174  _displaced_problem->undisplaceMesh();
175 
176  // Perform refinement and coarsening
177  mesh_changed = _mesh_refinement->refine_and_coarsen_elements();
178 
179  if (_displaced_problem && mesh_changed)
180  {
181 // Now do refinement/coarsening
182 #ifndef NDEBUG
183  bool displaced_mesh_changed =
184 #endif
185  _displaced_mesh_refinement->refine_and_coarsen_elements();
186 
187  // Since the undisplaced mesh changed, the displaced mesh better have changed!
188  mooseAssert(displaced_mesh_changed, "Undisplaced mesh changed, but displaced mesh did not!");
189  }
190 
191  if (mesh_changed && _print_mesh_changed)
192  {
193  _console << "\nMesh Changed:\n";
194  _mesh.printInfo();
195  }
196 
197  return mesh_changed;
198 }
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:259
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition: Adaptivity.h:289
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:262
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:255
NonlinearSystemBase & getNonlinearSystemBase()
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
Definition: Adaptivity.h:257
PerfID _adapt_mesh_timer
Timers.
Definition: Adaptivity.h:304
MooseMesh & _mesh
Definition: Adaptivity.h:246
FEProblemBase & _subproblem
Definition: Adaptivity.h:245
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:270
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:253
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2512
void printInfo(std::ostream &os=libMesh::out) const
Calls print_info() on the underlying Mesh.
Definition: MooseMesh.C:2533
AuxiliarySystem & getAuxiliarySystem()
virtual NumericVector< Number > & solution() override
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:286
virtual System & system() override
Get the reference to the libMesh system.
virtual MooseMesh & mesh() override
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:295

◆ getCyclesPerStep()

unsigned int Adaptivity::getCyclesPerStep ( ) const
inline

Pull out the number of cycles_per_step previously set through the AdaptivityAction.

Returns
the number of cycles per step

Definition at line 107 of file Adaptivity.h.

Referenced by FEProblemBase::adaptMesh().

107 { return _cycles_per_step; }
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:283

◆ getErrorVector()

ErrorVector & Adaptivity::getErrorVector ( const std::string &  indicator_field)

Get an ErrorVector that will be filled up with values corresponding to the indicator field name passed in.

Note that this returns a reference... and the return value should be stored as a reference!

Parameters
indicator_fieldThe name of the field to get an ErrorVector for.

Definition at line 280 of file Adaptivity.C.

Referenced by Marker::getErrorVector().

281 {
282  // Insert or retrieve error vector
283  auto insert_pair = moose_try_emplace(
284  _indicator_field_to_error_vector, indicator_field, libmesh_make_unique<ErrorVector>());
285  return *insert_pair.first->second;
286 }
std::pair< typename M::iterator, bool > moose_try_emplace(M &m, const typename M::key_type &k, Args &&... args)
Function to mirror the behavior of the C++17 std::map::try_emplace() method (no hint).
Definition: Moose.h:65
std::map< std::string, std::unique_ptr< ErrorVector > > _indicator_field_to_error_vector
Stores pointers to ErrorVectors associated with indicator field names.
Definition: Adaptivity.h:301

◆ getInitialSteps()

unsigned int Adaptivity::getInitialSteps ( ) const
inline

Pull out the number of initial steps previously set by calling init()

Returns
the number of initial steps

Definition at line 93 of file Adaptivity.h.

Referenced by FEProblemBase::hasInitialAdaptivity(), FEProblemBase::initialAdaptMesh(), and FEProblemBase::initialSetup().

93 { return _initial_steps; }
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:265

◆ getMaxHLevel()

unsigned int Adaptivity::getMaxHLevel ( )
inline

Return the maximum h-level.

Definition at line 217 of file Adaptivity.h.

217 { return _max_h_level; }
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:295

◆ getRecomputeMarkersFlag()

bool Adaptivity::getRecomputeMarkersFlag ( ) const
inline

Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.

Returns
the flag to recompute markers during adaptivity cycles

Definition at line 120 of file Adaptivity.h.

Referenced by FEProblemBase::adaptMesh().

bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:298

◆ getSteps()

unsigned int Adaptivity::getSteps ( ) const
inline

Pull out the number of steps previously set by calling init()

Returns
the number of steps

Definition at line 100 of file Adaptivity.h.

Referenced by Steady::execute().

100 { return _steps; }
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:267

◆ init()

void Adaptivity::init ( unsigned int  steps,
unsigned int  initial_steps 
)

Initialize and turn on adaptivity for the simulation.

initial_steps specifies the number of adaptivity cycles to perform before the simulation starts and steps indicates the number of adaptivity cycles to run during a steady (not transient) solve. steps is not used for transient or eigen solves.

Definition at line 59 of file Adaptivity.C.

Referenced by SetAdaptivityOptionsAction::act(), and AdaptivityAction::act().

60 {
61  // Get the pointer to the DisplacedProblem, this cannot be done at construction because
62  // DisplacedProblem
63  // does not exist at that point.
65 
66  _mesh_refinement = libmesh_make_unique<MeshRefinement>(_mesh);
67  _error = libmesh_make_unique<ErrorVector>();
68 
69  EquationSystems & es = _subproblem.es();
70  es.parameters.set<bool>("adaptivity") = true;
71 
72  _initial_steps = initial_steps;
73  _steps = steps;
74  _mesh_refinement_on = true;
75 
76  _mesh_refinement->set_periodic_boundaries_ptr(
77  _subproblem.getNonlinearSystemBase().dofMap().get_periodic_boundaries());
78 
79  // displaced problem
80  if (_displaced_problem != nullptr)
81  {
82  EquationSystems & displaced_es = _displaced_problem->es();
83  displaced_es.parameters.set<bool>("adaptivity") = true;
84 
86  _displaced_mesh_refinement = libmesh_make_unique<MeshRefinement>(_displaced_problem->mesh());
87 
88  // The periodic boundaries pointer allows the MeshRefinement
89  // object to determine elements which are "topological" neighbors,
90  // i.e. neighbors across periodic boundaries, for the purposes of
91  // refinement.
92  _displaced_mesh_refinement->set_periodic_boundaries_ptr(
93  _subproblem.getNonlinearSystemBase().dofMap().get_periodic_boundaries());
94 
95  // TODO: This is currently an empty function on the DisplacedProblem... could it be removed?
96  _displaced_problem->initAdaptivity();
97  }
98 
99  // indicate the Adaptivity system has been initialized
100  _initialized = true;
101 }
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:259
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:262
NonlinearSystemBase & getNonlinearSystemBase()
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:251
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
Definition: Adaptivity.h:257
MooseMesh & _mesh
Definition: Adaptivity.h:246
virtual EquationSystems & es() override
FEProblemBase & _subproblem
Definition: Adaptivity.h:245
virtual DofMap & dofMap()
Gets the dof map.
Definition: SystemBase.C:885
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:253
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:249
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:267
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:265

◆ initialAdaptMesh()

bool Adaptivity::initialAdaptMesh ( )

Used during initial adaptivity.

Returns
a boolean that indicates whether the mesh was changed

Definition at line 201 of file Adaptivity.C.

Referenced by FEProblemBase::initialAdaptMesh().

202 {
204 }
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
Definition: Adaptivity.C:125
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition: Adaptivity.h:292

◆ isAdaptivityDue()

bool Adaptivity::isAdaptivityDue ( )

Query if an adaptivity step should be performed at the current time / time step.

Definition at line 310 of file Adaptivity.C.

Referenced by FEProblemBase::adaptMesh().

311 {
312  return _mesh_refinement_on && (_start_time <= _t && _t < _stop_time) && _step % _interval == 0;
313 }
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:281
Real & _t
Time.
Definition: Adaptivity.h:273
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:249
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:277
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:279
int & _step
Time Step.
Definition: Adaptivity.h:275

◆ isInitialized()

bool Adaptivity::isInitialized ( )
inline

Returns whether or not Adaptivity::init() has ran.

Can be used to indicate if mesh adaptivity is available.

Returns
true if the Adaptivity system is ready to be used, otherwise false

Definition at line 175 of file Adaptivity.h.

175 { return _initialized; }
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:251

◆ isOn()

bool Adaptivity::isOn ( )
inline

Is adaptivity on?

Returns
true if mesh adaptivity is on, otherwise false

Definition at line 167 of file Adaptivity.h.

Referenced by FEProblemBase::checkProblemIntegrity(), and FEProblemBase::initialSetup().

167 { return _mesh_refinement_on; }
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:249

◆ registerTimedSection()

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
)
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 50 of file PerfGraphInterface.C.

51 {
52  if (_prefix != "")
53  return _perf_graph.registerSection(_prefix + "::" + section_name, level);
54  else
55  return _perf_graph.registerSection(section_name, level);
56 }
PerfGraph & _perf_graph
The performance graph to add to.
std::string _prefix
A prefix to use for all sections.
PerfID registerSection(const std::string &section_name, unsigned int level)
Registers a named section of code.
Definition: PerfGraph.C:41

◆ setAdaptivityOn()

void Adaptivity::setAdaptivityOn ( bool  state)

Allow adaptivity to be toggled programatically.

Parameters
stateThe adaptivity state (on/off).

Definition at line 245 of file Adaptivity.C.

246 {
247  // check if Adaptivity has been initialized before turning on
248  if (state == true && !_initialized)
249  mooseError("Mesh adaptivity system not available");
250 
251  _mesh_refinement_on = state;
252 }
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:251
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:249

◆ setCyclesPerStep()

void Adaptivity::setCyclesPerStep ( const unsigned int &  num)
inline

Set the number of cycles_per_step.

Parameters
numThe number of cycles per step to execute

Definition at line 113 of file Adaptivity.h.

Referenced by SetAdaptivityOptionsAction::act().

113 { _cycles_per_step = num; }
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:283

◆ setErrorEstimator()

void Adaptivity::setErrorEstimator ( const MooseEnum error_estimator_name)

Set the error estimator.

Parameters
error_estimator_namethe name of the error estimator (currently: Laplacian, Kelly, and PatchRecovery)

Definition at line 104 of file Adaptivity.C.

Referenced by AdaptivityAction::act().

105 {
106  if (error_estimator_name == "KellyErrorEstimator")
107  _error_estimator = libmesh_make_unique<KellyErrorEstimator>();
108  else if (error_estimator_name == "LaplacianErrorEstimator")
109  _error_estimator = libmesh_make_unique<LaplacianErrorEstimator>();
110  else if (error_estimator_name == "PatchRecoveryErrorEstimator")
111  _error_estimator = libmesh_make_unique<PatchRecoveryErrorEstimator>();
112  else
113  mooseError(std::string("Unknown error_estimator selection: ") +
114  std::string(error_estimator_name));
115 }
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:255
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ setErrorNorm()

void Adaptivity::setErrorNorm ( SystemNorm &  sys_norm)

Set the error norm (FIXME: improve description)

Definition at line 118 of file Adaptivity.C.

Referenced by AdaptivityAction::act().

119 {
120  mooseAssert(_error_estimator, "error_estimator not initialized. Did you call init_adaptivity()?");
121  _error_estimator->error_norm = sys_norm;
122 }
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:255

◆ setInitialMarkerVariableName()

void Adaptivity::setInitialMarkerVariableName ( std::string  marker_field)

Sets the name of the field variable to actually use to flag elements for initial refinement / coarsening.

This must be a CONSTANT, MONOMIAL Auxiliary Variable Name that contains values corresponding to libMesh::Elem::RefinementState.

Parameters
marker_fieldThe name of the field to use for refinement / coarsening.

Definition at line 274 of file Adaptivity.C.

Referenced by SetAdaptivityOptionsAction::act().

275 {
276  _initial_marker_variable_name = marker_field;
277 }
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition: Adaptivity.h:292

◆ setInterval()

void Adaptivity::setInterval ( unsigned int  interval)
inline

Set the interval (number of timesteps) between refinement steps.

Definition at line 222 of file Adaptivity.h.

Referenced by AdaptivityAction::act().

222 { _interval = interval; }
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:277

◆ setMarkerVariableName()

void Adaptivity::setMarkerVariableName ( std::string  marker_field)

Sets the name of the field variable to actually use to flag elements for refinement / coarsening.

This must be a CONSTANT, MONOMIAL Auxiliary Variable Name that contains values corresponding to libMesh::Elem::RefinementState.

Parameters
marker_fieldThe name of the field to use for refinement / coarsening.

Definition at line 268 of file Adaptivity.C.

Referenced by SetAdaptivityOptionsAction::act().

269 {
270  _marker_variable_name = marker_field;
271 }
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition: Adaptivity.h:289

◆ setMaxHLevel()

void Adaptivity::setMaxHLevel ( unsigned int  level)
inline

Set the maximum refinement level (for the new Adaptivity system).

Definition at line 212 of file Adaptivity.h.

Referenced by SetAdaptivityOptionsAction::act().

212 { _max_h_level = level; }
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:295

◆ setParam()

template<typename T >
void Adaptivity::setParam ( const std::string &  param_name,
const T &  param_value 
)

Set adaptivity parameter.

Parameters
param_namethe name of the parameter
param_valuethe value of parameter

Definition at line 312 of file Adaptivity.h.

Referenced by AdaptivityAction::act().

313 {
314  if (param_name == "refine fraction")
315  {
316  _mesh_refinement->refine_fraction() = param_value;
318  _displaced_mesh_refinement->refine_fraction() = param_value;
319  }
320  else if (param_name == "coarsen fraction")
321  {
322  _mesh_refinement->coarsen_fraction() = param_value;
324  _displaced_mesh_refinement->coarsen_fraction() = param_value;
325  }
326  else if (param_name == "max h-level")
327  {
328  _mesh_refinement->max_h_level() = param_value;
330  _displaced_mesh_refinement->max_h_level() = param_value;
331  }
332  else if (param_name == "cycles_per_step")
333  _cycles_per_step = param_value;
334  else if (param_name == "recompute_markers_during_cycles")
335  _recompute_markers_during_cycles = param_value;
336  else
337  mooseError("Invalid Param in adaptivity object");
338 }
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:262
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:298
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:253
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:283

◆ setPrintMeshChanged()

void Adaptivity::setPrintMeshChanged ( bool  state = true)
inline

Definition at line 86 of file Adaptivity.h.

Referenced by AdaptivityAction::act().

86 { _print_mesh_changed = state; }
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:270

◆ setRecomputeMarkersFlag()

void Adaptivity::setRecomputeMarkersFlag ( const bool  flag)
inline

Set the flag to recompute markers during adaptivity cycles.

Parameters
flagThe flag to recompute markers

Definition at line 126 of file Adaptivity.h.

Referenced by SetAdaptivityOptionsAction::act().

bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:298

◆ setTimeActive()

void Adaptivity::setTimeActive ( Real  start_time,
Real  stop_time 
)

Sets the time when the adaptivity is active.

Parameters
start_timeThe time when adaptivity starts
stop_timeThe time when adaptivity stops

Definition at line 255 of file Adaptivity.C.

Referenced by SetAdaptivityOptionsAction::act(), and AdaptivityAction::act().

256 {
257  _start_time = start_time;
258  _stop_time = stop_time;
259 }
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:281
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:279

◆ setUseNewSystem()

void Adaptivity::setUseNewSystem ( )

Tells this object we're using the "new" adaptivity system.

Definition at line 262 of file Adaptivity.C.

Referenced by SetAdaptivityOptionsAction::act().

263 {
264  _use_new_system = true;
265 }
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:286

◆ uniformRefine()

void Adaptivity::uniformRefine ( MooseMesh mesh)
static

Performs uniform refinement of the passed Mesh object.

The number of levels of refinement performed is stored in the MooseMesh object. No solution projection is performed in this version.

Definition at line 207 of file Adaptivity.C.

Referenced by SetupMeshCompleteAction::act().

208 {
209  mooseAssert(mesh, "Mesh pointer must not be NULL");
210 
211  // NOTE: we are using a separate object here, since adaptivity may not be on, but we need to be
212  // able to do refinements
213  MeshRefinement mesh_refinement(*mesh);
214  unsigned int level = mesh->uniformRefineLevel();
215  mesh_refinement.uniformly_refine(level);
216 }
unsigned int uniformRefineLevel() const
Returns the level of uniform refinement requested (zero if AMR is disabled).
Definition: MooseMesh.C:2306

◆ uniformRefineWithProjection()

void Adaptivity::uniformRefineWithProjection ( )

Performs uniform refinement on the meshes in the current object.

Projections are performed of the solution vectors.

Definition at line 219 of file Adaptivity.C.

Referenced by FEProblemBase::initialSetup().

220 {
221  TIME_SECTION(_uniform_refine_with_projection);
222 
223  // NOTE: we are using a separate object here, since adaptivity may not be on, but we need to be
224  // able to do refinements
225  MeshRefinement mesh_refinement(_mesh);
226  unsigned int level = _mesh.uniformRefineLevel();
227  MeshRefinement displaced_mesh_refinement(_displaced_problem ? _displaced_problem->mesh() : _mesh);
228 
229  // we have to go step by step so EquationSystems::reinit() won't freak out
230  for (unsigned int i = 0; i < level; i++)
231  {
232  // See comment above about why refining the displaced mesh is potentially unsafe.
233  if (_displaced_problem)
234  _displaced_problem->undisplaceMesh();
235 
236  mesh_refinement.uniformly_refine(1);
237 
238  if (_displaced_problem)
239  displaced_mesh_refinement.uniformly_refine(1);
241  }
242 }
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:259
PerfID _uniform_refine_with_projection
Definition: Adaptivity.h:306
MooseMesh & _mesh
Definition: Adaptivity.h:246
FEProblemBase & _subproblem
Definition: Adaptivity.h:245
virtual void meshChanged() override
Update data after a mesh change.
unsigned int uniformRefineLevel() const
Returns the level of uniform refinement requested (zero if AMR is disabled).
Definition: MooseMesh.C:2306

◆ updateErrorVectors()

void Adaptivity::updateErrorVectors ( )

Update the ErrorVectors that have been requested through calls to getErrorVector().

Definition at line 289 of file Adaptivity.C.

Referenced by FEProblemBase::computeMarkers().

290 {
291  TIME_SECTION(_update_error_vectors);
292 
293  // Resize all of the ErrorVectors in case the mesh has changed
294  for (const auto & it : _indicator_field_to_error_vector)
295  {
296  ErrorVector & vec = *(it.second);
297  vec.assign(_mesh.getMesh().max_elem_id(), 0);
298  }
299 
300  // Fill the vectors with the local contributions
302  Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), uevt);
303 
304  // Now sum across all processors
305  for (const auto & it : _indicator_field_to_error_vector)
306  _subproblem.comm().sum((std::vector<float> &)*(it.second));
307 }
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:779
MooseMesh & _mesh
Definition: Adaptivity.h:246
std::map< std::string, std::unique_ptr< ErrorVector > > _indicator_field_to_error_vector
Stores pointers to ErrorVectors associated with indicator field names.
Definition: Adaptivity.h:301
FEProblemBase & _subproblem
Definition: Adaptivity.h:245
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2512
PerfID _update_error_vectors
Definition: Adaptivity.h:307

Member Data Documentation

◆ _adapt_mesh_timer

PerfID Adaptivity::_adapt_mesh_timer
protected

Timers.

Definition at line 304 of file Adaptivity.h.

Referenced by adaptMesh().

◆ _console

const ConsoleStream ConsoleStreamInterface::_console
inherited

An instance of helper class to write streams to the Console objects.

Definition at line 32 of file ConsoleStreamInterface.h.

Referenced by IterationAdaptiveDT::acceptStep(), SetupRecoverFileBaseAction::act(), adaptMesh(), FEProblemBase::adaptMesh(), SimplePredictor::apply(), FEProblemBase::backupMultiApps(), FEProblemBase::checkProblemIntegrity(), IterationAdaptiveDT::computeAdaptiveDT(), Transient::computeConstrainedDT(), NonlinearSystemBase::computeDamping(), IterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeFailedDT(), IterationAdaptiveDT::computeInterpolationDT(), FEProblemBase::computeResidualTags(), IterationAdaptiveDT::constrainStep(), TimeStepper::constrainStep(), AB2PredictorCorrector::converged(), FEProblemBase::execMultiApps(), FEProblemBase::execMultiAppTransfers(), MultiAppPostprocessorTransfer::execute(), MultiAppPostprocessorInterpolationTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppNearestNodeTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppInterpolationTransfer::execute(), MultiAppMeshFunctionTransfer::execute(), MultiAppUserObjectTransfer::execute(), MultiAppProjectionTransfer::execute(), MultiAppVectorPostprocessorTransfer::execute(), MultiAppCopyTransfer::execute(), Steady::execute(), MultiAppDTKUserObjectTransfer::execute(), ActionWarehouse::executeActionsWithAction(), ActionWarehouse::executeAllActions(), FEProblemBase::FEProblemBase(), ElementQualityChecker::finalize(), FEProblemBase::finishMultiAppStep(), MultiApp::globalAppToLocal(), InversePowerMethod::init(), NonlinearEigen::init(), Steady::init(), FEProblemBase::initialAdaptMesh(), FEProblemBase::initialSetup(), EigenExecutionerBase::inversePowerIteration(), Transient::keepGoing(), IterationAdaptiveDT::limitDTByFunction(), IterationAdaptiveDT::limitDTToPostprocessorValue(), EigenExecutionerBase::makeBXConsistent(), Console::meshChanged(), MooseObject::mooseDeprecated(), MooseObject::mooseInfo(), MooseObject::mooseWarning(), PerfGraphOutput::output(), DOFMapOutput::output(), VariableResidualNormsDebugOutput::output(), Console::output(), ControlOutput::outputActiveObjects(), ControlOutput::outputChangedControls(), ControlOutput::outputControls(), Console::outputInput(), Console::outputPostprocessors(), Console::outputScalarVariables(), Console::outputSystemInformation(), FEProblemBase::possiblyRebuildGeomSearchPatches(), EigenExecutionerBase::postExecute(), ActionWarehouse::printActionDependencySets(), EigenExecutionerBase::printEigenvalue(), MaterialPropertyDebugOutput::printMaterialMap(), SolutionTimeAdaptiveDT::rejectStep(), DT2::rejectStep(), FEProblemBase::restoreMultiApps(), SimplePredictor::shouldApply(), NonlinearSystem::solve(), LStableDirk2::solve(), LStableDirk3::solve(), ImplicitMidpoint::solve(), ExplicitTVDRK2::solve(), LStableDirk4::solve(), AStableDirk4::solve(), ExplicitRK2::solve(), TransientMultiApp::solveStep(), Transient::solveStep(), DT2::step(), AB2PredictorCorrector::step(), NonlinearEigen::takeStep(), Console::writeTimestepInformation(), Console::writeVariableNorms(), and FEProblemBase::~FEProblemBase().

◆ _cycles_per_step

unsigned int Adaptivity::_cycles_per_step
protected

The number of adaptivity cycles per step.

Definition at line 283 of file Adaptivity.h.

Referenced by getCyclesPerStep(), setCyclesPerStep(), and setParam().

◆ _displaced_mesh_refinement

std::unique_ptr<MeshRefinement> Adaptivity::_displaced_mesh_refinement
protected

A mesh refinement object for displaced mesh.

Definition at line 262 of file Adaptivity.h.

Referenced by adaptMesh(), init(), and setParam().

◆ _displaced_problem

std::shared_ptr<DisplacedProblem> Adaptivity::_displaced_problem
protected

Definition at line 259 of file Adaptivity.h.

Referenced by adaptMesh(), init(), and uniformRefineWithProjection().

◆ _error

std::unique_ptr<ErrorVector> Adaptivity::_error
protected

Error vector for use with the error estimator.

Definition at line 257 of file Adaptivity.h.

Referenced by adaptMesh(), and init().

◆ _error_estimator

std::unique_ptr<ErrorEstimator> Adaptivity::_error_estimator
protected

Error estimator to be used by the apps.

Definition at line 255 of file Adaptivity.h.

Referenced by adaptMesh(), setErrorEstimator(), and setErrorNorm().

◆ _indicator_field_to_error_vector

std::map<std::string, std::unique_ptr<ErrorVector> > Adaptivity::_indicator_field_to_error_vector
protected

Stores pointers to ErrorVectors associated with indicator field names.

Definition at line 301 of file Adaptivity.h.

Referenced by getErrorVector(), and updateErrorVectors().

◆ _initial_marker_variable_name

std::string Adaptivity::_initial_marker_variable_name
protected

Name of the initial marker variable if using the new adaptivity system.

Definition at line 292 of file Adaptivity.h.

Referenced by initialAdaptMesh(), and setInitialMarkerVariableName().

◆ _initial_steps

unsigned int Adaptivity::_initial_steps
protected

the number of adaptivity steps to do at the beginning of simulation

Definition at line 265 of file Adaptivity.h.

Referenced by getInitialSteps(), and init().

◆ _initialized

bool Adaptivity::_initialized
protected

on/off flag reporting if the adaptivity system has been initialized

Definition at line 251 of file Adaptivity.h.

Referenced by init(), isInitialized(), and setAdaptivityOn().

◆ _interval

unsigned int Adaptivity::_interval
protected

intreval between adaptivity runs

Definition at line 277 of file Adaptivity.h.

Referenced by isAdaptivityDue(), and setInterval().

◆ _marker_variable_name

std::string Adaptivity::_marker_variable_name
protected

Name of the marker variable if using the new adaptivity system.

Definition at line 289 of file Adaptivity.h.

Referenced by adaptMesh(), and setMarkerVariableName().

◆ _max_h_level

unsigned int Adaptivity::_max_h_level
protected

The maximum number of refinement levels.

Definition at line 295 of file Adaptivity.h.

Referenced by adaptMesh(), getMaxHLevel(), and setMaxHLevel().

◆ _mesh

MooseMesh& Adaptivity::_mesh
protected

Definition at line 246 of file Adaptivity.h.

Referenced by adaptMesh(), init(), uniformRefineWithProjection(), and updateErrorVectors().

◆ _mesh_refinement

std::unique_ptr<MeshRefinement> Adaptivity::_mesh_refinement
protected

A mesh refinement object to be used either with initial refinement or with Adaptivity.

Definition at line 253 of file Adaptivity.h.

Referenced by adaptMesh(), init(), and setParam().

◆ _mesh_refinement_on

bool Adaptivity::_mesh_refinement_on
protected

on/off flag reporting if the adaptivity is being used

Definition at line 249 of file Adaptivity.h.

Referenced by init(), isAdaptivityDue(), isOn(), and setAdaptivityOn().

◆ _perf_graph

PerfGraph& PerfGraphInterface::_perf_graph
protectedinherited

The performance graph to add to.

Definition at line 66 of file PerfGraphInterface.h.

Referenced by PerfGraphData::getValue(), and PerfGraphInterface::registerTimedSection().

◆ _pg_params

const InputParameters* PerfGraphInterface::_pg_params
protectedinherited

Params.

Definition at line 63 of file PerfGraphInterface.h.

◆ _prefix

std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 69 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::registerTimedSection().

◆ _print_mesh_changed

bool Adaptivity::_print_mesh_changed
protected

True if we want to print out info when mesh has changed.

Definition at line 270 of file Adaptivity.h.

Referenced by adaptMesh(), and setPrintMeshChanged().

◆ _recompute_markers_during_cycles

bool Adaptivity::_recompute_markers_during_cycles
protected

Whether or not to recompute markers during adaptivity cycles.

Definition at line 298 of file Adaptivity.h.

Referenced by getRecomputeMarkersFlag(), setParam(), and setRecomputeMarkersFlag().

◆ _start_time

Real Adaptivity::_start_time
protected

When adaptivity start.

Definition at line 279 of file Adaptivity.h.

Referenced by isAdaptivityDue(), and setTimeActive().

◆ _step

int& Adaptivity::_step
protected

Time Step.

Definition at line 275 of file Adaptivity.h.

Referenced by isAdaptivityDue().

◆ _steps

unsigned int Adaptivity::_steps
protected

steps of adaptivity to perform

Definition at line 267 of file Adaptivity.h.

Referenced by getSteps(), and init().

◆ _stop_time

Real Adaptivity::_stop_time
protected

When adaptivity stops.

Definition at line 281 of file Adaptivity.h.

Referenced by isAdaptivityDue(), and setTimeActive().

◆ _subproblem

FEProblemBase& Adaptivity::_subproblem
protected

Definition at line 245 of file Adaptivity.h.

Referenced by adaptMesh(), init(), uniformRefineWithProjection(), and updateErrorVectors().

◆ _t

Real& Adaptivity::_t
protected

Time.

Definition at line 273 of file Adaptivity.h.

Referenced by isAdaptivityDue().

◆ _uniform_refine_timer

PerfID Adaptivity::_uniform_refine_timer
protected

Definition at line 305 of file Adaptivity.h.

◆ _uniform_refine_with_projection

PerfID Adaptivity::_uniform_refine_with_projection
protected

Definition at line 306 of file Adaptivity.h.

Referenced by uniformRefineWithProjection().

◆ _update_error_vectors

PerfID Adaptivity::_update_error_vectors
protected

Definition at line 307 of file Adaptivity.h.

Referenced by updateErrorVectors().

◆ _use_new_system

bool Adaptivity::_use_new_system
protected

Whether or not to use the "new" adaptivity system.

Definition at line 286 of file Adaptivity.h.

Referenced by adaptMesh(), and setUseNewSystem().


The documentation for this class was generated from the following files: