Skip to content

Commit

Permalink
Add MeshChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSewn committed May 1, 2024
1 parent b22295f commit 7ca7320
Show file tree
Hide file tree
Showing 23 changed files with 388 additions and 72 deletions.
Binary file modified doc/banner_3d.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 4 additions & 14 deletions scripts/test_tqmesh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@ set -e
./bin/run_tests EdgeList
./bin/run_tests Boundary
./bin/run_tests SizeFunction
./bin/run_tests SmoothingStrategy
./bin/run_tests Mesh
./bin/run_tests MeshGenerator
./bin/run_tests MeshCleanup
./bin/run_tests SmoothingStrategy

#./../bin/TQMesh ../input/Example_1.para
#./../bin/TQMesh ../input/Example_2.para
#./../bin/TQMesh ../input/Example_3.para
#./../bin/TQMesh ../input/Example_4.para
#./../bin/TQMesh ../input/Example_5.para

#./../bin/run_examples 1
#./../bin/run_examples 2
#./../bin/run_examples 3
#./../bin/run_examples 4
#./../bin/run_examples 5
./bin/run_tests ParaReader
./bin/run_tests MeshChecker

cd ..
#cd ..

if [ $? -eq 0 ]; then
echo ALL TESTS PASSED
Expand Down
20 changes: 20 additions & 0 deletions src/algorithm/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ class Domain
------------------------------------------------------------------*/
size_type size() const { return boundaries_.size(); }

/*------------------------------------------------------------------
| Get the maximum x-/y-extent of all vertices of this domain
------------------------------------------------------------------*/
std::pair<Vec2d,Vec2d> extent() const
{
Vec2d x_extent { 0.0, 0.0 };
Vec2d y_extent { 0.0, 0.0 };

for ( const auto& v : verts_ )
{
x_extent[0] = MIN( x_extent[0], v->x() );
x_extent[1] = MAX( x_extent[1], v->x() );

y_extent[0] = MIN( y_extent[0], v->y() );
y_extent[1] = MAX( y_extent[1], v->y() );
}

return {x_extent, y_extent};
}

/*------------------------------------------------------------------
| Get edges within a given point and radius
------------------------------------------------------------------*/
Expand Down
89 changes: 89 additions & 0 deletions src/algorithm/MeshChecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This source file is part of the tqmesh library.
* This code was written by Florian Setzwein in 2022,
* and is covered under the MIT License
* Refer to the accompanying documentation for details
* on usage and license.
*/
#pragma once

#include "TQMesh.h"

namespace TQMesh {

using namespace CppUtils;

/*********************************************************************
* This class can be used to check a mesh for its completeness and
* for certain quality measures
*********************************************************************/
class MeshChecker
{
public:

/*------------------------------------------------------------------
| Constructor
------------------------------------------------------------------*/
MeshChecker(Mesh& mesh, const Domain& domain)
: mesh_ { &mesh }
, domain_ { &domain }
{}

virtual ~MeshChecker() {}

/*------------------------------------------------------------------
| Getters
------------------------------------------------------------------*/
Mesh& mesh() { return *mesh_; }

/*------------------------------------------------------------------
| This function checks for the completeness of the given mesh
------------------------------------------------------------------*/
bool check_completeness(bool mesh_cleanup=true) const
{
// Make sure that the mesh structure is up to date
if ( mesh_cleanup )
perform_mesh_cleanup();

bool complete = true;

// The mesh may not contain any advancing front edges
complete &= ( mesh_->get_front_edges().size() == 0 );

// Check the mesh connectivity
complete &= EntityChecks::check_mesh_validity( *mesh_ );

// Check meshed area
const double mesh_area = mesh_->area();
const double domain_area = domain_->area();
auto extent = domain_->extent();
const double scale_x = extent.first[1] - extent.first[0];
const double scale_y = extent.second[1] - extent.second[0];
const double area_difference = ABS(mesh_area - domain_area);
complete &= (area_difference / (scale_x*scale_y)) < area_threshold_;

return complete;
}

private:
/*------------------------------------------------------------------
| This function calls some MeshCleanup functions which might be
| required to update the internal mesh structure
------------------------------------------------------------------*/
void perform_mesh_cleanup() const
{
MeshCleanup::assign_mesh_indices( *mesh_ );
MeshCleanup::setup_facet_connectivity( *mesh_ );
}

/*------------------------------------------------------------------
| Attributes
------------------------------------------------------------------*/
Mesh* mesh_;
const Domain* domain_;

const double area_threshold_ { 1.0E-10 };

}; // MeshChecker

} // namespace TQMesh
6 changes: 5 additions & 1 deletion src/algorithm/TQMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@
#include "Triangle.h"
#include "Quad.h"
#include "EntityChecks.h"

#include "Mesh.h"
#include "Front.h"
#include "FrontUpdate.h"
#include "MeshBuilder.h"
#include "MeshCleanup.h"
#include "MeshBuilder.h"
#include "MeshMerger.h"
#include "MeshWriter.h"
#include "MeshingStrategy.h"
#include "MeshChecker.h"

#include "ModificationStrategy.h"
#include "SmoothingStrategy.h"
#include "QuadLayerStrategy.h"
#include "RefinementStrategy.h"
#include "TriangulationStrategy.h"

#include "MeshGenerator.h"

15 changes: 14 additions & 1 deletion src/examples/01_simple_triangular_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace TQMesh;
/*********************************************************************
* This example covers the generation of a simple triangular mesh
*********************************************************************/
void simple_triangular_mesh()
bool simple_triangular_mesh()
{
/*------------------------------------------------------------------
| First, we define the size function. This function describes
Expand Down Expand Up @@ -143,6 +143,17 @@ void simple_triangular_mesh()
------------------------------------------------------------------*/
generator.mixed_smoothing(mesh).smooth(2);

/*------------------------------------------------------------------
| We can use a "MeshChecker" to verify if the triangulation
| succeeded
------------------------------------------------------------------*/
MeshChecker checker { mesh, domain };
if ( !checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Finally, we export the mesh to a file in VTU / TXT format.
------------------------------------------------------------------*/
Expand All @@ -156,4 +167,6 @@ void simple_triangular_mesh()
LOG(INFO) << "Writing mesh output to: " << filename << ".txt";
generator.write_mesh(mesh, filename, MeshExportType::TXT);

return true;

} // simple_triangular_mesh()
14 changes: 13 additions & 1 deletion src/examples/02_square_in_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace TQMesh;
* dedicated quad layers and we will utilize a method to obtain an
* all-quad mesh.
*********************************************************************/
void square_in_channel()
bool square_in_channel()
{
/*------------------------------------------------------------------
| Define the size function and the domain structure
Expand Down Expand Up @@ -161,6 +161,16 @@ void square_in_channel()
.quad_layer_smoothing(true) // Enable smoothing to quad layers
.smooth(3); // Smooth for three iterations

/*------------------------------------------------------------------
| Check if the meshing generation process succeeded
------------------------------------------------------------------*/
MeshChecker checker { mesh, domain };
if ( !checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Finally, we export the mesh to a file in VTU / TXT format.
------------------------------------------------------------------*/
Expand All @@ -174,4 +184,6 @@ void square_in_channel()
LOG(INFO) << "Writing mesh output to: " << file_name << ".txt";
generator.write_mesh(mesh, file_name, MeshExportType::TXT );

return true;

} // square_in_channel()
14 changes: 13 additions & 1 deletion src/examples/03_boundary_shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace TQMesh;
* This example covers the mesh generation where the domain boundaries
* are specified by predefined boundary shapes
*********************************************************************/
void boundary_shapes()
bool boundary_shapes()
{
/*------------------------------------------------------------------
| Define the size function and the domain structure
Expand Down Expand Up @@ -116,6 +116,16 @@ void boundary_shapes()
------------------------------------------------------------------*/
generator.mixed_smoothing(mesh).smooth(2);

/*------------------------------------------------------------------
| Check if the meshing generation process succeeded
------------------------------------------------------------------*/
MeshChecker checker { mesh, domain };
if ( !checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Finally, the mesh is exportet to a file in TXT format.
------------------------------------------------------------------*/
Expand All @@ -129,4 +139,6 @@ void boundary_shapes()
LOG(INFO) << "Writing mesh output to: " << file_name << ".txt";
generator.write_mesh(mesh, file_name, MeshExportType::TXT);

return true;

} // boundary_shapes()
13 changes: 12 additions & 1 deletion src/examples/04_fixed_vertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace TQMesh;
* This example covers the mesh generation with fixed interior
* vertices, as well as the usage of different mesh element colors
*********************************************************************/
void fixed_vertices()
bool fixed_vertices()
{
/*------------------------------------------------------------------
| Define the size function and the domain structure
Expand Down Expand Up @@ -115,6 +115,16 @@ void fixed_vertices()
------------------------------------------------------------------*/
generator.mixed_smoothing(mesh).smooth(2);

/*------------------------------------------------------------------
| Check if the meshing generation process succeeded
------------------------------------------------------------------*/
MeshChecker checker { mesh, domain };
if ( !checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Finally, the mesh is exportet to a file in TXT format.
------------------------------------------------------------------*/
Expand All @@ -128,5 +138,6 @@ void fixed_vertices()
LOG(INFO) << "Writing mesh output to: " << file_name << ".txt";
generator.write_mesh(mesh, file_name, MeshExportType::TXT);

return true;

} // fixed_vertices()
24 changes: 23 additions & 1 deletion src/examples/05_merge_meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace TQMesh;
* x-----------------------x
*
*********************************************************************/
void merge_meshes()
bool merge_meshes()
{
/*------------------------------------------------------------------
| Define the size function and domain of the outer mesh
Expand Down Expand Up @@ -110,6 +110,16 @@ void merge_meshes()
------------------------------------------------------------------*/
generator.mixed_smoothing(outer_mesh).smooth(2);

/*------------------------------------------------------------------
| Check if the meshing generation process succeeded
------------------------------------------------------------------*/
MeshChecker outer_checker { outer_mesh, outer_domain };
if ( !outer_checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Define the size function of the inner mesh
------------------------------------------------------------------*/
Expand Down Expand Up @@ -142,6 +152,16 @@ void merge_meshes()
------------------------------------------------------------------*/
generator.triangulation(inner_mesh).generate_elements();

/*------------------------------------------------------------------
| Check if the meshing generation process succeeded
------------------------------------------------------------------*/
MeshChecker inner_checker { inner_mesh, inner_domain };
if ( !inner_checker.check_completeness() )
{
LOG(ERROR) << "Mesh generation failed";
return false;
}

/*------------------------------------------------------------------
| Finally, merge both meshes. In this way, the outer mesh's
| elements will be added to the inner mesh. Be aware that the
Expand Down Expand Up @@ -169,4 +189,6 @@ void merge_meshes()
LOG(INFO) << "Writing mesh output to: " << file_name << ".txt";
generator.write_mesh(inner_mesh, file_name, MeshExportType::TXT);

return true;

} // merge_meshes()
Loading

0 comments on commit 7ca7320

Please sign in to comment.