23 std::string mplist, std::string prnsol,
35 std::ifstream fmplist;
36 fmplist.open(mplist.c_str(), std::ios::in);
39 std::cerr <<
" Could not open material file " << mplist
41 std::cerr <<
" The file perhaps does not exist.\n";
47 int il = 0, icurrmat = -1;
48 bool readerror =
false;
49 while (fmplist.getline(line, size,
'\n')) {
52 if (strcmp(line,
"1") == 0) {
53 fmplist.getline(line, size,
'\n');
55 fmplist.getline(line, size,
'\n');
57 fmplist.getline(line, size,
'\n');
59 fmplist.getline(line, size,
'\n');
61 fmplist.getline(line, size,
'\n');
67 token = strtok(line,
" ");
69 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
70 strcmp(token,
"TEMPERATURE") == 0 || strcmp(token,
"PROPERTY=") == 0 ||
71 int(token[0]) == 10 ||
int(token[0]) == 13)
75 if (strcmp(token,
"LIST") == 0) {
76 token = strtok(NULL,
" ");
77 token = strtok(NULL,
" ");
78 token = strtok(NULL,
" ");
79 token = strtok(NULL,
" ");
83 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
97 std::cout <<
" Number of materials: " <<
nMaterials <<
"\n";
99 }
else if (strcmp(token,
"MATERIAL") == 0) {
101 token = strtok(NULL,
" ");
102 token = strtok(NULL,
" ");
106 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
112 }
else if (strcmp(token,
"TEMP") == 0) {
114 token = strtok(NULL,
" ");
116 if (strncmp(token,
"PERX", 4) == 0) {
118 }
else if (strncmp(token,
"RSVX", 4) == 0) {
122 std::cerr <<
" Found unknown material property flag " << token
124 std::cerr <<
" on material properties file " << mplist <<
" (line "
128 fmplist.getline(line, size,
'\n');
131 token = strtok(line,
" ");
134 std::cerr <<
" Found out-of-range current material index "
136 std::cerr <<
" in material properties file " << mplist <<
".\n";
139 }
else if (itype == 1) {
141 }
else if (itype == 2) {
146 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
152 }
else if (strcmp(token,
"PROPERTY") == 0) {
154 token = strtok(NULL,
" ");
155 token = strtok(NULL,
" ");
157 if (strcmp(token,
"PERX") == 0) {
159 }
else if (strcmp(token,
"RSVX") == 0) {
164 std::cerr <<
" Found unknown material property flag " << token
166 std::cerr <<
" on material properties file " << mplist <<
" (line "
170 token = strtok(NULL,
" ");
171 token = strtok(NULL,
" ");
175 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
182 std::cerr <<
" Found out-of-range current material index " << imat
184 std::cerr <<
" in material properties file " << mplist <<
".\n";
187 fmplist.getline(line, size,
'\n');
189 fmplist.getline(line, size,
'\n');
192 token = strtok(line,
" ");
193 token = strtok(NULL,
" ");
196 }
else if (itype == 2) {
201 std::cerr <<
" Error reading file " << mplist <<
" (line " << il
217 for (
int imat = 0; imat <
nMaterials; ++imat) {
221 std::cerr <<
" Material " << imat
222 <<
" has been assigned a permittivity\n";
223 std::cerr <<
" equal to zero in " << mplist <<
".\n";
225 }
else if (iepsmin < 0 || epsmin >
materials[imat].eps) {
233 std::cerr <<
" No material with positive permittivity found \n";
234 std::cerr <<
" in material list " << mplist <<
".\n";
237 for (
int imat = 0; imat <
nMaterials; ++imat) {
238 if (imat == iepsmin) {
248 std::cout <<
" Read properties of " <<
nMaterials
249 <<
" materials from file " << mplist <<
".\n";
253 std::ifstream felist;
254 felist.open(elist.c_str(), std::ios::in);
257 std::cerr <<
" Could not open element file " << elist
258 <<
" for reading.\n";
259 std::cerr <<
" The file perhaps does not exist.\n";
270 while (felist.getline(line, size,
'\n')) {
275 token = strtok(line,
" ");
277 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
278 int(token[0]) == 10 ||
int(token[0]) == 13 ||
279 strcmp(token,
"LIST") == 0 || strcmp(token,
"ELEM") == 0)
283 token = strtok(NULL,
" ");
285 token = strtok(NULL,
" ");
286 token = strtok(NULL,
" ");
287 token = strtok(NULL,
" ");
288 token = strtok(NULL,
" ");
289 token = strtok(NULL,
" ");
290 if (!token) std::cerr <<
"No token available\n";
292 token = strtok(NULL,
" ");
294 token = strtok(NULL,
" ");
296 token = strtok(NULL,
" ");
298 token = strtok(NULL,
" ");
300 token = strtok(NULL,
" ");
302 token = strtok(NULL,
" ");
304 token = strtok(NULL,
" ");
310 std::cerr <<
" Error reading file " << elist <<
" (line " << il
315 }
else if (ielem - 1 !=
nElements + nbackground) {
317 std::cerr <<
" Synchronisation lost on file " << elist <<
" (line "
319 std::cerr <<
" Element: " << ielem <<
" (expected " <<
nElements
320 <<
"), material: " << imat <<
", nodes: (" << in0 <<
", " << in1
321 <<
", " << in2 <<
", " << in3 <<
", " << in4 <<
", " << in5
322 <<
", " << in6 <<
", " << in7 <<
")\n";
328 std::cerr <<
" Out-of-range material number on file " << elist
329 <<
" (line " << il <<
").\n";
330 std::cerr <<
" Element: " << ielem <<
", material: " << imat
331 <<
", nodes: (" << in0 <<
", " << in1 <<
", " << in2 <<
", "
332 << in3 <<
", " << in4 <<
", " << in5 <<
", " << in6 <<
", "
338 std::cerr <<
" Element " << ielem <<
" in element list " << elist
339 <<
" uses material " << imat <<
" which\n",
340 std::cerr <<
" has not been assigned a positive permittivity\n";
341 std::cerr <<
" in material list " << mplist <<
".\n";
345 if (in0 < 1 || in1 < 1 || in2 < 1 || in3 < 1 || in4 < 1 || in5 < 1 ||
346 in6 < 1 || in7 < 1) {
348 std::cerr <<
" Found a node number < 1 on file " << elist <<
" (line "
350 std::cerr <<
" Element: " << ielem <<
", material: " << imat <<
"\n";
353 if (in0 > highestnode) highestnode = in0;
354 if (in1 > highestnode) highestnode = in1;
355 if (in2 > highestnode) highestnode = in2;
356 if (in3 > highestnode) highestnode = in3;
357 if (in4 > highestnode) highestnode = in4;
358 if (in5 > highestnode) highestnode = in5;
359 if (in6 > highestnode) highestnode = in6;
360 if (in7 > highestnode) highestnode = in7;
367 if (in2 == in3 && in3 == in6) {
374 newElement.
matmap = imat - 1;
377 newElement.
emap[0] = in0 - 1;
378 newElement.
emap[1] = in1 - 1;
379 newElement.
emap[2] = in2 - 1;
380 newElement.
emap[3] = in4 - 1;
381 newElement.
emap[4] = in7 - 1;
382 newElement.
emap[5] = in5 - 1;
383 newElement.
emap[6] = in3 - 1;
384 newElement.
emap[7] = in6 - 1;
386 newElement.
emap[0] = in0 - 1;
387 newElement.
emap[1] = in1 - 1;
388 newElement.
emap[2] = in2 - 1;
389 newElement.
emap[3] = in3 - 1;
390 newElement.
emap[4] = in4 - 1;
391 newElement.
emap[5] = in5 - 1;
392 newElement.
emap[6] = in6 - 1;
393 newElement.
emap[7] = in7 - 1;
402 std::cout <<
" Read " <<
nElements <<
" elements from file " << elist
404 std::cout <<
" highest node number: " << highestnode <<
",\n";
405 std::cout <<
" degenerate elements: " << ndegenerate <<
",\n";
406 std::cout <<
" background elements skipped: " << nbackground <<
".\n";
409 if (strcmp(unit.c_str(),
"mum") == 0 || strcmp(unit.c_str(),
"micron") == 0 ||
410 strcmp(unit.c_str(),
"micrometer") == 0) {
412 }
else if (strcmp(unit.c_str(),
"mm") == 0 ||
413 strcmp(unit.c_str(),
"millimeter") == 0) {
415 }
else if (strcmp(unit.c_str(),
"cm") == 0 ||
416 strcmp(unit.c_str(),
"centimeter") == 0) {
418 }
else if (strcmp(unit.c_str(),
"m") == 0 ||
419 strcmp(unit.c_str(),
"meter") == 0) {
423 std::cerr <<
" Unknown length unit " << unit <<
".\n";
429 std::cout <<
" Unit scaling factor = " << funit <<
".\n";
433 std::ifstream fnlist;
434 fnlist.open(nlist.c_str(), std::ios::in);
437 std::cerr <<
" Could not open nodes file " << nlist <<
" for reading.\n";
438 std::cerr <<
" The file perhaps does not exist.\n";
447 while (fnlist.getline(line, size,
'\n')) {
452 token = strtok(line,
" ");
454 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
455 int(token[0]) == 10 ||
int(token[0]) == 13 ||
456 strcmp(token,
"LIST") == 0 || strcmp(token,
"NODE") == 0)
460 token = strtok(NULL,
" ");
461 double xnode =
ReadDouble(token, -1, readerror);
462 token = strtok(NULL,
" ");
463 double ynode =
ReadDouble(token, -1, readerror);
464 token = strtok(NULL,
" ");
465 double znode =
ReadDouble(token, -1, readerror);
469 std::cerr <<
" Error reading file " << nlist <<
" (line " << il
476 if (inode - 1 !=
nNodes) {
478 std::cerr <<
" Synchronisation lost on file " << nlist <<
" (line "
480 std::cerr <<
" Node: " << inode <<
" (expected " <<
nNodes
481 <<
"), (x,y,z) = (" << xnode <<
", " << ynode <<
", " << znode
487 newNode.
x = xnode * funit;
488 newNode.
y = ynode * funit;
489 newNode.
z = znode * funit;
490 nodes.push_back(newNode);
497 std::cout <<
" Read " <<
nNodes <<
" nodes from file " << nlist <<
".\n";
499 if (
nNodes != highestnode) {
501 std::cerr <<
" Number of nodes read (" <<
nNodes <<
") on " << nlist
503 std::cerr <<
" does not match element list (" << highestnode <<
").\n";
508 std::ifstream fprnsol;
509 fprnsol.open(prnsol.c_str(), std::ios::in);
510 if (fprnsol.fail()) {
512 std::cerr <<
" Could not open potential file " << prnsol
513 <<
" for reading.\n";
514 std::cerr <<
" The file perhaps does not exist.\n";
521 while (fprnsol.getline(line, size,
'\n')) {
525 token = strtok(line,
" ");
527 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
528 int(token[0]) == 10 ||
int(token[0]) == 13 ||
529 strcmp(token,
"PRINT") == 0 || strcmp(token,
"*****") == 0 ||
530 strcmp(token,
"LOAD") == 0 || strcmp(token,
"TIME=") == 0 ||
531 strcmp(token,
"MAXIMUM") == 0 || strcmp(token,
"VALUE") == 0 ||
532 strcmp(token,
"NODE") == 0)
536 token = strtok(NULL,
" ");
537 double volt =
ReadDouble(token, -1, readerror);
541 std::cerr <<
" Error reading file " << prnsol <<
" (line " << il
548 if (inode < 1 || inode >
nNodes) {
550 std::cerr <<
" Node number " << inode <<
" out of range\n";
551 std::cerr <<
" on potential file " << prnsol <<
" (line " << il
555 nodes[inode - 1].v = volt;
563 std::cout <<
" Read " << nread <<
" potentials from file " << prnsol
568 std::cerr <<
" Number of nodes read (" << nread <<
") on potential file "
569 << prnsol <<
" does not\n",
570 std::cerr <<
" match the node list (" <<
nNodes <<
").\n";
579 <<
" Field map could not be read and cannot be interpolated.\n";
598 std::cerr <<
m_className <<
"::SetWeightingField:\n";
599 std::cerr <<
" No valid field map is present.\n";
600 std::cerr <<
" Weighting field cannot be added.\n";
605 std::ifstream fprnsol;
606 fprnsol.open(prnsol.c_str(), std::ios::in);
607 if (fprnsol.fail()) {
608 std::cerr <<
m_className <<
"::SetWeightingField:\n";
609 std::cerr <<
" Could not open potential file " << prnsol
610 <<
" for reading.\n";
611 std::cerr <<
" The file perhaps does not exist.\n";
627 for (
int j =
nNodes; j--;) {
631 std::cout <<
m_className <<
"::SetWeightingField:\n";
632 std::cout <<
" Replacing existing weighting field " << label <<
".\n";
638 const int size = 100;
645 bool readerror =
false;
646 while (fprnsol.getline(line, size,
'\n')) {
650 token = strtok(line,
" ");
652 if (!token || strcmp(token,
" ") == 0 || strcmp(token,
"\n") == 0 ||
653 int(token[0]) == 10 ||
int(token[0]) == 13 ||
654 strcmp(token,
"PRINT") == 0 || strcmp(token,
"*****") == 0 ||
655 strcmp(token,
"LOAD") == 0 || strcmp(token,
"TIME=") == 0 ||
656 strcmp(token,
"MAXIMUM") == 0 || strcmp(token,
"VALUE") == 0 ||
657 strcmp(token,
"NODE") == 0)
661 token = strtok(NULL,
" ");
662 double volt =
ReadDouble(token, -1, readerror);
665 std::cerr <<
m_className <<
"::SetWeightingField:\n";
666 std::cerr <<
" Error reading file " << prnsol <<
" (line " << il
672 if (inode < 1 || inode >
nNodes) {
673 std::cerr <<
m_className <<
"::SetWeightingField:\n";
674 std::cerr <<
" Node number " << inode <<
" out of range\n";
675 std::cerr <<
" on potential file " << prnsol <<
" (line " << il
679 nodes[inode - 1].w[iw] = volt;
686 std::cout <<
m_className <<
"::SetWeightingField:\n";
687 std::cout <<
" Read " << nread <<
" potentials from file " << prnsol
691 std::cerr <<
m_className <<
"::SetWeightingField:\n";
692 std::cerr <<
" Number of nodes read (" << nread <<
") "
693 <<
" on potential file " << prnsol <<
"\n";
694 std::cerr <<
" does not match the node list (" <<
nNodes <<
").\n";
701 std::cerr <<
m_className <<
"::SetWeightingField:\n";
702 std::cerr <<
" Field map could not be read "
703 <<
"and cannot be interpolated.\n";
710 const double z,
double& ex,
double& ey,
711 double& ez,
Medium*& m,
int& status) {
718 const double zin,
double& ex,
double& ey,
719 double& ez,
double& volt,
Medium*& m,
723 double x = xin, y = yin, z = 0.;
726 bool xmirrored, ymirrored, zmirrored;
727 double rcoordinate, rotation;
728 MapCoordinates(x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
732 ex = ey = ez = volt = 0;
740 std::cerr <<
" Field map not available for interpolation.\n";
746 std::cerr <<
" Warnings have been issued for this field map.\n";
755 double t1, t2, t3, t4, jac[4][4], det;
756 int imap =
FindElement5(x, y, z, t1, t2, t3, t4, jac, det);
760 std::cout <<
" Point (" << x <<
", " << y <<
") not in the mesh.\n";
768 std::cout <<
" Global: (" << x <<
", " << y <<
"),\n";
769 std::cout <<
" Local: (" << t1 <<
", " << t2 <<
", " << t3 <<
", " << t4
770 <<
") in element " << imap
771 <<
" (degenerate: " <<
elements[imap].degenerate <<
")\n";
774 for (
int i = 0; i < 8; i++) {
775 printf(
" %-5d %12g %12g %12g\n",
elements[imap].emap[i],
789 ex = -(
nodes[
elements[imap].emap[0]].v * (4 * t1 - 1) * jac[0][1] +
793 (4 * t2 * jac[0][1] + 4 * t1 * jac[1][1]) +
795 (4 * t3 * jac[0][1] + 4 * t1 * jac[2][1]) +
797 (4 * t3 * jac[1][1] + 4 * t2 * jac[2][1])) /
799 ey = -(
nodes[
elements[imap].emap[0]].v * (4 * t1 - 1) * jac[0][2] +
803 (4 * t2 * jac[0][2] + 4 * t1 * jac[1][2]) +
805 (4 * t3 * jac[0][2] + 4 * t1 * jac[2][2]) +
807 (4 * t3 * jac[1][2] + 4 * t2 * jac[2][2])) /
811 -
nodes[
elements[imap].emap[0]].v * (1 - t1) * (1 - t2) * (1 + t1 + t2) /
813 nodes[
elements[imap].emap[1]].v * (1 + t1) * (1 - t2) * (1 - t1 + t2) /
815 nodes[
elements[imap].emap[2]].v * (1 + t1) * (1 + t2) * (1 - t1 - t2) /
817 nodes[
elements[imap].emap[3]].v * (1 - t1) * (1 + t2) * (1 + t1 - t2) /
819 nodes[
elements[imap].emap[4]].v * (1 - t1) * (1 + t1) * (1 - t2) / 2 +
820 nodes[
elements[imap].emap[5]].v * (1 + t1) * (1 + t2) * (1 - t2) / 2 +
821 nodes[
elements[imap].emap[6]].v * (1 - t1) * (1 + t1) * (1 + t2) / 2 +
822 nodes[
elements[imap].emap[7]].v * (1 - t1) * (1 + t2) * (1 - t2) / 2;
824 ((1 - t2) * (2 * t1 + t2) * jac[0][0] +
825 (1 - t1) * (t1 + 2 * t2) * jac[1][0]) /
828 ((1 - t2) * (2 * t1 - t2) * jac[0][0] -
829 (1 + t1) * (t1 - 2 * t2) * jac[1][0]) /
832 ((1 + t2) * (2 * t1 + t2) * jac[0][0] +
833 (1 + t1) * (t1 + 2 * t2) * jac[1][0]) /
836 ((1 + t2) * (2 * t1 - t2) * jac[0][0] -
837 (1 - t1) * (t1 - 2 * t2) * jac[1][0]) /
840 (t1 * (t2 - 1) * jac[0][0] +
841 (t1 - 1) * (t1 + 1) * jac[1][0] / 2) +
843 ((1 - t2) * (1 + t2) * jac[0][0] / 2 -
844 (1 + t1) * t2 * jac[1][0]) +
846 (-t1 * (1 + t2) * jac[0][0] +
847 (1 - t1) * (1 + t1) * jac[1][0] / 2) +
849 ((t2 - 1) * (t2 + 1) * jac[0][0] / 2 +
850 (t1 - 1) * t2 * jac[1][0])) /
853 ((1 - t2) * (2 * t1 + t2) * jac[0][1] +
854 (1 - t1) * (t1 + 2 * t2) * jac[1][1]) /
857 ((1 - t2) * (2 * t1 - t2) * jac[0][1] -
858 (1 + t1) * (t1 - 2 * t2) * jac[1][1]) /
861 ((1 + t2) * (2 * t1 + t2) * jac[0][1] +
862 (1 + t1) * (t1 + 2 * t2) * jac[1][1]) /
865 ((1 + t2) * (2 * t1 - t2) * jac[0][1] -
866 (1 - t1) * (t1 - 2 * t2) * jac[1][1]) /
869 (t1 * (t2 - 1) * jac[0][1] +
870 (t1 - 1) * (t1 + 1) * jac[1][1] / 2) +
872 ((1 - t2) * (1 + t2) * jac[0][1] / 2 -
873 (1 + t1) * t2 * jac[1][1]) +
875 (-t1 * (1 + t2) * jac[0][1] +
876 (1 - t1) * (1 + t1) * jac[1][1] / 2) +
878 ((t2 - 1) * (t2 + 1) * jac[0][1] / 2 +
879 (t1 - 1) * t2 * jac[1][1])) /
884 UnmapFields(ex, ey, ez, x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
890 std::cout <<
" Material " <<
elements[imap].matmap <<
", drift flag "
903 const double zin,
double& wx,
double& wy,
904 double& wz,
const std::string label) {
929 double x = xin, y = yin, z = zin;
932 bool xmirrored, ymirrored, zmirrored;
933 double rcoordinate, rotation;
934 MapCoordinates(x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
939 std::cerr <<
" Warnings have been issued for this field map.\n";
943 double t1, t2, t3, t4, jac[4][4], det;
944 int imap =
FindElement5(x, y, z, t1, t2, t3, t4, jac, det);
946 if (imap < 0)
return;
950 std::cout <<
" Global: (" << x <<
", " << y <<
"),\n";
951 std::cout <<
" Local: (" << t1 <<
", " << t2 <<
", " << t3 <<
", " << t4
952 <<
") in element " << imap
953 <<
" (degenerate: " <<
elements[imap].degenerate <<
")\n";
956 for (
int i = 0; i < 8; i++) {
957 printf(
" %-5d %12g %12g %12g\n",
elements[imap].emap[i],
965 wx = -(
nodes[
elements[imap].emap[0]].w[iw] * (4 * t1 - 1) * jac[0][1] +
966 nodes[
elements[imap].emap[1]].w[iw] * (4 * t2 - 1) * jac[1][1] +
967 nodes[
elements[imap].emap[2]].w[iw] * (4 * t3 - 1) * jac[2][1] +
969 (4 * t2 * jac[0][1] + 4 * t1 * jac[1][1]) +
971 (4 * t3 * jac[0][1] + 4 * t1 * jac[2][1]) +
973 (4 * t3 * jac[1][1] + 4 * t2 * jac[2][1])) /
975 wy = -(
nodes[
elements[imap].emap[0]].w[iw] * (4 * t1 - 1) * jac[0][2] +
976 nodes[
elements[imap].emap[1]].w[iw] * (4 * t2 - 1) * jac[1][2] +
977 nodes[
elements[imap].emap[2]].w[iw] * (4 * t3 - 1) * jac[2][2] +
979 (4 * t2 * jac[0][2] + 4 * t1 * jac[1][2]) +
981 (4 * t3 * jac[0][2] + 4 * t1 * jac[2][2]) +
983 (4 * t3 * jac[1][2] + 4 * t2 * jac[2][2])) /
987 ((1 - t2) * (2 * t1 + t2) * jac[0][0] +
988 (1 - t1) * (t1 + 2 * t2) * jac[1][0]) /
991 ((1 - t2) * (2 * t1 - t2) * jac[0][0] -
992 (1 + t1) * (t1 - 2 * t2) * jac[1][0]) /
995 ((1 + t2) * (2 * t1 + t2) * jac[0][0] +
996 (1 + t1) * (t1 + 2 * t2) * jac[1][0]) /
999 ((1 + t2) * (2 * t1 - t2) * jac[0][0] -
1000 (1 - t1) * (t1 - 2 * t2) * jac[1][0]) /
1003 (t1 * (t2 - 1) * jac[0][0] +
1004 (t1 - 1) * (t1 + 1) * jac[1][0] / 2) +
1006 ((1 - t2) * (1 + t2) * jac[0][0] / 2 -
1007 (1 + t1) * t2 * jac[1][0]) +
1009 (-t1 * (1 + t2) * jac[0][0] +
1010 (1 - t1) * (1 + t1) * jac[1][0] / 2) +
1012 ((t2 - 1) * (1 + t2) * jac[0][0] / 2 +
1013 (t1 - 1) * t2 * jac[1][0])) /
1016 ((1 - t2) * (2 * t1 + t2) * jac[0][1] +
1017 (1 - t1) * (t1 + 2 * t2) * jac[1][1]) /
1020 ((1 - t2) * (2 * t1 - t2) * jac[0][1] -
1021 (1 + t1) * (t1 - 2 * t2) * jac[1][1]) /
1024 ((1 + t2) * (2 * t1 + t2) * jac[0][1] +
1025 (1 + t1) * (t1 + 2 * t2) * jac[1][1]) /
1028 ((1 + t2) * (2 * t1 - t2) * jac[0][1] -
1029 (1 - t1) * (t1 - 2 * t2) * jac[1][1]) /
1032 (t1 * (t2 - 1) * jac[0][1] +
1033 (t1 - 1) * (t1 + 1) * jac[1][1] / 2) +
1035 ((1 - t2) * (1 + t2) * jac[0][1] / 2 -
1036 (1 + t1) * t2 * jac[1][1]) +
1038 (-t1 * (1 + t2) * jac[0][1] +
1039 (1 - t1) * (1 + t1) * jac[1][1] / 2) +
1041 ((t2 - 1) * (t2 + 1) * jac[0][1] / 2 +
1042 (t1 - 1) * t2 * jac[1][1])) /
1047 UnmapFields(wx, wy, wz, x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
1053 const std::string label) {
1056 if (!
ready)
return 0.;
1070 if (!found)
return 0.;
1075 double x = xin, y = yin, z = zin;
1078 bool xmirrored, ymirrored, zmirrored;
1079 double rcoordinate, rotation;
1080 MapCoordinates(x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
1084 std::cerr <<
m_className <<
"::WeightingPotential:\n";
1085 std::cerr <<
" Warnings have been issued for this field map.\n";
1089 double t1, t2, t3, t4, jac[4][4], det;
1090 int imap =
FindElement5(x, y, z, t1, t2, t3, t4, jac, det);
1092 if (imap < 0)
return 0.;
1095 std::cerr <<
m_className <<
"::WeightingPotential:\n";
1096 std::cout <<
" Global: (" << x <<
", " << y <<
"),\n";
1097 std::cout <<
" Local: (" << t1 <<
", " << t2 <<
", " << t3 <<
", " << t4
1098 <<
") in element " << imap
1099 <<
" (degenerate: " <<
elements[imap].degenerate <<
")\n";
1102 for (
int i = 0; i < 8; ++i) {
1103 printf(
" %-5d %12g %12g %12g\n",
elements[imap].emap[i],
1111 return nodes[
elements[imap].emap[0]].w[iw] * t1 * (2 * t1 - 1) +
1119 return -
nodes[
elements[imap].emap[0]].w[iw] * (1 - t1) * (1 - t2) *
1127 nodes[
elements[imap].emap[4]].w[iw] * (1 - t1) * (1 + t1) * (1 - t2) /
1129 nodes[
elements[imap].emap[5]].w[iw] * (1 + t1) * (1 + t2) * (1 - t2) /
1131 nodes[
elements[imap].emap[6]].w[iw] * (1 - t1) * (1 + t1) * (1 + t2) /
1133 nodes[
elements[imap].emap[7]].w[iw] * (1 - t1) * (1 + t2) * (1 - t2) /
1138 const double& zin) {
1141 double x = xin, y = yin, z = 0.;
1144 bool xmirrored, ymirrored, zmirrored;
1145 double rcoordinate, rotation;
1146 MapCoordinates(x, y, z, xmirrored, ymirrored, zmirrored, rcoordinate,
1156 std::cerr <<
" Field map not available for interpolation.\n";
1161 std::cerr <<
" Warnings have been issued for this field map.\n";
1165 double t1, t2, t3, t4, jac[4][4], det;
1166 int imap =
FindElement5(x, y, z, t1, t2, t3, t4, jac, det);
1170 std::cerr <<
" Point (" << x <<
", " << y <<
") not in the mesh.\n";
1177 std::cerr <<
" Point (" << x <<
", " << y <<
")"
1178 <<
" has out of range material number " << imap <<
".\n";
1185 std::cout <<
" Global: (" << x <<
", " << y <<
"),\n";
1186 std::cout <<
" Local: (" << t1 <<
", " << t2 <<
", " << t3 <<
", " << t4
1187 <<
") in element " << imap
1188 <<
" (degenerate: " <<
elements[imap].degenerate <<
")\n";
1191 for (
int i = 0; i < 8; i++) {
1192 printf(
" %-5d %12g %12g %12g\n",
elements[imap].emap[i],
1204 if (
fabs(zmax - zmin) <= 0.) {
1206 std::cerr <<
" Zero range is not permitted.\n";
1246 for (
int j = 0; j < np - 1; ++j) {
1247 for (
int k = j + 1; k < np; ++k) {
1249 const double dist =
sqrt(
1256 if (dist < dmin) dmin = dist;
1257 if (dist > dmax) dmax = dist;
DoubleAc pow(const DoubleAc &f, double p)
DoubleAc sqrt(const DoubleAc &f)
DoubleAc fabs(const DoubleAc &f)
bool SetWeightingField(std::string prnsol, std::string label)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)
double GetElementVolume(const int i)
void GetAspectRatio(const int i, double &dmin, double &dmax)
bool Initialise(std::string elist="ELIST.lis", std::string nlist="NLIST.lis", std::string mplist="MPLIST.lis", std::string prnsol="PRNSOL.lis", std::string unit="cm")
Medium * GetMedium(const double &x, const double &y, const double &z)
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string label)
void SetRangeZ(const double zmin, const double zmax)
double WeightingPotential(const double x, const double y, const double z, const std::string label)
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
std::vector< material > materials
void UnmapFields(double &ex, double &ey, double &ez, double &xpos, double &ypos, double &zpos, bool &xmirrored, bool &ymirrored, bool &zmirrored, double &rcoordinate, double &rotation)
void UpdatePeriodicityCommon()
int ReadInteger(char *token, int def, bool &error)
std::vector< element > elements
int FindElement5(const double x, const double y, const double z, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det)
std::vector< node > nodes
void UpdatePeriodicity2d()
std::vector< std::string > wfields