libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::VariationalMeshSmoother Class Reference

This is an implementation of Larisa Branets' smoothing algorithms. More...

#include <mesh_smoother_vsmoother.h>

Inheritance diagram for libMesh::VariationalMeshSmoother:
[legend]

Public Member Functions

 VariationalMeshSmoother (UnstructuredMesh &mesh, Real dilation_weight=0.5, const bool preserve_subdomain_boundaries=true, const Real relative_residual_tolerance=TOLERANCE *TOLERANCE, const Real absolute_residual_tolerance=TOLERANCE *TOLERANCE, const unsigned int verbosity=0)
 Constructor.
 
virtual ~VariationalMeshSmoother ()=default
 Destructor.
 
virtual void setup ()
 Setup method that creates equation systems, system, and constraints, to be called just prior to smoothing.
 
virtual void smooth () override
 Redefinition of the smooth function from the base class.
 
const MeshQualityInfo & get_mesh_info () const
 Getter for the _system's _mesh_info attribute.
 
void set_quadrature_type (QuadratureType qt)
 Set the quadrature rule type used by the underlying VariationalSmootherSystem to integrate the distortion-dilation metric.
 

Protected Attributes

UnstructuredMesh & _mesh
 

Private Member Functions

VariationalSmootherSystem * system () const
 Getter for _system to protect against dangling pointers.
 

Private Attributes

const unsigned int _verbosity
 verbosity setting
 
const Real _dilation_weight
 Smoother control variables.
 
const bool _preserve_subdomain_boundaries
 Whether subdomain boundaries are subject to change via smoothing.
 
std::unique_ptr< DistributedMesh > _mesh_copy
 Mesh copy to avoid multiple EquationSystems.
 
std::unique_ptr< EquationSystems > _equation_systems
 EquationsSystems object associated with the smoother.
 
VariationalSmootherSystem * _system
 
std::unique_ptr< VariationalSmootherConstraint > _constraint
 Constraints imposed on the smoothing process.
 
bool _setup_called
 Attribute the keep track of whether the setup method has been called.
 
Real _relative_residual_tolerance
 Solver relative residual tolerance.
 
Real _absolute_residual_tolerance
 Solver absolute residual tolerance.
 
QuadratureType _quadrature_type = QGAUSS
 Quadrature rule type used to integrate the distortion-dilation metric.
 

Detailed Description

This is an implementation of Larisa Branets' smoothing algorithms.

The initial implementation was done by her, the adaptation to libmesh was completed by Derek Gaston. The code was heavily refactored into something more closely resembling C++ by John Peterson in 2014. The code eventually fell out of use and stopped functioning. Patrick Behne reimplemented the smoother in 2025.

Here are the relevant publications: 1) L. Branets, G. Carey, "Extension of a mesh quality metric for elements with a curved boundary edge or surface", Journal of Computing and Information Science in Engineering, vol. 5(4), pp.302-308, 2005.

2) L. Branets, G. Carey, "A local cell quality metric and variational grid smoothing algorithm", Engineering with Computers, vol. 21, pp.19-28, 2005.

3) L. Branets, "A variational grid optimization algorithm based on a local cell quality metric", Ph.D. thesis, The University of Texas at Austin, 2005.

Notes:

1) The smoother supports tangled meshes. However, not all untangling solves converge. In other words, we are able to untangle SOME tangled meshes, but not ANY tangled mesh.

Author
Derek R. Gaston
Date
2006

Definition at line 75 of file mesh_smoother_vsmoother.h.

Constructor & Destructor Documentation

◆ VariationalMeshSmoother()

libMesh::VariationalMeshSmoother::VariationalMeshSmoother ( UnstructuredMesh &  mesh,
Real  dilation_weight = 0.5,
const bool  preserve_subdomain_boundaries = true,
const Real  relative_residual_tolerance = TOLERANCE * TOLERANCE,
const Real  absolute_residual_tolerance = TOLERANCE * TOLERANCE,
const unsigned int  verbosity = 0 
)

Constructor.

Parameters
meshMesh to smooth by minimizing the distortion-dilation metric.
dilation_wiehgtWeight to give the dilation metric. The distortion metric is given 1 - dilation_weight.
preserve_subdomain_boundariesWhether the smoother is to preserve or modify sobdomain boundaries.
relative_residual_toleranceSolver setting for the relative residual tolerance.
absolute_residual_toleranceSolver setting for the absolute residual tolerance.
verbositySmoother verbosity option specifying how much information is output. The verbosity levels and the corresponding information output are as follows:

verbosity = 0 : No information

verbosity > 15: Prints:

  • Solver nonlinear and linear iteration information

The VariationalSmootherSystem and VariationalSmootherConstraint classes use the same verbosity value as this VariationalMeshSmoother class. For details on what those systems print, refer to the documentation for the _verbosity attribute in each class.

Definition at line 54 of file mesh_smoother_vsmoother.C.

59 : MeshSmoother(mesh), _verbosity(verbosity),
60 _dilation_weight(dilation_weight),
61 _preserve_subdomain_boundaries(preserve_subdomain_boundaries),
62 _setup_called(false),
63 _relative_residual_tolerance(relative_residual_tolerance),
64 _absolute_residual_tolerance(absolute_residual_tolerance) {}
MeshSmoother(UnstructuredMesh &mesh)
Constructor.
const Real _dilation_weight
Smoother control variables.
const unsigned int _verbosity
verbosity setting
Real _relative_residual_tolerance
Solver relative residual tolerance.
Real _absolute_residual_tolerance
Solver absolute residual tolerance.
bool _setup_called
Attribute the keep track of whether the setup method has been called.
const bool _preserve_subdomain_boundaries
Whether subdomain boundaries are subject to change via smoothing.
MeshBase & mesh

◆ ~VariationalMeshSmoother()

virtual libMesh::VariationalMeshSmoother::~VariationalMeshSmoother ( )
virtualdefault

Destructor.

Member Function Documentation

◆ get_mesh_info()

const MeshQualityInfo & libMesh::VariationalMeshSmoother::get_mesh_info ( ) const

Getter for the _system's _mesh_info attribute.

Definition at line 200 of file mesh_smoother_vsmoother.C.

201{
202 libmesh_error_msg_if(!_setup_called, "Need to first call the setup() method of "
203 << "this VariationalMeshSmoother object, then call get_mesh_info() prior "
204 << "to calling smooth().");
205 return _system->get_mesh_info();
206}
const MeshQualityInfo & get_mesh_info()
Getter for the _mesh_info attribute.

References _setup_called, _system, and libMesh::VariationalSmootherSystem::get_mesh_info().

Referenced by MeshSmootherTest::testVariationalSmoother().

◆ set_quadrature_type()

void libMesh::VariationalMeshSmoother::set_quadrature_type ( QuadratureType  qt)
inline

Set the quadrature rule type used by the underlying VariationalSmootherSystem to integrate the distortion-dilation metric.

The default (QGAUSS) samples the element interior only, which can miss degeneracies localized at element corners (e.g. an element collapsing toward one of its nodes). A vertex-sampling rule such as QTRAP, QSIMPSON, QNODAL, or QGAUSS_LOBATTO evaluates the metric at the element nodes so a folding corner is penalized (and flagged as tangled) as it should be. Must be called before smooth()/setup(). See VariationalSmootherSystem::set_quadrature_type() for details and caveats.

Definition at line 143 of file mesh_smoother_vsmoother.h.

143{ _quadrature_type = qt; }
QuadratureType _quadrature_type
Quadrature rule type used to integrate the distortion-dilation metric.

References _quadrature_type.

Referenced by MeshSmootherTest::testVariationalQuadratureHourglass().

◆ setup()

void libMesh::VariationalMeshSmoother::setup ( )
virtual

Setup method that creates equation systems, system, and constraints, to be called just prior to smoothing.

Definition at line 66 of file mesh_smoother_vsmoother.C.

67{
68 // Check for multiple dimensions
71
72 if (_mesh.elem_dimensions().size() > 1)
73 libmesh_not_implemented_msg("Meshes containing elements of differing dimension are not yet supported.");
74
75 /*
76 Ideally we'd want to update _mesh directly even if it already has an
77 EquationSystems attached and doing work on it ... and that's thwarted by the
78 problems:
79
80 1. We can't easily tell if there's already an EquationSystems attached.
81 2. We can't attach a second EquationSystems safely (if it already has a system 0)
82 because the DoF indexing will need to be overwritten by our system.
83 3. The destructor of es won't even clean up after itself (we generally expect
84 a mesh to go unused after its EquationSystems is destroyed), much less know
85 how to restore anything from a previous EquationSystems.
86
87 To avoid these issues, we'll just construct a new DistributedMesh _mesh_copy
88 from _mesh, then do the solve on _mesh_copy, then copy its node locations back
89 to _mesh after the solve is done. That'll be slightly less memory-efficient
90 and somewhat more CPU-efficient in the case where _mesh is serial, though
91 it'll be significantly less memory-efficient when _mesh is already distributed,
92 but either way the robustness is probably worth it.
93 */
94
95 // Create a new mesh, EquationSystems, and System
96 _mesh_copy = std::make_unique<DistributedMesh>(_mesh);
97
98 // If the _mesh wasn't prepared, that's fine (we'll just be moving
99 // its nodes), but we do need the copy to be prepared before our
100 // solve does things like looking at neighbors. We'll disable
101 // repartitioning and renumbering first to make sure that we can
102 // transfer our geometry changes back to the original mesh.
103 _mesh_copy->allow_renumbering(false);
104 _mesh_copy->skip_partitioning(true);
105 _mesh_copy->complete_preparation();
106
107 _equation_systems = std::make_unique<EquationSystems>(*_mesh_copy);
108 _system =
109 &(_equation_systems->add_system<VariationalSmootherSystem>("variational_smoother_system"));
110
111 // Set this to something > 0 to add more quadrature points than the default
112 // rule that integrates order 2 * fe_order + 1 polynomials exactly.
113 // Using higher quadrature orders has not had a significant effect on observed solutions.
114 //system()->extra_quadrature_order = 0;
115
116 // The default Gauss rule samples the element interior only, so it can miss
117 // degeneracies localized at element corners (e.g. an element collapsing
118 // toward one of its nodes). Selecting a vertex-sampling rule (QTRAP,
119 // QSIMPSON, QNODAL, QGAUSS_LOBATTO) evaluates the metric at the element
120 // nodes instead. Defaults to QGAUSS.
122
123 // Uncomment these to debug
124 //system()->print_element_solutions=true;
125 //system()->print_element_residuals=true;
126 //system()->print_element_jacobians=true;
127
128 // Add boundary node and hanging node constraints
129 _constraint = std::make_unique<VariationalSmootherConstraint>(
132
133 // Set system parameters
136
137 // Set up solver
138 system()->time_solver = std::make_unique<SteadySolver>(*_system);
139
140 // Uncomment this line and use -snes_test_jacobian and -snes_test_jacobian_view
141 // flags to compare the hand-coded jacobian in VariationalSmootherSystem
142 // to finite difference jacobians.
143 //system()->time_solver->diff_solver() = std::make_unique<PetscDiffSolver>(*_system);
144
145 _equation_systems->init();
146
147 // Solver verbosity
148 if (_verbosity > 15) {
149 DiffSolver &solver = *(system()->time_solver->diff_solver().get());
150 solver.quiet = false;
151 solver.verbose = true;
152 }
153
154 // Solver convergence tolerances
155 system()->time_solver->diff_solver()->relative_residual_tolerance = _relative_residual_tolerance;
156 system()->time_solver->diff_solver()->absolute_residual_tolerance = _absolute_residual_tolerance;
157
158 _setup_called = true;
159}
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
Preparation preparation() const
Definition mesh_base.h:221
const std::set< unsigned char > & elem_dimensions() const
Definition mesh_base.h:2801
UnstructuredMesh & _mesh
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition system.C:2062
std::unique_ptr< VariationalSmootherConstraint > _constraint
Constraints imposed on the smoothing process.
std::unique_ptr< EquationSystems > _equation_systems
EquationsSystems object associated with the smoother.
VariationalSmootherSystem * system() const
Getter for _system to protect against dangling pointers.
std::unique_ptr< DistributedMesh > _mesh_copy
Mesh copy to avoid multiple EquationSystems.
void set_quadrature_type(QuadratureType qt)
Set the quadrature rule type used to integrate the distortion-dilation metric over each element.
void set_verbosity(const unsigned int verbosity)

References _absolute_residual_tolerance, _constraint, _dilation_weight, _equation_systems, libMesh::MeshSmoother::_mesh, _mesh_copy, _preserve_subdomain_boundaries, _quadrature_type, _relative_residual_tolerance, _setup_called, _system, _verbosity, libMesh::System::attach_constraint_object(), libMesh::MeshBase::cache_elem_data(), libMesh::MeshBase::elem_dimensions(), libMesh::VariationalSmootherSystem::get_dilation_weight(), libMesh::MeshBase::Preparation::has_cached_elem_data, libMesh::MeshBase::preparation(), libMesh::DiffSolver::quiet, libMesh::VariationalSmootherSystem::set_quadrature_type(), libMesh::VariationalSmootherSystem::set_verbosity(), system(), libMesh::DifferentiableSystem::time_solver, and libMesh::DiffSolver::verbose.

Referenced by smooth(), and MeshSmootherTest::testVariationalSmoother().

◆ smooth()

void libMesh::VariationalMeshSmoother::smooth ( )
overridevirtual

Redefinition of the smooth function from the base class.

All this does is call the smooth function in this class which takes an int, using a default value of 1.

Implements libMesh::MeshSmoother.

Definition at line 161 of file mesh_smoother_vsmoother.C.

162{
163 LOG_SCOPE("smooth()", "VariationalMeshSmoother");
164
165 if (!_setup_called)
166 setup();
167
168 libmesh_try
169 {
170 system()->solve();
171 }
172
173 libmesh_catch (ConvergenceFailure& e)
174 {
175#ifdef LIBMESH_ENABLE_EXCEPTIONS
176 throw ConvergenceFailure("The VariationalMeshSmoother solve failed to converge.");
177#endif
178 }
179
180 // Update _mesh from _mesh_copy
182 (_mesh_copy->local_node_stored_range(),
183 [this](Node * node_copy)
184 {
185 Point & node = _mesh.node_ref(node_copy->id());
186 node = *node_copy;
187 });
188
189 SyncNodalPositions sync_object(_mesh);
190 Parallel::sync_dofobject_data_by_id (_mesh.comm(), _mesh.nodes_begin(), _mesh.nodes_end(), sync_object);
191
192 // Release memory occupied by _mesh_copy
193 // Destruct this before _mesh_copy because it references _mesh_copy
194 _equation_systems.reset();
195 _mesh_copy.reset();
196 // We'll need to call setup again since we'll have to reconstruct _mesh_copy
197 _setup_called = false;
198}
const Parallel::Communicator & comm() const
virtual void setup()
Setup method that creates equation systems, system, and constraints, to be called just prior to smoot...
virtual void solve() override
Solves the system to smooth the mesh.
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.
void parallel_for_each(Range &&range, Body &&body, unsigned int n_threads=libMesh::n_threads())
A nicer syntax for parallel_for calls in cases where no setup or teardown is needed outside the subra...
Definition threads.h:308

References _equation_systems, libMesh::MeshSmoother::_mesh, _mesh_copy, _setup_called, libMesh::ParallelObject::comm(), libMesh::Threads::parallel_for_each(), setup(), libMesh::VariationalSmootherSystem::solve(), libMesh::Parallel::sync_dofobject_data_by_id(), and system().

Referenced by main(), MeshSmootherTest::testVariationalQuadratureHourglass(), MeshSmootherTest::testVariationalSmoother(), and MeshSmootherTest::testVariationalSmootherRegression().

◆ system()

VariationalSmootherSystem * libMesh::VariationalMeshSmoother::system ( ) const
inlineprivate

Getter for _system to protect against dangling pointers.

Definition at line 189 of file mesh_smoother_vsmoother.h.

190 {
192 return _system;
193 }
libmesh_assert(ctx)

References _system, and libMesh::libmesh_assert().

Referenced by setup(), and smooth().

Member Data Documentation

◆ _absolute_residual_tolerance

Real libMesh::VariationalMeshSmoother::_absolute_residual_tolerance
private

Solver absolute residual tolerance.

Definition at line 214 of file mesh_smoother_vsmoother.h.

Referenced by setup().

◆ _constraint

std::unique_ptr<VariationalSmootherConstraint> libMesh::VariationalMeshSmoother::_constraint
private

Constraints imposed on the smoothing process.

Definition at line 199 of file mesh_smoother_vsmoother.h.

Referenced by setup().

◆ _dilation_weight

const Real libMesh::VariationalMeshSmoother::_dilation_weight
private

Smoother control variables.

Definition at line 155 of file mesh_smoother_vsmoother.h.

Referenced by setup().

◆ _equation_systems

std::unique_ptr<EquationSystems> libMesh::VariationalMeshSmoother::_equation_systems
private

EquationsSystems object associated with the smoother.

Definition at line 175 of file mesh_smoother_vsmoother.h.

Referenced by setup(), and smooth().

◆ _mesh

UnstructuredMesh& libMesh::MeshSmoother::_mesh
protectedinherited

Definition at line 61 of file mesh_smoother.h.

Referenced by setup(), libMesh::LaplaceMeshSmoother::smooth(), and smooth().

◆ _mesh_copy

std::unique_ptr<DistributedMesh> libMesh::VariationalMeshSmoother::_mesh_copy
private

Mesh copy to avoid multiple EquationSystems.

Definition at line 169 of file mesh_smoother_vsmoother.h.

Referenced by setup(), and smooth().

◆ _preserve_subdomain_boundaries

const bool libMesh::VariationalMeshSmoother::_preserve_subdomain_boundaries
private

Whether subdomain boundaries are subject to change via smoothing.

Definition at line 160 of file mesh_smoother_vsmoother.h.

Referenced by setup().

◆ _quadrature_type

QuadratureType libMesh::VariationalMeshSmoother::_quadrature_type = QGAUSS
private

Quadrature rule type used to integrate the distortion-dilation metric.

See set_quadrature_type().

Definition at line 220 of file mesh_smoother_vsmoother.h.

Referenced by set_quadrature_type(), and setup().

◆ _relative_residual_tolerance

Real libMesh::VariationalMeshSmoother::_relative_residual_tolerance
private

Solver relative residual tolerance.

Definition at line 209 of file mesh_smoother_vsmoother.h.

Referenced by setup().

◆ _setup_called

bool libMesh::VariationalMeshSmoother::_setup_called
private

Attribute the keep track of whether the setup method has been called.

Definition at line 204 of file mesh_smoother_vsmoother.h.

Referenced by get_mesh_info(), setup(), and smooth().

◆ _system

VariationalSmootherSystem* libMesh::VariationalMeshSmoother::_system
private

Definition at line 184 of file mesh_smoother_vsmoother.h.

Referenced by get_mesh_info(), setup(), and system().

◆ _verbosity

const unsigned int libMesh::VariationalMeshSmoother::_verbosity
private

verbosity setting

Definition at line 150 of file mesh_smoother_vsmoother.h.

Referenced by setup().


The documentation for this class was generated from the following files: