Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
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
34
35#include <assert.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <signal.h>
39#include <string.h>
40#include <ctype.h>
41#include <math.h>
42#include <float.h>
43
45// if the header file is in the "include" directory
46// #include "libmmgs.h"
47// if the header file is in "include/mmg/mmgs"
48#include "mmg/mmgs/libmmgs.h"
49
50int main(int argc,char *argv[]) {
51 MMG5_pMesh mmgMesh;
52 MMG5_pSol mmgSol;
53 int ier;
54 char *inname, *outname1, *outname2;
55
56 fprintf(stdout," -- TEST MMGSLIB \n");
57
58 if ( argc != 4 ) {
59 printf(" Usage: %s filein fileout1 fileout2 \n",argv[0]);
60 return(1);
61 }
62
63 /* Name and path of the mesh files */
64 inname = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
65 if ( inname == NULL ) {
66 perror(" ## Memory problem: calloc");
67 exit(EXIT_FAILURE);
68 }
69 strcpy(inname,argv[1]);
70
71 outname1 = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
72 if ( outname1 == NULL ) {
73 perror(" ## Memory problem: calloc");
74 exit(EXIT_FAILURE);
75 }
76 strcpy(outname1,argv[2]);
77
78 outname2 = (char *) calloc(strlen(argv[3]) + 1, sizeof(char));
79 if ( outname2 == NULL ) {
80 perror(" ## Memory problem: calloc");
81 exit(EXIT_FAILURE);
82 }
83 strcpy(outname2,argv[3]);
84
86 /* args of InitMesh:
87 * MMG5_ARG_start: we start to give the args of a variadic func
88 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
89 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
90 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
91 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
92 mmgMesh = NULL;
93 mmgSol = NULL;
95 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
97
101
103 if ( MMGS_loadMesh(mmgMesh,inname) != 1 ) exit(EXIT_FAILURE);
104
108
110 if ( MMGS_loadSol(mmgMesh,mmgSol,inname) != 1 )
111 exit(EXIT_FAILURE);
112
114 if ( MMGS_Chk_meshData(mmgMesh,mmgSol) != 1 ) exit(EXIT_FAILURE);
115
119
120
122
123 /* debug mode ON (default value = OFF) */
124 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_debug, 1) != 1 )
125 exit(EXIT_FAILURE);
126
127 /* maximal memory size (default value = 50/100*ram) */
128 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_mem, 600) != 1 )
129 exit(EXIT_FAILURE);
130
131 /* Maximal mesh size (default FLT_MAX)*/
132 if ( MMGS_Set_dparameter(mmgMesh,mmgSol,MMGS_DPARAM_hmax,40) != 1 )
133 exit(EXIT_FAILURE);
134
135 /* Minimal mesh size (default 0)*/
136 if ( MMGS_Set_dparameter(mmgMesh,mmgSol,MMGS_DPARAM_hmin,0.001) != 1 )
137 exit(EXIT_FAILURE);
138
139 /* Global hausdorff value (default value = 0.01) applied on the whole boundary */
140 if ( MMGS_Set_dparameter(mmgMesh,mmgSol,MMGS_DPARAM_hausd, 0.1) != 1 )
141 exit(EXIT_FAILURE);
142
143 /* Gradation control */
144 if ( MMGS_Set_dparameter(mmgMesh,mmgSol,MMGS_DPARAM_hgrad, 2) != 1 )
145 exit(EXIT_FAILURE);
146
148 ier = MMGS_mmgslib(mmgMesh,mmgSol);
149 if ( ier == MMG5_STRONGFAILURE ) {
150 fprintf(stdout,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH\n");
151 return(ier);
152 } else if ( ier == MMG5_LOWFAILURE )
153 fprintf(stdout,"BAD ENDING OF MMGSLIB\n");
154
155 /* (Not mandatory) Automatically save the mesh */
156 MMGS_saveMesh(mmgMesh,outname1);
157
158 /* (Not mandatory) Automatically save the solution */
159 if ( MMGS_saveSol(mmgMesh,mmgSol,outname1) != 1 )
160 exit(EXIT_FAILURE);
161
162
164 /* We add different local hausdorff numbers on boundary componants (this
165 local values are used instead of the global hausdorff number) */
166
167 /* verbosity (default value = 4)*/
168 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_verbose, 4) != 1 )
169 exit(EXIT_FAILURE);
170
171 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_mem, 1000) != 1 )
172 exit(EXIT_FAILURE);
173 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_debug, 0) != 1 )
174 exit(EXIT_FAILURE);
175
176
178 /* use a hmin value of 0.005 on ref 36 and 0.1 on ref 38 */
179 /* use a hmax value of 0.05 on ref 36 and 1 on ref 38 */
180 /* For now, the local hausdroff value is not take into account */
181 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_numberOfLocalParam,2) != 1 )
182 exit(EXIT_FAILURE);
183
188
189 /* Be careful if you change the hausdorff number (or gradation value)
190 between 2 run: the information of the previous hausdorff number
191 (resp. gradation) is contained in the metric computed during
192 the previous run.
193 Then, you can not grow up the hausdorff value (resp. gradation) without
194 resetting this metric (but you can decrease this value). */
195
196 if ( MMGS_Set_localParameter(mmgMesh,mmgSol,MMG5_Triangle,36,0.005,0.05,1) != 1 )
197 exit(EXIT_FAILURE);
198 if ( MMGS_Set_localParameter(mmgMesh,mmgSol,MMG5_Triangle,38,0.1,1,1) != 1 )
199 exit(EXIT_FAILURE);
200
202 ier = MMGS_mmgslib(mmgMesh,mmgSol);
203 if ( ier == MMG5_STRONGFAILURE ) {
204 fprintf(stdout,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH\n");
205 return(ier);
206 } else if ( ier == MMG5_LOWFAILURE )
207 fprintf(stdout,"BAD ENDING OF MMGSLIB\n");
208
209 /* (Not mandatory) Automatically save the mesh */
210 if ( MMGS_saveMesh(mmgMesh,outname2) != 1 )
211 exit(EXIT_FAILURE);
212
213 /* (Not mandatory) Automatically save the solution */
214 if ( MMGS_saveSol(mmgMesh,mmgSol,outname2) != 1 )
215 exit(EXIT_FAILURE);
216
217 /* 7) free the MMGS structures */
219 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
221
222 free(inname);
223 inname = NULL;
224
225 free(outname1);
226 outname1 = NULL;
227
228 free(outname2);
229 outname2 = NULL;
230
231 return(ier);
232}
int MMGS_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
set an integer parameter of the remesher
int MMGS_Set_localParameter(MMG5_pMesh mesh, MMG5_pSol sol, int typ, MMG5_int ref, double hmin, double hmax, double hausd)
set a local parameter
int MMGS_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMGS_Free_all(const int starter,...)
Deallocations before return.
int MMGS_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
Check if the numbers of given entities match with mesh and solution size and check mesh data.
int MMGS_Set_dparameter(MMG5_pMesh mesh, MMG5_pSol sol, int dparam, double val)
set a real-valued parameter of the remesher
int ier
program main
Example for using mmglib (basic use)
Definition main.F90:6
int MMGS_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution) in medit's .sol format.
Definition inout_s.c:1312
int MMGS_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh or .meshb format.
Definition inout_s.c:842
int MMGS_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write an isotropic or anisotropic metric in medit file format.
Definition inout_s.c:1483
int MMGS_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition inout_s.c:41
int MMGS_mmgslib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for mesh adaptation.
Definition libmmgs.c:545
@ MMGS_IPARAM_numberOfLocalParam
Definition libmmgs.h:124
@ MMGS_DPARAM_hgrad
Definition libmmgs.h:136
@ MMGS_IPARAM_verbose
Definition libmmgs.h:110
@ MMGS_IPARAM_debug
Definition libmmgs.h:112
@ MMGS_DPARAM_hmin
Definition libmmgs.h:132
@ MMGS_DPARAM_hausd
Definition libmmgs.h:135
@ MMGS_IPARAM_mem
Definition libmmgs.h:111
@ MMGS_DPARAM_hmax
Definition libmmgs.h:133
#define MMG5_ARG_ppMesh
#define MMG5_ARG_end
#define MMG5_STRONGFAILURE
Definition libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition libmmgtypes.h:57
MMG5_Sol * MMG5_pSol
MMG5_Mesh * MMG5_pMesh
#define MMG5_ARG_start
Definition libmmgtypes.h:93
@ MMG5_Triangle
#define MMG5_ARG_ppMet