9 #define _CELL_SIZE_ (2.0)
24 mCellSize(
_CELL_SIZE_), mScale(1.0), mRdim(0), mZdim(0), mRmin(0.0), mZmin(0.0),
25 mUseInterpolation(
false), mFieldMap(0)
27 FILE *fmap = fopen(fname,
"r");
29 printf(
"Failed to open '%s' for reading!\n", fname);
32 #ifdef _USE_ORIGINAL_ELMER_FILE_
33 FILE *fout = fopen(
"mfield.4col.dat",
"w");
39 std::vector<BeastMagneticFieldCell> cells;
40 std::set<double> rset, zset;
43 while (fgets(buffer, 1024-1, fmap)) {
46 #ifdef _USE_ORIGINAL_ELMER_FILE_
48 sscanf(buffer,
"%le %lf %lf %le %le %le %le", &dummy, &dummy, &dummy, &r, &z, &br, &bz);
51 r *= 100.0; z *= 100.0;
52 fprintf(fout,
"%6.1f %6.1f %7.4f %7.4f\n", r, z, br, bz);
54 sscanf(buffer,
"%lf %lf %lf %lf", &r, &z, &br, &bz);
58 if (!r && enforce_axial_symmetry) br = 0.0;
60 rset.insert(r); zset.insert(z);
72 printf(
"Line count in the input file (%d) does not match the grid size (%d x %d)\n",
80 bool ok[
dim]; memset(ok,
false,
sizeof(ok));
83 for(
auto cell: cells) {
88 assert(ir >=0 && ir < (
int)
mRdim && iz >= 0 && iz < (
int)mZdim);
91 unsigned id = ir*mZdim + iz;
94 printf(
"Duplicate cells in the map file (%d,%d)!\n", ir, iz);
97 ok[id] =
true;
mFieldMap[id] = std::make_pair(cell.mBR, cell.mBZ);
103 #ifdef _USE_ORIGINAL_ELMER_FILE_
119 double &bx,
double &by,
double &bz)
const
121 double r = sqrt(x*x + y*y), br;
124 if (!ret)
return false;
126 double fi = atan2(y, x);
127 bx = br*
cos(fi); by = br*sin(fi);
140 if (r < 0.0)
return false;
149 if (ir < 0 || ir >= (
int)
mRdim-1 || iz < 0 || iz >= (int)
mZdim-1)
return false;
153 double wt[2][2] = {{(1.0-qdr)*(1.0-qdz), (1.0-qdr)*qdz},
154 { qdr *(1.0-qdz), qdr *qdz}};
156 for(
unsigned ip=0;
ip<2;
ip++)
157 for(
unsigned iq=0; iq<2; iq++)
159 for(
unsigned ip=0;
ip<2;
ip++)
160 for(
unsigned iq=0; iq<2; iq++)
163 for(
unsigned ip=0;
ip<2;
ip++)
164 for(
unsigned iq=0; iq<2; iq++) {
167 br += wt[
ip][iq]*cell.first;
168 bz += wt[
ip][iq]*cell.second;
176 if (ir < 0 || ir >= (
int)
mRdim || iz < 0 || iz >= (int)
mZdim)
return false;
178 unsigned id = ir*
mZdim + iz;
179 const std::pair<double, double> &cell =
mFieldMap[id];
180 br = cell.first; bz = cell.second;