45 char *p_in = (
char *) &sbin;
46 char *p = (
char *)&inv;
64 char *p_in = (
char *) &sbin;
65 char *p_out = (
char *) &out;
83 char *p_in = (
char *) &sbin;
84 char *p_out = (
char *) &out;
100 char *p_in = (
char *) &sbin;
101 char *p_out = (
char *) &out;
106 p_out[i] = p_in[7-i];
128 int *np,
int *na,
int* nt,
int *nq,
int *ne,
int *npr)
132 static char mmgWarn = 0;
149 for ( idx=0; idx<num; ++idx ) {
166 for ( idx=0; idx<num; ++idx ) {
184 for ( idx=0; idx<num; ++idx ) {
203 for ( idx=0; idx<num; ++idx ) {
222 for ( idx=0; idx<num; ++idx ){
243 for ( idx=0; idx<num; ++idx ){
253 fprintf(stderr,
"\n ## Warning: %s: unexpected type of element (%d) for at"
254 " least 1 element (%d).\n",__func__,typ,k);
280 long *posNodes,
long *posElts,
281 long **posNodeData,
int *bin,
int *iswp,
282 MMG5_int *nelts,
int *nsols) {
286 int k,nt,na,nq,ne,npr,np;
287 int typ,tagNum,posNodeDataSize,initPosNodeDataSize;
298 nt = na = nq = ne = npr = np = 0;
305 initPosNodeDataSize = posNodeDataSize = 20;
309 ptr = strstr(data,
".msh");
312 strcat(data,
".mshb");
313 if (!(*inm = fopen(data,
"rb")) ) {
314 ptr = strstr(data,
".msh");
317 if( !((*inm) = fopen(data,
"rb")) ) {
325 if( !((*inm) = fopen(data,
"rb")) ) {
333 fprintf(stdout,
" %%%% %s OPENED\n",data);
339 while(fscanf((*inm),
"%127s ",&chaine[0])!=EOF ) {
340 if(!strncmp(chaine,
"$MeshFormat",strlen(
"$MeshFormat"))) {
341 MMG_FSCANF((*inm),
"%4s %d %d ",verNum,bin,&ver);
343 if ( strncmp(verNum,
"2.2",3) ) {
344 fprintf(stderr,
"\n ## Warning: %s: format version (%s) may be not supported."
345 " Please, use the format version 2.2.\n",__func__,verNum);
350 assert(oneBin==16777216);
356 }
else if(!strncmp(chaine,
"$EndMeshFormat",strlen(
"EndMeshFormat"))) {
358 }
else if(!strncmp(chaine,
"$Nodes",strlen(
"$Nodes"))) {
360 *posNodes = ftell((*inm));
364 for ( k=1; k<=
mesh->
npi; ++k ) {
370 for ( k=1; k<=
mesh->
npi; ++k ) {
377 }
else if(!strncmp(chaine,
"$EndNodes",strlen(
"$EndNodes"))) {
379 }
else if(!strncmp(chaine,
"$NodeData",strlen(
"$NodeData"))) {
381 (*posNodeData)[*nsols] = ftell((*inm));
382 if ( ++(*nsols) == posNodeDataSize ) {
384 posNodeDataSize+initPosNodeDataSize,
385 long,
"posNodeData",
return -1);
386 posNodeDataSize += initPosNodeDataSize;
393 for ( k=0; k<tagNum; ++k ) {
394 if ( 0 != fscanf((*inm),
"%*[^\n]%*c") ) {
395 fputs (
"Reading error", stderr );
402 for ( k=0; k<tagNum; ++k ) {
403 if ( 0 != fscanf((*inm),
"%*[^\n]%*c") ) {
404 fputs (
"Reading error", stderr );
414 for ( k=3; k<tagNum; ++k ) {
418 for ( k=1; k<=np; ++k ) {
424 for ( k=1; k<=np; ++k ) {
431 }
else if(!strncmp(chaine,
"$EndNodeData",strlen(
"$EndNodeData"))) {
433 }
else if(!strncmp(chaine,
"$Elements",strlen(
"$Elements"))) {
435 *posElts = ftell((*inm));
439 for ( k=0; k<*nelts; ++k) {
467 if ( 0 != fscanf((*inm),
"%*[^\n]%*c") ) {
468 fputs (
"Reading error", stderr );
482 else if(!strncmp(chaine,
"$EndElements",strlen(
"$EndElements"))) {
488 fprintf(stderr,
" ** MISSING DATA.\n");
489 fprintf(stderr,
" Check that your mesh contains points and elements.\n");
490 fprintf(stderr,
" Exit program.\n");
505 fprintf(stderr,
" ** MISSING DATA.\n");
506 fprintf(stderr,
" Check that your mesh contains points.\n");
507 fprintf(stderr,
" Exit program.\n");
537 fprintf(stdout,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
538 fprintf(stdout,
" WARNING : %" MMG5_PRId
" entities with unexpected refs (ref< 0).",nref);
539 fprintf(stdout,
" We take their absolute values.\n");
540 fprintf(stdout,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
548 for (k=1; k<=
mesh->
nt; k++) {
551 for (i=0; i<3; i++) {
565 ptt->
v[2] = ptt->
v[1];
571 for (i=0; i<4; i++) {
580 for ( k=1; k<=
mesh->
ne; k++ ) {
582 if ( !
MG_EOK(pt) )
continue;
584 for (i=0; i<4; i++) {
601 for ( k=1; k<=
mesh->
nt; k++ ) {
603 if ( !
MG_EOK(ptt) )
continue;
604 for (i=0; i<3; i++) {
613 fprintf(stdout,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
614 fprintf(stdout,
" BAD ORIENTATION : vol < 0 -- %8" MMG5_PRId
" element(s) reoriented\n",
mesh->
xt);
615 fprintf(stdout,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
622 for (i=0; i<6; i++) {
630 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
"\n",
mesh->
np);
632 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
"\n",
mesh->
ne);
635 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",
mesh->
nprism);
637 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
"\n",
mesh->
nt);
639 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
"\n",
mesh->
nquad);
641 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
"\n",
mesh->
na);
665 const long posNodes,
const long posElts,
666 const long *posNodeData,
const int bin,
const int iswp,
667 const MMG5_int nelts,
const int nsols) {
678 int l,nref,nbl_t,nbl_a,k,v[4],nt,na,nq,ne,npr,idx,ref,num,iadr;
683 static int8_t mmgWarn=0, mmgWarn1=0;
687 fseek((*inm),posNodes,SEEK_SET);
690 for ( k=0; k<
mesh->
np; ++k)
695 for (i=0 ; i<
mesh->
dim ; i++) {
697 ppt->
c[i] = (double) fc;
704 for (i=0 ; i<
mesh->
dim ; i++) {
707 ppt->
c[i] = (double) fc;
716 for ( k=0; k<
mesh->
np; ++k)
721 MMG_FSCANF((*inm),
"%lf %lf %lf ",&ppt->
c[0],&ppt->
c[1],&ppt->
c[2]);
727 for (i=0 ; i<3 ; i++) {
739 fseek((*inm),posElts,SEEK_SET);
741 nbl_a = nbl_t = nt = na = nq = ne = npr = 0;
745 for ( k=0; k<nelts; ++k)
747 MMG_FSCANF((*inm),
"%d %d %d ",&i,&typ, &tagNum);
749 fprintf(stderr,
"\n ## Error: %s: elt %d (type %d): Expected at least 2 tags (%d given).\n",
750 __func__,k,typ,tagNum);
755 for ( l=2; l<tagNum; ++l ) {
766 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" ",&pa->
a,&pa->
b);
771 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" ",&pa->
a,&pa->
b);
779 assert( na+nbl_a<=mesh->na );
787 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&ptt->
v[0],&ptt->
v[1],&ptt->
v[2]);
792 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" ",&ptt->
v[0],&ptt->
v[1],&ptt->
v[2]);
794 if ( ptt->
ref < 0 ) {
799 assert( nt+nbl_t<=mesh->nt );
804 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" ",&pq1->
v[0],&pq1->
v[1],&pq1->
v[2],&pq1->
v[3]);
806 if ( pq1->
ref < 0 ) {
810 assert( nq<=mesh->nquad );
816 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" ",&pt->
v[0],&pt->
v[1],&pt->
v[2],&pt->
v[3]);
817 pt->
ref = MMG5_abs(ref);
819 MMG_FSCANF((*inm),
"%d %d %d %d ",&v[0],&v[1],&v[2],&v[3]);
826 assert( ne<=mesh->ne );
833 MMG_FSCANF((*inm),
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" ",&pp->
v[0],&pp->
v[1],&pp->
v[2],
834 &pp->
v[3],&pp->
v[4],&pp->
v[5]);
835 pp->
ref = MMG5_abs(ref);
840 assert( npr<=mesh->nprism );
847 if ( ppt->
ref < 0 ) {
851 assert( l<=mesh->np );
855 fprintf(stderr,
"\n ## Warning: %s: unexpected type for at least 1 element:"
856 " element %d, type %d\n",__func__,k,typ );
879 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
885 for ( idx=0; idx<num; ++idx ) {
891 for ( l=2; l<tagNum; ++l ) {
925 assert( na+nbl_a<=mesh->na );
939 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
945 for ( idx=0; idx<num; ++idx ) {
951 for ( l=2; l<tagNum; ++l ) {
960 for ( i=0; i<3 ; ++i ) {
967 for ( i=0; i<3 ; ++i ) {
973 if ( ptt->
ref < 0 ) {
978 assert( nt+nbl_t<=mesh->nt );
991 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
997 for ( idx=0; idx<num; ++idx ) {
1003 for ( l=2; l<tagNum; ++l ) {
1010 for ( i=0; i<4 ; ++i ) {
1016 if ( pq1->
ref < 0 ) {
1020 assert( nq<=mesh->nquad );
1034 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
1040 for ( idx=0; idx<num; ++idx ) {
1046 for ( l=2; l<tagNum; ++l ) {
1054 for ( i=0; i<4 ; ++i ) {
1059 pt->
ref = MMG5_abs(ref);
1060 assert( ne<=mesh->ne );
1063 for ( i=0; i<4 ; ++i )
1081 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
1087 for ( idx=0; idx<num; ++idx ) {
1093 for ( l=2; l<tagNum; ++l ) {
1101 for ( i=0; i<6 ; ++i ) {
1106 pp->
ref = MMG5_abs(ref);
1107 assert( npr<=mesh->nprism );
1110 for ( i=0; i<6 ; ++i )
1129 fprintf(stderr,
"\n ## Error: %s: Expected at least 2 tags per element (%d given).\n",
1135 for ( idx=0; idx<num; ++idx ) {
1141 for ( l=2; l<tagNum; ++l ) {
1151 if ( ppt->
ref < 0 ) {
1155 assert( l<=mesh->np );
1160 fprintf(stderr,
"\n ## Error: %s: unexpected type of element (%d)\n",
1169 assert ( na + nbl_a ==
mesh->
na );
1170 assert ( nt + nbl_t ==
mesh->
nt );
1178 else if ( nt < mesh->nt ) {
1180 fprintf(stderr,
" Exit program.\n");
1191 else if ( na < mesh->na ) {
1193 fprintf(stderr,
" Exit program.\n");
1204 if (
ier < 1 )
return ier;
1214 for ( isol=0; isol < nsols; ++isol ) {
1215 assert ( posNodeData[isol] );
1218 fseek((*inm),posNodeData[isol],SEEK_SET);
1229 if ( 1 != fscanf(*inm,
"\"%127s\"\n",&chaine[0]) ) {
1234 ptr = strstr(chaine,
":metric");
1246 fprintf(stderr,
"\n ## Warning: %s: unable to set solution name for"
1247 " at least 1 solution.\n",__func__);
1251 for ( k=1; k<tagNum; ++k ) {
1252 if ( 0 != fscanf((*inm),
"%*[^\n]%*c") )
return -1;
1256 if ( fscanf((*inm),
"%d",&tagNum) ) {
1257 for ( k=0; k<tagNum; ++k ) {
1265 fprintf(stderr,
" Error: %s: node data: Expected at least 3 tags (%d given).\n",
1275 for ( k=3; k<tagNum; ++k ) {
1280 fprintf(stderr,
" ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
1281 "THE MESH (%" MMG5_PRId
") DIFFERS FROM THE NUMBER OF VERTICES IN "
1282 "THE SOLUTION (%" MMG5_PRId
") \n",
mesh->
np,psl->
np);
1291 else if ( typ == 3 ) {
1295 else if ( typ == 9 ) {
1306 fprintf(stderr,
" ** DATA TYPE IGNORED %d \n",typ);
1316 fprintf(stderr,
" Exit program.\n");
1322 if ( psl->
size == 1 ) {
1323 if ( psl->
ver == 1 ) {
1324 for (k=1; k<=psl->
np; k++) {
1334 psl->
m[idx] = fbuf[0];
1338 for (k=1; k<=psl->
np; k++) {
1348 psl->
m[idx] = dbuf[0];
1353 else if ( psl->
size == psl->
dim ) {
1354 if ( psl->
ver == 1 ) {
1355 for (k=1; k<=psl->
np; k++) {
1358 for (i=0; i<psl->
dim; i++) {
1360 psl->
m[psl->
dim*idx+i] = fbuf[0];
1365 for (i=0; i<psl->
dim; i++) {
1368 psl->
m[psl->
dim*idx+i] = fbuf[0];
1374 for (k=1; k<=psl->
np; k++) {
1378 for (i=0; i<psl->
dim; i++) {
1380 psl->
m[psl->
dim*idx+i] = dbuf[0];
1387 for (i=0; i<psl->
dim; i++) {
1390 psl->
m[psl->
dim*idx+i] = dbuf[0];
1399 if ( psl->
ver == 1 ) {
1401 for (k=1; k<=psl->
np; k++) {
1405 for(i=0 ; i<9 ; i++)
1410 for(i=0 ; i<9 ; i++) {
1416 iadr = psl->
size*idx;
1418 if ( !metricData ) {
1419 if ( psl->
dim ==2 ) {
1420 psl->
m[iadr] = fbuf[0];
1421 psl->
m[iadr+1] = fbuf[1];
1422 psl->
m[iadr+2] = fbuf[3];
1423 psl->
m[iadr+3] = fbuf[4];
1426 for(i=0 ; i<9 ; i++) {
1427 psl->
m[iadr+i] = fbuf[i];
1432 if ( psl->
dim ==2 ) {
1433 assert ( fbuf[1] == fbuf[3] );
1435 psl->
m[iadr] = fbuf[0];
1436 psl->
m[iadr+1] = fbuf[1];
1437 psl->
m[iadr+2] = fbuf[4];
1440 assert ( fbuf[1]==fbuf[3] && fbuf[2]==fbuf[6] && fbuf[5]==fbuf[7] );
1442 psl->
m[iadr+0] = fbuf[0];
1443 psl->
m[iadr+1] = fbuf[1];
1444 psl->
m[iadr+2] = fbuf[2];
1445 psl->
m[iadr+3] = fbuf[4];
1446 psl->
m[iadr+4] = fbuf[5];
1447 psl->
m[iadr+5] = fbuf[8];
1453 for (k=1; k<=psl->
np; k++) {
1457 for(i=0 ; i<9 ; i++)
1462 for(i=0 ; i<9 ; i++) {
1468 iadr = psl->
size*idx;
1470 if ( !metricData ) {
1471 if ( psl->
dim ==2 ) {
1472 psl->
m[iadr ] = dbuf[0];
1473 psl->
m[iadr+1] = dbuf[1];
1474 psl->
m[iadr+2] = dbuf[3];
1475 psl->
m[iadr+3] = dbuf[4];
1478 for(i=0 ; i<9 ; i++) {
1479 psl->
m[iadr+i] = dbuf[i];
1484 if ( psl->
dim ==2 ) {
1485 assert ( dbuf[1] == dbuf[3] );
1487 psl->
m[iadr ] = dbuf[0];
1488 psl->
m[iadr+1] = dbuf[1];
1489 psl->
m[iadr+2] = dbuf[4];
1492 assert ( dbuf[1]==dbuf[3] || dbuf[2]==dbuf[6] || dbuf[5]==dbuf[7] );
1494 psl->
m[iadr+0] = dbuf[0];
1495 psl->
m[iadr+1] = dbuf[1];
1496 psl->
m[iadr+2] = dbuf[2];
1497 psl->
m[iadr+3] = dbuf[4];
1498 psl->
m[iadr+4] = dbuf[5];
1499 psl->
m[iadr+5] = dbuf[8];
1527 double mtmp[3],r[3][3];
1537 mtmp[0] =
sol->m[
sol->size*(ip)];
1538 mtmp[1] =
sol->m[
sol->size*(ip)+1];
1539 mtmp[2] =
sol->m[
sol->size*(ip)+3];
1542 r[0][0] = ppt->
n[0];
1543 r[1][0] = ppt->
n[1];
1544 r[2][0] = ppt->
n[2];
1556 dbuf[0] = mtmp[0]*r[0][0]*r[0][0] + mtmp[1]*r[0][1]*r[0][1] + mtmp[2]*r[0][2]*r[0][2];
1557 dbuf[1] = mtmp[0]*r[0][0]*r[1][0] + mtmp[1]*r[0][1]*r[1][1] + mtmp[2]*r[0][2]*r[1][2];
1558 dbuf[2] = mtmp[0]*r[0][0]*r[2][0] + mtmp[1]*r[0][1]*r[2][1] + mtmp[2]*r[0][2]*r[2][2];
1559 dbuf[3] = mtmp[0]*r[1][0]*r[1][0] + mtmp[1]*r[1][1]*r[1][1] + mtmp[2]*r[1][2]*r[1][2];
1560 dbuf[4] = mtmp[0]*r[1][0]*r[2][0] + mtmp[1]*r[1][1]*r[2][1] + mtmp[2]*r[1][2]*r[2][2];
1561 dbuf[5] = mtmp[0]*r[2][0]*r[2][0] + mtmp[1]*r[2][1]*r[2][1] + mtmp[2]*r[2][2]*r[2][2];
1564 for (i=0; i<
sol->size; i++) dbuf[i] = 0.;
1568 for (i=0; i<
sol->size; i++) dbuf[i] =
sol->m[
sol->size*ip+i];
1595 MMG5_int header[3],nq,ne,npr,np,nt,na,k,iadr,nelts,word;
1598 static char mmgWarn = 0;
1605 ptr = strstr(data,
".msh");
1608 strcat(data,
".mshb");
1609 if (!(inm = fopen(data,
"wb")) ) {
1610 ptr = strstr(data,
".msh");
1612 strcat(data,
".msh");
1613 if( !(inm = fopen(data,
"wb")) ) {
1614 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
1622 ptr = strstr(data,
".mshb");
1624 if( !(inm = fopen(data,
"wb")) ) {
1625 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
1632 fprintf(stdout,
" %%%% %s OPENED\n",data);
1636 fprintf(inm,
"$MeshFormat\n");
1637 fprintf(inm,
"2.2 %d %d\n",bin,8);
1643 fprintf(inm,
"$EndMeshFormat\n");
1647 for (k=1; k<=
mesh->
np; k++) {
1651 if (
mesh->
dim==2 ) ppt->
c[2] = 0.;
1654 fprintf(inm,
"$Nodes\n");
1655 fprintf(inm,
"%" MMG5_PRId
"\n",np);
1657 for (k=1; k<=
mesh->
np; k++) {
1661 fprintf(inm,
" %" MMG5_PRId
"",ppt->
tmp);
1662 for ( i=0; i<3; ++i )
1663 fprintf(inm,
" %.15lg",ppt->
c[i]);
1671 if ( bin ) fprintf(inm,
"\n");
1672 fprintf(inm,
"$EndNodes\n");
1677 for (k=1; k<=
mesh->
ne; k++) {
1679 if ( !
MG_EOK(pt) )
continue;
1685 if ( !
MG_EOK(pp) )
continue;
1691 if ( !
MG_EOK(pq) )
continue;
1695 for (k=1; k<=
mesh->
nt; k++) {
1697 if ( !
MG_EOK(ptt) )
continue;
1701 for (k=1; k<=
mesh->
na; k++) {
1703 if ( (!pa || !pa->
a) )
continue;
1707 fprintf(inm,
"$Elements\n");
1708 fprintf(inm,
"%" MMG5_PRId
"\n", np + ne + npr + nt + nq + na );
1719 fwrite(header,
MMG5_SW, 3, inm);
1722 for ( k=1; k<=
mesh->
np; ++k)
1725 if ( !
MG_VOK(ppt) )
continue;
1728 if ( !bin ) fprintf(inm,
"%" MMG5_PRId
" 15 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,MMG5_abs(ppt->
ref),
1729 MMG5_abs(ppt->
ref),ppt->
tmp);
1732 word = MMG5_abs(ppt->
ref);
1744 fwrite(header,
MMG5_SW, 3, inm);
1747 for (k=1; k<=
mesh->
na; ++k) {
1750 if ( !pa || !pa->
a )
continue;
1754 fprintf(inm,
"%" MMG5_PRId
" 1 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,pa->
ref,pa->
ref,
1770 fwrite(header,
MMG5_SW, 3, inm);
1773 for (k=1; k<=
mesh->
nt; ++k) {
1776 if ( !
MG_EOK(ptt) )
continue;
1780 fprintf(inm,
"%" MMG5_PRId
" 2 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,ptt->
ref,ptt->
ref,
1798 fwrite(header,
MMG5_SW, 3, inm);
1803 if ( !
MG_EOK(pq) )
continue;
1807 fprintf(inm,
"%" MMG5_PRId
" 3 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,pq->
ref,pq->
ref,
1826 fwrite(header,
MMG5_SW, 3, inm);
1829 for (k=1; k<=
mesh->
ne; ++k) {
1831 if ( !
MG_EOK(pt) )
continue;
1835 fprintf(inm,
"%" MMG5_PRId
" 4 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,pt->
ref,pt->
ref,
1854 fwrite(header,
MMG5_SW, 3, inm);
1859 if ( !
MG_EOK(pp) )
continue;
1863 fprintf(inm,
"%" MMG5_PRId
" 6 2 %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",nelts,pp->
ref,pp->
ref,
1879 if ( bin ) fprintf(inm,
"\n");
1880 fprintf(inm,
"$EndElements\n");
1884 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
"\n",np);
1885 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
"\n",ne);
1887 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",npr);
1889 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
"\n",nt);
1891 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
"\n",nq);
1893 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
"\n",na);
1899 if ( metricData==1 ) {
1912 for ( isol=0; isol<nsols; ++isol) {
1922 fprintf(stderr,
" ## Warning: %s: missing data for at least 1 solution."
1923 " Skipped.\n",__func__);
1928 fprintf(inm,
"$NodeData\n");
1934 if ( psl->
size == 1 ) {
1937 else if ( psl->
size == psl->
dim ) {
1947 fprintf(inm,
"\"%s:metric\"\n",
tmp);
1950 fprintf(inm,
"\"%s\"\n",
tmp);
1956 fprintf(inm,
"\"solution:metric\"\n");
1959 fprintf(inm,
"\"solution\"\n");
1965 fprintf(inm,
"0.0\n");
1970 fprintf(inm,
"%d\n",typ);
1971 fprintf(inm,
"%" MMG5_PRId
"\n",np);
1975 if ( psl->
size!= (psl->
dim*(psl->
dim+1))/2 ) {
1976 for (k=1; k<=
mesh->
np; k++) {
1978 if ( !
MG_VOK(ppt) )
continue;
1981 if ( psl->
dim == 2 )
1984 for ( i=0; i<psl->
size; ++i )
1985 dbuf[i] = psl->
m[iadr+i];
1988 fprintf(inm,
"%" MMG5_PRId
"",ppt->
tmp);
1989 for ( i=0; i<typ; ++i )
1990 fprintf(inm,
" %lg",dbuf[i]);
1995 fwrite(&dbuf,
MMG5_SD,typ,inm);
2000 for (k=1; k<=
mesh->
np; k++) {
2002 if ( !
MG_VOK(ppt) )
continue;
2004 if ( psl->
dim == 3 ) {
2010 for (i=0; i<psl->
size; i++) dbuf[i] = psl->
m[psl->
size*k+i];
2015 fprintf(inm,
"%" MMG5_PRId
"",ppt->
tmp);
2016 if ( psl->
dim==2 ) {
2018 fprintf(inm,
" %.15lg %.15lg %.15lg %.15lg %.15lg %.15lg"
2019 " %.15lg %.15lg %.15lg \n",
2020 psl->
m[iadr],psl->
m[iadr+1],0.,psl->
m[iadr+1],psl->
m[iadr+2],0.,0.,0.,1.);
2023 fprintf(inm,
" %.15lg %.15lg %.15lg %.15lg %.15lg %.15lg"
2024 " %.15lg %.15lg %.15lg \n", dbuf[0],dbuf[1],dbuf[2],
2025 dbuf[1],dbuf[3],dbuf[4],dbuf[2],dbuf[4],dbuf[5]);
2030 if ( psl->
dim==2 ) {
2032 fwrite(&psl->
m[iadr],
MMG5_SD,2,inm);
2033 dbuf[0] = dbuf[1] = dbuf[2] = 0.;
2036 fwrite(&psl->
m[iadr+1],
MMG5_SD,2,inm);
2040 fwrite(&dbuf[0],
MMG5_SD,3,inm);
2041 fwrite(&dbuf[1],
MMG5_SD,1,inm);
2042 fwrite(&dbuf[3],
MMG5_SD,2,inm);
2043 fwrite(&dbuf[2],
MMG5_SD,1,inm);
2044 fwrite(&dbuf[4],
MMG5_SD,2,inm);
2049 if ( bin ) fprintf(inm,
"\n");
2050 fprintf(inm,
"$EndNodeData\n");
2077 int *bin,
int *iswp,MMG5_int *np,
int *dim,
int *nsols,
int **type,
2078 long *posnp,
int imprim) {
2092 char *dot = strrchr(data,
'.');
2096 ptr = strstr(dot,
".mesh");
2098 if ( ptr ) *ptr =
'\0';
2100 ptr = strstr(data,
".sol");
2104 strcat(data,
".solb");
2105 if (!(*inm = fopen(data,
"rb")) ) {
2107 ptr = strstr(data,
".solb");
2109 strcat(data,
".sol");
2110 if (!(*inm = fopen(data,
"rb")) ) {
2112 fprintf(stderr,
" ** %s NOT FOUND. USE DEFAULT METRIC.\n",data);
2121 ptr = strstr(data,
".solb");
2122 if ( ptr ) *bin = 1;
2124 if (!(*inm = fopen(data,
"rb")) ) {
2126 fprintf(stderr,
" ** %s NOT FOUND. USE DEFAULT METRIC.\n",data);
2132 fprintf(stdout,
" %%%% %s OPENED\n",data);
2137 strcpy(chaine,
"DDD");
2138 while(fscanf(*inm,
"%127s",&chaine[0])!=EOF && strncmp(chaine,
"End",strlen(
"End")) ) {
2139 if(!strncmp(chaine,
"Dimension",strlen(
"Dimension"))) {
2141 if ( *dim!=meshDim ) {
2142 fprintf(stderr,
"BAD SOL DIMENSION: %d\n",*dim);
2147 }
else if(!strncmp(chaine,
"SolAtVertices",strlen(
"SolAtVertices"))) {
2151 for ( i=0; i<*nsols; ++i ) {
2154 *posnp = ftell(*inm);
2160 if(binch==16777216) (*iswp)=1;
2162 fprintf(stdout,
"BAD FILE ENCODING\n");
2168 while(fread(&binch,
MMG5_SW,1,*inm)!=EOF && binch!=54 ) {
2170 if(binch==54)
break;
2176 if ( *dim!=meshDim ) {
2177 fprintf(stderr,
"BAD SOL DIMENSION: %d\n",*dim);
2178 printf(
" Exit program.\n");
2183 }
else if(binch==62) {
2192 for ( i=0; i<*nsols; ++i ) {
2196 *posnp = ftell(*inm);
2202 fseek(*inm,bpos,SEEK_SET);
2226 switch (
sol->size ) {
2229 for (i=0; i<
sol->size; i++) {
2236 sol->m[
sol->size*pos+i] = fbuf[0];
2242 for(i=0 ; i<
sol->size ; i++)
2245 for(i=0 ; i<
sol->size ; i++) {
2253 for (i=0; i<6; i++)
sol->m[6*pos+i] = fbuf[i];
2272 double dbuf[6],tmpd;
2275 switch (
sol->size ) {
2278 for (i=0; i<
sol->size; i++) {
2285 sol->m[
sol->size*pos+i] = dbuf[i];
2292 for(i=0 ; i<
sol->size ; i++)
2295 for(i=0 ; i<
sol->size ; i++) {
2303 for (i=0; i<
sol->size; i++)
sol->m[6*pos+i] = dbuf[i];
2321 MMG5_int pos,
int metricData) {
2325 switch (
sol->size ) {
2328 for (i=0; i<
sol->size; i++) {
2329 for (i=0; i<
sol->size; i++) dbuf[i] =
sol->m[
sol->size*pos+i];
2331 for (i=0; i<
sol->size; i++)
2332 fprintf(inm,
" %.15lg",dbuf[i]);
2334 for(i=0; i<
sol->size; i++)
2335 fwrite((
unsigned char*)&dbuf[i],
MMG5_SD,1,inm);
2348 for (i=0; i<
sol->size; i++)
2350 dbuf[i] =
sol->m[6*pos+i];
2359 for(i=0; i<
sol->size; i++)
2360 fprintf(inm,
" %.15lg",dbuf[i]);
2362 for(i=0; i<
sol->size; i++)
2363 fwrite((
unsigned char*)&dbuf[i],
MMG5_SD,1,inm);
2390 FILE **inm,
int ver,
int *bin,MMG5_int *bpos,MMG5_int np,
int dim,
2391 int nsols,
int *entities,
int *type,
int *size) {
2401 ptr = strstr(data,
".sol");
2404 ptr = strstr(data,
".solb");
2406 if ( ptr ) *bin = 1;
2408 if( !(*inm = fopen(data,
"wb")) ) {
2409 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2417 ptr = strstr(data,
".mesh");
2418 if ( ptr ) *ptr =
'\0';
2420 strcat(data,
".sol");
2421 if (!(*inm = fopen(data,
"wb")) ) {
2422 ptr = strstr(data,
".solb");
2424 strcat(data,
".sol");
2425 if (!(*inm = fopen(data,
"wb")) ) {
2426 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2435 fprintf(stdout,
" %%%% %s OPENED\n",data);
2441 strcpy(&chaine[0],
"MeshVersionFormatted\n");
2442 fprintf(*inm,
"%s %d",chaine,ver);
2443 strcpy(&chaine[0],
"\n\nDimension\n");
2444 fprintf(*inm,
"%s %d",chaine,dim);
2447 fwrite(&binch,
MMG5_SW,1,*inm);
2449 fwrite(&binch,
MMG5_SW,1,*inm);
2451 fwrite(&binch,
MMG5_SW,1,*inm);
2455 fwrite(&binch,
MMG5_SW,1,*inm);
2459 for (k=1; k<=
mesh->
np; k++) {
2466 for (k=0; k<nsols; ++k ) {
2474 strcpy(&chaine[0],
"\n\nSolAtVertices\n");
2475 fprintf(*inm,
"%s",chaine);
2476 fprintf(*inm,
"%" MMG5_PRId
"\n",np);
2477 fprintf(*inm,
"%d",npointSols);
2478 for (k=0; k<nsols; ++k ) {
2482 fprintf(*inm,
" %d",type[k]);
2487 fwrite(&binch,
MMG5_SW,1,*inm);
2490 for (k=0; k<nsols; ++k ) {
2494 (*bpos) += 4 + (size[k]*ver)*4*np;
2499 fwrite(&npointSols,
MMG5_SW,1,*inm);
2500 for (k=0; k<nsols; ++k ) {
2504 fwrite(&type[k],
MMG5_SW,1,*inm);
2527 FILE *inm,
int ver,
int bin,MMG5_int *bpos,
2528 int nsols,
int nsolsAtTriangles,
2529 int *entities,
int *type,
int *size) {
2535 for (k=1; k<=
mesh->
nt; k++) {
2544 fprintf(inm,
"\n\nSolAtTriangles\n");
2545 fprintf(inm,
"%" MMG5_PRId
"\n",nt);
2546 fprintf(inm,
"%d",nsolsAtTriangles);
2547 for (k=0; k<nsols; ++k ) {
2551 fprintf(inm,
" %d",type[k]);
2559 for (k=0; k<nsols; ++k ) {
2563 (*bpos) += 4 + (size[k]*ver)*4*nt;
2568 fwrite(&nsolsAtTriangles,
MMG5_SW,1,inm);
2569 for (k=0; k<nsols; ++k ) {
2573 fwrite(&type[k],
MMG5_SW,1,inm);
2596 FILE *inm,
int ver,
int bin,MMG5_int *bpos,
2597 int nsols,
int nsolsAtTetra,
2598 int *entities,
int *type,
int *size) {
2604 for (k=1; k<=
mesh->
ne; k++) {
2613 fprintf(inm,
"\n\nSolAtTetrahedra\n");
2614 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
2615 fprintf(inm,
"%d",nsolsAtTetra);
2616 for (k=0; k<nsols; ++k ) {
2620 fprintf(inm,
" %d",type[k]);
2628 for (k=0; k<nsols; ++k ) {
2632 (*bpos) += 4 + (size[k]*ver)*4*ne;
2637 fwrite(&nsolsAtTetra,
MMG5_SW,1,inm);
2638 for (k=0; k<nsols; ++k ) {
2642 fwrite(&type[k],
MMG5_SW,1,inm);
2667 fprintf(stderr,
" ## Error: %s: Metric should apply on vertices.\n"
2668 " If your input file is at a non Medit"
2669 " file format, please ensure to remove non metric fields from your"
2670 " file and that the metric field"
2671 " contains the \":metric\" string.\n",__FILE__);
2672 if ( inm ) fclose(inm);
2680 if ( type[0]!=1 && type[0]!=3) {
2681 fprintf(stderr,
" ** DATA TYPE IGNORED %d \n",type[0]);
2682 fprintf(stderr,
" ## Error: %s: if your input file is at a non Medit"
2683 " file format, please ensure that the metric field"
2684 " contains the \":metric\" string.\n",__FILE__);
2685 if ( inm ) fclose(inm);
2690 if ( type[0] != 2 ) {
2691 fprintf(stderr,
" ** MISMATCH DATA TYPE FOR LAGRANGIAN MODE %d \n",
2693 if ( inm ) fclose(inm);
2709 if ( met->
size == 1 )
2710 fprintf(stdout,
" NUMBER OF SCALAR VALUES %8" MMG5_PRId
"\n",met->
np);
2711 else if ( met->
size == 3 )
2712 fprintf(stdout,
" NUMBER OF VECTOR VALUES %8" MMG5_PRId
"\n",met->
np);
2714 fprintf(stdout,
" NUMBER OF TENSOR VALUES %8" MMG5_PRId
"\n",met->
np);
2729 fprintf(stdout,
" NUMBER OF SOLUTIONS PER ENTITY %8d\n",
mesh->
nsols);
2730 fprintf(stdout,
" TYPE OF SOLUTIONS:\n ");
2732 if ( (*
sol)[j].size == 1 )
2733 fprintf(stdout,
" SCALAR");
2734 else if ( (*
sol)[j].size == 3 )
2735 fprintf(stdout,
" VECTOR");
2737 fprintf(stdout,
" TENSOR");
2739 fprintf(stdout,
"\n");
2758 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2766 ptr = strstr(data,
".node");
2772 strcat(data,
".node");
2773 if( !(inm = fopen(data,
"wb")) ) {
2774 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2779 fprintf(stdout,
" %%%% %s OPENED\n",data);
2784 for (k=1; k<=
mesh->
np; k++) {
2793 fprintf(inm,
"%" MMG5_PRId
" %d %d %d\n\n",np,
mesh->
dim,0,1);
2795 for ( k=1; k<=
mesh->
np; ++k ) {
2799 fprintf(inm,
"%" MMG5_PRId
" ",ppt->
tmp);
2802 for ( i=0; i<
mesh->
dim; ++i ) {
2803 fprintf(inm,
" %.15lf",ppt->
c[i]);
2807 fprintf(inm,
" %" MMG5_PRId
"\n",ppt->
ref);
2811 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
"\n",np);
2834 if ( (!
filename) || !(*filename) ) {
2837 if ( (!
filename) || !(*filename) ) {
2838 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2846 ptr = strstr(data,
".node");
2853 if( !(inm = fopen(data,
"wb")) ) {
2854 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2859 fprintf(stdout,
" %%%% %s OPENED\n",data);
2863 if ( !strcmp(ext,
".poly") ) {
2873 fprintf(inm,
"0 %d 0 1\n",
mesh->
dim);
2881 ptr_c = ptr_c-
sizeof(size_t);
2882 na_tot = (*((
size_t*)ptr_c));
2889 fprintf(inm,
"%zu %d\n",na_tot,1);
2891 for ( k=1; k<=na_tot; ++k ) {
2893 fprintf(inm,
"%" MMG5_PRId
" ",k);
2904 fprintf(inm,
"0 \n");
2907 fprintf(stdout,
" NUMBER OF EDGES %8zu\n",na_tot);
char * MMG5_Get_basename(char *path)
int MMG5_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
MMG5_pMesh MMG5_pSol * sol
if(!ier) exit(EXIT_FAILURE)
MMG5_pMesh char * filename
int MMG5_readDoubleSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, MMG5_int pos)
int MMG5_chkMetricType(MMG5_pMesh mesh, int *type, int *entities, FILE *inm)
void MMG5_build3DMetric(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_int ip, double dbuf[6])
void MMG5_printSolStats(MMG5_pMesh mesh, MMG5_pSol *sol)
float MMG5_swapf(float sbin)
int MMG5_check_readedMesh(MMG5_pMesh mesh, MMG5_int nref)
static int MMG5_countBinaryElts(FILE **inm, const int nelts, const int iswp, int *np, int *na, int *nt, int *nq, int *ne, int *npr)
int MMG5_saveSolAtTrianglesHeader(MMG5_pMesh mesh, FILE *inm, int ver, int bin, MMG5_int *bpos, int nsols, int nsolsAtTriangles, int *entities, int *type, int *size)
int MMG5_saveNode(MMG5_pMesh mesh, const char *filename)
int MMG5_saveEdge(MMG5_pMesh mesh, const char *filename, const char *ext)
int MMG5_saveSolHeader(MMG5_pMesh mesh, const char *filename, FILE **inm, int ver, int *bin, MMG5_int *bpos, MMG5_int np, int dim, int nsols, int *entities, int *type, int *size)
int MMG5_loadMshMesh_part1(MMG5_pMesh mesh, const char *filename, FILE **inm, long *posNodes, long *posElts, long **posNodeData, int *bin, int *iswp, MMG5_int *nelts, int *nsols)
void MMG5_writeDoubleSol3D(MMG5_pMesh mesh, MMG5_pSol sol, FILE *inm, int bin, MMG5_int pos, int metricData)
MMG5_int MMG5_swapbin_int(MMG5_int sbin)
int MMG5_saveSolAtTetrahedraHeader(MMG5_pMesh mesh, FILE *inm, int ver, int bin, MMG5_int *bpos, int nsols, int nsolsAtTetra, int *entities, int *type, int *size)
int MMG5_readFloatSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, int pos)
double MMG5_swapd(double sbin)
int MMG5_loadMshMesh_part2(MMG5_pMesh mesh, MMG5_pSol *sol, FILE **inm, const long posNodes, const long posElts, const long *posNodeData, const int bin, const int iswp, const MMG5_int nelts, const int nsols)
int MMG5_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename, int metricData)
void MMG5_printMetStats(MMG5_pMesh mesh, MMG5_pSol met)
int MMG5_loadSolHeader(const char *filename, int meshDim, FILE **inm, int *ver, int *bin, int *iswp, MMG5_int *np, int *dim, int *nsols, int **type, long *posnp, int imprim)
int MMG5_swapbin(int sbin)
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
double MMG2D_quickarea(double a[2], double b[2], double c[2])
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG_FREAD(ptr, size, count, stream)
double MMG5_orvol(MMG5_pPoint point, MMG5_int *v)
#define MMG5_FILESTR_LGTH
#define MMG5_SAFE_FREE(ptr)
#define MMG_FSCANF(stream, format,...)
#define MMG5_DEL_MEM(mesh, ptr)
#define MMG5_SAFE_RECALLOC(ptr, prevSize, newSize, type, message, law)
Structure to store edges of am MMG mesh.
Structure to store vertices of an MMG mesh.
Structure to store prsim of a MMG mesh.
Structure to store quadrangles of an MMG mesh.
Structure to store tetrahedra of an MMG mesh.
Structure to store triangles of a MMG mesh.