libMesh
mesh_smoother_vsmoother.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
21 #define LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
22 
23 #include "libmesh/libmesh_config.h"
24 #if defined(LIBMESH_ENABLE_VSMOOTHER)
25 
26 // Local Includes
27 #include "libmesh/libmesh_common.h"
28 #include "libmesh/mesh_smoother.h"
29 #include "libmesh/variational_smoother_system.h"
30 #include "libmesh/variational_smoother_constraint.h"
31 #include "petsc_diff_solver.h"
32 #include "libmesh/distributed_mesh.h"
33 #include "libmesh/equation_systems.h"
34 
35 // C++ Includes
36 #include <cstddef>
37 #include <vector>
38 #include <map>
39 #include <fstream>
40 
41 namespace libMesh
42 {
43 
44 // Forward declarations
45 class UnstructuredMesh;
46 
76 {
77 public:
91  Real dilation_weight = 0.5,
92  const bool preserve_subdomain_boundaries = true,
93  const double relative_residual_tolerance = TOLERANCE * TOLERANCE,
94  const double absolute_residual_tolerance = TOLERANCE * TOLERANCE,
95  const bool solver_quiet = true,
96  const bool solver_verbose = false);
97 
101  virtual ~VariationalMeshSmoother() = default;
102 
107  virtual void setup();
108 
115  virtual void smooth() override {this->smooth(1); }
116 
122  void smooth(unsigned int n_iterations);
123 
127  const MeshQualityInfo & get_mesh_info() const;
128 
129 private:
130 
135 
140 
141  // These must be declared in reverse dependency order to avoid corrupting the
142  // heap during destruction
143 
147  // independent of _equations_systems and _constraint
148  std::unique_ptr<DistributedMesh> _mesh_copy;
149 
153  // uses _mesh_copy, owns the system
154  std::unique_ptr<EquationSystems> _equation_systems;
155 
156 
157  // Now it's safe to store non-owning pointers to the above
158 
159  /*
160  * System used to smooth the mesh.
161  */
162  // Owned by _equation_systems
164 
169  {
171  return _system;
172  }
173 
177  // uses system, which is owned by _equations_systems
178  std::unique_ptr<VariationalSmootherConstraint> _constraint;
179 
184 
189 
194 
199 
204 };
205 
206 } // namespace libMesh
207 
208 #endif // defined(LIBMESH_ENABLE_VSMOOTHER)
209 
210 #endif // LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
const Real _dilation_weight
Smoother control variables.
bool _solver_verbose
Solver verbose setting.
virtual ~VariationalMeshSmoother()=default
Destructor.
std::unique_ptr< EquationSystems > _equation_systems
EquationsSystems object associated with the smoother.
static constexpr Real TOLERANCE
MeshBase & mesh
const MeshQualityInfo & get_mesh_info() const
Getter for the _system&#39;s _mesh_info attribute.
VariationalSmootherSystem * _system
VariationalSmootherSystem * system() const
Getter for _system to protect against dangling pointers.
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< VariationalSmootherConstraint > _constraint
Constraints imposed on the smoothing process.
std::unique_ptr< DistributedMesh > _mesh_copy
Mesh copy to avoid multiple EquationSystems.
Struct to hold smoother-relevant information about the mesh quality.
double _absolute_residual_tolerance
Solver absolute residual tolerance.
bool _setup_called
Attribute the keep track of whether the setup method has been called.
The UnstructuredMesh class is derived from the MeshBase class.
VariationalMeshSmoother(UnstructuredMesh &mesh, Real dilation_weight=0.5, const bool preserve_subdomain_boundaries=true, const double relative_residual_tolerance=TOLERANCE *TOLERANCE, const double absolute_residual_tolerance=TOLERANCE *TOLERANCE, const bool solver_quiet=true, const bool solver_verbose=false)
Constructor.
libmesh_assert(ctx)
bool _solver_quiet
Solver quiet setting.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is an implementation of Larisa Branets&#39; smoothing algorithms.
double _relative_residual_tolerance
Solver relative residual tolerance.
This class provides the necessary interface for mesh smoothing.
Definition: mesh_smoother.h:38
virtual void setup()
Setup method that creates equation systems, system, and constraints, to be called just prior to smoot...
const bool _preserve_subdomain_boundaries
Whether subdomain boundaries are subject to change via smoothing.
virtual void smooth() override
Redefinition of the smooth function from the base class.