A Simple Tetrahedral Mesh Example

The input to the tet-mesher is a boundary description of the water-tight, triangular surface mesh. This surface is a set of spatial positions (x, y, z) and a set of triangle connectivity referencing these spatial position, i.e., three indices of the triangle corners in the points array. The indices are ordered counter-clockwise when view from outside the volume as shown by the partial surface in Figure 1.

triconnect.png

Figure 1: Triangle Connectivity

The C++ code fragments below shows the code to generate a tetrahedral mesh.

    // read input file
  int    *tris   = NULL; // array allocated in read_tri_file
  double *points = NULL; // array allocated in read_tri_file
  int num_tris = 0, num_points = 0;
  if (!read_tri_file(num_points, points, num_tris, tris)) {
    printf("Failed read input\n");
    exit(EXIT_FAILURE);
  }

    // mesh the volume
  int *tets = NULL;
  int new_points = 0;
  int num_tets = 0;
  CMLTetMesher tet_mesher;
  ret_value = tet_mesher.set_boundary_mesh(num_points, points,
                                           num_tris, tris);
  if (!ret_value) {
    printf("Failed setting boundary mesh\n");
  }

In this example, a boundary mesh is read from a file. It is passed to the tet-mesher with the CMLTetMesher::set_boundary_mesh(...). Here, num_points is the number of points and num_tris is the number of triangles in the surface mesh.

    // delete memory allocated in read_tri_file
  delete [] points;
  delete [] tris;
  points = NULL;

Delete the surface boundary mesh since it is no longer needed. The points pointer will be reused so it is set to NULL.

    
    // generate the mesh
  if (ret_value) {
    ret_value = tet_mesher.generate_mesh(new_points, num_tets);
    if (!ret_value) {
      printf("Failed generating mesh\n");
    }
  }

The CMLTetMesher::generate_mesh(...) verifies the integrity of the input boundary mesh and fills the volume with tetrahedra using a constrained-Delaunay method. Also, it returns the number of points (new_points) and the number of tetrahedra (num_tets) generated. Use these numbers to allocate storage space for the mesh when retrieving the mesh.

    // allocate memory to accept tet mesh and retrieve it
  if (ret_value) {
    tets   = new int [num_tets * 4];
    points = new double [new_points * 3];
    ret_value = tet_mesher.get_mesh(new_points, points, num_tets, tets);
    if (!ret_value) {
      printf("Failed reading tet mesh\n");
    }
  }

Finally, the CMLTetMesher::get_mesh(...) method retrieves the generated mesh. The points returned include the input points; they appear as the first num_points in the list in the order they were passed to the tet-mesher. The tetrahedral connectivity references the spatial points by their position or index in the points array.

Figure 2 is a picture of the tetrahedral mesh.

tetmesh.png

Figure 2: Tetrahedral Mesh Example

Other Examples

  1. A Triangle Mesh Example
  2. An Unstructured Quadrilateral Mesh Example
  3. A Swept Hexahedral Mesh Example
  4. Curve Meshing Examples
  5. Another Triangle Mesh Example
  6. A Structured Quadrilateral Mesh Example -- Surface Mapper
  7. A Structured Quadrilateral Mesh Example -- Surface Submapper
  8. A Structured Hexahedral Mesh Example -- Volume Mapper

CAMAL 5.2-0 documentation created on 1 Jun 2010
Comments to csimsoft.com