https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Adaptivity.h
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
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"
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#include "libmesh/hp_coarsentest.h"
27#include "libmesh/sibling_coupling.h"
28
29class FEProblemBase;
30class MooseMesh;
32template <typename>
33class MooseVariableFE;
36class MooseEnum;
37class MultiMooseEnum;
38
39// Forward declare classes in libMesh
40namespace libMesh
41{
42class SystemNorm;
43class ErrorVector;
44class ErrorEstimator;
45}
46
51{
52 H = 0,
53 P = 1,
54 HP = 2
55};
56
62 public PerfGraphInterface,
64{
65public:
66 Adaptivity(FEProblemBase & fe_problem);
67 virtual ~Adaptivity();
68
76 void init(const unsigned int steps,
77 const unsigned int initial_steps,
78 const AdaptivityType adaptivity_type);
79
86 template <typename T>
87 void setParam(const std::string & param_name, const T & param_value);
88
95 void setErrorEstimator(const MooseEnum & error_estimator_name);
96
100 void setErrorNorm(libMesh::SystemNorm & sys_norm);
101
105 void setPrintMeshChanged(bool state = true) { _print_mesh_changed = state; }
106
112 unsigned int getInitialSteps() const { return _initial_steps; }
113
119 unsigned int getSteps() const { return _steps; }
120
126 unsigned int getCyclesPerStep() const { return _cycles_per_step; }
127
132 void setCyclesPerStep(const unsigned int & num) { _cycles_per_step = num; }
133
140
146
159 bool adaptMesh(std::string marker_name = std::string());
160
166 bool initialAdaptMesh();
167
174 static void uniformRefine(MooseMesh * mesh, unsigned int level = libMesh::invalid_uint);
175
181
186 void setAdaptivityOn(bool state);
187
193 bool isOn() { return _mesh_refinement_on; }
194
201 bool isInitialized() { return _initialized; }
202
208 void setTimeActive(Real start_time, Real stop_time);
209
215 void setAdaptivityControlFlag(const bool * adapt_control_flag);
216
220 void setUseNewSystem();
221
230 void setMarkerVariableName(std::string marker_field);
231
240 void setInitialMarkerVariableName(std::string marker_field);
241
245 void setMaxHLevel(unsigned int level) { _max_h_level = level; }
246
250 unsigned int getMaxHLevel() { return _max_h_level; }
251
255 void setInterval(unsigned int interval) { _interval = interval; }
256
265 libMesh::ErrorVector & getErrorVector(const std::string & indicator_field);
266
270 void updateErrorVectors();
271
275 bool isAdaptivityDue();
276
277protected:
280
286 std::unique_ptr<libMesh::MeshRefinement> _mesh_refinement;
288 std::unique_ptr<libMesh::ErrorEstimator> _error_estimator;
290 std::unique_ptr<libMesh::ErrorVector> _error;
291
292 std::shared_ptr<DisplacedProblem> _displaced_problem;
293
295 std::unique_ptr<libMesh::MeshRefinement> _displaced_mesh_refinement;
296
298 unsigned int _initial_steps;
300 unsigned int _steps;
301
304
306 Real & _t;
308 int & _step;
310 unsigned int _interval;
318 unsigned int _cycles_per_step;
319
322
325
328
331
333 unsigned int _max_h_level;
334
337
340 std::unique_ptr<libMesh::SiblingCoupling> _sibling_coupling;
341
343 std::unique_ptr<libMesh::HPCoarsenTest> _hp_coarsen_test;
344
346 std::map<std::string, std::unique_ptr<libMesh::ErrorVector>> _indicator_field_to_error_vector;
347};
348
349template <typename T>
350void
351Adaptivity::setParam(const std::string & param_name, const T & param_value)
352{
353 if (param_name == "refine fraction")
354 {
355 _mesh_refinement->refine_fraction() = param_value;
357 _displaced_mesh_refinement->refine_fraction() = param_value;
358 }
359 else if (param_name == "coarsen fraction")
360 {
361 _mesh_refinement->coarsen_fraction() = param_value;
363 _displaced_mesh_refinement->coarsen_fraction() = param_value;
364 }
365 else if (param_name == "max h-level")
366 {
367 _mesh_refinement->max_h_level() = param_value;
369 _displaced_mesh_refinement->max_h_level() = param_value;
370 }
371 else if (param_name == "cycles_per_step")
372 _cycles_per_step = param_value;
373 else if (param_name == "recompute_markers_during_cycles")
375 else
376 mooseError("Invalid Param in adaptivity object");
377}
378#endif // LIBMESH_ENABLE_AMR
AdaptivityType
Defines types of mesh adaptivity options available.
Definition Adaptivity.h:51
MooseVariableFE< Real > MooseVariable
Definition Adaptivity.h:34
MooseVariableFE< libMesh::VectorValue< Real > > VectorMooseVariable
Definition Adaptivity.h:35
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
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
std::unique_ptr< libMesh::SiblingCoupling > _sibling_coupling
Sibling coupling object for HP adaptivity for evaluating data on elements' siblings in HPCoarsenTest.
Definition Adaptivity.h:340
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition Adaptivity.h:298
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition Adaptivity.h:324
FEProblemBase & _fe_problem
Definition Adaptivity.h:278
std::map< std::string, std::unique_ptr< libMesh::ErrorVector > > _indicator_field_to_error_vector
Stores pointers to ErrorVectors associated with indicator field names.
Definition Adaptivity.h:346
MooseMesh & _mesh
Definition Adaptivity.h:279
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
Definition Adaptivity.C:380
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition Adaptivity.h:336
Real _start_time
When adaptivity start.
Definition Adaptivity.h:312
unsigned int getMaxHLevel()
Return the maximum h-level.
Definition Adaptivity.h:250
Real & _t
Time.
Definition Adaptivity.h:306
unsigned int getCyclesPerStep() const
Pull out the number of cycles_per_step previously set through the AdaptivityAction.
Definition Adaptivity.h:126
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition Adaptivity.C:366
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition Adaptivity.h:351
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition Adaptivity.h:255
std::unique_ptr< libMesh::ErrorVector > _error
Error vector for use with the error estimator.
Definition Adaptivity.h:290
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition Adaptivity.h:282
Real _stop_time
When adaptivity stops.
Definition Adaptivity.h:314
unsigned int _max_h_level
The maximum number of refinement levels.
Definition Adaptivity.h:333
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
bool initialAdaptMesh()
Used during initial adaptivity.
Definition Adaptivity.C:295
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
Definition Adaptivity.C:328
void setCyclesPerStep(const unsigned int &num)
Set the number of cycles_per_step.
Definition Adaptivity.h:132
void setErrorNorm(libMesh::SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
Definition Adaptivity.C:138
int & _step
Time Step.
Definition Adaptivity.h:308
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
Definition Adaptivity.C:356
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition Adaptivity.h:321
std::unique_ptr< libMesh::MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition Adaptivity.h:295
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition Adaptivity.C:301
void setAdaptivityControlFlag(const bool *adapt_control_flag)
Sets the boolean control flag to enable / disable adaptivity.
Definition Adaptivity.C:373
void setPrintMeshChanged(bool state=true)
Definition Adaptivity.h:105
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
libMesh::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:398
std::unique_ptr< libMesh::ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition Adaptivity.h:288
void setRecomputeMarkersFlag(const bool flag)
Set the flag to recompute markers during adaptivity cycles.
Definition Adaptivity.h:145
std::unique_ptr< libMesh::MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
Definition Adaptivity.h:286
bool getRecomputeMarkersFlag() const
Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.
Definition Adaptivity.h:139
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition Adaptivity.h:119
AdaptivityType _adaptivity_type
Type of mesh adaptivity.
Definition Adaptivity.h:327
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
Definition Adaptivity.C:145
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
Definition Adaptivity.C:428
bool isOn()
Is adaptivity on?
Definition Adaptivity.h:193
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition Adaptivity.h:292
virtual ~Adaptivity()
Definition Adaptivity.C:56
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition Adaptivity.h:318
std::unique_ptr< libMesh::HPCoarsenTest > _hp_coarsen_test
Object for HP adaptivity.
Definition Adaptivity.h:343
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
Definition Adaptivity.C:124
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
Definition Adaptivity.C:407
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition Adaptivity.h:284
bool isInitialized()
Returns whether or not Adaptivity::init() has ran.
Definition Adaptivity.h:201
unsigned int getInitialSteps() const
Pull out the number of initial steps previously set by calling init()
Definition Adaptivity.h:112
const bool * _controls_allow_adaptivity
If adaptivity is allowed by the control system.
Definition Adaptivity.h:316
unsigned int _steps
steps of adaptivity to perform
Definition Adaptivity.h:300
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition Adaptivity.h:303
unsigned int _interval
intreval between adaptivity runs
Definition Adaptivity.h:310
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition Adaptivity.h:330
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition Adaptivity.h:245
An inteface for the _console for outputting to the Console object.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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
Class for stuff related to variables.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
Interface for objects interacting with the PerfGraph.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const unsigned int invalid_uint