52 double lambda[3],vp[3][3],mu[3],is[6],isnis[6],mt[9],P[9],dd;
54 static int8_t mmgWarn=0;
61 fprintf(stderr,
"\n ## Warning: %s: unable to diagonalize at least"
62 " 1 metric.\n",__func__);
70 lambda[i] = sqrt(lambda[i]);
71 lambda[i] = 1.0 / lambda[i];
74 is[0] = lambda[0]*vp[0][0]*vp[0][0] + lambda[1]*vp[1][0]*vp[1][0]
75 + lambda[2]*vp[2][0]*vp[2][0];
76 is[1] = lambda[0]*vp[0][0]*vp[0][1] + lambda[1]*vp[1][0]*vp[1][1]
77 + lambda[2]*vp[2][0]*vp[2][1];
78 is[2] = lambda[0]*vp[0][0]*vp[0][2] + lambda[1]*vp[1][0]*vp[1][2]
79 + lambda[2]*vp[2][0]*vp[2][2];
80 is[3] = lambda[0]*vp[0][1]*vp[0][1] + lambda[1]*vp[1][1]*vp[1][1]
81 + lambda[2]*vp[2][1]*vp[2][1];
82 is[4] = lambda[0]*vp[0][1]*vp[0][2] + lambda[1]*vp[1][1]*vp[1][2]
83 + lambda[2]*vp[2][1]*vp[2][2];
84 is[5] = lambda[0]*vp[0][2]*vp[0][2] + lambda[1]*vp[1][2]*vp[1][2]
85 + lambda[2]*vp[2][2]*vp[2][2];
87 mt[0] = n[0]*is[0] + n[1]*is[1] + n[2]*is[2];
88 mt[1] = n[0]*is[1] + n[1]*is[3] + n[2]*is[4];
89 mt[2] = n[0]*is[2] + n[1]*is[4] + n[2]*is[5];
90 mt[3] = n[1]*is[0] + n[3]*is[1] + n[4]*is[2];
91 mt[4] = n[1]*is[1] + n[3]*is[3] + n[4]*is[4];
92 mt[5] = n[1]*is[2] + n[3]*is[4] + n[4]*is[5];
93 mt[6] = n[2]*is[0] + n[4]*is[1] + n[5]*is[2];
94 mt[7] = n[2]*is[1] + n[4]*is[3] + n[5]*is[4];
95 mt[8] = n[2]*is[2] + n[4]*is[4] + n[5]*is[5];
97 isnis[0] = is[0]*mt[0] + is[1]*mt[3] + is[2]*mt[6];
98 isnis[1] = is[0]*mt[1] + is[1]*mt[4] + is[2]*mt[7];
99 isnis[2] = is[0]*mt[2] + is[1]*mt[5] + is[2]*mt[8];
100 isnis[3] = is[1]*mt[1] + is[3]*mt[4] + is[4]*mt[7];
101 isnis[4] = is[1]*mt[2] + is[3]*mt[5] + is[4]*mt[8];
102 isnis[5] = is[2]*mt[2] + is[4]*mt[5] + is[5]*mt[8];
107 fprintf(stderr,
"\n ## Warning: %s: unable to diagonalize at least"
108 " 1 metric.\n",__func__);
115 P[0] = is[0]*vp[0][0] + is[1]*vp[0][1] + is[2]*vp[0][2];
116 P[1] = is[0]*vp[1][0] + is[1]*vp[1][1] + is[2]*vp[1][2];
117 P[2] = is[0]*vp[2][0] + is[1]*vp[2][1] + is[2]*vp[2][2];
118 P[3] = is[1]*vp[0][0] + is[3]*vp[0][1] + is[4]*vp[0][2];
119 P[4] = is[1]*vp[1][0] + is[3]*vp[1][1] + is[4]*vp[1][2];
120 P[5] = is[1]*vp[2][0] + is[3]*vp[2][1] + is[4]*vp[2][2];
121 P[6] = is[2]*vp[0][0] + is[4]*vp[0][1] + is[5]*vp[0][2];
122 P[7] = is[2]*vp[1][0] + is[4]*vp[1][1] + is[5]*vp[1][2];
123 P[8] = is[2]*vp[2][0] + is[4]*vp[2][1] + is[5]*vp[2][2];
128 if ( lambda[i] < 0.0 )
return 0;
129 dd = s*sqrt(lambda[i]) + (1.0-s);
132 mu[i] = lambda[i]/dd;
138 mr[0] = mu[0]*mt[0]*mt[0] + mu[1]*mt[3]*mt[3] + mu[2]*mt[6]*mt[6];
139 mr[1] = mu[0]*mt[0]*mt[1] + mu[1]*mt[3]*mt[4] + mu[2]*mt[6]*mt[7];
140 mr[2] = mu[0]*mt[0]*mt[2] + mu[1]*mt[3]*mt[5] + mu[2]*mt[6]*mt[8];
141 mr[3] = mu[0]*mt[1]*mt[1] + mu[1]*mt[4]*mt[4] + mu[2]*mt[7]*mt[7];
142 mr[4] = mu[0]*mt[1]*mt[2] + mu[1]*mt[4]*mt[5] + mu[2]*mt[7]*mt[8];
143 mr[5] = mu[0]*mt[2]*mt[2] + mu[1]*mt[5]*mt[5] + mu[2]*mt[8]*mt[8];
164 double v[3],
double mr[6]) {
167 double *m1,*m2,*n11,*n12,*n21,*n22,ps11,ps12,dd;
168 double hu1,hu2,hn1,hn2;
184 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[0]);
203 mr[0] = m1[0]*m2[0] / dd;
220 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[0]);
223 mr[0] = s < 0.5 ? m1[0] : m2[0];
226 mr[0] = m1[0]*m2[0] / dd;
231 dd = (1-s)*sqrt(m2[1]) + s*sqrt(m1[0]);
234 hu1 = s < 0.5 ? m1[0] : m2[1];
237 hu1 = m1[0]*m2[1] / dd;
239 dd = (1-s)*sqrt(m2[3]) + s*sqrt(m1[0]);
242 hn1 = s < 0.5 ? m1[0] : m2[3];
245 hn1 = m1[0]*m2[3] / dd;
249 dd = (1-s)*sqrt(m2[2]) + s*sqrt(m1[0]);
252 hu2 = s < 0.5 ? m1[0] : m2[2];
255 hu2 = m1[0]*m2[2] / dd;
257 dd = (1-s)*sqrt(m2[4]) + s*sqrt(m1[0]);
260 hn2 = s < 0.5 ? m1[0] : m2[4];
263 hn2 = m1[0]*m2[4] / dd;
267 ps11 = n21[0]*v[0] + n21[1]*v[1] + n21[2]*v[2];
268 ps12 = n22[0]*v[0] + n22[1]*v[1] + n22[2]*v[2];
269 if ( fabs(ps11) > fabs(ps12) ) {
292 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[0]);
295 mr[0] = s < 0.5 ? m1[0] : m2[0];
298 mr[0] = m1[0]*m2[0] / dd;
302 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[1]);
305 hu1 = s < 0.5 ? m1[1] : m2[0];
308 hu1 = m1[1]*m2[0] / dd;
310 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[3]);
313 hn1 = s < 0.5 ? m1[3] : m2[0];
316 hn1 = m1[3]*m2[0] / dd;
320 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[2]);
323 hu2 = s < 0.5 ? m1[2] : m2[0];
326 hu2 = m1[2]*m2[0] / dd;
328 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[4]);
331 hn2 = s < 0.5 ? m1[4] : m2[0];
334 hn2 = m1[4]*m2[0] / dd;
338 ps11 = n11[0]*v[0] + n11[1]*v[1] + n11[2]*v[2];
339 ps12 = n12[0]*v[0] + n12[1]*v[1] + n12[2]*v[2];
340 if ( fabs(ps11) > fabs(ps12) ) {
359 dd = (1-s)*sqrt(m2[0]) + s*sqrt(m1[0]);
362 mr[0] = s < 0.5 ? m1[0] : m2[0];
365 mr[0] = m1[0]*m2[0] / dd;
373 ps11 = n11[0]*n21[0] + n11[1]*n21[1] + n11[2]*n21[2];
374 ps12 = n11[0]*n22[0] + n11[1]*n22[1] + n11[2]*n22[2];
375 if ( fabs(ps11) > fabs(ps12) ) {
377 dd = (1-s)*sqrt(m2[1]) + s*sqrt(m1[1]);
380 hu1 = s < 0.5 ? m1[1] : m2[1];
383 hu1 = m1[1]*m2[1] / dd;
385 dd = (1-s)*sqrt(m2[3]) + s*sqrt(m1[3]);
388 hn1 = s < 0.5 ? m1[3] : m2[3];
391 hn1 = m1[3]*m2[3] / dd;
394 dd = (1-s)*sqrt(m2[2]) + s*sqrt(m1[2]);
397 hu2 = s < 0.5 ? m1[2] : m2[2];
400 hu2 = m1[2]*m2[2] / dd;
402 dd = (1-s)*sqrt(m2[4]) + s*sqrt(m1[4]);
405 hn2 = s < 0.5 ? m1[4] : m2[4];
408 hn2 = m1[4]*m2[4] / dd;
414 dd = (1-s)*sqrt(m2[2]) + s*sqrt(m1[1]);
417 hu1 = s < 0.5 ? m1[1] : m2[2];
420 hu1 = m1[1]*m2[2] / dd;
422 dd = (1-s)*sqrt(m2[4]) + s*sqrt(m1[3]);
425 hn1 = s < 0.5 ? m1[3] : m2[4];
428 hn1 = m1[3]*m2[4] / dd;
432 dd = (1-s)*sqrt(m2[1]) + s*sqrt(m1[2]);
435 hu2 = s < 0.5 ? m1[2] : m2[1];
438 hu2 = m1[2]*m2[1] / dd;
440 dd = (1-s)*sqrt(m2[3]) + s*sqrt(m1[4]);
443 hn2 = s < 0.5 ? m1[4] : m2[3];
446 hn2 = m1[4]*m2[3] / dd;
454 ps11 = n11[0]*v[0] + n11[1]*v[1] + n11[2]*v[2];
455 ps12 = n12[0]*v[0] + n12[1]*v[1] + n12[2]*v[2];
456 if ( fabs(ps11) > fabs(ps12) ) {
486 *mp = (1.0-t)*(*ma) + t*(*mb);
505 double s,
double mr[6]) {
508 double b1[3],b2[3],bn[3],c[3],nt[3],cold[3],nold[3],n[3];
509 double m1old[6],m2old[6],m1[6],m2[6],rbasis[3][3];
510 double *n1,*n2,step,u,r[3][3],dd,ddbn;
514 static int warn=0,warnnorm=0;
525 if ( !MMG5_bezierCP(
mesh,pt,&b,1) )
return 0;
529 memcpy(bn,&b.
n[i+3][0],3*
sizeof(
double));
530 memcpy(b1,&b.
b[2*i+3][0],3*
sizeof(
double));
531 memcpy(b2,&b.
b[2*i+4][0],3*
sizeof(
double));
533 ddbn = bn[0]*bn[0] + bn[1]*bn[1] + bn[2]*bn[2];
546 memcpy(m1,&met->
m[6*ip1],6*
sizeof(
double));
554 memcpy(m1,&met->
m[6*ip1],6*
sizeof(
double));
556 memcpy(m1old,m1,6*
sizeof(
double));
559 for (l=1; l<=nstep; l++) {
561 c[0] = p1->
c[0]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[0]\
562 + 3.0*u*u*(1.0-u)*b2[0] + u*u*u*p2->
c[0];
563 c[1] = p1->
c[1]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[1]\
564 + 3.0*u*u*(1.0-u)*b2[1] + u*u*u*p2->
c[1];
565 c[2] = p1->
c[2]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[2]\
566 + 3.0*u*u*(1.0-u)*b2[2] + u*u*u*p2->
c[2];
568 n[0] = (1.0-u)*(1.0-u)*n1[0] + 2.0*u*(1.0-u)*bn[0] + u*u*n2[0];
569 n[1] = (1.0-u)*(1.0-u)*n1[1] + 2.0*u*(1.0-u)*bn[1] + u*u*n2[1];
570 n[2] = (1.0-u)*(1.0-u)*n1[2] + 2.0*u*(1.0-u)*bn[2] + u*u*n2[2];
571 dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
580 memcpy(cold,c,3*
sizeof(
double));
581 memcpy(nold,n,3*
sizeof(
double));
582 memcpy(m1old,m1,6*
sizeof(
double));
587 step = (1.0-s) / nstep;
597 memcpy(m2,&met->
m[6*ip2],6*
sizeof(
double));
601 memcpy(n,n2,3*
sizeof(
double));
602 assert(
MMG5_EPSD < (n2[0]*n2[0]+n2[1]*n2[1]+n2[2]*n2[2]) &&
"normal at p2 is 0" );
607 fprintf(stderr,
" ## Warning: %s: %d: unexpected case (null normal),"
608 " impossible interpolation.\n",__func__,__LINE__);
620 memcpy(m2,&met->
m[6*ip2],6*
sizeof(
double));
622 memcpy(m2old,m2,6*
sizeof(
double));
625 for (l=1; l<=nstep; l++) {
627 c[0] = p1->
c[0]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[0]\
628 + 3.0*u*u*(1.0-u)*b2[0] + u*u*u*p2->
c[0];
629 c[1] = p1->
c[1]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[1]\
630 + 3.0*u*u*(1.0-u)*b2[1] + u*u*u*p2->
c[1];
631 c[2] = p1->
c[2]*(1.0-u)*(1.0-u)*(1.0-u) + 3.0*(1.0-u)*(1.0-u)*u*b1[2]\
632 + 3.0*u*u*(1.0-u)*b2[2] + u*u*u*p2->
c[2];
634 n[0] = (1.0-u)*(1.0-u)*n1[0] + 2.0*u*(1.0-u)*bn[0] + u*u*n2[0];
635 n[1] = (1.0-u)*(1.0-u)*n1[1] + 2.0*u*(1.0-u)*bn[1] + u*u*n2[1];
636 n[2] = (1.0-u)*(1.0-u)*n1[2] + 2.0*u*(1.0-u)*bn[2] + u*u*n2[2];
637 dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
646 memcpy(cold,c,3*
sizeof(
double));
647 memcpy(nold,n,3*
sizeof(
double));
648 memcpy(m2old,m2,6*
sizeof(
double));
663 fprintf(stderr,
"\n ## Warning: %s: at least 1 impossible metric"
664 " interpolation.\n", __func__);
667 fprintf(stderr,
" points: %"MMG5_PRId
": %e %e %e (tag %s)\n",MMG5_indPt(
mesh,ip1),
670 fprintf(stderr,
" %"MMG5_PRId
": %e %e %e (tag %s)\n",MMG5_indPt(
mesh,ip2),
674 fprintf(stderr,
"\n BEFORE ROTATION:\n");
675 fprintf(stderr,
"\n metric %e %e %e %e %e %e\n",
676 m1old[0],m1old[1],m1old[2],m1old[3],m1old[4],m1old[5]);
677 fprintf(stderr,
" %e %e %e %e %e %e\n",
678 m2old[0],m2old[1],m2old[2],m2old[3],m2old[4],m2old[5]);
680 fprintf(stderr,
"\n AFTER ROTATION (to %e %e %e):\n",n[0],n[1],n[2]);
681 fprintf(stderr,
"\n metric %e %e %e %e %e %e\n",
682 m1[0],m1[1],m1[2],m1[3],m1[4],m1[5]);
683 fprintf(stderr,
" %e %e %e %e %e %e\n",
684 m2[0],m2[1],m2[2],m2[3],m2[4],m2[5]);
693 m1old[0] = mr[0]*r[0][0]*r[0][0] + mr[3]*r[1][0]*r[1][0] + mr[5]*r[2][0]*r[2][0]
694 + 2.*( mr[1]*r[0][0]*r[1][0] + mr[2]*r[0][0]*r[2][0] + mr[4]*r[1][0]*r[2][0] );
695 m1old[3] = mr[0]*r[0][1]*r[0][1] + mr[3]*r[1][1]*r[1][1] + mr[5]*r[2][1]*r[2][1]
696 + 2.*( mr[1]*r[0][1]*r[1][1] + mr[2]*r[0][1]*r[2][1] + mr[4]*r[1][1]*r[2][1] );
697 m1old[5] = mr[0]*r[0][2]*r[0][2] + mr[3]*r[1][2]*r[1][2] + mr[5]*r[2][2]*r[2][2]
698 + 2.*( mr[1]*r[0][2]*r[1][2] + mr[2]*r[0][2]*r[2][2] + mr[4]*r[1][2]*r[2][2] );
700 m1old[1] = mr[0]*r[0][0]*r[0][1] + mr[1]*r[0][0]*r[1][1] + mr[2]*r[0][0]*r[2][1]
701 + mr[1]*r[1][0]*r[0][1] + mr[3]*r[1][0]*r[1][1] + mr[4]*r[1][0]*r[2][1]
702 + mr[2]*r[2][0]*r[0][1] + mr[4]*r[2][0]*r[1][1] + mr[5]*r[2][0]*r[2][1];
703 m1old[2] = mr[0]*r[0][0]*r[0][2] + mr[1]*r[0][0]*r[1][2] + mr[2]*r[0][0]*r[2][2]
704 + mr[1]*r[1][0]*r[0][2] + mr[3]*r[1][0]*r[1][2] + mr[4]*r[1][0]*r[2][2]
705 + mr[2]*r[2][0]*r[0][2] + mr[4]*r[2][0]*r[1][2] + mr[5]*r[2][0]*r[2][2];
706 m1old[4] = mr[0]*r[0][1]*r[0][2] + mr[1]*r[0][1]*r[1][2] + mr[2]*r[0][1]*r[2][2]
707 + mr[1]*r[1][1]*r[0][2] + mr[3]*r[1][1]*r[1][2] + mr[4]*r[1][1]*r[2][2]
708 + mr[2]*r[2][1]*r[0][2] + mr[4]*r[2][1]*r[1][2] + mr[5]*r[2][1]*r[2][2];
710 memcpy(mr,m1old,6*
sizeof(
double));
const char * MMG5_Get_tagName(uint16_t tag)
int MMG5_eigenv3d(int symmat, double *mat, double lambda[3], double v[3][3])
Find eigenvalues and vectors of a 3x3 matrix.
int MMG5_interp_iso(double *ma, double *mb, double *mp, double t)
int MMG5_mmgIntmet33_ani(double *m, double *n, double *mr, double s)
int MMG5_interpreg_ani(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pTria pt, int8_t i, double s, double mr[6])
int MMG5_intridmet(MMG5_pMesh mesh, MMG5_pSol met, MMG5_int ip1, MMG5_int ip2, double s, double v[3], double mr[6])
static const uint8_t MMG5_iprv2[3]
int MMG5_rmtr(double r[3][3], double m[6], double mr[6])
static const uint8_t MMG5_inxt2[6]
int MMG5_nortri(MMG5_pMesh mesh, MMG5_pTria pt, double *n)
int MMG5_rotmatrix(double n[3], double r[3][3])
int MMG5_invmatg(double m[9], double mi[9])
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.