50 char *mtc_domath(
const char *);
51 void mtc_init(FILE * input, FILE * output, FILE * error);
115 grid->
ydens[i] = 1.0;
123 grid->
zdens[i] = 1.0;
167 malloc((
size_t) (*nogrids)*
sizeof(
struct GridType));
190 grid->
xdens[2] = 0.5;
210 if(info)
printf(
"A simple 1D example mesh was created\n");
223 malloc((
size_t) (*nogrids)*
sizeof(
struct GridType));
302 if(info)
printf(
"A simple 2D example mesh was created\n");
315 malloc((
size_t) (*nogrids)*
sizeof(
struct GridType));
401 if(info)
printf(
"A simple 3D example mesh was created\n");
438 int i,j,nx,ny,nxmax = 0,nymax = 0;
439 int sumxelems,sumyelems,sumxyelems;
442 Real dxmax = 0,dymax = 0,
dx = 0,
dy = 0,dxlimit = 0;
444 if(0)
printf(
"SetElementDivision\n");
461 if(0)
printf(
"The mesh is devided into %d separate subcells.\n",grid->
nocells);
464 for(i=1; i<= nx ;i++) {
465 if (fabs(1.-grid->
xexpand[i]) < linearlimit)
467 else if (fabs(1.+grid->
xexpand[i]) < linearlimit)
473 for(i=1; i <= ny ;i++) {
474 if(fabs(1.-grid->
yexpand[i]) < linearlimit)
476 else if(fabs(1.+grid->
yexpand[i]) < linearlimit)
503 sumxelems += grid->
xelems[i];
507 sumyelems += grid->
yelems[i];
518 wantedelemsx = (int) (1.0*grid->
totxelems / relh);
519 wantedelemsy = (int) (1.0*grid->
totyelems / relh);
521 if(sumxelems > wantedelemsx) {
522 printf(
"SetElementDivision: %d is too few elements in x-direction\n",grid->
totxelems);
523 wantedelemsx = sumxelems+1;
525 if(sumyelems > wantedelemsy ) {
526 printf(
"SetElementDivision: %d is too few elements in y-direction\n",grid->
totyelems);
527 wantedelemsy = sumyelems+1;
530 for(;sumxelems < wantedelemsx;) {
533 if(grid->
xelems[i] == 0)
continue;
539 dx = (grid->
x[i] - grid->
x[i-1])/grid->
xelems[i];
543 dx = (grid->
x[i] - grid->
x[i-1]) *
544 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
xelems[i])));
550 dx = (grid->
x[i] - grid->
x[i-1])/grid->
xelems[i];
552 else if(grid->
xelems[i]%2 == 0) {
554 dx = 0.5 * (grid->
x[i] - grid->
x[i-1]) *
555 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
xelems[i]/2)));
557 else if(grid->
xelems[i]%2 == 1) {
559 dx = (grid->
x[i] - grid->
x[i-1]) /
560 (2.0*(1.-pow(ratio,(
Real)(grid->
xelems[i]/2)))/
577 for(;sumyelems < wantedelemsy;) {
580 if(grid->
yelems[i] == 0)
continue;
582 dy = (grid->
y[i] - grid->
y[i-1])/grid->
yelems[i];
585 dy = (grid->
y[i] - grid->
y[i-1]) *
586 (1.-ratio)/(1.-pow(ratio,(
Real)(grid->
yelems[i])));
604 if(grid->autoratio == 1) {
606 wantedelems = (int) (1.0*grid->wantedelems / (relh*relh));
614 if(grid->xelems[i] == 0)
continue;
615 if(grid->xlinear[i] || grid->xelems[i]==1)
616 dx = (grid->x[i] - grid->x[i-1])/grid->xelems[i];
618 if(grid->xexpand[i] > 0.0) {
619 ratio = pow(grid->xexpand[i],1./(grid->xelems[i]-1.));
620 dx = (grid->x[i] - grid->x[i-1]) *
623 dx *= grid->xexpand[i];
625 else if(grid->xelems[i]==2) {
626 dx = (grid->x[i] - grid->x[i-1])/grid->xelems[i];
628 else if(grid->xelems[i]%2 == 0) {
629 ratio = pow(-grid->xexpand[i],1./(grid->xelems[i]/2-1.));
630 dx = 0.5 * (grid->x[i] - grid->x[i-1]) *
633 else if(grid->xelems[i]%2 == 1) {
634 ratio = pow(-grid->xexpand[i],1./(grid->xelems[i]/2));
635 dx = (grid->x[i] - grid->x[i-1]) /
636 (2.0*(1.-pow(
ratio,(
Real)(grid->xelems[i]/2)))/
641 dx *= grid->xdens[i];
652 if(grid->yelems[i] == 0)
continue;
653 if(grid->ylinear[i] || grid->yelems[i]==1)
654 dy = (grid->y[i] - grid->y[i-1])/grid->yelems[i];
656 if(grid->yexpand[i] > 0.0) {
657 ratio = pow(grid->yexpand[i],1./(grid->yelems[i]-1));
658 dy = (grid->y[i] - grid->y[i-1]) *
661 dy *= grid->yexpand[i];
663 else if(grid->yelems[i]==2) {
664 dy = (grid->y[i] - grid->y[i-1])/grid->yelems[i];
666 else if(grid->yelems[i]%2 == 0) {
667 ratio = pow(-grid->yexpand[i],1./(grid->yelems[i]/2-1.));
668 dy = 0.5 * (grid->y[i] - grid->y[i-1]) *
671 else if(grid->yelems[i]%2 == 1) {
672 ratio = pow(-grid->yexpand[i],1./(grid->yelems[i]/2));
673 dy = (grid->y[i] - grid->y[i-1]) /
674 (2.0*(1.-pow(
ratio,(
Real)(grid->yelems[i]/2)))/
678 dy *= grid->ydens[i];
684 dymax /= grid->xyratio;
687 grid->xelems[nxmax] += 1;
692 grid->yelems[nymax] += 1;
698 for(j=1;j<=grid->ycells;j++)
699 for(i=1;i<=grid->xcells;i++)
700 if(grid->numbered[j][i]) sumxyelems += grid->xelems[i] * grid->yelems[j];
708 if(grid->autoratio == 3 || grid->limitdxverify) {
710 if(grid->autoratio == 3) {
711 dxlimit = relh * grid->limitdx;
712 dxmax = dymax = dxlimit;
718 if(grid->xlinear[i] || grid->xelems[i]==0)
719 dx = (grid->x[i] - grid->x[i-1])/(grid->xelems[i]+1);
721 if(grid->xexpand[i] > 0.0) {
722 ratio = pow(grid->xexpand[i],1./grid->xelems[i]);
723 dx = (grid->x[i] - grid->x[i-1]) *
726 dx *= grid->xexpand[i];
728 else if(grid->xelems[i]==1) {
729 dx = (grid->x[i] - grid->x[i-1])/(grid->xelems[i]+1);
731 else if((grid->xelems[i]+1)%2 == 0) {
732 ratio = pow(-grid->xexpand[i],1./(grid->xelems[i]/2));
733 dx = 0.5 * (grid->x[i] - grid->x[i-1]) *
736 else if((grid->xelems[i]+1)%2 == 1) {
737 ratio = pow(-grid->xexpand[i],1./((grid->xelems[i]+1)/2));
738 dx = (grid->x[i] - grid->x[i-1]) /
739 (2.0*(1.-pow(
ratio,(
Real)((grid->xelems[i]+1)/2)))/
743 dx *= grid->xdens[i];
746 if(fabs(
dx-dxlimit) < fabs(
dx*(1+1.0/grid->xelems[i]) -dxlimit) )
747 grid->xelems[i] += 1;
751 sumxelems += grid->xelems[i];
758 if(grid->ylinear[i] || grid->yelems[i]==0)
759 dy = (grid->y[i] - grid->y[i-1])/(grid->yelems[i]+1);
761 if(grid->yexpand[i] > 0.0) {
762 ratio = pow(grid->yexpand[i],1./grid->yelems[i]);
763 dy = (grid->y[i] - grid->y[i-1]) *
766 dy *= grid->yexpand[i];
768 else if(grid->yelems[i]==1) {
769 dy = (grid->y[i] - grid->y[i-1])/(grid->yelems[i]+1);
771 else if((grid->yelems[i]+1)%2 == 0) {
772 ratio = pow(-grid->yexpand[i],1./(grid->yelems[i]/2));
773 dy = 0.5 * (grid->y[i] - grid->y[i-1]) *
776 else if((grid->yelems[i]+1)%2 == 1) {
777 ratio = pow(-grid->yexpand[i],1./((grid->yelems[i]+1)/2));
778 dy = (grid->y[i] - grid->y[i-1]) /
779 (2.0*(1.-pow(
ratio,(
Real)((grid->yelems[i]+1)/2)))/
784 dy *= grid->ydens[i] / grid->xyratio;
786 if(fabs(
dy-dxlimit) < fabs(
dy*(1+1.0/grid->yelems[i]) -dxlimit) )
787 grid->yelems[i] += 1;
791 sumyelems += grid->yelems[i];
795 for(j=1;j<=grid->ycells;j++)
796 for(i=1;i<=grid->xcells;i++)
797 if(grid->numbered[j][i]) sumxyelems += grid->xelems[i] * grid->yelems[j];
802 for(i=1; i<= nx ;i++)
803 if (grid->xelems[i] == 1)
804 grid->xlinear[i] =
TRUE;
805 for(i=1; i <= ny ;i++)
806 if(grid->yelems[i] == 1)
807 grid->ylinear[i] =
TRUE;
813 if(grid->xlinear[i] ==
TRUE)
814 grid->dx[i] = (grid->x[i] - grid->x[i-1])/grid->xelems[i];
816 if(grid->xexpand[i] > 0.0) {
817 ratio = pow(grid->xexpand[i],1./(grid->xelems[i]-1.));
818 grid->xratios[i] =
ratio;
819 grid->dx[i] = (grid->x[i] - grid->x[i-1]) *
822 else if(grid->xelems[i] == 2) {
823 grid->dx[i] = (grid->x[i] - grid->x[i-1])/grid->xelems[i];
825 else if(grid->xelems[i]%2 == 0) {
826 ratio = pow(-grid->xexpand[i],1./(grid->xelems[i]/2-1.));
827 grid->xratios[i] =
ratio;
828 grid->dx[i] = 0.5 * (grid->x[i] - grid->x[i-1]) *
831 else if(grid->xelems[i]%2 == 1) {
832 ratio = pow(-grid->xexpand[i],1./(grid->xelems[i]/2));
833 grid->xratios[i] =
ratio;
834 grid->dx[i] = (grid->x[i] - grid->x[i-1]) /
835 (2.0*(1.-pow(
ratio,(
Real)(grid->xelems[i]/2)))/
843 if(grid->ylinear[i] ==
TRUE)
844 grid->dy[i] = (grid->y[i] - grid->y[i-1])/grid->yelems[i];
846 if(grid->yexpand[i] > 0.0) {
847 ratio = pow(grid->yexpand[i],1./(grid->yelems[i]-1.));
848 grid->yratios[i] =
ratio;
849 grid->dy[i] = (grid->y[i] - grid->y[i-1]) *
852 else if(grid->yelems[i] == 2) {
853 grid->dy[i] = (grid->y[i] - grid->y[i-1])/grid->yelems[i];
855 else if(grid->yelems[i]%2 == 0) {
856 ratio = pow(-grid->yexpand[i],1./(grid->yelems[i]/2-1.));
857 grid->yratios[i] =
ratio;
858 grid->dy[i] = 0.5 * (grid->y[i] - grid->y[i-1]) *
861 else if(grid->yelems[i]%2 == 1) {
862 ratio = pow(-grid->yexpand[i],1./(grid->yelems[i]/2));
863 grid->yratios[i] =
ratio;
864 grid->dy[i] = (grid->y[i] - grid->y[i-1]) /
865 (2.0*(1.-pow(
ratio,(
Real)(grid->yelems[i]/2)))/
873 for(j=1;j<=grid->ycells;j++)
874 for(i=1;i<=grid->xcells;i++)
875 if(grid->numbered[j][i]) sumxyelems += grid->xelems[i] * grid->yelems[j];
877 grid->noelements = sumxyelems;
879 if(0)
printf(
"Created a total of %d elements\n",sumxyelems);
894 for(j=1;j<= grid->
ycells ;j++)
895 for(i=1;i<= grid->
xcells; i++)
919 cell[cnew].
xwidth = grid->
x[i] - grid->
x[i-1];
920 cell[cnew].
ywidth = grid->
y[j] - grid->
y[j-1];
943 cell[cnew].
dx1 = grid->
dx[i];
944 cell[cnew].
dy1 = grid->
dy[j];
990 int i,j,level,center;
992 int cnew = 0,cup = 0,cleft = 0,cleftup = 0;
1015 printf(
"No %d numbering scheme exists!\n",numbering);
1021 centernodes =
FALSE;
1031 centernodes =
FALSE;
1041 centernodes =
FALSE;
1051 printf(
"CreateCells: No numbering scheme for %d-node elements.\n",
1057 for(level=0; level <= yelems[j] ;level++)
1058 for(center=0; center <
degree; center++)
1065 cleftup = grid->
numbered[j+1][i-1];
1067 cell[cnew].
xind = i;
1068 cell[cnew].
yind = j;
1075 cleftup = grid->
numbered[i-1][j+1];
1077 cell[cnew].
xind = j;
1078 cell[cnew].
yind = i;
1085 if (cnew && level==0 && !cell[cnew].left1st) {
1086 if(!cleft) knotno++;
1089 knotno += degree * xelems[i];
1091 knotno += xelems[i];
1095 else if (cnew && level > 0 && level < yelems[j]) {
1096 if(!cleft) knotno++;
1102 knotno += degree * xelems[i];
1104 knotno += xelems[i];
1108 else if ((cnew || cup) && level == yelems[j]) {
1109 if(!cleft && !cleftup)
1120 knotno += degree * xelems[i];
1122 knotno += xelems[i];
1126 if(cnew && level > 0) {
1128 cell[cnew].
elem1st = elemno+1;
1130 cell[cnew].
elemwidth = (elemno+1) - cell[cnew].elem1st;
1131 elemno += xelems[i];
1135 if(center && level < yelems[j]) {
1137 if(!cleft && sidenodes)
1139 if(level==0 && center==1)
1141 if(level==0 && center==2)
1143 if(level==1 && center==1)
1145 if(centernodes && sidenodes)
1146 knotno += degree * xelems[i];
1148 knotno += xelems[i];
1157 for(i=1;i<=
xcells; i++) {
1164 if(width > maxwidth)
1167 if(width > maxwidth)
1170 -(yelems[j]-2)*cell[cnew].levelwidth;
1171 if(width > maxwidth)
1182 printf(
"There are %d knots in %d %d-node elements.\n",knotno,elemno,nonodes);
1184 if(0)
printf(
"Numbering order was <x><y> and max levelwidth %d.\n",
1187 if(0)
printf(
"Numbering order was <y><x> and max levelwidth %d.\n",
1224 printf(
"CreateCells: No numbering scheme for %d-node elements.\n",
1229 for(i=1;i<=
xcells; i++) {
1233 if(cnew) cell[cnew].
xind = i;
1237 if(!cleft) knotno++;
1239 knotno += degree * xelems[i];
1242 cell[cnew].
elem1st = elemno+1;
1243 elemno += xelems[i];
1254 printf(
"Numbered %d knots in %d %d-node elements.\n",knotno,elemno,nonodes);
1269 int ind,aid,maxj = 0;
1285 aid = j; j = i; i = aid;
1324 if(i<=cell->xelem/2) {
1340 if(j<=cell->yelem/2) {
1377 if(nonodes == 4)
return(elemind);
1382 else if(nonodes == 8) {
1388 else if(nonodes == 9) {
1395 else if(nonodes == 12) {
1405 else if(nonodes == 16) {
1420 printf(
"GetElementIndices: not implemented for %d nodes.\n",nonodes);
1426 if(nonodes == 4)
return(elemind);
1431 else if (nonodes==8) {
1437 else if(nonodes == 9) {
1444 else if(nonodes == 12) {
1454 else if(nonodes == 16) {
1469 printf(
"GetElementIndices: not implemented for %d nodes.\n",nonodes);
1473 elemind = cell->
elem1st+(i-1);
1476 ind[1] = ind[0] + 1;
1478 else if(nonodes == 3) {
1479 ind[2] = ind[0] + 1;
1480 ind[1] = ind[0] + 2;
1482 else if(nonodes == 4) {
1483 ind[2] = ind[0] + 1;
1484 ind[3] = ind[0] + 2;
1485 ind[1] = ind[0] + 3;
1511 Real *globalcoord,
int *ind)
1526 elemind = cell->
elem1st+(i-1);
1528 &globalcoord[nonodes]);
1530 &globalcoord[nonodes+1]);
1533 globalcoord[2] = (globalcoord[0]+globalcoord[1])/2.0;
1534 globalcoord[5] = (globalcoord[3]+globalcoord[4])/2.0;
1535 ind[2] = ind[0] + 1;
1537 else if(nonodes == 4) {
1538 globalcoord[2] = (2.0*globalcoord[0]+globalcoord[1])/3.0;
1539 globalcoord[6] = (2.0*globalcoord[4]+globalcoord[5])/3.0;
1540 ind[2] = ind[0] + 1;
1541 globalcoord[3] = (globalcoord[0]+2.0*globalcoord[1])/3.0;
1542 globalcoord[7] = (globalcoord[4]+2.0*globalcoord[5])/3.0;
1543 ind[3] = ind[0] + 2;
1555 &globalcoord[TOPRIGHT+nonodes]);
1557 &globalcoord[BOTRIGHT+nonodes]);
1559 &globalcoord[TOPLEFT+nonodes]);
1561 &globalcoord[BOTLEFT+nonodes]);
1562 if(nonodes == 4)
return(elemind);
1570 xrat = sqrt(cell->
xratio);
1575 yrat = sqrt(cell->
yratio);
1580 globalcoord[4] = 0.5*(globalcoord[0]+globalcoord[2]);
1581 globalcoord[4+
k] = 0.5*(globalcoord[
k]+globalcoord[2+
k]);
1583 else if(nonodes == 8 || nonodes == 9) {
1584 globalcoord[4] = (xrat*globalcoord[0]+globalcoord[1])/(1+xrat);
1585 globalcoord[4+
k] = globalcoord[
k];
1586 globalcoord[5] = globalcoord[1];
1588 (yrat*globalcoord[1+
k]+globalcoord[2+
k])/(1+yrat);
1589 globalcoord[6] = globalcoord[4];
1590 globalcoord[6+
k] = globalcoord[2+
k];
1591 globalcoord[7] = globalcoord[3];
1592 globalcoord[7+
k] = globalcoord[5+
k];
1594 globalcoord[8] = globalcoord[4];
1595 globalcoord[8+
k] = globalcoord[5+
k];
1598 else if(nonodes == 12 || nonodes == 16) {
1599 globalcoord[4] = (2.*globalcoord[0]+globalcoord[1])/3.0;
1600 globalcoord[4+
k] = (2.*globalcoord[
k]+globalcoord[1+
k])/3.0;
1601 globalcoord[5] = (2.*globalcoord[1]+globalcoord[0])/3.0;
1602 globalcoord[5+
k] = (2.*globalcoord[1+
k]+globalcoord[
k])/3.0;
1603 globalcoord[6] = (2.*globalcoord[1]+globalcoord[2])/3.0;
1604 globalcoord[6+
k] = (2.*globalcoord[1+
k]+globalcoord[2+
k])/3.0;
1605 globalcoord[7] = (2.*globalcoord[2]+globalcoord[1])/3.0;
1606 globalcoord[7+
k] = (2.*globalcoord[2+
k]+globalcoord[1+
k])/3.0;
1607 globalcoord[8] = (2.*globalcoord[2]+globalcoord[3])/3.0;
1608 globalcoord[8+
k] = (2.*globalcoord[2+
k]+globalcoord[3+
k])/3.0;
1609 globalcoord[9] = (2.*globalcoord[3]+globalcoord[2])/3.0;
1610 globalcoord[9+
k] = (2.*globalcoord[3+
k]+globalcoord[2+
k])/3.0;
1611 globalcoord[10] = (2.*globalcoord[3]+globalcoord[0])/3.0;
1612 globalcoord[10+
k] = (2.*globalcoord[3+
k]+globalcoord[
k])/3.0;
1613 globalcoord[11] = (2.*globalcoord[0]+globalcoord[3])/3.0;
1614 globalcoord[11+
k] = (2.*globalcoord[
k]+globalcoord[3+
k])/3.0;
1616 globalcoord[12] = (2.*globalcoord[11]+globalcoord[6])/3.0;
1617 globalcoord[12+
k] = (2.*globalcoord[11+
k]+globalcoord[6+
k])/3.0;
1618 globalcoord[13] = (2.*globalcoord[6]+globalcoord[11])/3.0;
1619 globalcoord[13+
k] = (2.*globalcoord[6+
k]+globalcoord[11+
k])/3.0;
1620 globalcoord[14] = (2.*globalcoord[7]+globalcoord[10])/3.0;
1621 globalcoord[14+
k] = (2.*globalcoord[7+
k]+globalcoord[10+
k])/3.0;
1622 globalcoord[15] = (2.*globalcoord[10]+globalcoord[7])/3.0;
1623 globalcoord[15+
k] = (2.*globalcoord[10+
k]+globalcoord[7+
k])/3.0;
1629 printf(
"ind[%d]=%d x=%.4lg y=%.4lg\n",i,ind[i],
1630 globalcoord[i],globalcoord[i+k]);
1655 if(sideno = cell[cellno].neighbour[
LEFT])
1656 elemind[1] =
GetElementIndices(&(cell[sideno]),cell[sideno].xelem,element,&(ind[0]));
1664 elemind[0] =
GetElementIndices(&(cell)[cellno],cell[cellno].xelem,element,&(ind[0]));
1665 if(sideno = cell[cellno].neighbour[
RIGHT])
1679 if(element == cell[cellno].yelem) more =
FALSE;
1681 if(sideno = cell[cellno].neighbour[
LEFT])
1682 elemind[1] =
GetElementIndices(&(cell[sideno]),cell[sideno].xelem,element,&(ind[0]));
1688 if(element == cell[cellno].yelem) more =
FALSE;
1689 elemind[0] =
GetElementIndices(&(cell)[cellno],cell[cellno].xelem,element,&(ind[0]));
1690 if(sideno = cell[cellno].neighbour[
RIGHT])
1697 if(element == cell[cellno].xelem) more =
FALSE;
1699 if(sideno = cell[cellno].neighbour[
DOWN])
1700 elemind[1] =
GetElementIndices(&(cell[sideno]),element,cell[sideno].yelem,&(ind[0]));
1706 if(element == cell[cellno].xelem) more =
FALSE;
1707 elemind[0] =
GetElementIndices(&(cell)[cellno],element,cell[cellno].yelem,&(ind[0]));
1708 if(sideno = cell[cellno].neighbour[
UP])
1715 printf(
"Impossible option in GetSideInfo.\n");
1725 int i,nzmax = 0,sumzelems;
1729 linearlimit = 0.001;
1732 for(i=1;i<=grid->
zcells;i++)
1736 for(i=1;i<=grid->
zcells;i++)
1743 printf(
"SetElementDivision: %d is too few elements in z-direction (min. %d)\n",
1750 for(i=1; i<= grid->
zcells ;i++) {
1751 if (fabs(1.-grid->
zexpand[i]) < linearlimit)
1763 for(i=1;i<=grid->
zcells;i++) {
1764 if(grid->
zelems[i] == 0)
continue;
1766 dz = (grid->
z[i] - grid->
z[i-1])/(grid->
zelems[i]+1);
1770 dz = (grid->
z[i] - grid->
z[i-1]) *
1771 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
zelems[i]+1)));
1775 else if(grid->
zelems[i]==1) {
1776 dz = (grid->
z[i] - grid->
z[i-1])/(grid->
zelems[i]+1);
1778 else if((grid->
zelems[i]+1)%2 == 0) {
1779 ratio = pow(-grid->
zexpand[i],1./((grid->
zelems[i]+1)/2-1.));
1780 dz = 0.5 * (grid->
z[i] - grid->
z[i-1]) *
1781 (1.-ratio) / (1.-pow(ratio,(
Real)((grid->
zelems[i]+1)/2)));
1783 else if((grid->
zelems[i]+1)%2 == 1) {
1785 dz = (grid->
z[i] - grid->
z[i-1]) /
1786 (2.0*(1.-pow(ratio,(
Real)((grid->
zelems[i]+1)/2)))/
1798 if(fabs(
dz - grid->
dx0) < fabs(
dz*(1.0/(1.0-1.0/grid->
zelems[i])) - grid->
dx0) ) {
1810 grid->
zelems[nzmax] += 1;
1819 for(i=1;i<=grid->
zcells;i++) {
1822 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1])/grid->
zelems[i];
1823 else if(grid->
zexpand[i] > 0.0) {
1826 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1]) *
1827 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
zelems[i])));
1829 else if(grid->
zelems[i] == 2) {
1830 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1])/grid->
zelems[i];
1832 else if(grid->
zelems[i]%2 == 0) {
1835 grid->
dz[i] = 0.5 * (grid->
z[i] - grid->
z[i-1]) *
1836 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
zelems[i]/2)));
1838 else if(grid->
zelems[i]%2 == 1) {
1841 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1]) /
1842 (2.0*(1.-pow(ratio,(
Real)(grid->
zelems[i]/2)))/
1847 if(info)
printf(
"Created %d extruded divisions.\n",
1864 for(i=0;grid->
x[i]<
eps;i++); k=i;
1879 printf(
"SetElementDivisionCylinder: The division must be linear!\n");
1881 for(i=1;i<=grid->
zcells;i++) {
1882 grid->
z[i] = i*(2.0*
FM_PI)/8.0;
1893 for(i=1;i<=grid->
zcells;i++) {
1895 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1])/grid->
zelems[i];
1896 else if(grid->
zexpand[i] > 0.0) {
1899 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1]) *
1900 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
zelems[i])));
1902 else if(grid->
zelems[i] == 2) {
1903 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1])/grid->
zelems[i];
1905 else if(grid->
zelems[i]%2 == 0) {
1908 grid->
dz[i] = 0.5 * (grid->
z[i] - grid->
z[i-1]) *
1909 (1.-ratio) / (1.-pow(ratio,(
Real)(grid->
zelems[i]/2)));
1911 else if(grid->
zelems[i]%2 == 1) {
1914 grid->
dz[i] = (grid->
z[i] - grid->
z[i-1]) /
1915 (2.0*(1.-pow(ratio,(
Real)(grid->
zelems[i]/2)))/
1919 if(dzmax < grid->
dz[i]) dzmax = grid->
dz[i];
1922 if(info)
printf(
"Created %d divisions in %d cells for rotation [%.2lg %.2lg].\n",
1940 charend = fgets(line0,MAXLINESIZE,io);
1941 isend = (charend == NULL);
1943 if(isend)
return(1);
1945 if(line0[0] ==
'#' || line0[0] ==
'%' || line0[0] ==
'!')
goto newline;
1946 if(!
matcactive && line0[0] ==
'*')
goto newline;
1950 matcpntr0 = strchr(line0,
'$');
1952 matcpntr = mtc_domath(&matcpntr0[1]);
1954 strcpy(matcpntr0, matcpntr);
1955 if(0)
printf(
"A: %s\n%s\n",matcpntr0,matcpntr);
1961 if(strstr(line0,
"subcell boundaries"))
goto newline;
1962 if(strstr(line0,
"material structure"))
goto newline;
1963 if(strstr(line0,
"mode"))
goto newline;
1964 if(strstr(line0,
"type"))
goto newline;
1967 line1[i] = toupper(line0[i]);
1975 int i,j,isend,empty;
1981 line2[i] = line1[i] = line0[i] =
' ';
1983 charend = fgets(line0,MAXLINESIZE,io);
1984 isend = (charend == NULL);
1986 if(isend)
return(1);
1988 if(line0[0] ==
'#' || line0[0] ==
'%' || line0[0] ==
'!' || line0[0] ==
'\n' || line0[1] ==
'\n')
goto newline;
1989 if(!
matcactive && line0[0] ==
'*')
goto newline;
1992 for(i=1;i<20;i++)
if(line0[i] !=
' ') empty =
FALSE;
1993 if(empty)
goto newline;
1997 matcpntr0 = strchr(line0,
'$');
1999 matcpntr = mtc_domath(&matcpntr0[1]);
2001 strcpy(matcpntr0, matcpntr);
2002 if(0)
printf(
"B: %s\n%s\n",matcpntr0,matcpntr);
2005 if(0)
printf(
"B0: %s\n",matcpntr0);
2014 if(line0[i] ==
'=') {
2018 line1[i] = toupper(line0[i]);
2022 if(strstr(line1,
"END"))
return(0);
2023 if(strstr(line1,
"NEW MESH"))
return(0);
2028 line2[i-j-1] = line0[i];
2032 charend = fgets(line2,MAXLINESIZE,io);
2033 isend = (charend == NULL);
2034 if(isend)
return(2);
2035 if(line2[0] ==
'#' || line2[0] ==
'%' || line2[0] ==
'!')
goto newline2;
2036 if(!
matcactive && line2[0] ==
'*')
goto newline2;
2040 matcpntr0 = strchr(line2,
'$');
2042 matcpntr = mtc_domath(&matcpntr0[1]);
2044 strcpy(matcpntr0, matcpntr);
2045 if(0)
printf(
"C: %s\n%s\n",matcpntr0,matcpntr);
2061 int sameline,maxsameline;
2067 out = fopen(filename,
"w");
2075 if(dim >= 2 && grid->
ycells > maxsameline) sameline =
FALSE;
2076 if(dim >= 3 && grid->
zcells > maxsameline) sameline =
FALSE;
2078 fprintf(out,
"##### ElmerGrid input file for structured grid generation ######\n");
2079 fprintf(out,
"Version = 210903\n");
2081 fprintf(out,
"Coordinate System = ");
2083 fprintf(out,
"2D Axisymmetric\n");
2085 fprintf(out,
"2D Polar\n");
2087 fprintf(out,
"Cartesian %dD\n",dim);
2089 fprintf(out,
"Subcell Divisions in %dD = ",dim);
2090 if(dim >= 1) fprintf(out,
"%d ",grid->
xcells);
2091 if(dim >= 2) fprintf(out,
"%d ",grid->
ycells);
2092 if(dim >= 3) fprintf(out,
"%d ",grid->
zcells);
2095 fprintf(out,
"Subcell Limits 1 %s",sameline ?
"= ":
"\n ");
2096 for(i=0;i <= grid->
xcells;i++)
2097 fprintf(out,
"%.5lg ",grid->
x[i]);
2101 fprintf(out,
"Subcell Limits 2 %s",sameline ?
"= ":
"\n ");
2102 for(i=0;i <= grid->
ycells;i++)
2103 fprintf(out,
"%.5lg ",grid->
y[i]);
2108 fprintf(out,
"Subcell Limits 3 %s",sameline ?
"= ":
"\n ");
2109 for(i=0;i <= grid->
zcells;i++)
2110 fprintf(out,
"%.5lg ",grid->
z[i]);
2114 fprintf(out,
"Material Structure in %dD\n",dim==1 ? 1:2);
2115 for(j=grid->
ycells;j>=1;j--) {
2117 for(i=1;i<=grid->
xcells;i++)
2118 fprintf(out,
"%-5d",grid->
structure[j][i]);
2121 fprintf(out,
"End\n");
2124 fprintf(out,
"Geometry Mappings\n");
2125 fprintf(out,
"# mode line limits(2) Np params(Np)\n");
2127 fprintf(out,
" %-5d %-5d %-7.5lg %-7.5lg %-3d ",
2135 fprintf(out,
"End\n");
2140 fprintf(out,
"Revolve Blocks = %d\n",grid[j].
rotateblocks);
2141 fprintf(out,
"Revolve Radius = %-8.3lg\n",grid[j].
rotateradius2);
2143 fprintf(out,
"Revolve Improve = %-8.3lg\n",grid[j].
rotateimprove);
2147 fprintf(out,
"Revolve Curve Direct = %-8.3lg\n",grid[j].
curvezet);
2148 fprintf(out,
"Revolve Curve Radius = %-8.3lg\n",grid[j].
curverad);
2149 fprintf(out,
"Revolve Curve Angle = %-8.3lg\n",grid[j].
curveangle);
2153 fprintf(out,
"Polar Radius = %.3lg\n",grid[j].
polarradius);
2158 if(j>0) fprintf(out,
"\nStart New Mesh\n");
2160 fprintf(out,
"Materials Interval = %d %d\n",
2164 fprintf(out,
"Extruded Structure\n");
2165 fprintf(out,
"# %-8s %-8s %-8s\n",
"1stmat",
"lastmat",
"newmat");
2166 for(i=1;i<=grid[j].
zcells;i++)
2167 fprintf(out,
" %-8d %-8d %-8d\n",
2170 fprintf(out,
"End\n");
2174 fprintf(out,
"Boundary Definitions\n");
2175 fprintf(out,
"# %-8s %-8s %-8s\n",
"type",
"out",
"int");
2177 fprintf(out,
" %-8d %-8d %-8d %-8d\n",
2180 fprintf(out,
"End\n");
2184 fprintf(out,
"Numbering = Horizontal\n");
2186 fprintf(out,
"Numbering = Vertical\n");
2188 fprintf(out,
"Element Degree = %d\n",grid[j].
elemorder);
2189 fprintf(out,
"Element Innernodes = %s\n",grid[j].
elemmidpoints ?
"True" :
"False");
2190 fprintf(out,
"Triangles = %s\n",grid[j].
triangles ?
"True" :
"False");
2192 fprintf(out,
"Surface Elements = %d\n",grid[j].
wantedelems);
2194 fprintf(out,
"Coordinate Ratios = %-8.3lg\n",grid[j].
xyratio);
2196 fprintf(out,
"Coordinate Ratios = %-8.3lg %-8.3lg\n",
2197 grid[j].xyratio,grid[j].
xzratio);
2199 fprintf(out,
"Minimum Element Divisions = %d",grid[j].
minxelems);
2200 if(dim >= 2) fprintf(out,
" %d",grid[j].
minyelems);
2201 if(dim >= 3) fprintf(out,
" %d",grid[j].
minzelems);
2204 fprintf(out,
"Element Ratios 1 %s",sameline ?
"= ":
"\n ");
2205 for(i=1;i<=grid[j].
xcells;i++)
2206 fprintf(out,
"%.3lg ",grid[j].
xexpand[i]);
2209 fprintf(out,
"Element Ratios 2 %s",sameline ?
"= ":
"\n ");
2210 for(i=1;i<=grid[j].
ycells;i++)
2211 fprintf(out,
"%.3lg ",grid[j].
yexpand[i]);
2215 fprintf(out,
"Element Ratios 3 %s",sameline ?
"= ":
"\n ");
2216 for(i=1;i<=grid[j].
zcells;i++)
2217 fprintf(out,
"%.3lg ",grid[j].
zexpand[i]);
2221 if(grid[j].autoratio) {
2222 fprintf(out,
"Element Densities 1 %s",sameline ?
"= ":
"\n ");
2223 for(i=1;i<=grid[j].
xcells;i++)
2224 fprintf(out,
"%.3lg ",grid[j].
xdens[i]);
2227 fprintf(out,
"Element Densities 2 %s",sameline ?
"= ":
"\n ");
2228 for(i=1;i<=grid[j].
ycells;i++)
2229 fprintf(out,
"%.3lg ",grid[j].
ydens[i]);
2233 fprintf(out,
"Element Densities 3 %s",sameline ?
"= ":
"\n ");
2234 for(i=1;i<=grid[j].
zcells;i++)
2235 fprintf(out,
"%.3lg ",grid[j].
zdens[i]);
2240 fprintf(out,
"Element Divisions 1 %s",sameline ?
"= ":
"\n ");
2241 for(i=1;i<=grid[j].
xcells;i++)
2242 fprintf(out,
"%d ",grid[j].
xelems[i]);
2245 fprintf(out,
"Element Divisions 2 %s",sameline ?
"= ":
"\n ");
2246 for(i=1;i<=grid[j].
ycells;i++)
2247 fprintf(out,
"%d ",grid[j].
yelems[i]);
2251 fprintf(out,
"Element Divisions 3 %s",sameline ?
"= ":
"\n ");
2252 for(i=1;i<=grid[j].
zcells;i++)
2253 fprintf(out,
"%d ",grid[j].
zelems[i]);
2261 if(info)
printf(
"The Elmergrid input was saved to file %s.\n",filename);
2279 int elemcode,maxnodes,totelems,nogrids0,minmat,maxmat;
2284 if ((in = fopen(filename,
"r")) == NULL) {
2285 printf(
"LoadElmergrid: opening of the file '%s' wasn't succesfull !\n",filename);
2289 if(info)
printf(
"Loading the geometry from file '%s'.\n",filename);
2298 axisymmetric =
FALSE;
2307 if(0)
printf(
"Reached the end of command file\n");
2312 if(strstr(command,
"VERSION")) {
2313 sscanf(params,
"%ld",&code);
2314 if(code == 210903) {
2315 if(info)
printf(
"Loading ElmerGrid file version: %d\n", (
int)code);
2318 printf(
"Unknown ElmerGrid file version: %d\n", (
int)code);
2324 else if(strstr(command,
"MATC")) {
2325 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2326 if(strstr(params,
"FALSE"))
2331 mtc_init(NULL, stdout, stderr);
2332 strcpy(command,
"format( 12 )");
2333 mtc_domath(command);
2334 if(info)
printf(
"MATC language activated with 12 digit accuracy.\n");
2336 printf(
"This version was compiled without MATC library.\n");
2342 else if(strstr(command,
"COORDINATE SYSTEM")) {
2343 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2345 if(strstr(params,
"CARTESIAN 1D")) {
2349 else if(strstr(params,
"CARTESIAN 2D"))
2351 else if(strstr(params,
"AXISYMMETRIC"))
2353 else if(strstr(params,
"POLAR"))
2355 else if(strstr(params,
"CARTESIAN 3D")) {
2359 else printf(
"Unknown coordinate system: %s\n",params);
2360 if(0)
printf(
"Defining the coordinate system (%d-DIM).\n",grid[k]->
dimension);
2363 else if(strstr(command,
"SUBCELL DIVISIONS")) {
2365 sscanf(params,
"%d",&(*grid)[k].
xcells);
2369 sscanf(params,
"%d %d",&(*grid)[k].
xcells,&(*grid)[k].
ycells);
2371 sscanf(params,
"%d %d %d",&(*grid)[k].xcells,&(*grid)[k].ycells,&(*grid)[k].
zcells);
2373 printf(
"LoadElmergrid: Too many subcells [%d %d %d] vs. %d:\n",
2374 grid[k]->xcells,grid[k]->ycells,grid[k]->zcells,
MAXCELLS);
2378 for(j=grid[k]->ycells;j>=1;j--)
2379 for(i=1;i<=grid[
k]->
xcells;i++)
2383 else if(strstr(command,
"MINIMUM ELEMENT DIVISION")) {
2384 if(0)
printf(
"Loading minimum number of elements\n");
2386 sscanf(params,
"%d",&(*grid)[k].
minxelems);
2388 sscanf(params,
"%d %d",&(*grid)[k].minxelems,&(*grid)[k].
minyelems);
2390 sscanf(params,
"%d %d %d",&(*grid)[k].minxelems,&(*grid)[k].minyelems,&(*grid)[k].
minzelems);
2393 else if(strstr(command,
"SUBCELL LIMITS 1")) {
2394 if(0)
printf(
"Loading [%d] subcell limits in X-direction\n",grid[k]->
xcells+1);
2398 else if(strstr(command,
"SUBCELL LIMITS 2")) {
2399 if(0)
printf(
"Loading [%d] subcell limits in Y-direction\n",grid[k]->
ycells+1);
2403 else if(strstr(command,
"SUBCELL LIMITS 3")) {
2404 if(0)
printf(
"Loading [%d] subcell limits in Z-direction\n",grid[k]->
zcells+1);
2409 else if(strstr(command,
"SUBCELL SIZES 1")) {
2410 if(0)
printf(
"Loading [%d] subcell sizes in X-direction\n",grid[k]->
xcells);
2413 for(i=1;i<=grid[
k]->
xcells;i++) grid[k]->
x[i] = grid[k]->
x[i-1] + grid[k]->
x[i];
2415 else if(strstr(command,
"SUBCELL SIZES 2")) {
2416 if(0)
printf(
"Loading [%d] subcell sizes in Y-direction\n",grid[k]->
ycells);
2419 for(i=1;i<=grid[
k]->
ycells;i++) grid[k]->
y[i] = grid[k]->
y[i-1] + grid[k]->
y[i];
2421 else if(strstr(command,
"SUBCELL SIZES 3")) {
2422 if(0)
printf(
"Loading [%d] subcell sizes in Z-direction\n",grid[k]->
zcells);
2425 for(i=1;i<=grid[
k]->
zcells;i++) grid[k]->
z[i] = grid[k]->
z[i-1] + grid[k]->
z[i];
2428 else if(strstr(command,
"SUBCELL ORIGIN 1")) {
2429 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2430 if(strstr(params,
"CENTER")) {
2431 raid = 0.5 * (grid[
k]->
x[0] + grid[
k]->
x[grid[
k]->
xcells]);
2433 else if(strstr(params,
"LEFT") || strstr(params,
"MIN") ) {
2434 raid = grid[
k]->
x[0];
2436 else if(strstr(params,
"RIGHT") || strstr(params,
"MAX") ) {
2443 for(i=0;i<=grid[
k]->
xcells;i++) grid[k]->
x[i] -= raid;
2445 else if(strstr(command,
"SUBCELL ORIGIN 2")) {
2446 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2447 if(strstr(params,
"CENTER")) {
2448 raid = 0.5 * (grid[
k]->
y[0] + grid[
k]->
y[grid[
k]->
ycells]);
2450 else if(strstr(params,
"LEFT")) {
2451 raid = grid[
k]->
y[0];
2453 else if(strstr(params,
"RIGHT")) {
2460 for(i=0;i<=grid[
k]->
ycells;i++) grid[k]->
y[i] -= raid;
2462 else if(strstr(command,
"SUBCELL ORIGIN 3")) {
2463 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2464 if(strstr(params,
"CENTER")) {
2465 raid = 0.5 * (grid[
k]->
z[0] + grid[
k]->
z[grid[
k]->
zcells]);
2467 else if(strstr(params,
"LEFT")) {
2468 raid = grid[
k]->
z[0];
2470 else if(strstr(params,
"RIGHT")) {
2477 for(i=0;i<=grid[
k]->
zcells;i++) grid[k]->
z[i] -= raid;
2480 else if(strstr(command,
"MATERIAL STRUCTURE")) {
2481 if(0)
printf(
"Loading material structure\n");
2484 for(j=grid[k]->
ycells;j>=1;j--)
2485 for(i=1;i<=grid[
k]->
xcells;i++)
2488 for(j=grid[k]->
ycells;j>=1;j--) {
2491 for(i=1;i<=grid[
k]->
xcells;i++)
2495 for(j=grid[k]->
ycells;j>=1;j--)
2496 for(i=1;i<=grid[
k]->
xcells;i++) {
2503 printf(
"LoadElmergrid: please use positive material indices.\n");
2505 printf(
"LoadElmergrid: material indices larger to %d may create problems.\n",
2508 else if(strstr(command,
"MATERIALS INTERVAL")) {
2512 else if(strstr(command,
"REVOLVE")) {
2513 if(strstr(command,
"REVOLVE RADIUS")) {
2514 (*grid)[
k].rotate =
TRUE;
2517 else if(strstr(command,
"REVOLVE BLOCKS")) {
2518 (*grid)[
k].rotate =
TRUE;
2521 else if(strstr(command,
"REVOLVE IMPROVE")) {
2522 (*grid)[
k].rotate =
TRUE;
2525 else if(strstr(command,
"REVOLVE RADIUS")) {
2528 else if(strstr(command,
"REVOLVE CURVE DIRECT")) {
2529 (*grid)[
k].rotatecurve =
TRUE;
2530 sscanf(params,
"%le",&(*grid)[k].
curvezet);
2532 else if(strstr(command,
"REVOLVE CURVE RADIUS")) {
2533 (*grid)[
k].rotatecurve =
TRUE;
2534 sscanf(params,
"%le",&(*grid)[k].
curverad);
2536 else if(strstr(command,
"REVOLVE CURVE ANGLE")) {
2537 (*grid)[
k].rotatecurve =
TRUE;
2542 else if(strstr(command,
"REDUCE ORDER INTERVAL")) {
2547 else if(strstr(command,
"BOUNDARY DEFINITION")) {
2548 if(0)
printf(
"Loading boundary conditions\n");
2552 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2553 if(strstr(params,
"END"))
break;
2554 sscanf(params,
"%d %d %d %d",
2558 if(0)
printf(
"Found %d boundaries\n",i);
2559 (*grid)[
k].noboundaries = i;
2562 else if(strstr(command,
"LAYERED BOUNDARIES")) {
2563 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2564 if(strstr(params,
"TRUE")) (*grid)[
k].layeredbc = 1;
2565 if(strstr(params,
"FALSE")) (*grid)[
k].layeredbc = 0;
2568 else if(strstr(command,
"NUMBERING")) {
2569 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2570 if(strstr(params,
"HORIZONATAL")) (*grid)[
k].numbering =
NUMBER_XY;
2571 if(strstr(params,
"VERTICAL")) (*grid)[
k].numbering =
NUMBER_YX;
2574 else if(strstr(command,
"ELEMENT DEGREE")) {
2575 sscanf(params,
"%d",&(*grid)[k].
elemorder);
2578 else if(strstr(command,
"ELEMENT INNERNODES")) {
2579 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2580 if(strstr(params,
"TRUE")) (*grid)[
k].elemmidpoints =
TRUE;
2581 if(strstr(params,
"FALSE")) (*grid)[
k].elemmidpoints =
FALSE;
2583 else if(strstr(command,
"ELEMENTTYPE") || strstr(command,
"ELEMENTCODE")) {
2584 sscanf(params,
"%d",&elemcode);
2587 else if(strstr(command,
"TRIANGLES CRITICAL ANGLE")) {
2590 else if(strstr(command,
"TRIANGLES")) {
2591 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2592 if(strstr(params,
"TRUE")) (*grid)[
k].triangles =
TRUE;
2593 if(strstr(params,
"FALSE")) (*grid)[
k].triangles =
FALSE;
2596 else if(strstr(command,
"PLANE ELEMENTS")) {
2599 else if(strstr(command,
"SURFACE ELEMENTS")) {
2602 else if(strstr(command,
"REFERENCE DENSITY")) {
2603 sscanf(params,
"%le",&(*grid)[k].
limitdx);
2604 (*grid)[
k].autoratio = 3;
2606 else if(strstr(command,
"VERIFY DENSITY")) {
2607 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2608 if(strstr(params,
"TRUE")) (*grid)[
k].limitdxverify =
TRUE;
2609 if(strstr(params,
"FALSE")) (*grid)[
k].limitdxverify =
FALSE;
2611 else if(strstr(command,
"COORDINATE RATIO")) {
2613 sscanf(params,
"%le",&(*grid)[k].
xyratio);
2615 sscanf(params,
"%le %le",&(*grid)[k].xyratio,&(*grid)[k].
xzratio);
2618 else if(strstr(command,
"ELEMENT RATIOS 1")) {
2620 for(i=1;i<=(*grid)[
k].xcells;i++) (*grid)[
k].xexpand[i] =
next_real(&cp);
2622 else if(strstr(command,
"ELEMENT RATIOS 2")) {
2624 for(i=1;i<=(*grid)[
k].ycells;i++) (*grid)[
k].yexpand[i] =
next_real(&cp);
2626 else if(strstr(command,
"ELEMENT RATIOS 3")) {
2628 for(i=1;i<=(*grid)[
k].zcells;i++) (*grid)[
k].zexpand[i] =
next_real(&cp);
2631 else if(strstr(command,
"ELEMENT DENSITIES 1")) {
2633 for(i=1;i<=(*grid)[
k].xcells;i++) (*grid)[
k].xdens[i] =
next_real(&cp);
2635 else if(strstr(command,
"ELEMENT DENSITIES 2")) {
2637 for(i=1;i<=(*grid)[
k].ycells;i++) (*grid)[
k].ydens[i] =
next_real(&cp);
2639 else if(strstr(command,
"ELEMENT DENSITIES 3")) {
2641 for(i=1;i<=(*grid)[
k].zcells;i++) (*grid)[
k].zdens[i] =
next_real(&cp);
2644 else if(strstr(command,
"ELEMENT DIVISIONS 1")) {
2646 for(i=1;i<=(*grid)[
k].xcells;i++) (*grid)[
k].xelems[i] =
next_int(&cp);
2647 (*grid)[
k].autoratio = 0;
2649 else if(strstr(command,
"ELEMENT DIVISIONS 2")) {
2651 for(i=1;i<=(*grid)[
k].ycells;i++) (*grid)[
k].yelems[i] =
next_int(&cp);
2652 (*grid)[
k].autoratio = 0;
2654 else if(strstr(command,
"ELEMENT DIVISIONS 3")) {
2656 for(i=1;i<=(*grid)[
k].zcells;i++) (*grid)[
k].zelems[i] =
next_int(&cp);
2657 (*grid)[
k].autoratio = 0;
2660 else if(strstr(command,
"EXTRUDED STRUCTURE")) {
2661 for(i=1;i<=(*grid)[
k].zcells;i++) {
2663 sscanf(params,
"%d %d %d\n",
2668 else if(strstr(command,
"GEOMETRY MAPPINGS")) {
2669 if(k > 0) (*grid)[
k].mappings = 0;
2671 for(i=0;i<
MAXLINESIZE;i++) params[i] = toupper(params[i]);
2675 if(strstr(params,
"END"))
break;
2677 (*grid)[
k].mappingtype[i] =
next_int(&cp);
2681 (*grid)[
k].mappingline[i] =
next_int(&cp);
2682 (*grid)[
k].mappinglimits[2*i] =
next_real(&cp);
2683 (*grid)[
k].mappinglimits[2*i+1] =
next_real(&cp);
2684 (*grid)[
k].mappingpoints[i] =
next_int(&cp);
2686 for(j=0;j<(*grid)[
k].mappingpoints[i];j++)
2687 (*grid)[
k].mappingparams[i][j] =
next_real(&cp);
2689 if(0)
printf(
"Loaded %d geometry mappings\n",i);
2690 (*grid)[
k].mappings = i;
2693 else if(strstr(command,
"END") ) {
2694 if(0)
printf(
"End of field\n");
2697 else if(strstr(command,
"START NEW MESH")) {
2699 printf(
"There are more grids than was allocated for!\n");
2700 printf(
"Ignoring meshes starting from %d\n.",(*nogrids)+1);
2704 if(0)
printf(
"\nLoading element meshing no %d\n",*nogrids);
2706 if(k > nogrids0) (*grid)[
k] = (*grid)[k-1];
2710 if(1)
printf(
"Unknown command: %s",command);
2716 if(0)
printf(
"Found %d divisions for grid\n",*nogrids);
2718 for(k=nogrids0;k < (*nogrids) && k<
MAXCASES;k++) {
2722 (*grid)[
k].nonodes = (*grid)[
k].elemorder + 1;
2725 (*grid)[
k].nonodes = 4 * (*grid)[
k].elemorder;
2728 if((*grid)[k].
elemorder == 2) (*grid)[
k].nonodes = 9;
2729 if((*grid)[k].
elemorder == 3) (*grid)[
k].nonodes = 16;
2732 else if(elemcode/100 == 2) {
2733 (*grid)[
k].triangles =
FALSE;
2734 (*grid)[
k].nonodes = elemcode%100;
2736 else if(elemcode/100 == 4) {
2737 (*grid)[
k].triangles =
FALSE;
2738 (*grid)[
k].nonodes = elemcode%100;
2740 else if(elemcode/100 == 3) {
2741 (*grid)[
k].triangles =
TRUE;
2742 if(elemcode%100 == 3) (*grid)[
k].nonodes = 4;
2743 else if(elemcode%100 == 6) (*grid)[
k].nonodes = 9;
2744 else if(elemcode%100 == 10) (*grid)[
k].nonodes = 16;
2832 if (in = fopen(
"ELMERGRID_STARTINFO",
"r")) {
2833 fscanf(in,
"%s",filename);
2835 printf(
"Using the file %s defined in ELMERGRID_STARTINFO\n",filename);
2836 if ((in = fopen(filename,
"r")) == NULL) {
2837 printf(
"LoadCommands: opening of the file '%s' wasn't succesfull!\n",filename);
2840 else printf(
"Loading ElmerGrid commands from file '%s'.\n",filename);
2847 if ((in = fopen(filename,
"r")) == NULL) {
2848 printf(
"LoadCommands: opening of the file '%s' wasn't succesfull!\n",filename);
2851 if(info)
printf(
"Loading ElmerGrid commands from file '%s'.\n",filename);
2853 else if(mode == 2) {
2855 if ((in = fopen(filename,
"r")) == NULL) {
2856 printf(
"LoadCommands: opening of the file '%s' wasn't succesfull!\n",filename);
2859 if(info)
printf(
"Loading ElmerGrid commands from file '%s'.\n",filename);
2867 if(0)
printf(
"Reached the end of command file\n");
2874 if(strstr(command,
"INPUT FILE")) {
2875 sscanf(params,
"%s", &(eg->
filesin[0]));
2878 else if(strstr(command,
"OUTPUT FILE")) {
2879 sscanf(params,
"%s",&(eg->
filesout[0]));
2882 else if(strstr(command,
"INPUT MODE")) {
2883 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2886 if(strstr(params,IOmethods[i])) {
2894 else if(strstr(command,
"OUTPUT MODE")) {
2895 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2899 if(strstr(params,IOmethods[i])) {
2910 if(strstr(command,
"DECIMALS")) {
2913 else if(strstr(command,
"TRIANGLES CRITICAL ANGLE")) {
2916 else if(strstr(command,
"TRIANGLES")) {
2917 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2920 else if(strstr(command,
"MERGE NODES")) {
2922 sscanf(params,
"%le",&eg->
cmerge);
2924 else if(strstr(command,
"UNITE")) {
2925 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2928 else if(strstr(command,
"ORDER NODES")) {
2931 sscanf(params,
"%le",&eg->
corder[0]);
2932 else if(eg->
dim == 2)
2934 else if(eg->
dim == 3)
2937 else if(strstr(command,
"SCALE")) {
2940 sscanf(params,
"%le",&eg->
cscale[0]);
2941 else if(eg->
dim == 2)
2943 else if(eg->
dim == 3)
2946 else if(strstr(command,
"CENTRALIZE")) {
2949 else if(strstr(command,
"TRANSLATE")) {
2953 else if(eg->
dim == 2)
2955 else if(eg->
dim == 3)
2958 else if(strstr(command,
"ROTATE MESH")) {
2962 else if(strstr(command,
"CLONE")) {
2963 if(strstr(command,
"CLONE SIZE")) {
2966 else if(eg->
dim == 2)
2968 else if(eg->
dim == 3)
2973 sscanf(params,
"%d",&eg->
clone[0]);
2974 else if(eg->
dim == 2)
2975 sscanf(params,
"%d%d",&eg->
clone[0],&eg->
clone[1]);
2976 else if(eg->
dim == 3)
2981 else if(strstr(command,
"POLAR RADIUS")) {
2985 else if(strstr(command,
"CYLINDER")) {
2986 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2989 else if(strstr(command,
"REDUCE DEGREE")) {
2993 else if(strstr(command,
"INCREASE DEGREE")) {
2994 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
2997 else if(strstr(command,
"ADVANCED ELEMENTS")) {
2998 printf(
"Loading advanced element definitions\n");
3002 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3003 if(strstr(params,
"END"))
break;
3005 sscanf(params,
"%d%d%d%d%d%d%d",
3011 printf(
"Found %d definitions for advanced elements.\n",i);
3013 else if(strstr(command,
"POWER ELEMENTS")) {
3014 printf(
"Loading p-type element definitions\n");
3018 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3019 if(strstr(params,
"END"))
break;
3020 sscanf(params,
"%d%d%d",
3024 printf(
"Found %d definitions for p-elements.\n",i);
3026 else if(strstr(command,
"BUBBLE ELEMENTS")) {
3027 printf(
"Loading bubble element definitions\n");
3031 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3032 if(strstr(params,
"END"))
break;
3033 sscanf(params,
"%d%d%d",
3037 printf(
"Found %d definitions for bubble elements.\n",i);
3039 else if(strstr(command,
"METIS OPTION")) {
3041 sscanf(params,
"%d",&eg->
partopt);
3043 printf(
"This version of ElmerGrid was compiled without Metis library!\n");
3046 else if(strstr(command,
"METIS")) {
3048 sscanf(params,
"%d",&eg->
metis);
3050 printf(
"This version of ElmerGrid was compiled without Metis library!\n");
3053 else if(strstr(command,
"PARTITION ORDER")) {
3056 if(eg->
dim == 3) sscanf(params,
"%le%le%le",&eg->
partcorder[0],
3059 else if(strstr(command,
"PARTITION")) {
3063 for(i=0;i<eg->
dim;i++) {
3068 else if(strstr(command,
"PERIODIC")) {
3073 else if(strstr(command,
"HALO")) {
3074 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3077 else if(strstr(command,
"INDIRECT")) {
3078 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3081 else if(strstr(command,
"BOUNDARY TYPE MAPPINGS")) {
3084 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3085 if(strstr(params,
"END"))
break;
3089 printf(
"Found %d boundary type mappings\n",i);
3092 else if(strstr(command,
"BULK TYPE MAPPINGS")) {
3095 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3096 if(strstr(params,
"END"))
break;
3100 printf(
"Found %d bulk type mappings\n",i);
3103 else if(strstr(command,
"BOUNDARY BOUNDARY")) {
3106 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3107 if(strstr(params,
"END"))
break;
3111 printf(
"Found %d boundary boundary definitions\n",i);
3114 else if(strstr(command,
"MATERIAL BOUNDARY")) {
3117 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3118 if(strstr(params,
"END"))
break;
3122 printf(
"Found %d material boundary definitions\n",i);
3126 else if(strstr(command,
"RENUMBER BOUNDARY")) {
3128 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3129 if(strstr(params,
"END"))
break;
3133 printf(
"Found %d boundary mappings\n",i);
3136 else if(strstr(command,
"RENUMBER MATERIAL")) {
3138 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3139 if(strstr(params,
"END"))
break;
3143 printf(
"Found %d material mappings\n",i);
3147 else if(strstr(command,
"BOUNDARY LAYER")) {
3148 if(strstr(command,
"BOUNDARY LAYER MOVE")) {
3151 else if(strstr(command,
"BOUNDARY LAYER EPSILON")) {
3152 sscanf(params,
"%le",&eg->
layereps);
3157 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3160 if(strstr(params,
"END") || strstr(params,
"End") )
break;
3167 printf(
"Found %d boundary layers\n",i);
3171 else if(strstr(command,
"REMOVE LOWER DIMENSIONAL BOUNDARIES")) {
3172 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3175 else if(strstr(command,
"REMOVE UNUSED NODES")) {
3176 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3179 else if(strstr(command,
"REORDER MATERIAL")) {
3180 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3183 else if(strstr(command,
"REORDER BOUNDARY")) {
3184 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3187 else if(strstr(command,
"DIMENSION")) {
3188 sscanf(params,
"%d",&eg->
dim);
3190 else if(strstr(command,
"ISOPARAMETRIC")) {
3191 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3194 else if(strstr(command,
"NO BOUNDARY")) {
3195 for(j=0;j<
MAXLINESIZE;j++) params[j] = toupper(params[j]);
3198 else if(strstr(command,
"EXTRUDED")) {
3201 if(strstr(command,
"EXTRUDED DIVISIONS")) {
3202 sscanf(params,
"%d",&grid->
zcells);
3204 else if(strstr(command,
"EXTRUDED LIMITS")) {
3208 else if(strstr(command,
"EXTRUDED ELEMENTS")) {
3213 else if(strstr(command,
"EXTRUDED RATIOS")) {
3217 else if(strstr(command,
"EXTRUDED DENSITIES")) {
3221 else if(strstr(command,
"EXTRUDED STRUCTURE")) {
3222 for(i=1;i<= grid->
zcells;i++) {
3224 sscanf(params,
"%d %d %d\n",
3233 if(0)
printf(
"Read commands from a file\n");