Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.F90
Go to the documentation of this file.
1!> @author
2!> Cecile Dobrzynski, Charles Dapogny, Pascal Frey and Algiane Froehly
3!> @brief
4!> Example for using mmglib (basic use)
5
6PROGRAM main
7
8 IMPLICIT NONE
9
10!> Include here the mmg library hader file
11! if the "include/mmg" dir is in your include path
12!#include "libmmgf.h"
13
14! if your include path do not contain the "mmg/mmg" subdirectories
15#include "mmg/libmmgf.h"
16
17 mmg5_data_ptr_t :: mmgmesh
18 mmg5_data_ptr_t :: mmgsol
19 INTEGER :: ier,argc
20 CHARACTER(len=350) :: tdfile,tdfileout, bdfile, bdfileout,exec_name,fileout
21
22 WRITE(*,*) " -- TEST MMGLIB"
23
24 argc = command_argument_count();
25 CALL get_command_argument(0, exec_name)
26
27 IF ( argc /=3 ) THEN
28 print*,argc," Usage: ",trim(exec_name),&
29 " 2d_file_name 3d_file_name output_file_name"
30 CALL exit(1);
31 ENDIF
32
33 ! Name and path of the mesh file
34 CALL get_command_argument(1, bdfile)
35 CALL get_command_argument(2, tdfile)
36 CALL get_command_argument(3, fileout)
37
38 !> ================== 2d remeshing using the mmg2d library
39 !! ------------------------------ STEP I --------------------------
40 !! 1) Initialisation of mesh and sol structures */
41 !! args of InitMesh:
42 !! MMG5_ARG_start: we start to give the args of a variadic func
43 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
44 !! mmgMesh: your MMG5_pMesh (that store your mesh)
45 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
46 !! mmgSol: your MMG5_pSol (that store your metric) */
47
48
49 mmgmesh = 0
50 mmgsol = 0
51
52 CALL mmg2d_init_mesh(mmg5_arg_start, &
53 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
54 mmg5_arg_end)
55
56 !> 2) Build mesh in MMG5 format
57 !! Two solutions: just use the MMG2D_loadMesh function that will read a .mesh(b)
58 !! file formatted or manually set your mesh using the MMG2D_Set* functions
59
60 !> with MMG2D_loadMesh function
61 CALL mmg2d_loadmesh(mmgmesh,trim(adjustl(bdfile)),&
62 len(trim(adjustl(bdfile))),ier)
63 IF ( ier /= 1 ) CALL exit(102)
64
65 !> 3) Build sol in MMG5 format
66 !! Two solutions: just use the MMG2D_loadSol function that will read a .sol(b)
67 !! file formatted or manually set your sol using the MMG2D_Set* functions
68 CALL mmg2d_loadsol(mmgmesh,mmgsol,trim(adjustl(bdfile)),len(trim(adjustl(bdfile))),ier)
69 IF ( ier /= 1 ) THEN
70 CALL exit(104)
71 ENDIF
72
73 !> 4) (not mandatory): check if the number of given entities match with mesh size
74
75 !> ------------------------------ STEP II --------------------------
76 !! remesh function
77 CALL mmg2d_mmg2dlib(mmgmesh,mmgsol,ier)
78
79 IF ( ier == mmg5_strongfailure ) THEN
80 print*,"BAD ENDING OF MMG2DLIB: UNABLE TO SAVE MESH"
81 stop 2
82 ELSE IF ( ier == mmg5_lowfailure ) THEN
83 print*,"BAD ENDING OF MMG2DLIB"
84 ENDIF
85
86 !> ------------------------------ STEP III --------------------------
87 !! get results
88 !! Two solutions: just use the MMG2D_saveMesh/MMG2D_saveSol functions
89 !! that will write .mesh(b)/.sol formatted files or manually get your mesh/sol
90 !! using the MMG2D_getMesh/MMG2D_getSol functions
91
92 !> 1) Automatically save the mesh
93 CALL mmg2d_savemesh(mmgmesh,trim(adjustl(fileout)) // ".2d.mesh",&
94 len(trim(adjustl(fileout)) // ".2d.mesh"),ier)
95 IF ( ier /= 1 ) THEN
96 CALL exit(106)
97 ENDIF
98
99 !> 2) Automatically save the solution
100
101 !! b) save the solution in a file named bdfileout
102 CALL mmg2d_savesol(mmgmesh,mmgsol,trim(adjustl(fileout)) // ".2d.mesh",&
103 len(trim(adjustl(fileout)) // ".2d.mesh"),ier)
104 IF ( ier /= 1 ) THEN
105 CALL exit(107)
106 ENDIF
107
108 !> 3) Free the MMG2D5 structures
109 CALL mmg2d_free_all(mmg5_arg_start, &
110 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
111 mmg5_arg_end)
112
113 !> ================== surface remeshing using the mmgs library
114
115 !! ------------------------------ STEP I --------------------------
116 !! 1) Initialisation of mesh and sol structures */
117 !! args of InitMesh:
118 !! MMG5_ARG_start: we start to give the args of a variadic func
119 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
120 !! mmgMesh: your MMG5_pMesh (that store your mesh)
121 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
122 !! mmgSol: your MMG5_pSol (that store your metric) */
123
124 mmgmesh = 0
125 mmgsol = 0
126
127 CALL mmgs_init_mesh(mmg5_arg_start, &
128 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
129 mmg5_arg_end)
130
131 !> 2) Build mesh in MMG5 format
132 !! Two solutions: just use the MMGS_loadMesh function that will read a .mesh(b)
133 !! file formatted or manually set your mesh using the MMGS_Set* functions
134
135 !> with MMGS_loadMesh function
136 CALL mmgs_loadmesh(mmgmesh,trim(adjustl(tdfile)),&
137 len(trim(adjustl(tdfile))),ier);
138 IF ( ier /= 1 ) CALL exit(102)
139
140 !> 3) Build sol in MMG5 format
141 !! Two solutions: just use the MMGS_loadSol function that will read a .sol(b)
142 !! file formatted or manually set your sol using the MMGS_Set* functions
143
144 !> With MMGS_loadSol function
145 CALL mmgs_loadsol(mmgmesh,mmgsol,trim(adjustl(tdfile)),&
146 len(trim(adjustl(tdfile))),ier);
147 IF ( ier /= 1 ) THEN
148 CALL exit(104)
149 ENDIF
150
151 !> 4) (not mandatory): check if the number of given entities match with mesh size
152 CALL mmgs_chk_meshdata(mmgmesh,mmgsol,ier)
153 IF ( ier /=1 ) CALL exit(105)
154
155 !> ------------------------------ STEP II --------------------------
156 !! remesh function
157 CALL mmgs_mmgslib(mmgmesh,mmgsol,ier)
158
159 IF ( ier == mmg5_strongfailure ) THEN
160 print*,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH"
161 stop 2
162 ELSE IF ( ier == mmg5_lowfailure ) THEN
163 print*,"BAD ENDING OF MMGSLIB"
164 ENDIF
165
166 !> ------------------------------ STEP III --------------------------
167 !! get results
168 !! Two solutions: just use the MMGS_saveMesh/MMGS_saveSol functions
169 !! that will write .mesh(b)/.sol formatted files or manually get your mesh/sol
170 !! using the MMGS_getMesh/MMGS_getSol functions
171
172 !> 1) Automatically save the mesh
173 CALL mmgs_savemesh(mmgmesh,trim(adjustl(fileout)) // ".s.mesh",&
174 len(trim(adjustl(fileout)) // ".s.mesh"),ier);
175 IF ( ier /= 1 ) THEN
176 CALL exit(108)
177 ENDIF
178
179 !> 2) Automatically save the solution
180 CALL mmgs_savesol(mmgmesh,mmgsol,trim(adjustl(fileout))//".s.sol",&
181 len(trim(adjustl(fileout))//".s.sol"),ier);
182 IF ( ier /= 1 ) THEN
183 CALL exit(107)
184 ENDIF
185
186 !> 3) Free the MMGS5 structures
187 CALL mmgs_free_all(mmg5_arg_start, &
188 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
189 mmg5_arg_end)
190
191 !> ================== 3d remeshing using the mmg3d library
192
193 !! ------------------------------ STEP I --------------------------
194 !! 1) Initialisation of mesh and sol structures */
195 !! args of InitMesh:
196 !! MMG5_ARG_start: we start to give the args of a variadic func
197 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
198 !! mmgMesh: your MMG5_pMesh (that store your mesh)
199 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
200 !! mmgSol: your MMG5_pSol (that store your metric) */
201
202 mmgmesh = 0
203 mmgsol = 0
204
205 CALL mmg3d_init_mesh(mmg5_arg_start, &
206 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
207 mmg5_arg_end)
208
209 !> 2) Build mesh in MMG5 format
210 !! Two solutions: just use the MMG3D_loadMesh function that will read a .mesh(b)
211 !! file formatted or manually set your mesh using the MMG3D_Set* functions
212
213 !> with MMG3D_loadMesh function
214 CALL mmg3d_loadmesh(mmgmesh,trim(adjustl(tdfile)),&
215 len(trim(adjustl(tdfile))),ier)
216 IF ( ier /= 1 ) CALL exit(102)
217
218 !> 3) Build sol in MMG5 format
219 !! Two solutions: just use the MMG3D_loadSol function that will read a .sol(b)
220 !! file formatted or manually set your sol using the MMG3D_Set* functions
221
222 !> With MMG3D_loadSol function
223 CALL mmg3d_loadsol(mmgmesh,mmgsol,trim(adjustl(tdfile)),len(trim(adjustl(tdfile))),ier)
224 IF ( ier /= 1 ) THEN
225 CALL exit(104)
226 ENDIF
227
228 !> 4) (not mandatory): check if the number of given entities match with mesh size
229 CALL mmg3d_chk_meshdata(mmgmesh,mmgsol,ier)
230 IF ( ier /= 1 ) CALL exit(105)
231
232 !> ------------------------------ STEP II --------------------------
233 !! remesh function
234 CALL mmg3d_mmg3dlib(mmgmesh,mmgsol,ier)
235
236 IF ( ier == mmg5_strongfailure ) THEN
237 print*,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH"
238 stop 2
239 ELSE IF ( ier == mmg5_lowfailure ) THEN
240 print*,"BAD ENDING OF MMG3DLIB"
241 ENDIF
242
243 !> ------------------------------ STEP III --------------------------
244 !! get results
245 !! Two solutions: just use the MMG3D_saveMesh/MMG3D_saveSol functions
246 !! that will write .mesh(b)/.sol formatted files or manually get your mesh/sol
247 !! using the MMG3D_getMesh/MMG3D_getSol functions
248
249 !> 1) Automatically save the mesh
250 CALL mmg3d_savemesh(mmgmesh,trim(adjustl(fileout)) // ".3d.mesh",&
251 len(trim(adjustl(fileout)) // ".3d.mesh"),ier)
252 IF ( ier /= 1 ) THEN
253 CALL exit(108)
254 ENDIF
255
256 !> 2) Automatically save the solution
257 CALL mmg3d_savesol(mmgmesh,mmgsol,trim(adjustl(fileout)) // ".3d.sol",&
258 len(trim(adjustl(fileout)) // ".3d.sol"),ier)
259 IF ( ier /= 1 ) THEN
260 CALL exit(107)
261 ENDIF
262
263
264 !> 3) Free the MMG3D5 structures
265 CALL mmg3d_free_all(mmg5_arg_start, &
266 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
267 mmg5_arg_end)
268
269END PROGRAM main
int main(int argc, char *argv[])
Definition mmg2d.c:275