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 "libmmg3df.h"
12
13 ! if the header file is in "include/mmg/mmg3d"
14#include "mmg/mmg3d/libmmg3df.h"
15
16 mmg5_data_ptr_t :: mmgmesh
17 mmg5_data_ptr_t :: mmgsol,mmgmet,tmpsol
18 INTEGER :: ier,argc,opt,i4
19
20 !! To manually recover the mesh
21 INTEGER(MMG5F_INT) :: np,j
22 INTEGER :: nsol,typsol(mmg5_nsols_max)
23 REAL(kind=8),dimension(:),ALLOCATABLE :: sols
24
25 CHARACTER(len=300) :: exec_name,filename,fileout,option
26
27 print*," -- TEST MMG3DLIB"
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
49 !!> ------------------------------ STEP I --------------------------
50 !! 1) Initialisation of mesh and sol structures */
51 !! args of InitMesh:
52 !! MMG5_ARG_start: we start to give the args of a variadic func
53 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
54 !! &mmgMesh: pointer to your MMG5_pMesh (that stores your mesh)
55 !! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
56 !! &mmgSol: pointer to your MMG5_pSol (that stores your metric)
57
58 mmgmesh = 0
59 mmgsol = 0
60 mmgmet = 0
61 tmpsol = 0
62
63 CALL mmg3d_init_mesh(mmg5_arg_start, &
64 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppmet,mmgmet, &
65 mmg5_arg_end);
66
67
68 !!> 2) Build initial mesh and solutions in MMG5 format
69 !! Two solutions: just use the MMG3D_loadMesh function that will read a .mesh(b)
70 !! file formatted or manually set your mesh using the MMG3D_Set* functions
71
72 !!> Automatic loading of the mesh and multiple solutions
73 CALL mmg3d_loadmesh(mmgmesh,trim(adjustl(filename)),&
74 len(trim(adjustl(filename))),ier)
75 IF ( ier /= 1 ) CALL exit(102)
76
77 CALL mmg3d_loadallsols(mmgmesh,mmgsol,trim(adjustl(filename)),&
78 len(trim(adjustl(filename))),ier)
79 IF ( ier /= 1 ) CALL exit(103)
80
81 !!> ------------------------------ STEP II ---------------------------
82
83 !!> 3) Transfer the solutions in a new solutions array
84 !! a) Get the solutions sizes
85 CALL mmg3d_get_solsatverticessize(mmgmesh,mmgsol,nsol,np,typsol,ier)
86 IF ( ier /= 1 ) CALL exit(104)
87
88 !!> b) Manually set the size of the new solution: give info for the sol
89 !! structure: number of solutions, type of entities on which applied the
90 !! solutions, number of vertices, type of the solution */
91 CALL mmg3d_set_solsatverticessize(mmgmesh,tmpsol,nsol,np,typsol,ier)
92 IF ( ier /= 1 ) CALL exit(105)
93
94 !!> c) Get each solution and set it in the new structure
95
96 !!> b) give solutions values and positions
97 !! Get the entire field of a given solution
98 DO i4=1,nsol
99
100 IF ( opt==0 ) THEN
101 ! Get the ith solution array
102 IF ( typsol(i4) == mmg5_scalar ) THEN
103 ALLOCATE(sols(np))
104 ELSE IF ( typsol(i4) == mmg5_vector ) THEN
105 ALLOCATE(sols(3*np))
106 ELSE IF ( typsol(i4) == mmg5_tensor ) THEN
107 ALLOCATE(sols(6*np))
108 ENDIF
109
110 CALL mmg3d_get_ithsols_insolsatvertices(mmgsol,i4,sols,ier)
111 IF ( ier /= 1 ) CALL exit(107)
112
113 ! Set the ith solution in the new structure
114 CALL mmg3d_set_ithsols_insolsatvertices(tmpsol,i4,sols,ier)
115 IF ( ier /= 1 ) CALL exit(108)
116 ELSE
117 IF ( typsol(i4) == mmg5_scalar ) THEN
118 ALLOCATE(sols(1))
119 ELSE IF ( typsol(i4) == mmg5_vector ) THEN
120 ALLOCATE(sols(3))
121 ELSE IF ( typsol(i4) == mmg5_tensor ) THEN
122 ALLOCATE(sols(6))
123 ENDIF
124
125 DO j=1,np
126 ! Get and set the ith solution array vertex by vertex
127 CALL mmg3d_get_ithsol_insolsatvertices(mmgsol,i4,sols,j,ier)
128 IF ( ier /= 1 ) CALL exit(107)
129
130 ! Set the ith solution in the new structure
131 CALL mmg3d_set_ithsol_insolsatvertices(tmpsol,i4,sols,j,ier)
132 IF ( ier /= 1 ) CALL exit(108)
133 ENDDO
134 ENDIF
135
136 DEALLOCATE(sols)
137 ENDDO
138
139
140 !!> ------------------------------ STEP III --------------------------
141 !! Save the new data
142 !! Use the MMG3D_saveMesh/MMG3D_saveAllSols functions
143 !! save the mesh
145 CALL mmg3d_savemesh(mmgmesh,trim(adjustl(fileout)),len(trim(adjustl(fileout))),ier)
146 IF ( ier /= 1 ) CALL exit(110)
147
148 ! save the solutions array
149 CALL mmg3d_saveallsols(mmgmesh,tmpsol,trim(adjustl(fileout)), &
150 len(trim(adjustl(fileout))),ier)
151 IF ( ier /= 1 ) CALL exit(111)
152
153 !!> 3) Free the MMG3D structures
154 CALL mmg3d_free_allsols(mmgmesh,mmgsol,ier)
155
156 CALL mmg3d_free_all(mmg5_arg_start, &
157 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppsols,tmpsol, &
158 mmg5_arg_end)
159
160END PROGRAM main
int main(int argc, char *argv[])
Definition: mmg2d.c:275