18 const double z,
double& ex,
double& ey,
19 double& ez,
double& p,
Medium*& m,
27 <<
" Field map is not available for interpolation.\n";
34 unsigned int i = 0, j = 0, k = 0;
35 bool xMirrored =
false, yMirrored =
false, zMirrored =
false;
36 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
42 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
43 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl;
60 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
61 <<
"adjusted indices:\n "
62 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl;
67 Element& element = m_efields[i][j][k];
68 double ex000 = element.fx;
69 double ey000 = element.fy;
70 double ez000 = element.fz;
71 if (xMirrored) ex = -ex;
72 if (yMirrored) ey = -ey;
73 if (zMirrored) ez = -ez;
74 double p000 = element.v;
76 int region = m_regions[i][j][k];
77 if (region < 0 || region > (
int)m_media.size()) {
82 Medium* m000 = m_media[region];
83 if (!m000) status = -5;
85 element = m_efields[i + 1][j][k];
86 double ex100 = element.fx;
87 double ey100 = element.fy;
88 double ez100 = element.fz;
89 if (xMirrored) ex = -ex;
90 if (yMirrored) ey = -ey;
91 if (zMirrored) ez = -ez;
92 double p100 = element.v;
94 region = m_regions[i + 1][j][k];
95 if (region < 0 || region > (
int)m_media.size()) {
100 Medium* m100 = m_media[region];
101 if (!m100) status = -5;
103 element = m_efields[i][j + 1][k];
104 double ex010 = element.fx;
105 double ey010 = element.fy;
106 double ez010 = element.fz;
107 if (xMirrored) ex = -ex;
108 if (yMirrored) ey = -ey;
109 if (zMirrored) ez = -ez;
110 double p010 = element.v;
112 region = m_regions[i][j + 1][k];
113 if (region < 0 || region > (
int)m_media.size()) {
118 Medium* m010 = m_media[region];
119 if (!m010) status = -5;
121 element = m_efields[i][j][k + 1];
122 double ex001 = element.fx;
123 double ey001 = element.fy;
124 double ez001 = element.fz;
125 if (xMirrored) ex = -ex;
126 if (yMirrored) ey = -ey;
127 if (zMirrored) ez = -ez;
128 double p001 = element.v;
130 region = m_regions[i][j][k + 1];
131 if (region < 0 || region > (
int)m_media.size()) {
136 Medium* m001 = m_media[region];
137 if (!m001) status = -5;
139 element = m_efields[i + 1][j + 1][k];
140 double ex110 = element.fx;
141 double ey110 = element.fy;
142 double ez110 = element.fz;
143 if (xMirrored) ex = -ex;
144 if (yMirrored) ey = -ey;
145 if (zMirrored) ez = -ez;
146 double p110 = element.v;
148 region = m_regions[i + 1][j + 1][k];
149 if (region < 0 || region > (
int)m_media.size()) {
154 Medium* m110 = m_media[region];
155 if (!m110) status = -5;
157 element = m_efields[i + 1][j][k + 1];
158 double ex101 = element.fx;
159 double ey101 = element.fy;
160 double ez101 = element.fz;
161 if (xMirrored) ex = -ex;
162 if (yMirrored) ey = -ey;
163 if (zMirrored) ez = -ez;
164 double p101 = element.v;
166 region = m_regions[i + 1][j][k + 1];
167 if (region < 0 || region > (
int)m_media.size()) {
172 Medium* m101 = m_media[region];
173 if (!m101) status = -5;
175 element = m_efields[i][j + 1][k + 1];
176 double ex011 = element.fx;
177 double ey011 = element.fy;
178 double ez011 = element.fz;
179 if (xMirrored) ex = -ex;
180 if (yMirrored) ey = -ey;
181 if (zMirrored) ez = -ez;
182 double p011 = element.v;
184 region = m_regions[i][j + 1][k + 1];
185 if (region < 0 || region > (
int)m_media.size()) {
190 Medium* m011 = m_media[region];
191 if (!m011) status = -5;
193 element = m_efields[i + 1][j + 1][k + 1];
194 double ex111 = element.fx;
195 double ey111 = element.fy;
196 double ez111 = element.fz;
197 if (xMirrored) ex = -ex;
198 if (yMirrored) ey = -ey;
199 if (zMirrored) ez = -ez;
200 double p111 = element.v;
202 region = m_regions[i + 1][j + 1][k + 1];
203 if (region < 0 || region > (
int)m_media.size()) {
208 Medium* m111 = m_media[region];
209 if (!m111) status = -5;
211 double delx = (m_xMax - m_xMin) /
double(m_nX - 1);
212 double x0 = m_xMin + double(i) * delx;
213 double x1 = m_xMin + double(i + 1) * delx;
214 double dely = (m_yMax - m_yMin) /
double(m_nY - 1);
215 double y0 = m_yMin + double(j) * dely;
216 double y1 = m_yMin + double(j + 1) * dely;
217 double delz = (m_zMax - m_zMin) /
double(m_nZ - 1);
218 double z0 = m_zMin + double(k) * delz;
219 double z1 = m_zMin + double(k + 1) * delz;
220 double dx0 = (x - x0);
221 double dx1 = (x1 - x);
222 double dy0 = (y - y0);
223 double dy1 = (y1 - y);
224 double dz0 = (z - z0);
225 double dz1 = (z1 - z);
226 double xd = (x - x0) / (x1 - x0);
227 if (xd < 0.0) xd = 0.0;
228 if (xd > 1.0) xd = 1.0;
229 double yd = (y - y0) / (y1 - y0);
230 if (yd < 0.0) yd = 0.0;
231 if (yd > 1.0) yd = 1.0;
232 double zd = (z - z0) / (z1 - z0);
233 if (zd < 0.0) zd = 0.0;
234 if (zd > 1.0) zd = 1.0;
235 ex = TriLinInt(xd, yd, zd, ex000, ex100, ex010, ex001, ex110, ex101, ex011,
237 ey = TriLinInt(xd, yd, zd, ey000, ey100, ey010, ey001, ey110, ey101, ey011,
239 ez = TriLinInt(xd, yd, zd, ez000, ez100, ez010, ez001, ez110, ez101, ez011,
241 p = TriLinInt(xd, yd, zd, p000, p100, p010, p001, p110, p101, p011, p111);
247 double d000 = sqrt(dx0 * dx0 + dy0 * dy0 + dz0 * dz0);
248 double d100 = sqrt(dx1 * dx1 + dy0 * dy0 + dz0 * dz0);
249 double d010 = sqrt(dx0 * dx0 + dy1 * dy1 + dz0 * dz0);
250 double d001 = sqrt(dx0 * dx0 + dy0 * dy0 + dz1 * dz1);
251 double d110 = sqrt(dx1 * dx1 + dy1 * dy1 + dz0 * dz0);
252 double d101 = sqrt(dx1 * dx1 + dy0 * dy0 + dz1 * dz1);
253 double d011 = sqrt(dx0 * dx0 + dy1 * dy1 + dz1 * dz1);
254 double d111 = sqrt(dx1 * dx1 + dy1 * dy1 + dz1 * dz1);
259 double mindst = d000;
261 if (d100 <= mindst) {
265 }
else if (d010 <= mindst) {
269 }
else if (d001 <= mindst) {
273 }
else if (d110 <= mindst) {
277 }
else if (d101 <= mindst) {
281 }
else if (d011 <= mindst) {
285 }
else if (d111 <= mindst) {
292 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
293 <<
"i, j, k: " << i <<
", " << j <<
", " << k <<
"\n"
294 <<
"000=> ex, ey, ez, p, m: " << ex000 <<
", " << ey000 <<
", "
295 << ez000 <<
", " << p000 <<
", " << m000 <<
"\n"
296 <<
"100=> ex, ey, ez, p, m: " << ex100 <<
", " << ey100 <<
", "
297 << ez100 <<
", " << p100 <<
", " << m100 << std::endl
298 <<
"010=> ex, ey, ez, p, m: " << ex010 <<
", " << ey010 <<
", "
299 << ez010 <<
", " << p010 <<
", " << m010 << std::endl
300 <<
"001=> ex, ey, ez, p, m: " << ex001 <<
", " << ey001 <<
", "
301 << ez001 <<
", " << p001 <<
", " << m001 << std::endl
302 <<
"110=> ex, ey, ez, p, m: " << ex110 <<
", " << ey110 <<
", "
303 << ez110 <<
", " << p110 <<
", " << m110 << std::endl
304 <<
"101=> ex, ey, ez, p, m: " << ex101 <<
", " << ey101 <<
", "
305 << ez101 <<
", " << p101 <<
", " << m101 << std::endl
306 <<
"011=> ex, ey, ez, p, m: " << ex011 <<
", " << ey011 <<
", "
307 << ez011 <<
", " << p011 <<
", " << m011 << std::endl
308 <<
"111=> ex, ey, ez, p, m: " << ex111 <<
", " << ey111 <<
", "
309 << ez111 <<
", " << p111 <<
", " << m111 << std::endl
310 <<
"delx, x, x0, x1, dx0, dx1, xd: " << delx <<
", " << x <<
", "
311 << x0 <<
", " << x1 <<
", " << dx0 <<
", " << dx1 <<
", " << xd
313 <<
"dely, y, y0, y1, dy0, dy1, yd: " << dely <<
", " << y <<
", "
314 << y0 <<
", " << y1 <<
", " << dy0 <<
", " << dy1 <<
", " << yd
316 <<
"delz, z, z0, z1, dz0, dz1, zd: " << delz <<
", " << z <<
", "
317 << z0 <<
", " << z1 <<
", " << dz0 <<
", " << dz1 <<
", " << zd
319 <<
"Values after LinInt=> ex, ey, ez, p, m: " << ex <<
", " << ey
320 <<
", " << ez <<
", " << p <<
", " << m << std::endl;
332 const double z,
double& ex,
double& ey,
333 double& ez,
Medium*& m,
int& status) {
339 const double z,
double& wx,
double& wy,
341 const std::string& ) {
345 const double x1 = x - m_wField_xOffset;
346 const double y1 = y - m_wField_yOffset;
347 const double z1 = z - m_wField_zOffset;
353 const std::string& ) {
357 const double x1 = x - m_wField_xOffset;
358 const double y1 = y - m_wField_yOffset;
359 const double z1 = z - m_wField_zOffset;
360 double wx = 0., wy = 0., wz = 0.;
368 m_wField_xOffset = x;
369 m_wField_yOffset = y;
370 m_wField_zOffset = z;
374 const double z,
double& bx,
double& by,
375 double& bz,
int& status) {
381 unsigned int i = 0, j = 0, k = 0;
382 bool xMirrored =
false, yMirrored =
false, zMirrored =
false;
383 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
389 const Element& element = m_bfields[i][j][k];
393 if (xMirrored) bx = -bx;
394 if (yMirrored) by = -by;
395 if (zMirrored) bz = -bz;
403 <<
" Field map is not available for interpolation.\n";
407 unsigned int i, j, k;
408 bool xMirrored, yMirrored, zMirrored;
409 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
412 const int region = m_regions[i][j][k];
413 if (region < 0 || region > (
int)m_media.size())
return nullptr;
414 return m_media[region];
419 const std::string& MapInfoFile, std::string& MapVersion,
int& OptMap,
420 int& OptStaggerMap,
unsigned int& NbOfXCells,
unsigned int& NbOfYCells,
421 unsigned int& NbOfZCells,
double& Xmin,
double& Xmax,
double& Ymin,
422 double& Ymax,
double& Zmin,
double& Zmax,
double& XStagger,
423 double& YStagger,
double& ZStagger, std::string& MapDataFile) {
424 std::ifstream infile;
425 infile.open(MapInfoFile.c_str(), std::ios::in);
428 <<
" Could not open file " << MapInfoFile <<
".\n";
433 unsigned int nLines = 0;
436 if (!infile.fail()) {
438 std::getline(infile, line);
441 std::istringstream data;
447 <<
" Error reading line " << nLines <<
".\n"
448 <<
" Cannot retrieve MapVersion.\n";
454 if (!infile.fail()) {
456 std::getline(infile, line);
459 std::istringstream data;
465 <<
" Error reading line " << nLines <<
".\n"
466 <<
" Cannot retrieve OptMap.\n";
472 if (!infile.fail()) {
474 std::getline(infile, line);
477 std::istringstream data;
479 data >> OptStaggerMap;
483 <<
" Error reading line " << nLines <<
".\n"
484 <<
" Cannot retrieve OptStaggerMap.\n";
490 if (!infile.fail()) {
492 std::getline(infile, line);
495 std::istringstream data;
501 <<
" Error reading line " << nLines <<
".\n"
502 <<
" Cannot retrieve NbOfXCells.\n";
508 if (!infile.fail()) {
510 std::getline(infile, line);
513 std::istringstream data;
519 <<
" Error reading line " << nLines <<
".\n"
520 <<
" Cannot retrieve NbOfYCells.\n";
526 if (!infile.fail()) {
528 std::getline(infile, line);
531 std::istringstream data;
537 <<
" Error reading line " << nLines <<
".\n"
538 <<
" Cannot retrieve NbOfZCells.\n";
544 if (!infile.fail()) {
546 std::getline(infile, line);
549 std::istringstream data;
551 data >> Xmin >> Xmax;
555 <<
" Error reading line " << nLines <<
".\n"
556 <<
" Cannot retrieve Xmin, Xmax.\n";
562 if (!infile.fail()) {
564 std::getline(infile, line);
567 std::istringstream data;
569 data >> Ymin >> Ymax;
573 <<
" Error reading line " << nLines <<
".\n"
574 <<
" Cannot retrieve Ymin, Ymax.\n";
580 if (!infile.fail()) {
582 std::getline(infile, line);
585 std::istringstream data;
587 data >> Zmin >> Zmax;
591 <<
" Error reading line " << nLines <<
".\n"
592 <<
" Cannot retrieve Zmin, Zmax.\n";
598 if (!infile.fail()) {
600 std::getline(infile, line);
603 std::istringstream data;
609 <<
" Error reading line " << nLines <<
".\n"
610 <<
" Cannot retrieve XStagger.\n";
616 if (!infile.fail()) {
618 std::getline(infile, line);
621 std::istringstream data;
627 <<
" Error reading line " << nLines <<
".\n"
628 <<
" Cannot retrieve YStagger.\n";
634 if (!infile.fail()) {
636 std::getline(infile, line);
639 std::istringstream data;
645 <<
" Error reading line " << nLines <<
".\n"
646 <<
" Cannot retrieve ZStagger.\n";
652 if (!infile.fail()) {
654 std::getline(infile, line);
657 std::istringstream data;
663 <<
" Error reading line " << nLines <<
".\n"
664 <<
" Cannot retrieve MapDataFile.\n";
673 const unsigned int nz,
const double xmin,
674 const double xmax,
const double ymin,
675 const double ymax,
const double zmin,
678 if (nx == 0 || ny == 0 || nz == 0) {
680 <<
" Number of mesh elements must be positive.\n";
684 std::cerr <<
m_className <<
"::SetMesh: Invalid x range.\n";
686 }
else if (ymin >= ymax) {
687 std::cerr <<
m_className <<
"::SetMesh: Invalid y range.\n";
689 }
else if (zmin >= zmax) {
690 std::cerr <<
m_className <<
"::SetMesh: Invalid z range.\n";
706 const std::string& filename,
const std::string& format,
707 const bool withPotential,
const bool withRegion,
const double scaleX,
708 const double scaleE,
const double scaleP) {
710 m_hasPotential = m_hasEfield =
false;
712 std::cerr <<
m_className <<
"::LoadElectricField:\n"
713 <<
" Mesh is not set. Call SetMesh first.\n";
718 m_efields.resize(m_nX);
719 m_regions.resize(m_nX);
720 for (
unsigned int i = 0; i < m_nX; ++i) {
721 m_efields[i].resize(m_nY);
722 m_regions[i].resize(m_nY);
723 for (
unsigned int j = 0; j < m_nY; ++j) {
724 m_efields[i][j].resize(m_nZ);
725 m_regions[i][j].resize(m_nZ);
726 for (
unsigned int k = 0; k < m_nZ; ++k) {
727 m_efields[i][j][k].fx = 0.;
728 m_efields[i][j][k].fy = 0.;
729 m_efields[i][j][k].fz = 0.;
730 m_efields[i][j][k].v = 0.;
731 m_regions[i][j][k] = 0;
736 m_pMin = m_pMax = 0.;
741 return LoadData(filename, format, withPotential, withRegion, scaleX, scaleE,
746 const std::string& format,
748 const double scaleB) {
751 std::cerr <<
m_className <<
"::LoadMagneticField:\n"
752 <<
" Mesh is not set. Call SetMesh first.\n";
757 m_bfields.resize(m_nX);
758 for (
unsigned int i = 0; i < m_nX; ++i) {
759 m_bfields[i].resize(m_nY);
760 for (
unsigned int j = 0; j < m_nY; ++j) {
761 m_bfields[i][j].resize(m_nZ);
762 for (
unsigned int k = 0; k < m_nZ; ++k) {
763 m_bfields[i][j][k].fx = 0.;
764 m_bfields[i][j][k].fy = 0.;
765 m_bfields[i][j][k].fz = 0.;
766 m_bfields[i][j][k].v = 0.;
771 return LoadData(filename, format,
false,
false, scaleX, scaleB, 1.,
'b');
774bool ComponentNeBem3dMap::LoadData(
const std::string& filename,
775 std::string format,
const bool withPotential,
776 const bool withRegion,
const double scaleX,
777 const double scaleF,
const double scaleP,
780 std::cerr <<
m_className <<
"::LoadData: Mesh has not been set.\n";
784 unsigned int nValues = 0;
786 std::vector<std::vector<std::vector<bool> > > isSet(
788 std::vector<std::vector<bool> >(m_nY, std::vector<bool>(m_nZ,
false)));
790 std::ifstream infile;
791 infile.open(filename.c_str(), std::ios::in);
794 <<
" Could not open file " << filename <<
".\n";
798 std::transform(format.begin(), format.end(), format.begin(), toupper);
799 unsigned int fmt = 0;
800 if (format ==
"XY") {
802 }
else if (format ==
"XYZ") {
804 }
else if (format ==
"IJ") {
806 }
else if (format ==
"IJK") {
808 }
else if (format ==
"YXZ") {
812 <<
" Unkown format (" << format <<
").\n";
816 unsigned int nLines = 0;
818 while (!infile.fail()) {
820 std::getline(infile, line);
825 if (line.empty())
continue;
827 if (line[0] ==
'#')
continue;
828 if (line[0] ==
'/' && line[1] ==
'/')
continue;
837 std::istringstream data;
845 <<
" Error reading line " << nLines <<
".\n"
846 <<
" Cannot retrieve element coordinates.\n";
852 const double z = 0.5 * (m_zMin + m_zMax);
853 bool xMirrored, yMirrored, zMirrored;
854 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
856 <<
" Error reading line " << nLines <<
".\n"
857 <<
" Point is outside mesh.\n";
861 }
else if (fmt == 2) {
867 <<
" Error reading line " << nLines <<
".\n"
868 <<
" Cannot retrieve element coordinates.\n";
875 bool xMirrored, yMirrored, zMirrored;
876 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
878 <<
" Error reading line " << nLines <<
".\n"
879 <<
" Point is outside mesh.\n";
883 }
else if (fmt == 3) {
889 <<
" Error reading line " << nLines <<
".\n"
890 <<
" Cannot retrieve element index.\n";
894 }
else if (fmt == 4) {
899 <<
" Error reading line " << nLines <<
".\n"
900 <<
" Cannot retrieve element index.\n";
904 }
else if (fmt == 5) {
906 double x,
y,
z, temp;
907 data >>
y >>
x >> temp;
911 <<
" Error reading line " << nLines <<
".\n"
912 <<
" Cannot retrieve element coordinates.\n";
919 bool xMirrored, yMirrored, zMirrored;
920 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
922 <<
" Error reading line " << nLines <<
".\n"
923 <<
" Point is outside mesh.\n";
929 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
931 <<
" Error reading line " << nLines <<
".\n"
932 <<
" Index (" << i <<
", " << j <<
", " << k
933 <<
") out of range.\n";
936 if (isSet[i][j][k]) {
938 <<
" Error reading line " << nLines <<
".\n"
939 <<
" Mesh element (" << i <<
", " << j <<
", " << k
940 <<
") has already been set.\n";
944 if (fmt == 1 || fmt == 3) {
948 }
else if (fmt == 5) {
950 data >> fy >> fx >> temp;
953 data >> fx >> fy >> fz;
957 <<
" Error reading line " << nLines <<
".\n"
958 <<
" Cannot read field values.\n";
969 <<
" Error reading line " << nLines <<
".\n"
970 <<
" Cannot read potential.\n";
975 if (m_pMin > m_pMax) {
980 if (v < m_pMin) m_pMin = v;
981 if (v > m_pMax) m_pMax = v;
988 <<
" Error reading line " << nLines <<
".\n"
989 <<
" Cannot read region.\n";
994 if (fmt == 1 || fmt == 3) {
996 for (
unsigned int kk = 0; kk < m_nZ; ++kk) {
998 m_efields[i][j][kk].fx = fx;
999 m_efields[i][j][kk].fy = fy;
1000 m_efields[i][j][kk].fz = fz;
1001 m_efields[i][j][kk].v = v;
1002 m_regions[i][j][kk] = region;
1003 }
else if (field ==
'b') {
1004 m_bfields[i][j][kk].fx = fx;
1005 m_bfields[i][j][kk].fy = fy;
1006 m_bfields[i][j][kk].fz = fz;
1008 isSet[i][j][kk] =
true;
1012 m_efields[i][j][k].fx = fx;
1013 m_efields[i][j][k].fy = fy;
1014 m_efields[i][j][k].fz = fz;
1015 m_efields[i][j][k].v = v;
1016 m_regions[i][j][k] = region;
1017 }
else if (field ==
'b') {
1018 m_bfields[i][j][k].fx = fx;
1019 m_bfields[i][j][k].fy = fy;
1020 m_bfields[i][j][k].fz = fz;
1022 isSet[i][j][k] =
true;
1026 if (bad)
return false;
1028 <<
" Read " << nValues <<
" values from " << filename <<
".\n";
1029 unsigned int nExpected = m_nX * m_nY;
1030 if (fmt == 2 || fmt == 4 || fmt == 5) nExpected *= m_nZ;
1031 if (nExpected != nValues) {
1033 <<
" Expected " << nExpected <<
" values.\n";
1038 if (withPotential) m_hasPotential =
true;
1039 }
else if (field ==
'b') {
1046 double& zmin,
double& xmax,
1047 double& ymax,
double& zmax) {
1083 double& eymin,
double& eymax,
1084 double& ezmin,
double& ezmax) {
1086 std::cerr <<
m_className <<
"::GetElectricFieldRange:\n";
1087 std::cerr <<
" Field map not available.\n";
1091 exmin = exmax = m_efields[0][0][0].fx;
1092 eymin = eymax = m_efields[0][0][0].fy;
1093 ezmin = ezmax = m_efields[0][0][0].fz;
1094 for (
unsigned int i = 0; i < m_nX; ++i) {
1095 for (
unsigned int j = 0; j < m_nY; ++j) {
1096 for (
unsigned int k = 0; k < m_nZ; ++k) {
1097 const Element& element = m_efields[i][j][k];
1098 if (element.fx < exmin) exmin = element.fx;
1099 if (element.fx > exmax) exmax = element.fx;
1100 if (element.fy < eymin) eymin = element.fy;
1101 if (element.fy > eymax) eymax = element.fy;
1102 if (element.fz < ezmin) ezmin = element.fz;
1103 if (element.fz > ezmax) ezmax = element.fz;
1114 <<
" Field map not yet initialised.\n";
1118 if (m_media.empty()) {
1119 std::cerr <<
m_className <<
"::PrintRegions: No regions defined.\n";
1124 std::cout <<
" Index Medium\n";
1125 const unsigned int nMedia = m_media.size();
1126 for (
unsigned int i = 0; i < nMedia; ++i) {
1127 const std::string name = m_media[i] ? m_media[i]->GetName() :
"none";
1128 std::cout <<
" " << i <<
" " << name <<
"\n";
1134 std::cerr <<
m_className <<
"::SetMedium: Null pointer.\n";
1135 if (m_media.empty())
return;
1137 if (i >= m_media.size()) m_media.resize(i + 1,
nullptr);
1142 if (i > m_media.size()) {
1143 std::cerr <<
m_className <<
"::GetMedium: Index out of range.\n";
1150 const double zi,
unsigned int& i,
1151 unsigned int& j,
unsigned int& k,
1152 bool& xMirrored,
bool& yMirrored,
1153 bool& zMirrored)
const {
1155 std::cerr <<
m_className <<
"::GetElement: Mesh is not set.\n";
1163 if (x < m_xMin || x > m_xMax)
return false;
1166 if (y < m_yMin || y > m_yMax)
return false;
1169 if (z < m_zMin || z > m_zMax)
return false;
1175 const double dy = (m_yMax - m_yMin) / (m_nY - 1);
1176 const double dz = (m_zMax - m_zMin) / (m_nZ - 1);
1177 i = (
unsigned int)((x - m_xMin) / dx);
1178 j = (
unsigned int)((y - m_yMin) / dy);
1179 k = (
unsigned int)((z - m_zMin) / dz);
1180 if (i >= m_nX) i = m_nX - 1;
1181 if (j >= m_nY) j = m_nY - 1;
1182 if (k >= m_nZ) k = m_nZ - 1;
1185 <<
"x, y, z: " << x <<
", " << y <<
", " << z << std::endl
1186 <<
"m_xMax, m_yMax, m_zMax: " << m_xMax <<
", " << m_yMax <<
", "
1187 << m_zMax << std::endl
1188 <<
"m_xMin, m_yMin, m_zMin: " << m_xMin <<
", " << m_yMin <<
", "
1189 << m_zMin << std::endl
1190 <<
"m_nX, m_nY, m_nZ: " << m_nX <<
", " << m_nY <<
", " << m_nZ
1192 <<
"dx, dy, dz: " << dx <<
", " << dy <<
", " << dz << std::endl
1193 <<
"x-m_xMin, y-m_yMin, z-m_zMin: " << x - m_xMin <<
", "
1194 << y - m_yMin <<
", " << z - m_zMin << std::endl
1195 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl
1196 <<
"End GetElement" << std::endl;
1202 const unsigned int k,
double& v,
1203 double& ex,
double& ey,
double& ez)
const {
1204 v = ex = ey = ez = 0.;
1207 std::cerr <<
m_className <<
"::GetElement: Mesh not set.\n";
1210 std::cerr <<
m_className <<
"::GetElement: Field map not set.\n";
1213 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
1214 std::cerr <<
m_className <<
"::GetElement: Index out of range.\n";
1217 const Element& element = m_efields[i][j][k];
1225void ComponentNeBem3dMap::Reset() {
1229 m_nX = m_nY = m_nZ = 0;
1230 m_xMin = m_yMin = m_zMin = 0.;
1231 m_xMax = m_yMax = m_zMax = 0.;
1232 m_pMin = m_pMax = 0.;
1236 m_hasPotential =
false;
1237 m_hasEfield =
false;
1238 m_hasBfield =
false;
1242void ComponentNeBem3dMap::UpdatePeriodicity() {
1244 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1245 <<
" Field map not available.\n";
1250 for (
unsigned int i = 0; i < 3; ++i) {
1252 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1253 <<
" Both simple and mirror periodicity requested. Reset.\n";
1259 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1260 <<
" Axial symmetry is not supported. Reset.\n";
1266 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1267 <<
" Rotation symmetry is not supported. Reset.\n";
1272double ComponentNeBem3dMap::Reduce(
const double xin,
const double xmin,
1273 const double xmax,
const bool simplePeriodic,
1274 const bool mirrorPeriodic,
1275 bool& mirrored)
const {
1278 const double lx = xmax - xmin;
1279 if (simplePeriodic) {
1280 x = xmin + fmod(x - xmin, lx);
1281 if (x < xmin)
x += lx;
1282 }
else if (mirrorPeriodic) {
1283 double xNew = xmin + fmod(x - xmin, lx);
1284 if (xNew < xmin) xNew += lx;
1285 const int nx = int(floor(0.5 + (xNew - x) / lx));
1286 if (nx != 2 * (nx / 2)) {
1287 xNew = xmin + xmax - xNew;
1295double ComponentNeBem3dMap::TriLinInt(
const double xd,
const double yd,
1296 const double zd,
const double c000,
1297 const double c100,
const double c010,
1298 const double c001,
const double c110,
1299 const double c101,
const double c011,
1300 const double c111) {
1301 double c00 = c000 * (1.0 - xd) + c100 * xd;
1302 double c10 = c010 * (1.0 - xd) + c110 * xd;
1303 double c01 = c001 * (1.0 - xd) + c101 * xd;
1304 double c11 = c011 * (1.0 - xd) + c111 * xd;
1305 double c0 = c00 * (1.0 - yd) + c10 * yd;
1306 double c1 = c01 * (1.0 - yd) + c11 * yd;
1307 return (c0 * (1.0 - zd) + c1 * zd);
Abstract base class for components.
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
std::array< bool, 3 > m_rotationSymmetric
Rotation symmetry around x-axis, y-axis, z-axis.
std::array< bool, 3 > m_axiallyPeriodic
Axial periodicity in x, y, z.
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
bool m_ready
Ready for use?
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.
std::string m_className
Class name.
bool m_debug
Switch on/off debugging messages.
bool GetElement(const double xi, const double yi, const double zi, unsigned int &i, unsigned int &j, unsigned int &k, bool &xMirrored, bool &yMirrored, bool &zMirrored) const
Return the indices of the element at a given point.
void SetMedium(const unsigned int i, Medium *m)
Set the medium in region i.
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
void PrintRegions() const
Print all regions.
bool LoadMapInfo(const std::string &MapInfoFile, std::string &MapVersion, int &OptMap, int &OptStaggerMap, unsigned int &NbOfXCells, unsigned int &NbOfYCells, unsigned int &NbOfZCells, double &Xmin, double &Xmax, double &Ymin, double &Ymax, double &Zmin, double &Zmax, double &XStagger, double &YStagger, double &ZStagger, std::string &MapDataFile)
Map related information.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
Calculate the drift field [V/cm] and potential [V] at (x, y, z).
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
ComponentNeBem3dMap()
Constructor.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
bool LoadMagneticField(const std::string &filename, const std::string &format, const double scaleX=1., const double scaleB=1.)
Import magnetic field values from a file.
bool GetElectricFieldRange(double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
bool LoadElectricField(const std::string &filename, const std::string &format, const bool withPotential, const bool withRegion, const double scaleX=1., const double scaleE=1., const double scaleP=1.)
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void SetMesh(const unsigned int nx, const unsigned int ny, const unsigned int nz, const double xmin, const double xmax, const double ymin, const double ymax, const double zmin, const double zmax)
void SetWeightingFieldOffset(const double x, const double y, const double z)
Abstract base class for media.
void ltrim(std::string &line)