Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.F90
Go to the documentation of this file.
1
4
5PROGRAM main
6
7 IMPLICIT NONE
8
10 ! if the header file is in the "include" directory
11 ! #include "libmmg2df.h"
12
13 ! if the header file is in "include/mmg/mmg2d"
14#include "mmg/mmg2d/libmmg2df.h"
15
16 mmg5_data_ptr_t :: mmgmesh
17 mmg5_data_ptr_t :: mmgsol,mmgmet,tmpsol
18 INTEGER :: ier,argc,i,opt
19
20 !! To manually recover the mesh
21 INTEGER :: nsol,typsol(mmg5_nsols_max)
22 INTEGER(MMG5F_INT) :: np,j
23 REAL(kind=8),dimension(:),ALLOCATABLE :: sols
24
25 CHARACTER(len=300) :: exec_name,filename,fileout,option
26
27 print*," -- TEST MMG2DLIB"
28
29 argc = command_argument_count();
30 CALL get_command_argument(0, exec_name)
31
32
33 IF ( argc /=3 ) THEN
34 print*," Usage: ",trim(adjustl(exec_name)),&
35 " input_file_name output_file_name io_option"
36 print*," io_option = 0 to Get/Set the solution field by field"
37 print*," io_option = 1 to Get/Set the solution field by field &
38 & and vertex by vertex"
39 CALL exit(1);
40 ENDIF
41
42 ! Name and path of the mesh file
43 CALL get_command_argument(1, filename)
44 CALL get_command_argument(2, fileout)
45 CALL get_command_argument(3, option)
46
47 READ(option, '(I2)') opt
48 !!> ------------------------------ STEP I --------------------------
49 !! 1) Initialisation of mesh and sol structures */
50 !! args of InitMesh:
51 !! MMG5_ARG_start: we start to give the args of a variadic func
52 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
53 !! &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
54 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
55 !! &mmgSol: pointer toward your MMG5_pSol (that store your metric)
56
57 mmgmesh = 0
58 mmgsol = 0
59 mmgmet = 0
60 tmpsol = 0
61
62 CALL mmg2d_init_mesh(mmg5_arg_start, &
63 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgmet, &
64 mmg5_arg_end);
65
66
67 !!> 2) Build initial mesh and solutions in MMG5 format
68 !! Two solutions: just use the MMG2D_loadMesh function that will read a .mesh(b)
69 !! file formatted or manually set your mesh using the MMG2D_Set* functions
70
71 !!> Automatic loading of the mesh and multiple solutions
72 CALL mmg2d_loadmesh(mmgmesh,trim(adjustl(filename)),&
73 len(trim(adjustl(filename))),ier)
74 IF ( ier /= 1 ) CALL exit(102)
75
76 CALL mmg2d_loadallsols(mmgmesh,mmgsol,trim(adjustl(filename)),&
77 len(trim(adjustl(filename))),ier)
78 IF ( ier /= 1 ) CALL exit(103)
79
80 !!> ------------------------------ STEP II ---------------------------
81
82 !!> 3) Transfer the solutions in a new solutions array
83 !! a) Get the solutions sizes
84 CALL mmg2d_get_solsatverticessize(mmgmesh,mmgsol,nsol,np,typsol,ier)
85 IF ( ier /= 1 ) CALL exit(104)
86
87 !!> b) Manually set the size of the new solution: give info for the sol
88 !! structure: number of solutions, type of entities on which applied the
89 !! solutions, number of vertices, type of the solution */
90 CALL mmg2d_set_solsatverticessize(mmgmesh,tmpsol,nsol,np,typsol,ier)
91 IF ( ier /= 1 ) CALL exit(105)
92
93 !!> c) Get each solution and set it in the new structure
94
95 !!> b) give solutions values and positions
96 !! Get the entire field of a given solution
97 DO i=1,nsol
98
99 IF ( opt==0 ) THEN
100 ! Get the ith solution array
101 IF ( typsol(i) == mmg5_scalar ) THEN
102 ALLOCATE(sols(np))
103 ELSE IF ( typsol(i) == mmg5_vector ) THEN
104 ALLOCATE(sols(2*np))
105 ELSE IF ( typsol(i) == mmg5_tensor ) THEN
106 ALLOCATE(sols(3*np))
107 ENDIF
108
109 CALL mmg2d_get_ithsols_insolsatvertices(mmgsol,i,sols,ier)
110 IF ( ier /= 1 ) CALL exit(107)
111
112 ! Set the ith solution in the new structure
113 CALL mmg2d_set_ithsols_insolsatvertices(tmpsol,i,sols,ier)
114 IF ( ier /= 1 ) CALL exit(108)
115 ELSE
116 IF ( typsol(i) == mmg5_scalar ) THEN
117 ALLOCATE(sols(1))
118 ELSE IF ( typsol(i) == mmg5_vector ) THEN
119 ALLOCATE(sols(3))
120 ELSE IF ( typsol(i) == mmg5_tensor ) THEN
121 ALLOCATE(sols(6))
122 ENDIF
123
124 DO j=1,np
125 ! Get and set the ith solution array vertex by vertex
126 CALL mmg2d_get_ithsol_insolsatvertices(mmgsol,i,sols,j,ier)
127 IF ( ier /= 1 ) CALL exit(107)
128
129 ! Set the ith solution in the new structure
130 CALL mmg2d_set_ithsol_insolsatvertices(tmpsol,i,sols,j,ier)
131 IF ( ier /= 1 ) CALL exit(108)
132 ENDDO
133 ENDIF
134
135 DEALLOCATE(sols)
136 ENDDO
137
138
139 !!> ------------------------------ STEP III --------------------------
140 !! Save the new data
141 !! Use the MMG2D_saveMesh/MMG2D_saveAllSols functions
142 !! save the mesh
144 CALL mmg2d_savemesh(mmgmesh,trim(adjustl(fileout)),len(trim(adjustl(fileout))),ier)
145 IF ( ier /= 1 ) CALL exit(110)
146
147 ! save the solutions array
148 CALL mmg2d_saveallsols(mmgmesh,tmpsol,trim(adjustl(fileout)), &
149 len(trim(adjustl(fileout))),ier)
150 IF ( ier /= 1 ) CALL exit(111)
151
152 !!> 3) Free the MMG2D structures
153 CALL mmg2d_free_allsols(mmgmesh,mmgsol,ier)
154
155 CALL mmg2d_free_all(mmg5_arg_start, &
156 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppsols,tmpsol, &
157 mmg5_arg_end)
158
159END PROGRAM main
int main(int argc, char *argv[])
Definition: mmg2d.c:275