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
24!>
25! Example of use of the mmgsls function of the mmgs 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
40!> Include here the mmgs library hader file
41! if the header file is in the "include" directory
42! #include "libmmgsf.h"
43
44! if the header file is in "include/mmg/mmgs"
45#include "mmg/mmgs/libmmgsf.h"
46
47 mmg5_data_ptr_t :: mmgmesh
48 mmg5_data_ptr_t :: mmgls,mmgmet
49 INTEGER(MMG5F_INT) :: k, np
50 INTEGER :: ier,argc
51 CHARACTER(len=300) :: exec_name,inname,outname,lsname
52 !> to cast integers into MMG5F_INT integers
53 INTEGER,PARAMETER :: immg = mmg5f_int
54
55 WRITE(*,*) " -- TEST MMGSLIB"
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
70 !> ------------------------------ STEP I --------------------------
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 store your mesh)
76 ! MMG5_ARG_ppLs: next arg will be a pointer over a MMG5_pSol storing a level-set
77 ! mmgLs: pointer toward your MMG5_pSol (that store 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 toward your MMG5_pSol (that will store the input metric)
81 mmgmesh = 0
82 mmgls = 0
83 mmgmet = 0
84
85 CALL mmgs_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 mmgs_set_iparameter(mmgmesh,mmgls,mmgs_iparam_iso, 1_immg,ier)
94 IF ( ier == 0 ) CALL exit(101)
95
96 !> 2) Build mesh in MMG5 format
97 !! Two solutions: just use the MMGS_loadMesh function that will read a .mesh(b)
98 !! file formatted or manually set your mesh using the MMGS_Set* functions
99
100 !> with MMGS_loadMesh function
101 CALL mmgs_loadmesh(mmgmesh,trim(adjustl(inname)),&
102 len(trim(adjustl(inname))),ier)
103 IF ( ier == 0 ) CALL exit(102)
104
105 !> 3) Build the level-set and metric in MMG5 format
106 ! Two solutions: just use the MMGS_loadSol function that will read a .sol(b)
107 ! file formatted or manually set your level-set using the MMGS_Set* functions
108
109 !> load the level-set with MMGS_loadSol function
110 CALL mmgs_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 mmgs_get_meshsize(mmgmesh,np,%val(0_immg),%val(0_immg),ier)
122 IF ( ier /= 1 ) THEN
123 CALL exit(204)
124 ENDIF
125
126
127 CALL mmgs_set_solsize(mmgmesh,mmgmet,mmg5_vertex,np,mmg5_tensor,ier)
128 IF ( ier /= 1 ) THEN
129 CALL exit(304)
130 ENDIF
131
132 ! b) give metric values and positions
133 DO k=1,np
134 ! the Metric is constant over the mesh and follow the canonical
135 ! directions: it is given by the tensor (10000,0,100)
136 CALL mmgs_set_tensorsol(mmgmet,10000.d0,0.d0,0.d0,100.d0,0.d0,1.d0,k,ier)
137 IF ( ier /= 1 ) THEN
138 CALL exit(404)
139 ENDIF
140 ENDDO
141
142 !> 4) (not mandatory): check the mesh and levelset sizes
143 CALL mmgs_chk_meshdata(mmgmesh,mmgls,ier)
144 IF ( ier /= 1 ) CALL exit(105)
145
146 !> ------------------------------ STEP II --------------------------
147 ! isovalue discretization followed by an adaptation step over the input
148 ! Metric mmgMet. The mmgMet structure is updated so at the end it contains
149 ! the output metric of Mmg.
150 CALL mmgs_mmgsls(mmgmesh,mmgls,mmgmet,ier)
151
152 IF ( ier == mmg5_strongfailure ) THEN
153 print*,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH"
154 stop 2
155 ELSE IF ( ier == mmg5_lowfailure ) THEN
156 print*,"BAD ENDING OF MMGSLIB"
157 ENDIF
158
159 !> ------------------------------ STEP III --------------------------
160 !! get results
161 !! Two solutions: just use the MMGS_saveMesh function
162 !! that will write .mesh(b) formatted file or manually get your mesh
163 !! using the MMGS_getMesh function
164
165 !> 1) Automatically save the mesh
166 CALL mmgs_savemesh(mmgmesh,trim(adjustl(outname)),&
167 len(trim(adjustl(outname))),ier)
168 IF ( ier /= 1 ) THEN
169 CALL exit(106)
170 ENDIF
171
172 !> 2) (Not mandatory) Automatically save the output metric
173 CALL mmgs_savesol(mmgmesh,mmgmet,trim(adjustl(outname)),&
174 len(trim(adjustl(outname))),ier)
175 IF ( ier /= 1 ) THEN
176 CALL exit(107)
177 ENDIF
178
179 !> 3) Free the MMGS5 structures
180 CALL mmgs_free_all(mmg5_arg_start, &
181 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppls,mmgls, &
182 mmg5_arg_ppmet,mmgmet, &
183 mmg5_arg_end)
184
185END PROGRAM
int main(int argc, char *argv[])
Definition mmg2d.c:275