53 double lambda[],
double v[]) {
61 for( i = 0; i < dim; i++ ) {
63 for( j = i; j < dim; j++ ) {
74 for( k = 0; k < dim; k++ ) {
75 m[ij] += lambda[k]*v[k*dim+i]*v[k*dim+j];
81 assert( ij == (dim+1)*dim/2 );
101 double lambda[],
double v[],
double iv[]){
109 for( i = 0; i < dim; i++ ) {
111 for( j = 0; j < dim; j++ ) {
122 for( k = 0; k < dim; k++ ) {
123 m[ij] += lambda[k]*v[k*dim+i]*iv[j*dim+k];
129 assert( ij == dim*dim );
238 double lambda[2],v[2][2];
251 }
else if( dim == 3 ) {
252 double lambda[3],v[3][3];
280 double *swap,int8_t *perm ) {
283 for( int8_t i = 0; i < dim; i++ )
303 double mnum[3],lambdanum[2],vpnum[2][2];
304 double swap[2],maxerr,err;
305 int8_t perm[2] = {0,1};
314 fprintf(stderr,
" ## Error matrix recomposition: in function %s, max error %e\n",
330 fprintf(stderr,
" ## Error matrix eigenvalues: in function %s, max error %e\n",
337 for( int8_t i = 0; i < 2; i++ ) {
339 for( int8_t j = 0; j < 2; j++ )
340 err += vpex[i][j] * vpnum[i][j];
342 maxerr =
MG_MAX(maxerr,err);
345 fprintf(stderr,
" ## Error matrix eigenvectors: in function %s, max error %e\n",
356 fprintf(stderr,
" ## Error matrix eigendecomposition and recomposition: in function %s, max error %e\n",
380 double vpex[][2],
double ivpex[][2]) {
381 double mnum[4],lambdanum[2],vpnum[2][2];
382 double swap[2],maxerr,err;
383 int8_t perm[2] = {0,1};
392 fprintf(stderr,
" ## Error matrix recomposition: in function %s, max error %e\n",
408 fprintf(stderr,
" ## Error matrix eigenvalues: in function %s, max error %e\n",
415 for( int8_t i = 0; i < 2; i++ ) {
417 for( int8_t j = 0; j < 2; j++ )
418 err += vpex[i][j] * vpnum[i][j];
420 maxerr =
MG_MAX(maxerr,err);
423 fprintf(stderr,
" ## Error matrix eigenvectors: in function %s, max error %e\n",
434 fprintf(stderr,
" ## Error matrix eigendecomposition and recomposition: in function %s, max error %e\n",
458 double mnum[6],lambdanum[3],vpnum[3][3];
459 double swap[3],maxerr,err;
460 int8_t perm[3] = {0,1,2};
469 fprintf(stderr,
" ## Error matrix recomposition: in function %s, max error %e\n",
485 fprintf(stderr,
" ## Error matrix eigenvalues: in function %s, max error %e\n",
493 for( int8_t i = 0; i < 2; i++ ) {
494 for( int8_t j = i+1; j < 3; j++ ) {
496 for( int8_t k = 0; k < 3; k++ )
497 err += vpnum[i][k] * vpnum[j][k];
499 maxerr =
MG_MAX(maxerr,err);
503 fprintf(stderr,
" ## Error matrix eigenvectors orthogonality: in function %s, max error %e\n",
514 fprintf(stderr,
" ## Error matrix eigendecomposition and recomposition: in function %s, max error %e\n",
537 double vpex[][3],
double ivpex[][3]) {
538 double mnum[9],lambdanum[3],vpnum[3][3];
539 double swap[3],maxerr;
540 int8_t perm[3] = {0,1,2};
549 fprintf(stderr,
" ## Error matrix recomposition: in function %s, max error %e\n",
565 fprintf(stderr,
" ## Error matrix eigenvalues: in function %s, max error %e\n",
578 fprintf(stderr,
" ## Error matrix eigendecomposition and recomposition: in function %s, max error %e\n",
602 double dv,
double dn,
double m[6]) {
605 u[0] = n[1]*t[2] - n[2]*t[1];
606 u[1] = n[2]*t[0] - n[0]*t[2];
607 u[2] = n[0]*t[1] - n[1]*t[0];
610 r[0][0] = t[0]; r[0][1] = u[0]; r[0][2] = n[0];
611 r[1][0] = t[1]; r[1][1] = u[1]; r[1][2] = n[1];
612 r[2][0] = t[2]; r[2][1] = u[2]; r[2][2] = n[2];
614 m[0] = dtan*r[0][0]*r[0][0] + dv*r[0][1]*r[0][1] + dn*r[0][2]*r[0][2];
615 m[1] = dtan*r[0][0]*r[1][0] + dv*r[0][1]*r[1][1] + dn*r[0][2]*r[1][2];
616 m[2] = dtan*r[0][0]*r[2][0] + dv*r[0][1]*r[2][1] + dn*r[0][2]*r[2][2];
617 m[3] = dtan*r[1][0]*r[1][0] + dv*r[1][1]*r[1][1] + dn*r[1][2]*r[1][2];
618 m[4] = dtan*r[1][0]*r[2][0] + dv*r[1][1]*r[2][1] + dn*r[1][2]*r[2][2];
619 m[5] = dtan*r[2][0]*r[2][0] + dv*r[2][1]*r[2][1] + dn*r[2][2]*r[2][2];
637 double lambda[2],vp[2][2],siz,isqhmin;
642 for (i=0; i<2; i++) {
643 siz = n[0]*vp[i][0]*vp[i][0] + 2.0*n[1]*vp[i][0]*vp[i][1]
644 + n[2]*vp[i][1]*vp[i][1];
645 lambda[i] =
MG_MAX(lambda[i],siz);
646 lambda[i] =
MG_MIN(lambda[i],isqhmin);
648 mr[0] = lambda[0]*vp[0][0]*vp[0][0] + lambda[1]*vp[1][0]*vp[1][0];
649 mr[1] = lambda[0]*vp[0][0]*vp[0][1] + lambda[1]*vp[1][0]*vp[1][1];
650 mr[2] = lambda[0]*vp[0][1]*vp[0][1] + lambda[1]*vp[1][1]*vp[1][1];
677 double ux,
double uy,
double uz,
double mr[6],
681 double ps1,ps2,*n1,*n2,*t,*m,dv,dn,u[3];
689 assert ( t[0]*t[0] + t[1]*t[1] + t[2]*t[2] > 0. &&
"Null tangent");
697 ps1 = ux*n1[0] + uy*n1[1] + uz*n1[2];
698 ps2 = ux*n2[0] + uy*n2[1] + uz*n2[2];
700 if ( fabs(ps2)<fabs(ps1) ) {
715 assert ( n1[0]*n1[0] + n1[1]*n1[1] + n1[2]*n1[2] > 0. &&
"Null normal");
717 u[0] = n1[1]*t[2] - n1[2]*t[1];
718 u[1] = n1[2]*t[0] - n1[0]*t[2];
719 u[2] = n1[0]*t[1] - n1[1]*t[0];
723 r[0][0] = t[0]; r[0][1] = u[0]; r[0][2] = n1[0];
724 r[1][0] = t[1]; r[1][1] = u[1]; r[1][2] = n1[1];
725 r[2][0] = t[2]; r[2][1] = u[2]; r[2][2] = n1[2];
727 mr[0] = m[0]*r[0][0]*r[0][0] + dv*r[0][1]*r[0][1] + dn*r[0][2]*r[0][2];
728 mr[1] = m[0]*r[0][0]*r[1][0] + dv*r[0][1]*r[1][1] + dn*r[0][2]*r[1][2];
729 mr[2] = m[0]*r[0][0]*r[2][0] + dv*r[0][1]*r[2][1] + dn*r[0][2]*r[2][2];
730 mr[3] = m[0]*r[1][0]*r[1][0] + dv*r[1][1]*r[1][1] + dn*r[1][2]*r[1][2];
731 mr[4] = m[0]*r[1][0]*r[2][0] + dv*r[1][1]*r[2][1] + dn*r[1][2]*r[2][2];
732 mr[5] = m[0]*r[2][0]*r[2][0] + dv*r[2][1]*r[2][1] + dn*r[2][2]*r[2][2];
752 double mr[6],
double r[3][3] ) {
755 double ps1,ps2,*n1,*n2,*t,*m,dv,dn,u[3];
768 ps1 = nt[0]*n1[0] + nt[1]*n1[1] + nt[2]*n1[2];
769 ps2 = nt[0]*n2[0] + nt[1]*n2[1] + nt[2]*n2[2];
771 if ( fabs(ps2) > fabs(ps1) ) {
783 u[0] = n1[1]*t[2] - n1[2]*t[1];
784 u[1] = n1[2]*t[0] - n1[0]*t[2];
785 u[2] = n1[0]*t[1] - n1[1]*t[0];
789 r[0][0] = t[0]; r[0][1] = u[0]; r[0][2] = n1[0];
790 r[1][0] = t[1]; r[1][1] = u[1]; r[1][2] = n1[1];
791 r[2][0] = t[2]; r[2][1] = u[2]; r[2][2] = n1[2];
793 mr[0] = m[0]*r[0][0]*r[0][0] + dv*r[0][1]*r[0][1] + dn*r[0][2]*r[0][2];
794 mr[1] = m[0]*r[0][0]*r[1][0] + dv*r[0][1]*r[1][1] + dn*r[0][2]*r[1][2];
795 mr[2] = m[0]*r[0][0]*r[2][0] + dv*r[0][1]*r[2][1] + dn*r[0][2]*r[2][2];
796 mr[3] = m[0]*r[1][0]*r[1][0] + dv*r[1][1]*r[1][1] + dn*r[1][2]*r[1][2];
797 mr[4] = m[0]*r[1][0]*r[2][0] + dv*r[1][1]*r[2][1] + dn*r[1][2]*r[2][2];
798 mr[5] = m[0]*r[2][0]*r[2][0] + dv*r[2][1]*r[2][1] + dn*r[2][2]*r[2][2];
815 double det,imn[4],lambda[2],vp[2][2],dm[2],dn[2],d0,d1,ip[4];
816 double isqhmin,isqhmax;
817 static int8_t mmgWarn0 = 0;
824 det = m[0]*m[2] - m[1]*m[1];
827 fprintf(stderr,
"\n ## Warning: %s: null metric det : %E \n",__func__,det);
834 imn[0] = det * ( m[2]*n[0] - m[1]*n[1]);
835 imn[1] = det * ( m[2]*n[1] - m[1]*n[2]);
836 imn[2] = det * (-m[1]*n[0] + m[0]*n[1]);
837 imn[3] = det * (-m[1]*n[1] + m[0]*n[2]);
845 fprintf(stderr,
"\n ## Warning: %s: at least 1 failing"
846 " simultaneous reduction.\n",__func__);
866 dn[0] =
MG_MAX(dm[0],lambda[0]*dm[0]);
868 dn[1] =
MG_MAX(dm[1],lambda[0]*dm[1]);
872 mr[0] = dn[0]*vp[0][0]*vp[0][0] + dn[1]*vp[1][0]*vp[1][0];
873 mr[1] = dn[0]*vp[0][0]*vp[0][1] + dn[1]*vp[1][0]*vp[1][1];
874 mr[2] = dn[0]*vp[0][1]*vp[0][1] + dn[1]*vp[1][1]*vp[1][1];
881 else if( order == 1 ) {
884 dm[0] = m[0]*vp[0][0]*vp[0][0] + 2.0*m[1]*vp[0][0]*vp[0][1] + m[2]*vp[0][1]*vp[0][1];
885 dm[1] = m[0]*vp[1][0]*vp[1][0] + 2.0*m[1]*vp[1][0]*vp[1][1] + m[2]*vp[1][1]*vp[1][1];
886 dn[0] = n[0]*vp[0][0]*vp[0][0] + 2.0*n[1]*vp[0][0]*vp[0][1] + n[2]*vp[0][1]*vp[0][1];
887 dn[1] = n[0]*vp[1][0]*vp[1][0] + 2.0*n[1]*vp[1][0]*vp[1][1] + n[2]*vp[1][1]*vp[1][1];
897 det = vp[0][0]*vp[1][1] - vp[0][1]*vp[1][0];
898 if ( fabs(det) <
MMG5_EPS )
return 0;
901 ip[0] = vp[1][1]*det;
902 ip[1] = -vp[1][0]*det;
903 ip[2] = -vp[0][1]*det;
904 ip[3] = vp[0][0]*det;
906 mr[0] = d0*ip[0]*ip[0] + d1*ip[2]*ip[2];
907 mr[1] = d0*ip[0]*ip[1] + d1*ip[2]*ip[3];
908 mr[2] = d0*ip[1]*ip[1] + d1*ip[3]*ip[3];
925 double vp[3][3],dm[3],dn[3],d[3],ivp[3][3];
926 double isqhmin,isqhmax;
937 for( i = 0; i < 3; i++ ) {
938 d[i] =
MG_MAX(dm[i],dn[i]);
963 double m[3] = { 508., -504, 502.};
964 double n[3] = {4020.,-2020.,1020.};
965 double intex[3] = {4500.,-2500.,1500.};
966 double intnum[3],maxerr;
975 fprintf(stderr,
" ## Error metric intersection: in function %s, line %d, max error %e\n",
976 __func__,__LINE__,maxerr);
982 for( int8_t it = 0; it < 20; it++ ) {
991 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
992 __func__,__LINE__,it,maxerr);
1004 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1005 __func__,__LINE__,it,maxerr);
1017 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1018 __func__,__LINE__,it,maxerr);
1030 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1031 __func__,__LINE__,it,maxerr);
1048 double m[6] = {111./2.,-109./2., 89./2.,111./2.,-91./2.,111./2.};
1049 double n[6] = {409./2.,-393./2.,-407./2.,409./2.,391./2.,409./2.};
1050 double intex[6] = {254.,-246.,-154.,254.,146.,254.};
1051 double intnum[6],maxerr;
1060 fprintf(stderr,
" ## Error metric intersection: in function %s, line %d, max error %e\n",
1061 __func__,__LINE__,maxerr);
1067 for( int8_t it = 0; it < 20; it++ ) {
1076 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1077 __func__,__LINE__,it,maxerr);
1089 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1090 __func__,__LINE__,it,maxerr);
1102 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1103 __func__,__LINE__,it,maxerr);
1115 fprintf(stderr,
" ## Error metric re-intersection: in function %s, line %d, iteration %d, max error %e\n",
1116 __func__,__LINE__,it,maxerr);
1143 double hu,isqhmin,isqhmax,dd,alpha1,alpha2,alpha3,u[3];
1144 double lambda[3],vp[3][3];
1145 double *m,*n1,*n2,*t,r[3][3],mrot[6],mr[3],mtan[3],metan[3];
1148 static int8_t mmgWarn=0, mmgWarn1=0, mmgWarn2=0;
1183 fprintf(stderr,
"\n ## Warning: %s: Unable to diagonalize at least"
1184 " 1 metric.\n",__func__);
1191 for( i = 0; i < 3; i++ ) {
1192 hu =
MG_MAX(hu,lambda[i]);
1201 m[0] = m[3] = m[5] = hu;
1208 hu = me[0]*t[0]*t[0] + me[3]*t[1]*t[1] + me[5]*t[2]*t[2] \
1209 + 2.0*me[1]*t[0]*t[1] + 2.0*me[2]*t[0]*t[2] + 2.0*me[4]*t[1]*t[2];
1221 u[0] = n1[1]*t[2] - n1[2]*t[1];
1222 u[1] = n1[2]*t[0] - n1[0]*t[2];
1223 u[2] = n1[0]*t[1] - n1[1]*t[0];
1224 dd = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
1226 dd = 1.0 / sqrt(dd);
1232 hu = me[0]*u[0]*u[0] + me[3]*u[1]*u[1] + me[5]*u[2]*u[2] \
1233 + 2.0*me[1]*u[0]*u[1] + 2.0*me[2]*u[0]*u[2] + 2.0*me[4]*u[1]*u[2];
1240 u[0] = n2[1]*t[2] - n2[2]*t[1];
1241 u[1] = n2[2]*t[0] - n2[0]*t[2];
1242 u[2] = n2[0]*t[1] - n2[1]*t[0];
1243 dd = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
1245 dd = 1.0 / sqrt(dd);
1251 hu = me[0]*u[0]*u[0] + me[3]*u[1]*u[1] + me[5]*u[2]*u[2] \
1252 + 2.0*me[1]*u[0]*u[1] + 2.0*me[2]*u[0]*u[2] + 2.0*me[4]*u[1]*u[2];
1260 hu = me[0]*n1[0]*n1[0] + me[3]*n1[1]*n1[1] + me[5]*n1[2]*n1[2]
1261 + 2.0*me[1]*n1[0]*n1[1] + 2.0*me[2]*n1[0]*n1[2] + 2.0*me[4]*n1[1]*n1[2];
1268 hu = me[0]*n2[0]*n2[0] + me[3]*n2[1]*n2[1] + me[5]*n2[2]*n2[2]
1269 + 2.0*me[1]*n2[0]*n2[1] + 2.0*me[2]*n2[0]*n2[2] + 2.0*me[4]*n2[1]*n2[2];
1294 fprintf(stderr,
"\n ## Warning: %s: impossible metric intersection:"
1295 " surfacic metric skipped.\n",__func__);
1310 mtan[0] = mr[0]*r[0][0] + mr[1]*r[1][0];
1311 mtan[1] = mr[0]*r[0][1] + mr[1]*r[1][1];
1312 mtan[2] = mr[0]*r[0][2] + mr[1]*r[1][2];
1313 metan[0] = mr[1]*r[0][0] + mr[2]*r[1][0];
1314 metan[1] = mr[1]*r[0][1] + mr[2]*r[1][1];
1315 metan[2] = mr[1]*r[0][2] + mr[2]*r[1][2];
1317 alpha1 = r[2][0]*mrot[5];
1318 alpha2 = r[2][1]*mrot[5];
1319 alpha3 = r[2][2]*mrot[5];
1321 m[0] = r[0][0] * mtan[0] + r[1][0] * metan[0] + r[2][0]*alpha1;
1322 m[1] = r[0][0] * mtan[1] + r[1][0] * metan[1] + r[2][0]*alpha2;
1323 m[2] = r[0][0] * mtan[2] + r[1][0] * metan[2] + r[2][0]*alpha3;
1324 m[3] = r[0][1] * mtan[1] + r[1][1] * metan[1] + r[2][1]*alpha2;
1325 m[4] = r[0][1] * mtan[2] + r[1][1] * metan[2] + r[2][1]*alpha3;
1326 m[5] = r[0][2] * mtan[2] + r[1][2] * metan[2] + r[2][2]*alpha3;
1333 fprintf(stderr,
"\n ## Warning: %s: Unable to diagonalize at least"
1334 " 1 metric.\n",__func__);
1340 for (i=0; i<3; i++) {
1343 fprintf(stderr,
"\n ## Warning: %s: at least 1 wrong metric "
1344 "(eigenvalues : %e %e %e): surfacic metric skipped.\n",
1345 __func__,lambda[0],lambda[1],lambda[2]);
1356 lambda[i]=
MG_MIN(isqhmin,lambda[i]);
1357 lambda[i]=
MG_MAX(isqhmax,lambda[i]);
1360 m[0] = vp[0][0]*vp[0][0]*lambda[0] + vp[1][0]*vp[1][0]*lambda[1]
1361 + vp[2][0]*vp[2][0]*lambda[2];
1362 m[1] = vp[0][0]*vp[0][1]*lambda[0] + vp[1][0]*vp[1][1]*lambda[1]
1363 + vp[2][0]*vp[2][1]*lambda[2];
1364 m[2] = vp[0][0]*vp[0][2]*lambda[0] + vp[1][0]*vp[1][2]*lambda[1]
1365 + vp[2][0]*vp[2][2]*lambda[2];
1366 m[3] = vp[0][1]*vp[0][1]*lambda[0] + vp[1][1]*vp[1][1]*lambda[1]
1367 + vp[2][1]*vp[2][1]*lambda[2];
1368 m[4] = vp[0][1]*vp[0][2]*lambda[0] + vp[1][1]*vp[1][2]*lambda[1]
1369 + vp[2][1]*vp[2][2]*lambda[2];
1370 m[5] = vp[0][2]*vp[0][2]*lambda[0] + vp[1][2]*vp[1][2]*lambda[1]
1371 + vp[2][2]*vp[2][2]*lambda[2];
1390int MMG5_paratmet(
double c0[3],
double n0[3],
double m[6],
double c1[3],
double n1[3],
double mt[6]) {
1391 double r[3][3],mrot[6],mtan[3],lambda[2],vp[2][2],u[3],ps,ll;
1404 u[0] = r[0][0]*vp[0][0] + r[1][0]*vp[0][1];
1405 u[1] = r[0][1]*vp[0][0] + r[1][1]*vp[0][1];
1406 u[2] = r[0][2]*vp[0][0] + r[1][2]*vp[0][1];
1409 ps = u[0]*n1[0] + u[1]*n1[1] + u[2]*n1[2];
1413 ll = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
1415 ll = 1.0 / sqrt(ll);
1426 r[0][1] = n1[1]*u[2] - n1[2]*u[1];
1427 r[1][1] = n1[2]*u[0] - n1[0]*u[2];
1428 r[2][1] = n1[0]*u[1] - n1[1]*u[0];
1430 ll = r[0][1]*r[0][1] + r[1][1]*r[1][1] + r[2][1]*r[2][1];
1432 ll = 1.0 / sqrt(ll);
1442 mt[0] = lambda[0]*r[0][0]*r[0][0] + lambda[1]*r[0][1]*r[0][1]
1443 + mrot[5]*r[0][2]*r[0][2];
1445 mt[1] = lambda[0]*r[0][0]*r[1][0]
1446 + lambda[1]*r[0][1]*r[1][1] + mrot[5]*r[0][2]*r[1][2];
1448 mt[2] = lambda[0]*r[0][0]*r[2][0]
1449 + lambda[1]*r[0][1]*r[2][1] + mrot[5]*r[0][2]*r[2][2];
1451 mt[3] = lambda[0]*r[1][0]*r[1][0] + lambda[1]*r[1][1]*r[1][1]
1452 + mrot[5]*r[1][2]*r[1][2];
1454 mt[4] = lambda[0]*r[2][0]*r[1][0]
1455 + lambda[1]*r[2][1]*r[1][1] + mrot[5]*r[2][2]*r[1][2];
1457 mt[5] = lambda[0]*r[2][0]*r[2][0] + lambda[1]*r[2][1]*r[2][1]
1458 + mrot[5]*r[2][2]*r[2][2];
int MMG5_simred3d(MMG5_pMesh mesh, double *m, double *n, double dm[3], double dn[3], double vp[3][3])
int MMG5_eigensym(double m[3], double lambda[2], double vp[2][2])
int MMG5_eigenv3d(int symmat, double *mat, double lambda[3], double v[3][3])
Find eigenvalues and vectors of a 3x3 matrix.
int MMG5_eigenv2d(int symmat, double *mat, double lambda[2], double vp[2][2])
Find eigenvalues and vectors of a 2x2 matrix.
static void MMG5_simredmat(int8_t dim, double *m, double *dm, double *iv)
double MMG5_test_mat_error(int8_t nelem, double m1[], double m2[])
int MMG5_rmtr(double r[3][3], double m[6], double mr[6])
int MMG5_invmat33(double m[3][3], double mi[3][3])
int MMG5_rotmatrix(double n[3], double r[3][3])
void MMG5_nsort(int8_t, double *, int8_t *)
void MMG5_nperm(int8_t n, int8_t shift, int8_t stride, double *val, double *oldval, int8_t *perm)
int MMG5_invmat22(double m[2][2], double mi[2][2])
Structure to store vertices of an MMG mesh.
Structure to store surface vertices of an MMG mesh.