Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1
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 "libmmg3d.h"
47// if the header file is in "include/mmg/mmg3d"
48#include "mmg/mmg3d/libmmg3d.h"
49
50int main(int argc,char *argv[]) {
51 MMG5_pMesh mmgMesh;
52 MMG5_pSol mmgSol;
53 int k,ier;
54 char *inname, *outname1, *outname2;
55
56 fprintf(stdout," -- TEST MMG3DLIB \n");
57
58 if ( argc != 4 ) {
59 printf(" Usage: %s filein fileout1 filout2 \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 to your MMG5_pMesh (that stores your mesh)
90 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
91 * &mmgSol: pointer to your MMG5_pSol (that stores your metric) */
92
93 mmgMesh = NULL;
94 mmgSol = NULL;
95
97 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
99
105 if ( MMG3D_loadMesh(mmgMesh,inname) != 1 ) exit(EXIT_FAILURE);
106
112 if ( MMG3D_loadSol(mmgMesh,mmgSol,inname) != 1 )
113 exit(EXIT_FAILURE);
114
116 if ( MMG3D_Chk_meshData(mmgMesh,mmgSol) != 1 ) exit(EXIT_FAILURE);
117
125 /* debug mode ON (default value = OFF) */
126 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_debug, 1) != 1 )
127 exit(EXIT_FAILURE);
128
129 /* maximal memory size (default value = 50/100*ram) */
130 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_mem, 600) != 1 )
131 exit(EXIT_FAILURE);
132
133 /* Maximal mesh size (default FLT_MAX)*/
134 if ( MMG3D_Set_dparameter(mmgMesh,mmgSol,MMG3D_DPARAM_hmax,40) != 1 )
135 exit(EXIT_FAILURE);
136
137 /* Minimal mesh size (default 0)*/
138 if ( MMG3D_Set_dparameter(mmgMesh,mmgSol,MMG3D_DPARAM_hmin,0.001) != 1 )
139 exit(EXIT_FAILURE);
140
141 /* Global hausdorff value (default value = 0.01) applied on the whole boundary */
142 if ( MMG3D_Set_dparameter(mmgMesh,mmgSol,MMG3D_DPARAM_hausd, 0.1) != 1 )
143 exit(EXIT_FAILURE);
144
145 /* Gradation control*/
146 if ( MMG3D_Set_dparameter(mmgMesh,mmgSol,MMG3D_DPARAM_hgrad, 2) != 1 )
147 exit(EXIT_FAILURE);
148
150 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
151
152 if ( ier == MMG5_STRONGFAILURE ) {
153 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
154 return(ier);
155 } else if ( ier == MMG5_LOWFAILURE )
156 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
157
158 /* (Not mandatory) Automatically save the mesh */
159 MMG3D_saveMesh(mmgMesh,outname1);
160
161 if ( MMG3D_saveSol(mmgMesh,mmgSol,outname1) != 1 )
162 exit(EXIT_FAILURE);
163
164
166 /* We add different local hausdorff numbers on boundary componants (this
167 local values are used instead of the global hausdorff number) */
168
169 /* verbosity (default value = 4)*/
170 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_verbose, 4) != 1 )
171 exit(EXIT_FAILURE);
172
173 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_mem, 1000) != 1 )
174 exit(EXIT_FAILURE);
175 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_debug, 0) != 1 )
176 exit(EXIT_FAILURE);
177
178
180 /* use 2 local hausdorff numbers on ref 36 (hausd = 0.01) and 38 (hausd = 1) */
181 if ( MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_numberOfLocalParam,2) != 1 )
182 exit(EXIT_FAILURE);
183
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 ( MMG3D_Set_localParameter(mmgMesh,mmgSol,MMG5_Triangle,36,0.00001,40.,0.01) != 1 )
197 exit(EXIT_FAILURE);
198 if ( MMG3D_Set_localParameter(mmgMesh,mmgSol,MMG5_Triangle,38,0.00001,40.,1) != 1 )
199 exit(EXIT_FAILURE);
200
202 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
203
204 if ( ier == MMG5_STRONGFAILURE ) {
205 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
206 return(ier);
207 } else if ( ier == MMG5_LOWFAILURE )
208 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
209
213 /* New metric to see the effect of the local hausdorff number on triangles
214 of ref 38: constant and of size 10 */
215 for ( k=1; k<=mmgSol->np; k++ ) {
216 if ( MMG3D_Set_scalarSol(mmgSol,10,k) != 1 ) exit(EXIT_FAILURE);
217 }
218
219 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
220
221 if ( ier == MMG5_STRONGFAILURE ) {
222 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
223 return(ier);
224 } else if ( ier == MMG5_LOWFAILURE )
225 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
226
227
228 /* 7) Automatically save the mesh */
229 if ( MMG3D_saveMesh(mmgMesh,outname2) != 1 )
230 exit(EXIT_FAILURE);
231
232 /* 8) Automatically save the solution */
233 if ( MMG3D_saveSol(mmgMesh,mmgSol,outname2) != 1 )
234 exit(EXIT_FAILURE);
235
236
237 /* 9) free the MMG3D5 structures */
239 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
241
242 free(inname);
243 inname = NULL;
244
245 free(outname1);
246 outname1 = NULL;
247
248 free(outname2);
249 outname2 = NULL;
250
251 return(ier);
252}
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Set_dparameter(MMG5_pMesh mesh, MMG5_pSol sol, int dparam, double val)
set a real-valued parameter of the remesher
int MMG3D_Set_localParameter(MMG5_pMesh mesh, MMG5_pSol sol, int typ, MMG5_int ref, double hmin, double hmax, double hausd)
set a local parameter
int MMG3D_Set_scalarSol(MMG5_pSol met, double s, MMG5_int pos)
Set a single element of a scalar solution structure.
int MMG3D_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
Check if the number of given entities match with mesh and sol size.
int MMG3D_Free_all(const int starter,...)
Deallocations before return.
int MMG3D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
set an integer parameter of the remesher
int ier
program main
Example for using mmglib (basic use)
Definition: main.F90:6
int MMG3D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
Definition: inout_3d.c:1273
int MMG3D_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution).
Definition: inout_3d.c:2143
int MMG3D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_3d.c:1049
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write isotropic or anisotropic metric.
Definition: inout_3d.c:2314
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg3d.c:975
@ MMG3D_DPARAM_hmin
Definition: libmmg3d.h:171
@ MMG3D_IPARAM_debug
Definition: libmmg3d.h:146
@ MMG3D_IPARAM_numberOfLocalParam
Definition: libmmg3d.h:161
@ MMG3D_DPARAM_hausd
Definition: libmmg3d.h:174
@ MMG3D_DPARAM_hgrad
Definition: libmmg3d.h:175
@ MMG3D_DPARAM_hmax
Definition: libmmg3d.h:172
@ MMG3D_IPARAM_verbose
Definition: libmmg3d.h:144
@ MMG3D_IPARAM_mem
Definition: libmmg3d.h:145
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:102
#define MMG5_ARG_end
Definition: libmmgtypes.h:179
#define MMG5_STRONGFAILURE
Definition: libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition: libmmgtypes.h:57
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
@ MMG5_Triangle
Definition: libmmgtypes.h:232
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613
MMG5_int np
Definition: libmmgtypes.h:674