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 class MultiMooseEnum;
36 
37 // Forward declare classes in libMesh
38 namespace libMesh
39 {
40 class SystemNorm;
41 class ErrorVector;
42 class ErrorEstimator;
43 }
44 
50  public PerfGraphInterface,
52 {
53 public:
54  Adaptivity(FEProblemBase & fe_problem);
55  virtual ~Adaptivity();
56 
63  void init(unsigned int steps, unsigned int initial_steps);
64 
71  template <typename T>
72  void setParam(const std::string & param_name, const T & param_value);
73 
80  void setErrorEstimator(const MooseEnum & error_estimator_name);
81 
85  void setErrorNorm(SystemNorm & sys_norm);
86 
90  void setPrintMeshChanged(bool state = true) { _print_mesh_changed = state; }
91 
97  unsigned int getInitialSteps() const { return _initial_steps; }
98 
104  unsigned int getSteps() const { return _steps; }
105 
111  unsigned int getCyclesPerStep() const { return _cycles_per_step; }
112 
117  void setCyclesPerStep(const unsigned int & num) { _cycles_per_step = num; }
118 
125 
131 
137  void doingPRefinement(bool doing_p_refinement,
138  const MultiMooseEnum & disable_p_refinement_for_families);
139 
145  bool adaptMesh(std::string marker_name = std::string());
146 
152  bool initialAdaptMesh();
153 
160  static void uniformRefine(MooseMesh * mesh, unsigned int level = libMesh::invalid_uint);
161 
167 
172  void setAdaptivityOn(bool state);
173 
179  bool isOn() { return _mesh_refinement_on; }
180 
187  bool isInitialized() { return _initialized; }
188 
194  void setTimeActive(Real start_time, Real stop_time);
195 
199  void setUseNewSystem();
200 
209  void setMarkerVariableName(std::string marker_field);
210 
219  void setInitialMarkerVariableName(std::string marker_field);
220 
224  void setMaxHLevel(unsigned int level) { _max_h_level = level; }
225 
229  unsigned int getMaxHLevel() { return _max_h_level; }
230 
234  void setInterval(unsigned int interval) { _interval = interval; }
235 
244  ErrorVector & getErrorVector(const std::string & indicator_field);
245 
249  void updateErrorVectors();
250 
254  bool isAdaptivityDue();
255 
256 protected:
259 
265  std::unique_ptr<MeshRefinement> _mesh_refinement;
267  std::unique_ptr<ErrorEstimator> _error_estimator;
269  std::unique_ptr<ErrorVector> _error;
270 
271  std::shared_ptr<DisplacedProblem> _displaced_problem;
272 
274  std::unique_ptr<MeshRefinement> _displaced_mesh_refinement;
275 
277  unsigned int _initial_steps;
279  unsigned int _steps;
280 
283 
285  Real & _t;
287  int & _step;
289  unsigned int _interval;
295  unsigned int _cycles_per_step;
296 
299 
302 
305 
307  unsigned int _max_h_level;
308 
311 
313  std::map<std::string, std::unique_ptr<ErrorVector>> _indicator_field_to_error_vector;
314 
315  bool _p_refinement_flag = false;
316 };
317 
318 template <typename T>
319 void
320 Adaptivity::setParam(const std::string & param_name, const T & param_value)
321 {
322  if (param_name == "refine fraction")
323  {
324  _mesh_refinement->refine_fraction() = param_value;
326  _displaced_mesh_refinement->refine_fraction() = param_value;
327  }
328  else if (param_name == "coarsen fraction")
329  {
330  _mesh_refinement->coarsen_fraction() = param_value;
332  _displaced_mesh_refinement->coarsen_fraction() = param_value;
333  }
334  else if (param_name == "max h-level")
335  {
336  _mesh_refinement->max_h_level() = param_value;
338  _displaced_mesh_refinement->max_h_level() = param_value;
339  }
340  else if (param_name == "cycles_per_step")
341  _cycles_per_step = param_value;
342  else if (param_name == "recompute_markers_during_cycles")
343  _recompute_markers_during_cycles = param_value;
344  else
345  mooseError("Invalid Param in adaptivity object");
346 }
347 #endif // LIBMESH_ENABLE_AMR
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
Definition: Adaptivity.C:123
bool initialAdaptMesh()
Used during initial adaptivity.
Definition: Adaptivity.C:260
void doingPRefinement(bool doing_p_refinement, const MultiMooseEnum &disable_p_refinement_for_families)
Indicate whether the kind of adaptivity we&#39;re doing is p-refinement.
Definition: Adaptivity.C:390
void setPrintMeshChanged(bool state=true)
Definition: Adaptivity.h:90
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition: Adaptivity.h:271
Real _stop_time
When adaptivity stops.
Definition: Adaptivity.h:293
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition: Adaptivity.h:301
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition: Adaptivity.h:274
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:234
const unsigned int invalid_uint
Class for stuff related to variables.
Definition: Adaptivity.h:31
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition: Adaptivity.h:267
bool _p_refinement_flag
Definition: Adaptivity.h:315
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition: Adaptivity.h:263
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition: Adaptivity.C:266
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:130
virtual ~Adaptivity()
Definition: Adaptivity.C:54
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition: Adaptivity.h:117
unsigned int getCyclesPerStep() const
Pull out the number of cycles_per_step previously set through the AdaptivityAction.
Definition: Adaptivity.h:111
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition: Adaptivity.h:310
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
Definition: Adaptivity.C:363
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
Definition: Adaptivity.C:57
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:329
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
Definition: Adaptivity.h:269
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition: Adaptivity.h:224
void setUseNewSystem()
Tells this object we&#39;re using the "new" adaptivity system.
Definition: Adaptivity.C:336
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
MooseVariableFE< Real > MooseVariable
Definition: Adaptivity.h:31
bool isOn()
Is adaptivity on?
Definition: Adaptivity.h:179
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:304
MooseMesh & _mesh
Definition: Adaptivity.h:258
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:313
Real & _t
Time.
Definition: Adaptivity.h:285
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition: Adaptivity.h:282
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition: Adaptivity.h:265
bool getRecomputeMarkersFlag() const
Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.
Definition: Adaptivity.h:124
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition: Adaptivity.h:261
Adaptivity(FEProblemBase &fe_problem)
Definition: Adaptivity.C:31
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:88
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
Definition: Adaptivity.C:319
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
Definition: Adaptivity.C:102
unsigned int _steps
steps of adaptivity to perform
Definition: Adaptivity.h:279
Interface for objects interacting with the PerfGraph.
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
Definition: Adaptivity.C:293
unsigned int getMaxHLevel()
Return the maximum h-level.
Definition: Adaptivity.h:229
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition: Adaptivity.h:277
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition: Adaptivity.h:298
unsigned int _interval
intreval between adaptivity runs
Definition: Adaptivity.h:289
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:49
unsigned int getInitialSteps() const
Pull out the number of initial steps previously set by calling init()
Definition: Adaptivity.h:97
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:354
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition: Adaptivity.h:104
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition: Adaptivity.h:295
Real _start_time
When adaptivity start.
Definition: Adaptivity.h:291
void setErrorNorm(SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
Definition: Adaptivity.C:116
int & _step
Time Step.
Definition: Adaptivity.h:287
MooseVariableFE< VectorValue< Real > > VectorMooseVariable
Definition: Adaptivity.h:33
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
Definition: Adaptivity.C:384
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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:342
unsigned int _max_h_level
The maximum number of refinement levels.
Definition: Adaptivity.h:307
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition: Adaptivity.h:320
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:348
FEProblemBase & _fe_problem
Definition: Adaptivity.h:257
bool isInitialized()
Returns whether or not Adaptivity::init() has ran.
Definition: Adaptivity.h:187