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
213 void setUseNewSystem();
214
223 void setMarkerVariableName(std::string marker_field);
224
233 void setInitialMarkerVariableName(std::string marker_field);
234
238 void setMaxHLevel(unsigned int level) { _max_h_level = level; }
239
243 unsigned int getMaxHLevel() { return _max_h_level; }
244
248 void setInterval(unsigned int interval) { _interval = interval; }
249
258 libMesh::ErrorVector & getErrorVector(const std::string & indicator_field);
259
263 void updateErrorVectors();
264
268 bool isAdaptivityDue();
269
270protected:
273
279 std::unique_ptr<libMesh::MeshRefinement> _mesh_refinement;
281 std::unique_ptr<libMesh::ErrorEstimator> _error_estimator;
283 std::unique_ptr<libMesh::ErrorVector> _error;
284
285 std::shared_ptr<DisplacedProblem> _displaced_problem;
286
288 std::unique_ptr<libMesh::MeshRefinement> _displaced_mesh_refinement;
289
291 unsigned int _initial_steps;
293 unsigned int _steps;
294
297
299 Real & _t;
301 int & _step;
303 unsigned int _interval;
309 unsigned int _cycles_per_step;
310
313
316
319
322
324 unsigned int _max_h_level;
325
328
331 std::unique_ptr<libMesh::SiblingCoupling> _sibling_coupling;
332
334 std::unique_ptr<libMesh::HPCoarsenTest> _hp_coarsen_test;
335
337 std::map<std::string, std::unique_ptr<libMesh::ErrorVector>> _indicator_field_to_error_vector;
338};
339
340template <typename T>
341void
342Adaptivity::setParam(const std::string & param_name, const T & param_value)
343{
344 if (param_name == "refine fraction")
345 {
346 _mesh_refinement->refine_fraction() = param_value;
348 _displaced_mesh_refinement->refine_fraction() = param_value;
349 }
350 else if (param_name == "coarsen fraction")
351 {
352 _mesh_refinement->coarsen_fraction() = param_value;
354 _displaced_mesh_refinement->coarsen_fraction() = param_value;
355 }
356 else if (param_name == "max h-level")
357 {
358 _mesh_refinement->max_h_level() = param_value;
360 _displaced_mesh_refinement->max_h_level() = param_value;
361 }
362 else if (param_name == "cycles_per_step")
363 _cycles_per_step = param_value;
364 else if (param_name == "recompute_markers_during_cycles")
366 else
367 mooseError("Invalid Param in adaptivity object");
368}
369#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:60
std::unique_ptr< libMesh::SiblingCoupling > _sibling_coupling
Sibling coupling object for HP adaptivity for evaluating data on elements' siblings in HPCoarsenTest.
Definition Adaptivity.h:331
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
Definition Adaptivity.h:291
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
Definition Adaptivity.h:315
FEProblemBase & _fe_problem
Definition Adaptivity.h:271
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:390
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:337
MooseMesh & _mesh
Definition Adaptivity.h:272
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
Definition Adaptivity.C:372
bool _recompute_markers_during_cycles
Whether or not to recompute markers during adaptivity cycles.
Definition Adaptivity.h:327
Real _start_time
When adaptivity start.
Definition Adaptivity.h:305
unsigned int getMaxHLevel()
Return the maximum h-level.
Definition Adaptivity.h:243
Real & _t
Time.
Definition Adaptivity.h:299
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:365
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition Adaptivity.h:342
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition Adaptivity.h:248
std::unique_ptr< libMesh::ErrorVector > _error
Error vector for use with the error estimator.
Definition Adaptivity.h:283
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Definition Adaptivity.h:275
Real _stop_time
When adaptivity stops.
Definition Adaptivity.h:307
unsigned int _max_h_level
The maximum number of refinement levels.
Definition Adaptivity.h:324
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:378
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:301
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
Definition Adaptivity.C:355
bool _use_new_system
Whether or not to use the "new" adaptivity system.
Definition Adaptivity.h:312
std::unique_ptr< libMesh::MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
Definition Adaptivity.h:288
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition Adaptivity.C:301
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:384
std::unique_ptr< libMesh::ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
Definition Adaptivity.h:281
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:279
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:318
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:420
bool isOn()
Is adaptivity on?
Definition Adaptivity.h:193
std::shared_ptr< DisplacedProblem > _displaced_problem
Definition Adaptivity.h:285
virtual ~Adaptivity()
Definition Adaptivity.C:57
unsigned int _cycles_per_step
The number of adaptivity cycles per step.
Definition Adaptivity.h:309
std::unique_ptr< libMesh::HPCoarsenTest > _hp_coarsen_test
Object for HP adaptivity.
Definition Adaptivity.h:334
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:399
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
Definition Adaptivity.h:277
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
unsigned int _steps
steps of adaptivity to perform
Definition Adaptivity.h:293
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
Definition Adaptivity.h:296
unsigned int _interval
intreval between adaptivity runs
Definition Adaptivity.h:303
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
Definition Adaptivity.h:321
void setMaxHLevel(unsigned int level)
Set the maximum refinement level (for the new Adaptivity system).
Definition Adaptivity.h:238
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