Skip to content

Commit 89e0cec

Browse files
committed
In 2d mesh generation: insert a point at triangle barycenter if we are unable to star the delaunay cavity.
1 parent 4be2667 commit 89e0cec

File tree

3 files changed

+171
-5
lines changed

3 files changed

+171
-5
lines changed

src/mmg2d/mmg2d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ int _MMG2_split3_sim(MMG5_pMesh ,MMG5_pSol ,int ,int vx[3]);
297297
int _MMG2_split1(MMG5_pMesh ,MMG5_pSol ,int ,int vx[3]);
298298
int _MMG2_split2(MMG5_pMesh ,MMG5_pSol ,int ,int vx[3]);
299299
int _MMG2_split3(MMG5_pMesh ,MMG5_pSol ,int ,int vx[3]);
300+
int _MMG2_splitbar(MMG5_pMesh ,int ,int );
300301
int MMG2_assignEdge(MMG5_pMesh );
301302
int MMG2_bdryEdge(MMG5_pMesh );
302303
int _MMG2_setadj(MMG5_pMesh );

src/mmg2d/mmg2d2.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ int MMG2_insertpointdelone(MMG5_pMesh mesh,MMG5_pSol sol) {
220220
continue;
221221
} else {
222222
if(!_MMG2_delone(mesh,sol,k,list,lon)) {
223-
if(mesh->info.imprim > 4) {
223+
if ( abs(mesh->info.imprim) > 4) {
224224
nud++;
225225
if ( !mmgWarn2 ) {
226226
mmgWarn2 = 1;
@@ -235,16 +235,62 @@ int MMG2_insertpointdelone(MMG5_pMesh mesh,MMG5_pSol sol) {
235235
}
236236
}
237237

238-
if(mesh->info.imprim > 4)
238+
if ( abs(mesh->info.imprim) > 4)
239239
fprintf(stdout," %8d vertex inserted %8d not inserted\n",ns,nu+nud);
240240
if(mesh->info.imprim < 0)
241241
fprintf(stdout," unable to insert %8d vertex : cavity %8d -- delaunay %8d \n",nu+nud,nu,nud);
242242
} while (ns && ++iter<maxiter);
243243

244244
if(abs(nus-ns)) {
245-
fprintf(stderr," ## Error: %s: some vertex are not "
245+
if ( mesh->info.imprim < 0 ) {
246+
fprintf(stderr,"\n ## Warning: %s: unable to"
247+
" insert %8d point with Delaunay \n",__func__,abs(nus-ns));
248+
fprintf(stdout," try to insert with splitbar\n");
249+
}
250+
mmgWarn2 = 0;
251+
nus = ns = 0;
252+
/*try to insert using splitbar*/
253+
for(k=1; k<=mesh->np-4; k++) {
254+
ppt = &mesh->point[k];
255+
if(ppt->flag != -10) continue;
256+
nus++;
257+
/* Find the triangle lel of the mesh containing ppt */
258+
list[0] = MMG2_findTria(mesh,k);
259+
260+
/* Exhaustive search if not found */
261+
if ( !list[0] ) {
262+
if ( mesh->info.ddebug )
263+
printf(" ** exhaustive search of point location.\n");
264+
265+
for(kk=1; kk<=mesh->nt; kk++) {
266+
list[0] = MMG2_isInTriangle(mesh,kk,&ppt->c[0]);
267+
if ( list[0] ) break;
268+
}
269+
270+
if ( kk>mesh->nt ) {
271+
if ( !mmgWarn0 ) {
272+
mmgWarn0 = 1;
273+
fprintf(stderr,"\n ## Error: %s: unable to find triangle"
274+
" for at least vertex %8d.\n",__func__,k);
275+
}
276+
return 0;
277+
}
278+
}
279+
if(!_MMG2_splitbar(mesh,list[0],k)) {
280+
if ( !mmgWarn2 ) {
281+
mmgWarn2 = 1;
282+
if(mesh->info.imprim < 0) fprintf(stderr,"\n ## Warning: %s: unable to"
283+
" insert at least 1 point with splitbar (%8d)\n",__func__,k);
284+
}
285+
} else {
286+
ns++;
287+
}
288+
}
289+
if ( abs(nus-ns) ) {
290+
fprintf(stderr," ## Error: %s: some vertex are not "
246291
"inserted %d.\n",__func__,abs(nus-ns));
247-
return(0);
292+
return 0;
293+
}
248294
}
249295
return(1);
250296
}

src/mmg2d/split_2d.c

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,5 +694,124 @@ int _MMG2_split3(MMG5_pMesh mesh, MMG5_pSol sol, int k, int vx[3]) {
694694
pt3->tag[0] = pt3->tag[1] = pt3->tag[2] = MG_NOTAG;
695695
pt3->edg[0] = pt3->edg[1] = pt3->edg[2] = 0;
696696

697-
return(1);
697+
return 1;
698+
}
699+
700+
/**
701+
* \param mesh pointer toward the mesh
702+
* \param k index of the tria to split
703+
* \param ip global index of the new point
704+
*
705+
* \return 1 if success, 0 if fail
706+
*
707+
* Insert the point ip inside the tria k
708+
*
709+
*/
710+
int _MMG2_splitbar(MMG5_pMesh mesh,int k,int ip) {
711+
MMG5_pTria pt,pt0,pt1,pt2;
712+
MMG5_pPoint p0,p1,p2,ppt;
713+
int *adja,iel1,iel2,jel0,jel1,jel2;
714+
int ip0,ip1,ip2;
715+
char i1,i2,m,j,j1,j2,j0;
716+
double cal,calseuil;
717+
718+
pt = &mesh->tria[k];
719+
pt0 = &mesh->tria[0];
720+
ppt = &mesh->point[ip];
721+
ip0 = pt->v[0];
722+
p0 = &mesh->point[ip0];
723+
ip1 = pt->v[1];
724+
p1 = &mesh->point[ip1];
725+
ip2 = pt->v[2];
726+
p2 = &mesh->point[ip2];
727+
728+
calseuil = _MMG2_EPSD ;
729+
730+
/* Check quality of the three new elements */
731+
cal = MMG2_quickarea(ppt->c,p1->c,p2->c);
732+
if ( (cal < calseuil) ) {
733+
return(0);
734+
}
735+
736+
cal = MMG2_quickarea(p0->c,ppt->c,p2->c);
737+
if ( (cal < calseuil) ) {
738+
return(0);
739+
}
740+
pt0->v[0] = ip0;
741+
cal = MMG2_quickarea(p0->c,p1->c,ppt->c);
742+
if ( (cal < calseuil) ) {
743+
return(0);
744+
}
745+
746+
iel1 = _MMG2D_newElt(mesh);
747+
if ( !iel1 ) {
748+
_MMG2D_TRIA_REALLOC(mesh,iel1,mesh->gap,
749+
printf(" ## Error: unable to allocate a new element.\n");
750+
_MMG5_INCREASE_MEM_MESSAGE();
751+
printf(" Exit program.\n");return 0;,0);
752+
}
753+
iel2 = _MMG2D_newElt(mesh);
754+
if ( !iel2 ) {
755+
_MMG2D_TRIA_REALLOC(mesh,iel2,mesh->gap,
756+
printf(" ## Error: unable to allocate a new element.\n");
757+
_MMG5_INCREASE_MEM_MESSAGE();
758+
printf(" Exit program.\n");return 0;,0);
759+
}
760+
761+
pt->flag = 0;
762+
pt->base = mesh->base;
763+
764+
adja = &mesh->adja[3*(k-1)+1];
765+
jel0 = adja[0] / 3;
766+
j0 = adja[0] % 3;
767+
jel1 = adja[1] / 3;
768+
j1 = adja[1] % 3;
769+
jel2 = adja[2] / 3;
770+
j2 = adja[2] % 3;
771+
772+
pt1 = &mesh->tria[iel1];
773+
memcpy(pt1,pt,sizeof(MMG5_Tria));
774+
memcpy(&mesh->adja[3*(iel1-1)+1],&mesh->adja[3*(k-1)+1],3*sizeof(int));
775+
pt2 = &mesh->tria[iel2];
776+
memcpy(pt2,pt,sizeof(MMG5_Tria));
777+
memcpy(&mesh->adja[3*(iel2-1)+1],&mesh->adja[3*(k-1)+1],3*sizeof(int));
778+
779+
/* Update the three triangles */
780+
pt->v[1] = ip;
781+
pt1->v[2] = ip;
782+
pt2->v[0] = ip;
783+
784+
pt->tag[1] = MG_NOTAG;
785+
pt->edg[1] = 0;
786+
787+
pt1->tag[2] = MG_NOTAG;
788+
pt1->edg[2] = 0;
789+
790+
pt2->tag[0] = MG_NOTAG;
791+
pt2->edg[0] = 0;
792+
793+
/* Update external adjacencies */
794+
assert(mesh->adja[3*(k-1)+1+1] == 3*jel1+j1);
795+
if ( jel1 ) {
796+
assert(mesh->adja[3*(jel1-1)+1+j1] == 3*k+1);
797+
}
798+
mesh->adja[3*(iel1-1)+1+2] = 3*jel2+j2;
799+
if ( jel2 )
800+
mesh->adja[3*(jel2-1)+1+j2] = 3*iel1+2;
801+
802+
mesh->adja[3*(iel2-1)+1+0] = 3*jel0+j0;
803+
if ( jel0 )
804+
mesh->adja[3*(jel0-1)+1+j0] = 3*iel2+0;
805+
806+
/*update internal adjacencies*/
807+
mesh->adja[3*(k-1)+1+0] = 3*iel2+1;
808+
mesh->adja[3*(iel2-1)+1+1] = 3*k+0;
809+
810+
mesh->adja[3*(k-1)+1+2] = 3*iel1+1;
811+
mesh->adja[3*(iel1-1)+1+1] = 3*k+2;
812+
813+
mesh->adja[3*(iel1-1)+1+0] = 3*iel2+2;
814+
mesh->adja[3*(iel2-1)+1+2] = 3*iel1+0;
815+
816+
return 1;
698817
}

0 commit comments

Comments
 (0)