Chi-Tech
MeshTutorial_04_Predef2d.h
Go to the documentation of this file.
1/** \page MeshTutorial_04 Mesh Tutorial 4: Predefined 2D Mesh Setup
2
3Consider an example of using a predeveloped mesh as shown in Figure 1 below.
4
5\image html Meshing/SquareMesh2x2.png "Figure 1 - Mesh spanning from [-1,-1] to [1,1]" width=200px
6
7
8The first step in this process is to create a chi_mesh::MeshHandler for all
9subsequent meshing operations. This will also serve as a global subspace for
10other meshing objects that will be added.
11
12\code
13chiMeshHandlerCreate()
14\endcode
15
16We next import a surface mesh (chi_mesh::SurfaceMesh) that will define our
17 problem. **Solvers will directly operate
18on predefined meshes**.
19
20\code
21newSurfMesh = chiSurfaceMeshCreate();
22chiSurfaceMeshImportFromOBJFile(newSurfMesh,"CHI_RESOURCES/TestObjects/SquareMesh2x2.obj")
23\endcode
24
25The next step is to break up the boundaries of this mesh into edges that we can
26assign to boundaries. We first collect *loops* of edges, which are lists of
27 connected edges. We then split these loops by angle into further loops. Finally
28 we assign each fine-grained loop to a chi_mesh::LineMesh object that can be
29 added to a chi_mesh::Boundary type.
30
31 \code
32line_mesh = {};
33line_mesh_count = 0;
34--
35for k=1,loop_count do
36 split_loops,split_count = chiEdgeLoopSplitByAngle(loops,k-1);
37 for m=1,split_count do
38 line_mesh_count = line_mesh_count + 1;
39 line_mesh[line_mesh_count] = chiLineMeshCreateFromLoop(split_loops,m-1);
40 end
41--
42end
43\endcode
44
45Next we create a chi_mesh::Region object to which we are going to add boundaries.
46We can add a boundary for each chi_mesh::LineMesh and each chi_mesh::SurfaceMesh.
47
48\code
49region1 = chiRegionCreate()
50chiRegionAddSurfaceBoundary(region1,newSurfMesh);
51for k=1,line_mesh_count do
52 chiRegionAddLineBoundary(region1,line_mesh[k]);
53end
54\endcode
55
56We now have everything we need to do a Predefined 2D mesh operation. To do this
57we create a chi_mesh::SurfaceMesher with the type *SURFACEMESHER_PREDEFINED* as
58 well as a chi_mesh::VolumeMesher with the type *VOLUMEMESHER_PREDEFINED2D*.
59
60\code
61chiSurfaceMesherCreate(SURFACEMESHER_PREDEFINED);
62chiVolumeMesherCreate(VOLUMEMESHER_PREDEFINED2D);
63--
64chiSurfaceMesherExecute();
65chiVolumeMesherExecute()
66\endcode
67
68The *SURFACEMESHER_PREDEFINED* is just a pass-through mesher, in contrast to the
69 *SURFACEMESHER_DELAUNAY* type which will re-mesh surfaces. The
70 *VOLUMEMESHER_PREDEFINED2D* similarly does not create new mesh elements but at
71 least this instantiates the notion of nodes and cells.
72
73### Complete code segment
74
75\code
76chiMeshHandlerCreate()
77--
78newSurfMesh = chiSurfaceMeshCreate();
79chiSurfaceMeshImportFromOBJFile(newSurfMesh,"CHI_RESOURCES/TestObjects/SquareMesh2x2.obj")
80loops,loop_count = chiSurfaceMeshGetEdgeLoops(newSurfMesh)
81--
82--
83line_mesh = {};
84line_mesh_count = 0;
85--
86for k=1,loop_count do
87 split_loops,split_count = chiEdgeLoopSplitByAngle(loops,k-1);
88 for m=1,split_count do
89 line_mesh_count = line_mesh_count + 1;
90 line_mesh[line_mesh_count] = chiLineMeshCreateFromLoop(split_loops,m-1);
91 end
92--
93end
94--
95region1 = chiRegionCreate()
96chiRegionAddSurfaceBoundary(region1,newSurfMesh);
97for k=1,line_mesh_count do
98 chiRegionAddLineBoundary(region1,line_mesh[k]);
99end
100--
101chiSurfaceMesherCreate(SURFACEMESHER_PREDEFINED);
102chiVolumeMesherCreate(VOLUMEMESHER_PREDEFINED2D);
103--
104chiSurfaceMesherExecute();
105chiVolumeMesherExecute()
106\endcode
107
108*/