Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main_optim.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 mmg3dls function of the mmg3d library (basic use of
26!> level-set discretization option): here the user only provide the level-set
27!>
28!> @author Charles Dapogny (LJLL, UPMC)
29!> @author Pascal Frey (LJLL, UPMC)
30!> @author Algiane Froehly (Inria / IMB, Université de Bordeaux)
31!> @version 5
32!> @copyright GNU Lesser General Public License.
33!>
34
35PROGRAM main
36
37 IMPLICIT NONE
38
39!> Include here the mmg3d library hader file
40! if the header file is in the "include" directory
41! #include "libmmg3df.h"
42
43! if the header file is in "include/mmg/mmg3d"
44#include "mmg/mmg3d/libmmg3df.h"
45
46 mmg5_data_ptr_t :: mmgmesh
47 mmg5_data_ptr_t :: mmgls
48 INTEGER :: ier,argc
49 CHARACTER(len=300) :: exec_name,inname,outname,lsname
50 !> to cast integers into MMG5F_INT integers
51 INTEGER,PARAMETER :: immg = mmg5f_int
52
53 WRITE(*,*) " -- TEST MMG3DLIB"
54
55 argc = command_argument_count();
56 CALL get_command_argument(0, exec_name)
57
58 IF ( argc /=3 ) THEN
59 print*," Usage: ",trim(exec_name)," meshfile lsfile meshout"
60 CALL exit(1);
61 ENDIF
62
63 ! Name and path of the mesh file
64 CALL get_command_argument(1, inname)
65 CALL get_command_argument(2, lsname)
66 CALL get_command_argument(3, outname)
67
68 !> ------------------------------ STEP I --------------------------
69 !! 1) Initialisation of mesh and sol structures
70 !! args of InitMesh:
71 !! MMG5_ARG_start: we start to give the args of a variadic func
72 !! MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
73 !! mmgMesh: your MMG5_pMesh (that stores your mesh)
74 !! MMG5_ARG_ppLs: next arg will be a pointer over a MMG5_pSol storing a level-set
75 !! &mmgLs: pointer to your MMG5_pSol (that stores your level-set)
76
77 mmgmesh = 0
78 mmgls = 0
79
80 CALL mmg3d_init_mesh(mmg5_arg_start, &
81 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppls,mmgls, &
82 mmg5_arg_end)
83
84 !!------------------- Level set discretization option ---------------------
85 ! Ask for level set discretization: note that it is important to do this step
86 ! here because in iso mode, some filters are applied at mesh loading
87 !
88 ! Pass 0_8 (0 at 64 bytes precision) if you don't want to pass the mmgLs
89 ! structure (unused argument of Set_iparameter functions).
90 CALL mmg3d_set_iparameter(mmgmesh,0_8,mmg3d_iparam_iso, 1_immg,ier)
91 IF ( ier == 0 ) CALL exit(101)
92
93 ! Ask for optim mode: compute the mean of input edge lengths.
94 CALL mmg3d_set_iparameter(mmgmesh,0_8,mmg3d_iparam_optim, 1_immg,ier)
95 IF ( ier == 0 ) CALL exit(101)
96
97 ! Ask to do this with anisotropic metric (unit tensor metric is computed).
98 CALL mmg3d_set_iparameter(mmgmesh,0_8,mmg3d_iparam_anisosize, 1_immg,ier)
99 IF ( ier == 0 ) CALL exit(101)
100
101 !> 2) Build mesh in MMG5 format
102 !! Two solutions: just use the MMG3D_loadMesh function that will read a .mesh(b)
103 !! file formatted or manually set your mesh using the MMG3D_Set* functions
104
105 !> with MMG3D_loadMesh function
106 CALL mmg3d_loadmesh(mmgmesh,trim(adjustl(inname)),&
107 len(trim(adjustl(inname))),ier)
108 IF ( ier == 0 ) CALL exit(102)
109
110 !> 3) Build the level-set in MMG5 format
111 !! Two solutions: just use the MMG3D_loadSol function that will read a .sol(b)
112 !! file formatted or manually set your level-set using the MMG3D_Set* functions
113
114 !> With MMG3D_loadSol function
115 CALL mmg3d_loadsol(mmgmesh,mmgls,trim(adjustl(lsname)),&
116 len(trim(adjustl(lsname))),ier)
117 IF ( ier /= 1 ) THEN
118 CALL exit(104)
119 ENDIF
120
121 !> 4) (not mandatory): check the mesh and levelset sizes
122 CALL mmg3d_chk_meshdata(mmgmesh,mmgls,ier)
123 IF ( ier /= 1 ) CALL exit(105)
124
125 !> ------------------------------ STEP II --------------------------
126 !! isovalue discretization: as we don't want to impose an input metric we
127 !! pass %val(0_8) instead of the metric structure as function argument
128 CALL mmg3d_mmg3dls(mmgmesh,mmgls,%val(0_8),ier)
129
130 IF ( ier == mmg5_strongfailure ) THEN
131 print*,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH"
132 stop 2
133 ELSE IF ( ier == mmg5_lowfailure ) THEN
134 print*,"BAD ENDING OF MMG3DLIB"
135 ENDIF
136
137 !> ------------------------------ STEP III --------------------------
138 !! get results
139 !! Two solutions: just use the MMG3D_saveMesh function
140 !! that will write .mesh(b) formatted file or manually get your mesh
141 !! using the MMG3D_getMesh function
142
143 !> 1) Automatically save the mesh
144 CALL mmg3d_savemesh(mmgmesh,trim(adjustl(outname)),&
145 len(trim(adjustl(outname))),ier)
146 IF ( ier /= 1 ) THEN
147 CALL exit(106)
148 ENDIF
149
150 !> 3) Free the MMG3D5 structures
151 CALL mmg3d_free_all(mmg5_arg_start, &
152 mmg5_arg_ppmesh,mmgmesh,mmg5_arg_ppls,mmgls, &
153 mmg5_arg_end)
154
155END PROGRAM
int main(int argc, char *argv[])
Definition mmg2d.c:275