56 double aa,bb,ab,ll,l,mlon,devmean,GV[3],gv[2],cosalpha,sinalpha,r[3][3],*n,lispoi[3*
MMG5_TRIA_LMAX+3];
57 double ux,uy,uz,det2d,detloc,step,lambda[3],uv[2],o[3],no[3],to[3],Vold,Vnew,calold,calnew,caltmp;
58 MMG5_int k,iel,ipp,ibeg,iend;
61 static int8_t mmgErr0=0,mmgErr1=0;
75 k = list[ilist-1] / 3;
76 i0 = list[ilist-1] % 3;
83 if ( iend != ibeg )
return 0;
91 for (k=0; k<ilist; k++) {
97 mlon += (p1->
c[0]-p0->
c[0])*(p1->
c[0]-p0->
c[0]) + (p1->
c[1]-p0->
c[1])*(p1->
c[1]-p0->
c[1]) \
98 + (p1->
c[2]-p0->
c[2])*(p1->
c[2]-p0->
c[2]);
104 GV[0] = GV[1] = GV[2] = 0.0;
105 for (k=0; k<ilist; k++) {
112 devmean = (p1->
c[0]-p0->
c[0])*(p1->
c[0]-p0->
c[0]) + (p1->
c[1]-p0->
c[1])*(p1->
c[1]-p0->
c[1]) \
113 + (p1->
c[2]-p0->
c[2])*(p1->
c[2]-p0->
c[2]) - mlon;
114 GV[0] += devmean*(p1->
c[0]-p0->
c[0]);
115 GV[1] += devmean*(p1->
c[1]-p0->
c[1]);
116 GV[2] += devmean*(p1->
c[2]-p0->
c[2]);
117 Vold += devmean*devmean;
120 GV[0] *= (4.0 / npt);
121 GV[1] *= (4.0 / npt);
122 GV[2] *= (4.0 / npt);
132 sinalpha = sqrt(1.0-
MG_MIN(1.0,cosalpha*cosalpha));
137 r[0][0] = 1.0 ; r[0][1] = 0.0 ; r[0][2] = 0.0;
138 r[1][0] = 0.0 ; r[1][1] = 1.0 ; r[1][2] = 0.0;
139 r[2][0] = 0.0 ; r[2][1] = 0.0 ; r[2][2] = 1.0;
142 r[0][0] = -1.0 ; r[0][1] = 0.0 ; r[0][2] = 0.0;
143 r[1][0] = 0.0 ; r[1][1] = 1.0 ; r[1][2] = 0.0;
144 r[2][0] = 0.0 ; r[2][1] = 0.0 ; r[2][2] = -1.0;
150 r[0][0] = (aa*cosalpha + bb)/ll;
151 r[0][1] = ab*(cosalpha-1)/ll;
152 r[0][2] = -n[0]*sinalpha/l;
154 r[1][1] = (bb*cosalpha + aa)/ll;
155 r[1][2] = -n[1]*sinalpha/l;
156 r[2][0] = n[0]*sinalpha/l;
157 r[2][1] = n[1]*sinalpha/l;
162 gv[0] = r[0][0]*GV[0] + r[0][1]*GV[1] + r[0][2]*GV[2];
163 gv[1] = r[1][0]*GV[0] + r[1][1]*GV[1] + r[1][2]*GV[2];
167 for (k=0; k<ilist; k++) {
174 ux = p1->
c[0] - p0->
c[0];
175 uy = p1->
c[1] - p0->
c[1];
176 uz = p1->
c[2] - p0->
c[2];
178 lispoi[3*k+1] = r[0][0]*ux + r[0][1]*uy + r[0][2]*uz;
179 lispoi[3*k+2] = r[1][0]*ux + r[1][1]*uy + r[1][2]*uz;
180 lispoi[3*k+3] = r[2][0]*ux + r[2][1]*uy + r[2][2]*uz;
184 lispoi[3*ilist+1] = lispoi[1];
185 lispoi[3*ilist+2] = lispoi[2];
186 lispoi[3*ilist+3] = lispoi[3];
190 for (k=0; k<ilist; k++) {
191 gv[0] += lispoi[3*k+1];
192 gv[1] += lispoi[3*k+2];
194 gv[0] *= (1.0 / npt);
195 gv[1] *= (1.0 / npt);
198 for (k=0; k<ilist-1; k++) {
199 det2d = lispoi[3*k+1]*lispoi[3*(k+1)+2] - lispoi[3*k+2]*lispoi[3*(k+1)+1];
200 if ( det2d < 0.0 )
return 0;
202 det2d = lispoi[3*(ilist-1)+1]*lispoi[3*0+2] - lispoi[3*(ilist-1)+2]*lispoi[3*0+1];
203 if ( det2d < 0.0 )
return 0;
206 det2d = lispoi[1]*gv[1] - lispoi[2]*gv[0];
208 if ( det2d >= 0.0 ) {
209 for (k=0; k<ilist; k++) {
210 detloc = gv[0]*lispoi[3*(k+1)+2] - gv[1]*lispoi[3*(k+1)+1];
211 if ( detloc >= 0.0 ) {
216 if ( k == ilist )
return 0;
219 for (k=ilist-1; k>=0; k--) {
220 detloc = gv[1]*lispoi[3*k+1] - gv[0]*lispoi[3*k+2];
221 if ( detloc >= 0.0 ) {
226 if ( k == -1 )
return 0;
230 det2d = -gv[1]*(lispoi[3*(kel+1)+1] - lispoi[3*(kel)+1]) \
231 + gv[0]*(lispoi[3*(kel+1)+2] - lispoi[3*(kel)+2]);
236 det2d = lispoi[3*(kel)+1]*(lispoi[3*(kel+1)+2] - lispoi[3*(kel)+2]) - \
237 lispoi[3*(kel)+2 ]*(lispoi[3*(kel+1)+1] - lispoi[3*(kel)+1]);
244 det2d = lispoi[3*kel+1]*lispoi[3*(kel+1)+2] - lispoi[3*kel+2]*lispoi[3*(kel+1)+1];
247 lambda[1] = lispoi[3*(kel+1)+2]*gv[0] - lispoi[3*(kel+1)+1]*gv[1];
248 lambda[2] = -lispoi[3*(kel)+2]*gv[0] + lispoi[3*(kel)+1]*gv[1];
251 lambda[0] = 1.0 - lambda[1] - lambda[2];
258 ier = MMG5_bezierCP(
mesh,pt,&b,1);
262 fprintf(stderr,
"\n ## Warning: %s: function MMG5_bezierCP return 0.\n",
274 else if ( i0 == 1 ) {
287 fprintf(stderr,
" ## Warning: %s: function MMGS_bezierInt return 0.\n",
295 for (k=0; k<ilist; k++) {
301 mlon += (p1->
c[0]-o[0])*(p1->
c[0]-o[0]) + (p1->
c[1]-o[1])*(p1->
c[1]-o[1]) \
302 + (p1->
c[2]-o[2])*(p1->
c[2]-o[2]);
306 for (k=0; k<ilist; k++) {
312 devmean = (p1->
c[0]-o[0])*(p1->
c[0]-o[0]) + (p1->
c[1]-o[1])*(p1->
c[1]-o[1]) \
313 + (p1->
c[2]-o[2])*(p1->
c[2]-o[2]) - mlon;
314 Vnew += devmean*devmean;
330 calold = calnew = DBL_MAX;
331 for (k= 0; k<ilist; k++) {
339 calold =
MG_MIN(calold,caltmp);
342 calnew =
MG_MIN(calnew,caltmp);
344 if ( calold <
MMG5_EPSOK && calnew <= calold )
return 0;
346 else if ( calnew < 0.3*calold )
return 0;
376 double step,
double o[3]) {
379 double uv[2],nn1[3],to[3];
385 ier = MMG5_bezierCP(
mesh,pt,&b,1);
389 if ( pt->
v[0] == ip0 ) {
390 if ( pt->
v[1] == ip ) {
394 else if ( pt->
v[2] == ip ) {
399 else if ( pt->
v[0] == ip ) {
400 if ( pt->
v[1] == ip0 ) {
404 else if ( pt->
v[2] == ip0 ) {
410 if ( pt->
v[1] == ip0 ) {
414 else if ( pt->
v[2] == ip0 ) {
450 double llold,
double lam0,
double lam1,
double lam2,
451 double no1[3],
double no2[3],
452 double np1[3],
double np2[3],
453 double nn1[3],
double nn2[3],
double to[3] ) {
455 double dd1,dd2,ddt,ps2;
457 nn1[0] = no1[0]+np1[0];
458 nn1[1] = no1[1]+np1[1];
459 nn1[2] = no1[2]+np1[2];
461 nn2[0] = no2[0]+np2[0];
462 nn2[1] = no2[1]+np2[1];
463 nn2[2] = no2[2]+np2[2];
465 ps2 = (p->
c[0]-p0->
c[0])*nn1[0]+(p->
c[1]-p0->
c[1])*nn1[1]+(p->
c[2]-p0->
c[2])*nn1[2];
470 ps2 *= (2.0 / llold);
471 nn1[0] -= ps2*(p->
c[0]-p0->
c[0]);
472 nn1[1] -= ps2*(p->
c[1]-p0->
c[1]);
473 nn1[2] -= ps2*(p->
c[2]-p0->
c[2]);
475 ps2 = (p->
c[0]-p0->
c[0])*nn2[0]+(p->
c[1]-p0->
c[1])*nn2[1]+(p->
c[2]-p0->
c[2])*nn2[2];
477 nn2[0] -= ps2*(p->
c[0]-p0->
c[0]);
478 nn2[1] -= ps2*(p->
c[1]-p0->
c[1]);
479 nn2[2] -= ps2*(p->
c[2]-p0->
c[2]);
481 dd1 = nn1[0]*nn1[0] + nn1[1]*nn1[1] + nn1[2]*nn1[2];
482 dd2 = nn2[0]*nn2[0] + nn2[1]*nn2[1] + nn2[2]*nn2[2];
487 dd1 = 1.0 / sqrt(dd1);
492 dd2 = 1.0 / sqrt(dd2);
499 nn1[0] = lam0*no1[0] + lam1*nn1[0] + lam2*np1[0];
500 nn1[1] = lam0*no1[1] + lam1*nn1[1] + lam2*np1[1];
501 nn1[2] = lam0*no1[2] + lam1*nn1[2] + lam2*np1[2];
503 nn2[0] = lam0*no2[0] + lam1*nn2[0] + lam2*np2[0];
504 nn2[1] = lam0*no2[1] + lam1*nn2[1] + lam2*np2[1];
505 nn2[2] = lam0*no2[2] + lam1*nn2[2] + lam2*np2[2];
507 to[0] = nn1[1]*nn2[2]-nn1[2]*nn2[1];
508 to[1] = nn1[2]*nn2[0]-nn1[0]*nn2[2];
509 to[2] = nn1[0]*nn2[1]-nn1[1]*nn2[0];
511 ddt = to[0]*to[0] + to[1]*to[1] + to[2]*to[2];
512 dd1 = nn1[0]*nn1[0] + nn1[1]*nn1[1] + nn1[2]*nn1[2];
513 dd2 = nn2[0]*nn2[0] + nn2[1]*nn2[1] + nn2[2]*nn2[2];
519 dd1 = 1.0 / sqrt(dd1);
524 dd2 = 1.0 / sqrt(dd2);
529 ddt = 1.0 / sqrt(ddt);
556 double llold,
double lam0,
double lam1,
double lam2,
557 double nn1[3],
double nn2[3],
double to[3]) {
559 double *no1,*no2,*np1,*np2,psn11,psn12;
572 psn11 = no1[0]*np1[0] + no1[1]*np1[1] + no1[2]*np1[2];
573 psn12 = no1[0]*np2[0] + no1[1]*np2[1] + no1[2]*np2[2];
576 if ( fabs(1.0-fabs(psn11)) < fabs(1.0-fabs(psn12)) ){
578 no1,no2,np1,np2,nn1,nn2,to ) ) {
586 no1,no2,np2,np1,nn1,nn2,to ) ) {
599 double step,ll1old,ll1new,ll2old,ll2new,o[3];
600 double nn1[3],nn2[3],to[3],calold,calnew,lam0,lam1,lam2;
601 MMG5_int k,iel,ip,ip0,ip1,ip2,it,it1,it2;
602 int8_t i0,i1,i2,isrid1,isrid2,isrid;
605 isrid1 = 0 ; isrid2 = 0;
610 for (k=0; k<ilist; k++) {
623 else if ( it1 && !it2 ) {
624 if ( ip1 != pt->
v[i2] ) {
630 else if ( it1 && it2 && (pt->
v[i2] != ip1) && (pt->
v[i2] != ip2) ) {
641 else if ( it1 && !it2 ) {
642 if ( ip1 != pt->
v[i1] ) {
648 else if ( it1 && it2 && (pt->
v[i1] != ip1) && (pt->
v[i1] != ip2) ) {
663 ll1old = (p1->
c[0]-p0->
c[0])*(p1->
c[0]-p0->
c[0])
664 + (p1->
c[1]-p0->
c[1])*(p1->
c[1]-p0->
c[1])
665 + (p1->
c[2]-p0->
c[2])*(p1->
c[2]-p0->
c[2]);
667 ll2old = (p2->
c[0] -p0->
c[0])*(p2->
c[0]-p0->
c[0])
668 + (p2->
c[1]-p0->
c[1])*(p2->
c[1]-p0->
c[1])
669 + (p2->
c[2]-p0->
c[2])*(p2->
c[2]-p0->
c[2]);
671 if ( (!ll1old) || (!ll2old) )
return 0;
673 if ( ll1old < ll2old ) {
691 ll1new = (p1->
c[0]-o[0])*(p1->
c[0]-o[0])
692 + (p1->
c[1]-o[1])* (p1->
c[1]-o[1])
693 + (p1->
c[2]-o[2])* (p1->
c[2]-o[2]);
695 ll2new = (p2->
c[0]-o[0])*(p2->
c[0]-o[0])
696 + (p2->
c[1]-o[1])*(p2->
c[1]-o[1])
697 + (p2->
c[2]-o[2])*(p2->
c[2]-o[2]);
699 if( fabs(ll2new -ll1new) >= fabs(ll2old -ll1old) )
return 0;
703 lam0 = (1.0-step)*(1.0-step);
704 lam1 = 2.0*step*(1.0-step);
708 if ( ll2old > ll1old ) {
743 for (k=0; k<ilist; k++) {
753 if ( (calnew < 0.001) && (calnew<calold) )
return 0;
int MMGS_bezierInt(MMG5_pBezier pb, double uv[2], double o[3], double no[3], double to[3])
double caleltsig_iso(MMG5_pMesh mesh, MMG5_pSol met, MMG5_int iel)
static const uint8_t MMG5_inxt2[6]
int MMGS_moveTowardPoint(MMG5_pMesh mesh, MMG5_pPoint p0, MMG5_pPoint p, double llold, double lam0, double lam1, double lam2, double nn1[3], double nn2[3], double to[3])
int movridpt_iso(MMG5_pMesh mesh, MMG5_pSol met, MMG5_int *list, int ilist)
int movintpt_iso(MMG5_pMesh mesh, MMG5_pSol met, MMG5_int *list, int ilist)
static int MMGS_update_normalAndTangent(MMG5_pMesh mesh, MMG5_pPoint p0, MMG5_pPoint p, double llold, double lam0, double lam1, double lam2, double no1[3], double no2[3], double np1[3], double np2[3], double nn1[3], double nn2[3], double to[3])
int MMGS_paramDisp(MMG5_pMesh mesh, MMG5_int it, int8_t isrid, MMG5_int ip0, MMG5_int ip, double step, double o[3])
Structure to store vertices of an MMG mesh.
Structure to store triangles of a MMG mesh.
Structure to store surface vertices of an MMG mesh.