16 const double z,
double& ex,
double& ey,
17 double& ez,
double& p,
Medium*& m,
25 <<
" Field map is not available for interpolation.\n";
32 unsigned int i = 0, j = 0, k = 0;
33 bool xMirrored =
false, yMirrored =
false, zMirrored =
false;
34 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
40 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
41 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl;
58 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
59 <<
"adjusted indices:\n "
60 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl;
65 Element& element = m_efields[i][j][k];
66 double ex000 = element.fx;
67 double ey000 = element.fy;
68 double ez000 = element.fz;
69 if (xMirrored) ex = -ex;
70 if (yMirrored) ey = -ey;
71 if (zMirrored) ez = -ez;
72 double p000 = element.v;
74 int region = m_regions[i][j][k];
75 if (region < 0 || region > (
int)m_media.size()) {
80 Medium* m000 = m_media[region];
81 if (!m000) status = -5;
83 element = m_efields[i + 1][j][k];
84 double ex100 = element.fx;
85 double ey100 = element.fy;
86 double ez100 = element.fz;
87 if (xMirrored) ex = -ex;
88 if (yMirrored) ey = -ey;
89 if (zMirrored) ez = -ez;
90 double p100 = element.v;
92 region = m_regions[i + 1][j][k];
93 if (region < 0 || region > (
int)m_media.size()) {
98 Medium* m100 = m_media[region];
99 if (!m100) status = -5;
101 element = m_efields[i][j + 1][k];
102 double ex010 = element.fx;
103 double ey010 = element.fy;
104 double ez010 = element.fz;
105 if (xMirrored) ex = -ex;
106 if (yMirrored) ey = -ey;
107 if (zMirrored) ez = -ez;
108 double p010 = element.v;
110 region = m_regions[i][j + 1][k];
111 if (region < 0 || region > (
int)m_media.size()) {
116 Medium* m010 = m_media[region];
117 if (!m010) status = -5;
119 element = m_efields[i][j][k + 1];
120 double ex001 = element.fx;
121 double ey001 = element.fy;
122 double ez001 = element.fz;
123 if (xMirrored) ex = -ex;
124 if (yMirrored) ey = -ey;
125 if (zMirrored) ez = -ez;
126 double p001 = element.v;
128 region = m_regions[i][j][k + 1];
129 if (region < 0 || region > (
int)m_media.size()) {
134 Medium* m001 = m_media[region];
135 if (!m001) status = -5;
137 element = m_efields[i + 1][j + 1][k];
138 double ex110 = element.fx;
139 double ey110 = element.fy;
140 double ez110 = element.fz;
141 if (xMirrored) ex = -ex;
142 if (yMirrored) ey = -ey;
143 if (zMirrored) ez = -ez;
144 double p110 = element.v;
146 region = m_regions[i + 1][j + 1][k];
147 if (region < 0 || region > (
int)m_media.size()) {
152 Medium* m110 = m_media[region];
153 if (!m110) status = -5;
155 element = m_efields[i + 1][j][k + 1];
156 double ex101 = element.fx;
157 double ey101 = element.fy;
158 double ez101 = element.fz;
159 if (xMirrored) ex = -ex;
160 if (yMirrored) ey = -ey;
161 if (zMirrored) ez = -ez;
162 double p101 = element.v;
164 region = m_regions[i + 1][j][k + 1];
165 if (region < 0 || region > (
int)m_media.size()) {
170 Medium* m101 = m_media[region];
171 if (!m101) status = -5;
173 element = m_efields[i][j + 1][k + 1];
174 double ex011 = element.fx;
175 double ey011 = element.fy;
176 double ez011 = element.fz;
177 if (xMirrored) ex = -ex;
178 if (yMirrored) ey = -ey;
179 if (zMirrored) ez = -ez;
180 double p011 = element.v;
182 region = m_regions[i][j + 1][k + 1];
183 if (region < 0 || region > (
int)m_media.size()) {
188 Medium* m011 = m_media[region];
189 if (!m011) status = -5;
191 element = m_efields[i + 1][j + 1][k + 1];
192 double ex111 = element.fx;
193 double ey111 = element.fy;
194 double ez111 = element.fz;
195 if (xMirrored) ex = -ex;
196 if (yMirrored) ey = -ey;
197 if (zMirrored) ez = -ez;
198 double p111 = element.v;
200 region = m_regions[i + 1][j + 1][k + 1];
201 if (region < 0 || region > (
int)m_media.size()) {
206 Medium* m111 = m_media[region];
207 if (!m111) status = -5;
209 double delx = (m_xMax - m_xMin) /
double(m_nX - 1);
210 double x0 = m_xMin + double(i) * delx;
211 double x1 = m_xMin + double(i + 1) * delx;
212 double dely = (m_yMax - m_yMin) /
double(m_nY - 1);
213 double y0 = m_yMin + double(j) * dely;
214 double y1 = m_yMin + double(j + 1) * dely;
215 double delz = (m_zMax - m_zMin) /
double(m_nZ - 1);
216 double z0 = m_zMin + double(k) * delz;
217 double z1 = m_zMin + double(k + 1) * delz;
218 double dx0 = (x - x0);
219 double dx1 = (x1 - x);
220 double dy0 = (y - y0);
221 double dy1 = (y1 - y);
222 double dz0 = (z - z0);
223 double dz1 = (z1 - z);
224 double xd = (x - x0) / (x1 - x0);
225 if (xd < 0.0) xd = 0.0;
226 if (xd > 1.0) xd = 1.0;
227 double yd = (y - y0) / (y1 - y0);
228 if (yd < 0.0) yd = 0.0;
229 if (yd > 1.0) yd = 1.0;
230 double zd = (z - z0) / (z1 - z0);
231 if (zd < 0.0) zd = 0.0;
232 if (zd > 1.0) zd = 1.0;
233 ex = TriLinInt(xd, yd, zd, ex000, ex100, ex010, ex001, ex110, ex101, ex011,
235 ey = TriLinInt(xd, yd, zd, ey000, ey100, ey010, ey001, ey110, ey101, ey011,
237 ez = TriLinInt(xd, yd, zd, ez000, ez100, ez010, ez001, ez110, ez101, ez011,
239 p = TriLinInt(xd, yd, zd, p000, p100, p010, p001, p110, p101, p011, p111);
245 double d000 = sqrt(dx0 * dx0 + dy0 * dy0 + dz0 * dz0);
246 double d100 = sqrt(dx1 * dx1 + dy0 * dy0 + dz0 * dz0);
247 double d010 = sqrt(dx0 * dx0 + dy1 * dy1 + dz0 * dz0);
248 double d001 = sqrt(dx0 * dx0 + dy0 * dy0 + dz1 * dz1);
249 double d110 = sqrt(dx1 * dx1 + dy1 * dy1 + dz0 * dz0);
250 double d101 = sqrt(dx1 * dx1 + dy0 * dy0 + dz1 * dz1);
251 double d011 = sqrt(dx0 * dx0 + dy1 * dy1 + dz1 * dz1);
252 double d111 = sqrt(dx1 * dx1 + dy1 * dy1 + dz1 * dz1);
257 double mindst = d000;
259 if (d100 <= mindst) {
263 }
else if (d010 <= mindst) {
267 }
else if (d001 <= mindst) {
271 }
else if (d110 <= mindst) {
275 }
else if (d101 <= mindst) {
279 }
else if (d011 <= mindst) {
283 }
else if (d111 <= mindst) {
290 std::cout <<
"x, y, z: " << x <<
", " << y <<
", " << z <<
"\n"
291 <<
"i, j, k: " << i <<
", " << j <<
", " << k <<
"\n"
292 <<
"000=> ex, ey, ez, p, m: " << ex000 <<
", " << ey000 <<
", "
293 << ez000 <<
", " << p000 <<
", " << m000 <<
"\n"
294 <<
"100=> ex, ey, ez, p, m: " << ex100 <<
", " << ey100 <<
", "
295 << ez100 <<
", " << p100 <<
", " << m100 << std::endl
296 <<
"010=> ex, ey, ez, p, m: " << ex010 <<
", " << ey010 <<
", "
297 << ez010 <<
", " << p010 <<
", " << m010 << std::endl
298 <<
"001=> ex, ey, ez, p, m: " << ex001 <<
", " << ey001 <<
", "
299 << ez001 <<
", " << p001 <<
", " << m001 << std::endl
300 <<
"110=> ex, ey, ez, p, m: " << ex110 <<
", " << ey110 <<
", "
301 << ez110 <<
", " << p110 <<
", " << m110 << std::endl
302 <<
"101=> ex, ey, ez, p, m: " << ex101 <<
", " << ey101 <<
", "
303 << ez101 <<
", " << p101 <<
", " << m101 << std::endl
304 <<
"011=> ex, ey, ez, p, m: " << ex011 <<
", " << ey011 <<
", "
305 << ez011 <<
", " << p011 <<
", " << m011 << std::endl
306 <<
"111=> ex, ey, ez, p, m: " << ex111 <<
", " << ey111 <<
", "
307 << ez111 <<
", " << p111 <<
", " << m111 << std::endl
308 <<
"delx, x, x0, x1, dx0, dx1, xd: " << delx <<
", " << x <<
", "
309 << x0 <<
", " << x1 <<
", " << dx0 <<
", " << dx1 <<
", " << xd
311 <<
"dely, y, y0, y1, dy0, dy1, yd: " << dely <<
", " << y <<
", "
312 << y0 <<
", " << y1 <<
", " << dy0 <<
", " << dy1 <<
", " << yd
314 <<
"delz, z, z0, z1, dz0, dz1, zd: " << delz <<
", " << z <<
", "
315 << z0 <<
", " << z1 <<
", " << dz0 <<
", " << dz1 <<
", " << zd
317 <<
"Values after LinInt=> ex, ey, ez, p, m: " << ex <<
", " << ey
318 <<
", " << ez <<
", " << p <<
", " << m << std::endl;
330 const double z,
double& ex,
double& ey,
331 double& ez,
Medium*& m,
int& status) {
337 const double z,
double& wx,
double& wy,
339 const std::string& ) {
343 const double x1 = x - m_wField_xOffset;
344 const double y1 = y - m_wField_yOffset;
345 const double z1 = z - m_wField_zOffset;
351 const std::string& ) {
355 const double x1 = x - m_wField_xOffset;
356 const double y1 = y - m_wField_yOffset;
357 const double z1 = z - m_wField_zOffset;
358 double wx = 0., wy = 0., wz = 0.;
366 m_wField_xOffset = x;
367 m_wField_yOffset = y;
368 m_wField_zOffset = z;
372 const double z,
double& bx,
double& by,
373 double& bz,
int& status) {
379 unsigned int i = 0, j = 0, k = 0;
380 bool xMirrored =
false, yMirrored =
false, zMirrored =
false;
381 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
387 const Element& element = m_bfields[i][j][k];
391 if (xMirrored) bx = -bx;
392 if (yMirrored) by = -by;
393 if (zMirrored) bz = -bz;
401 <<
" Field map is not available for interpolation.\n";
405 unsigned int i, j, k;
406 bool xMirrored, yMirrored, zMirrored;
407 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
410 const int region = m_regions[i][j][k];
411 if (region < 0 || region > (
int)m_media.size())
return nullptr;
412 return m_media[region];
418 int&
OptStaggerMap,
unsigned int& NbOfXCells,
unsigned int& NbOfYCells,
419 unsigned int& NbOfZCells,
double& Xmin,
double& Xmax,
double& Ymin,
420 double& Ymax,
double& Zmin,
double& Zmax,
double& XStagger,
421 double& YStagger,
double& ZStagger, std::string& MapDataFile) {
422 std::ifstream infile;
423 infile.open(MapInfoFile.c_str(), std::ios::in);
426 <<
" Could not open file " << MapInfoFile <<
".\n";
431 unsigned int nLines = 0;
434 if (!infile.fail()) {
436 std::getline(infile, line);
439 std::istringstream data;
445 <<
" Error reading line " << nLines <<
".\n"
446 <<
" Cannot retrieve MapVersion.\n";
452 if (!infile.fail()) {
454 std::getline(infile, line);
457 std::istringstream data;
463 <<
" Error reading line " << nLines <<
".\n"
464 <<
" Cannot retrieve OptMap.\n";
470 if (!infile.fail()) {
472 std::getline(infile, line);
475 std::istringstream data;
481 <<
" Error reading line " << nLines <<
".\n"
482 <<
" Cannot retrieve OptStaggerMap.\n";
488 if (!infile.fail()) {
490 std::getline(infile, line);
493 std::istringstream data;
499 <<
" Error reading line " << nLines <<
".\n"
500 <<
" Cannot retrieve NbOfXCells.\n";
506 if (!infile.fail()) {
508 std::getline(infile, line);
511 std::istringstream data;
517 <<
" Error reading line " << nLines <<
".\n"
518 <<
" Cannot retrieve NbOfYCells.\n";
524 if (!infile.fail()) {
526 std::getline(infile, line);
529 std::istringstream data;
535 <<
" Error reading line " << nLines <<
".\n"
536 <<
" Cannot retrieve NbOfZCells.\n";
542 if (!infile.fail()) {
544 std::getline(infile, line);
547 std::istringstream data;
549 data >> Xmin >> Xmax;
553 <<
" Error reading line " << nLines <<
".\n"
554 <<
" Cannot retrieve Xmin, Xmax.\n";
560 if (!infile.fail()) {
562 std::getline(infile, line);
565 std::istringstream data;
567 data >> Ymin >> Ymax;
571 <<
" Error reading line " << nLines <<
".\n"
572 <<
" Cannot retrieve Ymin, Ymax.\n";
578 if (!infile.fail()) {
580 std::getline(infile, line);
583 std::istringstream data;
585 data >> Zmin >> Zmax;
589 <<
" Error reading line " << nLines <<
".\n"
590 <<
" Cannot retrieve Zmin, Zmax.\n";
596 if (!infile.fail()) {
598 std::getline(infile, line);
601 std::istringstream data;
607 <<
" Error reading line " << nLines <<
".\n"
608 <<
" Cannot retrieve XStagger.\n";
614 if (!infile.fail()) {
616 std::getline(infile, line);
619 std::istringstream data;
625 <<
" Error reading line " << nLines <<
".\n"
626 <<
" Cannot retrieve YStagger.\n";
632 if (!infile.fail()) {
634 std::getline(infile, line);
637 std::istringstream data;
643 <<
" Error reading line " << nLines <<
".\n"
644 <<
" Cannot retrieve ZStagger.\n";
650 if (!infile.fail()) {
652 std::getline(infile, line);
655 std::istringstream data;
661 <<
" Error reading line " << nLines <<
".\n"
662 <<
" Cannot retrieve MapDataFile.\n";
671 const unsigned int nz,
const double xmin,
672 const double xmax,
const double ymin,
673 const double ymax,
const double zmin,
676 if (nx == 0 || ny == 0 || nz == 0) {
678 <<
" Number of mesh elements must be positive.\n";
682 std::cerr <<
m_className <<
"::SetMesh: Invalid x range.\n";
684 }
else if (ymin >= ymax) {
685 std::cerr <<
m_className <<
"::SetMesh: Invalid y range.\n";
687 }
else if (zmin >= zmax) {
688 std::cerr <<
m_className <<
"::SetMesh: Invalid z range.\n";
704 const std::string& filename,
const std::string& format,
705 const bool withPotential,
const bool withRegion,
const double scaleX,
706 const double scaleE,
const double scaleP) {
708 m_hasPotential = m_hasEfield =
false;
710 std::cerr <<
m_className <<
"::LoadElectricField:\n"
711 <<
" Mesh is not set. Call SetMesh first.\n";
716 m_efields.resize(m_nX);
717 m_regions.resize(m_nX);
718 for (
unsigned int i = 0; i < m_nX; ++i) {
719 m_efields[i].resize(m_nY);
720 m_regions[i].resize(m_nY);
721 for (
unsigned int j = 0; j < m_nY; ++j) {
722 m_efields[i][j].resize(m_nZ);
723 m_regions[i][j].resize(m_nZ);
724 for (
unsigned int k = 0; k < m_nZ; ++k) {
725 m_efields[i][j][k].fx = 0.;
726 m_efields[i][j][k].fy = 0.;
727 m_efields[i][j][k].fz = 0.;
728 m_efields[i][j][k].v = 0.;
729 m_regions[i][j][k] = 0;
734 m_pMin = m_pMax = 0.;
739 return LoadData(filename, format, withPotential, withRegion, scaleX, scaleE,
744 const std::string& format,
746 const double scaleB) {
749 std::cerr <<
m_className <<
"::LoadMagneticField:\n"
750 <<
" Mesh is not set. Call SetMesh first.\n";
755 m_bfields.resize(m_nX);
756 for (
unsigned int i = 0; i < m_nX; ++i) {
757 m_bfields[i].resize(m_nY);
758 for (
unsigned int j = 0; j < m_nY; ++j) {
759 m_bfields[i][j].resize(m_nZ);
760 for (
unsigned int k = 0; k < m_nZ; ++k) {
761 m_bfields[i][j][k].fx = 0.;
762 m_bfields[i][j][k].fy = 0.;
763 m_bfields[i][j][k].fz = 0.;
764 m_bfields[i][j][k].v = 0.;
769 return LoadData(filename, format,
false,
false, scaleX, scaleB, 1.,
'b');
772bool ComponentNeBem3dMap::LoadData(
const std::string& filename,
773 std::string format,
const bool withPotential,
774 const bool withRegion,
const double scaleX,
775 const double scaleF,
const double scaleP,
778 std::cerr <<
m_className <<
"::LoadData: Mesh has not been set.\n";
782 unsigned int nValues = 0;
784 std::vector<std::vector<std::vector<bool> > > isSet(
786 std::vector<std::vector<bool> >(m_nY, std::vector<bool>(m_nZ,
false)));
788 std::ifstream infile;
789 infile.open(filename.c_str(), std::ios::in);
792 <<
" Could not open file " << filename <<
".\n";
796 std::transform(format.begin(), format.end(), format.begin(), toupper);
797 unsigned int fmt = 0;
798 if (format ==
"XY") {
800 }
else if (format ==
"XYZ") {
802 }
else if (format ==
"IJ") {
804 }
else if (format ==
"IJK") {
806 }
else if (format ==
"YXZ") {
810 <<
" Unkown format (" << format <<
").\n";
814 unsigned int nLines = 0;
817 while (std::getline(infile, line)) {
822 if (line.empty())
continue;
824 if (line[0] ==
'#')
continue;
825 if (line[0] ==
'/' && line[1] ==
'/')
continue;
834 std::istringstream data;
842 <<
" Error reading line " << nLines <<
".\n"
843 <<
" Cannot retrieve element coordinates.\n";
849 const double z = 0.5 * (m_zMin + m_zMax);
850 bool xMirrored, yMirrored, zMirrored;
851 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
853 <<
" Error reading line " << nLines <<
".\n"
854 <<
" Point is outside mesh.\n";
858 }
else if (fmt == 2) {
864 <<
" Error reading line " << nLines <<
".\n"
865 <<
" Cannot retrieve element coordinates.\n";
872 bool xMirrored, yMirrored, zMirrored;
873 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
875 <<
" Error reading line " << nLines <<
".\n"
876 <<
" Point is outside mesh.\n";
880 }
else if (fmt == 3) {
886 <<
" Error reading line " << nLines <<
".\n"
887 <<
" Cannot retrieve element index.\n";
891 }
else if (fmt == 4) {
896 <<
" Error reading line " << nLines <<
".\n"
897 <<
" Cannot retrieve element index.\n";
901 }
else if (fmt == 5) {
903 double x,
y,
z, temp;
904 data >>
y >>
x >> temp;
908 <<
" Error reading line " << nLines <<
".\n"
909 <<
" Cannot retrieve element coordinates.\n";
916 bool xMirrored, yMirrored, zMirrored;
917 if (!
GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
919 <<
" Error reading line " << nLines <<
".\n"
920 <<
" Point is outside mesh.\n";
926 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
928 <<
" Error reading line " << nLines <<
".\n"
929 <<
" Index (" << i <<
", " << j <<
", " << k
930 <<
") out of range.\n";
933 if (isSet[i][j][k]) {
935 <<
" Error reading line " << nLines <<
".\n"
936 <<
" Mesh element (" << i <<
", " << j <<
", " << k
937 <<
") has already been set.\n";
941 if (fmt == 1 || fmt == 3) {
945 }
else if (fmt == 5) {
947 data >> fy >> fx >> temp;
950 data >> fx >> fy >> fz;
954 <<
" Error reading line " << nLines <<
".\n"
955 <<
" Cannot read field values.\n";
966 <<
" Error reading line " << nLines <<
".\n"
967 <<
" Cannot read potential.\n";
972 if (m_pMin > m_pMax) {
977 if (v < m_pMin) m_pMin = v;
978 if (v > m_pMax) m_pMax = v;
985 <<
" Error reading line " << nLines <<
".\n"
986 <<
" Cannot read region.\n";
991 if (fmt == 1 || fmt == 3) {
993 for (
unsigned int kk = 0; kk < m_nZ; ++kk) {
995 m_efields[i][j][kk].fx = fx;
996 m_efields[i][j][kk].fy = fy;
997 m_efields[i][j][kk].fz = fz;
998 m_efields[i][j][kk].v = v;
999 m_regions[i][j][kk] = region;
1000 }
else if (field ==
'b') {
1001 m_bfields[i][j][kk].fx = fx;
1002 m_bfields[i][j][kk].fy = fy;
1003 m_bfields[i][j][kk].fz = fz;
1005 isSet[i][j][kk] =
true;
1009 m_efields[i][j][k].fx = fx;
1010 m_efields[i][j][k].fy = fy;
1011 m_efields[i][j][k].fz = fz;
1012 m_efields[i][j][k].v = v;
1013 m_regions[i][j][k] = region;
1014 }
else if (field ==
'b') {
1015 m_bfields[i][j][k].fx = fx;
1016 m_bfields[i][j][k].fy = fy;
1017 m_bfields[i][j][k].fz = fz;
1019 isSet[i][j][k] =
true;
1023 if (bad)
return false;
1025 <<
" Read " << nValues <<
" values from " << filename <<
".\n";
1026 unsigned int nExpected = m_nX * m_nY;
1027 if (fmt == 2 || fmt == 4 || fmt == 5) nExpected *= m_nZ;
1028 if (nExpected != nValues) {
1030 <<
" Expected " << nExpected <<
" values.\n";
1035 if (withPotential) m_hasPotential =
true;
1036 }
else if (field ==
'b') {
1043 double& zmin,
double& xmax,
1044 double& ymax,
double& zmax) {
1080 double& eymin,
double& eymax,
1081 double& ezmin,
double& ezmax) {
1083 std::cerr <<
m_className <<
"::GetElectricFieldRange:\n";
1084 std::cerr <<
" Field map not available.\n";
1088 exmin = exmax = m_efields[0][0][0].fx;
1089 eymin = eymax = m_efields[0][0][0].fy;
1090 ezmin = ezmax = m_efields[0][0][0].fz;
1091 for (
unsigned int i = 0; i < m_nX; ++i) {
1092 for (
unsigned int j = 0; j < m_nY; ++j) {
1093 for (
unsigned int k = 0; k < m_nZ; ++k) {
1094 const Element& element = m_efields[i][j][k];
1095 if (element.fx < exmin) exmin = element.fx;
1096 if (element.fx > exmax) exmax = element.fx;
1097 if (element.fy < eymin) eymin = element.fy;
1098 if (element.fy > eymax) eymax = element.fy;
1099 if (element.fz < ezmin) ezmin = element.fz;
1100 if (element.fz > ezmax) ezmax = element.fz;
1111 <<
" Field map not yet initialised.\n";
1115 if (m_media.empty()) {
1116 std::cerr <<
m_className <<
"::PrintRegions: No regions defined.\n";
1121 std::cout <<
" Index Medium\n";
1122 const unsigned int nMedia = m_media.size();
1123 for (
unsigned int i = 0; i < nMedia; ++i) {
1124 const std::string name = m_media[i] ? m_media[i]->GetName() :
"none";
1125 std::cout <<
" " << i <<
" " << name <<
"\n";
1131 std::cerr <<
m_className <<
"::SetMedium: Null pointer.\n";
1132 if (m_media.empty())
return;
1134 if (i >= m_media.size()) m_media.resize(i + 1,
nullptr);
1139 if (i >= m_media.size()) {
1140 std::cerr <<
m_className <<
"::GetMedium: Index out of range.\n";
1147 const double zi,
unsigned int& i,
1148 unsigned int& j,
unsigned int& k,
1149 bool& xMirrored,
bool& yMirrored,
1150 bool& zMirrored)
const {
1152 std::cerr <<
m_className <<
"::GetElement: Mesh is not set.\n";
1160 if (x < m_xMin || x > m_xMax)
return false;
1163 if (y < m_yMin || y > m_yMax)
return false;
1166 if (z < m_zMin || z > m_zMax)
return false;
1172 const double dy = (m_yMax - m_yMin) / (m_nY - 1);
1173 const double dz = (m_zMax - m_zMin) / (m_nZ - 1);
1174 i = (
unsigned int)((x - m_xMin) / dx);
1175 j = (
unsigned int)((y - m_yMin) / dy);
1176 k = (
unsigned int)((z - m_zMin) / dz);
1177 if (i >= m_nX) i = m_nX - 1;
1178 if (j >= m_nY) j = m_nY - 1;
1179 if (k >= m_nZ) k = m_nZ - 1;
1182 <<
"x, y, z: " << x <<
", " << y <<
", " << z << std::endl
1183 <<
"m_xMax, m_yMax, m_zMax: " << m_xMax <<
", " << m_yMax <<
", "
1184 << m_zMax << std::endl
1185 <<
"m_xMin, m_yMin, m_zMin: " << m_xMin <<
", " << m_yMin <<
", "
1186 << m_zMin << std::endl
1187 <<
"m_nX, m_nY, m_nZ: " << m_nX <<
", " << m_nY <<
", " << m_nZ
1189 <<
"dx, dy, dz: " << dx <<
", " << dy <<
", " << dz << std::endl
1190 <<
"x-m_xMin, y-m_yMin, z-m_zMin: " << x - m_xMin <<
", "
1191 << y - m_yMin <<
", " << z - m_zMin << std::endl
1192 <<
"i, j, k: " << i <<
", " << j <<
", " << k << std::endl
1193 <<
"End GetElement" << std::endl;
1199 const unsigned int k,
double& v,
1200 double& ex,
double& ey,
double& ez)
const {
1201 v = ex = ey = ez = 0.;
1204 std::cerr <<
m_className <<
"::GetElement: Mesh not set.\n";
1207 std::cerr <<
m_className <<
"::GetElement: Field map not set.\n";
1210 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
1211 std::cerr <<
m_className <<
"::GetElement: Index out of range.\n";
1214 const Element& element = m_efields[i][j][k];
1222void ComponentNeBem3dMap::Reset() {
1226 m_nX = m_nY = m_nZ = 0;
1227 m_xMin = m_yMin = m_zMin = 0.;
1228 m_xMax = m_yMax = m_zMax = 0.;
1229 m_pMin = m_pMax = 0.;
1233 m_hasPotential =
false;
1234 m_hasEfield =
false;
1235 m_hasBfield =
false;
1239void ComponentNeBem3dMap::UpdatePeriodicity() {
1241 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1242 <<
" Field map not available.\n";
1247 for (
unsigned int i = 0; i < 3; ++i) {
1249 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1250 <<
" Both simple and mirror periodicity requested. Reset.\n";
1256 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1257 <<
" Axial symmetry is not supported. Reset.\n";
1263 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
1264 <<
" Rotation symmetry is not supported. Reset.\n";
1269double ComponentNeBem3dMap::Reduce(
const double xin,
const double xmin,
1270 const double xmax,
const bool simplePeriodic,
1271 const bool mirrorPeriodic,
1272 bool& mirrored)
const {
1275 const double lx = xmax - xmin;
1276 if (simplePeriodic) {
1277 x = xmin + fmod(x - xmin, lx);
1278 if (x < xmin)
x += lx;
1279 }
else if (mirrorPeriodic) {
1280 double xNew = xmin + fmod(x - xmin, lx);
1281 if (xNew < xmin) xNew += lx;
1282 const int nx = int(floor(0.5 + (xNew - x) / lx));
1283 if (nx != 2 * (nx / 2)) {
1284 xNew = xmin + xmax - xNew;
1292double ComponentNeBem3dMap::TriLinInt(
const double xd,
const double yd,
1293 const double zd,
const double c000,
1294 const double c100,
const double c010,
1295 const double c001,
const double c110,
1296 const double c101,
const double c011,
1297 const double c111) {
1298 double c00 = c000 * (1.0 - xd) + c100 * xd;
1299 double c10 = c010 * (1.0 - xd) + c110 * xd;
1300 double c01 = c001 * (1.0 - xd) + c101 * xd;
1301 double c11 = c011 * (1.0 - xd) + c111 * xd;
1302 double c0 = c00 * (1.0 - yd) + c10 * yd;
1303 double c1 = c01 * (1.0 - yd) + c11 * yd;
1304 return (c0 * (1.0 - zd) + c1 * zd);
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 components.
std::array< bool, 3 > m_rotationSymmetric
Rotation symmetry around x-axis, y-axis, z-axis.
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.
bool m_debug
Switch on/off debugging messages.
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
std::string m_className
Class name.
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_axiallyPeriodic
Axial periodicity in x, y, z.
Abstract base class for media.
void ltrim(std::string &line)
neBEMGLOBAL int OptStaggerMap
neBEMGLOBAL char MapVersion[10]