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 mmgslib (basic use)
5
6PROGRAM main
7
8 IMPLICIT NONE
9
10 !> Include the mmgs library hader file
11 ! if the header file is in the "include" directory
12 ! #include "libmmgsf.h"
13
14 ! if the header file is in "include/mmg/mmgs"
15#include "mmg/mmgs/libmmgsf.h"
16
17
18 mmg5_data_ptr_t :: mmgmesh
19 mmg5_data_ptr_t :: mmgsol
20 INTEGER :: ier,argc
21 CHARACTER(len=300) :: exec_name,filename,fileout
22
23 WRITE(*,*) " -- TEST MMGSLIB"
24
25 argc = command_argument_count();
26 CALL get_command_argument(0, exec_name)
27
28 IF ( argc /=2 ) THEN
29 print*," Usage: ",trim(exec_name)," input_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, filename)
35 CALL get_command_argument(2, fileout)
36
37 !> ------------------------------ STEP I --------------------------
38 !! 1) Initialisation of mesh and sol structures
39 !! args of InitMesh:
40 !! MMG5_ARG_start: we start to give the args of a variadic func
41 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
42 !! mmgMesh: your MMG5_pMesh (that store your mesh)
43 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
44 !! mmgSol: your MMG5_pSol (that store your metric) */
45 mmgmesh = 0
46 mmgsol = 0
47
48 CALL mmgs_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 MMGS_loadMesh function that will read a .mesh(b)
54 !! file formatted or manually set your mesh using the MMGS_Set* functions
55
56 !> with MMGS_loadMesh function
57 CALL mmgs_loadmesh(mmgmesh,trim(adjustl(filename)),&
58 len(trim(adjustl(filename))),ier)
59 IF ( ier /= 1 ) CALL exit(102)
60
61 !> 3) Build sol in MMG5 format
62 !! Two solutions: just use the MMGS_loadSol function that will read a .sol(b)
63 !! file formatted or manually set your sol using the MMGS_Set* functions
64
65 !> With MMGS_loadSol function
66 CALL mmgs_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 mmgs_chk_meshdata(mmgmesh,mmgsol,ier)
74 IF ( ier /= 1 ) CALL exit(105)
75
76 !> ------------------------------ STEP II --------------------------
77 !! remesh function
78 !! Remark: %val(0) allow to pass the value 0 (i.e. NULL) instead of a pointer
79 !! toward NULL.
80 CALL mmgs_mmgslib(mmgmesh,mmgsol,ier)
81 IF ( ier == mmg5_strongfailure ) THEN
82 print*,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH"
83 stop 2
84 ELSE IF ( ier == mmg5_lowfailure ) THEN
85 print*,"BAD ENDING OF MMGSLIB"
86 ENDIF
87
88 !> ------------------------------ STEP III --------------------------
89 !! get results
90 !! Two solutions: just use the MMGS_saveMesh/MMGS_saveSol functions
91 !! that will write .mesh(b)/.sol formatted files or manually get your mesh/sol
92 !! using the MMGS_getMesh/MMGS_getSol functions
93
94 !> 1) Automatically save the mesh
95 CALL mmgs_savemesh(mmgmesh,trim(adjustl(fileout)),len(trim(adjustl(fileout))),ier)
96 IF ( ier /= 1 ) CALL exit(106)
97
98 !> 2) Automatically save the solution
99 CALL mmgs_savesol(mmgmesh,mmgsol,trim(adjustl(fileout)),len(trim(adjustl(fileout))),ier)
100 IF ( ier /= 1 ) CALL exit(107)
101
102 !> 3) Free the MMGS5 structures
103 CALL mmgs_free_all(mmg5_arg_start, &
104 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgsol, &
105 mmg5_arg_end)
106
107END PROGRAM main
int main(int argc, char *argv[])
Definition mmg2d.c:275