Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
libmmg2d.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
24#include "libmmg2d.h"
25#include "libmmg2d_private.h"
27#include "mmgexterns_private.h"
28
33#define MMG2D_RETURN_AND_PACK(mesh,met,sol,val)do \
34 { \
35 if ( !MMG2D_pack(mesh,met,sol) ) { \
36 mesh->npi = mesh->np; \
37 mesh->nti = mesh->nt; \
38 mesh->nai = mesh->na; \
39 mesh->nei = mesh->ne; \
40 mesh->xt = 0; \
41 if ( met ) { met->npi = met->np; } \
42 if ( sol ) { sol->npi = sol->np; } \
43 return MMG5_LOWFAILURE; \
44 } \
45 _LIBMMG5_RETURN(mesh,met,sol,val); \
46 }while(0)
47
53 MMG5_chkmsh = MMG5_mmg2dChkmsh;
54 MMG5_grad2met_ani = MMG2D_grad2met_ani;
55 MMG5_grad2metreq_ani = MMG2D_grad2metreq_ani;
56 MMG5_solTruncature_ani = MMG5_2dSolTruncature_ani;
57 MMG5_indPt = MMG2D_indPt;
58 MMG5_indElt = MMG2D_indElt;
59
60 return;
61}
62
64{
65 MMG5_pSol sol=NULL; // unused
66 mytime ctim[TIMEMAX];
67 char stim[32];
68
69 assert ( mesh );
70 assert ( met );
71 assert ( mesh->point );
72 assert ( mesh->tria );
73
74 MMG5_version(mesh,"2D");
75
76 /*uncomment to callback*/
77 //MMG2D_callbackinsert = titi;
78
79 /* interrupts */
80 signal(SIGABRT,MMG2D_excfun);
81 signal(SIGFPE,MMG2D_excfun);
82 signal(SIGILL,MMG2D_excfun);
83 signal(SIGSEGV,MMG2D_excfun);
84 signal(SIGTERM,MMG2D_excfun);
85 signal(SIGINT,MMG2D_excfun);
86
87 tminit(ctim,TIMEMAX);
88 chrono(ON,&(ctim[0]));
89
90 /* Check options */
91 if ( !mesh->nt ) {
92 fprintf(stdout,"\n ## ERROR: NO TRIANGLES IN THE MESH. \n");
93 fprintf(stdout," To generate a mesh from boundaries call the"
94 " MMG2D_mmg2dmesh function\n.");
96 }
97 else if ( mesh->info.iso || mesh->info.isosurf ) {
98 fprintf(stdout,"\n ## ERROR: LEVEL-SET DISCRETISATION UNAVAILABLE"
99 " (MMG2D_IPARAM_iso or MMG2D_IPARAM_isosurf ):\n"
100 " YOU MUST CALL THE MMG2D_mmg2dls FUNCTION TO USE THIS"
101 " OPTION.\n");
103 }
104 else if ( mesh->info.lag >= 0 ) {
105 fprintf(stdout,"\n ## ERROR: LAGRANGIAN MODE UNAVAILABLE (MMG2D_IPARAM_lag):\n"
106 " YOU MUST CALL THE MMG2D_mmg2dmov FUNCTION TO MOVE A"
107 " RIGIDBODY.\n");
109 }
110
111 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MMG2DLIB: INPUT DATA\n");
112
113 /* Check input */
114 chrono(ON,&(ctim[1]));
115
116 if ( met->np && ( met->np != mesh->np ) ) {
117 fprintf(stdout,"\n ## WARNING: WRONG SOLUTION NUMBER : %" MMG5_PRId " != %" MMG5_PRId "\n",met->np,mesh->np);
119 }
120 else if ( met->size!=1 && met->size!=3 ) {
121 fprintf(stderr,"\n ## ERROR: WRONG DATA TYPE.\n");
123 }
124
125 /* specific meshing */
126 if ( met->np ) {
127 if ( mesh->info.optim ) {
128 printf("\n ## ERROR: MISMATCH OPTIONS: OPTIM OPTION CAN NOT BE USED"
129 " WITH AN INPUT METRIC.\n");
131 }
132
133 if ( mesh->info.hsiz>0. ) {
134 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ OPTION CAN NOT BE USED"
135 " WITH AN INPUT METRIC.\n");
137 }
138 }
139
140 if ( mesh->info.optim && mesh->info.hsiz>0. ) {
141 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ AND OPTIM OPTIONS CAN NOT BE USED"
142 " TOGETHER.\n");
144 }
145
146 chrono(OFF,&(ctim[1]));
147 printim(ctim[1].gdif,stim);
148
149 if ( mesh->info.imprim > 0 )
150 fprintf(stdout," -- INPUT DATA COMPLETED. %s\n",stim);
151
152 /* Set function pointers */
153 MMG2D_setfunc(mesh,met);
155
156 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug ) {
157 fprintf(stdout," MAXIMUM NUMBER OF POINTS (NPMAX) : %8" MMG5_PRId "\n",mesh->npmax);
158 fprintf(stdout," MAXIMUM NUMBER OF TRIANGLES (NTMAX) : %8" MMG5_PRId "\n",mesh->ntmax);
159 }
160
161 /* Data analysis */
162 chrono(ON,&ctim[2]);
163 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- PHASE 1 : DATA ANALYSIS\n");
164
165 /* Keep only one domain if asked */
167
168 /* reset fem value to user setting (needed for multiple library call) */
170
171 /* reset metRidTyp value to 0 (needed for multiple library call because it is
172 * used to mark if input edge have been stored into triangles) */
173 mesh->info.metRidTyp = 0;
174
175 /* Scale input mesh */
177
178 /* Specific meshing */
179 if ( mesh->info.optim ) {
180 if ( !MMG2D_doSol(mesh,met) ) {
183 }
184 }
185
186 if ( mesh->info.hsiz > 0. ) {
187 if ( !MMG2D_Set_constantSize(mesh,met) ) {
190 }
191 }
192
193 /* Print initial quality history */
194 if ( mesh->info.imprim > 0 || mesh->info.imprim < -1 ) {
195 if ( !MMG2D_outqua(mesh,met) ) {
198 }
199 }
200
201 /* Mesh analysis */
202 if (! MMG2D_analys(mesh) ) {
205 }
206
207 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,0) ) _LIBMMG5_RETURN(mesh,met,sol,MMG5_STRONGFAILURE);
208
209 if ( mesh->info.imprim > 1 && met->m && met->np ) MMG2D_prilen(mesh,met);
210
211 chrono(OFF,&(ctim[2]));
212 printim(ctim[2].gdif,stim);
213 if ( mesh->info.imprim > 0 )
214 fprintf(stdout," -- PHASE 1 COMPLETED. %s\n",stim);
215
216 /* remeshing */
217 chrono(ON,&ctim[3]);
218
219 if ( mesh->info.imprim > 0 )
220 fprintf(stdout,"\n -- PHASE 2 : %s MESHING\n",met->size < 3 ? "ISOTROPIC" : "ANISOTROPIC");
221
222 /* Mesh improvement */
223 if ( !MMG2D_mmg2d1n(mesh,met) ) {
226 }
227
228 chrono(OFF,&(ctim[3]));
229 printim(ctim[3].gdif,stim);
230 if ( mesh->info.imprim > 0 ) {
231 fprintf(stdout," -- PHASE 2 COMPLETED. %s\n",stim);
232 }
233
234 /* Print output quality history */
235 if ( !MMG2D_outqua(mesh,met) ) {
238 }
239
240 /* Print edge length histories */
241 if ( (abs(mesh->info.imprim) > 4) && met->m && met->np ) {
242 MMG2D_prilen(mesh,met);
243 }
244
245 chrono(ON,&(ctim[1]));
246 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MESH PACKED UP\n");
247
248 /* Unscale mesh */
251
252 chrono(OFF,&(ctim[1]));
253
254 chrono(OFF,&ctim[0]);
255 printim(ctim[0].gdif,stim);
256 if ( mesh->info.imprim >= 0 ) {
257 fprintf(stdout,"\n MMG2DLIB: ELAPSED TIME %s\n",stim);
258 fprintf(stdout,"\n %s\n END OF MODULE MMG2D\n %s\n\n",MG_STR,MG_STR);
259 }
261
262}
263
274static inline
276 MMG5_int k;
277
279 if ( !mesh->tria ) {
280 /* If we call the library more than one time and if we free the triangles
281 * using the MMG2D_Free_triangles function we need to reallocate it */
282 MMG5_ADD_MEM(mesh,(mesh->ntmax+1)*sizeof(MMG5_Tria),
283 "initial triangles",return 0);
285 mesh->nenil = mesh->nt + 1;
286 for ( k=mesh->nenil; k<mesh->ntmax-1; k++) {
287 mesh->tria[k].v[2] = k+1;
288 }
289 }
290 if ( mesh->na && !mesh->edge ) {
291 /* If we call the library more than one time and if we free the triangles
292 * using the MMG2D_Free_triangles function we need to reallocate it */
293 MMG5_ADD_MEM(mesh,(mesh->namax+1)*sizeof(MMG5_Edge),
294 "initial edges",return 0);
296 if ( mesh->na < mesh->namax ) {
297 mesh->nanil = mesh->na + 1;
298 }
299 else
300 mesh->nanil = 0;
301 }
302
303 return 1;
304}
305
306
308 MMG5_pSol sol=NULL; // unused
309 mytime ctim[TIMEMAX];
310 char stim[32];
311
312 assert ( mesh );
313 assert ( met );
314 assert ( mesh->point );
315
316 MMG5_version(mesh,"2D");
317
318 /*uncomment for callback*/
319 //MMG2D_callbackinsert = titi;
320
321 /* interrupts */
322 signal(SIGABRT,MMG2D_excfun);
323 signal(SIGFPE,MMG2D_excfun);
324 signal(SIGILL,MMG2D_excfun);
325 signal(SIGSEGV,MMG2D_excfun);
326 signal(SIGTERM,MMG2D_excfun);
327 signal(SIGINT,MMG2D_excfun);
328
329 tminit(ctim,TIMEMAX);
330 chrono(ON,&(ctim[0]));
331
332 /* Check options */
333 if ( mesh->nt ) {
334 fprintf(stdout,"\n ## ERROR: YOUR MESH CONTAINS ALREADY TRIANGLES.\n"
335 " THE MESH GENERATION OPTION IS UNAVAILABLE.\n");
337 }
338
339 else if ( mesh->info.iso || mesh->info.isosurf ) {
340 fprintf(stdout,"\n ## ERROR: LEVEL-SET DISCRETISATION UNAVAILABLE"
341 " (MMG2D_IPARAM_iso || MMG2D_IPARAM_isosurf ):\n"
342 " YOU MUST CALL THE MMG2D_MMG2DLS FUNCTION TO USE THIS OPTION.\n");
344 }
345
346 else if ( mesh->info.lag >= 0 ) {
347 fprintf(stdout,"\n ## ERROR: LAGRANGIAN MODE UNAVAILABLE (MMG2D_IPARAM_lag):\n"
348 " YOU MUST CALL THE MMG2D_MMG2DMOV FUNCTION TO MOVE A RIGIDBODY.\n");
350 }
351 /* specific meshing */
352 if ( met->np ) {
353 if ( mesh->info.optim ) {
354 printf("\n ## ERROR: MISMATCH OPTIONS: OPTIM OPTION CAN NOT BE USED"
355 " WITH AN INPUT METRIC.\n");
357 }
358
359 if ( mesh->info.hsiz>0. ) {
360 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ OPTION CAN NOT BE USED"
361 " WITH AN INPUT METRIC.\n");
363 }
364 }
365
366 if ( mesh->info.optim && mesh->info.hsiz>0. ) {
367 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ AND OPTIM OPTIONS CAN NOT BE USED"
368 " TOGETHER.\n");
370 }
371
372 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MMG2DMESH: INPUT DATA\n");
373
374 /* Check input */
375 chrono(ON,&(ctim[1]));
376
377 if ( met->np && (met->np != mesh->np) ) {
378 fprintf(stdout,"\n ## WARNING: WRONG SOLUTION NUMBER : %" MMG5_PRId " != %" MMG5_PRId "\n",met->np,mesh->np);
380 } else if ( met->size!=1 && met->size!=3 ) {
381 fprintf(stderr,"\n ## ERROR: WRONG DATA TYPE.\n");
383 }
384
385 chrono(OFF,&(ctim[1]));
386 printim(ctim[1].gdif,stim);
387 if ( mesh->info.imprim > 0 )
388 fprintf(stdout," -- INPUT DATA COMPLETED. %s\n",stim);
389
390 /* Create function pointers */
391 MMG2D_setfunc(mesh,met);
393
394 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug ) {
395 fprintf(stdout," MAXIMUM NUMBER OF POINTS (NPMAX) : %8" MMG5_PRId "\n",mesh->npmax);
396 fprintf(stdout," MAXIMUM NUMBER OF TRIANGLES (NTMAX) : %8" MMG5_PRId "\n",mesh->ntmax);
397 }
398
399 /* analysis */
400 chrono(ON,&ctim[2]);
401
402 if ( !MMG2D_restart(mesh) ) {
404 }
405
406 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- PHASE 1 : MESH GENERATION\n");
407
408 /* reset fem value to user setting (needed for multiple library call) */
410
411 /* reset metRidTyp value to 0 (needed for multiple library call because it is
412 * used to mark if input edge have been stored into triangles) */
413 mesh->info.metRidTyp = 0;
414
415 /* scaling mesh */
417
418 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,0) ) _LIBMMG5_RETURN(mesh,met,sol,MMG5_STRONGFAILURE);
419
420 /* Memory alloc */
421 MMG5_ADD_MEM(mesh,(3*mesh->ntmax+5)*sizeof(MMG5_int),"adjacency table",
422 printf(" Exit program.\n");
423 return MMG5_STRONGFAILURE);
424 MMG5_SAFE_CALLOC(mesh->adja,3*mesh->ntmax+5,MMG5_int,return MMG5_STRONGFAILURE);
425
426 /* Delaunay triangulation of the set of points contained in the mesh,
427 * enforcing the edges of the mesh */
428 if ( !MMG2D_mmg2d2(mesh,met) ) {
431 }
432
433 chrono(OFF,&(ctim[2]));
434 printim(ctim[2].gdif,stim);
435 if ( mesh->info.imprim > 0 )
436 fprintf(stdout," -- PHASE 1 COMPLETED. %s\n",stim);
437
438 /* remeshing */
439 chrono(ON,&ctim[3]);
440 if ( mesh->info.imprim > 0 ) {
441 fprintf(stdout,"\n -- PHASE 2 : ANALYSIS\n");
442 }
443
444 /* specific meshing */
445 if ( mesh->info.optim ) {
446 if ( !MMG2D_doSol(mesh,met) ) {
447 if ( !MMG5_unscaleMesh(mesh,met,NULL) )
450 }
451 } else if (mesh->info.hsiz > 0.) {
452 if ( !MMG2D_Set_constantSize(mesh,met) ) {
455 }
456 } else {
457 /* Set default hmin and hmax values */
459 if ( !MMG5_unscaleMesh(mesh,met,NULL) )
462 }
463 }
464
465 /* Mesh analysis */
466 if (! MMG2D_analys(mesh) ) {
467 if ( !MMG5_unscaleMesh(mesh,met,NULL) )
470 }
471 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,1) ) _LIBMMG5_RETURN(mesh,met,sol,MMG5_STRONGFAILURE);
472
473 chrono(OFF,&(ctim[3]));
474 printim(ctim[3].gdif,stim);
475 if ( mesh->info.imprim > 0 )
476 fprintf(stdout," -- PHASE 2 COMPLETED. %s\n",stim);
477
478 /* Mesh improvement - call new version of mmg2d1 */
479 chrono(ON,&(ctim[4]));
480 if ( mesh->info.imprim > 0 )
481 fprintf(stdout,"\n -- PHASE 3 : MESH IMPROVEMENT (%s)\n",
482 met->size < 3 ? "ISOTROPIC" : "ANISOTROPIC");
483
484 if ( !MMG2D_mmg2d1n(mesh,met) ) {
487 }
488
489 chrono(OFF,&(ctim[4]));
490 printim(ctim[4].gdif,stim);
491 if ( mesh->info.imprim > 0 ) {
492 fprintf(stdout," -- PHASE 3 COMPLETED. %s\n",stim);
493 }
494
495 /* Print quality histories */
496 if ( !MMG2D_outqua(mesh,met) ) {
498 }
499
500 /* Print edge length histories */
501 if ( abs(mesh->info.imprim) > 4 && met->m && met->np ) {
502 MMG2D_prilen(mesh,met);
503 }
504
505 /* Unscale mesh */
507
508 chrono(ON,&(ctim[1]));
509 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MESH PACKED UP\n");
510
512
513 chrono(OFF,&(ctim[1]));
514
515 chrono(OFF,&ctim[0]);
516 printim(ctim[0].gdif,stim);
517 if ( mesh->info.imprim >= 0 ) {
518 fprintf(stdout,"\n MMG2DMESH: ELAPSED TIME %s\n",stim);
519 fprintf(stdout,"\n %s\n END OF MODULE MMG2D\n %s\n\n",MG_STR,MG_STR);
520 }
521
523
524}
525
527{
528 MMG5_pSol met=NULL;
529 mytime ctim[TIMEMAX];
530 char stim[32];
531 int8_t mettofree = 0;
532
533 assert ( mesh );
534 assert ( sol );
535 assert ( mesh->point );
536 assert ( mesh->tria );
537
538 MMG5_version(mesh,"2D");
539
540 if ( (!mesh->info.iso) && (!mesh->info.isosurf) ) {
541 fprintf(stdout,"\n ## WARNING: ISO MODE NOT PROVIDED: ENABLING ISOVALUE DISCRETIZATION MODE (-ls) \n");
542 mesh->info.iso = 1;
543 }
544
545 if ( !umet ) {
546 /* User doesn't provide the metric, allocate our own one */
548 mettofree = 1;
549 }
550 else {
551 met = umet;
552 }
553
554 /*uncomment for callback*/
555 //MMG2D_callbackinsert = titi;
556
557 /* interrupts */
558 signal(SIGABRT,MMG2D_excfun);
559 signal(SIGFPE,MMG2D_excfun);
560 signal(SIGILL,MMG2D_excfun);
561 signal(SIGSEGV,MMG2D_excfun);
562 signal(SIGTERM,MMG2D_excfun);
563 signal(SIGINT,MMG2D_excfun);
564
565 tminit(ctim,TIMEMAX);
566 chrono(ON,&(ctim[0]));
567
568 /* Check options */
569 if ( mesh->info.lag >= 0 ) {
570 fprintf(stdout,"\n ## ERROR: LAGRANGIAN MODE UNAVAILABLE (MMG2D_IPARAM_lag):\n"
571 " YOU MUST CALL THE MMG2D_mmg2dmov FUNCTION TO MOVE A RIGIDBODY.\n");
573 }
574
575 /* Check input */
576 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MMG2DLS: INPUT DATA\n");
577 chrono(ON,&(ctim[1]));
578
579 sol->ver = mesh->ver;
580
581 if ( !mesh->nt ) {
582 fprintf(stdout,"\n ## ERROR: NO TRIANGLES IN THE MESH \n");
583 if ( mettofree ) { MMG5_SAFE_FREE (met); }
585 }
586 else if ( !sol->m ) {
587 fprintf(stdout,"\n ## ERROR: A VALID SOLUTION FILE IS NEEDED \n");
588 if ( mettofree ) { MMG5_SAFE_FREE (met); }
590 } else if ( sol->size != 1 ) {
591 fprintf(stdout,"\n ## ERROR: WRONG DATA TYPE.\n");
592 if ( mettofree ) { MMG5_SAFE_FREE (met); }
594 } else if ( sol->np && (sol->np != mesh->np) ) {
595 fprintf(stdout,"\n ## WARNING: WRONG SOLUTION NUMBER. IGNORED\n");
596 if ( mettofree ) { MMG5_SAFE_FREE (met); }
598 }
599
600 /* specific meshing */
601 if ( met && met->np ) {
602 if ( mesh->info.optim ) {
603 printf("\n ## ERROR: MISMATCH OPTIONS: OPTIM OPTION CAN NOT BE USED"
604 " WITH AN INPUT METRIC.\n");
605 if ( mettofree ) { MMG5_SAFE_FREE (met); }
607 }
608
609 if ( mesh->info.hsiz>0. ) {
610 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ OPTION CAN NOT BE USED"
611 " WITH AN INPUT METRIC.\n");
612 if ( mettofree ) { MMG5_SAFE_FREE (met); }
614 }
615 if ( met->np != mesh->np ) {
616 fprintf(stdout,"\n ## WARNING: WRONG METRIC NUMBER. IGNORED\n");
617 if ( mettofree ) { MMG5_SAFE_FREE (met); }
619 }
620 }
621
622 if ( mesh->info.optim && mesh->info.hsiz>0. ) {
623 printf("\n ## ERROR: MISMATCH OPTIONS: HSIZ AND OPTIM OPTIONS CAN NOT BE USED"
624 " TOGETHER.\n");
625 if ( mettofree ) { MMG5_SAFE_FREE (met); }
627 }
628
629 if ( mesh->nquad && mesh->quadra ) {
630 printf("\n ## ERROR: UNABLE TO HANDLE HYBRID MESHES IN ISOVALUE DISCRETIZATION MODE.\n");
631 if ( mettofree ) { MMG5_SAFE_FREE (met); }
633 }
634
635 chrono(OFF,&(ctim[1]));
636 printim(ctim[1].gdif,stim);
637 if ( mesh->info.imprim > 0 )
638 fprintf(stdout," -- INPUT DATA COMPLETED. %s\n",stim);
639
640 chrono(ON,&ctim[2]);
641
642 /* Set pointers */
643 MMG2D_setfunc(mesh,met);
645
646 if ( mesh->info.imprim > 0 )
647 fprintf(stdout,"\n -- PHASE 1 : ISOSURFACE DISCRETIZATION\n");
648
649 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug ) {
650 fprintf(stdout," MAXIMUM NUMBER OF POINTS (NPMAX) : %8"MMG5_PRId"\n",mesh->npmax);
651 fprintf(stdout," MAXIMUM NUMBER OF TRIANGLES (NTMAX) : %8"MMG5_PRId"\n",mesh->ntmax);
652 }
653
654 /* reset fem value to user setting (needed for multiple library call) */
656
657 /* reset metRidTyp value to 0 (needed for multiple library call because it is
658 * used to mark if input edge have been stored into triangles) */
659 mesh->info.metRidTyp = 0;
660
661 /* scaling mesh */
662 if ( !MMG5_scaleMesh(mesh,met,sol) ) {
663 if ( mettofree ) { MMG5_SAFE_FREE (met); }
665 }
666
667 if ( mesh->nt && !MMG2D_hashTria(mesh) ) {
668 if ( mettofree ) { MMG5_SAFE_FREE (met); }
670 }
671
672 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,0) ) {
673 if ( mettofree ) { MMG5_SAFE_FREE (met); }
675 }
676
677 /* Print initial quality */
678 if ( mesh->info.imprim > 0 || mesh->info.imprim < -1 ) {
679 if ( !MMG2D_outqua(mesh,met) ) {
680 if ( mettofree ) {
681 MMG5_DEL_MEM(mesh,met->m);
682 MMG5_SAFE_FREE (met);
683 }
684 if ( !MMG5_unscaleMesh(mesh,met,sol) ) {
686 }
688 }
689 }
690
691 /* Specific meshing: compute optim option here because after isovalue
692 * discretization mesh elements have too bad qualities */
693 if ( mesh->info.optim ) {
694 if ( !MMG2D_doSol(mesh,met) ) {
695 if ( mettofree ) {
696 MMG5_DEL_MEM(mesh,met->m);
697 MMG5_SAFE_FREE (met);
698 }
699
700 if ( !MMG5_unscaleMesh(mesh,met,NULL) ) {
703 }
704 }
705
706 /* Discretization of the mesh->info.ls isovalue of sol in the mesh */
707 if ( !MMG2D_mmg2d6(mesh,sol,met) ) {
708 if ( mettofree ) { MMG5_SAFE_FREE (met); }
709 if ( !MMG5_unscaleMesh(mesh,met,sol) ) {
711 }
713 }
714
715 chrono(OFF,&(ctim[2]));
716 printim(ctim[2].gdif,stim);
717 if ( mesh->info.imprim > 0 )
718 fprintf(stdout," -- PHASE 1 COMPLETED. %s\n",stim);
719
720 chrono(ON,&(ctim[3]));
721 if ( mesh->info.imprim > 0 ) {
722 fprintf(stdout,"\n -- PHASE 2 : ANALYSIS\n");
723 }
724
725 /* Specific meshing: compute hsiz on mesh after isovalue discretization */
726 if ( mesh->info.hsiz > 0. ) {
727 if ( !MMG2D_Set_constantSize(mesh,met) ) {
728 if ( mettofree ) {
729 MMG5_DEL_MEM(mesh,met->m);
730 MMG5_SAFE_FREE (met);
731 }
732 if ( !MMG5_unscaleMesh(mesh,met,sol) ) {
734 }
736 }
737 }
738
739 /* Mesh analysis */
740 if (! MMG2D_analys(mesh) ) {
741 if ( mettofree ) {
742 MMG5_DEL_MEM(mesh,met->m);
743 MMG5_SAFE_FREE (met);
744 }
745 if ( !MMG5_unscaleMesh(mesh,met,NULL) ) {
747 }
749 }
750 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,1) ) _LIBMMG5_RETURN(mesh,met,sol,MMG5_STRONGFAILURE);
751
752 chrono(OFF,&(ctim[3]));
753 printim(ctim[3].gdif,stim);
754 if ( mesh->info.imprim > 0 )
755 fprintf(stdout," -- PHASE 2 COMPLETED. %s\n",stim);
756
757 /* Mesh improvement - call new version of mmg2d1 */
758 chrono(ON,&ctim[4]);
759 if ( mesh->info.imprim > 0 ) {
760 fprintf(stdout,"\n -- PHASE 3 : MESH IMPROVEMENT\n");
761 }
762
763 if ( !MMG2D_mmg2d1n(mesh,met) ) {
764 if ( mettofree ) {
765 MMG5_DEL_MEM(mesh,met->m);
766 MMG5_SAFE_FREE (met);
767 }
770 }
771
772 /* End of mmg2dls */
773 chrono(OFF,&(ctim[4]));
774 printim(ctim[4].gdif,stim);
775 if ( mesh->info.imprim > 0 ) {
776 fprintf(stdout," -- PHASE 3 COMPLETED. %s\n",stim);
777 }
778
779 /* Print quality histories */
780 if ( !MMG2D_outqua(mesh,met) ) {
781 if ( mettofree ) {
782 MMG5_DEL_MEM(mesh,met->m);
783 MMG5_SAFE_FREE (met);
784 }
786 }
787
788 /* Unscale mesh */
789 if ( !MMG5_unscaleMesh(mesh,met,NULL) ) {
790 if ( mettofree ) {
791 MMG5_DEL_MEM(mesh,met->m);
792 MMG5_SAFE_FREE (met);
793 }
795 }
796
797 chrono(ON,&(ctim[1]));
798 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MESH PACKED UP\n");
799
800 /* Pack mesh */
801 if (!MMG2D_pack(mesh,sol,met) ) {
802 if ( mettofree ) { MMG5_SAFE_FREE (met); }
804 }
805
806 chrono(OFF,&(ctim[1]));
807
808 chrono(OFF,&ctim[0]);
809 printim(ctim[0].gdif,stim);
810 if ( mesh->info.imprim >= 0 ) {
811 fprintf(stdout,"\n MMG2DLS: ELAPSED TIME %s\n",stim);
812 fprintf(stdout,"\n %s\n END OF MODULE MMG2D\n %s\n\n",MG_STR,MG_STR);
813 }
814 if ( mettofree ) {
815 MMG5_DEL_MEM(mesh,met->m);
816 MMG5_SAFE_FREE (met);
817 }
819
820}
821
823 mytime ctim[TIMEMAX];
824 char stim[32];
825 int ier;
826 MMG5_int k,*invalidTris;
827
828 assert ( mesh );
829 assert ( disp );
830 assert ( met );
831 assert ( mesh->point );
832 assert ( mesh->tria );
833
834 MMG5_version(mesh,"2D");
835
836 /*uncomment for callback*/
837 //MMG2D_callbackinsert = titi;
838
839 /* interrupts */
840 signal(SIGABRT,MMG2D_excfun);
841 signal(SIGFPE,MMG2D_excfun);
842 signal(SIGILL,MMG2D_excfun);
843 signal(SIGSEGV,MMG2D_excfun);
844 signal(SIGTERM,MMG2D_excfun);
845 signal(SIGINT,MMG2D_excfun);
846
847 tminit(ctim,TIMEMAX);
848 chrono(ON,&(ctim[0]));
849
850 /* Check data compatibility */
851 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MMG2DMOV: INPUT DATA\n");
852 chrono(ON,&(ctim[1]));
853
854 disp->ver = mesh->ver;
855
856#ifndef USE_ELAS
857 fprintf(stderr,"\n ## ERROR: YOU NEED TO COMPILE WITH THE USE_ELAS"
858 " CMake's FLAG SET TO ON TO USE THE RIGIDBODY MOVEMENT LIBRARY.\n");
860#endif
861
862 if ( !mesh->nt ) {
863 fprintf(stdout,"\n ## ERROR: NO TRIANGLES IN THE MESH \n");
865 }
866 else if ( !disp->m ) {
867 fprintf(stdout,"\n ## ERROR: A VALID SOLUTION FILE IS NEEDED \n");
869 }
870 else if ( disp->size != 2 ) {
871 fprintf(stdout,"\n ## ERROR: LAGRANGIAN MOTION OPTION NEED A VECTOR DISPLACEMENT.\n");
873 }
874 else if ( disp->np && (disp->np != mesh->np) ) {
875 fprintf(stdout,"\n ## WARNING: WRONG SOLUTION NUMBER. IGNORED\n");
876 MMG5_DEL_MEM(mesh,disp->m);
877 disp->np = 0;
878 }
879
880 if ( mesh->info.optim ) {
881 printf("\n ## ERROR: OPTIM OPTION UNAVAILABLE IN LAGRANGIAN"
882 " MOVEMENT MODE.\n");
884 }
885 if ( mesh->info.hsiz>0. ) {
886 printf("\n ## ERROR: HSIZ OPTION UNAVAILABLE IN LAGRANGIAN"
887 " MOVEMENT MODE.\n");
889 }
890
891 if ( mesh->nquad && mesh->quadra ) {
892 printf("\n ## ERROR: UNABLE TO HANDLE HYBRID MESHES IN LAGRANGIAN MOVEMENT MODE.\n");
894 }
895
896
897 chrono(OFF,&(ctim[1]));
898 printim(ctim[1].gdif,stim);
899 if ( mesh->info.imprim > 0 )
900 fprintf(stdout," -- INPUT DATA COMPLETED. %s\n",stim);
901
902 /* Set pointers */
903 MMG2D_setfunc(mesh,met);
905
906 chrono(ON,&ctim[2]);
907
908 if ( mesh->info.imprim > 0 ) {
909 fprintf(stdout,"\n -- PHASE 1 : ANALYSIS\n");
910 }
911
912 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug ) {
913 fprintf(stdout," MAXIMUM NUMBER OF POINTS (NPMAX) : %8" MMG5_PRId "\n",mesh->npmax);
914 fprintf(stdout," MAXIMUM NUMBER OF TRIANGLES (NTMAX) : %8" MMG5_PRId "\n",mesh->ntmax);
915 }
916
917 /* Analysis */
918
919 /* reset fem value to user setting (needed for multiple library call) */
921
922 /* reset metRidTyp value to 0 (needed for multiple library call because it is
923 * used to mark if input edge have been stored into triangles) */
924 mesh->info.metRidTyp = 0;
925
926 /* scaling mesh */
927 if ( !MMG5_scaleMesh(mesh,NULL,disp) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_STRONGFAILURE);
928
930
931 /* Print initial quality */
932 if ( mesh->info.imprim > 0 || mesh->info.imprim < -1 ) {
933 if ( !MMG2D_outqua(mesh,met) ) {
934 if ( !MMG5_unscaleMesh(mesh,NULL,disp) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_STRONGFAILURE);
936 }
937 }
938
939 /* Mesh analysis */
940 if (! MMG2D_analys(mesh) )
942
943 if ( mesh->info.ddebug && !MMG5_chkmsh(mesh,1,1) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_STRONGFAILURE);
944
945 chrono(OFF,&(ctim[2]));
946 printim(ctim[2].gdif,stim);
947 if ( mesh->info.imprim > 0 )
948 fprintf(stdout," -- PHASE 1 COMPLETED. %s\n",stim);
949
950 /* Lagrangian motion */
951 chrono(ON,&(ctim[3]));
952 if ( mesh->info.imprim > 0 ) {
953 fprintf(stdout,"\n -- PHASE 2 : LAGRANGIAN MOTION\n");
954 }
955
956 /* Lagrangian mode */
957 invalidTris = NULL;
958 ier = MMG2D_mmg2d9(mesh,disp,met,&invalidTris);
959 if ( !ier ) {
960 disp->npi = disp->np;
962 }
963 else if ( ier < 0 ) {
964 printf("\n ## Warning: Unable to perform any movement "
965 "(%d intersecting triangles).\n",-ier);
966 if ( mesh->info.imprim > 1 ) {
967 printf(" List of invalid trias: ");
968 for ( k=0; k<-ier; ++k ) {
969 printf("%" MMG5_PRId " ",MMG2D_indElt(mesh,invalidTris[k]));
970 }
971 printf("\n\n");
972 }
973 MMG5_SAFE_FREE(invalidTris);
974 }
975
976 chrono(OFF,&(ctim[3]));
977 printim(ctim[3].gdif,stim);
978 if ( mesh->info.imprim > 0 ) {
979 fprintf(stdout," -- PHASE 2 COMPLETED. %s\n",stim);
980 }
981
982 /* End with a classical remeshing stage, provided mesh->info.lag > 1 */
983 if ( (ier > 0) && (mesh->info.lag >= 1) ) {
984 chrono(ON,&(ctim[4]));
985 if ( mesh->info.imprim > 0 ) {
986 fprintf(stdout,"\n -- PHASE 3 : MESH IMPROVEMENT\n");
987 }
988
989 if ( !MMG2D_mmg2d1n(mesh,met) ) {
990 if ( !MMG5_unscaleMesh(mesh,met,NULL) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_STRONGFAILURE);
992 }
993
994 chrono(OFF,&(ctim[4]));
995 printim(ctim[4].gdif,stim);
996 if ( mesh->info.imprim > 0 ) {
997 fprintf(stdout," -- PHASE 3 COMPLETED. %s\n",stim);
998 }
999 }
1000
1001 /* Print quality histories */
1002 if ( !MMG2D_outqua(mesh,met) ) {
1004 }
1005
1006 /* Unscale mesh */
1007 if ( !MMG5_unscaleMesh(mesh,met,NULL) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_STRONGFAILURE);
1008
1009 chrono(ON,&(ctim[1]));
1010 if ( mesh->info.imprim > 0 ) fprintf(stdout,"\n -- MESH PACKED UP\n");
1011
1012 /* Pack mesh */
1013 if (!MMG2D_pack(mesh,met,disp) ) _LIBMMG5_RETURN(mesh,met,disp,MMG5_LOWFAILURE);
1014
1015 chrono(OFF,&(ctim[1]));
1016
1017 chrono(OFF,&ctim[0]);
1018 printim(ctim[0].gdif,stim);
1019 if ( mesh->info.imprim >= 0 ) {
1020 fprintf(stdout,"\n MMG2DMOV: ELAPSED TIME %s\n",stim);
1021 fprintf(stdout,"\n %s\n END OF MODULE MMG2D\n %s\n\n",MG_STR,MG_STR);
1022 }
1023
1025}
int MMG5_Set_defaultTruncatureSizes(MMG5_pMesh mesh, int8_t sethmin, int8_t sethmax)
int ier
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
int MMG2D_analys(MMG5_pMesh mesh)
Definition: analys_2d.c:1010
int MMG2D_grad2metreq_ani(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pTria pt, MMG5_int npmaster, MMG5_int npslave)
Definition: anisosiz_2d.c:600
MMG5_int MMG2D_grad2met_ani(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pTria pt, MMG5_int np1, MMG5_int np2)
Definition: anisosiz_2d.c:537
int MMG5_mmg2dChkmsh(MMG5_pMesh mesh, int severe, MMG5_int base)
Definition: chkmsh_2d.c:36
void tminit(mytime *t, int maxtim)
Initialize mytime object.
Definition: chrono.c:120
void printim(double elps, char *stim)
Print real time.
Definition: chrono.c:160
void chrono(int cmode, mytime *ptt)
Function to measure time.
Definition: chrono.c:49
#define TIMEMAX
int MMG2D_hashTria(MMG5_pMesh mesh)
Definition: hash_2d.c:35
int MMG2D_pack(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_pSol met)
Definition: hash_2d.c:527
int MMG2D_prilen(MMG5_pMesh mesh, MMG5_pSol sol)
Definition: length_2d.c:125
int MMG2D_mmg2dlib(MMG5_pMesh mesh, MMG5_pSol met)
Definition: libmmg2d.c:63
#define MMG2D_RETURN_AND_PACK(mesh, met, sol, val)
Definition: libmmg2d.c:33
int MMG2D_mmg2dls(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_pSol umet)
Definition: libmmg2d.c:526
int MMG2D_mmg2dmesh(MMG5_pMesh mesh, MMG5_pSol met)
Definition: libmmg2d.c:307
static int MMG2D_restart(MMG5_pMesh mesh)
Definition: libmmg2d.c:275
void MMG2D_Set_commonFunc(void)
Definition: libmmg2d.c:52
int MMG2D_mmg2dmov(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol disp)
Definition: libmmg2d.c:822
API headers for the mmg2d library.
LIBMMG2D_EXPORT int(* MMG2D_doSol)(MMG5_pMesh mesh, MMG5_pSol met)
Definition: mmg2dexterns.c:9
LIBMMG2D_EXPORT int MMG2D_Set_constantSize(MMG5_pMesh mesh, MMG5_pSol met)
LIBMMG2D_EXPORT void MMG2D_setfunc(MMG5_pMesh mesh, MMG5_pSol met)
int MMG2D_mmg2d1n(MMG5_pMesh, MMG5_pSol)
Definition: mmg2d1.c:819
MMG5_int MMG2D_indPt(MMG5_pMesh mesh, MMG5_int kp)
Definition: tools_2d.c:70
static void MMG2D_excfun(int sigid)
int MMG2D_mmg2d9(MMG5_pMesh, MMG5_pSol, MMG5_pSol, MMG5_int **)
Definition: mmg2d9.c:459
int MMG2D_mmg2d2(MMG5_pMesh, MMG5_pSol)
Definition: mmg2d2.c:508
MMG5_int MMG2D_indElt(MMG5_pMesh mesh, MMG5_int kel)
Definition: tools_2d.c:46
int MMG2D_outqua(MMG5_pMesh, MMG5_pSol)
Definition: quality_2d.c:183
void MMG2D_keep_only1Subdomain(MMG5_pMesh mesh, int nsd)
Definition: tools_2d.c:92
int MMG2D_mmg2d6(MMG5_pMesh, MMG5_pSol, MMG5_pSol)
Definition: mmg2d6.c:204
LIBMMG_CORE_EXPORT int MMG5_unscaleMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol ls)
Definition: scalem.c:689
LIBMMG_CORE_EXPORT int MMG5_scaleMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol ls)
Definition: scalem.c:649
#define MMG5_STRONGFAILURE
Definition: libmmgtypes.h:59
#define MMG5_LOWFAILURE
Definition: libmmgtypes.h:51
#define MMG5_SUCCESS
Definition: libmmgtypes.h:43
void MMG5_version(MMG5_pMesh mesh, char *dim)
Functions needed by libraries API.
Definition: libtools.c:43
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define _LIBMMG5_RETURN(mesh, sol, met, val)
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MG_STR
int MMG5_2dSolTruncature_ani(MMG5_pMesh mesh, MMG5_pSol met)
Definition: scalem.c:365
#define MMG5_SAFE_FREE(ptr)
#define MMG5_DEL_MEM(mesh, ptr)
Structure to store edges of a MMG mesh.
Definition: libmmgtypes.h:305
int8_t iso
Definition: libmmgtypes.h:534
int8_t ddebug
Definition: libmmgtypes.h:532
double hsiz
Definition: libmmgtypes.h:518
int8_t isosurf
Definition: libmmgtypes.h:535
double hmin
Definition: libmmgtypes.h:518
int8_t setfem
Definition: libmmgtypes.h:536
uint8_t metRidTyp
Definition: libmmgtypes.h:547
double hmax
Definition: libmmgtypes.h:518
int8_t lag
Definition: libmmgtypes.h:540
MMG5_int nsd
Definition: libmmgtypes.h:522
uint8_t optim
Definition: libmmgtypes.h:546
int8_t fem
Definition: libmmgtypes.h:539
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_int ntmax
Definition: libmmgtypes.h:612
MMG5_pQuad quadra
Definition: libmmgtypes.h:648
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_pPoint point
Definition: libmmgtypes.h:641
MMG5_int * adja
Definition: libmmgtypes.h:624
MMG5_int nquad
Definition: libmmgtypes.h:613
MMG5_int npmax
Definition: libmmgtypes.h:612
MMG5_int nenil
Definition: libmmgtypes.h:622
MMG5_int namax
Definition: libmmgtypes.h:612
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
MMG5_pEdge edge
Definition: libmmgtypes.h:649
MMG5_int nanil
Definition: libmmgtypes.h:623
MMG5_int na
Definition: libmmgtypes.h:612
MMG5_int npi
Definition: libmmgtypes.h:667
double * m
Definition: libmmgtypes.h:671
MMG5_int np
Definition: libmmgtypes.h:665
MMG5_int v[3]
Definition: libmmgtypes.h:334
Chrono object.