21 #include "libmesh/equation_systems.h" 22 #include "libmesh/kelly_error_estimator.h" 23 #include "libmesh/patch_recovery_error_estimator.h" 24 #include "libmesh/fourth_error_estimators.h" 25 #include "libmesh/parallel.h" 26 #include "libmesh/error_vector.h" 27 #include "libmesh/distributed_mesh.h" 29 #ifdef LIBMESH_ENABLE_AMR 34 ParallelObject(fe_problem.getMooseApp()),
35 _fe_problem(fe_problem),
36 _mesh(_fe_problem.
mesh()),
37 _mesh_refinement_on(false),
41 _print_mesh_changed(false),
42 _t(_fe_problem.time()),
43 _step(_fe_problem.timeStep()),
45 _start_time(-
std::numeric_limits<
Real>::
max()),
48 _use_new_system(false),
50 _recompute_markers_during_cycles(false)
65 _error = std::make_unique<ErrorVector>();
68 es.parameters.set<
bool>(
"adaptivity") =
true;
81 displaced_es.parameters.set<
bool>(
"adaptivity") =
true;
104 if (error_estimator_name ==
"KellyErrorEstimator")
106 else if (error_estimator_name ==
"LaplacianErrorEstimator")
108 else if (error_estimator_name ==
"PatchRecoveryErrorEstimator")
111 mooseError(std::string(
"Unknown error_estimator selection: ") +
112 std::string(error_estimator_name));
118 mooseAssert(
_error_estimator,
"error_estimator not initialized. Did you call init_adaptivity()?");
125 TIME_SECTION(
"adaptMesh", 3,
"Adapting Mesh");
128 if (marker_name.empty())
131 bool mesh_changed =
false;
134 bool distributed_adaptivity =
false;
138 if (!marker_name.empty())
142 std::vector<Number> serialized_solution;
147 std::unique_ptr<ConstElemRange> all_elems;
152 if (distributed_mesh && !distributed_mesh->is_serial_on_zero())
156 distributed_adaptivity =
true;
168 all_elems = std::make_unique<ConstElemRange>(
176 distributed_adaptivity =
false;
191 Threads::parallel_reduce(*all_elems, fet);
221 if (distributed_adaptivity)
234 if (distributed_adaptivity)
241 bool displaced_mesh_changed =
246 mooseAssert(displaced_mesh_changed,
"Undisplaced mesh changed, but displaced mesh did not!");
268 mooseAssert(
mesh,
"Mesh pointer must not be NULL");
272 MeshRefinement mesh_refinement(*
mesh);
274 level =
mesh->uniformRefineLevel();
282 if (
mesh->skipDeletionRepartitionAfterRefine())
284 mesh->getMesh().skip_partitioning(
true);
285 mesh->getMesh().allow_remote_element_removal(
false);
286 mesh->needsRemoteElemDeletion(
false);
289 mesh_refinement.uniformly_refine(level);
295 TIME_SECTION(
"uniformRefineWithProjection", 2,
"Uniformly Refining and Reprojecting");
299 MeshRefinement mesh_refinement(
_mesh);
304 for (
unsigned int i = 0; i < level; i++)
310 mesh_refinement.uniformly_refine(1);
313 displaced_mesh_refinement.uniformly_refine(1);
323 mooseError(
"Mesh adaptivity system not available");
359 return *insert_pair.first->second;
365 TIME_SECTION(
"updateErrorVectors", 5,
"Updating Error Vectors");
370 ErrorVector & vec = *(it.second);
397 #endif // LIBMESH_ENABLE_AMR virtual void update(bool update_libmesh_system=true)
Update the system (doing libMesh magic)
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
bool initialAdaptMesh()
Used during initial adaptivity.
void doingPRefinement(bool doing_p_refinement, const MultiMooseEnum &disable_p_refinement_for_families)
Indicate whether the kind of adaptivity we're doing is p-refinement.
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
std::shared_ptr< DisplacedProblem > _displaced_problem
Real _stop_time
When adaptivity stops.
std::string _marker_variable_name
Name of the marker variable if using the new adaptivity system.
std::unique_ptr< MeshRefinement > _displaced_mesh_refinement
A mesh refinement object for displaced mesh.
const unsigned int invalid_uint
std::unique_ptr< ErrorEstimator > _error_estimator
Error estimator to be used by the apps.
bool _initialized
on/off flag reporting if the adaptivity system has been initialized
NumericVector< Number > & solution()
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
void init(unsigned int steps, unsigned int initial_steps)
Initialize and turn on adaptivity for the simulation.
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
virtual void doingPRefinement(bool doing_p_refinement, const MultiMooseEnum &disable_p_refinement_for_families) override
Indicate whether the kind of adaptivity we're doing is p-refinement.
const Parallel::Communicator & comm() const
std::unique_ptr< ErrorVector > _error
Error vector for use with the error estimator.
void setUseNewSystem()
Tells this object we're using the "new" adaptivity system.
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).
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.
std::map< std::string, std::unique_ptr< ErrorVector > > _indicator_field_to_error_vector
Stores pointers to ErrorVectors associated with indicator field names.
auto max(const L &left, const R &right)
virtual EquationSystems & es() override
bool _print_mesh_changed
True if we want to print out info when mesh has changed.
virtual DofMap & dofMap()
Gets writeable reference to the dof map.
std::unique_ptr< MeshRefinement > _mesh_refinement
A mesh refinement object to be used either with initial refinement or with Adaptivity.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
bool _mesh_refinement_on
on/off flag reporting if the adaptivity is being used
Adaptivity(FEProblemBase &fe_problem)
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...
virtual void meshChanged() override
Update data after a mesh change.
void setAdaptivityOn(bool state)
Allow adaptivity to be toggled programatically.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
unsigned int uniformRefineLevel() const
Returns the level of uniform refinement requested (zero if AMR is disabled).
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
AuxiliarySystem & getAuxiliarySystem()
unsigned int _steps
steps of adaptivity to perform
Interface for objects interacting with the PerfGraph.
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
void printInfo(std::ostream &os=libMesh::out, const unsigned int verbosity=0) const
Calls print_info() on the underlying Mesh.
unsigned int _initial_steps
the number of adaptivity steps to do at the beginning of simulation
bool _use_new_system
Whether or not to use the "new" adaptivity system.
unsigned int _interval
intreval between adaptivity runs
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
ErrorVector & getErrorVector(const std::string &indicator_field)
Get an ErrorVector that will be filled up with values corresponding to the indicator field name passe...
virtual System & system() override
Get the reference to the libMesh system.
virtual MooseMesh & mesh() override
Real _start_time
When adaptivity start.
void setErrorNorm(SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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...
unsigned int _max_h_level
The maximum number of refinement levels.
void setInitialMarkerVariableName(std::string marker_field)
Sets the name of the field variable to actually use to flag elements for initial refinement / coarsen...
FEProblemBase & _fe_problem
virtual void localize(std::vector< Number > &v_local) const =0