Skip to content

Commit

Permalink
Add examples for fixed edges
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSewn committed Jul 5, 2024
1 parent 0a66645 commit abab7ce
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ via CSV files. This example shows an airfoil that has been meshed in this way.
<img src="doc/airfoil.png" alt="TQMesh-airfoil" width="350"/>
</details>


<details>
<summary>Fixed interior edges</summary>

Fixed edges can be defined within the domain to guide the meshing process.

<img src="doc/fixed_edges.png" alt="TQMesh-fixed-edges" width="350"/>
</details>

## Output format
Currently, **TQMesh** features the VTU output format (which can be read for example by Paraview) or alternatively a simple text output format.

Expand Down
Binary file added doc/fixed_edges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 26 additions & 25 deletions input/09_fixed_interior_edges.para
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#===========================================================
# TQMESH
#===========================================================

#-----------------------------------------------------------
# MESH DEFINITION
#
# First, we provide some general meshing properties,
# such as the overall element size, element color and
# the applied meshing algorithm:
#-----------------------------------------------------------
Define mesh:
Element size: 0.35
Expand All @@ -21,40 +17,45 @@ Define mesh:
Output file prefix: ./fixed_edges

#---------------------------------------------------------
#
# BOUNDARIES
#---------------------------------------------------------
Define boundary vertices:
1.0, 0.0
6.0, 0.5
4.0, 5.0
-1.0, 4.5
1.0, 0.0 # Vertex 0
6.0, 0.5 # Vertex 1
4.0, 5.0 # Vertex 2
-1.0, 4.5 # Vertex 3
End boundary vertices

#---------------------------------------------------------
#
#---------------------------------------------------------
Define exterior boundary edges:
0, 1, 2 # 2: Color for bottom edge
1, 2, 3 # 3: Color for right edge
2, 3, 2 # 2: Color for top edge
3, 0, 1 # 1: Color for left edge
0, 1, 1
1, 2, 2
2, 3, 3
3, 0, 4
End exterior boundary edges

#---------------------------------------------------------
# FIXED VERTICES & FIXED EDGES
#
# Similar to interior / exterior boundary edges, we define
# fixed edges by providing the IDs of the respective start
# and ending vertices. However, fixed vertices do not
# require the additional color values.
# Note, that the vertex ID count starts with boundary v
# vertices and proceeds with fixed vertices - as indicated
# in the comments.
#---------------------------------------------------------
Define fixed vertices:
2.5, 2.5, 0.05, 1.0 # 4
1.5, 1.5, 0.05, 1.0
3.5, 1.5, 0.05, 1.0
3.5, 3.5, 0.05, 1.0
1.5, 3.5, 0.05, 1.0
2.5, 2.5, 0.05, 1.0 # Vertex 5
1.5, 1.5, 0.05, 1.0 # Vertex 6
3.5, 1.5, 0.05, 1.0 # Vertex 7
3.5, 3.5, 0.05, 1.0 # Vertex 8
1.5, 3.5, 0.05, 1.0 # Vertex 9
End fixed vertices

Define fixed edges:
4, 5
4, 6
4, 7
4, 5 # This edge connects vertex 4 and vertex 5,
4, 6 # this edge connects vertex 4 and vertex 6
4, 7 # and so on ...
4, 8
5, 6
6, 7
Expand Down
95 changes: 95 additions & 0 deletions src/examples/09_fixed_edges.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* This 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.
*/
#include <iostream>
#include <cassert>

#include "TQMesh.h"
#include "run_examples.h"

using namespace CppUtils;
using namespace TQMesh;
/*********************************************************************
* This example covers the usage of fixed interior edges
*********************************************************************/
bool fixed_edges()
{
UserSizeFunction f = [](const Vec2d& p) { return 0.35; };

Domain domain { f };

// Vertices
Vertex& v0 = domain.add_vertex( 1.0, 0.0 );
Vertex& v1 = domain.add_vertex( 6.0, 0.5 );
Vertex& v2 = domain.add_vertex( 4.0, 5.0 );
Vertex& v3 = domain.add_vertex(-1.0, 4.5 );

Boundary& b_ext = domain.add_exterior_boundary();
b_ext.add_edge( v0, v1, 1 ); // 1: Color for bottom edge
b_ext.add_edge( v1, v2, 2 ); // 2: Color for right edge
b_ext.add_edge( v2, v3, 3 ); // 3: Color for top edge
b_ext.add_edge( v3, v0, 4 ); // 4: Color for left edge

// Fixed vertices
Vertex& v4 = domain.add_fixed_vertex(2.5, 2.5, 0.05, 1.0);
Vertex& v5 = domain.add_fixed_vertex(1.5, 1.5, 0.05, 1.0);
Vertex& v6 = domain.add_fixed_vertex(3.5, 1.5, 0.05, 1.0);
Vertex& v7 = domain.add_fixed_vertex(3.5, 3.5, 0.05, 1.0);
Vertex& v8 = domain.add_fixed_vertex(1.5, 3.5, 0.05, 1.0);

// Define fixed edges
domain.add_fixed_edge( v4, v5 );
domain.add_fixed_edge( v4, v6 );
domain.add_fixed_edge( v4, v7 );
domain.add_fixed_edge( v4, v8 );

domain.add_fixed_edge( v5, v6 );
domain.add_fixed_edge( v6, v7 );
domain.add_fixed_edge( v7, v8 );
domain.add_fixed_edge( v8, v5 );

/*------------------------------------------------------------------
| Mesh generation
------------------------------------------------------------------*/
MeshGenerator generator {};
Mesh& mesh = generator.new_mesh( domain );

generator.triangulation(mesh).generate_elements();

generator.quad_refinement(mesh).refine();

generator.mixed_smoothing(mesh)
.epsilon(0.7)
.smooth(5);

/*------------------------------------------------------------------
| 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.
------------------------------------------------------------------*/
std::string source_dir { TQMESH_SOURCE_DIR };
std::string file_name
{ source_dir + "/auxiliary/example_data/fixed_edges" };

LOG(INFO) << "Writing mesh output to: " << file_name << ".vtu";
generator.write_mesh(mesh, file_name, MeshExportType::VTU );

LOG(INFO) << "Writing mesh output to: " << file_name << ".txt";
generator.write_mesh(mesh, file_name, MeshExportType::TXT );


return true;

} // fixed_edges()
File renamed without changes.
3 changes: 2 additions & 1 deletion src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ add_executable( ${EXAMPLES}
#example_9.cpp
#example_8.cpp
#example_7.cpp
09_tqmesh_banner.cpp
10_tqmesh_banner.cpp
09_fixed_edges.cpp
08_thin_fracture.cpp
07_multiple_meshes.cpp
06_airfoil_from_csv.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/examples/run_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ int run_examples(const std::string& example)
success &= thin_fracture();
}
else if ( !example.compare("9") || !example.compare("09") ||
!example.compare("fixed_edges") )
{
LOG(INFO) << "Running example \"fixed_edges\"...";
LOG(INFO) << "";
success &= fixed_edges();
}
else if ( !example.compare("10") ||
!example.compare("tqmesh_banner") )
{
LOG(INFO) << "Running example \"tqmesh_banner\"...";
Expand Down
1 change: 1 addition & 0 deletions src/examples/run_examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bool merge_meshes();
bool airfoil_from_csv();
bool multiple_meshes();
bool thin_fracture();
bool fixed_edges();
bool tqmesh_banner();
bool run_example_7();
bool run_example_8();
Expand Down

0 comments on commit abab7ce

Please sign in to comment.