28 disableFieldComponent[0] =
false;
29 disableFieldComponent[1] =
false;
30 disableFieldComponent[2] =
false;
35 std::string mplist, std::string prnsol,
48 std::ifstream fmplist;
49 fmplist.open(mplist.c_str(), std::ios::in);
51 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
52 std::cerr <<
" Could not open material file " << mplist
53 <<
" for reading." << std::endl,
54 std::cerr <<
" The file perhaps does not exist." << std::endl;
61 bool readerror =
false;
62 while (fmplist.getline(line, size,
'\n')) {
66 token = strtok(line,
" ");
68 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
69 int(token[0]) == 10 ||
int(token[0]) == 13)
73 if (strcmp(token,
"Materials") == 0) {
74 token = strtok(NULL,
" ");
77 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
78 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
91 std::cout <<
m_className <<
"::Initialise:" << std::endl;
92 std::cout <<
" Number of materials: " <<
m_nMaterials <<
""
95 }
else if (strcmp(token,
"Material") == 0) {
96 token = strtok(NULL,
" ");
99 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
100 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
106 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
107 std::cerr <<
" Found out-of-range material index " << imat <<
"in"
109 std::cerr <<
" material properties file " << mplist <<
"."
113 token = strtok(NULL,
" ");
115 if (strcmp(token,
"PERX") == 0) {
117 }
else if (strcmp(token,
"RSVX") == 0) {
120 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
121 std::cerr <<
" Found unknown material property flag " << token
123 std::cerr <<
" on material properties file " << mplist <<
"(line "
124 << il <<
")." << std::endl;
127 token = strtok(NULL,
" ");
130 }
else if (itype == 2) {
132 token = strtok(NULL,
" ");
133 if (strcmp(token,
"PERX") != 0) {
134 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
135 std::cerr <<
" Found unknown material property falg " << token
137 std::cerr <<
" on material file " << mplist <<
" (material "
141 token = strtok(NULL,
" ");
146 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
147 std::cerr <<
" Error reading file " << mplist <<
"(line " << il
148 <<
")." << std::endl;
154 std::cout <<
m_className <<
"::Initialise:" << std::endl;
155 std::cout <<
" Read material properties for material "
156 << (imat - 1) <<
"" << std::endl;
158 std::cout <<
" eps = " <<
materials[imat - 1].eps
159 <<
" ohm = " <<
materials[imat - 1].ohm <<
""
162 std::cout <<
" eps = " <<
materials[imat - 1].eps <<
""
173 unsigned int iepsmin = 0;
174 for (
unsigned int imat = 0; imat <
m_nMaterials; ++imat) {
177 std::cout <<
m_className <<
"::Initialise:" << std::endl;
178 std::cout <<
" Material " << imat
179 <<
" has been assigned a permittivity" << std::endl;
180 std::cout <<
" equal to zero in " << mplist <<
"." << std::endl;
182 }
else if (epsmin < 0. || epsmin >
materials[imat].eps) {
188 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
189 std::cerr <<
" No material with positive permittivity found in"
191 std::cerr <<
" material list " << mplist.c_str() <<
"." << std::endl;
194 for (
unsigned int imat = 0; imat <
m_nMaterials; ++imat) {
195 if (imat == iepsmin) {
203 std::cout <<
m_className <<
"::Initialise:" << std::endl;
204 std::cout <<
" Read properties of " <<
m_nMaterials <<
" materials"
206 std::cout <<
" from file " << mplist <<
"." << std::endl;
211 if (strcmp(unit.c_str(),
"mum") == 0 || strcmp(unit.c_str(),
"micron") == 0 ||
212 strcmp(unit.c_str(),
"micrometer") == 0) {
214 }
else if (strcmp(unit.c_str(),
"mm") == 0 ||
215 strcmp(unit.c_str(),
"millimeter") == 0) {
217 }
else if (strcmp(unit.c_str(),
"cm") == 0 ||
218 strcmp(unit.c_str(),
"centimeter") == 0) {
220 }
else if (strcmp(unit.c_str(),
"m") == 0 ||
221 strcmp(unit.c_str(),
"meter") == 0) {
224 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
225 std::cerr <<
" Unknown length unit " << unit <<
"." << std::endl;
230 std::cout <<
m_className <<
"::Initialise:" << std::endl;
231 std::cout <<
" Unit scaling factor = " << funit <<
"." << std::endl;
235 std::ifstream fnlist;
236 fnlist.open(nlist.c_str(), std::ios::in);
238 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
239 std::cerr <<
" Could not open nodes file " << nlist <<
" for reading."
241 std::cerr <<
" The file perhaps does not exist." << std::endl;
247 int xlines = 0, ylines = 0, zlines = 0;
250 while (fnlist.getline(line, size,
'\n')) {
255 token = strtok(line,
" ");
257 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
258 int(token[0]) == 10 ||
int(token[0]) == 13)
261 if (strcmp(token,
"xmax") == 0) {
262 token = strtok(NULL,
" ");
264 token = strtok(NULL,
" ");
265 token = strtok(NULL,
" ");
267 token = strtok(NULL,
" ");
268 token = strtok(NULL,
" ");
270 if (readerror)
break;
273 if (strcmp(token,
"x-lines\n") == 0 || strcmp(token,
"x-lines") == 0) {
276 std::cout <<
m_className <<
"::Initialise:" << std::endl;
277 std::cout <<
" Reading x-lines from file " << nlist <<
"."
282 if (strcmp(token,
"y-lines\n") == 0 || strcmp(token,
"y-lines") == 0) {
285 std::cout <<
m_className <<
"::Initialise:" << std::endl;
286 std::cout <<
" Reading y-lines from file " << nlist <<
"."
291 if (strcmp(token,
"z-lines\n") == 0 || strcmp(token,
"z-lines") == 0) {
294 std::cout <<
m_className <<
"::Initialise:" << std::endl;
295 std::cout <<
" Reading z-lines from file " << nlist <<
"."
302 m_xlines.push_back(line_tmp * funit);
303 else if (lines_type == 2)
304 m_ylines.push_back(line_tmp * funit);
305 else if (lines_type == 3)
306 m_zlines.push_back(line_tmp * funit);
308 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
309 std::cerr <<
" Line type was not set in " << nlist <<
" (line " << il
310 <<
", token = " << token <<
")." << std::endl;
311 std::cerr <<
" Maybe it is in the wrong format" << std::endl;
312 std::cerr <<
" e.g. missing tailing space after x-lines." << std::endl;
316 if (readerror)
break;
320 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
321 std::cerr <<
" Error reading file " << nlist <<
" (line " << il <<
")."
330 if ((
unsigned)xlines == m_xlines.size() &&
331 (
unsigned)ylines == m_ylines.size() &&
332 (
unsigned)zlines == m_zlines.size()) {
333 std::cout <<
m_className <<
"::Initialise:" << std::endl;
334 std::cout <<
" Found in file " << nlist <<
"\n " << xlines
335 <<
" x-lines\n " << ylines <<
" y-lines\n " << zlines
336 <<
" z-lines" << std::endl;
338 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
339 std::cerr <<
" There should be " << xlines <<
" x-lines, " << ylines
340 <<
" y-lines and " << zlines <<
" z-lines in file " << nlist
341 <<
" but I found :\n " << m_xlines.size() <<
" x-lines, "
342 << m_ylines.size() <<
" x-lines, " << m_zlines.size()
343 <<
" z-lines." << std::endl;
345 m_nx = m_xlines.size();
346 m_ny = m_ylines.size();
347 m_nz = m_zlines.size();
348 nNodes = m_nx * m_ny * m_nz;
349 nElements = (m_nx - 1) * (m_ny - 1) * (m_nz - 1);
352 std::cout <<
m_className <<
"::Initialise:" << std::endl;
353 std::cout <<
" Read " <<
nNodes <<
" nodes from file " << nlist <<
"."
358 std::ifstream felist;
359 felist.open(elist.c_str(), std::ios::in);
361 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
362 std::cerr <<
" Could not open element file " << elist <<
" for reading."
364 std::cerr <<
" The file perhaps does not exist." << std::endl;
370 while (felist.getline(line, size,
'\n')) {
375 token = strtok(line,
" ");
377 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
378 int(token[0]) == 10 ||
int(token[0]) == 13 ||
379 strcmp(token,
"LIST") == 0 || strcmp(token,
"ELEM") == 0)
383 token = strtok(NULL,
" ");
384 unsigned char imat = atoi(token);
386 std::vector<int> node_nb;
390 m_elementMaterial.at(ielem) = (imat - 1);
393 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
394 std::cerr <<
" Error reading file " << elist <<
" (line " << il <<
")."
396 std::cerr <<
" The element index (" << ielem
397 <<
") is not in the expected range: 0 - " <<
nElements
404 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
405 std::cerr <<
" Out-of-range material number on file " << elist
406 <<
" (line " << il <<
")." << std::endl;
407 std::cerr <<
" Element: " << ielem <<
", material: " << imat
412 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
413 std::cerr <<
" Element " << ielem <<
" in element list " << elist
414 <<
" uses material " << imat <<
" which" << std::endl;
415 std::cerr <<
" has not been assigned a positive permittivity"
417 std::cerr <<
" in material list " << mplist <<
"." << std::endl;
424 std::cout <<
m_className <<
"::Initialise:" << std::endl;
425 std::cout <<
" Read " <<
nElements <<
" elements from file " << elist
429 m_potential.resize(
nNodes);
430 std::ifstream fprnsol;
431 fprnsol.open(prnsol.c_str(), std::ios::in);
432 if (fprnsol.fail()) {
433 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
434 std::cerr <<
" Could not open potential file " << prnsol
435 <<
" for reading." << std::endl;
436 std::cerr <<
" The file perhaps does not exist." << std::endl;
443 while (fprnsol.getline(line, size,
'\n')) {
447 token = strtok(line,
" ");
449 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
450 int(token[0]) == 10 ||
int(token[0]) == 13 || strcmp(token,
"Max") == 0)
455 token = strtok(NULL,
" ");
456 double volt =
ReadDouble(token, -1, readerror);
459 m_potential.at(inode - 1) = volt;
463 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
464 std::cerr <<
" Error reading file " << prnsol <<
" (line " << il
465 <<
")." << std::endl;
466 std::cerr <<
" The node index (" << inode - 1
467 <<
") is not in the expected range: 0 - " <<
nNodes
475 std::cout <<
m_className <<
"::Initialise:" << std::endl;
476 std::cout <<
" Read " << nread <<
"/" <<
nNodes
477 <<
" (expected) potentials from file " << prnsol <<
"."
481 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
482 std::cerr <<
" Number of nodes read (" << nread <<
") on potential file "
483 << prnsol <<
" does not" << std::endl;
484 std::cerr <<
" match the node list (" <<
nNodes <<
")." << std::endl;
491 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
492 std::cerr <<
" Field map could not be read and cannot be interpolated."
510 if (strcmp(unit.c_str(),
"mum") == 0 || strcmp(unit.c_str(),
"micron") == 0 ||
511 strcmp(unit.c_str(),
"micrometer") == 0) {
513 }
else if (strcmp(unit.c_str(),
"mm") == 0 ||
514 strcmp(unit.c_str(),
"millimeter") == 0) {
516 }
else if (strcmp(unit.c_str(),
"cm") == 0 ||
517 strcmp(unit.c_str(),
"centimeter") == 0) {
519 }
else if (strcmp(unit.c_str(),
"m") == 0 ||
520 strcmp(unit.c_str(),
"meter") == 0) {
523 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
524 std::cerr <<
" Unknown length unit " << unit <<
"." << std::endl;
529 std::cout <<
m_className <<
"::Initialise:" << std::endl;
530 std::cout <<
" Unit scaling factor = " << funit <<
"." << std::endl;
532 FILE* f = fopen(dataFile.c_str(),
"rb");
534 std::cerr <<
m_className <<
"::Initilise:" << std::endl;
535 std::cerr <<
" Could not open file:" << dataFile.c_str() << std::endl;
539 struct stat fileStatus;
540 stat(dataFile.c_str(), &fileStatus);
541 int fileSize = fileStatus.st_size;
543 if (fileSize < 1000) {
545 std::cerr <<
m_className <<
"::Initilise:" << std::endl;
546 std::cerr <<
" Error. The file is extremely short and does not seem to "
547 "contain a header or data." << std::endl;
551 char header[headerSize];
553 result = fread(header,
sizeof(
char), headerSize, f);
554 if (result != headerSize) {
555 fputs(
"Reading error while reading header.", stderr);
559 int nx = 0, ny = 0, nz = 0;
560 int m_x = 0, m_y = 0, m_z = 0;
561 int n_s = 0, n_x = 0, n_y = 0, n_z = 0;
562 int e_s = 0, e_x = 0, e_y = 0, e_z = 0;
566 filled = std::sscanf(
567 header, (std::string(
"mesh_nx=%d mesh_ny=%d mesh_nz=%d\n") +
568 std::string(
"mesh_xlines=%d mesh_ylines=%d mesh_zlines=%d\n") +
570 "nodes_scalar=%d nodes_vector_x=%d nodes_vector_y=%d "
571 "nodes_vector_z=%d\n") +
573 "elements_scalar=%d elements_vector_x=%d "
574 "elements_vector_y=%d elements_vector_z=%d\n") +
575 std::string(
"elements_material=%d\n") +
576 std::string(
"n_materials=%d\n")).c_str(),
577 &nx, &ny, &nz, &m_x, &m_y, &m_z, &n_s, &n_x, &n_y, &n_z, &e_s, &e_x, &e_y,
581 std::cerr <<
m_className <<
"::Initilise:" << std::endl;
582 std::cerr <<
" Error. File header of " << dataFile.c_str()
583 <<
" is broken." << std::endl;
586 if (fileSize < 1000 + (m_x + m_y + m_z) * 8 +
587 (n_s + n_x + n_y + n_z + e_s + e_x + e_y + e_z) * 4 +
593 std::cout <<
m_className <<
"::Initialise:" << std::endl;
594 std::cout <<
" Information about the data stored in the given binary file:"
596 std::cout <<
" Mesh (nx): " << nx <<
"\t Mesh (ny): " << ny
597 <<
"\t Mesh (nz): " << nz << std::endl;
598 std::cout <<
" Mesh (x_lines): " << m_x <<
"\t Mesh (y_lines): " << m_y
599 <<
"\t Mesh (z_lines): " << m_z << std::endl;
600 std::cout <<
" Nodes (scalar): " << n_s <<
"\t Nodes (x): " << n_x
601 <<
"\t Nodes (y): " << n_y <<
"\t Nodes (z): " << n_z
603 std::cout <<
" Field (scalar): " << e_s <<
"\t Field (x): " << e_x
604 <<
"\t Field (y): " << e_y <<
"\t Field (z): " << e_z
606 std::cout <<
" Elements: " << e_m <<
"\t Materials: " <<
m_nMaterials
612 nNodes = m_nx * m_ny * m_nz;
613 nElements = (m_nx - 1) * (m_ny - 1) * (m_nz - 1);
615 m_xlines.resize(m_x);
616 m_ylines.resize(m_y);
617 m_zlines.resize(m_z);
618 m_potential.resize(n_s);
619 m_elementMaterial.resize(e_m);
622 result = fread(m_xlines.data(),
sizeof(
double), m_xlines.size(), f);
623 if (result != m_xlines.size()) {
624 fputs(
"Reading error while reading xlines.", stderr);
626 }
else if (result == 0) {
627 fputs(
"No xlines are stored in the data file.", stderr);
630 result = fread(m_ylines.data(),
sizeof(
double), m_ylines.size(), f);
631 if (result != m_ylines.size()) {
632 fputs(
"Reading error while reading ylines", stderr);
634 }
else if (result == 0) {
635 fputs(
"No ylines are stored in the data file.", stderr);
638 result = fread(m_zlines.data(),
sizeof(
double), m_zlines.size(), f);
639 if (result != m_zlines.size()) {
640 fputs(
"Reading error while reasing zlines", stderr);
642 }
else if (result == 0) {
643 fputs(
"No zlines are stored in the data file.", stderr);
646 result = fread(m_potential.data(),
sizeof(
float), m_potential.size(), f);
647 if (result != m_potential.size()) {
648 fputs(
"Reading error while reading nodes.", stderr);
650 }
else if (result == 0) {
651 fputs(
"No potentials are stored in the data file.", stderr);
654 fseek(f, e_s *
sizeof(
float), SEEK_CUR);
656 result = fread(m_elementMaterial.data(),
sizeof(
unsigned char),
657 m_elementMaterial.size(), f);
658 if (result != m_elementMaterial.size()) {
659 fputs(
"Reading error while reading element material", stderr);
662 std::stringstream st;
668 for (
unsigned int i = 0; i <
materials.size(); i++) {
670 result = fread(&(
id),
sizeof(
float), 1, f);
672 fputs(
"Input error while reading material id.", stderr);
675 unsigned int description_size = 0;
676 result = fread(&(description_size),
sizeof(
int), 1, f);
678 fputs(
"Input error while reading material description size.", stderr);
681 char* c =
new char[description_size];
682 result = fread(c,
sizeof(
char), description_size, f);
683 if (result != description_size) {
684 fputs(
"Input error while reading material description.", stderr);
687 std::string name = c;
688 st <<
" Read material: " << name.c_str();
689 if (name.compare(
"gas") == 0) {
690 st <<
" (considered as drift medium)";
697 result = fread(&(tmp_eps),
sizeof(
float), 1, f);
700 fputs(
"Reading error while reading eps.", stderr);
710 st <<
"; eps is: " <<
materials.at(
id).eps <<
713 "\t id is: " <<
id << std::endl;
715 fseek(f, 2 *
sizeof(
float), SEEK_CUR);
719 std::cout << st.str();
720 for (std::vector<Material>::iterator it =
materials.begin(),
722 it != it_end; it++) {
723 std::cout <<
"Material id: " << std::distance(
materials.begin(), it)
724 <<
" \t driftable: " << (*it).driftmedium << std::endl;
728 std::sort(m_xlines.begin(), m_xlines.end());
729 std::sort(m_ylines.begin(), m_ylines.end());
730 std::sort(m_zlines.begin(), m_zlines.end());
732 std::transform(m_xlines.begin(), m_xlines.end(), m_xlines.begin(),
733 std::bind1st(std::multiplies<double>(), funit));
734 std::transform(m_ylines.begin(), m_ylines.end(), m_ylines.begin(),
735 std::bind1st(std::multiplies<double>(), funit));
736 std::transform(m_zlines.begin(), m_zlines.end(), m_zlines.begin(),
737 std::bind1st(std::multiplies<double>(), funit));
740 std::cout <<
m_className <<
"::Initialise" << std::endl;
741 std::cout <<
" x range: " << *(m_xlines.begin()) <<
" - "
742 << *(m_xlines.end() - 1) << std::endl;
743 std::cout <<
" y range: " << *(m_ylines.begin()) <<
" - "
744 << *(m_ylines.end() - 1) << std::endl;
745 std::cout <<
" z range: " << *(m_zlines.begin()) <<
" - "
746 << *(m_zlines.end() - 1) << std::endl;
752 std::cerr <<
m_className <<
"::Initialise:" << std::endl;
753 std::cerr <<
" Field map could not be read and cannot be interpolated."
765 std::vector<float> potentials(
nNodes);
767 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
768 std::cerr <<
" No valid field map is present." << std::endl;
769 std::cerr <<
" Weighting field cannot be added." << std::endl;
774 std::ifstream fprnsol;
775 fprnsol.open(prnsol.c_str(), std::ios::in);
776 if (fprnsol.fail()) {
777 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
778 std::cerr <<
" Could not open potential file " << prnsol
779 <<
" for reading." << std::endl;
780 std::cerr <<
" The file perhaps does not exist." << std::endl;
784 std::map<std::string, std::vector<float> >::iterator it =
785 m_weightingFields.find(label);
786 if (it != m_weightingFields.end()) {
787 std::cout <<
m_className <<
"::SetWeightingField:" << std::endl;
788 std::cout <<
" Replacing existing weighting field " << label <<
"."
795 if (std::distance(m_weightingFields.begin(), it) !=
798 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
799 std::cerr <<
" Indexes of the weighting fields and the weighting field "
800 "counter are not equal!" << std::endl;
803 unsigned int iField = std::distance(m_weightingFields.begin(), it);
808 std::cout <<
m_className <<
"::SetWeightingField:" << std::endl;
809 std::cout <<
" Reading weighting field from binary file:"
810 << prnsol.c_str() << std::endl;
811 FILE* f = fopen(prnsol.c_str(),
"rb");
813 std::cerr <<
m_className <<
"::Initilise:" << std::endl;
814 std::cerr <<
" Could not open file:" << prnsol.c_str() << std::endl;
818 struct stat fileStatus;
819 stat(prnsol.c_str(), &fileStatus);
820 int fileSize = fileStatus.st_size;
822 if (fileSize < 1000) {
824 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
825 std::cerr <<
" Error. The file is extremely short and does not seem "
826 "to contain a header or data." << std::endl;
830 char header[headerSize];
832 result = fread(header,
sizeof(
char), headerSize, f);
833 if (result != headerSize) {
834 fputs(
"Reading error while reading header.", stderr);
838 int nx = 0, ny = 0, nz = 0;
839 int m_x = 0, m_y = 0, m_z = 0;
840 int n_x = 0, n_y = 0, n_z = 0;
841 int e_s = 0, e_x = 0, e_y = 0, e_z = 0;
845 filled = std::sscanf(
846 header, (std::string(
"mesh_nx=%d mesh_ny=%d mesh_nz=%d\n") +
847 std::string(
"mesh_xlines=%d mesh_ylines=%d mesh_zlines=%d\n") +
849 "nodes_scalar=%d nodes_vector_x=%d nodes_vector_y=%d "
850 "nodes_vector_z=%d\n") +
852 "elements_scalar=%d elements_vector_x=%d "
853 "elements_vector_y=%d elements_vector_z=%d\n") +
854 std::string(
"elements_material=%d\n") +
855 std::string(
"n_materials=%d\n")).c_str(),
856 &nx, &ny, &nz, &m_x, &m_y, &m_z, &nread, &n_x, &n_y, &n_z, &e_s, &e_x,
860 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
861 std::cerr <<
" Error. File header of " << prnsol.c_str()
862 <<
" is broken." << std::endl;
865 if (fileSize < 1000 + (m_x + m_y + m_z) * 8 +
866 (nread + n_x + n_y + n_z + e_s + e_x + e_y + e_z) * 4 +
872 std::cout <<
m_className <<
"::SetWeightingField:" << std::endl;
874 <<
" Information about the data stored in the given binary file:"
876 std::cout <<
" Mesh (nx): " << nx <<
"\t Mesh (ny): " << ny
877 <<
"\t Mesh (nz): " << nz << std::endl;
878 std::cout <<
" Mesh (x_lines): " << m_x <<
"\t Mesh (y_lines): " << m_y
879 <<
"\t Mesh (z_lines): " << m_z << std::endl;
880 std::cout <<
" Nodes (scalar): " << nread <<
"\t Nodes (x): " << n_x
881 <<
"\t Nodes (y): " << n_y <<
"\t Nodes (z): " << n_z
883 std::cout <<
" Field (scalar): " << e_s <<
"\t Field (x): " << e_x
884 <<
"\t Field (y): " << e_y <<
"\t Field (z): " << e_z
886 std::cout <<
" Elements: " << e_m <<
"\t Materials: " <<
m_nMaterials
890 fseek(f, m_x *
sizeof(
double), SEEK_CUR);
891 fseek(f, m_y *
sizeof(
double), SEEK_CUR);
892 fseek(f, m_z *
sizeof(
double), SEEK_CUR);
893 result = fread(potentials.data(),
sizeof(
float), potentials.size(), f);
894 if (result != potentials.size()) {
895 fputs(
"Reading error while reading nodes.", stderr);
897 }
else if (result == 0) {
898 fputs(
"No wighting potentials are stored in the data file.", stderr);
903 std::cout <<
m_className <<
"::SetWeightingField:" << std::endl;
904 std::cout <<
" Reading weighting field from text file:" << prnsol.c_str()
907 const int size = 100;
913 bool readerror =
false;
914 while (fprnsol.getline(line, size,
'\n')) {
918 token = strtok(line,
" ");
920 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
921 int(token[0]) == 10 ||
int(token[0]) == 13 ||
922 strcmp(token,
"PRINT") == 0 || strcmp(token,
"*****") == 0 ||
923 strcmp(token,
"LOAD") == 0 || strcmp(token,
"TIME=") == 0 ||
924 strcmp(token,
"MAXIMUM") == 0 || strcmp(token,
"VALUE") == 0 ||
925 strcmp(token,
"NODE") == 0)
929 token = strtok(NULL,
" ");
930 double volt =
ReadDouble(token, -1, readerror);
932 potentials.at(inode - 1) = volt;
936 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
937 std::cerr <<
" Node number " << inode <<
" out of range."
939 std::cerr <<
" on potential file " << prnsol <<
" (line " << il
940 <<
")." << std::endl;
941 std::cerr <<
" Size of the potential vector is: "
942 << potentials.size() << std::endl;
950 std::cout <<
m_className <<
"::SetWeightingField:" << std::endl;
951 std::cout <<
" Read " << nread <<
"/" <<
nNodes
952 <<
" (expected) potentials from file " << prnsol <<
"."
956 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
957 std::cerr <<
" Number of nodes read (" << nread <<
")"
958 <<
" on potential file (" << prnsol <<
")" << std::endl;
959 std::cerr <<
" does not match the node list (" <<
nNodes <<
")."
964 std::cerr <<
m_className <<
"::SetWeightingField:" << std::endl;
965 std::cerr <<
" Field map could not be read "
966 <<
"and cannot be interpolated." << std::endl;
970 m_weightingFields[label] = potentials;
978 const double zShift) {
979 std::transform(m_xlines.begin(), m_xlines.end(), m_xlines.begin(),
980 std::bind1st(std::plus<double>(), xShift));
981 std::transform(m_ylines.begin(), m_ylines.end(), m_ylines.begin(),
982 std::bind1st(std::plus<double>(), yShift));
983 std::transform(m_zlines.begin(), m_zlines.end(), m_zlines.begin(),
984 std::bind1st(std::plus<double>(), zShift));
988 std::cout <<
m_className <<
"::ShiftComponent:" << std::endl;
989 std::cout <<
" Shifted component in x-direction: " << xShift
990 <<
"\t y-direction: " << yShift <<
"\t z-direction: " << zShift
995 const double zin,
double& ex,
double& ey,
996 double& ez,
Medium*& m,
int& status) {
998 ElectricFieldBinary(xin, yin, zin, ex, ey, ez, volt, m, status);
1002 const double zin,
double& ex,
double& ey,
1003 double& ez,
double& volt,
Medium*& m,
1005 ElectricFieldBinary(xin, yin, zin, ex, ey, ez, volt, m, status,
true);
1009 const double zin,
double& wx,
double& wy,
1010 double& wz,
const std::string& label) {
1019 std::map<std::string, std::vector<float> >::iterator it =
1020 m_weightingFields.find(label);
1021 if (it == m_weightingFields.end()) {
1023 std::cerr <<
"No weighting field named " << label.c_str() <<
" found!"
1029 if (!
wfieldsOk[std::distance(m_weightingFields.begin(), it)])
return;
1032 double x = xin, y = yin, z = zin;
1036 double rcoordinate, rotation;
1037 unsigned int i, j, k;
1038 double position_mapped[3] = {0., 0., 0.};
1040 rcoordinate, rotation))
1043 double rx = (position_mapped[0] - m_xlines.at(i)) /
1044 (m_xlines.at(i + 1) - m_xlines.at(i));
1045 double ry = (position_mapped[1] - m_ylines.at(j)) /
1046 (m_ylines.at(j + 1) - m_ylines.at(j));
1047 double rz = (position_mapped[2] - m_zlines.at(k)) /
1048 (m_zlines.at(k + 1) - m_zlines.at(k));
1050 float fwx, fwy, fwz;
1051 if (!disableFieldComponent[0])
1052 fwx = GetFieldComponent(i, j, k, rx, ry, rz,
'x', &((*it).second));
1053 if (!disableFieldComponent[1])
1054 fwy = GetFieldComponent(i, j, k, rx, ry, rz,
'y', &((*it).second));
1055 if (!disableFieldComponent[2])
1056 fwz = GetFieldComponent(i, j, k, rx, ry, rz,
'z', &((*it).second));
1058 if (m_elementMaterial.size() > 0 && doShaping) {
1059 ShapeField(fwx, fwy, fwz, rx, ry, rz, i, j, k, &((*it).second));
1061 if (mirrored[0]) fwx *= -1.;
1062 if (mirrored[1]) fwy *= -1.;
1063 if (mirrored[2]) fwz *= -1.;
1066 if (!disableFieldComponent[0]) wx = fwx;
1067 if (!disableFieldComponent[1]) wy = fwy;
1068 if (!disableFieldComponent[2]) wz = fwz;
1074 const std::string& label) {
1080 std::map<std::string, std::vector<float> >::iterator it =
1081 m_weightingFields.find(label);
1082 if (it == m_weightingFields.end()) {
1084 std::cerr <<
"No weighting field named " << label.c_str() <<
" found!"
1090 if (!
wfieldsOk[std::distance(m_weightingFields.begin(), it)])
return 0.;
1093 double x = xin, y = yin, z = zin;
1097 double rcoordinate, rotation;
1098 unsigned int i, j, k;
1099 double position_mapped[3] = {0., 0., 0.};
1101 rcoordinate, rotation))
1104 double rx = (position_mapped[0] - m_xlines.at(i)) /
1105 (m_xlines.at(i + 1) - m_xlines.at(i));
1106 double ry = (position_mapped[1] - m_ylines.at(j)) /
1107 (m_ylines.at(j + 1) - m_ylines.at(j));
1108 double rz = (position_mapped[2] - m_zlines.at(k)) /
1109 (m_zlines.at(k + 1) - m_zlines.at(k));
1111 double potential = GetPotential(i, j, k, rx, ry, rz, &((*it).second));
1114 std::cout <<
m_className <<
"::WeightingPotential:" << std::endl;
1115 std::cout <<
" Global: (" << x <<
"," << y <<
"," << z <<
"),"
1117 std::cout <<
" Local: (" << rx <<
"," << ry <<
"," << rz
1118 <<
") in element with indexes: i=" << i <<
", j=" << j
1119 <<
", k=" << k << std::endl;
1120 std::cout <<
" Node xyzV:" << std::endl;
1121 std::cout <<
"Node 0 position: " << Index2Node(i + 1, j, k)
1122 <<
"\t potential: " << ((*it).second).at(Index2Node(i + 1, j, k))
1123 <<
"Node 1 position: " << Index2Node(i + 1, j + 1, k)
1125 << ((*it).second).at(Index2Node(i + 1, j + 1, k))
1126 <<
"Node 2 position: " << Index2Node(i, j + 1, k)
1127 <<
"\t potential: " << ((*it).second).at(Index2Node(i, j + 1, k))
1128 <<
"Node 3 position: " << Index2Node(i, j, k)
1129 <<
"\t potential: " << ((*it).second).at(Index2Node(i, j, k))
1130 <<
"Node 4 position: " << Index2Node(i + 1, j, k + 1)
1132 << ((*it).second).at(Index2Node(i + 1, j, k + 1))
1133 <<
"Node 5 position: " << Index2Node(i + 1, j + 1, k + 1)
1135 << ((*it).second).at(Index2Node(i + 1, j + 1, k + 1))
1136 <<
"Node 6 position: " << Index2Node(i, j + 1, k + 1)
1138 << ((*it).second).at(Index2Node(i, j + 1, k + 1))
1139 <<
"Node 7 position: " << Index2Node(i, j, k + 1)
1140 <<
"\t potential: " << ((*it).second).at(Index2Node(i, j, k))
1147 unsigned int& n_z) {
1148 n_x = m_xlines.size();
1149 n_y = m_ylines.size();
1150 n_z = m_zlines.size();
1154 double& xmax,
double& ymin,
1155 double& ymax,
double& zmin,
1157 unsigned int i, j, k;
1158 Element2Index(element, i, j, k);
1159 xmin = m_xlines.at(i);
1160 xmax = m_xlines.at(i + 1);
1161 ymin = m_ylines.at(j);
1162 ymax = m_ylines.at(j + 1);
1163 zmin = m_zlines.at(k);
1164 zmax = m_zlines.at(k + 1);
1169 unsigned int i, j, k;
1172 std::cout <<
m_className <<
"::GetMedium:" << std::endl;
1173 std::cout <<
" Found position (" << xin <<
", " << yin <<
", " << zin
1174 <<
"): " << std::endl;
1175 std::cout <<
" Indexes are: x: " << i <<
"/" << m_xlines.size()
1176 <<
"\t y: " << j <<
"/" << m_ylines.size() <<
"\t z: " << k <<
"/"
1177 << m_zlines.size() << std::endl;
1178 std::cout <<
" Element material index: " <<
Index2Element(i, j, k)
1180 std::cout <<
" Element index: "
1181 << (int)m_elementMaterial.at(
Index2Element(i, j, k)) << std::endl;
1189 mapxmax = *(m_xlines.end() - 1);
1191 mapymax = *(m_ylines.end() - 1);
1193 mapzmax = *(m_zlines.end() - 1);
1194 mapvmin = *std::min_element(m_potential.begin(), m_potential.end());
1195 mapvmax = *std::max_element(m_potential.begin(), m_potential.end());
1217 if (fabs(zmax - zmin) <= 0.) {
1218 std::cerr <<
m_className <<
"::SetRangeZ:" << std::endl;
1219 std::cerr <<
" Zero range is not permitted." << std::endl;
1227 const double z,
unsigned int& i,
1228 unsigned int& j,
unsigned int& k) {
1229 bool mirrored[3] = {
false,
false,
false};
1230 double position_mapped[3] = {0., 0., 0.};
1231 double rcoordinate, rotation;
1233 rcoordinate, rotation);
1237 const unsigned int k) {
1239 if (i > m_nx - 2 || j > m_ny - 2 || k > m_nz - 2) {
1240 throw "FieldMap::ElementByIndex: Error. Element indexes out of bounds.";
1242 return i + j * (m_nx - 1) + k * (m_nx - 1) * (m_ny - 1);
1246 const double zin,
unsigned int& i,
1247 unsigned int& j,
unsigned int& k,
1248 double* position_mapped,
bool* mirrored,
1249 double& rcoordinate,
double& rotation) {
1251 position_mapped[0] = xin;
1252 position_mapped[1] = yin;
1253 position_mapped[2] = zin;
1254 MapCoordinates(position_mapped[0], position_mapped[1], position_mapped[2],
1255 mirrored[0], mirrored[1], mirrored[2], rcoordinate, rotation);
1257 std::vector<double>::iterator it_x, it_y, it_z;
1258 it_x = std::lower_bound(m_xlines.begin(), m_xlines.end(), position_mapped[0]);
1259 it_y = std::lower_bound(m_ylines.begin(), m_ylines.end(), position_mapped[1]);
1260 it_z = std::lower_bound(m_zlines.begin(), m_zlines.end(), position_mapped[2]);
1261 if (it_x == m_xlines.end() || it_y == m_ylines.end() ||
1262 it_z == m_zlines.end() || position_mapped[0] < m_xlines.at(0) ||
1263 position_mapped[1] < m_ylines.at(0) ||
1264 position_mapped[2] < m_zlines.at(0)) {
1266 std::cerr <<
m_className <<
"::ElectricFieldBinary:" << std::endl;
1267 std::cerr <<
" Could not find the given coordinate!" << std::endl;
1268 std::cerr <<
" You ask for the following position: " << xin <<
", "
1269 << yin <<
", " << zin << std::endl;
1270 std::cerr <<
" The mapped position is: " << position_mapped[0] <<
", "
1271 << position_mapped[1] <<
", " << position_mapped[2]
1283 if (it_x == m_xlines.begin())
1286 i = std::distance(m_xlines.begin(), it_x - 1);
1287 if (it_y == m_ylines.begin())
1290 j = std::distance(m_ylines.begin(), it_y - 1);
1291 if (it_z == m_zlines.begin())
1294 k = std::distance(m_zlines.begin(), it_z - 1);
1311 unsigned int i, j, k;
1312 Element2Index(element, i, j, k);
1313 std::vector<double> distances;
1314 distances.push_back(m_xlines.at(i + 1) - m_xlines.at(i));
1315 distances.push_back(m_ylines.at(j + 1) - m_ylines.at(j));
1316 distances.push_back(m_zlines.at(k + 1) - m_zlines.at(k));
1317 std::sort(distances.begin(), distances.end());
1318 dmin = distances.at(0);
1319 dmax = distances.at(2);
1324 if ((
int)element >=
nElements)
return 0.;
1325 unsigned int i, j, k;
1326 Element2Index(element, i, j, k);
1327 const double volume = fabs((m_xlines.at(i + 1) - m_xlines.at(i)) *
1328 (m_xlines.at(j + 1) - m_ylines.at(j)) *
1329 (m_xlines.at(k + 1) - m_zlines.at(k)));
1333void ComponentCST::ElectricFieldBinary(
const double xin,
const double yin,
1334 const double zin,
double& ex,
double& ey,
1335 double& ez,
double& volt,
Medium*& m,
1336 int& status,
bool calculatePotential) {
1338 double x = xin, y = yin, z = zin;
1343 double rcoordinate, rotation;
1344 unsigned int i, j, k;
1345 double position_mapped[3] = {0., 0., 0.};
1347 rcoordinate, rotation))
1350 double rx = (position_mapped[0] - m_xlines.at(i)) /
1351 (m_xlines.at(i + 1) - m_xlines.at(i));
1352 double ry = (position_mapped[1] - m_ylines.at(j)) /
1353 (m_ylines.at(j + 1) - m_ylines.at(j));
1354 double rz = (position_mapped[2] - m_zlines.at(k)) /
1355 (m_zlines.at(k + 1) - m_zlines.at(k));
1357 float fex = GetFieldComponent(i, j, k, rx, ry, rz,
'x', &m_potential);
1358 float fey = GetFieldComponent(i, j, k, rx, ry, rz,
'y', &m_potential);
1359 float fez = GetFieldComponent(i, j, k, rx, ry, rz,
'z', &m_potential);
1361 if (m_elementMaterial.size() > 0 && doShaping) {
1362 ShapeField(fex, fey, fez, rx, ry, rz, i, j, k, &m_potential);
1364 if (mirrored[0]) fex *= -1.;
1365 if (mirrored[1]) fey *= -1.;
1366 if (mirrored[2]) fez *= -1.;
1368 std::cout <<
m_className <<
"::ElectricFieldBinary:" << std::endl;
1369 std::cout <<
" Found position (" << x <<
", " << y <<
", " << z
1370 <<
"): " << std::endl;
1371 std::cout <<
" Indexes are: x: " << i <<
"/" << m_xlines.size()
1372 <<
"\t y: " << j <<
"/" << m_ylines.size() <<
"\t z: " << k <<
"/"
1373 << m_zlines.size() << std::endl;
1374 if (i != 0 && j != 0 && k != 0) {
1375 std::cout <<
" index: " << i <<
"\t x before: " << m_xlines.at(i - 1)
1376 <<
"\t x behind: " << m_xlines.at(i) <<
"\t r = " << rx
1377 <<
"\n index: " << j <<
"\t y before: " << m_ylines.at(j - 1)
1378 <<
"\t y behind: " << m_ylines.at(j) <<
"\t r = " << ry
1379 <<
"\n index: " << k <<
"\t z before: " << m_zlines.at(k - 1)
1380 <<
"\t z behind: " << m_zlines.at(k) <<
"\t r = " << rz
1383 std::cout <<
" Electric field is: " << fex <<
", " << fey <<
", " << fez
1384 <<
"): " << std::endl;
1396 if (!disableFieldComponent[0]) ex = fex;
1397 if (!disableFieldComponent[1]) ey = fey;
1398 if (!disableFieldComponent[2]) ez = fez;
1399 if (calculatePotential)
1400 volt = GetPotential(i, j, k, rx, ry, rz, &m_potential);
1403float ComponentCST::GetFieldComponent(
const unsigned int i,
1404 const unsigned int j,
1405 const unsigned int k,
const double rx,
1406 const double ry,
const double rz,
1407 const char component,
1408 const std::vector<float>* potentials) {
1409 float dv1 = 0, dv2 = 0, dv3 = 0, dv4 = 0;
1410 float dv11 = 0, dv21 = 0, dv = 0;
1412 if (component ==
'x') {
1413 dv1 = potentials->at(Index2Node(i + 1, j, k)) -
1414 potentials->at(Index2Node(i, j, k));
1415 dv2 = potentials->at(Index2Node(i + 1, j + 1, k)) -
1416 potentials->at(Index2Node(i, j + 1, k));
1417 dv3 = potentials->at(Index2Node(i + 1, j + 1, k + 1)) -
1418 potentials->at(Index2Node(i, j + 1, k + 1));
1419 dv4 = potentials->at(Index2Node(i + 1, j, k + 1)) -
1420 potentials->at(Index2Node(i, j, k + 1));
1422 dv11 = dv1 + (dv4 - dv1) * rz;
1423 dv21 = dv2 + (dv3 - dv2) * rz;
1424 dv = dv11 + (dv21 - dv11) * ry;
1425 e = -1 * dv / (m_xlines.at(i + 1) - m_xlines.at(i));
1427 if (component ==
'y') {
1428 dv1 = potentials->at(Index2Node(i, j + 1, k)) -
1429 potentials->at(Index2Node(i, j, k));
1430 dv2 = potentials->at(Index2Node(i, j + 1, k + 1)) -
1431 potentials->at(Index2Node(i, j, k + 1));
1432 dv3 = potentials->at(Index2Node(i + 1, j + 1, k + 1)) -
1433 potentials->at(Index2Node(i + 1, j, k + 1));
1434 dv4 = potentials->at(Index2Node(i + 1, j + 1, k)) -
1435 potentials->at(Index2Node(i + 1, j, k));
1437 dv11 = dv1 + (dv4 - dv1) * rx;
1438 dv21 = dv2 + (dv3 - dv2) * rx;
1439 dv = dv11 + (dv21 - dv11) * rz;
1440 e = -1 * dv / (m_ylines.at(j + 1) - m_ylines.at(j));
1442 if (component ==
'z') {
1443 dv1 = potentials->at(Index2Node(i, j, k + 1)) -
1444 potentials->at(Index2Node(i, j, k));
1445 dv2 = potentials->at(Index2Node(i + 1, j, k + 1)) -
1446 potentials->at(Index2Node(i + 1, j, k));
1447 dv3 = potentials->at(Index2Node(i + 1, j + 1, k + 1)) -
1448 potentials->at(Index2Node(i + 1, j + 1, k));
1449 dv4 = potentials->at(Index2Node(i, j + 1, k + 1)) -
1450 potentials->at(Index2Node(i, j + 1, k));
1452 dv11 = dv1 + (dv4 - dv1) * ry;
1453 dv21 = dv2 + (dv3 - dv2) * ry;
1454 dv = dv11 + (dv21 - dv11) * rx;
1455 e = -1 * dv / (m_zlines.at(k + 1) - m_zlines.at(k));
1460float ComponentCST::GetPotential(
const unsigned int i,
const unsigned int j,
1461 const unsigned int k,
const double rx,
1462 const double ry,
const double rz,
1463 const std::vector<float>* potentials) {
1464 double t1 = rx * 2. - 1;
1465 double t2 = ry * 2. - 1;
1466 double t3 = rz * 2. - 1;
1467 return (potentials->at(Index2Node(i + 1, j, k)) * (1 - t1) * (1 - t2) *
1469 potentials->at(Index2Node(i + 1, j + 1, k)) * (1 + t1) * (1 - t2) *
1471 potentials->at(Index2Node(i, j + 1, k)) * (1 + t1) * (1 + t2) *
1473 potentials->at(Index2Node(i, j, k)) * (1 - t1) * (1 + t2) * (1 - t3) +
1474 potentials->at(Index2Node(i + 1, j, k + 1)) * (1 - t1) * (1 - t2) *
1476 potentials->at(Index2Node(i + 1, j + 1, k + 1)) * (1 + t1) *
1477 (1 - t2) * (1 + t3) +
1478 potentials->at(Index2Node(i, j + 1, k + 1)) * (1 + t1) * (1 + t2) *
1480 potentials->at(Index2Node(i, j, k + 1)) * (1 - t1) * (1 + t2) *
1485void ComponentCST::ShapeField(
float& ex,
float& ey,
float& ez,
const double rx,
1486 const double ry,
const double rz,
1487 const unsigned int i,
const unsigned int j,
1488 const unsigned int k,
1489 std::vector<float>* potentials) {
1491 if ((i == 0 && rx >= 0.5) || (i == m_xlines.size() - 2 && rx < 0.5) ||
1492 (i > 0 && i < m_xlines.size() - 2)) {
1498 GetFieldComponent(i + 1, j, k, 0.5, ry, rz,
'x', potentials);
1499 ex = ex + (rx - 0.5) * (ex_next - ex) *
1500 (m_xlines.at(i + 1) - m_xlines.at(i)) /
1501 (m_xlines.at(i + 2) - m_xlines.at(i + 1));
1507 GetFieldComponent(i - 1, j, k, 0.5, ry, rz,
'x', potentials);
1508 ex = ex_before + (rx + 0.5) * (ex - ex_before) *
1509 (m_xlines.at(i) - m_xlines.at(i - 1)) /
1510 (m_xlines.at(i + 1) - m_xlines.at(i));
1515 if ((j == 0 && ry >= 0.5) || (j == m_ylines.size() - 2 && ry < 0.5) ||
1516 (j > 0 && j < m_ylines.size() - 2)) {
1522 GetFieldComponent(i, j + 1, k, rx, 0.5, rz,
'y', potentials);
1523 ey = ey + (ry - 0.5) * (ey_next - ey) *
1524 (m_ylines.at(j + 1) - m_ylines.at(j)) /
1525 (m_ylines.at(j + 2) - m_ylines.at(j + 1));
1531 GetFieldComponent(i, j - 1, k, rx, 0.5, rz,
'y', potentials);
1532 ey = ey_next + (ry + 0.5) * (ey - ey_next) *
1533 (m_ylines.at(j) - m_ylines.at(j - 1)) /
1534 (m_ylines.at(j + 1) - m_ylines.at(j));
1539 if ((k == 0 && rz >= 0.5) || (k == m_zlines.size() - 2 && rz < 0.5) ||
1540 (k > 0 && k < m_zlines.size() - 2)) {
1546 GetFieldComponent(i, j, k + 1, rx, ry, 0.5,
'z', potentials);
1547 ez = ez + (rz - 0.5) * (ez_next - ez) *
1548 (m_zlines.at(k + 1) - m_zlines.at(k)) /
1549 (m_zlines.at(k + 2) - m_zlines.at(k + 1));
1555 GetFieldComponent(i, j, k - 1, rx, ry, 0.5,
'z', potentials);
1556 ez = ez_next + (rz + 0.5) * (ez - ez_next) *
1557 (m_zlines.at(k) - m_zlines.at(k - 1)) /
1558 (m_zlines.at(k + 1) - m_zlines.at(k));
1564void ComponentCST::Element2Index(
int element,
unsigned int& i,
unsigned int& j,
1567 k = element / ((m_xlines.size() - 1) * (m_ylines.size() - 1));
1568 tmp -= k * (m_xlines.size() - 1) * (m_ylines.size() - 1);
1569 j = tmp / (m_xlines.size() - 1);
1570 i = element - j * (m_xlines.size() - 1) -
1571 k * (m_xlines.size() - 1) * (m_ylines.size() - 1);
1574int ComponentCST::Index2Node(
const unsigned int i,
const unsigned int j,
1575 const unsigned int k) {
1577 if (i > m_nx - 1 || j > m_ny - 1 || k > m_nz - 1) {
1578 throw "FieldMap::NodeByIndex: Error. Node indexes out of bounds.";
1580 return i + j * m_nx + k * m_nx * m_ny;
bool m_ready
Ready for use?
std::string m_className
Class name.
bool m_debug
Switch on/off debugging messages.
void UpdatePeriodicity()
Verify periodicities.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
bool Coordinate2Index(const double x, const double y, const double z, unsigned int &i, unsigned int &j, unsigned int &k)
void GetNumberOfMeshLines(unsigned int &n_x, unsigned int &n_y, unsigned int &n_z)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)
int Index2Element(const unsigned int i, const unsigned int j, const unsigned int k)
bool Initialise(std::string elist, std::string nlist, std::string mplist, std::string prnsol, std::string unit="cm")
double GetElementVolume(const unsigned int i)
void GetAspectRatio(const unsigned int i, double &dmin, double &dmax)
Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
bool SetWeightingField(std::string prnsol, std::string label, bool isBinary=true)
double WeightingPotential(const double x, const double y, const double z, const std::string &label)
void ShiftComponent(const double xShift, const double yShift, const double zShift)
void GetElementBoundaries(unsigned int element, double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax)
void SetRange()
Calculate x, y, z, V and angular ranges.
void SetRangeZ(const double zmin, const double zmax)
Base class for components based on finite-element field maps.
void PrintRange()
Show x, y, z, V and angular ranges.
void PrintMaterials()
List all currently defined materials.
double ReadDouble(char *token, double def, bool &error)
std::vector< bool > wfieldsOk
void MapCoordinates(double &xpos, double &ypos, double &zpos, bool &xmirrored, bool &ymirrored, bool &zmirrored, double &rcoordinate, double &rotation) const
Move (xpos, ypos, zpos) to field map coordinates.
void PrintWarning(const std::string &header)
void UpdatePeriodicityCommon()
int ReadInteger(char *token, int def, bool &error)
unsigned int m_nMaterials
std::vector< Material > materials
void UpdatePeriodicity2d()
std::vector< std::string > wfields
Abstract base class for media.