Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
split_2d.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*/
34#include "libmmg2d_private.h"
36
37extern uint8_t ddb;
38
51MMG5_int MMG2D_chkspl(MMG5_pMesh mesh,MMG5_pSol met,MMG5_int k,int8_t i) {
52 MMG5_pTria pt,pt1,pt0;
53 MMG5_pPoint p1,p2,ppt;
54 double mid[2],o[2],no[2],calnew,caltmp,tp,to,t,calseuil;
55 MMG5_int ip,jel,*adja,npinit;
56 int it,maxit;
57 const double s = 0.5;
58 int8_t i1,i2,j,j1,j2,ier,isv;
59 assert ( met );
60
61 calseuil = 1e-4 / MMG2D_ALPHAD;
62 npinit = mesh->np;
63
64
65 pt = &mesh->tria[k];
66 pt0 = &mesh->tria[0];
67 i1 = MMG5_inxt2[i];
68 i2 = MMG5_iprv2[i];
69
70 p1 = &mesh->point[pt->v[i1]];
71 p2 = &mesh->point[pt->v[i2]];
72
73 adja = &mesh->adja[3*(k-1)+1];
74
75 jel = adja[i] / 3;
76 j = adja[i] % 3;
77 j1 = MMG5_inxt2[j];
78 j2 = MMG5_iprv2[j];
79
80 /* Midpoint of edge i */
81 mid[0] = s*(p1->c[0]+p2->c[0]);
82 mid[1] = s*(p1->c[1]+p2->c[1]);
83
84 /* If the splitted edge is not geometric, the new point is simply its midpoint */
85 if ( !MG_EDG(pt->tag[i]) ) {
86 ip = MMG2D_newPt(mesh,mid,0);
87 if ( !ip ) {
88 /* reallocation of point table */
90 printf(" ## Error: unable to allocate a new point.\n");
92 do {
94 } while ( mesh->np>npinit );return -1;,
95 mid,pt->tag[i]);
96
97 }
98 /* If there is a metric in the mesh, interpolate it at the new point */
99 if ( met->m )
100 MMG2D_intmet(mesh,met,k,i,ip,s);
101
102 ppt = &mesh->point[ip];
103 if ( pt->tag[i] ) ppt->tag = pt->tag[i];
104 if ( pt->edg[i] ) ppt->ref = pt->edg[i];
105
106 /* Check quality of the four new elements */
107 calnew = DBL_MAX;
108 memcpy(pt0,pt,sizeof(MMG5_Tria));
109 pt0->v[i2] = ip;
110
111 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
112 calnew = MG_MIN(calnew,caltmp);
113
114 pt0->v[i1] = ip; pt0->v[i2] = pt->v[i2];
115 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
116 calnew = MG_MIN(calnew,caltmp);
117
118 if ( jel ) {
119 pt1 = &mesh->tria[jel];
120 memcpy(pt0,pt1,sizeof(MMG5_Tria));
121 pt0->v[j1] = ip;
122 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
123 calnew = MG_MIN(calnew,caltmp);
124
125 pt0->v[j1] = pt1->v[j1] ; pt0->v[j2] = ip;
126 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
127 calnew = MG_MIN(calnew,caltmp);
128 }
129
130 /* Delete point and abort splitting if one of the created triangles
131 has very bad quality.
132 MMG5_EPSOK is not sufficient :
133 we were created very bad element and were not able to delete them */
134 if ( (calnew < calseuil) ) {
135 MMG2D_delPt(mesh,ip);
136 return 0;
137 }
138 }
139 /* Otherwise, the new point is inserted on the underlying curve to the edge;
140 a dichotomy is applied to find the largest distance to the edge that yields an admissible configuration */
141 else {
142 ier = MMG2D_bezierCurv(mesh,k,i,s,o,no);
143 if ( !ier ) return 0;
144
145 ip = MMG2D_newPt(mesh,o,pt->tag[i]);
146 if ( !ip ) {
147 /* reallocation of point table */
149 printf(" ## Error: unable to allocate a new point.\n");
151 do {
153 } while ( mesh->np>npinit ); return -1;,
154 o,pt->tag[i]);
155 }
156 if ( met->m )
157 MMG2D_intmet(mesh,met,k,i,ip,s);
158
159 ppt = &mesh->point[ip];
160 if ( pt->tag[i] ) ppt->tag = pt->tag[i];
161 if ( pt->edg[i] ) ppt->ref = pt->edg[i];
162
163 ppt->n[0] = no[0];
164 ppt->n[1] = no[1];
165
166 isv = 0;
167 it = 0;
168 maxit = 5;
169 tp = 1.0;
170 t = 1.0;
171 to = 0.0;
172
173 do {
174 ppt->c[0] = mid[0] + t*(o[0] - mid[0]);
175 ppt->c[1] = mid[1] + t*(o[1] - mid[1]);
176
177 /* Check quality of the four new elements */
178 calnew = DBL_MAX;
179 memcpy(pt0,pt,sizeof(MMG5_Tria));
180 pt0->v[i2] = ip;
181 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
182 calnew = MG_MIN(calnew,caltmp);
183
184 pt0->v[i1] = ip; pt0->v[i2] = pt->v[i2];
185 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
186 calnew = MG_MIN(calnew,caltmp);
187
188 if ( jel ) {
189 pt1 = &mesh->tria[jel];
190 memcpy(pt0,pt1,sizeof(MMG5_Tria));
191 pt0->v[j1] = ip;
192 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
193 calnew = MG_MIN(calnew,caltmp);
194
195 pt0->v[j1] = pt1->v[j1] ; pt0->v[j2] = ip;
196 caltmp = MMG2D_ALPHAD*MMG2D_caltri(mesh,met,pt0);
197 calnew = MG_MIN(calnew,caltmp);
198 }
199
200 ier = ( calnew > MMG5_EPSOK );
201 if ( ier ) {
202 isv = 1;
203 to = t;
204 if ( t == tp ) break;
205 }
206 else
207 tp = t;
208
209 /* If no admissible position has been found, do the last iteration with the midpoint m */
210 if ( (it == maxit-2) && !isv )
211 t = 0.0;
212 else
213 t = 0.5*(to+tp);
214 }
215 while ( ++it < maxit );
216
217 /* One satisfying position has been found: to */
218 if ( isv ) {
219 ppt->c[0] = mid[0] + to*(o[0] - mid[0]);
220 ppt->c[1] = mid[1] + to*(o[1] - mid[1]);
221 }
222 /* No satisfying position has been found */
223 else {
224 MMG2D_delPt(mesh,ip);
225 return 0;
226 }
227 }
228
229 return ip;
230}
231
244int MMG2D_split1b(MMG5_pMesh mesh,MMG5_int k,int8_t i,MMG5_int ip) {
245 MMG5_pTria pt,pt1;
246 MMG5_int *adja,iel,jel,kel,mel;
247 int8_t i1,i2,m,j,j1,j2;
248
249 iel = MMG2D_newElt(mesh);
250 if ( !iel ) {
252 printf(" ## Error: unable to allocate a new element.\n");
254 printf(" Exit program.\n");return 0);
255 }
256
257 pt = &mesh->tria[k];
258 pt->flag = 0;
259 pt->base = mesh->base;
260
261 i1 = MMG5_inxt2[i];
262 i2 = MMG5_iprv2[i];
263
264 adja = &mesh->adja[3*(k-1)+1];
265 jel = adja[i] / 3;
266 j = adja[i] % 3;
267
268 pt1 = &mesh->tria[iel];
269 memcpy(pt1,pt,sizeof(MMG5_Tria));
270 memcpy(&mesh->adja[3*(iel-1)+1],&mesh->adja[3*(k-1)+1],3*sizeof(MMG5_int));
271
272 /* Update both triangles */
273 pt->v[i2] = ip;
274 pt1->v[i1] = ip;
275
276 pt->tag[i1] = MG_NOTAG;
277 pt->edg[i1] = 0;
278
279 pt1->tag[i2] = MG_NOTAG;
280 pt1->edg[i2] = 0;
281
282 /* Update adjacencies */
283 mel = adja[i1] / 3;
284 m = adja[i1] % 3;
285 mesh->adja[3*(k-1)+1+i1] = 3*iel+i2;
286 mesh->adja[3*(iel-1)+1+i2] = 3*k+i1;
287 if ( mel )
288 mesh->adja[3*(mel-1)+1+m] = 3*iel+i1;
289
290 if ( jel ) {
291 kel = MMG2D_newElt(mesh);
292 if ( !kel ) {
294 printf(" ## Error: unable to allocate a new element.\n");
296 printf(" Exit program.\n");return 0);
297 }
298
299 pt = &mesh->tria[jel];
300 pt1 = &mesh->tria[kel];
301 j1 = MMG5_inxt2[j];
302 j2 = MMG5_iprv2[j];
303
304 pt->flag = 0;
305 pt->base = mesh->base;
306
307 memcpy(pt1,pt,sizeof(MMG5_Tria));
308 memcpy(&mesh->adja[3*(kel-1)+1],&mesh->adja[3*(jel-1)+1],3*sizeof(MMG5_int));
309
310 /* Update triangles */
311 pt->v[j1] = ip;
312 pt1->v[j2] = ip;
313 pt->tag[j2] = MG_NOTAG;
314 pt->edg[j2] = 0;
315 pt1->tag[j1] = MG_NOTAG;
316 pt1->edg[j1] = 0;
317
318 /* Update adjacencies */
319 adja = &mesh->adja[3*(jel-1)+1];
320 mel = adja[j2] / 3;
321 m = adja[j2] % 3;
322 mesh->adja[3*(jel-1)+1+j2] = 3*kel+j1;
323 mesh->adja[3*(kel-1)+1+j1] = 3*jel+j2;
324 if ( mel )
325 mesh->adja[3*(mel-1)+1+m] = 3*kel+j2;
326
327 mesh->adja[3*(iel-1)+1+i] = 3*kel+j;
328 mesh->adja[3*(kel-1)+1+j] = 3*iel+i;
329 }
330
331 return 1;
332}
333
345int MMG2D_split1_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
346 MMG5_pTria pt,pt0;
347 double cal;
348 uint8_t tau[3];
349
350 pt = &mesh->tria[k];
351 pt0 = &mesh->tria[0];
352 memcpy(pt0,pt,sizeof(MMG5_Tria));
353
354 /* Set permutation from the reference configuration (case 1: edge 0 is splitted) to the actual one */
355 tau[0] = 0; tau[1] = 1; tau[2] = 2;
356
357 switch ( pt->flag ) {
358 case 2:
359 tau[0] = 1; tau[1] = 2; tau[2] = 0;
360 break;
361
362 case 4:
363 tau[0] = 2; tau[1] = 0; tau[2] = 1;
364 break;
365 }
366
367 pt0->v[tau[2]] = vx[tau[0]];
368 cal = MMG2D_quickcal(mesh,pt0);
369 if ( cal < MMG5_EPSD ) return 0;
370
371 pt0->v[tau[2]] = pt->v[tau[2]];
372 pt0->v[tau[1]] = vx[tau[0]];
373 cal = MMG2D_quickcal(mesh,pt0);
374 if ( cal < MMG5_EPSD ) return 0;
375
376 return 1;
377}
378
390int MMG2D_split1(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
391 MMG5_pTria pt,pt1;
392 MMG5_pPoint p0;
393 MMG5_int iel;
394 uint8_t tau[3];
395
396 pt = &mesh->tria[k];
397
398 /* Set permutation from the reference configuration (case 1: edge 0 is splitted) to the actual one */
399 tau[0] = 0; tau[1] = 1; tau[2] = 2;
400
401 switch ( pt->flag ) {
402 case 2:
403 tau[0] = 1; tau[1] = 2; tau[2] = 0;
404 break;
405
406 case 4:
407 tau[0] = 2; tau[1] = 0; tau[2] = 1;
408 break;
409 }
410
411 pt->flag = 0;
412
413 /* Update of point references */
414 p0 = &mesh->point[vx[tau[0]]];
415
416 if ( pt->edg[tau[0]] > 0 )
417 p0->ref = pt->edg[tau[0]];
418
419 iel = MMG2D_newElt(mesh);
420 if ( !iel ) {
422 printf(" ## Error: unable to allocate a new element.\n");
424 printf(" Exit program.\n");return 0);
425 pt = &mesh->tria[k];
426 }
427 pt1 = &mesh->tria[iel];
428 memcpy(pt1,pt,sizeof(MMG5_Tria));
429
430 /* Generic formulation for the split of one edge */
431 /* Update of vertices */
432 pt->v[tau[2]] = vx[tau[0]];
433 pt1->v[tau[1]] = vx[tau[0]];
434
435 /* Update of edge references and tags*/
436 pt->tag[tau[1]] = MG_NOTAG;
437 pt->edg[tau[1]] = 0;
438
439 pt1->tag[tau[2]] = MG_NOTAG;
440 pt1->edg[tau[2]] = 0;
441
442 return 1;
443}
444
456int MMG2D_split2_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
457 MMG5_pTria pt,pt0;
458 double cal;
459 uint8_t tau[3];
460
461 pt = &mesh->tria[k];
462 pt0 = &mesh->tria[0];
463 memcpy(pt0,pt,sizeof(MMG5_Tria));
464
465 /* Set permutation from the reference configuration (case 6: edges 1,2 are splitted) to the actual one */
466 tau[0] = 0; tau[1] = 1; tau[2] = 2;
467
468 switch ( pt->flag ) {
469 case 5:
470 tau[0] = 1; tau[1] = 2; tau[2] = 0;
471 break;
472
473 case 3:
474 tau[0] = 2; tau[1] = 0; tau[2] = 1;
475 break;
476 }
477
478 pt0->v[tau[1]] = vx[tau[2]] ; pt0->v[tau[2]] = vx[tau[1]];
479 cal = MMG2D_quickcal(mesh,pt0);
480 if ( cal < MMG5_EPSD ) return 0;
481
482 pt0->v[tau[1]] = pt->v[tau[1]] ; pt0->v[tau[2]] = pt->v[tau[2]];
483 pt0->v[tau[0]] = vx[tau[2]];
484 cal = MMG2D_quickcal(mesh,pt0);
485 if ( cal < MMG5_EPSD ) return 0;
486
487 pt0->v[tau[0]] = vx[tau[1]] ; pt0->v[tau[1]] = vx[tau[2]];
488 cal = MMG2D_quickcal(mesh,pt0);
489 if ( cal < MMG5_EPSD ) return 0;
490
491 return 1;
492}
493
505int MMG2D_split2(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
506 MMG5_pTria pt,pt1,pt2;
507 MMG5_pPoint p1,p2;
508 MMG5_int iel,jel;
509 uint8_t tau[3];
510
511 pt = &mesh->tria[k];
512
513 /* Set permutation from the reference configuration (case 6: edges 1,2 are splitted) to the actual one */
514 tau[0] = 0; tau[1] = 1; tau[2] = 2;
515
516 switch ( pt->flag ) {
517 case 5:
518 tau[0] = 1; tau[1] = 2; tau[2] = 0;
519 break;
520
521 case 3:
522 tau[0] = 2; tau[1] = 0; tau[2] = 1;
523 break;
524 }
525
526 pt->flag = 0;
527
528 /* Update of point references */
529 p1 = &mesh->point[vx[tau[1]]];
530 p2 = &mesh->point[vx[tau[2]]];
531
532 if ( pt->edg[tau[1]] > 0 )
533 p1->ref = pt->edg[tau[1]];
534
535 if ( pt->edg[tau[2]] > 0 )
536 p2->ref = pt->edg[tau[2]];
537
538 iel = MMG2D_newElt(mesh);
539 if ( !iel ) {
541 printf(" ## Error: unable to allocate a new element.\n");
543 printf(" Exit program.\n");return 0);
544 pt = &mesh->tria[k];
545 }
546
547 jel = MMG2D_newElt(mesh);
548 if ( !jel ) {
550 printf(" ## Error: unable to allocate a new element.\n");
552 printf(" Exit program.\n");return 0);
553 pt = &mesh->tria[k];
554 }
555
556 pt1 = &mesh->tria[iel];
557 pt2 = &mesh->tria[jel];
558 memcpy(pt1,pt,sizeof(MMG5_Tria));
559 memcpy(pt2,pt,sizeof(MMG5_Tria));
560
561
562 /* Generic formulation for the split of two edges */
563 /* Update of vertices */
564 pt->v[tau[1]] = vx[tau[2]] ; pt->v[tau[2]] = vx[tau[1]];
565 pt1->v[tau[0]] = vx[tau[2]];
566 pt2->v[tau[0]] = vx[tau[1]]; pt2->v[tau[1]] = vx[tau[2]];
567
568 /* Update of edge references and tags*/
569 pt->tag[tau[0]] = MG_NOTAG;
570 pt->edg[tau[0]] = 0;
571
572 pt1->tag[tau[1]] = MG_NOTAG;
573 pt1->edg[tau[1]] = 0;
574
575 pt2->tag[tau[0]] = MG_NOTAG; pt2->tag[tau[2]] = MG_NOTAG;
576 pt2->edg[tau[0]] = MG_NOTAG; pt2->edg[tau[2]] = MG_NOTAG;
577
578 return 1;
579}
580
592int MMG2D_split3_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
593 MMG5_pTria pt,pt0;
594 double cal;
595
596 pt = &mesh->tria[k];
597 pt0 = &mesh->tria[0];
598 memcpy(pt0,pt,sizeof(MMG5_Tria));
599
600 pt0->v[1] = vx[2] ; pt0->v[2] = vx[1];
601 cal = MMG2D_quickcal(mesh,pt0);
602 if ( cal < MMG5_EPSD ) return 0;
603
604 pt0->v[0] = vx[2] ; pt0->v[1] = pt->v[1]; pt0->v[2] = vx[0];
605 cal = MMG2D_quickcal(mesh,pt0);
606 if ( cal < MMG5_EPSD ) return 0;
607
608 pt0->v[0] = vx[1] ; pt0->v[1] = vx[0]; pt0->v[2] = pt->v[2];
609 cal = MMG2D_quickcal(mesh,pt0);
610 if ( cal < MMG5_EPSD ) return 0;
611
612 pt0->v[1] = vx[2]; pt0->v[2] = vx[0];
613 cal = MMG2D_quickcal(mesh,pt0);
614 if ( cal < MMG5_EPSD ) return 0;
615
616 return 1;
617}
618
630int MMG2D_split3(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3]) {
631 MMG5_pTria pt,pt1,pt2,pt3;
632 MMG5_pPoint p0,p1,p2;
633 MMG5_int iel,jel,kel;
634
635 pt = &mesh->tria[k];
636 pt->flag = 0;
637
638 /* Update of point references */
639 p0 = &mesh->point[vx[0]];
640 p1 = &mesh->point[vx[1]];
641 p2 = &mesh->point[vx[2]];
642
643 if ( pt->edg[0] > 0 )
644 p0->ref = pt->edg[0];
645
646 if ( pt->edg[1] > 0 )
647 p1->ref = pt->edg[1];
648
649 if ( pt->edg[2] > 0 )
650 p2->ref = pt->edg[2];
651
652 iel = MMG2D_newElt(mesh);
653 if ( !iel ) {
655 printf(" ## Error: unable to allocate a new element.\n");
657 printf(" Exit program.\n");return 0);
658
659 pt = &mesh->tria[k];
660 }
661
662 jel = MMG2D_newElt(mesh);
663
664 if ( !jel ) {
666 printf(" ## Error: unable to allocate a new element.\n");
668 printf(" Exit program.\n");return 0);
669 pt = &mesh->tria[k];
670 }
671
672 kel = MMG2D_newElt(mesh);
673
674 if ( !kel ) {
676 printf(" ## Error: unable to allocate a new element.\n");
678 printf(" Exit program.\n");return 0);
679 pt = &mesh->tria[k];
680 }
681
682 pt1 = &mesh->tria[iel];
683 pt2 = &mesh->tria[jel];
684 pt3 = &mesh->tria[kel];
685 memcpy(pt1,pt,sizeof(MMG5_Tria));
686 memcpy(pt2,pt,sizeof(MMG5_Tria));
687 memcpy(pt3,pt,sizeof(MMG5_Tria));
688
689 /* Update of vertices */
690 pt->v[1] = vx[2] ; pt->v[2] = vx[1];
691 pt1->v[0] = vx[2] ; pt1->v[2] = vx[0];
692 pt2->v[0] = vx[1]; pt2->v[1] = vx[0];
693 pt3->v[0] = vx[1] ; pt3->v[1] = vx[2] ; pt3->v[2] = vx[0];
694
695 /* Update of tags and references */
696 pt->tag[0] = MG_NOTAG;
697 pt->edg[0] = 0;
698
699 pt1->tag[1] = MG_NOTAG;
700 pt1->edg[1] = 0;
701
702 pt2->tag[2] = MG_NOTAG;
703 pt2->edg[2] = 0;
704
705 pt3->tag[0] = pt3->tag[1] = pt3->tag[2] = MG_NOTAG;
706 pt3->edg[0] = pt3->edg[1] = pt3->edg[2] = 0;
707
708 return 1;
709}
710
721int MMG2D_splitbar(MMG5_pMesh mesh,MMG5_int k,MMG5_int ip) {
722 MMG5_pTria pt,pt0,pt1,pt2;
723 MMG5_pPoint p0,p1,p2,ppt;
724 MMG5_int *adja,iel1,iel2,jel0,jel2;
725 MMG5_int ip0,ip1,ip2;
726 int8_t j2,j0;
727 double cal,calseuil;
728
729 pt = &mesh->tria[k];
730 pt0 = &mesh->tria[0];
731 ppt = &mesh->point[ip];
732 ip0 = pt->v[0];
733 p0 = &mesh->point[ip0];
734 ip1 = pt->v[1];
735 p1 = &mesh->point[ip1];
736 ip2 = pt->v[2];
737 p2 = &mesh->point[ip2];
738
739 calseuil = MMG5_EPSOK ;
740
741 /* Check quality of the three new elements */
742 cal = MMG2D_quickarea(ppt->c,p1->c,p2->c);
743 if ( (cal < calseuil) ) {
744 return 0;
745 }
746
747 cal = MMG2D_quickarea(p0->c,ppt->c,p2->c);
748 if ( (cal < calseuil) ) {
749 return 0;
750 }
751 pt0->v[0] = ip0;
752 cal = MMG2D_quickarea(p0->c,p1->c,ppt->c);
753 if ( (cal < calseuil) ) {
754 return 0;
755 }
756
757 iel1 = MMG2D_newElt(mesh);
758 if ( !iel1 ) {
760 printf(" ## Error: unable to allocate a new element.\n");
762 printf(" Exit program.\n");return 0);
763 }
764 iel2 = MMG2D_newElt(mesh);
765 if ( !iel2 ) {
767 printf(" ## Error: unable to allocate a new element.\n");
769 printf(" Exit program.\n");return 0);
770 }
771
772 pt->flag = 0;
773 pt->base = mesh->base;
774
775 adja = &mesh->adja[3*(k-1)+1];
776 jel0 = adja[0] / 3;
777 j0 = adja[0] % 3;
778#ifndef NDEBUG
779 int8_t jel1 = adja[1] / 3;
780 int8_t j1 = adja[1] % 3;
781#endif
782 jel2 = adja[2] / 3;
783 j2 = adja[2] % 3;
784
785 pt1 = &mesh->tria[iel1];
786 memcpy(pt1,pt,sizeof(MMG5_Tria));
787 memcpy(&mesh->adja[3*(iel1-1)+1],&mesh->adja[3*(k-1)+1],3*sizeof(MMG5_int));
788 pt2 = &mesh->tria[iel2];
789 memcpy(pt2,pt,sizeof(MMG5_Tria));
790 memcpy(&mesh->adja[3*(iel2-1)+1],&mesh->adja[3*(k-1)+1],3*sizeof(MMG5_int));
791
792 /* Update the three triangles */
793 pt->v[1] = ip;
794 pt1->v[2] = ip;
795 pt2->v[0] = ip;
796
797 pt->tag[1] = MG_NOTAG;
798 pt->edg[1] = 0;
799
800 pt1->tag[2] = MG_NOTAG;
801 pt1->edg[2] = 0;
802
803 pt2->tag[0] = MG_NOTAG;
804 pt2->edg[0] = 0;
805
806 /* Update external adjacencies */
807#ifndef NDEBUG
808 assert(mesh->adja[3*(k-1)+1+1] == 3*jel1+j1);
809 if ( jel1 ) {
810 assert(mesh->adja[3*(jel1-1)+1+j1] == 3*k+1);
811 }
812#endif
813
814 mesh->adja[3*(iel1-1)+1+2] = 3*jel2+j2;
815 if ( jel2 )
816 mesh->adja[3*(jel2-1)+1+j2] = 3*iel1+2;
817
818 mesh->adja[3*(iel2-1)+1+0] = 3*jel0+j0;
819 if ( jel0 )
820 mesh->adja[3*(jel0-1)+1+j0] = 3*iel2+0;
821
822 /*update internal adjacencies*/
823 mesh->adja[3*(k-1)+1+0] = 3*iel2+1;
824 mesh->adja[3*(iel2-1)+1+1] = 3*k+0;
825
826 mesh->adja[3*(k-1)+1+2] = 3*iel1+1;
827 mesh->adja[3*(iel1-1)+1+1] = 3*k+2;
828
829 mesh->adja[3*(iel1-1)+1+0] = 3*iel2+2;
830 mesh->adja[3*(iel2-1)+1+2] = 3*iel1+0;
831
832 return 1;
833}
int ier
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
int MMG2D_bezierCurv(MMG5_pMesh mesh, MMG5_int k, int8_t i, double s, double *o, double *no)
Definition: bezier_2d.c:185
#define MMG5_EPSD
#define MMG2D_POINT_REALLOC(mesh, sol, ip, wantedGap, law, o, tag)
double MMG2D_quickcal(MMG5_pMesh, MMG5_pTria)
Definition: quality_2d.c:46
#define MMG2D_TRIA_REALLOC(mesh, jel, wantedGap, law)
void MMG2D_delPt(MMG5_pMesh mesh, MMG5_int ip)
Definition: zaldy_2d.c:57
MMG5_int MMG2D_newPt(MMG5_pMesh mesh, double c[2], int16_t tag)
Definition: zaldy_2d.c:38
#define MMG2D_ALPHAD
MMG5_int MMG2D_newElt(MMG5_pMesh mesh)
Definition: zaldy_2d.c:85
#define MMG5_EPSOK
double MMG2D_quickarea(double a[2], double b[2], double c[2])
Definition: tools.c:971
#define MMG5_INCREASE_MEM_MESSAGE()
#define MG_MIN(a, b)
#define MG_EDG(tag)
#define MG_NOTAG
static const uint8_t MMG5_iprv2[3]
static const uint8_t MMG5_inxt2[6]
int MMG2D_split1(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:390
int MMG2D_split1_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:345
int MMG2D_split2(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:505
int MMG2D_split3(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:630
uint8_t ddb
Definition: mmg3d1_delone.c:42
int MMG2D_split1b(MMG5_pMesh mesh, MMG5_int k, int8_t i, MMG5_int ip)
Definition: split_2d.c:244
MMG5_int MMG2D_chkspl(MMG5_pMesh mesh, MMG5_pSol met, MMG5_int k, int8_t i)
Definition: split_2d.c:51
int MMG2D_split2_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:456
int MMG2D_split3_sim(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int k, MMG5_int vx[3])
Definition: split_2d.c:592
int MMG2D_splitbar(MMG5_pMesh mesh, MMG5_int k, MMG5_int ip)
Definition: split_2d.c:721
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_pPoint point
Definition: libmmgtypes.h:641
MMG5_int * adja
Definition: libmmgtypes.h:624
double gap
Definition: libmmgtypes.h:608
MMG5_int base
Definition: libmmgtypes.h:616
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
Structure to store points of a MMG mesh.
Definition: libmmgtypes.h:270
double n[3]
Definition: libmmgtypes.h:272
int16_t tag
Definition: libmmgtypes.h:284
double c[3]
Definition: libmmgtypes.h:271
MMG5_int ref
Definition: libmmgtypes.h:278
double * m
Definition: libmmgtypes.h:671
MMG5_int edg[3]
Definition: libmmgtypes.h:339
int16_t tag[3]
Definition: libmmgtypes.h:342
MMG5_int flag
Definition: libmmgtypes.h:341
MMG5_int base
Definition: libmmgtypes.h:336
MMG5_int v[3]
Definition: libmmgtypes.h:334