Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.F90
Go to the documentation of this file.
1!! =============================================================================
2!! This file is part of the mmg software package for the tetrahedral
3!! mesh modification.
4!! Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- .
5!!
6!! mmg is free software: you can redistribute it and/or modify it
7!! under the terms of the GNU Lesser General Public License as published
8!! by the Free Software Foundation, either version 3 of the License, or
9!! (at your option) any later version.
10!!
11!! mmg is distributed in the hope that it will be useful, but WITHOUT
12!! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13!! FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14!! License for more details.
15!!
16!! You should have received a copy of the GNU Lesser General Public
17!! License and of the GNU General Public License along with mmg (in
18!! files COPYING.LESSER and COPYING). If not, see
19!! <http://www.gnu.org/licenses/>. Please read their terms carefully and
20!! use this copy of the mmg distribution only if you accept them.
21!! =============================================================================
22!!
23
25! Example of use of the mmg3dls function of the mmg3d library (basic use of
26! level-set discretization option): here the user
27! provide a level-set and a metric on which he want to adapt the final mesh
28!
29! @author Charles Dapogny (LJLL, UPMC)
30! @author Pascal Frey (LJLL, UPMC)
31! @author Algiane Froehly (Inria / IMB, Université de Bordeaux)
32! @version 5
33! @copyright GNU Lesser General Public License.
34!
35
36PROGRAM main
37
38 IMPLICIT NONE
39
41! if the header file is in the "include" directory
42! #include "libmmg3df.h"
43
44! if the header file is in "include/mmg/mmg3d"
45#include "mmg/mmg3d/libmmg3df.h"
46
47 mmg5_data_ptr_t :: mmgmesh
48 mmg5_data_ptr_t :: mmgls,mmgmet
49 INTEGER :: ier,argc
50 INTEGER(MMG5F_INT) :: k,np
51 CHARACTER(len=300) :: exec_name,inname,outname,lsname
53 INTEGER,PARAMETER :: immg = mmg5f_int
54
55 WRITE(*,*) " -- TEST MMG3DLIB"
56
57 argc = command_argument_count();
58 CALL get_command_argument(0, exec_name)
59
60 IF ( argc /=3 ) THEN
61 print*," Usage: ",trim(exec_name)," meshfile lsfile meshout"
62 CALL exit(1);
63 ENDIF
64
65 ! Name and path of the mesh file
66 CALL get_command_argument(1, inname)
67 CALL get_command_argument(2, lsname)
68 CALL get_command_argument(3, outname)
69
71 ! 1) Initialisation of mesh and sol structures
72 ! args of InitMesh:
73 ! MMG5_ARG_start: we start to give the args of a variadic func
74 ! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
75 ! mmgMesh: your MMG5_pMesh (that stores your mesh)
76 ! MMG5_ARG_ppLs: next arg will be a pointer over a MMG5_pSol storing a level-set
77 ! mmgLs: pointer to your MMG5_pSol (that stores your level-set)
78 ! MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol that will
79 ! store the input metric
80 ! mmgMet: pointer to your MMG5_pSol (that will store the input metric)
81 mmgmesh = 0
82 mmgls = 0
83 mmgmet = 0
84
85 CALL mmg3d_init_mesh(mmg5_arg_start, &
86 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppls,mmgls, &
87 mmg5_arg_ppmet,mmgmet, &
88 mmg5_arg_end)
89
90 !!------------------- Level set discretization option ---------------------
91 ! Ask for level set discretization: note that it is important to do this step
92 ! here because in iso mode, some filters are applied at mesh loading
93 CALL mmg3d_set_iparameter(mmgmesh,mmgls,mmg3d_iparam_iso, 1_immg,ier)
94 IF ( ier == 0 ) CALL exit(101)
95
99
101 CALL mmg3d_loadmesh(mmgmesh,trim(adjustl(inname)),&
102 len(trim(adjustl(inname))),ier)
103 IF ( ier == 0 ) CALL exit(102)
104
106 ! Two solutions: just use the MMG3D_loadSol function that will read a .sol(b)
107 ! file formatted or manually set your level-set using the MMG3D_Set* functions
108
110 CALL mmg3d_loadsol(mmgmesh,mmgls,trim(adjustl(lsname)),&
111 len(trim(adjustl(lsname))),ier)
112 IF ( ier /= 1 ) THEN
113 CALL exit(104)
114 ENDIF
115
116 ! ------------------- Give the Metric to Mmg ------------------------------
117 ! Manually for example
118 ! a) give info for the metric: the metric is applied on vertex
119 ! entities, number of vertices np is recoverd using get_meshSize and the sol
120 ! is tensorial
121 CALL mmg3d_get_meshsize(mmgmesh,np,%val(0_immg),%val(0_immg),&
122 %val(0_immg),%val(0_immg),%val(0_immg),ier)
123 IF ( ier /= 1 ) THEN
124 CALL exit(204)
125 ENDIF
126
127
128 CALL mmg3d_set_solsize(mmgmesh,mmgmet,mmg5_vertex,np,mmg5_tensor,ier)
129 IF ( ier /= 1 ) THEN
130 CALL exit(304)
131 ENDIF
132
133 ! b) give metric values and positions
134 DO k=1,np
135 ! the Metric is constant over the mesh and follow the canonical
136 ! directions: it is given by the tensor (10000,0,100)
137 CALL mmg3d_set_tensorsol(mmgmet,10.d0,0.d0,0.d0,1.d0,0.d0,1.d0,k,ier)
138 IF ( ier /= 1 ) THEN
139 CALL exit(404)
140 ENDIF
141 ENDDO
142
144 CALL mmg3d_chk_meshdata(mmgmesh,mmgls,ier)
145 IF ( ier /= 1 ) CALL exit(105)
146
148 ! isovalue discretization followed by an adaptation step over the input
149 ! Metric mmgMet. The mmgMet structure is updated so at the end it contains
150 ! the output metric of Mmg.
151 CALL mmg3d_mmg3dls(mmgmesh,mmgls,mmgmet,ier)
152
153 IF ( ier == mmg5_strongfailure ) THEN
154 print*,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH"
155 stop 2
156 ELSE IF ( ier == mmg5_lowfailure ) THEN
157 print*,"BAD ENDING OF MMG3DLIB"
158 ENDIF
159
165
167 CALL mmg3d_savemesh(mmgmesh,trim(adjustl(outname)),&
168 len(trim(adjustl(outname))),ier)
169 IF ( ier /= 1 ) THEN
170 CALL exit(106)
171 ENDIF
172
174 CALL mmg3d_savesol(mmgmesh,mmgmet,trim(adjustl(outname)),&
175 len(trim(adjustl(outname))),ier)
176 IF ( ier /= 1 ) THEN
177 CALL exit(107)
178 ENDIF
179
181 CALL mmg3d_free_all(mmg5_arg_start, &
182 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppls,mmgls, &
183 mmg5_arg_ppmet,mmgmet, &
184 mmg5_arg_end)
185
186END PROGRAM
int main(int argc, char *argv[])
Definition: mmg2d.c:275