Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
libtools.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/CNRS/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
35#include "mmgcommon_private.h"
36
43void MMG5_version(MMG5_pMesh mesh,char *dim) {
44
45 if ( mesh->info.imprim >= 0 ) {
46#ifndef MMG_COMPARABLE_OUTPUT
47 fprintf(stdout,"\n %s\n MODULE MMG%s: %s (%s)\n %s\n",
48 MG_STR,dim,MMG_VERSION_RELEASE,MMG_RELEASE_DATE,MG_STR);
49#else
50 fprintf(stdout,"\n %s\n MODULE MMG%s\n %s\n",
51 MG_STR,dim,MG_STR);
52#endif
53
54#if !defined _WIN32 && !defined MMG_COMPARABLE_OUTPUT
55 fprintf(stdout," git branch: %s\n",MMG_GIT_BRANCH);
56 fprintf(stdout," git commit: %s\n",MMG_GIT_COMMIT);
57 fprintf(stdout," git date: %s\n\n",MMG_GIT_DATE);
58#endif
59 }
60
61}
62
71
72 fprintf(stdout,"\nDefault parameters values:\n");
73
74 fprintf(stdout,"\n** Generic options :\n");
75 fprintf(stdout,"verbosity (-v) : %d\n",
77 fprintf(stdout,"maximal memory size (-m) : %zu MB\n",
79
80
81 fprintf(stdout,"\n** Parameters\n");
82 fprintf(stdout,"angle detection (-ar) : %lf\n",
83 180/M_PI*acos(mesh->info.dhd) );
84 fprintf(stdout,"minimal mesh size (-hmin) : %lf\n"
85 "If not yet computed: 0.001 of "
86 "the mesh bounding box if no metric is provided, 0.1 times the "
87 "minimum of the metric sizes otherwise.\n",mesh->info.hmin);
88 fprintf(stdout,"maximal mesh size (-hmax) : %lf\n"
89 " If not yet computed: size of "
90 "the mesh bounding box without metric, 10 times the maximum of the "
91 "metric sizes otherwise.\n",mesh->info.hmax);
92 fprintf(stdout,"Hausdorff distance (-hausd) : %lf\n",
93 mesh->info.hausd);
94
95 fprintf(stdout,"gradation control (-hgrad) : %lf\n",
96 (mesh->info.hgrad < 0) ? mesh->info.hgrad : exp(mesh->info.hgrad) );
97
98 fprintf(stdout,"gradation control for required entities (-hgradreq) : %lf\n",
99 (mesh->info.hgradreq < 0) ? mesh->info.hgradreq : exp(mesh->info.hgradreq) );
100 fprintf(stdout,"coordinate regularization parameter (-xreg) : %lf\n",
101 mesh->info.lxreg);
102}
103
105 int split,MMG5_int rin,MMG5_int rex){
106 MMG5_pMat mat;
107 int k;
108
109 (void)sol;
110
111 if ( !mesh->info.nmat ) {
112 fprintf(stderr,"\n ## Error: %s: You must set the number of material",__func__);
113 fprintf(stderr," with the MMG2D_Set_iparameters function before setting");
114 fprintf(stderr," values in multi material structure. \n");
115 return 0;
116 }
117 if ( mesh->info.nmati >= mesh->info.nmat ) {
118 fprintf(stderr,"\n ## Error: %s: unable to set a new material.\n",
119 __func__);
120 fprintf(stderr," max number of materials: %d\n",mesh->info.nmat);
121 return 0;
122 }
123 if ( ref < 0 ) {
124 fprintf(stderr,"\n ## Error: %s: negative references are not allowed.\n",
125 __func__);
126 return 0;
127 }
128
129 for (k=0; k<mesh->info.nmati; k++) {
130 mat = &mesh->info.mat[k];
131
132 if ( mat->ref == ref ) {
133 mat->dospl = split;
134 if ( split ) {
135 mat->rin = rin;
136 mat->rex = rex;
137 }
138 else {
139 mat->rin = mat->ref;
140 mat->rex = mat->ref;
141 }
142 if ( (mesh->info.imprim > 5) || mesh->info.ddebug ) {
143 fprintf(stderr,"\n ## Warning: %s: new materials (interior, exterior)",
144 __func__);
145 fprintf(stderr," for material of ref %" MMG5_PRId "\n",ref);
146 }
147 return 1;
148 }
149 }
150
151 if ( ( split != MMG5_MMAT_Split ) && ( split != MMG5_MMAT_NoSplit ) ) {
152 fprintf(stderr,"\n ## Error: %s: unexpected value for the 'split' argument."
153 " You must use the MMG5_MMAT_Split or MMG5_MMAT_NpSplit keywords \n",
154 __func__);
155 return 0;
156 }
157
158 mesh->info.mat[mesh->info.nmati].ref = ref;
159 mesh->info.mat[mesh->info.nmati].dospl = split;
160 mesh->info.mat[mesh->info.nmati].rin = rin;
161 mesh->info.mat[mesh->info.nmati].rex = rex;
162
163 mesh->info.nmati++;
164
165 /* Invert the table if all materials have been set */
166 if( mesh->info.nmati == mesh->info.nmat )
167 if( !MMG5_MultiMat_init(mesh) ) {
168 fprintf(stderr,"\n ## Error: %s: unable to create lookup table for multiple materials.\n",
169 __func__);
170 return 0;
171 }
172
173 return 1;
174}
175
177
178 (void)sol;
179
180 if ( !mesh->info.nbr ) {
181 fprintf(stderr,"\n ## Error: %s: You must set the number of"
182 " level-set based references",__func__);
183 fprintf(stderr," with the MMG2D_Set_iparameters function before setting");
184 fprintf(stderr," based references values. \n");
185 return 0;
186 }
187 if ( mesh->info.nbri >= mesh->info.nbr ) {
188 fprintf(stderr,"\n ## Error: %s: unable to set a new level-set"
189 " based reference.\n",__func__);
190 fprintf(stderr," max number of level-set based references: %d\n",mesh->info.nbr);
191 return 0;
192 }
193 if ( br < 0 ) {
194 fprintf(stderr,"\n ## Error: %s: negative references are not allowed.\n",
195 __func__);
196 return 0;
197 }
198
199 mesh->info.br[mesh->info.nbri] = br;
200 mesh->info.nbri++;
201
202 return 1;
203}
204
205
212void MMG5_mmgUsage(char *prog) {
213 fprintf(stdout,"\nUsage: %s [-v [n]] [opts..] filein [fileout]\n",prog);
214
215 fprintf(stdout,"\n** Generic options\n");
216 fprintf(stdout,"-h Print this message\n");
217 fprintf(stdout,"-v [n] Tune level of verbosity, [-1..10]\n");
218 fprintf(stdout,"-m [n] Set maximal memory size to n Mbytes\n");
219 fprintf(stdout,"-d Turn on debug mode\n");
220 fprintf(stdout,"-val Print the default parameters values\n");
221 fprintf(stdout,"-default Save a local parameters file for default parameters"
222 " values\n");
223
224 fprintf(stdout,"\n** File specifications\n");
225 fprintf(stdout,"-in file input triangulation\n");
226 fprintf(stdout,"-out file output triangulation\n");
227 fprintf(stdout,"-sol file load solution or metric file\n");
228 fprintf(stdout,"-met file load metric file\n");
229 fprintf(stdout,"-f file load parameter file\n");
230
231 fprintf(stdout,"\n** Mode specifications (mesh adaptation by default)\n");
232 fprintf(stdout,"-ls val create mesh of isovalue val (0 if no argument provided)\n");
233 fprintf(stdout,"-lssurf val split mesh boundaries on isovalue val (0 if no argument provided)\n");
234
235}
236
243 fprintf(stdout,"\n** Parameters\n");
244 fprintf(stdout,"-A enable anisotropy (without metric file).\n");
245 fprintf(stdout,"-ar val angle detection\n");
246 fprintf(stdout,"-nr no angle detection\n");
247 fprintf(stdout,"-hausd val control Hausdorff distance\n");
248 fprintf(stdout,"-hgrad val control gradation\n");
249 fprintf(stdout,"-hmax val maximal mesh size\n");
250 fprintf(stdout,"-hmin val minimal mesh size\n");
251 fprintf(stdout,"-hsiz val constant mesh size\n");
252 fprintf(stdout,"-rmc [val] enable the removal of componants whose volume fraction is less than\n"
253 " val (1e-5 if not given) of the mesh volume (ls mode).\n");
254}
255
262
263 fprintf(stdout,"-noinsert no point insertion/deletion \n");
264 fprintf(stdout,"-nomove no point relocation\n");
265 fprintf(stdout,"-noswap no edge or face flipping\n");
266 fprintf(stdout,"-nreg normal regul.\n");
267 fprintf(stdout,"-xreg vertex regul.\n");
268 fprintf(stdout,"-nsd val save the subdomain number val (0==all subdomain)\n");
269 fprintf(stdout,"-optim mesh optimization\n");
270
271}
272
278void MMG5_lagUsage(void) {
279
280#ifdef USE_ELAS
281 fprintf(stdout,"-lag [n] lagrangian mesh displacement according to mode [0/1/2]\n");
282 fprintf(stdout," 0: displacement\n");
283 fprintf(stdout," 1: displacement + remeshing (swap and move)\n");
284 fprintf(stdout," 2: displacement + remeshing (split, collapse,"
285 " swap and move)\n");
286#endif
287}
288
294void MMG5_2d3dUsage(void) {
295
296 fprintf(stdout,"-opnbdy preserve input triangles at the interface of"
297 " two domains of the same reference.\n");
298}
299
306
307 fprintf(stdout,"\n** Parameters for advanced users\n");
308 fprintf(stdout,"-nosizreq disable setting of required edge sizes over required vertices.\n");
309 fprintf(stdout,"-hgradreq val control gradation from required entities toward others\n");
310
311}
312
320static inline
322 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
323 if ( MG_REQ & mesh->point[pa->a].tag ) {
324 mesh->point[pa->a].tag &= ~MG_REQ;
325 }
326 if ( MG_REQ & mesh->point[pa->b].tag ) {
327 mesh->point[pa->b].tag &= ~MG_REQ;
328 }
329 if ( MG_CRN & mesh->point[pa->a].tag ) {
330 mesh->point[pa->a].tag &= ~MG_CRN;
331 }
332 if ( MG_CRN & mesh->point[pa->b].tag ) {
333 mesh->point[pa->b].tag &= ~MG_CRN;
334 }
335}
336
347static inline
349 int8_t to_remove;
350
351 if ( !pa->a ) {
352 to_remove = 1;
353 }
354 else {
355 int8_t not_ridge = !(pa->tag & MG_GEO);
356 to_remove = (MMG5_abs(pa->ref) == mesh->info.isoref) && not_ridge;
357 }
358
359 return to_remove;
360}
361
369 MMG5_int k,nref;
370
371 nref = 0;
372
374 if ( mesh->edge ) {
375 MMG5_int na = mesh->na;
376
377 k = 1;
378 do {
379
380 MMG5_pEdge pa = &mesh->edge[k];
381 if ( !pa->a ) {
382 continue;
383 }
384
385 if ( MMG5_abs(pa->ref) == mesh->info.isoref ) {
386 /* Current tria will be suppressed */
387 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
389
390 /* Do not delete ridge */
391 if ( !(pa->tag & MG_GEO) ) {
392 /* search last non isosurf tria to fill empty position */
393 MMG5_pEdge pa1 = &mesh->edge[mesh->na];
394 assert( pa1 );
395
396 int8_t to_remove = MMG5_should_edge_be_removed(mesh,pa1);
397
398 while ( to_remove && (k < mesh->na) ) {
399 if ( pa1->a ) {
400 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
402 }
403 --mesh->na;
404 pa1 = &mesh->edge[mesh->na];
405 to_remove = MMG5_should_edge_be_removed(mesh,pa1);
406 }
407 if ( pa != pa1 ) {
408 /* We don't find any edge to keep after index k */
409 memcpy(pa,pa1,sizeof(MMG5_Edge));
410 --mesh->na;
411 }
412 }
413 }
414
415 /* Initially negative refs were used to mark isosurface: keep following
416 * piece of code for retrocompatibility */
417 if ( pa->ref < 0 ) {
418 pa->ref = -pa->ref;
419 ++nref;
420 }
421 }
422 while ( ++k < mesh->na );
423
424 /* At the end of the loop, either k==mesh->na, either k==mesh->na+1 (because
425 * edg at idx mesh->na was iso or unused and element mesh->na+1 has been
426 * copied into k) */
427 assert ( (k==mesh->na) || (k==mesh->na+1) );
428
429 /* Check if last edge is iso */
430 MMG5_pEdge pa = &mesh->edge[mesh->na];
431 if ( (!pa->a) || (MMG5_abs(pa->a) == mesh->info.isoref) ) {
432 --mesh->na;
433 }
434
435 if ( mesh->info.imprim > 4 ) {
436 fprintf(stdout," Deleted iso edges: %" MMG5_PRId "\n",na-mesh->na);
437 }
438
439 if( !mesh->na ) {
441 }
442 else if ( mesh->na < na ) {
443 MMG5_ADD_MEM(mesh,(mesh->na-na)*sizeof(MMG5_Edge),"edges",
444 fprintf(stderr," Exit program.\n");
445 return 0);
447 "edges",return 0);
448 }
449 }
450
451 return 1;
452}
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
#define MMG5_MMAT_Split
Definition: libmmgtypes.h:211
#define MMG5_MMAT_NoSplit
Definition: libmmgtypes.h:203
void MMG5_advancedUsage(void)
Definition: libtools.c:305
void MMG5_mmgUsage(char *prog)
Definition: libtools.c:212
void MMG5_paramUsage1(void)
Definition: libtools.c:242
void MMG5_2d3dUsage(void)
Definition: libtools.c:294
void MMG5_mmgDefaultValues(MMG5_pMesh mesh)
Definition: libtools.c:70
void MMG5_lagUsage(void)
Definition: libtools.c:278
static void MMG5_Clean_isoTags(MMG5_pMesh mesh, MMG5_pEdge pa)
Definition: libtools.c:321
int MMG5_Set_lsBaseReference(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int br)
Definition: libtools.c:176
void MMG5_version(MMG5_pMesh mesh, char *dim)
Functions needed by libraries API.
Definition: libtools.c:43
static int8_t MMG5_should_edge_be_removed(MMG5_pMesh mesh, MMG5_pEdge pa)
Definition: libtools.c:348
void MMG5_paramUsage2(void)
Definition: libtools.c:261
int MMG5_Set_multiMat(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int ref, int split, MMG5_int rin, MMG5_int rex)
Definition: libtools.c:104
int MMG5_Clean_isoEdges(MMG5_pMesh mesh)
Definition: libtools.c:368
int MMG5_MultiMat_init(MMG5_pMesh mesh)
Definition: mmg2.c:326
#define MG_REQ
#define MG_GEO
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG5_MILLION
#define MG_CRN
#define MG_STR
#define MMG5_DEL_MEM(mesh, ptr)
#define MMG5_SAFE_RECALLOC(ptr, prevSize, newSize, type, message, law)
Structure to store edges of am MMG mesh.
Definition: libmmgtypes.h:311
MMG5_int b
Definition: libmmgtypes.h:312
uint16_t tag
Definition: libmmgtypes.h:316
MMG5_int ref
Definition: libmmgtypes.h:313
MMG5_int a
Definition: libmmgtypes.h:312
int8_t ddebug
Definition: libmmgtypes.h:539
MMG5_int * br
Definition: libmmgtypes.h:527
double hmin
Definition: libmmgtypes.h:525
MMG5_pMat mat
Definition: libmmgtypes.h:562
double hgrad
Definition: libmmgtypes.h:525
double lxreg
Definition: libmmgtypes.h:526
MMG5_int isoref
Definition: libmmgtypes.h:528
double hmax
Definition: libmmgtypes.h:525
double dhd
Definition: libmmgtypes.h:525
double hgradreq
Definition: libmmgtypes.h:525
double hausd
Definition: libmmgtypes.h:525
To store user-defined references in the mesh (useful in LS mode)
Definition: libmmgtypes.h:502
MMG5_int ref
Definition: libmmgtypes.h:504
int8_t dospl
Definition: libmmgtypes.h:503
MMG5_int rex
Definition: libmmgtypes.h:504
MMG5_int rin
Definition: libmmgtypes.h:504
MMG mesh structure.
Definition: libmmgtypes.h:613
MMG5_Info info
Definition: libmmgtypes.h:659
MMG5_pPoint point
Definition: libmmgtypes.h:649
size_t memMax
Definition: libmmgtypes.h:614
MMG5_pEdge edge
Definition: libmmgtypes.h:657
MMG5_int na
Definition: libmmgtypes.h:620
uint16_t tag
Definition: libmmgtypes.h:290