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 mmg3dlib (basic use)
5
6PROGRAM main
7
8 IMPLICIT NONE
9
10!> Include here the mmg3d library hader file
11! if the header file is in the "include" directory
12! #include "libmmg3df.h"
13
14! if the header file is in "include/mmg/mmg3d"
15#include "mmg/mmg3d/libmmg3df.h"
16
17 mmg5_data_ptr_t :: mmgmesh
18 mmg5_data_ptr_t :: mmgsol
19 INTEGER :: ier,argc
20 CHARACTER(len=300) :: exec_name,filename,fileout
21
22 WRITE(*,*) " -- TEST MMG3DLIB"
23
24 argc = command_argument_count();
25 CALL get_command_argument(0, exec_name)
26
27 IF ( argc /=2 ) THEN
28 print*," Usage: ",trim(exec_name)," input_file_name output_filename"
29 CALL exit(1);
30 ENDIF
31
32 ! Name and path of the mesh file
33 CALL get_command_argument(1, filename)
34 CALL get_command_argument(2, fileout)
35
36 !> ------------------------------ STEP I --------------------------
37 !! 1) Initialisation of mesh and sol structures
38 !! args of InitMesh:
39 !! MMG5_ARG_start: we start to give the args of a variadic func
40 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
41 !! mmgMesh: your MMG5_pMesh (that store your mesh)
42 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
43 !! mmgSol: your MMG5_pSol (that store your metric) */
44
45 mmgmesh = 0
46 mmgsol = 0
47
48 CALL mmg3d_init_mesh(mmg5_arg_start, &
49 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
50 mmg5_arg_end)
51
52 !> 2) Build mesh in MMG5 format
53 !! Two solutions: just use the MMG3D_loadMesh function that will read a .mesh(b)
54 !! file formatted or manually set your mesh using the MMG3D_Set* functions
55
56 !> with MMG3D_loadMesh function
57 CALL mmg3d_loadmesh(mmgmesh,trim(adjustl(filename)),&
58 len(trim(adjustl(filename))),ier)
59 IF ( ier == 0 ) CALL exit(102)
60
61 !> 3) Build sol in MMG5 format
62 !! Two solutions: just use the MMG3D_loadSol function that will read a .sol(b)
63 !! file formatted or manually set your sol using the MMG3D_Set* functions
64
65 !> With MMG3D_loadSol function
66 CALL mmg3d_loadsol(mmgmesh,mmgsol,trim(adjustl(filename)),&
67 len(trim(adjustl(filename))),ier)
68 IF ( ier /= 1 ) THEN
69 CALL exit(104)
70 ENDIF
71
72 !> 4) (not mandatory): check if the number of given entities match with mesh size
73 CALL mmg3d_chk_meshdata(mmgmesh,mmgsol,ier)
74 IF ( ier /= 1 ) CALL exit(105)
75
76 !> ------------------------------ STEP II --------------------------
77 !! remesh function
78 CALL mmg3d_mmg3dlib(mmgmesh,mmgsol,ier)
79
80 IF ( ier == mmg5_strongfailure ) THEN
81 print*,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH"
82 stop 2
83 ELSE IF ( ier == mmg5_lowfailure ) THEN
84 print*,"BAD ENDING OF MMG3DLIB"
85 ENDIF
86
87 !> ------------------------------ STEP III --------------------------
88 !! get results
89 !! Two solutions: just use the MMG3D_saveMesh/MMG3D_saveSol functions
90 !! that will write .mesh(b)/.sol formatted files or manually get your mesh/sol
91 !! using the MMG3D_getMesh/MMG3D_getSol functions
92
93 !> 1) Automatically save the mesh
94 CALL mmg3d_savemesh(mmgmesh,trim(adjustl(fileout)),&
95 len(trim(adjustl(fileout))),ier)
96 IF ( ier /= 1 ) THEN
97 CALL exit(106)
98 ENDIF
99
100 !> 2) Automatically save the solution
101 CALL mmg3d_savesol(mmgmesh,mmgsol,trim(adjustl(fileout)),&
102 len(trim(adjustl(fileout))),ier)
103 IF ( ier /= 1 ) THEN
104 CALL exit(107)
105 ENDIF
106
107 !> 3) Free the MMG3D5 structures
108 CALL mmg3d_free_all(mmg5_arg_start, &
109 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
110 mmg5_arg_end)
111
112END PROGRAM main
int main(int argc, char *argv[])
Definition mmg2d.c:275