49inline void MMG5_nsort(int8_t n,
double *val,int8_t *perm){
53 for (i=0; i<n; i++) perm[i] = i;
56 for (j=i+1; j<n; j++) {
57 if ( val[perm[i]] > val[perm[j]] ) {
80inline void MMG5_nperm(int8_t n,int8_t shift,int8_t stride,
double *val,
double *oldval,int8_t *perm) {
83 for( i = 0; i < n; i++ )
84 oldval[i] = val[shift+i*stride];
86 for( i = 0; i < n; i++ ) {
88 val[shift+i*stride] = oldval[k];
107 dev = n1[0]*n2[0] + n1[1]*n2[1] + n1[2]*n2[2];
128 MMG5_int ip1,MMG5_int ip2, MMG5_int ip3,
double *n) {
130 double abx,aby,abz,acx,acy,acz;
137 abx = p2->
c[0] - p1->
c[0];
138 aby = p2->
c[1] - p1->
c[1];
139 abz = p2->
c[2] - p1->
c[2];
141 acx = p3->
c[0] - p1->
c[0];
142 acy = p3->
c[1] - p1->
c[1];
143 acz = p3->
c[2] - p1->
c[2];
145 n[0] = aby*acz - abz*acy;
146 n[1] = abz*acx - abx*acz;
147 n[2] = abx*acy - aby*acx;
162 MMG5_int ip1, ip2, ip3;
170 return n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
188 det = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
192 dd = 1.0 / sqrt(det);
222 for( int8_t i = 0; i < 2; i++ ) {
223 for( int8_t j = i+1; j < 3; j++ ) {
237 double a[3][3] = {{1.,2.,3.},
240 double b[3][3] = {{1.,4.,7.},
249 fprintf(stderr,
" ## Error matrix transposition: in function %s, max error %e\n",
267 for( int8_t i = 0; i < dim; i++ )
268 *result += a[i]*b[i];
277 double a[4] = {1.0, 2.0, 3.0, 4.0};
278 double b[4] = {1.0, 0.5, 1./3., 0.25};
283 err = fabs(cex-cnum);
285 fprintf(stderr,
" ## Error scalar product: in function %s, error %e\n",
301 result[0] = a[1]*b[2] - a[2]*b[1];
302 result[1] = a[2]*b[0] - a[0]*b[2];
303 result[2] = a[0]*b[1] - a[1]*b[0];
312 double a[3] = {1., 0., 0.};
313 double b[3] = {1./sqrt(2.),1./sqrt(2.),0.};
314 double cex[3] = {0.,0.,1./sqrt(2.)};
315 double cnum[3],maxerr;
321 fprintf(stderr,
" ## Error 3D cross product: in function %s, max error %e\n",
337void MMG5_mn(
double m[6],
double n[6],
double mn[9] ){
339 mn[0] = m[0]*n[0] + m[1]*n[1] + m[2]*n[2];
340 mn[1] = m[0]*n[1] + m[1]*n[3] + m[2]*n[4];
341 mn[2] = m[0]*n[2] + m[1]*n[4] + m[2]*n[5];
342 mn[3] = m[1]*n[0] + m[3]*n[1] + m[4]*n[2];
343 mn[4] = m[1]*n[1] + m[3]*n[3] + m[4]*n[4];
344 mn[5] = m[1]*n[2] + m[3]*n[4] + m[4]*n[5];
345 mn[6] = m[2]*n[0] + m[4]*n[1] + m[5]*n[2];
346 mn[7] = m[2]*n[1] + m[4]*n[3] + m[5]*n[4];
347 mn[8] = m[2]*n[2] + m[4]*n[4] + m[5]*n[5];
358 double m[6] = {1.,2.,3.,4.,5.,6.};
359 double n[6] = {2.,3.,4.,5.,6.,7.};
360 double mnex[9] = {20., 31., 37.,
363 double nmex[9] = {20., 36., 45.,
366 double prodnum[9],maxerr;
374 fprintf(stderr,
" ## Error 3x3 symmetric matrix product m*n: in function %s, max error %e\n",
386 fprintf(stderr,
" ## Error 3x3 symmetric matrix product n*m: in function %s, max error %e\n",
405inline int MMG5_rmtr(
double r[3][3],
double m[6],
double mr[6]){
408 n[0][0] = m[0]*r[0][0] + m[1]*r[0][1] + m[2]*r[0][2];
409 n[1][0] = m[1]*r[0][0] + m[3]*r[0][1] + m[4]*r[0][2];
410 n[2][0] = m[2]*r[0][0] + m[4]*r[0][1] + m[5]*r[0][2];
412 n[0][1] = m[0]*r[1][0] + m[1]*r[1][1] + m[2]*r[1][2];
413 n[1][1] = m[1]*r[1][0] + m[3]*r[1][1] + m[4]*r[1][2];
414 n[2][1] = m[2]*r[1][0] + m[4]*r[1][1] + m[5]*r[1][2];
416 n[0][2] = m[0]*r[2][0] + m[1]*r[2][1] + m[2]*r[2][2];
417 n[1][2] = m[1]*r[2][0] + m[3]*r[2][1] + m[4]*r[2][2];
418 n[2][2] = m[2]*r[2][0] + m[4]*r[2][1] + m[5]*r[2][2];
420 mr[0] = r[0][0]*n[0][0] + r[0][1]*n[1][0] + r[0][2]*n[2][0];
421 mr[1] = r[0][0]*n[0][1] + r[0][1]*n[1][1] + r[0][2]*n[2][1];
422 mr[2] = r[0][0]*n[0][2] + r[0][1]*n[1][2] + r[0][2]*n[2][2];
423 mr[3] = r[1][0]*n[0][1] + r[1][1]*n[1][1] + r[1][2]*n[2][1];
424 mr[4] = r[1][0]*n[0][2] + r[1][1]*n[1][2] + r[1][2]*n[2][2];
425 mr[5] = r[2][0]*n[0][2] + r[2][1]*n[1][2] + r[2][2]*n[2][2];
436 double m[6] = {111./2.,-109./2., 89./2.,111./2.,-91./2.,111./2.};
437 double r[3][3] = {{1./sqrt(2.),1./sqrt(2.), 0.},
438 { 0.,1./sqrt(2.),1./sqrt(2.)},
439 {1./sqrt(2.), 0.,1./sqrt(2.)}};
440 double outex[6] = {1., 0., 0., 10., 0., 100.};
441 double outnum[6],maxerr;
450 fprintf(stderr,
" ## Error linear transformation of symmetric matrix: in function %s, max error %e\n",
468 double aa,bb,ab,ll,l,cosalpha,sinalpha;
475 sinalpha = sqrt(1.0-
MG_MIN(1.0,cosalpha*cosalpha));
480 r[0][0] = 1.0 ; r[0][1] = 0.0 ; r[0][2] = 0.0;
481 r[1][0] = 0.0 ; r[1][1] = 1.0 ; r[1][2] = 0.0;
482 r[2][0] = 0.0 ; r[2][1] = 0.0 ; r[2][2] = 1.0;
485 r[0][0] = -1.0 ; r[0][1] = 0.0 ; r[0][2] = 0.0;
486 r[1][0] = 0.0 ; r[1][1] = 1.0 ; r[1][2] = 0.0;
487 r[2][0] = 0.0 ; r[2][1] = 0.0 ; r[2][2] = -1.0;
493 r[0][0] = (aa*cosalpha + bb)/ll;
494 r[0][1] = ab*(cosalpha-1)/ll;
495 r[0][2] = -n[0]*sinalpha/l;
497 r[1][1] = (bb*cosalpha + aa)/ll;
498 r[1][2] = -n[1]*sinalpha/l;
499 r[2][0] = n[0]*sinalpha/l;
500 r[2][1] = n[1]*sinalpha/l;
513 double n[3] = {1./sqrt(1000101.),1000./sqrt(1000101.),10./sqrt(1000101.)};
514 double idex[6] = {1.,0.,0.,1.,0.,1.};
515 double ezex [3] = {0.,0.,1.};
516 double R[3][3],idnum[6],eznum[3],maxerr;
525 for( int8_t i = 0; i < 3; i++ ) {
527 for( int8_t j = 0; j < 3; j++ )
528 eznum[i] += R[i][j]*n[j];
534 fprintf(stderr,
" ## Error vector rotation: in function %s, max error %e\n",
547 fprintf(stderr,
" ## Error rotation matrix orthonormality: in function %s, max error %e\n",
563 double aa,bb,cc,det,vmax,maxx;
569 if( maxx > vmax ) vmax = maxx;
571 if( maxx > vmax ) vmax = maxx;
576 mi[1] = mi[2] = mi[4] = 0.0;
582 for (k=1; k<6; k++) {
584 if ( maxx > vmax ) vmax = maxx;
586 if ( vmax == 0.0 )
return 0;
589 aa = m[3]*m[5] - m[4]*m[4];
590 bb = m[4]*m[2] - m[1]*m[5];
591 cc = m[1]*m[4] - m[2]*m[3];
592 det = m[0]*aa + m[1]*bb + m[2]*cc;
599 mi[3] = (m[0]*m[5] - m[2]*m[2])*det;
600 mi[4] = (m[1]*m[2] - m[0]*m[4])*det;
601 mi[5] = (m[0]*m[3] - m[1]*m[1])*det;
614 double aa,bb,cc,det,vmax,maxx;
619 for (k=1; k<9; k++) {
621 if ( maxx > vmax ) vmax = maxx;
623 if ( vmax == 0.0 )
return 0;
626 aa = m[4]*m[8] - m[5]*m[7];
627 bb = m[5]*m[6] - m[3]*m[8];
628 cc = m[3]*m[7] - m[4]*m[6];
629 det = m[0]*aa + m[1]*bb + m[2]*cc;
636 mi[1] = (m[2]*m[7] - m[1]*m[8])*det;
637 mi[4] = (m[0]*m[8] - m[2]*m[6])*det;
638 mi[7] = (m[1]*m[6] - m[0]*m[7])*det;
639 mi[2] = (m[1]*m[5] - m[2]*m[4])*det;
640 mi[5] = (m[2]*m[3] - m[0]*m[5])*det;
641 mi[8] = (m[0]*m[4] - m[1]*m[3])*det;
654 double aa,bb,cc,det,vmax,maxx;
658 vmax = fabs(m[0][0]);
659 for (k=0; k<3; k++) {
660 for (l=0; l<3; l++) {
661 maxx = fabs(m[k][l]);
662 if ( maxx > vmax ) vmax = maxx;
665 if ( vmax == 0.0 )
return 0;
669 vmax = fabs(m[1][0]);
670 maxx = fabs(m[2][0]);
671 if( maxx > vmax ) vmax = maxx;
672 maxx = fabs(m[2][1]);
673 if( maxx > vmax ) vmax = maxx;
675 maxx = fabs(m[0][1]);
676 if( maxx > vmax ) vmax = maxx;
677 maxx = fabs(m[0][2]);
678 if( maxx > vmax ) vmax = maxx;
679 maxx = fabs(m[1][2]);
680 if( maxx > vmax ) vmax = maxx;
683 mi[0][0] = 1./m[0][0];
684 mi[1][1] = 1./m[1][1];
685 mi[2][2] = 1./m[2][2];
686 mi[1][0] = mi[0][1] = mi[2][0] = mi[0][2] = mi[1][2] = mi[2][1] = 0.0;
691 aa = m[1][1]*m[2][2] - m[2][1]*m[1][2];
692 bb = m[2][1]*m[0][2] - m[0][1]*m[2][2];
693 cc = m[0][1]*m[1][2] - m[1][1]*m[0][2];
694 det = m[0][0]*aa + m[1][0]*bb + m[2][0]*cc;
701 mi[1][0] = (m[2][0]*m[1][2] - m[1][0]*m[2][2])*det;
702 mi[1][1] = (m[0][0]*m[2][2] - m[2][0]*m[0][2])*det;
703 mi[1][2] = (m[1][0]*m[0][2] - m[0][0]*m[1][2])*det;
704 mi[2][0] = (m[1][0]*m[2][1] - m[2][0]*m[1][1])*det;
705 mi[2][1] = (m[2][0]*m[0][1] - m[0][0]*m[2][1])*det;
706 mi[2][2] = (m[0][0]*m[1][1] - m[1][0]*m[0][1])*det;
712 res[0][0] = m[0][0] * mi[0][0] + m[0][1] * mi[1][0] + m[0][2] * mi[2][0];
713 res[0][1] = m[0][0] * mi[0][1] + m[0][1] * mi[1][1] + m[0][2] * mi[2][1];
714 res[0][2] = m[0][0] * mi[0][2] + m[0][1] * mi[1][2] + m[0][2] * mi[2][2];
716 res[1][0] = m[1][0] * mi[0][0] + m[1][1] * mi[1][0] + m[1][2] * mi[2][0];
717 res[1][1] = m[1][0] * mi[0][1] + m[1][1] * mi[1][1] + m[1][2] * mi[2][1];
718 res[1][2] = m[1][0] * mi[0][2] + m[1][1] * mi[1][2] + m[1][2] * mi[2][2];
720 res[2][0] = m[2][0] * mi[0][0] + m[2][1] * mi[1][0] + m[2][2] * mi[2][0];
721 res[2][1] = m[2][0] * mi[0][1] + m[2][1] * mi[1][1] + m[2][2] * mi[2][1];
722 res[2][2] = m[2][0] * mi[0][2] + m[2][1] * mi[1][2] + m[2][2] * mi[2][2];
725 assert ( ( fabs(res[0][0]-1.) <
MMG5_EPS ) &&
726 ( fabs(res[1][1]-1.) <
MMG5_EPS ) &&
727 ( fabs(res[2][2]-1.) <
MMG5_EPS ) &&
731 ( fabs(res[2][1]) <
MMG5_EPS ) &&
"Matrix inversion" );
748 det = m[0][0]*m[1][1] - m[0][1]*m[1][0];
749 if ( fabs(det) <
MMG5_EPS )
return 0;
752 mi[0][0] = m[1][1]*det;
753 mi[0][1] = -m[0][1]*det;
754 mi[1][0] = -m[1][0]*det;
755 mi[1][1] = m[0][0]*det;
770 double ia[6],as[6],det,m;
776 m =
MG_MIN ( fabs(a[3]), m );
777 m =
MG_MIN ( fabs(a[5]), m );
792 det = as[0]*(as[3]*as[5]-as[4]*as[4]) - as[1]*(as[1]*as[5]-as[2]*as[4]) \
793 + as[2]*(as[1]*as[4]-as[2]*as[3]);
800 ia[0] = (as[3]*as[5]-as[4]*as[4]);
801 ia[1] = - (as[1]*as[5]-as[2]*as[4]);
802 ia[2] = (as[1]*as[4]-as[2]*as[3]);
803 ia[3] = (as[0]*as[5]-as[2]*as[2]);
804 ia[4] = -(as[0]*as[4]-as[2]*as[1]);
805 ia[5] = (as[0]*as[3]-as[1]*as[1]);
807 r[0] = ia[0]*b[0] + ia[1]*b[1] + ia[2]*b[2];
808 r[1] = ia[1]*b[0] + ia[3]*b[1] + ia[4]*b[2];
809 r[2] = ia[2]*b[0] + ia[4]*b[1] + ia[5]*b[2];
830 inm = fopen(fileName,
"w");
832 fprintf(inm,
"----------> %" MMG5_PRId
" TRIANGLES <----------\n",
mesh->
nt);
833 for(k=1; k<=
mesh->
nt; k++) {
835 fprintf(inm,
"num %" MMG5_PRId
" -> %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",k,ptt->
v[0],ptt->
v[1],
837 fprintf(inm,
"ref -> %" MMG5_PRId
"\n",ptt->
ref);
838 fprintf(inm,
"tag -> %d %d %d\n",ptt->
tag[0],ptt->
tag[1],ptt->
tag[2]);
839 fprintf(inm,
"edg -> %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",ptt->
edg[0],ptt->
edg[1],ptt->
edg[2]);
842 fprintf(inm,
"---------> END TRIANGLES <--------\n");
855#if (defined(__APPLE__) && defined(__MACH__))
859 if ( sysctlbyname(
"hw.memsize",&mem,&size,NULL,0) == -1)
862#elif defined(__unix__) || defined(__unix) || defined(unix)
863 mem = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
865#elif defined(_WIN16) || defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
866 MEMORYSTATUSEX status;
868 status.dwLength =
sizeof(status);
869 GlobalMemoryStatusEx(&status);
871 mem = status.ullTotalPhys & SIZE_MAX;
872 if (mem == status.ullTotalPhys)
return mem;
873 else return SIZE_MAX;
876 fprintf(stderr,
"\n ## Warning: %s: unknown system, recover of maximal memory"
877 " not available.\n",__func__);
900 printf(
" Maximum memory set to default value: %d MB.\n",
MMG5_MEMMAX);
907 fprintf(stderr,
"\n ## Warning: %s: asking for %d MB of memory ",
921 double m00,m10,m20,m01,m11,m21,det;
923 m00 = c1[0] - c0[0] ; m01 = c2[0] - c0[0];
924 m10 = c1[1] - c0[1] ; m11 = c2[1] - c0[1];
925 m20 = c1[2] - c0[2] ; m21 = c2[2] - c0[2];
926 det = v[0]*(m10*m21 - m20*m11) -v[1]*(m00*m21-m20*m01) + v[2]*(m00*m11-m10*m01);
932inline double MMG5_det4pt(
double c0[3],
double c1[3],
double c2[3],
double c3[3]) {
935 m[0] = c3[0] - c0[0];
936 m[1] = c3[1] - c0[1];
937 m[2] = c3[2] - c0[2];
972 double abx,aby,acx,acy;
983 aire = abx*acy - aby*acx;
998 for ( k=1; k<=
mesh->
np; k++ ) {
1000 if ( !
MG_VOK(ppt) )
continue;
1026 for ( k=1; k<=
mesh->
np; k++ ) {
1032 ppt->
tag &= ~MG_NUL;
1036 for ( k=1; k<=
mesh->
nt; k++ ) {
1038 if ( !
MG_EOK(pt) )
continue;
1040 for (i=0; i<3; i++) {
1042 ppt->
tag &= ~MG_NUL;
1048 if ( !
MG_EOK(pq) )
continue;
1050 for (i=0; i<4; i++) {
1052 ppt->
tag &= ~MG_NUL;
1076 MMG5_int k,*adja,iadr,iadrv;
1079 for ( k=1 ; k <=
mesh->
nt ; k++) {
1082 if ( !
MG_EOK(pt) )
continue;
1089 if ( pt->
ref == nsd )
continue;
1094 iadr = nfac*(k-1) + 1;
1096 for ( i=0; i<nfac; ++i ) {
1103 mesh->
adja[nfac*(iadrv-1)+1+iv] = 0;
1129 for( k = 0; k < nelem; k++ )
1130 maxerr =
MG_MAX(maxerr,fabs(m1[k] - m2[k]));
1141 double A[2][2] = {{4.0,2.0},{1.0,1.0}};
1142 double iAex[2][2] = {{0.5,-1.0},{-0.5,2.0}};
1152 fprintf(stderr,
" ## Error matrix inversion: in function %s, max error %e\n",
1166 double A[3][3] = {{7.0,2.0,1.0},{0.0,3.0,-1.0},{-3.0,4.0,-2.0}};
1167 double iAex[3][3] = {{-2.0,8.0,-5.0},{3.0,-11.0,7.0},{9.0,-34.0,21.0}};
1177 fprintf(stderr,
" ## Error matrix inversion: in function %s, max error %e\n",
Structure to store vertices of an MMG mesh.
Structure to store quadrangles of an MMG mesh.
Structure to store triangles of a MMG mesh.