5#define DEFINE_ISLESGLOBAL
20#define XNSegApprox 100
21#define ZNSegApprox 100
27#ifdef _GLIBCXX_HAVE_OBSOLETE_ISINF_ISNAN
40int ExactRecSurf(
double X,
double Y,
double Z,
double xlo,
double zlo,
41 double xhi,
double zhi,
double *Potential,
Vector3D *Flux) {
43 if (
DebugISLES) printf(
"In ExactRecSurf ...\n");
50 if ((fabs(xhi - xlo) < 3.0 *
MINDIST) || (fabs(zhi - zlo) < 3.0 *
MINDIST)) {
51 fprintf(stdout,
"Element size too small! ... returning ...\n");
55 double ar = fabs((zhi - zlo) / (xhi - xlo));
57 fprintf(stdout,
"Element too thin! ... returning ...\n");
65 double dxlo = X - xlo;
66 if (fabs(dxlo) <
MINDIST) dxlo = 0.0;
67 double dxhi = X - xhi;
68 if (fabs(dxhi) <
MINDIST) dxhi = 0.0;
69 double dzlo = Z - zlo;
70 if (fabs(dzlo) <
MINDIST) dzlo = 0.0;
71 double dzhi = Z - zhi;
72 if (fabs(dzhi) <
MINDIST) dzhi = 0.0;
77 double D11 = sqrt(dxlo * dxlo + Y * Y + dzlo * dzlo);
78 if (fabs(D11) <
MINDIST) D11 = 0.0;
79 double D21 = sqrt(dxhi * dxhi + Y * Y + dzlo * dzlo);
80 if (fabs(D21) <
MINDIST) D21 = 0.0;
81 double D12 = sqrt(dxlo * dxlo + Y * Y + dzhi * dzhi);
82 if (fabs(D12) <
MINDIST) D12 = 0.0;
83 double D22 = sqrt(dxhi * dxhi + Y * Y + dzhi * dzhi);
84 if (fabs(D22) <
MINDIST) D22 = 0.0;
89 double modY = fabs(Y);
91 double I1 = dxlo * modY;
92 double I2 = dxhi * modY;
93 double R1 = Y * Y + dzlo * dzlo;
94 double R2 = Y * Y + dzhi * dzhi;
102 fprintf(stdout,
"X: %.16lg, Y: %.16lg, Z: %.16lg\n", X, Y, Z);
103 fprintf(stdout,
"xlo: %.16lg, zlo: %.16lg, xhi: %.16lg, zhi: %.16lg\n", xlo,
105 fprintf(stdout,
"dxlo: %.16lg, dzlo: %.16lg, dxhi: %.16lg, dzhi: %.16lg\n",
106 dxlo, dzlo, dxhi, dzhi);
107 fprintf(stdout,
"D11: %.16lg, D12: %.16lg, D21: %.16lg, D22: %.16lg\n", D11,
109 fprintf(stdout,
"S1: %d, S2: %d, modY: %.16lg\n", S1, S2, modY);
110 fprintf(stdout,
"I1: %.16lg, I2: %.16lg, R1: %.16lg, R2: %.16lg\n", I1, I2,
112 fprintf(stdout,
"MINDIST: %.16lg, MINDIST2: %.16lg, SHIFT: %.16lg\n",
141 if (
DebugISLES) printf(
"fabs(D11) <= MINDIST ... ");
144 if ((X >= xlo) && (Z >= zlo)) {
149 }
else if ((X <= xlo) && (Z >= zlo)) {
154 }
else if ((X >= xlo) && (Z <= zlo)) {
159 }
else if ((X <= xlo) && (Z <= zlo)) {
167 ExactRecSurf(X1, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
176 if (
DebugISLES) printf(
"fabs(D21) <= MINDIST ... ");
179 if ((X >= xhi) && (Z >= zlo)) {
184 }
else if ((X <= xhi) && (Z >= zlo)) {
189 }
else if ((X >= xhi) && (Z <= zlo)) {
194 }
else if ((X <= xhi) && (Z <= zlo)) {
202 ExactRecSurf(X1, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
211 if (
DebugISLES) printf(
"fabs(D12) <= MINDIST ... ");
214 if ((X >= xlo) && (Z >= zhi)) {
219 }
else if ((X <= xlo) && (Z >= zhi)) {
224 }
else if ((X >= xlo) && (Z <= zhi)) {
229 }
else if ((X <= xlo) && (Z <= zhi)) {
237 ExactRecSurf(X1, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
246 if (
DebugISLES) printf(
"fabs(D22) <= MINDIST ... ");
249 if ((X >= xhi) && (Z >= zhi)) {
254 }
else if ((X <= xhi) && (Z >= zhi)) {
259 }
else if ((X >= xhi) && (Z <= zhi)) {
264 }
else if ((X <= xhi) && (Z <= zhi)) {
272 ExactRecSurf(X1, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
287 if (
DebugISLES) printf(
"fabs(dxlo) < MINDIST ... ");
303 ExactRecSurf(X1, Y, Z, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
304 ExactRecSurf(X2, Y, Z, xlo, zlo, xhi, zhi, &Pot2, &Flux2);
305 *Potential = 0.5 * (Pot1 + Pot2);
306 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
307 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
308 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
313 if (
DebugISLES) printf(
"fabs(dzlo) < MINDIST ... ");
329 ExactRecSurf(X, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
330 ExactRecSurf(X, Y, Z2, xlo, zlo, xhi, zhi, &Pot2, &Flux2);
331 *Potential = 0.5 * (Pot1 + Pot2);
332 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
333 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
334 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
339 if (
DebugISLES) printf(
"fabs(dxhi) < MINDIST ... ");
355 ExactRecSurf(X1, Y, Z, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
356 ExactRecSurf(X2, Y, Z, xlo, zlo, xhi, zhi, &Pot2, &Flux2);
357 *Potential = 0.5 * (Pot1 + Pot2);
358 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
359 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
360 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
365 if (
DebugISLES) printf(
"fabs(dzhi) < MINDIST ... ");
381 ExactRecSurf(X, Y, Z1, xlo, zlo, xhi, zhi, &Pot1, &Flux1);
382 ExactRecSurf(X, Y, Z2, xlo, zlo, xhi, zhi, &Pot2, &Flux2);
383 *Potential = 0.5 * (Pot1 + Pot2);
384 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
385 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
386 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
394 double DZTerm1 = log((D11 - dzlo) / (D12 - dzhi));
395 double DZTerm2 = log((D21 - dzlo) / (D22 - dzhi));
396 double DXTerm1 = log((D11 - dxlo) / (D21 - dxhi));
397 double DXTerm2 = log((D12 - dxlo) / (D22 - dxhi));
402 "DZTerm1: %.16lg, DZTerm2: %.16lg, DXTerm1: %.16lg, DXTerm2: %.16lg\n",
403 DZTerm1, DZTerm2, DXTerm1, DXTerm2);
406 if (isnan(DZTerm1) || isinf(DZTerm1)) {
412 fprintf(stdout,
"DZTerm1 problem ... approximating: %d.\n",
ApproxFlag);
416 if (isnan(DZTerm2) || isinf(DZTerm2)) {
422 fprintf(stdout,
"DZTerm2 problem ... approximating: %d.\n",
ApproxFlag);
426 if (isnan(DXTerm1) || isinf(DXTerm1)) {
432 fprintf(stdout,
"DXTerm1 problem ... approximating: %d.\n",
ApproxFlag);
436 if (isnan(DXTerm2) || isinf(DXTerm2)) {
442 fprintf(stdout,
"DXTerm2 problem ... approximating: %d.\n",
ApproxFlag);
459 fprintf(stdout,
"S1-I1 problem ... approximating: %d.\n",
ApproxFlag);
471 fprintf(stdout,
"S1-I2 problem ... approximating: %d.\n",
ApproxFlag);
485 fprintf(stdout,
"S2-I1 problem ... approximating: %d.\n",
ApproxFlag);
497 fprintf(stdout,
"S2-I2 problem ... approximating: %d.\n",
ApproxFlag);
504 double sumTanTerms = 0.;
510 double a = D11 * D11 * dzlo * dzlo;
511 double b = R1 * R1 + I1 * I1;
512 double tmp = -S1 * atan(2 * I1 * D11 * fabs(dzlo) / (a - b));
514 if ((X > xlo && Z > zlo) || (X < xlo && Z < zlo)) {
516 }
else if ((X < xlo && Z > zlo) || (X > xlo && Z < zlo)) {
524 double a = D21 * D21 * dzlo * dzlo;
525 double b = R1 * R1 + I2 * I2;
526 double tmp = -S1 * atan(2 * I2 * D21 * fabs(dzlo) / (a - b));
528 if ((X > xhi && Z > zlo) || (X < xhi && Z < zlo)) {
530 }
else if ((X < xhi && Z > zlo) || (X > xhi && Z < zlo)) {
540 double a = D12 * D12 * dzhi * dzhi;
541 double b = R2 * R2 + I1 * I1;
542 double tmp = -S2 * atan(2 * I1 * D12 * fabs(dzhi) / (a - b));
544 if ((X > xlo && Z > zhi) || (X < xlo && Z < zhi)) {
546 }
else if ((X < xlo && Z > zhi) || (X > xlo && Z < zhi)) {
554 double a = D22 * D22 * dzhi * dzhi;
555 double b = R2 * R2 + I2 * I2;
556 double tmp = -S2 * atan(2 * I2 * D22 * fabs(dzhi) / (a - b));
558 if ((X > xhi && Z > zhi) || (X < xhi && Z < zhi)) {
560 }
else if ((X < xhi && Z > zhi) || (X > xhi && Z < zhi)) {
569 double Pot = -dxlo * DZTerm1 + dxhi * DZTerm2 + modY * sumTanTerms -
570 dzlo * DXTerm1 + dzhi * DXTerm2;
571 double Fx = DZTerm1 - DZTerm2;
572 double Fy = -SY * sumTanTerms;
573 double Fz = DXTerm1 - DXTerm2;
575 printf(
"XTerms: %.16lg, YTerms: %.16lg, ZTerms: %.16lg\n",
576 -dxlo * DZTerm1 + dxhi * DZTerm2, modY * sumTanTerms,
577 -dzlo * DXTerm1 + dzhi * DXTerm2);
578 printf(
"Pot: %lf, Fx: %lf, Fy: %lf, Fz: %lf\n", Pot, Fx, Fy, Fz);
587 Pot -= 2.0 * modY *
ST_PI;
589 Fy += 2.0 * (double)SY *
ST_PI;
594 printf(
"Constants of integration added for potential and Fy.\n");
595 printf(
"Pot: %lf, Fx: %lf, Fy: %lf, Fz: %lf\n", Pot, Fx, Fy, Fz);
600 if ((Pot < 0.0) || (isnan(Pot) || isinf(Pot))) {
601 fprintf(
fIsles,
"\n--- Approximation in ExactRecSurf ---\n");
602 fprintf(
fIsles,
"Negative, nan or inf potential ... approximating!\n");
604 fprintf(stdout,
"\n--- Approximation in ExactRecSurf ---\n");
605 fprintf(stdout,
"Negative, nan or inf potential ... approximating!\n");
607 fprintf(
fIsles,
"X: %.16lg, Y: %.16lg, Z: %.16lg\n", X, Y, Z);
608 fprintf(
fIsles,
"xlo: %.16lg, zlo: %.16lg, xhi: %.16lg, zhi: %.16lg\n", xlo,
610 fprintf(
fIsles,
"dxlo: %.16lg, dzlo: %.16lg, dxhi: %.16lg, dzhi: %.16lg\n",
611 dxlo, dzlo, dxhi, dzhi);
612 fprintf(
fIsles,
"D11: %.16lg, D12: %.16lg, D21: %.16lg, D22: %.16lg\n", D11,
614 fprintf(
fIsles,
"modY: %.16lg\n", modY);
615 fprintf(
fIsles,
"I1: %.16lg, I2: %.16lg, R1: %.16lg, R2: %.16lg\n", I1, I2,
617 fprintf(
fIsles,
"S1: %d, S2: %d\n", S1, S2);
618 fprintf(
fIsles,
"Computed Pot: %.16lg\n", Pot);
626 if (isnan(Fx) || isinf(Fx)) {
627 fprintf(
fIsles,
"\n--- Approximation in ExactRecSurf ---\n");
628 fprintf(
fIsles,
"Nan or inf Fx ... approximating!\n");
630 fprintf(stdout,
"\n--- Approximation in ExactRecSurf ---\n");
631 fprintf(stdout,
"Nan or inf Fx ... approximating!\n");
633 fprintf(
fIsles,
"X: %.16lg, Y: %.16lg, Z: %.16lg\n", X, Y, Z);
634 fprintf(
fIsles,
"xlo: %.16lg, zlo: %.16lg, xhi: %.16lg, zhi: %.16lg\n", xlo,
636 fprintf(
fIsles,
"dxlo: %.16lg, dzlo: %.16lg, dxhi: %.16lg, dzhi: %.16lg\n",
637 dxlo, dzlo, dxhi, dzhi);
638 fprintf(
fIsles,
"D11: %.16lg, D12: %.16lg, D21: %.16lg, D22: %.16lg\n", D11,
640 fprintf(
fIsles,
"Computed Fx: %.16lg\n", Fx);
648 if (isnan(Fy) || isinf(Fy)) {
649 fprintf(
fIsles,
"\n--- Approximation in ExactRecSurf ---\n");
650 fprintf(
fIsles,
"Nan or inf Fy ... approximating!\n");
652 fprintf(stdout,
"\n--- Approximation in ExactRecSurf ---\n");
653 fprintf(stdout,
"Nan or inf Fy ... approximating!\n");
655 fprintf(
fIsles,
"X: %.16lg, Y: %.16lg, Z: %.16lg\n", X, Y, Z);
656 fprintf(
fIsles,
"xlo: %.16lg, zlo: %.16lg, xhi: %.16lg, zhi: %.16lg\n", xlo,
658 fprintf(
fIsles,
"dxlo: %.16lg, dzlo: %.16lg, dxhi: %.16lg, dzhi: %.16lg\n",
659 dxlo, dzlo, dxhi, dzhi);
660 fprintf(
fIsles,
"D11: %.16lg, D12: %.16lg, D21: %.16lg, D22: %.16lg\n", D11,
662 fprintf(
fIsles,
"S1: %d, S2: %d, SY: %d, modY: %.16lg\n", S1, S2, SY, modY);
663 fprintf(
fIsles,
"I1: %.16lg, I2: %.16lg, R1: %.16lg, R2: %.16lg\n", I1, I2,
665 fprintf(
fIsles,
"Computed Fy: %.16lg\n", Fy);
673 if (isnan(Fz) || isinf(Fz)) {
674 fprintf(
fIsles,
"\n--- Approximation in ExactRecSurf ---\n");
675 fprintf(
fIsles,
"Nan or inf Fz ... approximating!\n");
677 fprintf(stdout,
"\n--- Approximation in ExactRecSurf ---\n");
678 fprintf(stdout,
"Nan or inf Fz ... approximating!\n");
680 fprintf(
fIsles,
"X: %.16lg, Y: %.16lg, Z: %.16lg\n", X, Y, Z);
681 fprintf(
fIsles,
"xlo: %.16lg, zlo: %.16lg, xhi: %.16lg, zhi: %.16lg\n", xlo,
683 fprintf(
fIsles,
"dxlo: %.16lg, dzlo: %.16lg, dxhi: %.16lg, dzhi: %.16lg\n",
684 dxlo, dzlo, dxhi, dzhi);
685 fprintf(
fIsles,
"D11: %.16lg, D12: %.16lg, D21: %.16lg, D22: %.16lg\n", D11,
687 fprintf(
fIsles,
"Computed Fz: %.16lg\n", Fz);
701 if (
DebugISLES) printf(
"Going out of ExactRecSurf ...\n");
707 double xhi,
double zhi,
int xseg,
int zseg,
double *Potential,
711 printf(
"In ApproxRecSurf ...\n");
716 double dx = (xhi - xlo) / xseg;
717 double dz = (zhi - zlo) / zseg;
718 double xel = (xhi - xlo) / xseg;
719 double zel = (zhi - zlo) / zseg;
720 double diag = sqrt(dx * dx + dz * dz);
721 double area = xel * zel;
723 double Pot = 0., XFlux = 0., YFlux = 0., ZFlux = 0.;
726 for (
int i = 1; i <= xseg; ++i) {
727 double xi = xlo + (dx / 2.0) + (i - 1) * dx;
728 for (
int k = 1; k <= zseg; ++k) {
729 double zk = zlo + (dz / 2.0) + (k - 1) * dz;
731 double dist = sqrt((X - xi) * (X - xi) + Y * Y + (Z - zk) * (Z - zk));
737 Pot += 2.0 * (xel * log((zel + sqrt(xel * xel + zel * zel)) / xel) +
738 zel * log((xel + sqrt(xel * xel + zel * zel)) / zel));
742 if (
DebugISLES) printf(
"Special Pot: %lg\n", area / diag);
746 double f = area / (dist * dist * dist);
747 XFlux += f * (X - xi);
749 ZFlux += f * (Z - zk);
751 double f = area / (diag * diag * diag);
752 XFlux += f * (X - xi);
754 ZFlux += f * (Z - zk);
756 printf(
"Special XFlux: %lg, YFlux: %lg, ZFlux: %lg\n",
757 f * (X - xi), f * Y, f * (Z - zk));
784int ExactTriSurf(
double zMax,
double X,
double Y,
double Z,
double *Potential,
787 if (
DebugISLES) printf(
"In ExactTriSurf ...\n");
798 fprintf(stdout,
"Element size too small! ... returning ...\n");
803 fprintf(stdout,
"Element too thin! ... returning ...\n");
810 if (fabs(X) <
MINDIST) X = 0.0;
811 if (fabs(Y) <
MINDIST) Y = 0.0;
812 if (fabs(Z) <
MINDIST) Z = 0.0;
813 double modY = fabs(Y);
814 if (modY <
MINDIST) modY = 0.0;
819 double D11 = sqrt(X * X + Y * Y + Z * Z);
821 double D21 = sqrt((X - 1.0) * (X - 1.0) + Y * Y + Z * Z);
823 double D12 = sqrt(X * X + Y * Y + (Z - zMax) * (Z - zMax));
826 double G = zMax * (X - 1.0) + Z;
827 if (fabs(G) <
MINDIST) G = 0.0;
828 double E1 = (X - zMax * (Z - zMax));
829 if (fabs(E1) <
MINDIST) E1 = 0.0;
830 double E2 = (X - 1.0 - zMax * Z);
831 if (fabs(E2) <
MINDIST) E2 = 0.0;
832 double H1 = Y * Y + (Z - zMax) * G;
834 double H2 = Y * Y + Z * G;
836 double R1 = Y * Y + Z * Z;
838 double I1 = modY * X;
840 double I2 = modY * (X - 1.0);
842 double Hypot = sqrt(1.0 + zMax * zMax);
844 fprintf(stdout,
"Hypotenuse too small! ... returning ...\n");
847 double Zhyp = zMax * (1.0 - X);
850 printf(
"\n\nzMax: %.16lg, X: %.16lg, Y: %.16lg, Z: %.16lg\n", zMax, X, Y,
852 printf(
"D11: %.16lg, D21: %.16lg, D12: %.16lg, Hypot: %.16lg\n", D11, D21,
854 printf(
"modY: %.16lg, G: %.16lg\n", modY, G);
855 printf(
"E1: %.16lg, E2: %.16lg, H1: %.16lg, H2: %.16lg\n", E1, E2, H1, H2);
856 printf(
"S1: %d, SY: %d, R1: %.16lg, I1: %.16lg, I2: %.16lg\n", S1, SY, R1,
858 printf(
"H1+G*D12: %.16lg, E1-zMax*D12: %.16lg\n", H1 + G * D12,
860 printf(
"H2+G*D21: %.16lg, E2-zMax*D21: %.16lg\n", H2 + G * D21,
862 printf(
"D11*fabs(Z): %.16lg, D21*fabs(Z): %.16lg\n", D11 * fabs(Z),
864 printf(
"Hypot*D12 - E1: %.16lg\n", Hypot * D12 - E1);
865 printf(
"Hypot*D21 - E2: %.16lg\n\n", Hypot * D21 - E2);
866 fprintf(stdout,
"MINDIST: %.16lg, MINDIST2: %.16lg, SHIFT: %.16lg\n",
897 if ((X >= 0.0) && (Z >= 0.0)) {
902 }
else if ((X <= 0.0) && (Z >= 0.0)) {
907 }
else if ((X >= 0.0) && (Z <= 0.0)) {
912 }
else if ((X <= 0.0) && (Z <= 0.0)) {
931 if ((X >= 1.0) && (Z >= 0.0)) {
936 }
else if ((X <= 1.0) && (Z >= 0.0)) {
942 }
else if ((X >= 1.0) && (Z <= 0.0)) {
947 }
else if ((X <= 1.0) && (Z <= 0.0)) {
966 if ((X >= 0.0) && (Z >= zMax)) {
971 }
else if ((X <= 0.0) && (Z >= zMax)) {
976 }
else if ((X >= 0.0) && (Z <= zMax)) {
982 }
else if ((X <= 0.0) && (Z <= zMax)) {
1000 if (
DebugISLES) printf(
"Y line at (0,0,0) corner\n");
1003 if ((X >= 0.0) && (Z >= 0.0)) {
1008 }
else if ((X <= 0.0) && (Z >= 0.0)) {
1013 }
else if ((X >= 0.0) && (Z <= 0.0)) {
1018 }
else if ((X <= 0.0) && (Z <= 0.0)) {
1035 if (
DebugISLES) printf(
"Y line at (1,0,0) corner\n");
1038 if ((X >= 1.0) && (Z >= 0.0)) {
1043 }
else if ((X <= 1.0) && (Z >= 0.0)) {
1048 }
else if ((X >= 1.0) && (Z <= 0.0)) {
1053 }
else if ((X <= 1.0) && (Z <= 0.0)) {
1070 if (
DebugISLES) printf(
"Y line at (0,0,zMax) corner\n");
1073 if ((X >= 0.0) && (Z >= zMax)) {
1078 }
else if ((X <= 0.0) && (Z >= zMax)) {
1083 }
else if ((X >= 0.0) && (Z <= zMax)) {
1088 }
else if ((X <= 0.0) && (Z <= zMax)) {
1114 if (
DebugISLES) printf(
"edge along X-axis\n");
1115 double X1 = X, X2 = X;
1121 }
else if (X <= 0.0) {
1131 *Potential = 0.5 * (Pot1 + Pot2);
1132 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
1133 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
1134 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
1159 if (fabs(X - 1.0) <
MINDIST) {
1161 if (
DebugISLES) printf(
"edge along X = 1.\n");
1162 double X1 = X, X2 = X;
1168 }
else if (X >= 1.0) {
1178 *Potential = 0.5 * (Pot1 + Pot2);
1179 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
1180 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
1181 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
1184 if (fabs(Z - zMax) <
MINDIST) {
1186 if (
DebugISLES) printf(
"edge along Z = zMax\n");
1187 double Z1 = Z, Z2 = Z;
1193 }
else if (Z <= zMax) {
1203 *Potential = 0.5 * (Pot1 + Pot2);
1204 Flux->
X = 0.5 * (Flux1.
X + Flux2.
X);
1205 Flux->
Y = 0.5 * (Flux1.
Y + Flux2.
Y);
1206 Flux->
Z = 0.5 * (Flux1.
Z + Flux2.
Z);
1209 if (fabs(Z - Zhyp) <
MINDIST) {
1211 if (
DebugISLES) printf(
"edge along Hypotenuse\n");
1212 double X1 = X, Z1 = Z;
1218 }
else if (Z >= Zhyp) {
1241 "(fabs(G) <= MINDIST) && (modY <= MINDIST) ... approximating: %d.\n",
1299 double DblTmp1 = (Hypot * D12 - E1) / (Hypot * D21 - E2);
1301 printf(
"DblTmp1: %.16lg\n", DblTmp1);
1305 double DTerm1 = log(DblTmp1);
1306 if (isnan(DTerm1) || isinf(DTerm1)) {
1316 double DblTmp2 = (D11 - X) / (D21 - X + 1.0);
1318 printf(
"DblTmp2: %.16lg\n", DblTmp2);
1322 double DTerm2 = log(DblTmp2);
1323 if (isnan(DTerm2) || isinf(DTerm2)) {
1333 printf(
"DTerm1: %.16lg, DTerm2: %.16lg\n", DTerm1, DTerm2);
1338 double deltaLog = 0.;
1339 double deltaArg = 0.;
1341 const double s1 = 1. / (X * X + modY * modY);
1342 double Re1 = ((-X) * (H1 + G * D12) + modY * modY * (E1 - zMax * D12)) * s1;
1343 double Im1 = ((-X) * modY * (E1 - zMax * D12) - (H1 + G * D12) * modY) * s1;
1344 const double s2 = 1. / ((1. - X) * (1. - X) + modY * modY);
1345 double Re2 = ((1. - X) * (H2 + G * D21) + modY * modY * (E2 - zMax * D21)) * s2;
1346 double Im2 = ((1. - X) * modY * (E2 - zMax * D21) - (H2 + G * D21) * modY) * s2;
1347 deltaLog = 0.5 * log((Re1 * Re1 + Im1 * Im1) / (Re2 * Re2 + Im2 * Im2));
1348 deltaArg = atan2(Im1, Re1) - atan2(Im2, Re2);
1350 double f1 = fabs((H1 + G * D12) / (-X));
1352 double f2 = fabs((H2 + G * D21) / (1. - X));
1354 deltaLog = log(f1 / f2);
1356 const double c1 = 2. / (G * G + zMax * zMax * modY * modY);
1357 double LTerm1 = c1 * (G * deltaLog - zMax * modY * deltaArg);
1358 double LTerm2 = c1 * (G * deltaArg + zMax * modY * deltaLog);
1360 printf(
"LTerm1: %.16lg, LTerm2: %.16lg\n", LTerm1, LTerm2);
1382 double TanhTerm1 = 0.;
1383 double TanhTerm2 = 0.;
1386 const double f1 = R1 / (D11 * fabs(Z));
1387 const double f2 = R1 / (D21 * fabs(Z));
1388 TanhTerm1 = log1p(f1) - log1p(-f1) - log1p(f2) + log1p(-f2);
1391 if (fabs(R1 - D11 * fabs(Z)) >
MINDIST2 ||
true) {
1392 const double rp = D11 * fabs(Z) + R1;
1393 const double rm = D11 * fabs(Z) - R1;
1394 TanhTerm1 *= (I1 * I1 + rp * rp) / (I1 * I1 + rm * rm);
1396 if (fabs(R1 - D21 * fabs(Z)) >
MINDIST2 ||
true) {
1397 const double rp = D21 * fabs(Z) + R1;
1398 const double rm = D21 * fabs(Z) - R1;
1399 TanhTerm1 *= (I2 * I2 + rm * rm) / (I2 * I2 + rp * rp);
1401 TanhTerm1 = 0.5 * log(TanhTerm1);
1405 double a = D11 * D11 * Z * Z;
1406 double b = R1 * R1 + I1 * I1;
1407 double tmp = atan(2 * I1 * D11 * fabs(Z) / (a - b));
1418 double a = D21 * D21 * Z * Z;
1419 double b = R1 * R1 + I2 * I2;
1420 double tmp = atan(2 * I2 * D21 * fabs(Z) / (a - b));
1433 printf(
"TanhTerm1: %.16lg, TanhTerm2: %.16lg\n", TanhTerm1, TanhTerm2);
1437 double Pot = (zMax * Y * Y - X * G) * LTerm1 -
1438 (zMax * X + G) * modY * LTerm2 +
1439 (S1 * X * TanhTerm1) + S1 * modY * TanhTerm2 +
1440 2. * (G * DTerm1 - Z * DTerm2);
1442 double Fx = G * LTerm1 + zMax * modY * LTerm2 - S1 * TanhTerm1 - 2.0 * zMax * DTerm1;
1444 double Fy = -zMax * Y * LTerm1 + G * SY * LTerm2 - S1 * SY * TanhTerm2;
1447 double Fz = DTerm2 - DTerm1;
1449 printf(
"Pot: %.16lg, Fx: %.16lg, Fy: %.16lg, Fz: %.16lg\n", Pot, Fx, Fy,
1461 if ((X >= 0.0) && (X <= 1.0)) {
1464 if ((Z >= 0.0) && (Z <= Zhyp)) {
1467 Pot -= modY *
ST_PI;
1474 }
else if ((Z <= 0.0) && (Z >= -Zhyp)) {
1477 Pot += modY *
ST_PI;
1484 }
else if (((Z > Zhyp) && (Z <= zMax))) {
1488 Pot -= modY *
ST_PI;
1495 }
else if ((Z < -Zhyp) && (Z >= -zMax)) {
1499 Pot += modY *
ST_PI;
1506 }
else if (Z > zMax) {
1509 Pot -= modY *
ST_PI;
1516 }
else if (Z < -zMax) {
1519 Pot += modY *
ST_PI;
1560 printf(
"After constant addition %d\n", ConstAdd);
1561 printf(
"Pot: %.16lg, Fx: %.16lg, Fy: %.16lg, Fz: %.16lg\n", Pot, Fx, Fy,
1568 if ((Pot < 0) || isnan(Pot) || isinf(Pot)) {
1569 fprintf(
fIsles,
"\n---Approximation in ExactTriSurf---\n");
1570 fprintf(
fIsles,
"Problem with potential ... approximating!\n");
1571 fprintf(
fIsles,
"zMax: %.16lg, X: %.16lg, Y: %.16lg, Z: %.16lg\n", zMax, X, Y,
1573 fprintf(
fIsles,
"D11: %.16lg, D21: %.16lg, D12: %.16lg, Hypot: %.16lg\n", D11,
1575 fprintf(
fIsles,
"modY: %.16lg, G: %.16lg\n", modY, G);
1576 fprintf(
fIsles,
"E1: %.16lg, E2: %.16lg, H1: %.16lg, H2: %.16lg\n", E1, E2,
1578 fprintf(
fIsles,
"S1: %d, R1: %.16lg, I1: %.16lg, I2: %.16lg\n", S1, R1, I1,
1580 fprintf(
fIsles,
"Pot: %.16lg\n", Pot);
1587 if (isnan(Fx) || isinf(Fx)) {
1588 fprintf(
fIsles,
"\n---Approximation in ExactTriSurf---\n");
1589 fprintf(
fIsles,
"Problem with Fx ... approximating!\n");
1590 fprintf(
fIsles,
"zMax: %.16lg, X: %.16lg, Y: %.16lg, Z: %.16lg\n", zMax, X, Y,
1592 fprintf(
fIsles,
"D11: %.16lg, D21: %.16lg, D12: %.16lg, Hypot: %.16lg\n", D11,
1594 fprintf(
fIsles,
"modY: %.16lg, G: %.16lg\n", modY, G);
1595 fprintf(
fIsles,
"E1: %.16lg, E2: %.16lg, H1: %.16lg, H2: %.16lg\n", E1, E2,
1597 fprintf(
fIsles,
"S1: %d, R1: %.16lg, I1: %.16lg, I2: %.16lg\n", S1, R1, I1,
1599 fprintf(
fIsles,
"Fx: %.16lg\n", Fx);
1606 if (isnan(Fy) || isinf(Fy)) {
1607 fprintf(
fIsles,
"\n---Approximation in ExactTriSurf---\n");
1608 fprintf(
fIsles,
"Problem with Fy ... approximating!\n");
1609 fprintf(
fIsles,
"zMax: %.16lg, X: %.16lg, Y: %.16lg, Z: %.16lg\n", zMax, X, Y,
1611 fprintf(
fIsles,
"D11: %.16lg, D21: %.16lg, D12: %.16lg, Hypot: %.16lg\n", D11,
1613 fprintf(
fIsles,
"modY: %.16lg, G: %.16lg\n", modY, G);
1614 fprintf(
fIsles,
"E1: %.16lg, E2: %.16lg, H1: %.16lg, H2: %.16lg\n", E1, E2,
1616 fprintf(
fIsles,
"S1: %d, R1: %.16lg, I1: %.16lg, I2: %.16lg\n", S1, R1, I1,
1618 fprintf(
fIsles,
"Fy: %.16lg\n", Fy);
1625 if (isnan(Fz) || isinf(Fz)) {
1626 fprintf(
fIsles,
"\n---Approximation in ExactTriSurf---\n");
1627 fprintf(
fIsles,
"Problem with Fz ... approximating!\n");
1628 fprintf(
fIsles,
"zMax: %.16lg, X: %.16lg, Y: %.16lg, Z: %.16lg\n", zMax, X, Y,
1630 fprintf(
fIsles,
"D11: %.16lg, D21: %.16lg, D12: %.16lg, Hypot: %.16lg\n", D11,
1632 fprintf(
fIsles,
"modY: %.16lg\n", modY);
1633 fprintf(
fIsles,
"E1: %.16lg, E2: %.16lg\n", E1, E2);
1634 fprintf(
fIsles,
"Fz: %.16lg\n", Fz);
1647 if (
DebugISLES) printf(
"Going out of ExactTriSurf ...\n\n");
1661 int nbzseg,
double *Potential,
Vector3D *Flux) {
1663 if (
DebugISLES) printf(
"In ApproxTriSurf ...\n");
1667 printf(
"zMax: %lg, X: %lg, Y: %lg, Z: %lg\n", zMax, X, Y, Z);
1668 printf(
"nbxseg: %d, nbzseg: %d\n", nbxseg, nbzseg);
1671 double dx = (1.0 - 0.0) / nbxseg;
1672 double dz = (zMax - 0.0) / nbzseg;
1673 double diag = sqrt(dx * dx + dz * dz);
1674 if (
DebugISLES) printf(
"dx: %lg, dz: %lg, diag: %lg\n", dx, dz, diag);
1676 printf(
"sub-element size too small in ApproxTriSurf.\n");
1680 double grad = (zMax - 0.0) / (1.0 - 0.0);
1683 double Pot = 0., XFlux = 0., YFlux = 0., ZFlux = 0.;
1685 for (
int i = 1; i <= nbxseg; ++i) {
1686 double xbgn = (i - 1) * dx;
1687 double zlimit_xbgn = zMax - grad * xbgn;
1688 double xend = i * dx;
1689 double zlimit_xend = zMax - grad * xend;
1691 printf(
"i: %d, xbgn: %lg, zlimit_xbgn: %lg, xend: %lg, zlimit_xend:%lg\n",
1692 i, xbgn, zlimit_xbgn, xend, zlimit_xend);
1694 for (
int k = 1; k <= nbzseg; ++k) {
1695 double zbgn = (k - 1) * dz;
1696 double zend = k * dz;
1697 if (
DebugISLES) printf(
"k: %d, zbgn: %lg, zend: %lg\n", k, zbgn, zend);
1698 int type_subele = 0;
1700 double xi = 0., zk = 0.;
1701 if (zbgn >= zlimit_xbgn) {
1705 }
else if (zend <= zlimit_xend) {
1708 xi = xbgn + 0.5 * dx;
1709 zk = zbgn + 0.5 * dz;
1711 }
else if ((zbgn <= zlimit_xend) && (zend >= zlimit_xend)) {
1715 double a = (zlimit_xend - zbgn);
1716 double b = (zlimit_xbgn - zbgn);
1722 xi = xbgn + (h / 3.0);
1723 zk = zbgn + (b / 3.0);
1727 xi = xbgn + (h * (2. * a + b)) / (3. * (a + b));
1728 zk = zbgn + (a * a + a * b + b * b) / (3. * (a + b));
1729 area = 0.5 * h * (a + b);
1736 if (
DebugISLES) printf(
"type_subele: %d, area: %lg\n", type_subele, area);
1740 double dist = sqrt((X - xi) * (X - xi) + Y * Y + (Z - zk) * (Z - zk));
1744 double f = area / (dist * dist * dist);
1745 XFlux += f * (X - xi);
1747 ZFlux += f * (Z - zk);
1750 if (
DebugISLES) printf(
"Special Pot: %lg\n", area / diag);
1751 double f = area / (diag * diag * diag);
1752 XFlux += f * (X - xi);
1754 ZFlux += f * (Z - zk);
1756 printf(
"Special XFlux: %lg, YFlux: %lg, ZFlux: %lg\n",
1757 f * (X - xi), f * Y, f * (Z - zk));
1781 if (
DebugISLES) printf(
"In ExactCentroidalP_W ...\n");
1782 const double h = 0.5 * lW;
1783 double dtmp1 = hypot(rW, h);
1784 dtmp1 = log((dtmp1 + h) / (dtmp1 - h));
1785 return 2.0 *
ST_PI * dtmp1 * rW;
1790 if (
DebugISLES) printf(
"In ExactAxialP_W ...\n");
1792 const double h = 0.5 * lW;
1793 const double r2 = rW * rW;
1794 const double a = h + Z;
1795 const double b = h - Z;
1796 double Pot = log((a + sqrt(a * a + r2)) * (b + sqrt(b * b + r2)) / r2);
1797 return 2. *
ST_PI * rW * Pot;
1802 if (
DebugISLES) printf(
"In ExactAxialFZ_W ...\n");
1803 double h = 0.5 * lW;
1804 double Fz = 2.0 *
ST_PI *
1805 (sqrt(h * h + 2.0 * Z * h + Z * Z + rW * rW) -
1806 sqrt(h * h - 2.0 * Z * h + Z * Z + rW * rW)) /
1807 sqrt(h * h - 2.0 * Z * h + Z * Z + rW * rW) /
1808 sqrt(h * h + 2.0 * Z * h + Z * Z + rW * rW);
1812double ApproxP_W(
double rW,
double lW,
double X,
double Y,
double Z,
int zseg) {
1814 if (
DebugISLES) printf(
"In ApproxP_W ...\n");
1817 double dz = lW / zseg;
1818 double area = 2.0 *
ST_PI * rW * dz;
1821 double z0 = -0.5 * lW + 0.5 * dz;
1822 for (
int k = 1; k <= zseg; ++k) {
1823 double zk = z0 + (k - 1) * dz;
1824 double dist = sqrt(X * X + Y * Y + (Z - zk) * (Z - zk));
1833double ApproxFX_W(
double rW,
double lW,
double X,
double Y,
double Z,
1835 if (
DebugISLES) printf(
"In ApproxFX_W ...\n");
1838 double dz = lW / zseg;
1839 double area = 2.0 *
ST_PI * rW * dz;
1842 double z0 = -0.5 * lW + 0.5 * dz;
1843 for (
int k = 1; k <= zseg; ++k) {
1844 double zk = z0 + (k - 1) * dz;
1845 double dist = sqrt(X * X + Y * Y + (Z - zk) * (Z - zk));
1846 double dist3 = pow(dist, 3.0);
1848 Fx += (area * X / dist3);
1855double ApproxFY_W(
double rW,
double lW,
double X,
double Y,
double Z,
1857 if (
DebugISLES) printf(
"In ApproxFY_W ...\n");
1860 double dz = lW / zseg;
1861 double area = 2.0 *
ST_PI * rW * dz;
1864 double z0 = -0.5 * lW + 0.5 * dz;
1865 for (
int k = 1; k <= zseg; ++k) {
1866 double zk = z0 + (k - 1) * dz;
1867 double dist = sqrt(X * X + Y * Y + (Z - zk) * (Z - zk));
1868 double dist3 = pow(dist, 3.0);
1870 Fy += (area * X / dist3);
1877double ApproxFZ_W(
double rW,
double lW,
double X,
double Y,
double Z,
1879 if (
DebugISLES) printf(
"In ApproxFZ_W ...\n");
1882 double dz = lW / zseg;
1883 double area = 2.0 *
ST_PI * rW * dz;
1886 double z0 = -0.5 * lW + 0.5 * dz;
1887 for (
int k = 1; k <= zseg; ++k) {
1888 double zk = z0 + (k - 1) * dz;
1889 double dist = sqrt(X * X + Y * Y + (Z - zk) * (Z - zk));
1890 double dist3 = pow(dist, 3.0);
1892 Fz += (area * X / dist3);
1899int ApproxWire(
double rW,
double lW,
double X,
double Y,
double Z,
int zseg,
1900 double *potential,
Vector3D *Flux) {
1901 if (
DebugISLES) printf(
"In ApproxWire ...\n");
1905 double dz = lW / zseg;
1906 double area = 2.0 *
ST_PI * rW * dz;
1908 double Pot = 0., Fx = 0., Fy = 0., Fz = 0.;
1909 double z0 = -0.5 * lW + 0.5 * dz;
1910 for (
int k = 1; k <= zseg; ++k) {
1911 double zk = z0 + (k - 1) * dz;
1912 double dist = sqrt(X * X + Y * Y + (Z - zk) * (Z - zk));
1913 double dist3 = pow(dist, 3.0);
1916 Fx += (area * X / dist3);
1917 Fy += (area * Y / dist3);
1918 Fz += (area * Z / dist3);
1930double ImprovedP_W(
double rW,
double lW,
double X,
double Y,
double Z) {
1933 if (
DebugISLES) printf(
"In ImprovedP_W ...\n");
1935 double dz = 0.5 * lW;
1936 double dtmp1 = (X * X + Y * Y + (Z - dz) * (Z - dz));
1937 dtmp1 = sqrt(dtmp1);
1938 dtmp1 = dtmp1 - (Z - dz);
1939 double dtmp2 = (X * X + Y * Y + (Z + dz) * (Z + dz));
1940 dtmp2 = sqrt(dtmp2);
1941 dtmp2 = dtmp2 - (Z + dz);
1942 double dtmp3 = log(dtmp1 / dtmp2);
1943 return (2.0 *
ST_PI * rW * dtmp3);
1947 if (
DebugISLES) printf(
"In ImprovedFX_W ...\n");
1949 double dist = sqrt(X * X + Y * Y + Z * Z);
1958 double C = (Z) - (lW / 2.0);
1959 double D = (Z) + (lW / 2.0);
1960 double A = sqrt(X * X + Y * Y + C * C);
1961 double B = sqrt(X * X + Y * Y + D * D);
1963 double tmp1 = 2.0 *
ST_PI * rW;
1964 double tmp2 = (X / (A * (B - D))) - ((A - C) * X / (B * (B - D) * (B - D)));
1965 double tmp3 = (B - D) / (A - C);
1966 return (-1.0 * tmp1 * tmp2 * tmp3);
1971 if (
DebugISLES) printf(
"In ImprovedFY_W ...\n");
1973 double dist = sqrt(X * X + Y * Y + Z * Z);
1982 double C = (Z) - (lW / 2.0);
1983 double D = (Z) + (lW / 2.0);
1984 double A = sqrt(X * X + Y * Y + C * C);
1985 double B = sqrt(X * X + Y * Y + D * D);
1987 double tmp1 = 2.0 *
ST_PI * rW;
1988 double tmp2 = (Y / (A * (B - D))) - ((A - C) * Y / (B * (B - D) * (B - D)));
1989 double tmp3 = (B - D) / (A - C);
1990 return (-1.0 * tmp1 * tmp2 * tmp3);
1995 if (
DebugISLES) printf(
"In ImprovedFZ_W ...\n");
1997 double dist = sqrt(X * X + Y * Y + Z * Z);
2003 double C = Z - (lW / 2.0);
2004 double D = Z + (lW / 2.0);
2005 double A = sqrt(X * X + Y * Y + C * C);
2006 double B = sqrt(X * X + Y * Y + D * D);
2008 double tmp1 = 2.0 *
ST_PI * rW;
2009 double tmp2 = (1.0 / B) - (1.0 / A);
2010 return (-1.0 * tmp1 * tmp2);
2013 double C = Z - (lW / 2.0);
2014 double D = Z + (lW / 2.0);
2015 double A = sqrt(X * X + Y * Y + C * C);
2016 double B = sqrt(X * X + Y * Y + D * D);
2018 double tmp1 = 2.0 *
ST_PI * rW;
2019 double tmp2 = (1.0 / B) - (1.0 / A);
2020 return (-1.0 * tmp1 * tmp2);
2025 double *potential,
Vector3D *Flux) {
2026 if (
DebugISLES) printf(
"In ImprovedWire ...\n");
2028 double dz = 0.5 * lW;
2030 double dtmp1 = (X * X + Y * Y + (Z - dz) * (Z - dz));
2031 dtmp1 = sqrt(dtmp1);
2032 dtmp1 = dtmp1 - (Z - dz);
2033 double dtmp2 = (X * X + Y * Y + (Z + dz) * (Z + dz));
2034 dtmp2 = sqrt(dtmp2);
2035 dtmp2 = dtmp2 - (Z + dz);
2036 double dtmp3 = log(dtmp1 / dtmp2);
2037 *potential = 2.0 *
ST_PI * rW * dtmp3;
2039 double dist = sqrt(X * X + Y * Y + Z * Z);
2040 double Fx = 0.0, Fy = 0.0, Fz = 0.0;
2052 double C = Z - (lW / 2.0);
2053 double D = Z + (lW / 2.0);
2054 double A = sqrt(X * X + Y * Y + C * C);
2055 double B = sqrt(X * X + Y * Y + D * D);
2057 double tmp1 = 2.0 *
ST_PI * rW;
2058 double tmp2 = (1.0 / B) - (1.0 / A);
2059 Fz = -1.0 * tmp1 * tmp2;
2062 double C = (Z) - (lW / 2.0);
2063 double D = (Z) + (lW / 2.0);
2064 double A = sqrt(X * X + Y * Y + C * C);
2065 double B = sqrt(X * X + Y * Y + D * D);
2067 double tmp1 = 2.0 *
ST_PI * rW;
2068 double tmp2 = (X / (A * (B - D))) - ((A - C) * X / (B * (B - D) * (B - D)));
2069 double tmp3 = (B - D) / (A - C);
2070 Fx = -1.0 * tmp1 * tmp2 * tmp3;
2072 tmp2 = (Y / (A * (B - D))) - ((A - C) * Y / (B * (B - D) * (B - D)));
2073 Fy = -1.0 * tmp1 * tmp2 * tmp3;
2075 tmp2 = (1.0 / B) - (1.0 / A);
2076 Fz = -1.0 * tmp1 * tmp2;
2090 printf(
"In ExactThinP_W ...\n");
2091 printf(
"rW: %lg, lW: %lg, X: %lg, Y: %lg, Z: %lg\n", rW, lW, X, Y, Z);
2094 const double h = 0.5 * lW;
2095 const double r2 = X * X + Y * Y;
2096 const double a = h + Z;
2097 const double b = h - Z;
2098 double Pot = log((a + sqrt(r2 + a * a)) * (b + sqrt(r2 + b * b)) / r2);
2099 return 2. *
ST_PI * rW * Pot;
2105 printf(
"In ExactThinFX_W ...\n");
2106 printf(
"rW: %lg, lW: %lg, X: %lg, Y: %lg, Z: %lg\n", rW, lW, X, Y, Z);
2109 double h = 0.5 * lW;
2110 double Fx = 2.0 * X *
2111 (sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) * h -
2112 sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) * Z +
2113 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) * h +
2114 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) * Z) /
2115 (X * X + Y * Y) / sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) /
2116 sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) *
ST_PI;
2123 printf(
"In ExactThinFY_W ...\n");
2124 printf(
"rW: %lg, lW: %lg, X: %lg, Y: %lg, Z: %lg\n", rW, lW, X, Y, Z);
2127 double h = 0.5 * lW;
2128 double Fy = 2.0 * Y *
2129 (sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) * h -
2130 sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) * Z +
2131 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) * h +
2132 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) * Z) /
2133 (X * X + Y * Y) / sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) /
2134 sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) *
ST_PI;
2141 printf(
"In ExactThinFZ_W ...\n");
2142 printf(
"rW: %lg, lW: %lg, X: %lg, Y: %lg, Z: %lg\n", rW, lW, X, Y, Z);
2146 double h = 0.5 * lW;
2148 (sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) -
2149 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h)) /
2150 sqrt(X * X + Y * Y + Z * Z - 2.0 * Z * h + h * h) /
2151 sqrt(X * X + Y * Y + Z * Z + h * h + 2.0 * Z * h) *
ST_PI;
2156 double *potential,
Vector3D *Flux) {
2158 printf(
"In ExactThinWire_W ...\n");
2159 printf(
"rW: %lg, lW: %lg, X: %lg, Y: %lg, Z: %lg\n", rW, lW, X, Y, Z);
2161 const double h = 0.5 * lW;
2162 const double r2 = X * X + Y * Y;
2163 const double a = h + Z;
2164 const double b = h - Z;
2165 const double c = sqrt(r2 + a * a);
2166 const double d = sqrt(r2 + b * b);
2167 const double s = 2. *
ST_PI * rW;
2168 *potential = s * log((a + c) * (b + d) / r2);
2169 double f = s * (c * b + d * a) / (r2 * c * d);
2172 Flux->
Z = s * (c - d) / (c * d);
2179 double dist3 = pow(dist, 3.0);
2186 globalF->
X = (FieldPt.
X - SourcePt.
X) / dist3;
2187 globalF->
Y = (FieldPt.
Y - SourcePt.
Y) / dist3;
2188 globalF->
Z = (FieldPt.
Z - SourcePt.
Z) / dist3;
2194 return (1.0 / dist);
2201 double xvert[2], yvert[2], zvert[2];
2202 xvert[0] = LineStart.
X;
2203 xvert[1] = LineStop.
X;
2204 yvert[0] = LineStart.
Y;
2205 yvert[1] = LineStop.
Y;
2206 zvert[0] = LineStart.
Z;
2207 zvert[1] = LineStop.
Z;
2209 double xfld = FieldPt.
X;
2210 double yfld = FieldPt.
Y;
2211 double zfld = FieldPt.
Z;
2213 double xorigin = 0.5 * (xvert[1] + xvert[0]);
2214 double yorigin = 0.5 * (yvert[1] + yvert[0]);
2215 double zorigin = 0.5 * (zvert[1] + zvert[0]);
2229 DirCos.
ZUnit.
X = (xvert[1] - xvert[0]) / LZ;
2230 DirCos.
ZUnit.
Y = (yvert[1] - yvert[0]) / LZ;
2231 DirCos.
ZUnit.
Z = (zvert[1] - zvert[0]) / LZ;
2239 if (fabs(ZUnit.
X) >= fabs(ZUnit.
Z) && fabs(ZUnit.
Y) >= fabs(ZUnit.
Z)) {
2243 }
else if (fabs(ZUnit.
X) >= fabs(ZUnit.
Y) &&
2244 fabs(ZUnit.
Z) >= fabs(ZUnit.
Y)) {
2273 double InitialVector[4];
2274 double TransformationMatrix[4][4] = {{0.0, 0.0, 0.0, 0.0},
2275 {0.0, 0.0, 0.0, 0.0},
2276 {0.0, 0.0, 0.0, 0.0},
2277 {0.0, 0.0, 0.0, 1.0}};
2278 double FinalVector[4];
2280 InitialVector[0] = xfld - xorigin;
2281 InitialVector[1] = yfld - yorigin;
2282 InitialVector[2] = zfld - zorigin;
2283 InitialVector[3] = 1.0;
2285 TransformationMatrix[0][0] = DirCos.
XUnit.
X;
2286 TransformationMatrix[0][1] = DirCos.
XUnit.
Y;
2287 TransformationMatrix[0][2] = DirCos.
XUnit.
Z;
2288 TransformationMatrix[1][0] = DirCos.
YUnit.
X;
2289 TransformationMatrix[1][1] = DirCos.
YUnit.
Y;
2290 TransformationMatrix[1][2] = DirCos.
YUnit.
Z;
2291 TransformationMatrix[2][0] = DirCos.
ZUnit.
X;
2292 TransformationMatrix[2][1] = DirCos.
ZUnit.
Y;
2293 TransformationMatrix[2][2] = DirCos.
ZUnit.
Z;
2295 for (
int i = 0; i < 4; ++i) {
2296 FinalVector[i] = 0.0;
2297 for (
int j = 0; j < 4; ++j) {
2298 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
2302 localPt.
X = FinalVector[0];
2303 localPt.
Y = FinalVector[1];
2304 localPt.
Z = FinalVector[2];
2309 double xpt = localPt.
X;
2310 double ypt = localPt.
Y;
2311 double zpt = localPt.
Z;
2317 double dist = sqrt(xpt * xpt + ypt * ypt + zpt * zpt);
2321 double dA = 2.0 *
ST_PI * rW * lW;
2323 double dist3 = dist * dist * dist;
2324 localF.
X = dA * xpt / dist3;
2325 localF.
Y = dA * ypt / dist3;
2326 localF.
Z = dA * zpt / dist3;
2335 localF.
X = localF.
Y = 0.0;
2354 "Only rectangular areas with known charges allowed at present ...\n");
2358 double xvert[4], yvert[4], zvert[4];
2359 xvert[0] = Vertex[0].
X;
2360 xvert[1] = Vertex[1].
X;
2361 xvert[2] = Vertex[2].
X;
2362 xvert[3] = Vertex[3].
X;
2363 yvert[0] = Vertex[0].
Y;
2364 yvert[1] = Vertex[1].
Y;
2365 yvert[2] = Vertex[2].
Y;
2366 yvert[3] = Vertex[3].
Y;
2367 zvert[0] = Vertex[0].
Z;
2368 zvert[1] = Vertex[1].
Z;
2369 zvert[2] = Vertex[2].
Z;
2370 zvert[3] = Vertex[3].
Z;
2372 double xfld = FieldPt.
X;
2373 double yfld = FieldPt.
Y;
2374 double zfld = FieldPt.
Z;
2376 double xorigin = 0.25 * (xvert[3] + xvert[2] + xvert[1] + xvert[0]);
2377 double yorigin = 0.25 * (yvert[3] + yvert[2] + yvert[1] + yvert[0]);
2378 double zorigin = 0.25 * (zvert[3] + zvert[2] + zvert[1] + zvert[0]);
2381 double SurfLX = sqrt((xvert[1] - xvert[0]) * (xvert[1] - xvert[0]) +
2382 (yvert[1] - yvert[0]) * (yvert[1] - yvert[0]) +
2383 (zvert[1] - zvert[0]) * (zvert[1] - zvert[0]));
2384 double SurfLZ = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
2385 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
2386 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
2402 DirCos.
XUnit.
X = (xvert[1] - xvert[0]) / SurfLX;
2403 DirCos.
XUnit.
Y = (yvert[1] - yvert[0]) / SurfLX;
2404 DirCos.
XUnit.
Z = (zvert[1] - zvert[0]) / SurfLX;
2405 DirCos.
ZUnit.
X = (xvert[0] - xvert[3]) / SurfLZ;
2406 DirCos.
ZUnit.
Y = (yvert[0] - yvert[3]) / SurfLZ;
2407 DirCos.
ZUnit.
Z = (zvert[0] - zvert[3]) / SurfLZ;
2415 double InitialVector[4];
2416 double TransformationMatrix[4][4] = {{0.0, 0.0, 0.0, 0.0},
2417 {0.0, 0.0, 0.0, 0.0},
2418 {0.0, 0.0, 0.0, 0.0},
2419 {0.0, 0.0, 0.0, 1.0}};
2420 double FinalVector[4];
2422 InitialVector[0] = xfld - xorigin;
2423 InitialVector[1] = yfld - yorigin;
2424 InitialVector[2] = zfld - zorigin;
2425 InitialVector[3] = 1.0;
2427 TransformationMatrix[0][0] = DirCos.
XUnit.
X;
2428 TransformationMatrix[0][1] = DirCos.
XUnit.
Y;
2429 TransformationMatrix[0][2] = DirCos.
XUnit.
Z;
2430 TransformationMatrix[1][0] = DirCos.
YUnit.
X;
2431 TransformationMatrix[1][1] = DirCos.
YUnit.
Y;
2432 TransformationMatrix[1][2] = DirCos.
YUnit.
Z;
2433 TransformationMatrix[2][0] = DirCos.
ZUnit.
X;
2434 TransformationMatrix[2][1] = DirCos.
ZUnit.
Y;
2435 TransformationMatrix[2][2] = DirCos.
ZUnit.
Z;
2437 for (
int i = 0; i < 4; ++i) {
2438 FinalVector[i] = 0.0;
2439 for (
int j = 0; j < 4; ++j) {
2440 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
2444 localPt.
X = FinalVector[0];
2445 localPt.
Y = FinalVector[1];
2446 localPt.
Z = FinalVector[2];
2451 double xpt = localPt.
X;
2452 double ypt = localPt.
Y;
2453 double zpt = localPt.
Z;
2457 double diag = sqrt(a * a + b * b);
2460 double dist = sqrt(xpt * xpt + ypt * ypt + zpt * zpt);
2461 double dist3 = dist * dist * dist;
2467 localF.
X = xpt * dA / dist3;
2468 localF.
Y = ypt * dA / dist3;
2469 localF.
Z = zpt * dA / dist3;
2473 ExactRecSurf(xpt / a, ypt / a, zpt / a, -1.0 / 2.0, -(b / a) / 2.0,
2474 1.0 / 2.0, (b / a) / 2.0, &Pot, &localF);
2477 printf(
"problem in computing Potential of rectangular element ... \n");
2478 printf(
"a: %lg, b: %lg, X: %lg, Y: %lg, Z: %lg\n", a, b, xpt, ypt, zpt);
2493 printf(
"VolumeKnChPF not implemented yet ... returning zero flux\n");
2500 printf(
"VolumeKnChPF not implemented yet ... returning 0.0\n");
2510 return (x < 0 ? -1 : 1);
double ApproxFZ_W(double rW, double lW, double X, double Y, double Z, int zseg)
double ApproxP_W(double rW, double lW, double X, double Y, double Z, int zseg)
double ExactThinFX_W(double rW, double lW, double X, double Y, double Z)
int ApproxTriSurf(double zMax, double X, double Y, double Z, int nbxseg, int nbzseg, double *Potential, Vector3D *Flux)
int ApproxWire(double rW, double lW, double X, double Y, double Z, int zseg, double *potential, Vector3D *Flux)
double ExactCentroidalP_W(double rW, double lW)
double ApproxFX_W(double rW, double lW, double X, double Y, double Z, int zseg)
double ExactThinFY_W(double rW, double lW, double X, double Y, double Z)
double ImprovedFZ_W(double rW, double lW, double X, double Y, double Z)
double ExactAxialP_W(double rW, double lW, double Z)
double ExactAxialFZ_W(double rW, double lW, double Z)
double ApproxFY_W(double rW, double lW, double X, double Y, double Z, int zseg)
int ExactThinWire(double rW, double lW, double X, double Y, double Z, double *potential, Vector3D *Flux)
double ImprovedFY_W(double rW, double lW, double X, double Y, double Z)
double ExactThinFZ_W(double rW, double lW, double X, double Y, double Z)
double LineKnChPF(Point3D LineStart, Point3D LineStop, double radius, Point3D FieldPt, Vector3D *globalF)
int ExactRecSurf(double X, double Y, double Z, double xlo, double zlo, double xhi, double zhi, double *Potential, Vector3D *Flux)
int ExactTriSurf(double zMax, double X, double Y, double Z, double *Potential, Vector3D *Flux)
double ExactThinP_W(double rW, double lW, double X, double Y, double Z)
double ImprovedFX_W(double rW, double lW, double X, double Y, double Z)
int ImprovedWire(double rW, double lW, double X, double Y, double Z, double *potential, Vector3D *Flux)
int ApproxRecSurf(double X, double Y, double Z, double xlo, double zlo, double xhi, double zhi, int xseg, int zseg, double *Potential, Vector3D *Flux)
double AreaKnChPF(int NbVertices, Point3D *Vertex, Point3D FieldPt, Vector3D *globalF)
double PointKnChPF(Point3D SourcePt, Point3D FieldPt, Vector3D *globalF)
double VolumeKnChPF(int, Point3D *, Point3D, Vector3D *globalF)
double ImprovedP_W(double rW, double lW, double X, double Y, double Z)
ISLESGLOBAL int ApproxCntr
ISLESGLOBAL int IslesCntr
ISLESGLOBAL FILE * fIsles
ISLESGLOBAL int FailureCntr
ISLESGLOBAL int ApproxFlag
ISLESGLOBAL int DebugISLES
ISLESGLOBAL int ExactCntr
Vector3D RotateVector3D(Vector3D *A, DirnCosn3D *DC, int Sense)
double GetDistancePoint3D(Point3D *a, Point3D *b)
Vector3D UnitVector3D(Vector3D *v)
Vector3D Vector3DCrossProduct(Vector3D *A, Vector3D *B)
neBEMGLOBAL int * NbVertices