Go to the documentation of this file.
22 #include "libmesh/equation_systems.h"
23 #include "libmesh/kelly_error_estimator.h"
24 #include "libmesh/patch_recovery_error_estimator.h"
25 #include "libmesh/fourth_error_estimators.h"
26 #include "libmesh/parallel.h"
27 #include "libmesh/error_vector.h"
29 #ifdef LIBMESH_ENABLE_AMR
34 ParallelObject(subproblem.getMooseApp()),
35 _subproblem(subproblem),
36 _mesh(_subproblem.mesh()),
37 _mesh_refinement_on(false),
41 _print_mesh_changed(false),
42 _t(_subproblem.time()),
43 _step(_subproblem.timeStep()),
45 _start_time(-
std::numeric_limits<Real>::max()),
46 _stop_time(
std::numeric_limits<Real>::max()),
48 _use_new_system(false),
50 _recompute_markers_during_cycles(false),
51 _adapt_mesh_timer(registerTimedSection(
"adaptMesh", 3)),
52 _uniform_refine_timer(registerTimedSection(
"uniformRefine", 2)),
53 _uniform_refine_with_projection(registerTimedSection(
"uniformRefineWithProjection", 2)),
54 _update_error_vectors(registerTimedSection(
"updateErrorVectors", 5))
69 _error = libmesh_make_unique<ErrorVector>();
72 es.parameters.set<
bool>(
"adaptivity") =
true;
85 displaced_es.parameters.set<
bool>(
"adaptivity") =
true;
108 if (error_estimator_name ==
"KellyErrorEstimator")
110 else if (error_estimator_name ==
"LaplacianErrorEstimator")
112 else if (error_estimator_name ==
"PatchRecoveryErrorEstimator")
115 mooseError(std::string(
"Unknown error_estimator selection: ") +
116 std::string(error_estimator_name));
122 mooseAssert(
_error_estimator,
"error_estimator not initialized. Did you call init_adaptivity()?");
132 if (marker_name.empty())
135 bool mesh_changed =
false;
139 if (!marker_name.empty())
143 std::vector<Number> serialized_solution;
151 Threads::parallel_reduce(all_elems, fet);
184 bool displaced_mesh_changed =
189 mooseAssert(displaced_mesh_changed,
"Undisplaced mesh changed, but displaced mesh did not!");
210 mooseAssert(mesh,
"Mesh pointer must not be NULL");
214 MeshRefinement mesh_refinement(*mesh);
215 if (level == libMesh::invalid_uint)
217 mesh_refinement.uniformly_refine(level);
225 CONSOLE_TIMED_PRINT(
"Uniformly refining mesh and reprojecting");
229 MeshRefinement mesh_refinement(
_mesh);
234 for (
unsigned int i = 0; i < level; i++)
240 mesh_refinement.uniformly_refine(1);
243 displaced_mesh_refinement.uniformly_refine(1);
253 mooseError(
"Mesh adaptivity system not available");
289 return *insert_pair.first->second;
300 ErrorVector & vec = *(it.second);
310 _subproblem.comm().sum((std::vector<float> &)*(it.second));
319 #endif // LIBMESH_ENABLE_AMR
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
An inteface for the _console for outputting to the Console object.
bool initialAdaptMesh()
Used during initial adaptivity.
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
virtual void meshChanged() override
Update data after a mesh change.
NumericVector< Number > & solution() override
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
virtual DofMap & dofMap()
Gets writeable reference to the dof map.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
PerfID _adapt_mesh_timer
Timers.
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
void printInfo(std::ostream &os=libMesh::out) const
Calls print_info() on the underlying Mesh.
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
std::map< std::string, std::unique_ptr< ErrorVector > > _indicator_field_to_error_vector
Stores pointers to ErrorVectors associated with indicator field names.
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
FEProblemBase & _subproblem
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
PerfID _update_error_vectors
unsigned int _max_h_level
The maximum number of refinement levels.
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
virtual System & system() override
Get the reference to the libMesh system.
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
std::string _initial_marker_variable_name
Name of the initial marker variable if using the new adaptivity system.
void setInitialMarkerVariableName(std::string marker_field)
Sets the name of the field variable to actually use to flag elements for initial refinement / coarsen...
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
unsigned int _steps
steps of adaptivity to perform
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Interface for objects that needs transient capabilities.
Real _stop_time
When adaptivity stops.
PerfID _uniform_refine_with_projection
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
bool _use_new_system
Whether or not to use the "new" adaptivity system.
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
NonlinearSystemBase & getNonlinearSystemBase()
AuxiliarySystem & getAuxiliarySystem()
virtual EquationSystems & es() override
std::pair< typename M::iterator, bool > moose_try_emplace(M &m, const typename M::key_type &k, Args &&... args)
Function to mirror the behavior of the C++17 std::map::try_emplace() method (no hint).
ErrorVector & getErrorVector(const std::string &indicator_field)
Get an ErrorVector that will be filled up with values corresponding to the indicator field name passe...
void setMarkerVariableName(std::string marker_field)
Sets the name of the field variable to actually use to flag elements for refinement / coarsening.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
unsigned int uniformRefineLevel() const
Returns the level of uniform refinement requested (zero if AMR is disabled).
std::shared_ptr< DisplacedProblem > _displaced_problem
Real _start_time
When adaptivity start.
void setErrorNorm(SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
Adaptivity(FEProblemBase &subproblem)
unsigned int _interval
intreval between adaptivity runs
virtual MooseMesh & mesh() override