www.mooseframework.org
Adaptivity.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef ADAPTIVITY_H
16 #define ADAPTIVITY_H
17 
18 #include "libmesh/libmesh_config.h"
19 
20 #ifdef LIBMESH_ENABLE_AMR
21 
22 #include "Moose.h"
23 #include "MooseError.h"
24 #include "ConsoleStreamInterface.h"
25 #include "MooseTypes.h"
26 
27 // libMesh
28 #include "libmesh/mesh_refinement.h"
29 
30 class FEProblemBase;
31 class MooseMesh;
32 class DisplacedProblem;
33 class MooseVariable;
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 {
50 public:
51  Adaptivity(FEProblemBase & subproblem);
52  virtual ~Adaptivity();
53 
60  void init(unsigned int steps, unsigned int initial_steps);
61 
68  template <typename T>
69  void setParam(const std::string & param_name, const T & param_value);
70 
77  void setErrorEstimator(const MooseEnum & error_estimator_name);
78 
82  void setErrorNorm(SystemNorm & sys_norm);
83 
87  void setPrintMeshChanged(bool state = true) { _print_mesh_changed = state; }
88 
94  unsigned int getInitialSteps() const { return _initial_steps; }
95 
101  unsigned int getSteps() const { return _steps; }
102 
108  unsigned int getCyclesPerStep() const { return _cycles_per_step; }
109 
114  void setCyclesPerStep(const unsigned int & num) { _cycles_per_step = num; }
115 
121  bool getRecomputeMarkersFlag() const { return _recompute_markers_during_cycles; }
122 
127  void setRecomputeMarkersFlag(const bool flag) { _recompute_markers_during_cycles = flag; }
128 
134  bool adaptMesh(std::string marker_name = std::string());
135 
141  bool initialAdaptMesh();
142 
149  static void uniformRefine(MooseMesh * mesh);
150 
155  void uniformRefineWithProjection();
156 
161  void setAdaptivityOn(bool state);
162 
168  bool isOn() { return _mesh_refinement_on; }
169 
176  bool isInitialized() { return _initialized; }
177 
183  void setTimeActive(Real start_time, Real stop_time);
184 
188  void setUseNewSystem();
189 
198  void setMarkerVariableName(std::string marker_field);
199 
208  void setInitialMarkerVariableName(std::string marker_field);
209 
213  void setMaxHLevel(unsigned int level) { _max_h_level = level; }
214 
218  unsigned int getMaxHLevel() { return _max_h_level; }
219 
223  void setInterval(unsigned int interval) { _interval = interval; }
224 
233  ErrorVector & getErrorVector(const std::string & indicator_field);
234 
238  void updateErrorVectors();
239 
243  bool isAdaptivityDue();
244 
245 protected:
248 
254  std::unique_ptr<MeshRefinement> _mesh_refinement;
256  std::unique_ptr<ErrorEstimator> _error_estimator;
258  std::unique_ptr<ErrorVector> _error;
259 
260  std::shared_ptr<DisplacedProblem> _displaced_problem;
261 
263  std::unique_ptr<MeshRefinement> _displaced_mesh_refinement;
264 
266  unsigned int _initial_steps;
268  unsigned int _steps;
269 
272 
274  Real & _t;
276  int & _step;
278  unsigned int _interval;
284  unsigned int _cycles_per_step;
285 
288 
291 
294 
296  unsigned int _max_h_level;
297 
300 
302  std::map<std::string, std::unique_ptr<ErrorVector>> _indicator_field_to_error_vector;
303 };
304 
305 template <typename T>
306 void
307 Adaptivity::setParam(const std::string & param_name, const T & param_value)
308 {
309  if (param_name == "refine fraction")
310  {
311  _mesh_refinement->refine_fraction() = param_value;
312  if (_displaced_mesh_refinement)
313  _displaced_mesh_refinement->refine_fraction() = param_value;
314  }
315  else if (param_name == "coarsen fraction")
316  {
317  _mesh_refinement->coarsen_fraction() = param_value;
318  if (_displaced_mesh_refinement)
319  _displaced_mesh_refinement->coarsen_fraction() = param_value;
320  }
321  else if (param_name == "max h-level")
322  {
323  _mesh_refinement->max_h_level() = param_value;
324  if (_displaced_mesh_refinement)
325  _displaced_mesh_refinement->max_h_level() = param_value;
326  }
327  else if (param_name == "cycles_per_step")
328  _cycles_per_step = param_value;
329  else if (param_name == "recompute_markers_during_cycles")
330  _recompute_markers_during_cycles = param_value;
331  else
332  mooseError("Invalid Param in adaptivity object");
333 }
334 #endif // LIBMESH_ENABLE_AMR
335 
336 #endif /* ADAPTIVITY_H */
void setPrintMeshChanged(bool state=true)
Definition: Adaptivity.h:87
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:260
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:282
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition: Adaptivity.h:290
unsigned int getInitialSteps() const
Pull out the number of initial steps previously set by calling init()
Definition: Adaptivity.h:94
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:263
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:223
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:256
Class for stuff related to variables.
Definition: MooseVariable.h:43
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:252
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:127
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:114
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:299
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
bool getRecomputeMarkersFlag() const
Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.
Definition: Adaptivity.h:121
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
Definition: Adaptivity.h:258
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:213
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool isOn()
Is adaptivity on?
Definition: Adaptivity.h:168
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition: Adaptivity.h:293
MooseMesh & _mesh
Definition: Adaptivity.h:247
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:302
Real & _t
Time.
Definition: Adaptivity.h:274
FEProblemBase & _subproblem
Definition: Adaptivity.h:246
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:271
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:254
unsigned int getCyclesPerStep() const
Pull out the number of cycles_per_step previously set through the AdaptivityAction.
Definition: Adaptivity.h:108
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:250
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition: Adaptivity.h:101
An inteface for the _console for outputting to the Console object.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:268
unsigned int getMaxHLevel()
Return the maximum h-level.
Definition: Adaptivity.h:218
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:266
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:287
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:278
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:48
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:284
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:280
int & _step
Time Step.
Definition: Adaptivity.h:276
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:296
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition: Adaptivity.h:307
bool isInitialized()
Returns whether or not Adaptivity::init() has ran.
Definition: Adaptivity.h:176