44 phi [0] = 0.;
phi [1] = 90.;
60 memset(
this, 0x00,
sizeof(
Mgrid));
63 if (fread(
this,
sizeof(
MgridHeader), 1, fin) != 1)
return;
99 (tail && fread(
properties,
sizeof(
char), tail, fin) != tail))
124 mgrid->
coord = *coord;
125 mgrid->
field = *field;
129 for(
int ik=0; ik<3; ik++)
136 printf(
"[create_single_mgrid_header()]: dir[] pointer should be NULL"
137 " for fake coordinates\n");
146 mgrid->
dir[ik] = *dir[ik];
260 for(
int ik=0; ik<3; ik++)
263 for(
int ik=0; ik<3; ik++)
292 for(
int ik=0; ik<3; ik++)
327 if (!inter)
return -1;
356 int adim[3] = {4, 3, 3};
357 char sequence[3] = {
'Y',
'X',
'Z'};
368 if ( !htci)
return -1;
412 if (!cname)
return -1;
415 if (
this != inter->
_mgrid)
return -1;
418 for(
int ik=0; ik<3; ik++)
422 if (ik == cname->
id)
break;
462 #define quad1(x,xarr,yarr) \
463 (d3 = ((x)-(xarr)[2])/((xarr)[1]-(xarr)[0]), \
464 d1 = ((x)-(xarr)[1])/((xarr)[2]-(xarr)[0]), \
465 d2 = ((x)-(xarr)[0])/((xarr)[2]-(xarr)[1]), \
466 ( (yarr)[2]*d1*d2 + d3*((yarr)[0]*d1-(yarr)[1]*d2) ))
468 #define quad2(x,xarr,yarr) \
469 (d6 = ((x)-(xarr)[2])/((xarr)[1]-(xarr)[0]), \
470 d4 = ((x)-(xarr)[1])/((xarr)[2]-(xarr)[0]), \
471 d5 = ((x)-(xarr)[0])/((xarr)[2]-(xarr)[1]), \
472 ( (yarr)[2]*d4*d5 + d6*((yarr)[0]*d4-(yarr)[1]*d5) ))
474 static double quad3(
double x,
double xa[4],
double ya[4])
477 double d1,d2,d3,d4,d5,d6;
478 if( xa[1] < xa[2] ) {
482 return quad1( x, xa, ya);
486 return quad1( x, xa+1, ya+1);
488 return (
quad1( x, xa, ya) * w2 +
quad2( x, xa+1, ya+1) * w1 )/(w1+w2);
492 return quad1( x, xa, ya);
496 return quad1( x, xa+1, ya+1);
498 return (
quad1( x, xa, ya) * w2 +
quad2( x, xa+1, ya+1) * w1 )/(w1+w2);
516 double slope = (value[1] - value[0])/(coord[1] - coord[0]);
518 return value[0] + slope*(xx - coord[0]);
528 return quad1(xx, coord, value);
551 for(
int ik=0; ik<3; ik++)
553 if (_adim[ik] < 1 || _adim[ik] > 4 ||
555 _adim[ik] > this->
dir[ik].
dim)
559 inter->
adim[ik] = _adim[ik];
566 for(
int ik=0; ik<3; ik++)
579 for(
int ik=0; ik<3; ik++)
582 if (inter->
v[ik])
delete[] inter->
v[ik];
605 for(
int ik=0; ik<3; ik++)
625 for(
int ik=0; ik<3; ik++)
627 if (_pdim[ik] < 1 || _pdim[ik] >
dir[ik].
dim ||
628 (!
coord.
fake[ik] && _pdim[ik] >= _adim[ik]))
631 inter->
pdim[ik] = _pdim[ik];
652 for(
int ik=0; ik<3; ik++)
672 for(
int ik=0; ik<3; ik++)
676 if (pdim[ik] < 1 || pdim[ik] > inter->
adim[ik])
return NULL;
679 inter->
pdim[ik] = pdim[ik];
691 int pdim[],
char sequence[])
698 if (adim || pdim || sequence)
return NULL;
701 if (pdim)
return NULL;
704 if (pdim)
return NULL;
709 if (pdim || sequence)
return NULL;
712 if (sequence)
return NULL;
714 default:
return NULL;
724 for(
int ik=0; ik<3; ik++)
725 if (
id[ik] < 0 ||
id[ik] >=
dir[ik].
dim)
return -1;
737 if (linear < 0 || linear >=
cell_num)
return -1;
740 for(
int ik=
_Z_; ik>=
_X_; ik--)
744 id[ik] = linear % pdir->
dim;
755 if (linear < 0 || linear >=
cell_num)
return NULL;
766 if (linear == -1)
return NULL;
775 for(
int ik=0; ik<3; ik++)
780 if (
id[ik] < 0 ||
id[ik] >= pdir->
dim)
return -1;
782 xx[ik] = pdir->
min + (
id[ik] + 0.5)*pdir->
step;
794 if (linear < 0 || linear >=
cell_num)
return -1;
813 if (linear < 0 || linear >=
cell_num)
return -1;
828 for(
int ik=0; ik<3; ik++)
836 if (xx[ik] < pdir->
min)
841 if (xx[ik] > pdir->
max)
845 id[ik] = (int)floor((xx[ik] - pdir->
min)/pdir->
step);
850 if (
id[ik] < 0 ||
id[ik] >= pdir->
dim) ret = -1;
875 if (linear == -1)
return -1;
901 TVector3 xv(xx[0], xx[1], xx[2]);
958 unsigned char *addr =
cells;
970 if (contents >> 2)
return -1;
976 if (fwrite(
this,
sizeof(
MgridHeader), 1, fout) != 1)
return -1;
1004 if (tail && fwrite(
properties,
sizeof(
char), tail, fout) != tail)
1019 FILE *fout = fopen(file_name,
"w");
1020 if (!fout)
return -1;
1069 #define COORD_NAMES_NUM (sizeof(coord_names)/sizeof(coord_names[0]))
1077 if (name == cname->
name)
1100 if (
sizeof(
double) != 8)
return 0;
1110 int shift_flag = 0, rotation_flag = 0;
1111 TVector3 basis[3],
buffer;
1115 for(
int ik=0; ik<3; ik++)
1124 phi [0] != 0. ||
phi [1] != 90.)
1127 if (!shift_flag && !rotation_flag &&
position)
1147 for(
int ik=0; ik<3; ik++)
1159 for(
int ii=1; ii<3; ii++)
1161 for(
int ik=0; ik<ii; ik++)
1163 projection = basis[ii].Dot(basis[ik]);
1167 basis[ii] -= projection * basis[ik];
1170 basis[ii].SetMag(1.0);
1173 buffer = basis[0].Cross(basis[1]);
1176 if (buffer.Dot(basis[2]) < 0.)
1178 printf(
"Transformation to a left-handed system!\n");
1186 for(
int ii=0; ii<3; ii++)
1187 for(
int ik=0; ik<3; ik++)
1205 for(
int ik=0; ik<3; ik++)
1206 shift[ik] = _shift[ik];
1209 for(
int ik=0; ik<3; ik++)
1210 theta[ik] = _theta[ik];
1213 for(
int ik=0; ik<3; ik++)
1214 phi [ik] = _phi [ik];
1228 int i012[3], seq[3], rev[3];
1267 for(
int ik=0; ik<3; ik++)
1282 for(i012[2]=0; i012[2]<inter->
adim[seq[2]]; i012[2]++)
1284 for(i012[1]=0; i012[1]<inter->
adim[seq[1]]; i012[1]++)
1287 for(i012[0]=0; i012[0]<inter->
adim[seq[0]]; i012[0]++)
1317 for(i012[2]=0; i012[2]<inter->
adim[seq[2]]; i012[2]++)
1321 for(i012[1]=0; i012[1]<inter->
adim[seq[1]]; i012[1]++)
1326 for(i012[0]=0; i012[0]<inter->
adim[seq[0]]; i012[0]++)
1332 point0->
f = cell->
B[cmp];
1391 for(
int ik=0; ik<3; ik++)
1399 for(
int ik=0; ik<3; ik++)
1400 if (inter->
left[ik])
1433 for(
int ik=0; ik<3; ik++)
1470 unsigned char wanted_field_coord_system_type = D->
system_type;
1503 for(
int ik=0; ik<3; ik++)
1519 for(
int ik=0; ik<3; ik++)
1520 D->
xx[ik] += DL.
xx[ik];
1567 for(
int ik=0; ik<3; ik++)
1581 for(
int ik=0; ik<3; ik++)
1598 for(
int ik=0; ik<3; ik++)
1629 unsigned char desired_coord_system)
1631 double angle_in_radians;
1635 if (X->
system_type == desired_coord_system)
return *X;
1649 XL.
xx[
_Y_] = X->
xx[
_R_]*sin(angle_in_radians);
1669 unsigned char desired_coord_system)
1674 if (D->
system_type == desired_coord_system)
return;
1677 for(
int ik=0; ik<2; ik++)
1679 bff[ik] = D->
xx[ik];
1691 mtx[1][0] = -mtx[1][0];
1692 mtx[0][1] = -mtx[0][1];
1699 for(
int ii=0; ii<2; ii++)
1700 for(
int ik=0; ik<2; ik++)
1701 D->
xx[ii] += mtx[ii][ik]*bff[ik];
1712 unsigned char wanted_field_coord_system_type)
1716 double angle_in_radians;
1730 mtx[0][0] = mtx[1][1] =
cos(angle_in_radians);
1731 mtx[0][1] = sin(angle_in_radians);
1732 mtx[1][0] = -mtx[0][1];
1756 if (D->
system_type != wanted_field_coord_system_type)
1783 for(
int iqq=0; iqq<3; iqq++)