Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions include/mesh/mesh_smoother_vsmoother.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ class VariationalMeshSmoother : public MeshSmoother
*/
const MeshQualityInfo & get_mesh_info() const;

/**
* Set the quadrature rule type used by the underlying
* VariationalSmootherSystem to integrate the distortion-dilation metric.
* The default (\p 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 \p QTRAP,
* \p QSIMPSON, \p QNODAL, or \p 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.
*/
void set_quadrature_type(QuadratureType qt) { _quadrature_type = qt; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all I need from MOOSE side


private:

/**
Expand Down Expand Up @@ -199,6 +212,12 @@ class VariationalMeshSmoother : public MeshSmoother
* Solver absolute residual tolerance
*/
Real _absolute_residual_tolerance;

/**
* Quadrature rule type used to integrate the distortion-dilation metric.
* See set_quadrature_type().
*/
QuadratureType _quadrature_type = QGAUSS;
};

} // namespace libMesh
Expand Down
18 changes: 18 additions & 0 deletions include/systems/fem_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Local Includes
#include "libmesh/diff_context.h"
#include "libmesh/id_types.h"
#include "libmesh/enum_quadrature_type.h"
#include "libmesh/fe_type.h"
#include "libmesh/fe_base.h"
#include "libmesh/vector_value.h"
Expand Down Expand Up @@ -107,6 +108,23 @@ class FEMContext : public DiffContext
*/
void use_unweighted_quadrature_rules(int extra_quadrature_order=0);

/**
* Use a specified quadrature rule type \p qt for every element,
* side, and edge dimension, at the default quadrature order for the
* hardest FE type plus \p extra_quadrature_order.
*
* This is useful when the default Gauss rules (whose points lie in
* the element interior) are inadequate. For example, rules whose
* points include the element vertices (\p QTRAP, \p QSIMPSON, \p
* QNODAL, \p QGAUSS_LOBATTO) can detect integrand behavior that is
* localized at element corners --- a feature interior Gauss points
* can miss entirely. Note that not every quadrature type is defined
* for every element type (e.g. \p QGAUSS_LOBATTO is only available for
* tensor-product elements); it is the caller's responsibility to pick
* a type compatible with the mesh.
*/
void use_quadrature_rules(QuadratureType qt, int extra_quadrature_order=0);

/**
* Reports if the boundary id is found on the current side
*/
Expand Down
31 changes: 30 additions & 1 deletion include/systems/variational_smoother_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// libMesh includes
#include "libmesh/enum_fe_family.h"
#include "libmesh/enum_quadrature_type.h"
#include "libmesh/fem_function_base.h"
#include "libmesh/fem_system.h"
#include "libmesh/libmesh_common.h"
Expand Down Expand Up @@ -94,7 +95,8 @@ class VariationalSmootherSystem : public libMesh::FEMSystem
_epsilon_squared_assembly(0.),
_ref_vol(0.),
_dilation_weight(0.5),
_untangling_solve(false)
_untangling_solve(false),
_quadrature_type(QGAUSS)
{}

// Default destructor
Expand All @@ -110,6 +112,27 @@ class VariationalSmootherSystem : public libMesh::FEMSystem

Real & get_dilation_weight() { return _dilation_weight; }

/**
* Set the quadrature rule type used to integrate the distortion-dilation
* metric over each element. The default (\p 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 \p QTRAP, \p QSIMPSON, \p QNODAL, or \p QGAUSS_LOBATTO
* evaluates the metric at the element nodes, so a folding corner drives the
* metric up (and is flagged as tangled) as it should be. The number of
* points is set from the default order for the mesh's FE type plus the
* System's \p extra_quadrature_order. Not every quadrature type is defined
* for every element type (e.g. \p QGAUSS_LOBATTO is only available for
* tensor-product elements), so choose a type compatible with the mesh.
*/
void set_quadrature_type(QuadratureType qt) { _quadrature_type = qt; }

/**
* Get the quadrature rule type used to integrate the distortion-dilation
* metric. See set_quadrature_type().
*/
QuadratureType get_quadrature_type() const { return _quadrature_type; }

/**
* Solves the system to smooth the mesh. If the mesh is initially tangled,
* a solve is first performed to untangle the mesh, followed by a solve to
Expand Down Expand Up @@ -241,6 +264,12 @@ class VariationalSmootherSystem : public libMesh::FEMSystem
* Flag to indicate if the current solve is to untangle or smooth
*/
bool _untangling_solve;

/**
* The quadrature rule type used to integrate the distortion-dilation metric.
* See set_quadrature_type().
*/
QuadratureType _quadrature_type;
};

} // namespace libMesh
Expand Down
7 changes: 7 additions & 0 deletions src/mesh/mesh_smoother_vsmoother.C
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ void VariationalMeshSmoother::setup()
// Using higher quadrature orders has not had a significant effect on observed solutions.
//system()->extra_quadrature_order = 0;

// The default Gauss rule samples the element interior only, so it can miss
// degeneracies localized at element corners (e.g. an element collapsing
// toward one of its nodes). Selecting a vertex-sampling rule (QTRAP,
// QSIMPSON, QNODAL, QGAUSS_LOBATTO) evaluates the metric at the element
// nodes instead. Defaults to QGAUSS.
system()->set_quadrature_type(_quadrature_type);

// Uncomment these to debug
//system()->print_element_solutions=true;
//system()->print_element_residuals=true;
Expand Down
26 changes: 26 additions & 0 deletions src/systems/fem_context.C
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ void FEMContext::use_unweighted_quadrature_rules(int extra_quadrature_order)
}


void FEMContext::use_quadrature_rules(QuadratureType qt, int extra_quadrature_order)
{
_extra_quadrature_order = extra_quadrature_order;

const FEType hardest_fe_type = this->find_hardest_fe_type();

// Match the accuracy of the default rule (which over-integrates a mass
// matrix), then add any requested extra order on top.
const Order order = static_cast<Order>(hardest_fe_type.default_quadrature_order()
+ extra_quadrature_order);

for (const auto & dim : _elem_dims)
{
// Create the requested quadrature rule for the element and its
// lower-dimensional sides/edges
_element_qrule[dim] = QBase::build(qt, dim, order);
if (dim)
_side_qrule[dim] = QBase::build(qt, cast_int<unsigned int>(dim - 1), order);
if (dim == 3)
_edge_qrule = QBase::build(qt, 1, order);
}

this->attach_quadrature_rules();
}


void FEMContext::init_internal_data(const System & sys)
{
// Reserve space for the FEAbstract and QBase objects for each
Expand Down
9 changes: 9 additions & 0 deletions src/systems/variational_smoother_system.C
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ void VariationalSmootherSystem::init_context(DiffContext & context)
}

FEMSystem::init_context(context);

// Override the default (interior-only) Gauss rule if a different quadrature
// type has been requested. A vertex-sampling rule (e.g. QTRAP, QSIMPSON,
// QNODAL, QGAUSS_LOBATTO) lets the metric "see" degeneracies localized at
// element corners that interior Gauss points miss. Do this after
// FEMSystem::init_context() so it is not overwritten. The System's
// extra_quadrature_order is respected for the point count.
if (_quadrature_type != QGAUSS)
c.use_quadrature_rules(_quadrature_type, this->extra_quadrature_order);
}


Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ data = matrices/geom_1_extraction_op.h5 \
meshes/Cluster_34.stl \
meshes/engraving.stl \
meshes/quad4_tri3_smoothed.xda.gz \
meshes/quad4_tri3_hourglass.xda.gz \
meshes/hex8_prism6_smoothed.xda.gz \
solutions/lagrange_vec_solution_mesh.xda \
solutions/lagrange_vec_solution.xda \
Expand Down
58 changes: 58 additions & 0 deletions tests/mesh/mesh_smoother_test.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <libmesh/boundary_info.h>
#include <libmesh/elem.h>
#include <libmesh/enum_elem_type.h>
#include <libmesh/enum_quadrature_type.h>
#include <libmesh/function_base.h>
#include <libmesh/libmesh.h>
#include <libmesh/mesh_generation.h>
Expand Down Expand Up @@ -273,6 +274,7 @@ public:
#if defined(LIBMESH_HAVE_GZSTREAM)
CPPUNIT_TEST(testVariationalMixed2D);
CPPUNIT_TEST(testVariationalMixed3D);
CPPUNIT_TEST(testVariationalQuadratureHourglass);
#endif

#endif // LIBMESH_ENABLE_VSMOOTHER
Expand Down Expand Up @@ -1367,6 +1369,62 @@ public:
testVariationalSmootherRegression(mesh);
}

// Verify that a vertex-sampling quadrature rule prevents the "hourglass"
// failure mode of the variational smoother.
//
// The fixture is a mixed QUAD4/TRI3 patch built around a hub node that is
// pinned as a subdomain-boundary node. With the default (interior-only) Gauss
// rule, minimizing the distortion-dilation metric folds one of the quads
// toward a node---it collapses into a near-triangle (an hourglass)---while the
// interior quadrature points still report positive Jacobians, so the mesh is
// never flagged as tangled. Switching to a quadrature rule whose points
// include the element vertices (here QNODAL) evaluates the metric at the
// corners, so the fold is penalized and does not form.
//
// We detect the fold with Elem::has_invertible_map(), whose default
// implementation evaluates the physical-to-reference map Jacobian at the
// element nodes (nodal quadrature) and returns false if any nodal Jacobian is
// non-positive. A quad folded toward one of its nodes has a non-positive
// Jacobian at that corner, so its map is not invertible.
void testVariationalQuadratureHourglass()
{
LOG_UNIT_TEST;

auto count_non_invertible = [](const MeshBase & m) {
unsigned int n_bad = 0;
for (const auto * elem : m.active_element_ptr_range())
if (!elem->has_invertible_map())
++n_bad;
return n_bad;
};

// (1) Default Gauss rule: characterizes the bug. At least one element folds
// into an hourglass and loses its invertible map. (If a future change to the
// default smoother fixes this on its own, this assertion should be revisited.)
{
ReplicatedMesh mesh(*TestCommWorld);
mesh.read("meshes/quad4_tri3_hourglass.xda.gz");

VariationalMeshSmoother smoother(mesh, 0.5, true);
smoother.smooth();

CPPUNIT_ASSERT(count_non_invertible(mesh) > 0);
}

// (2) Vertex-sampling rule (QNODAL): the metric now "sees" the corners, so
// every element keeps an invertible map.
{
ReplicatedMesh mesh(*TestCommWorld);
mesh.read("meshes/quad4_tri3_hourglass.xda.gz");

VariationalMeshSmoother smoother(mesh, 0.5, true);
smoother.set_quadrature_type(QNODAL);
smoother.smooth();

CPPUNIT_ASSERT_EQUAL(0u, count_non_invertible(mesh));
}
}

void testVariationalMixed3D()
{
ReplicatedMesh mesh(*TestCommWorld);
Expand Down
Binary file added tests/meshes/quad4_tri3_hourglass.xda.gz
Binary file not shown.