www.mooseframework.org
Adaptivity.h
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 
10 #pragma once
11 
12 #include "libmesh/libmesh_config.h"
13 
14 #ifdef LIBMESH_ENABLE_AMR
15 
16 #include "Moose.h"
17 #include "MooseError.h"
18 #include "ConsoleStreamInterface.h"
19 #include "MooseTypes.h"
20 #include "PerfGraphInterface.h"
21 
22 #include "libmesh/parallel_object.h"
23 
24 // libMesh
25 #include "libmesh/mesh_refinement.h"
26 
27 class FEProblemBase;
28 class MooseMesh;
29 class DisplacedProblem;
30 template <typename>
34 class MooseEnum;
35 
36 // Forward declare classes in libMesh
37 namespace libMesh
38 {
39 class SystemNorm;
40 class ErrorVector;
41 class ErrorEstimator;
42 }
43 
49  public PerfGraphInterface,
50  public libMesh::ParallelObject
51 {
52 public:
53  Adaptivity(FEProblemBase & subproblem);
54  virtual ~Adaptivity();
55 
62  void init(unsigned int steps, unsigned int initial_steps);
63 
70  template <typename T>
71  void setParam(const std::string & param_name, const T & param_value);
72 
79  void setErrorEstimator(const MooseEnum & error_estimator_name);
80 
84  void setErrorNorm(SystemNorm & sys_norm);
85 
89  void setPrintMeshChanged(bool state = true) { _print_mesh_changed = state; }
90 
96  unsigned int getInitialSteps() const { return _initial_steps; }
97 
103  unsigned int getSteps() const { return _steps; }
104 
110  unsigned int getCyclesPerStep() const { return _cycles_per_step; }
111 
116  void setCyclesPerStep(const unsigned int & num) { _cycles_per_step = num; }
117 
124 
130 
136  bool adaptMesh(std::string marker_name = std::string());
137 
143  bool initialAdaptMesh();
144 
151  static void uniformRefine(MooseMesh * mesh, unsigned int level = libMesh::invalid_uint);
152 
158 
163  void setAdaptivityOn(bool state);
164 
170  bool isOn() { return _mesh_refinement_on; }
171 
178  bool isInitialized() { return _initialized; }
179 
185  void setTimeActive(Real start_time, Real stop_time);
186 
190  void setUseNewSystem();
191 
200  void setMarkerVariableName(std::string marker_field);
201 
210  void setInitialMarkerVariableName(std::string marker_field);
211 
215  void setMaxHLevel(unsigned int level) { _max_h_level = level; }
216 
220  unsigned int getMaxHLevel() { return _max_h_level; }
221 
225  void setInterval(unsigned int interval) { _interval = interval; }
226 
235  ErrorVector & getErrorVector(const std::string & indicator_field);
236 
240  void updateErrorVectors();
241 
245  bool isAdaptivityDue();
246 
247 protected:
250 
256  std::unique_ptr<MeshRefinement> _mesh_refinement;
258  std::unique_ptr<ErrorEstimator> _error_estimator;
260  std::unique_ptr<ErrorVector> _error;
261 
262  std::shared_ptr<DisplacedProblem> _displaced_problem;
263 
265  std::unique_ptr<MeshRefinement> _displaced_mesh_refinement;
266 
268  unsigned int _initial_steps;
270  unsigned int _steps;
271 
274 
276  Real & _t;
278  int & _step;
280  unsigned int _interval;
286  unsigned int _cycles_per_step;
287 
290 
293 
296 
298  unsigned int _max_h_level;
299 
302 
304  std::map<std::string, std::unique_ptr<ErrorVector>> _indicator_field_to_error_vector;
305 
311 };
312 
313 template <typename T>
314 void
315 Adaptivity::setParam(const std::string & param_name, const T & param_value)
316 {
317  if (param_name == "refine fraction")
318  {
319  _mesh_refinement->refine_fraction() = param_value;
321  _displaced_mesh_refinement->refine_fraction() = param_value;
322  }
323  else if (param_name == "coarsen fraction")
324  {
325  _mesh_refinement->coarsen_fraction() = param_value;
327  _displaced_mesh_refinement->coarsen_fraction() = param_value;
328  }
329  else if (param_name == "max h-level")
330  {
331  _mesh_refinement->max_h_level() = param_value;
333  _displaced_mesh_refinement->max_h_level() = param_value;
334  }
335  else if (param_name == "cycles_per_step")
336  _cycles_per_step = param_value;
337  else if (param_name == "recompute_markers_during_cycles")
338  _recompute_markers_during_cycles = param_value;
339  else
340  mooseError("Invalid Param in adaptivity object");
341 }
342 #endif // LIBMESH_ENABLE_AMR
Adaptivity::_initial_steps
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:268
Adaptivity::uniformRefine
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition: Adaptivity.C:208
ConsoleStreamInterface
An inteface for the _console for outputting to the Console object.
Definition: ConsoleStreamInterface.h:21
Adaptivity::_t
Real & _t
Time.
Definition: Adaptivity.h:276
Adaptivity::initialAdaptMesh
bool initialAdaptMesh()
Used during initial adaptivity.
Definition: Adaptivity.C:202
Adaptivity::_marker_variable_name
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition: Adaptivity.h:292
Adaptivity::updateErrorVectors
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
Definition: Adaptivity.C:293
Adaptivity::_recompute_markers_during_cycles
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:301
Adaptivity::_cycles_per_step
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:286
Adaptivity::setInterval
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:225
Adaptivity::_displaced_mesh_refinement
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:265
PerfGraphInterface.h
Adaptivity::setMaxHLevel
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:215
libMesh
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Definition: AddPeriodicBCAction.h:16
Adaptivity::_step
int & _step
Time Step.
Definition: Adaptivity.h:278
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
Moose.h
Adaptivity::init
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:61
Adaptivity
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:48
Adaptivity::uniformRefineWithProjection
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
Definition: Adaptivity.C:221
Adaptivity::setRecomputeMarkersFlag
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:129
Adaptivity::setAdaptivityOn
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
Definition: Adaptivity.C:249
Adaptivity::_error
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
Definition: Adaptivity.h:260
Adaptivity::setCyclesPerStep
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:116
Adaptivity::~Adaptivity
virtual ~Adaptivity()
Definition: Adaptivity.C:58
Adaptivity::_adapt_mesh_timer
PerfID _adapt_mesh_timer
Timers.
Definition: Adaptivity.h:307
Adaptivity::isInitialized
bool isInitialized()
Returns whether or not Adaptivity::init() has ran.
Definition: Adaptivity.h:178
Adaptivity::adaptMesh
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
Definition: Adaptivity.C:127
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
Adaptivity::setPrintMeshChanged
void setPrintMeshChanged(bool state=true)
Definition: Adaptivity.h:89
Adaptivity::_uniform_refine_timer
PerfID _uniform_refine_timer
Definition: Adaptivity.h:308
Adaptivity::isOn
bool isOn()
Is adaptivity on?
Definition: Adaptivity.h:170
Adaptivity::_initialized
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:254
PerfID
unsigned int PerfID
Definition: MooseTypes.h:198
Adaptivity::_indicator_field_to_error_vector
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:304
Adaptivity::_mesh_refinement
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:256
ConsoleStreamInterface.h
Adaptivity::setTimeActive
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:259
Adaptivity::_subproblem
FEProblemBase & _subproblem
Definition: Adaptivity.h:248
Adaptivity::_update_error_vectors
PerfID _update_error_vectors
Definition: Adaptivity.h:310
Adaptivity::_max_h_level
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:298
DisplacedProblem
Definition: DisplacedProblem.h:39
Adaptivity::setUseNewSystem
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
Definition: Adaptivity.C:266
Adaptivity::_print_mesh_changed
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:273
Adaptivity::_initial_marker_variable_name
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition: Adaptivity.h:295
VectorMooseVariable
MooseVariableFE< VectorValue< Real > > VectorMooseVariable
Definition: Adaptivity.h:33
Adaptivity::setInitialMarkerVariableName
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:278
Adaptivity::getInitialSteps
unsigned int getInitialSteps() const
Pull out the number of initial steps previously set by calling init()
Definition: Adaptivity.h:96
Adaptivity::setErrorEstimator
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
Definition: Adaptivity.C:106
Adaptivity::_steps
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:270
Adaptivity::getSteps
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition: Adaptivity.h:103
Adaptivity::_error_estimator
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:258
MooseVariable
MooseVariableFE< Real > MooseVariable
Definition: Adaptivity.h:31
Adaptivity::getMaxHLevel
unsigned int getMaxHLevel()
Return the maximum h-level.
Definition: Adaptivity.h:220
Adaptivity::_mesh_refinement_on
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:252
PerfGraphInterface
Interface for objects that needs transient capabilities.
Definition: PerfGraphInterface.h:31
MooseError.h
Adaptivity::_stop_time
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:284
Adaptivity::_uniform_refine_with_projection
PerfID _uniform_refine_with_projection
Definition: Adaptivity.h:309
MooseMesh
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
Adaptivity::_use_new_system
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:289
Adaptivity::isAdaptivityDue
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
Definition: Adaptivity.C:314
Adaptivity::getRecomputeMarkersFlag
bool getRecomputeMarkersFlag() const
Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.
Definition: Adaptivity.h:123
Adaptivity::getErrorVector
ErrorVector & getErrorVector(const std::string &indicator_field)
Get an ErrorVector that will be filled up with values corresponding to the indicator field name passe...
Definition: Adaptivity.C:284
Adaptivity::setMarkerVariableName
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:272
MooseTypes.h
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
Adaptivity::_displaced_problem
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:262
Adaptivity::_start_time
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:282
Adaptivity::setErrorNorm
void setErrorNorm(SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
Definition: Adaptivity.C:120
Adaptivity::getCyclesPerStep
unsigned int getCyclesPerStep() const
Pull out the number of cycles_per_step previously set through the AdaptivityAction.
Definition: Adaptivity.h:110
Adaptivity::Adaptivity
Adaptivity(FEProblemBase &subproblem)
Definition: Adaptivity.C:31
Adaptivity::setParam
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition: Adaptivity.h:315
MooseVariableFE
Class for stuff related to variables.
Definition: Adaptivity.h:31
Adaptivity::_interval
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:280
Adaptivity::_mesh
MooseMesh & _mesh
Definition: Adaptivity.h:249