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