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}
101
103 int split,MMG5_int rin,MMG5_int rex){
104 MMG5_pMat mat;
105 int k;
106
107 (void)sol;
108
109 if ( !mesh->info.nmat ) {
110 fprintf(stderr,"\n ## Error: %s: You must set the number of material",__func__);
111 fprintf(stderr," with the MMG2D_Set_iparameters function before setting");
112 fprintf(stderr," values in multi material structure. \n");
113 return 0;
114 }
115 if ( mesh->info.nmati >= mesh->info.nmat ) {
116 fprintf(stderr,"\n ## Error: %s: unable to set a new material.\n",
117 __func__);
118 fprintf(stderr," max number of materials: %d\n",mesh->info.nmat);
119 return 0;
120 }
121 if ( ref < 0 ) {
122 fprintf(stderr,"\n ## Error: %s: negative references are not allowed.\n",
123 __func__);
124 return 0;
125 }
126
127 for (k=0; k<mesh->info.nmati; k++) {
128 mat = &mesh->info.mat[k];
129
130 if ( mat->ref == ref ) {
131 mat->dospl = split;
132 if ( split ) {
133 mat->rin = rin;
134 mat->rex = rex;
135 }
136 else {
137 mat->rin = mat->ref;
138 mat->rex = mat->ref;
139 }
140 if ( (mesh->info.imprim > 5) || mesh->info.ddebug ) {
141 fprintf(stderr,"\n ## Warning: %s: new materials (interior, exterior)",
142 __func__);
143 fprintf(stderr," for material of ref %" MMG5_PRId "\n",ref);
144 }
145 return 1;
146 }
147 }
148
149 if ( ( split != MMG5_MMAT_Split ) && ( split != MMG5_MMAT_NoSplit ) ) {
150 fprintf(stderr,"\n ## Error: %s: unexpected value for the 'split' argument."
151 " You must use the MMG5_MMAT_Split or MMG5_MMAT_NpSplit keywords \n",
152 __func__);
153 return 0;
154 }
155
156 mesh->info.mat[mesh->info.nmati].ref = ref;
157 mesh->info.mat[mesh->info.nmati].dospl = split;
158 mesh->info.mat[mesh->info.nmati].rin = rin;
159 mesh->info.mat[mesh->info.nmati].rex = rex;
160
161 mesh->info.nmati++;
162
163 /* Invert the table if all materials have been set */
164 if( mesh->info.nmati == mesh->info.nmat )
165 if( !MMG5_MultiMat_init(mesh) ) {
166 fprintf(stderr,"\n ## Error: %s: unable to create lookup table for multiple materials.\n",
167 __func__);
168 return 0;
169 }
170
171 return 1;
172}
173
175
176 (void)sol;
177
178 if ( !mesh->info.nbr ) {
179 fprintf(stderr,"\n ## Error: %s: You must set the number of"
180 " level-set based references",__func__);
181 fprintf(stderr," with the MMG2D_Set_iparameters function before setting");
182 fprintf(stderr," based references values. \n");
183 return 0;
184 }
185 if ( mesh->info.nbri >= mesh->info.nbr ) {
186 fprintf(stderr,"\n ## Error: %s: unable to set a new level-set"
187 " based reference.\n",__func__);
188 fprintf(stderr," max number of level-set based references: %d\n",mesh->info.nbr);
189 return 0;
190 }
191 if ( br < 0 ) {
192 fprintf(stderr,"\n ## Error: %s: negative references are not allowed.\n",
193 __func__);
194 return 0;
195 }
196
197 mesh->info.br[mesh->info.nbri] = br;
198 mesh->info.nbri++;
199
200 return 1;
201}
202
203
210void MMG5_mmgUsage(char *prog) {
211 fprintf(stdout,"\nUsage: %s [-v [n]] [opts..] filein [fileout]\n",prog);
212
213 fprintf(stdout,"\n** Generic options\n");
214 fprintf(stdout,"-h Print this message\n");
215 fprintf(stdout,"-v [n] Tune level of verbosity, [-1..10]\n");
216 fprintf(stdout,"-m [n] Set maximal memory size to n Mbytes\n");
217 fprintf(stdout,"-d Turn on debug mode\n");
218 fprintf(stdout,"-val Print the default parameters values\n");
219 fprintf(stdout,"-default Save a local parameters file for default parameters"
220 " values\n");
221
222 fprintf(stdout,"\n** File specifications\n");
223 fprintf(stdout,"-in file input triangulation\n");
224 fprintf(stdout,"-out file output triangulation\n");
225 fprintf(stdout,"-sol file load solution or metric file\n");
226 fprintf(stdout,"-met file load metric file\n");
227
228 fprintf(stdout,"\n** Mode specifications (mesh adaptation by default)\n");
229 fprintf(stdout,"-ls val create mesh of isovalue val (0 if no argument provided)\n");
230 fprintf(stdout,"-lssurf val split mesh boundaries on isovalue val (0 if no argument provided)\n");
231
232}
233
240 fprintf(stdout,"\n** Parameters\n");
241 fprintf(stdout,"-A enable anisotropy (without metric file).\n");
242 fprintf(stdout,"-ar val angle detection\n");
243 fprintf(stdout,"-nr no angle detection\n");
244 fprintf(stdout,"-hausd val control Hausdorff distance\n");
245 fprintf(stdout,"-hgrad val control gradation\n");
246 fprintf(stdout,"-hmax val maximal mesh size\n");
247 fprintf(stdout,"-hmin val minimal mesh size\n");
248 fprintf(stdout,"-hsiz val constant mesh size\n");
249 fprintf(stdout,"-rmc [val] enable the removal of componants whose volume fraction is less than\n"
250 " val (1e-5 if not given) of the mesh volume (ls mode).\n");
251}
252
259
260 fprintf(stdout,"-noinsert no point insertion/deletion \n");
261 fprintf(stdout,"-nomove no point relocation\n");
262 fprintf(stdout,"-noswap no edge or face flipping\n");
263 fprintf(stdout,"-nreg normal regul.\n");
264 fprintf(stdout,"-xreg vertex regul.\n");
265 fprintf(stdout,"-nsd val save the subdomain number val (0==all subdomain)\n");
266 fprintf(stdout,"-optim mesh optimization\n");
267
268}
269
275void MMG5_lagUsage(void) {
276
277#ifdef USE_ELAS
278 fprintf(stdout,"-lag [n] lagrangian mesh displacement according to mode [0/1/2]\n");
279 fprintf(stdout," 0: displacement\n");
280 fprintf(stdout," 1: displacement + remeshing (swap and move)\n");
281 fprintf(stdout," 2: displacement + remeshing (split, collapse,"
282 " swap and move)\n");
283#endif
284}
285
291void MMG5_2d3dUsage(void) {
292
293 fprintf(stdout,"-opnbdy preserve input triangles at the interface of"
294 " two domains of the same reference.\n");
295}
296
303
304 fprintf(stdout,"\n** Parameters for advanced users\n");
305 fprintf(stdout,"-nosizreq disable setting of required edge sizes over required vertices.\n");
306 fprintf(stdout,"-hgradreq val control gradation from required entities toward others\n");
307
308}
309
317static inline
319 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
320 if ( MG_REQ & mesh->point[pa->a].tag ) {
321 mesh->point[pa->a].tag &= ~MG_REQ;
322 }
323 if ( MG_REQ & mesh->point[pa->b].tag ) {
324 mesh->point[pa->b].tag &= ~MG_REQ;
325 }
326 if ( MG_CRN & mesh->point[pa->a].tag ) {
327 mesh->point[pa->a].tag &= ~MG_CRN;
328 }
329 if ( MG_CRN & mesh->point[pa->b].tag ) {
330 mesh->point[pa->b].tag &= ~MG_CRN;
331 }
332}
333
344static inline
346 int8_t to_remove;
347
348 if ( !pa->a ) {
349 to_remove = 1;
350 }
351 else {
352 int8_t not_ridge = !(pa->tag & MG_GEO);
353 to_remove = (MMG5_abs(pa->ref) == mesh->info.isoref) && not_ridge;
354 }
355
356 return to_remove;
357}
358
366 MMG5_int k,nref;
367
368 nref = 0;
369
371 if ( mesh->edge ) {
372 MMG5_int na = mesh->na;
373
374 k = 1;
375 do {
376
377 MMG5_pEdge pa = &mesh->edge[k];
378 if ( !pa->a ) {
379 continue;
380 }
381
382 if ( MMG5_abs(pa->ref) == mesh->info.isoref ) {
383 /* Current tria will be suppressed */
384 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
386
387 /* Do not delete ridge */
388 if ( !(pa->tag & MG_GEO) ) {
389 /* search last non isosurf tria to fill empty position */
390 MMG5_pEdge pa1 = &mesh->edge[mesh->na];
391 assert( pa1 );
392
393 int8_t to_remove = MMG5_should_edge_be_removed(mesh,pa1);
394
395 while ( to_remove && (k < mesh->na) ) {
396 if ( pa1->a ) {
397 /* Remove MG_REQ and MG_CRN tags on ISO edges extremities */
399 }
400 --mesh->na;
401 pa1 = &mesh->edge[mesh->na];
402 to_remove = MMG5_should_edge_be_removed(mesh,pa1);
403 }
404 if ( pa != pa1 ) {
405 /* We don't find any edge to keep after index k */
406 memcpy(pa,pa1,sizeof(MMG5_Edge));
407 --mesh->na;
408 }
409 }
410 }
411
412 /* Initially negative refs were used to mark isosurface: keep following
413 * piece of code for retrocompatibility */
414 if ( pa->ref < 0 ) {
415 pa->ref = -pa->ref;
416 ++nref;
417 }
418 }
419 while ( ++k < mesh->na );
420
421 /* At the end of the loop, either k==mesh->na, either k==mesh->na+1 (because
422 * edg at idx mesh->na was iso or unused and element mesh->na+1 has been
423 * copied into k) */
424 assert ( (k==mesh->na) || (k==mesh->na+1) );
425
426 /* Check if last edge is iso */
427 MMG5_pEdge pa = &mesh->edge[mesh->na];
428 if ( (!pa->a) || (MMG5_abs(pa->a) == mesh->info.isoref) ) {
429 --mesh->na;
430 }
431
432 if ( mesh->info.imprim > 4 ) {
433 fprintf(stdout," Deleted iso edges: %" MMG5_PRId "\n",na-mesh->na);
434 }
435
436 if( !mesh->na ) {
438 }
439 else if ( mesh->na < na ) {
440 MMG5_ADD_MEM(mesh,(mesh->na-na)*sizeof(MMG5_Edge),"edges",
441 fprintf(stderr," Exit program.\n");
442 return 0);
444 "edges",return 0);
445 }
446 }
447
448 return 1;
449}
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
#define MMG5_MMAT_Split
Definition: libmmgtypes.h:205
#define MMG5_MMAT_NoSplit
Definition: libmmgtypes.h:197
void MMG5_advancedUsage(void)
Definition: libtools.c:302
void MMG5_mmgUsage(char *prog)
Definition: libtools.c:210
void MMG5_paramUsage1(void)
Definition: libtools.c:239
void MMG5_2d3dUsage(void)
Definition: libtools.c:291
void MMG5_mmgDefaultValues(MMG5_pMesh mesh)
Definition: libtools.c:70
void MMG5_lagUsage(void)
Definition: libtools.c:275
static void MMG5_Clean_isoTags(MMG5_pMesh mesh, MMG5_pEdge pa)
Definition: libtools.c:318
int MMG5_Set_lsBaseReference(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int br)
Definition: libtools.c:174
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:345
void MMG5_paramUsage2(void)
Definition: libtools.c:258
int MMG5_Set_multiMat(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int ref, int split, MMG5_int rin, MMG5_int rex)
Definition: libtools.c:102
int MMG5_Clean_isoEdges(MMG5_pMesh mesh)
Definition: libtools.c:365
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 a MMG mesh.
Definition: libmmgtypes.h:305
MMG5_int b
Definition: libmmgtypes.h:306
MMG5_int ref
Definition: libmmgtypes.h:307
int16_t tag
Definition: libmmgtypes.h:310
MMG5_int a
Definition: libmmgtypes.h:306
int8_t ddebug
Definition: libmmgtypes.h:532
MMG5_int * br
Definition: libmmgtypes.h:520
double hmin
Definition: libmmgtypes.h:518
MMG5_pMat mat
Definition: libmmgtypes.h:554
double hgrad
Definition: libmmgtypes.h:518
MMG5_int isoref
Definition: libmmgtypes.h:521
double hmax
Definition: libmmgtypes.h:518
double dhd
Definition: libmmgtypes.h:518
double hgradreq
Definition: libmmgtypes.h:518
double hausd
Definition: libmmgtypes.h:518
To store user-defined references in the mesh (useful in LS mode)
Definition: libmmgtypes.h:495
MMG5_int ref
Definition: libmmgtypes.h:497
int8_t dospl
Definition: libmmgtypes.h:496
MMG5_int rex
Definition: libmmgtypes.h:497
MMG5_int rin
Definition: libmmgtypes.h:497
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_pPoint point
Definition: libmmgtypes.h:641
size_t memMax
Definition: libmmgtypes.h:606
MMG5_pEdge edge
Definition: libmmgtypes.h:649
MMG5_int na
Definition: libmmgtypes.h:612
int16_t tag
Definition: libmmgtypes.h:284