12#define DEFINE_INTFACEGLOBAL
13#define DEFINE_neBEMGLOBAL
14#define DEFINE_NRGLOBAL
44 printf(
"Using neBEM version %s and ISLES version %s\n",
neBEMVersion,
69 neBEMMessage(
"neBEMInitialize - neBEMGetInputFromFiles");
87 strcat(IslesFile,
"/Isles.log");
88 fIsles = fopen(IslesFile,
"w");
100 FILE *processFile = fopen(
"neBEMProcess.inp",
"r");
101 if (processFile == NULL) {
102 printf(
"neBEMProcess.inp absent ... assuming defaults ...\n");
106 fscanf(processFile,
"PrimAfter: %d\n", &
PrimAfter);
107 fscanf(processFile,
"RqstdThreads: %d\n", &RqstdThreads);
112 int MaxProcessors = omp_get_num_procs();
113 if (RqstdThreads > 1) {
114 if (RqstdThreads < MaxProcessors) {
116 omp_set_num_threads(RqstdThreads);
118 printf(
"RqstdThreads: %d\n", RqstdThreads);
119 RqstdThreads = MaxProcessors - 1;
120 omp_set_num_threads(RqstdThreads);
121 printf(
"Adjusted RqstdThreads: %d\n", RqstdThreads);
126 omp_set_num_threads(RqstdThreads);
127 printf(
"RqstdThreads: %d => No Multi-threading ...\n", RqstdThreads);
132 printf(
"RqstdThreads: %d, MaxProcessors: %d\n", RqstdThreads, MaxProcessors);
133 printf(
"Maximum number of threads to be used for parallelization: %d\n",
134 omp_get_max_threads());
135 printf(
"Number of threads used for neBEMInitialize: %d\n", omp_get_num_threads());
138 FILE *voxelInpFile = fopen(
"neBEMVoxel.inp",
"r");
139 if (voxelInpFile == NULL) {
140 printf(
"neBEMVoxel.inp absent ... assuming OptVoxel = 0 ...\n");
144 fscanf(voxelInpFile,
"OptVoxel: %d\n", &
OptVoxel);
146 fscanf(voxelInpFile,
"Xmin: %le\n", &
Voxel.
Xmin);
147 fscanf(voxelInpFile,
"Xmax: %le\n", &
Voxel.
Xmax);
148 fscanf(voxelInpFile,
"Ymin: %le\n", &
Voxel.
Ymin);
149 fscanf(voxelInpFile,
"Ymax: %le\n", &
Voxel.
Ymax);
150 fscanf(voxelInpFile,
"Zmin: %le\n", &
Voxel.
Zmin);
151 fscanf(voxelInpFile,
"Zmax: %le\n", &
Voxel.
Zmax);
158 fclose(voxelInpFile);
162 FILE *mapInpFile = fopen(
"neBEMMap.inp",
"r");
163 if (mapInpFile == NULL) {
164 printf(
"neBEMMap.inp absent ... assuming OptMap = 0 ...\n");
170 fscanf(mapInpFile,
"OptMap: %d\n", &
OptMap);
172 fscanf(mapInpFile,
"MapVersion: %9s\n",
MapVersion);
173 fscanf(mapInpFile,
"Xmin: %le\n", &
Map.
Xmin);
174 fscanf(mapInpFile,
"Xmax: %le\n", &
Map.
Xmax);
175 fscanf(mapInpFile,
"Ymin: %le\n", &
Map.
Ymin);
176 fscanf(mapInpFile,
"Ymax: %le\n", &
Map.
Ymax);
177 fscanf(mapInpFile,
"Zmin: %le\n", &
Map.
Zmin);
178 fscanf(mapInpFile,
"Zmax: %le\n", &
Map.
Zmax);
179 fscanf(mapInpFile,
"XStagger: %le\n", &
Map.
XStagger);
180 fscanf(mapInpFile,
"YStagger: %le\n", &
Map.
YStagger);
181 fscanf(mapInpFile,
"ZStagger: %le\n", &
Map.
ZStagger);
182 fscanf(mapInpFile,
"NbOfXCells: %d\n", &
Map.
NbXCells);
183 fscanf(mapInpFile,
"NbOfYCells: %d\n", &
Map.
NbYCells);
184 fscanf(mapInpFile,
"NbOfZCells: %d\n", &
Map.
NbZCells);
189 FILE *fastInpFile = fopen(
"neBEMFastVol.inp",
"r");
190 if (fastInpFile == NULL) {
191 printf(
"neBEMFastVol.inp absent ... assuming OptFastVol = 0 ...\n");
200 fscanf(fastInpFile,
"OptFastVol: %d\n", &
OptFastVol);
204 fscanf(fastInpFile,
"NbPtSkip: %d\n", &
NbPtSkip);
205 fscanf(fastInpFile,
"NbStgPtSkip: %d\n", &
NbStgPtSkip);
206 fscanf(fastInpFile,
"LX: %le\n", &
FastVol.
LX);
207 fscanf(fastInpFile,
"LY: %le\n", &
FastVol.
LY);
208 fscanf(fastInpFile,
"LZ: %le\n", &
FastVol.
LZ);
222 fscanf(fastInpFile,
"NbOfXCells: %d\n", &
BlkNbXCells[block]);
223 fscanf(fastInpFile,
"NbOfYCells: %d\n", &
BlkNbYCells[block]);
224 fscanf(fastInpFile,
"NbOfZCells: %d\n", &
BlkNbZCells[block]);
225 fscanf(fastInpFile,
"LZ: %le\n", &
BlkLZ[block]);
226 fscanf(fastInpFile,
"CornerZ: %le\n", &
BlkCrnrZ[block]);
237 fscanf(fastInpFile,
"OmitVolLX: %le\n", &
OmitVolLX[omit]);
238 fscanf(fastInpFile,
"OmitVolLY: %le\n", &
OmitVolLY[omit]);
239 fscanf(fastInpFile,
"OmitVolLZ: %le\n", &
OmitVolLZ[omit]);
240 fscanf(fastInpFile,
"OmitVolCornerX: %le\n", &
OmitVolCrnrX[omit]);
241 fscanf(fastInpFile,
"OmitVolCornerY: %le\n", &
OmitVolCrnrY[omit]);
242 fscanf(fastInpFile,
"OmitVolCornerZ: %le\n", &
OmitVolCrnrZ[omit]);
254 fscanf(fastInpFile,
"IgnoreVolLX: %le\n", &
IgnoreVolLX[ignore]);
255 fscanf(fastInpFile,
"IgnoreVolLY: %le\n", &
IgnoreVolLY[ignore]);
256 fscanf(fastInpFile,
"IgnoreVolLZ: %le\n", &
IgnoreVolLZ[ignore]);
257 fscanf(fastInpFile,
"IgnoreVolCornerX: %le\n", &
IgnoreVolCrnrX[ignore]);
258 fscanf(fastInpFile,
"IgnoreVolCornerY: %le\n", &
IgnoreVolCrnrY[ignore]);
259 fscanf(fastInpFile,
"IgnoreVolCornerZ: %le\n", &
IgnoreVolCrnrZ[ignore]);
274 FILE *fixedWtInpFile = fopen(
"neBEMFixedWtField.inp",
"r");
275 if (fixedWtInpFile == NULL) {
277 "neBEMFixedWtField.inp absent ... assuming OptFixedWtField = 0 ...\n");
286 fscanf(fixedWtInpFile,
"FixedWtFieldX: %lg\n", &
FixedWtFieldX);
287 fscanf(fixedWtInpFile,
"FixedWtFieldY: %lg\n", &
FixedWtFieldY);
288 fscanf(fixedWtInpFile,
"FixedWtFieldZ: %lg\n", &
FixedWtFieldZ);
289 fclose(fixedWtInpFile);
293 FILE *fastWtFldInpFile = fopen(
"neBEMWtFldFastVol.inp",
"r");
294 if (fastWtFldInpFile == NULL) {
296 "neBEMWtFldFastVol.inp absent ... assuming OptWtFldFastVol = 0 ...\n");
306 fscanf(fastWtFldInpFile,
"OptStaggerFastVol: %d\n",
331 fscanf(fastWtFldInpFile,
"LZ: %le\n", &
WtFldBlkLZ[block]);
332 fscanf(fastWtFldInpFile,
"CornerZ: %le\n", &
WtFldBlkCrnrZ[block]);
343 fscanf(fastWtFldInpFile,
"OmitVolLX: %le\n", &
WtFldOmitVolLX[omit]);
344 fscanf(fastWtFldInpFile,
"OmitVolLY: %le\n", &
WtFldOmitVolLY[omit]);
345 fscanf(fastWtFldInpFile,
"OmitVolLZ: %le\n", &
WtFldOmitVolLZ[omit]);
346 fscanf(fastWtFldInpFile,
"OmitVolCornerX: %le\n",
348 fscanf(fastWtFldInpFile,
"OmitVolCornerY: %le\n",
350 fscanf(fastWtFldInpFile,
"OmitVolCornerZ: %le\n",
354 fscanf(fastWtFldInpFile,
"NbOfIgnoreVols: %d\n",
364 fscanf(fastWtFldInpFile,
"IgnoreVolLX: %le\n",
366 fscanf(fastWtFldInpFile,
"IgnoreVolLY: %le\n",
368 fscanf(fastWtFldInpFile,
"IgnoreVolLZ: %le\n",
370 fscanf(fastWtFldInpFile,
"IgnoreVolCornerX: %le\n",
372 fscanf(fastWtFldInpFile,
"IgnoreVolCornerY: %le\n",
374 fscanf(fastWtFldInpFile,
"IgnoreVolCornerZ: %le\n",
386 fclose(fastWtFldInpFile);
389 printf(
"neBEM initialized ...\n");
416 neBEMMessage(
"neBEMReadGeometry - problem reading stored Primitives.\n");
423 printf(
"geometry inputs ...\n");
425 printf(
"reading geometry possible only after initialization ...\n");
516 int nvertex, volref1, volref2, volmax = 0;
524 double xnorm, ynorm, znorm;
528 xvert.data(), yvert.data(), zvert.data(),
529 &xnorm, &ynorm, &znorm, &volref1, &volref2);
532 &xnorm, &ynorm, &znorm, &volref1, &volref2);
538 if (volmax < volref1) {
541 if (volmax < volref2) {
546 printf(
"Number of vertices for primitive %d exceeds %d!\n", prim,
548 printf(
"Returning to garfield ...\n");
554 for (
int vert = 0; vert <
NbVertices[prim]; ++vert) {
555 XVertex[prim][vert] = xvert[vert];
556 YVertex[prim][vert] = yvert[vert];
557 ZVertex[prim][vert] = zvert[vert];
577 printf(
"neBEM:\tprimitive %d between volumes %d, %d has %d vertices\n",
578 prim, volref1, volref2, nvertex);
579 for (
int ivertex = 0; ivertex < nvertex; ivertex++) {
580 printf(
"\tnode %d (%g,%g,%g)\n", ivertex, xvert[ivertex],
581 yvert[ivertex], zvert[ivertex]);
583 printf(
"\tnormal vector: (%g,%g,%g)\n", xnorm, ynorm, znorm);
594 int shape1, material1, boundarytype1;
595 double epsilon1, potential1, charge1;
602 &potential1, &charge1, &boundarytype1);
605 printf(
"\tvolref1: %d\n", volref1);
606 printf(
"\t\tboundarytype1: %d, shape1: %d, material1: %d\n",
607 boundarytype1, shape1, material1);
608 printf(
"\t\tepsilon1: %lg, potential1: %lg, charge1: %lg\n", epsilon1,
609 potential1, charge1);
612 int shape2, material2, boundarytype2;
613 double epsilon2, potential2, charge2;
623 &potential2, &charge2, &boundarytype2);
626 printf(
"\tvolref2: %d\n", volref2);
627 printf(
"\t\tboundarytype2: %d, shape2: %d, material2: %d\n",
628 boundarytype2, shape2, material2);
629 printf(
"\t\tepsilon2: %lg, potential2: %lg, charge2: %lg\n", epsilon2,
630 potential2, charge2);
670 switch (boundarytype1) {
672 if (boundarytype2 == 0 || boundarytype2 == 4) {
676 }
else if (boundarytype2 == 1) {
678 if (fabs(potential1 - potential2)
679 < 1e-6 * (1 + fabs(potential1) + fabs(potential2))) {
680 printf(
"neBEMReadGeometry: identical potentials; skipped.\n");
681 printf(
"Primitive skipped: #%d\n", prim);
685 printf(
"neBEMReadGeometry: different potentials; rejected.\n");
691 "neBEMReadGeometry: conductor at given potential; rejected.\n");
697 if ((boundarytype2 == 0) || (boundarytype2 == 4)) {
702 printf(
"neBEMReadGeometry: charged conductor; rejected.\n");
708 if ((boundarytype2 == 0) || (boundarytype2 == 4)) {
714 printf(
"neBEMReadGeometry: floating conductor; rejected.\n");
720 if (boundarytype2 == 0) {
725 Lambda[prim] = (epsilon1 - epsilon2) / (epsilon1 + epsilon2);
727 }
else if (boundarytype2 == 1) {
731 }
else if (boundarytype2 == 2) {
735 }
else if (boundarytype2 == 3) {
738 }
else if (boundarytype2 == 4) {
740 if (fabs(epsilon1 - epsilon2) < 1e-6 * (1 + fabs(epsilon1) + fabs(epsilon2))) {
743 "neBEMReadGeometry: between identical dielectrica; skipd.\n");
744 printf(
"Primitive skipped: #%d\n", prim);
751 Lambda[prim] = (epsilon1 - epsilon2) / (epsilon1 + epsilon2);
754 }
else if (boundarytype2 == 5) {
756 if (fabs(epsilon1 - epsilon2)
757 < 1e-6 * (1 + fabs(epsilon1) + fabs(epsilon2))) {
759 "neBEMReadGeometry: between identical dielectrica; skipped.\n");
760 printf(
"Primitive skipped: #%d\n", prim);
766 Lambda[prim] = (epsilon1 - epsilon2) / (epsilon1 + epsilon2);
770 printf(
"neBEMReadGeometry: unknown dielectric; rejected.\n");
776 if (boundarytype2 == 0) {
779 Lambda[prim] = (epsilon1 - epsilon2) / (epsilon1 + epsilon2);
781 }
else if (boundarytype2 == 4) {
782 if (fabs(epsilon1 - epsilon2) < 1e-6 * (1 + fabs(epsilon1) + fabs(epsilon2))) {
785 "neBEMReadGeometry: between identical dielectrica; skipd.\n");
786 printf(
"Primitive skipped: #%d\n", prim);
792 Lambda[prim] = (epsilon1 - epsilon2) / (epsilon1 + epsilon2);
798 "neBEMReadGeometry: charged dielectric adjacent to a conductor; "
805 if (boundarytype2 == 0) {
808 printf(
"neBEMReadGeometry: E-parallel symmetry; rejected.\n");
814 if (boundarytype2 == 0) {
817 printf(
"neBEMReadGeometry: E-perpendicular symmetry; rejected.\n");
823 printf(
"neBEMReadGeometry: Boundary type 1: %d\n", boundarytype1);
824 printf(
"neBEMReadGeometry: Boundary type 2: %d\n", boundarytype2);
825 printf(
"neBEMReadGeometry: out of range ... exiting.\n");
831 "\tType: %d, ApplPot: %lg, Epsilon1: %lg, Epsilon2: %lg, Lambda: "
832 "%lg, ApplCh: %lg\n",
852 neBEMMessage(
"neBEMReadGeometry - neBEMGetPeriodicities");
863 printf(
"For primitive: %d\n", prim);
864 printf(
"\tPeriodicTypeX: %d, PeriodicTypeY: %d, PeriodicTypeZ: %d\n",
866 printf(
"\tPeriodicInX: %d, PeriodicInY: %d, PeriodicInZ: %d\n", jx, jy,
868 printf(
"\tXPeriod: %lg, YPeriod: %lg, ZPeriod: %lg\n", sx, sy, sz);
906 neBEMGetMirror(prim, &ix, &jx, &sx, &iy, &jy, &sy, &iz, &jz, &sz);
919 printf(
"For primitive: %d\n", prim);
920 printf(
"\tMirrorTypeX: %d, MirrorTypeY: %d, MirrorTypeZ: %d\n", ix, iy,
922 printf(
"\tNOT USED ==> MirrorInX: %d, MirrorInY: %d, MirrorInZ: %d\n",
924 printf(
"\tMirrorDistX: %lg, MirrorDistY: %lg, MirrorDistZ: %lg\n", sx,
954 int ixmin, ixmax, iymin, iymax, izmin, izmax;
955 double cxmin, cxmax, cymin, cymax, czmin, czmax;
956 double vxmin, vxmax, vymin, vymax, vzmin, vzmax;
958 &ixmin, &cxmin, &vxmin, &ixmax, &cxmax, &vxmax, &iymin, &cymin, &vymin,
959 &iymax, &cymax, &vymax, &izmin, &czmin, &vzmin, &izmax, &czmax, &vzmax);
961 neBEMMessage(
"neBEMReadGeometry - neBEMGetBoundingPlanes");
1022 for (
int volref = 0; volref <=
VolMax; ++volref) {
1027 printf(
"volref: %d\n", volref);
1028 printf(
"shape: %d, material: %d\n",
volShape[volref],
1048 int NbSkipped = 0, effprim;
1049 double DVertex[4], minDVertex = 0.0;
1051 effprim = prim - NbSkipped;
1054 for (
int vert = 0; vert <
NbVertices[prim] - 1; ++vert) {
1063 minDVertex = DVertex[vert];
1065 if (DVertex[vert] < minDVertex) minDVertex = DVertex[vert];
1074 for (
int vert = 0; vert <
NbVertices[effprim]; ++vert) {
1081 XNorm[effprim] = 0.0;
1082 YNorm[effprim] = 0.0;
1083 ZNorm[effprim] = 0.0;
1140 printf(
"Skipped primitive %d, InterfaceType: %d, minDVertex: %lg\n",
1146 printf(
"Number of primitives skipped: %d, Effective NbPrimitives: %d\n",
1522 FILE *rmprimFile = fopen(
"neBEMRmPrim.inp",
"r");
1523 if (rmprimFile == NULL) {
1524 printf(
"neBEMRmPrim.inp absent ... assuming defaults ...\n");
1527 fscanf(rmprimFile,
"NbRmPrims: %d\n", &NbRmPrims);
1531 std::vector<double> rmXNorm(NbRmPrims + 1, 0.);
1532 std::vector<double> rmYNorm(NbRmPrims + 1, 0.);
1533 std::vector<double> rmZNorm(NbRmPrims + 1, 0.);
1534 std::vector<double> rmXVert(NbRmPrims + 1, 0.);
1535 std::vector<double> rmYVert(NbRmPrims + 1, 0.);
1536 std::vector<double> rmZVert(NbRmPrims + 1, 0.);
1538 double rmXNorm[NbRmPrims + 1], rmYNorm[NbRmPrims + 1];
1539 double rmZNorm[NbRmPrims + 1];
1540 double rmXVert[NbRmPrims + 1], rmYVert[NbRmPrims + 1];
1541 double rmZVert[NbRmPrims + 1];
1543 for (
int rmprim = 1; rmprim <= NbRmPrims; ++rmprim) {
1544 fscanf(rmprimFile,
"Prim: %d\n", &tint);
1545 fscanf(rmprimFile,
"rmXNorm: %le\n", &rmXNorm[rmprim]);
1546 fscanf(rmprimFile,
"rmYNorm: %le\n", &rmYNorm[rmprim]);
1547 fscanf(rmprimFile,
"rmZNorm: %le\n", &rmZNorm[rmprim]);
1548 fscanf(rmprimFile,
"rmXVert: %le\n", &rmXVert[rmprim]);
1549 fscanf(rmprimFile,
"rmYVert: %le\n", &rmYVert[rmprim]);
1550 fscanf(rmprimFile,
"rmZVert: %le\n", &rmZVert[rmprim]);
1552 "rmprim: %d, rmXNorm: %lg, rmYNorm: %lg, rmZNorm: %lg, "
1553 "rmXVert: %lg, rmYVert: %lg, rmZVert: %lg\n",
1554 rmprim, rmXNorm[rmprim], rmYNorm[rmprim], rmZNorm[rmprim],
1555 rmXVert[rmprim], rmYVert[rmprim], rmZVert[rmprim]);
1566 printf(
"\n\nprim: %d, XVertex: %lg, YVertex: %lg, ZVertex: %lg\n",
1569 printf(
"XNorm: %lg, YNorm: %lg, ZNorm: %lg\n",
XNorm[prim],
1573 for (
int rmprim = 1; rmprim <= NbRmPrims; ++rmprim) {
1576 "rmprim: %d, rmXVertex: %lg, rmYVertex: %lg, rmZVertex: "
1578 rmprim, rmXVert[rmprim], rmYVert[rmprim], rmZVert[rmprim]);
1579 printf(
"rmXNorm: %lg, rmYNorm: %lg, rmZNorm: %lg\n",
1580 rmXNorm[rmprim], rmYNorm[rmprim], rmZNorm[rmprim]);
1584 if ((fabs(fabs(
XNorm[prim]) - fabs(rmXNorm[rmprim])) <=
1586 (fabs(fabs(
YNorm[prim]) - fabs(rmYNorm[rmprim])) <=
1588 (fabs(fabs(
ZNorm[prim]) - fabs(rmZNorm[rmprim])) <=
1596 if (fabs(fabs(
XNorm[prim]) - 1.0) <= 1.0e-12) {
1602 if (fabs(fabs(
YNorm[prim]) - 1.0) <= 1.0e-12) {
1608 if (fabs(fabs(
ZNorm[prim]) - 1.0) <= 1.0e-12) {
1616 printf(
"prim: %d, rmprim: %d, remove: %d\n", prim, rmprim,
1619 if (remove[prim] == 1)
1626 FILE *fprrm = fopen(
"RmPrims.info",
"w");
1627 if (fprrm == NULL) {
1629 "error opening RmPrims.info file in write mode ... "
1643 orgnlNb = orgnlprim;
1648 if (remove[prim] == 1) {
1651 fprintf(fprrm,
"NbRemoved: %d, Removed primitive: %d\n",
1653 fprintf(fprrm,
"PrimType: %d\n",
PrimType[prim]);
1654 fprintf(fprrm,
"NbVertices: %d\n",
NbVertices[prim]);
1655 for (
int vert = 0; vert <
NbVertices[prim]; ++vert) {
1656 fprintf(fprrm,
"Vertx %d: %lg, %lg, %lg\n", vert,
1660 fprintf(fprrm,
"Normals: %lg, %lg, %lg\n",
XNorm[prim],
1665 int effprim = prim - NbRemoved;
1670 for (
int vert = 0; vert <
NbVertices[effprim]; ++vert) {
1677 XNorm[effprim] = 0.0;
1678 YNorm[effprim] = 0.0;
1679 ZNorm[effprim] = 0.0;
1737 "Number of primitives removed: %d, Effective NbPrimitives: %d\n",
1745 FILE *fignore = fopen(
"IgnorePrims.info",
"w");
1746 if (fignore == NULL) {
1748 "error opening IgnorePrims.info file in write mode ... returning\n");
1761 printf(
"ROM: switch to primitive representation after %d repetitions.\n",
1765 char NativeInFile[256];
1768 strcat(NativeInFile,
"/neBEMNative.inp");
1769 FILE *fNativeInFile = fopen(NativeInFile,
"w");
1770 fprintf(fNativeInFile,
"#====>Input directory\n");
1772 fprintf(fNativeInFile,
"#====>No. of primitives:\n");
1774 fprintf(fNativeInFile,
"#====>No. of volumes:\n");
1775 fprintf(fNativeInFile,
"%d\n",
VolMax);
1777 char NativePrimFile[256];
1779 sprintf(strPrimNb,
"%d", prim);
1780 strcpy(NativePrimFile,
"Primitive");
1781 strcat(NativePrimFile, strPrimNb);
1782 strcat(NativePrimFile,
".inp");
1784 fprintf(fNativeInFile,
"#Input filename for primitive:\n");
1785 fprintf(fNativeInFile,
"%s\n", NativePrimFile);
1788 strcat(NativePrimFile,
"/Primitive");
1789 strcat(NativePrimFile, strPrimNb);
1790 strcat(NativePrimFile,
".inp");
1792 FILE *fNativePrim = fopen(NativePrimFile,
"w");
1794 fprintf(fNativePrim,
"#Number of vertices:\n");
1795 fprintf(fNativePrim,
"%d\n",
NbVertices[prim]);
1796 for (
int vertex = 0; vertex <
NbVertices[prim]; ++vertex) {
1797 fprintf(fNativePrim,
"#Vertex %d:\n", vertex);
1798 fprintf(fNativePrim,
"%lg %lg %lg\n",
XVertex[prim][vertex],
1801 fprintf(fNativePrim,
"#Outward normal:\n");
1802 fprintf(fNativePrim,
"%lg %lg %lg\n",
XNorm[prim],
YNorm[prim],
1804 fprintf(fNativePrim,
"#Volume references:\n");
1806 fprintf(fNativePrim,
"#Maximum number of segments:\n");
1807 fprintf(fNativePrim,
"%d %d\n", 0, 0);
1808 fprintf(fNativePrim,
"#Information on X periodicity:\n");
1811 fprintf(fNativePrim,
"#Information on Y periodicity:\n");
1814 fprintf(fNativePrim,
"#Information on Z periodicity:\n");
1818 fclose(fNativePrim);
1821 fprintf(fNativeInFile,
"#====>No. of boundary conditions per element:\n");
1822 fprintf(fNativeInFile,
"%d\n", 1);
1823 fprintf(fNativeInFile,
"#====>Device output directory name:\n");
1824 fprintf(fNativeInFile,
"NativeResults\n");
1825 fprintf(fNativeInFile,
"#====>Map input file:\n");
1826 fprintf(fNativeInFile,
"MapFile.inp\n");
1827 fclose(fNativeInFile);
1829 for (
int volume = 0; volume <=
VolMax; ++volume) {
1832 int shape, material, boundarytype;
1833 double epsilon, potential, charge;
1835 &charge, &boundarytype);
1837 char NativeVolFile[256];
1839 sprintf(strVolNb,
"%d", volume);
1842 strcat(NativeVolFile,
"/Volume");
1843 strcat(NativeVolFile, strVolNb);
1844 strcat(NativeVolFile,
".inp");
1846 FILE *fNativeVol = fopen(NativeVolFile,
"w");
1848 fprintf(fNativeVol,
"#Shape of the volume:\n");
1849 fprintf(fNativeVol,
"%d\n", shape);
1850 fprintf(fNativeVol,
"#Material of the volume:\n");
1851 fprintf(fNativeVol,
"%d\n", material);
1852 fprintf(fNativeVol,
"#Relative permittivity:\n");
1853 fprintf(fNativeVol,
"%lg\n", epsilon);
1854 fprintf(fNativeVol,
"#Potential:\n");
1855 fprintf(fNativeVol,
"%lg\n", potential);
1856 fprintf(fNativeVol,
"#Charge:\n");
1857 fprintf(fNativeVol,
"%lg\n", charge);
1858 fprintf(fNativeVol,
"#Boundary type:\n");
1859 fprintf(fNativeVol,
"%d\n", boundarytype);
1866 char NativeMapFile[256];
1869 strcat(NativeMapFile,
"/MapFile.inp");
1871 FILE *fNativeMap = fopen(NativeMapFile,
"w");
1873 fprintf(fNativeMap,
"#Number of maps\n");
1874 fprintf(fNativeMap,
"%d\n", 0);
1875 fprintf(fNativeMap,
"#Number of lines\n");
1876 fprintf(fNativeMap,
"%d\n", 0);
1877 fprintf(fNativeMap,
"#Number of points\n");
1878 fprintf(fNativeMap,
"%d\n", 0);
1888 neBEMMessage(
"neBEMReadGeometry - problem writing Primtives.\n");
1895 "neBEMReadGeometry - unformatted write not inplemented yet.\n");
1900 printf(
"neBEMReadGeometry: Geometry read!\n");
1906 printf(
"to read geometry\n");
1925 neBEMMessage(
"neBEMDiscretize - problem reading stored Elements.\n");
1934 printf(
"discretization can continue only in State 3 ...\n");
1961 char MeshLogFile[256];
1964 strcat(MeshLogFile,
"/MeshLog.out");
1965 fMeshLog = fopen(MeshLogFile,
"w");
1966 fprintf(
fMeshLog,
"Details of primitive discretization\n");
1970 NbSurfSegX[prim] = NbElemsOnPrimitives[prim][1];
1971 NbSurfSegZ[prim] = NbElemsOnPrimitives[prim][2];
1980 NbSurfSegX[prim] = NbElemsOnPrimitives[prim][1];
1981 NbSurfSegZ[prim] = NbElemsOnPrimitives[prim][2];
1991 NbWireSeg[prim] = NbElemsOnPrimitives[prim][1];
2001 printf(
"Primitive %d to be discretized into %d elements.\n", prim,
2004 printf(
"Primitive %d to be discretized into %d X %d elements.\n", prim,
2009 printf(
"Memory allocated for maximum %d elements.\n",
NbElements);
2014 printf(
"neBEMDiscretize: NbElements = %d, sizeof(Element) = %zu\n",
2023 printf(
"neBEMDiscretize: Re-allocating EleArr failed.\n");
2026 printf(
"neBEMDiscretize: Re-allocated EleArr.\n");
2042 strcat(GnuFile,
"/GViewDir/gPrimView.gp");
2044 fprintf(
fgnuPrim,
"set title \"neBEM primitives in gnuplot VIEWER\"\n");
2047 fprintf(
fgnuPrim,
"#set style data pm3d\n");
2048 fprintf(
fgnuPrim,
"#set palette model CMY\n");
2049 fprintf(
fgnuPrim,
"set hidden3d\n");
2051 fprintf(
fgnuPrim,
"set xlabel \"X\"\n");
2052 fprintf(
fgnuPrim,
"set ylabel \"Y\"\n");
2053 fprintf(
fgnuPrim,
"set zlabel \"Z\"\n");
2054 fprintf(
fgnuPrim,
"set view 70, 335, 1, 1\n");
2058 strcat(GnuFile,
"/GViewDir/gElemView.gp");
2060 fprintf(
fgnuElem,
"set title \"neBEM elements in gnuplot VIEWER\"\n");
2063 fprintf(
fgnuElem,
"#set style data pm3d\n");
2064 fprintf(
fgnuElem,
"#set palette model CMY\n");
2065 fprintf(
fgnuElem,
"set hidden3d\n");
2067 fprintf(
fgnuElem,
"set xlabel \"X\"\n");
2068 fprintf(
fgnuElem,
"set ylabel \"Y\"\n");
2069 fprintf(
fgnuElem,
"set zlabel \"Z\"\n");
2070 fprintf(
fgnuElem,
"set view 70, 335, 1, 1\n");
2074 strcat(GnuFile,
"/GViewDir/gMeshView.gp");
2076 fprintf(
fgnuMesh,
"set title \"neBEM mesh in gnuplot VIEWER\"\n");
2079 fprintf(
fgnuMesh,
"#set style data pm3d\n");
2080 fprintf(
fgnuMesh,
"#set palette model CMY\n");
2081 fprintf(
fgnuMesh,
"set hidden3d\n");
2083 fprintf(
fgnuMesh,
"set xlabel \"X\"\n");
2084 fprintf(
fgnuMesh,
"set ylabel \"Y\"\n");
2085 fprintf(
fgnuMesh,
"set zlabel \"Z\"\n");
2086 fprintf(
fgnuMesh,
"set view 70, 335, 1, 1\n");
2119 printf(
"PrimType out of range in CreateElements ... exiting ...\n");
2135 neBEMMessage(
"neBEMDiscretize - EleCntr more than NbElements!");
2141 int startcntr = 1, cntr1, cntr2, NbCollPtOverlaps = 0;
2144 for (cntr1 = startcntr; cntr1 <=
EleCntr; ++cntr1) {
2145 pt1.
X = (
EleArr + cntr1 - 1)->BC.CollPt.X;
2146 pt1.
Y = (
EleArr + cntr1 - 1)->BC.CollPt.Y;
2147 pt1.
Z = (
EleArr + cntr1 - 1)->BC.CollPt.Z;
2148 for (cntr2 = cntr1 + 1; cntr2 <=
EleCntr; ++cntr2) {
2149 pt2.
X = (
EleArr + cntr2 - 1)->BC.CollPt.X;
2150 pt2.
Y = (
EleArr + cntr2 - 1)->BC.CollPt.Y;
2151 pt2.
Z = (
EleArr + cntr2 - 1)->BC.CollPt.Z;
2165 int prim1 = (
EleArr + cntr1 - 1)->PrimitiveNb;
2167 int prim2 = (
EleArr + cntr2 - 1)->PrimitiveNb;
2170 neBEMMessage(
"neBEMDiscretize - Overlapping collocation points!");
2171 printf(
"Element %d, primitive %d, volume %d overlaps with\n", cntr1,
2173 printf(
"\telement %d, primitive %d, volume %d.\n", cntr2, prim2,
2175 printf(
"\tposition 1: (%g , %g , %g) micron,\n", 1e6 * pt1.
X,
2176 1e6 * pt1.
Y, 1e6 * pt1.
Z);
2177 printf(
"\tposition 2: (%g , %g , %g) micron.\n", 1e6 * pt2.
X,
2178 1e6 * pt2.
Y, 1e6 * pt2.
Z);
2179 printf(
"Please redo the geometry.\n");
2187 printf(
"Total final number of elements: %d\n",
NbElements);
2194 neBEMMessage(
"neBEMDiscretize - problem writing Elements.\n");
2201 "neBEMDiscretize - unformatted write not inplemented yet.\n");
2209 printf(
"to complete discretization\n");
2225 neBEMMessage(
"neBEMBondaryConditions - BoundaryConditions");
2231 printf(
"Boundary conditions can be set only in state 4 / 7 ...\n");
2232 printf(
"returning ...\n");
2238 printf(
"to setup boundary conditions.\n");
2283 FILE *KnChInpFile = fopen(
"neBEMKnCh.inp",
"r");
2284 if (KnChInpFile == NULL) {
2287 "neBEMKnCh.inp absent ... assuming absence of known charges ...\n");
2289 fscanf(KnChInpFile,
"OptKnCh: %d\n", &
OptKnCh);
2290 if (1) printf(
"OptKnCh: %d\n",
OptKnCh);
2292 if (!
OptKnCh) printf(
"OptKnCh = 0 ... assuming no known charges ...\n");
2295 char PointKnChFile[256];
2296 char LineKnChFile[256];
2297 char AreaKnChFile[256];
2298 char VolumeKnChFile[256];
2301 fscanf(KnChInpFile,
"NbPointsKnCh: %d\n", &
NbPointsKnCh);
2302 fscanf(KnChInpFile,
"PointKnChFile: %255s\n", PointKnChFile);
2303 fscanf(KnChInpFile,
"NbLinesKnCh: %d\n", &
NbLinesKnCh);
2304 fscanf(KnChInpFile,
"LineKnChFile: %255s\n", LineKnChFile);
2305 fscanf(KnChInpFile,
"NbAreasKnCh: %d\n", &
NbAreasKnCh);
2306 fscanf(KnChInpFile,
"AreaKnChFile: %255s\n", AreaKnChFile);
2308 fscanf(KnChInpFile,
"VolumeKnChFile: %255s\n", VolumeKnChFile);
2309 fscanf(KnChInpFile,
"KnChFactor: %lg\n", &KnChFactor);
2312 printf(
"PointKnChFile: %s\n", PointKnChFile);
2314 printf(
"LineKnChFile: %s\n", LineKnChFile);
2316 printf(
"AreaKnChFile: %s\n", AreaKnChFile);
2318 printf(
"VolumeKnChFile: %s\n", VolumeKnChFile);
2319 printf(
"KnChFactor: %lg\n", KnChFactor);
2324 printf(
"No. of points with known charges: %d\n",
NbPointsKnCh);
2326 FILE *fptrPointKnChFile = fopen(PointKnChFile,
"r");
2327 if (fptrPointKnChFile == NULL) {
2335 neBEMMessage(
"Memory allocation failed ... returning\n");
2336 fclose(fptrPointKnChFile);
2349 fgets(header, 256, fptrPointKnChFile);
2352 fscanf(fptrPointKnChFile,
"%d %lg %lg %lg %lg\n",
2360 fclose(fptrPointKnChFile);
2361 if (debugFn) printf(
"done for all points\n");
2366 printf(
"No. of lines with known charges: %d\n",
NbLinesKnCh);
2368 FILE *fptrLineKnChFile = fopen(LineKnChFile,
"r");
2369 if (fptrLineKnChFile == NULL) {
2377 neBEMMessage(
"Memory allocation failed ... returning\n");
2378 fclose(fptrLineKnChFile);
2395 fgets(header, 256, fptrLineKnChFile);
2398 fscanf(fptrLineKnChFile,
"%d %lg %lg %lg %lg %lg %lg %lg %lg\n",
2407 fclose(fptrLineKnChFile);
2408 if (debugFn) printf(
"done for all lines\n");
2413 printf(
"No. of areas with known charges: %d\n",
NbAreasKnCh);
2415 FILE *fptrAreaKnChFile = fopen(AreaKnChFile,
"r");
2416 if (fptrAreaKnChFile == NULL) {
2424 neBEMMessage(
"Memory allocation failed ... returning\n");
2425 fclose(fptrAreaKnChFile);
2442 fgets(header, 256, fptrAreaKnChFile);
2445 fscanf(fptrAreaKnChFile,
"%d %d %le\n",
2451 fscanf(fptrAreaKnChFile,
"%le %le %le\n",
2459 fclose(fptrAreaKnChFile);
2460 if (debugFn) printf(
"done for all areas\n");
2465 printf(
"No. of volumes with known charges: %d\n",
NbVolumesKnCh);
2467 FILE *fptrVolumeKnChFile = fopen(VolumeKnChFile,
"r");
2468 if (fptrVolumeKnChFile == NULL) {
2469 neBEMMessage(
"VolumeKnCh file absent ... returning\n");
2476 neBEMMessage(
"Memory allocation failed ... returning\n");
2477 fclose(fptrVolumeKnChFile);
2494 fgets(header, 256, fptrVolumeKnChFile);
2497 fscanf(fptrVolumeKnChFile,
"%d %d %le\n",
2503 fscanf(fptrVolumeKnChFile,
"%le %le %le\n",
2511 fclose(fptrVolumeKnChFile);
2512 if (debugFn) printf(
"done for all volumes\n");
2517 fclose(KnChInpFile);
2536 for (
int ele = 1; ele <=
NbElements; ++ele) {
2537 printf(
"ele, Assigned charge: %d, %lg\n", ele,
2538 (
EleArr + ele - 1)->Assigned);
2547 FILE *ChargingUpInpFile = fopen(
"neBEMChargingUp.inp",
"r");
2548 if (ChargingUpInpFile == NULL) {
2550 "neBEMChargingUp.inp absent ... assuming no charging up effect "
2554 fscanf(ChargingUpInpFile,
"OptChargingUp: %d\n", &
OptChargingUp);
2556 printf(
"OptChargingUp = 0 ... assuming no charging up effect ...\n");
2560 char ChargingUpEFile[256];
2561 char ChargingUpIFile[256];
2563 int *NbChUpEonEle, *NbChUpIonEle;
2565 fscanf(ChargingUpInpFile,
"ChargingUpEFile: %255s\n", ChargingUpEFile);
2566 fscanf(ChargingUpInpFile,
"ChargingUpIFile: %255s\n", ChargingUpIFile);
2567 fscanf(ChargingUpInpFile,
"ChUpFactor: %lg\n", &ChUpFactor);
2569 printf(
"ChargingUpEFile: %s\n", ChargingUpEFile);
2570 printf(
"ChargingUpIFile: %s\n", ChargingUpIFile);
2571 printf(
"ChUpFactor: %lg\n", ChUpFactor);
2575 FILE *fptrChargingUpEFile = fopen(ChargingUpEFile,
"r");
2576 if (fptrChargingUpEFile == NULL) {
2577 neBEMMessage(
"ChargingUpE file absent ... returning\n");
2582 neBEMMessage(
"Too few lines in ChargingUpE ... returning\n");
2583 fclose(fptrChargingUpEFile);
2586 NbChUpEonEle = (
int *)malloc((
NbElements + 1) *
sizeof(int));
2587 if (NbChUpEonEle == NULL) {
2588 neBEMMessage(
"Memory allocation failed ... returning\n");
2589 fclose(fptrChargingUpEFile);
2592 for (
int ele = 0; ele <=
NbElements; ++ele) {
2594 NbChUpEonEle[ele] = 0;
2599 fgets(header, 256, fptrChargingUpEFile);
2602 if (debugFn) printf(
"No. of electrons: %d\n", NbOfE);
2603 const char *tmpEFile =
"/tmp/ElectronTempFile.out";
2604 FILE *ftmpEF = fopen(tmpEFile,
"w");
2605 if (ftmpEF == NULL) {
2606 printf(
"cannot open temporary output file ... returning ...\n");
2610 FILE *fPtEChUpMap = fopen(
"PtEChUpMap.out",
"w");
2611 if (fPtEChUpMap == NULL) {
2612 printf(
"cannot open PtEChUpMap.out file for writing ...\n");
2620 double xlbend, ylbend, zlbend;
2621 double xend, yend, zend;
2624 for (
int electron = 1; electron <= NbOfE; ++electron) {
2625 fscanf(fptrChargingUpEFile,
"%c %d %d %lg %lg %lg %lg %lg %lg\n",
2626 &label, &vol, &enb, &xlbend, &xend, &ylbend, ¥d, &zlbend,
2646 double lseg = (xend - xlbend) * (xend - xlbend) +
2647 (yend - ylbend) * (yend - ylbend) +
2648 (zend - zlbend) * (zend - zlbend);
2651 (xend - xlbend) / lseg;
2652 double ygrd = (yend - ylbend) / lseg;
2653 double zgrd = (zend - zlbend) / lseg;
2655 printf(
"\nelectron: %d\n", electron);
2656 printf(
"xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
2658 printf(
"xend: %lg, yend: %lg, zend: %lg\n", xend, yend, zend);
2659 printf(
"xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd, zgrd);
2660 fprintf(ftmpEF,
"#e: %d, label: %c, vol: %d\n", electron, label,
2662 fprintf(ftmpEF,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
2663 fprintf(ftmpEF,
"%lg %lg %lg\n", xend, yend, zend);
2664 fprintf(ftmpEF,
"#xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd,
2666 fprintf(ftmpEF,
"\n");
2683 int PrimIntsctd = -1,
2685 int nearestprim = -1;
2686 double dist = 1.0e6, mindist = 1.0e6;
2692 int intersect = 0, extrasect = 1;
2693 int InPrim = 0, InEle = 0;
2695 printf(
"prim: %d, mindist: %lg, nearestprim: %d\n", prim,
2696 mindist, nearestprim);
2705 printf(
"prim: %d\n", prim);
2706 printf(
"vertex0: %lg, %lg, %lg\n",
XVertex[prim][0],
2708 printf(
"vertex1: %lg, %lg, %lg\n",
XVertex[prim][1],
2710 printf(
"vertex2: %lg, %lg, %lg\n",
XVertex[prim][2],
2713 printf(
"vertex3: %lg, %lg, %lg\n",
XVertex[prim][3],
2716 fprintf(ftmpEF,
"#prim: %d\n", prim);
2717 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][0],
2719 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][1],
2721 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][2],
2724 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][3],
2727 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][0],
2729 fprintf(ftmpEF,
"\n");
2735 double a =
XNorm[prim];
2736 double b =
YNorm[prim];
2737 double c =
ZNorm[prim];
2742 dist = (xend * a + yend * b + zend * c + d) /
2743 sqrt(a * a + b * b + c * c);
2749 if ((prim == 1) && debugFn)
2751 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
2752 mindist, nearestprim);
2761 double norm1 = sqrt(a * a + b * b + c * c);
2762 double norm2 = sqrt(xgrd * xgrd + ygrd * ygrd + zgrd * zgrd);
2764 a * xgrd + b * ygrd + c * zgrd;
2767 intersect = extrasect = 0;
2770 printf(
"a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
2772 printf(
"vector n: ai + bj + ck\n");
2773 printf(
"vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
2775 printf(
"norm1, norm2, (vec n . vec v) denom: %lg, %lg, %lg\n",
2776 norm1, norm2, denom);
2777 printf(
"if vec n . vec v == 0, line and plane parallel\n");
2781 if (fabs(denom) < tol * norm1 * norm2) {
2783 if (fabs(a * xlbend + b * ylbend + c * zlbend + d) <=
2787 ptintsct.
X = xlbend;
2788 ptintsct.
Y = ylbend;
2789 ptintsct.
Z = zlbend;
2799 printf(
"line and plane parallel ...\n");
2800 printf(
"intersect: %d, extrasect: %d\n", intersect,
2802 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2803 ptintsct.
Y, ptintsct.
Z);
2808 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
2815 (fabs(t) > fabs(lseg)))
2818 ptintsct.
X = xlbend + t * xgrd;
2819 ptintsct.
Y = ylbend + t * ygrd;
2820 ptintsct.
Z = zlbend + t * zgrd;
2823 ptintsct.
X = xlbend + t * xgrd;
2824 ptintsct.
Y = ylbend + t * ygrd;
2825 ptintsct.
Z = zlbend + t * zgrd;
2828 printf(
"line and plane NOT parallel ...\n");
2829 printf(
"intersect: %d, extrasect: %d\n", intersect,
2831 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2832 ptintsct.
Y, ptintsct.
Z);
2833 printf(
"t, lseg: %lg, %lg\n", t, lseg);
2835 "for an interesting intersection, lseg > t > 0.0 "
2848 if (dist < mindist) {
2853 printf(
"nearestprim: %d, mindist: %lg\n\n", nearestprim,
2860 if ((intersect == 1) && (extrasect == 0)) {
2881 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) {
2887 printf(
"Prim: %d\n", prim);
2888 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
2890 printf(
"nvert: %d\n", nvert);
2891 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
2892 polynode[0].Y, polynode[0].Z);
2893 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
2894 polynode[1].Y, polynode[1].Z);
2895 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
2896 polynode[2].Y, polynode[2].Z);
2898 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
2899 polynode[3].Y, polynode[3].Z);
2901 printf(
"SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
2916 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
2917 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
2920 "no vertex in element! ... neBEMKnownCharges ...\n");
2921 fclose(fPtEChUpMap);
2925 polynode[0].
X = (
EleArr + ele - 1)->G.Vertex[0].X;
2926 polynode[0].
Y = (
EleArr + ele - 1)->G.Vertex[0].Y;
2927 polynode[0].
Z = (
EleArr + ele - 1)->G.Vertex[0].Z;
2928 polynode[1].
X = (
EleArr + ele - 1)->G.Vertex[1].X;
2929 polynode[1].
Y = (
EleArr + ele - 1)->G.Vertex[1].Y;
2930 polynode[1].
Z = (
EleArr + ele - 1)->G.Vertex[1].Z;
2931 polynode[2].
X = (
EleArr + ele - 1)->G.Vertex[2].X;
2932 polynode[2].
Y = (
EleArr + ele - 1)->G.Vertex[2].Y;
2933 polynode[2].
Z = (
EleArr + ele - 1)->G.Vertex[2].Z;
2935 polynode[3].
X = (
EleArr + ele - 1)->G.Vertex[3].X;
2936 polynode[3].
Y = (
EleArr + ele - 1)->G.Vertex[3].Y;
2937 polynode[3].
Z = (
EleArr + ele - 1)->G.Vertex[3].Z;
2942 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8)
2946 printf(
"Ele: %d\n", ele);
2947 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X,
2948 ptintsct.
Y, ptintsct.
Z);
2949 printf(
"nvert: %d\n", nvert);
2950 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
2951 polynode[0].Y, polynode[0].Z);
2952 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
2953 polynode[1].Y, polynode[1].Z);
2954 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
2955 polynode[2].Y, polynode[2].Z);
2957 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
2958 polynode[3].Y, polynode[3].Z);
2960 printf(
"SumOfAngles: %lg, InEle: %d\n", SumOfAngles,
2965 ptintsct.
X = (
EleArr + ele - 1)->G.Origin.X;
2966 ptintsct.
Y = (
EleArr + ele - 1)->G.Origin.Y;
2967 ptintsct.
Z = (
EleArr + ele - 1)->G.Origin.Z;
2970 NbChUpEonEle[ele]++;
2971 fprintf(fPtEChUpMap,
"%d %lg %lg %lg %d %d %d %d\n",
2972 electron, ptintsct.
X, ptintsct.
Y, ptintsct.
Z,
2973 prim, InPrim, ele, InEle);
2976 printf(
"# electron: %d\n", electron);
2977 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
2978 printf(
"%lg %lg %lg\n", xend, yend, zend);
2979 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
2981 printf(
"# Associated primitive: %d\n", prim);
2983 "# Associated element and origin: %d, %lg, %lg, "
2985 ele, (
EleArr + ele - 1)->G.Origin.X,
2986 (
EleArr + ele - 1)->G.Origin.Y,
2987 (
EleArr + ele - 1)->G.Origin.Z);
2988 printf(
"#NbChUpEonEle on element: %d\n",
2990 fprintf(ftmpEF,
"#Element: %d\n", ele);
2991 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X,
2992 polynode[0].Y, polynode[0].Z);
2993 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[1].X,
2994 polynode[1].Y, polynode[1].Z);
2995 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[2].X,
2996 polynode[2].Y, polynode[2].Z);
2998 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[3].X,
2999 polynode[3].Y, polynode[3].Z);
3001 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X,
3002 polynode[0].Y, polynode[0].Z);
3003 fprintf(ftmpEF,
"\n");
3014 "Element not identified ... neBEMKnownCharges\n");
3020 if ((InPrim) && (intersect) && (!extrasect) && (InEle)) {
3034 double distele = 1.0e6;
3035 double mindistele = 1.0e6;
3038 printf(
"prim == (NbPrimitives) ... checking nearest ...\n");
3039 printf(
"nearestprim: %d, mindist: %lg\n", nearestprim,
3043 if (mindist <= 10.0e-6) {
3044 PrimIntsctd = nearestprim;
3055 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3056 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3059 "no vertex element! ... neBEMKnownCharges ...\n");
3133 eleOrigin.
X = (
EleArr + ele - 1)->G.Origin.X;
3134 eleOrigin.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3135 eleOrigin.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3136 distele = (eleOrigin.
X - xend) * (eleOrigin.
X - xend) +
3137 (eleOrigin.
Y - yend) * (eleOrigin.
Y - yend) +
3138 (eleOrigin.
Z - zend) * (eleOrigin.
Z - zend);
3139 distele = pow(distele, 0.5);
3142 mindistele = distele;
3145 if (distele < mindistele) {
3146 mindistele = distele;
3157 "distele: %lg, mindistele: %lg,from nearest ele "
3159 distele, mindistele, nearestele);
3168 EleIntsctd = nearestele;
3170 ptintsct.
X = (
EleArr + EleIntsctd - 1)->G.Origin.X;
3171 ptintsct.
Y = (
EleArr + EleIntsctd - 1)->G.Origin.Y;
3172 ptintsct.
Z = (
EleArr + EleIntsctd - 1)->G.Origin.Z;
3173 NbChUpEonEle[EleIntsctd]++;
3175 fprintf(fPtEChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", electron,
3176 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3181 printf(
"# electron: %d\n", electron);
3182 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3183 printf(
"%lg %lg %lg\n", xend, yend, zend);
3184 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y, ptintsct.
Z);
3185 printf(
"# Associated primitive: %d\n", PrimIntsctd);
3186 printf(
"# Associated element and origin: %d, %lg, %lg, %lg\n",
3187 EleIntsctd, (
EleArr + EleIntsctd - 1)->G.Origin.X,
3188 (
EleArr + EleIntsctd - 1)->G.Origin.Y,
3189 (
EleArr + EleIntsctd - 1)->G.Origin.Z);
3190 printf(
"#NbChUpEonEle on element: %d\n",
3191 NbChUpEonEle[EleIntsctd]);
3194 fprintf(ftmpEF,
"#Element: %d\n", EleIntsctd);
3195 polynode[0].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3196 polynode[0].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3197 polynode[0].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3198 polynode[1].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3199 polynode[1].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3200 polynode[1].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3201 polynode[2].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3202 polynode[2].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3203 polynode[2].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3205 polynode[3].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3206 polynode[3].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3207 polynode[3].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3209 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3211 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3213 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3216 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[3].X,
3217 polynode[3].Y, polynode[3].Z);
3219 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3221 fprintf(ftmpEF,
"\n");
3228 printf(
"writing file for checking electron positions\n");
3233 char elecposdbg[256], enbstr[10];
3234 sprintf(enbstr,
"%d", electron);
3235 strcpy(elecposdbg,
"/tmp/Electron");
3236 strcat(elecposdbg, enbstr);
3237 strcat(elecposdbg,
".out");
3238 FILE *fepd = fopen(elecposdbg,
"w");
3241 "cannot open writable file to debug electron positions "
3243 printf(
"returning ...\n");
3248 fprintf(fepd,
"#electron: %d %d\n", enb,
3250 fprintf(fepd,
"#last but end position:\n");
3251 fprintf(fepd,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3252 fprintf(fepd,
"#end position:\n");
3253 fprintf(fepd,
"%lg %lg %lg\n\n", xend, yend, zend);
3254 fprintf(fepd,
"#intersected primitive number: %d\n", PrimIntsctd);
3255 if (PrimIntsctd >= 1) {
3256 fprintf(fepd,
"#PrimType: %d\n",
PrimType[PrimIntsctd]);
3257 fprintf(fepd,
"#prim vertices:\n");
3258 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
3260 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][1],
3262 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][2],
3265 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][3],
3268 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
3270 fprintf(fepd,
"\n");
3272 fprintf(fepd,
"#ptintsct:\n");
3273 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3275 fprintf(fepd,
"\n");
3277 fprintf(fepd,
"#intersected element number: %d\n", EleIntsctd);
3278 if (EleIntsctd >= 1) {
3279 int gtype = (
EleArr + EleIntsctd - 1)->G.Type;
3280 fprintf(fepd,
"#EleType: %d\n", gtype);
3281 fprintf(fepd,
"#element vertices:\n");
3282 double x0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3283 double y0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3284 double z0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3285 double x1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3286 double y1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3287 double z1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3288 double x2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3289 double y2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3290 double z2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3291 fprintf(fepd,
"%lg %lg %lg\n", x0, y0, z0);
3292 fprintf(fepd,
"%lg %lg %lg\n", x1, y1, z1);
3293 fprintf(fepd,
"%lg %lg %lg\n", x2, y2, z2);
3295 double x3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3296 double y3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3297 double z3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3298 fprintf(fepd,
"%lg %lg %lg\n", x3, y3, z3);
3300 fprintf(fepd,
"%lg %lg %lg\n", x0, y0, z0);
3301 fprintf(fepd,
"\n");
3303 fprintf(fepd,
"#ptintsct:\n");
3304 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3306 fprintf(fepd,
"\n");
3312 printf(
"done writing file for checking electron positions\n");
3314 fclose(fPtEChUpMap);
3315 if (debugFn) printf(
"done for all electrons\n");
3317 FILE *fEleEChUpMap = fopen(
"EleEChUpMap.out",
"w");
3318 if (fEleEChUpMap == NULL) {
3319 printf(
"cannot open EleEChUpMap.out file for writing ...\n");
3322 for (
int ele = 1; ele <=
NbElements; ++ele) {
3323 (
EleArr + ele - 1)->Assigned +=
3324 ChUpFactor *
Q_E * NbChUpEonEle[ele] / (
EleArr + ele - 1)->G.dA;
3325 fprintf(fEleEChUpMap,
"%d %lg %lg %lg %d %lg\n", ele,
3326 (
EleArr + ele - 1)->G.Origin.X,
3327 (
EleArr + ele - 1)->G.Origin.Y,
3328 (
EleArr + ele - 1)->G.Origin.Z, NbChUpEonEle[ele],
3329 (
EleArr + ele - 1)->Assigned);
3331 fclose(fEleEChUpMap);
3338 FILE *fptrChargingUpIFile = fopen(ChargingUpIFile,
"r");
3339 if (fptrChargingUpIFile == NULL) {
3340 neBEMMessage(
"ChargingUpI file absent ... returning\n");
3345 neBEMMessage(
"Too few lines in ChargingUpI ... returning\n");
3346 fclose(fptrChargingUpIFile);
3350 NbChUpIonEle = (
int *)malloc((
NbElements + 1) *
sizeof(int));
3351 if (NbChUpIonEle == NULL) {
3352 neBEMMessage(
"Memory allocation failed ... returning\n");
3353 fclose(fptrChargingUpIFile);
3356 for (
int ele = 0; ele <=
NbElements; ++ele) {
3358 NbChUpIonEle[ele] = 0;
3363 fgets(header, 256, fptrChargingUpIFile);
3366 if (debugFn) printf(
"No. of ions: %d\n", NbOfI);
3367 const char *tmpIFile =
"/tmp/IonTempFile.out";
3368 FILE *ftmpIF = fopen(tmpIFile,
"w");
3369 if (ftmpIF == NULL) {
3370 printf(
"cannot open temporary ion output file ... returning ...\n");
3374 FILE *fPtIChUpMap = fopen(
"PtIChUpMap.out",
"w");
3375 if (fPtIChUpMap == NULL) {
3376 printf(
"cannot open PtIChUpMap.out file for writing ...\n");
3384 double xlbend, ylbend, zlbend;
3385 double xend, yend, zend;
3387 for (
int ion = 1; ion <= NbOfI; ++ion) {
3388 fscanf(fptrChargingUpIFile,
"%c %d %d %lg %lg %lg %lg %lg %lg\n",
3389 &label, &vol, &inb, &xlbend, &xend, &ylbend, ¥d, &zlbend,
3409 double lseg = (xend - xlbend) * (xend - xlbend) +
3410 (yend - ylbend) * (yend - ylbend) +
3411 (zend - zlbend) * (zend - zlbend);
3414 (xend - xlbend) / lseg;
3415 double ygrd = (yend - ylbend) / lseg;
3416 double zgrd = (zend - zlbend) / lseg;
3418 printf(
"\nion: %d\n", ion);
3419 printf(
"xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
3421 printf(
"xend: %lg, yend: %lg, zend: %lg\n", xend, yend, zend);
3422 printf(
"xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd, zgrd);
3423 fprintf(ftmpIF,
"#e: %d, label: %c, vol: %d\n", ion, label, vol);
3424 fprintf(ftmpIF,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3425 fprintf(ftmpIF,
"%lg %lg %lg\n", xend, yend, zend);
3426 fprintf(ftmpIF,
"#xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd,
3428 fprintf(ftmpIF,
"\n");
3444 int PrimIntsctd = -1,
3446 int nearestprim = -1;
3447 double dist = 1.0e6, mindist = 1.0e6;
3454 int intersect = 0, extrasect = 1;
3455 int InPrim = 0, InEle = 0;
3457 printf(
"prim: %d, mindist: %lg, nearestprim: %d\n", prim,
3458 mindist, nearestprim);
3469 printf(
"prim: %d\n", prim);
3470 printf(
"vertex0: %lg, %lg, %lg\n",
XVertex[prim][0],
3472 printf(
"vertex1: %lg, %lg, %lg\n",
XVertex[prim][1],
3474 printf(
"vertex2: %lg, %lg, %lg\n",
XVertex[prim][2],
3477 printf(
"vertex3: %lg, %lg, %lg\n",
XVertex[prim][3],
3480 fprintf(ftmpIF,
"#prim: %d\n", prim);
3481 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][0],
3483 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][1],
3485 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][2],
3488 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][3],
3491 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][0],
3493 fprintf(ftmpIF,
"\n");
3506 zend *
ZNorm[prim] + d) /
3514 if ((prim == 1) && debugFn)
3516 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
3517 mindist, nearestprim);
3526 double a =
XNorm[prim];
3527 double b =
YNorm[prim];
3528 double c =
ZNorm[prim];
3529 double norm1 = sqrt(a * a + b * b + c * c);
3530 double norm2 = sqrt(xgrd * xgrd + ygrd * ygrd + zgrd * zgrd);
3532 a * xgrd + b * ygrd + c * zgrd;
3535 intersect = extrasect = 0;
3538 printf(
"a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
3540 printf(
"vector n: ai + bj + ck\n");
3541 printf(
"vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
3543 printf(
"norm1, norm2, (vec n . vec v) denom: %lg, %lg, %lg\n",
3544 norm1, norm2, denom);
3545 printf(
"if vec n . vec v == 0, line and plane parallel\n");
3549 if (fabs(denom) < tol * norm1 * norm2) {
3551 if (a * xlbend + b * ylbend + c * zlbend + d ==
3556 ptintsct.
X = xlbend;
3557 ptintsct.
Y = ylbend;
3558 ptintsct.
Z = zlbend;
3568 printf(
"line and plane parallel ...\n");
3569 printf(
"intersect: %d, extrasect: %d\n", intersect,
3571 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3572 ptintsct.
Y, ptintsct.
Z);
3577 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
3583 if ((t < 0.0) || (fabs(t) > fabs(lseg))) {
3585 ptintsct.
X = xlbend + t * xgrd;
3586 ptintsct.
Y = ylbend + t * ygrd;
3587 ptintsct.
Z = zlbend + t * zgrd;
3590 ptintsct.
X = xlbend + t * xgrd;
3591 ptintsct.
Y = ylbend + t * ygrd;
3592 ptintsct.
Z = zlbend + t * zgrd;
3595 printf(
"line and plane NOT parallel ...\n");
3596 printf(
"intersect: %d, extrasect: %d\n", intersect,
3598 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3599 ptintsct.
Y, ptintsct.
Z);
3600 printf(
"t, lseg: %lg, %lg\n", t, lseg);
3602 "for an interesting intersection, lseg > t > 0.0 "
3614 if (dist < mindist) {
3623 if ((intersect == 1) && (extrasect == 0)) {
3644 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) {
3650 printf(
"Prim: %d\n", prim);
3651 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3653 printf(
"nvert: %d\n", nvert);
3654 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
3655 polynode[0].Y, polynode[0].Z);
3656 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
3657 polynode[1].Y, polynode[1].Z);
3658 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
3659 polynode[2].Y, polynode[2].Z);
3661 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
3662 polynode[3].Y, polynode[3].Z);
3664 printf(
"SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
3667 if (!InPrim)
continue;
3675 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3676 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3679 "no vertex in element! ... neBEMKnownCharges ...\n");
3680 if (fPtIChUpMap) fclose(fPtIChUpMap);
3684 polynode[0].
X = (
EleArr + ele - 1)->G.Vertex[0].X;
3685 polynode[0].
Y = (
EleArr + ele - 1)->G.Vertex[0].Y;
3686 polynode[0].
Z = (
EleArr + ele - 1)->G.Vertex[0].Z;
3687 polynode[1].
X = (
EleArr + ele - 1)->G.Vertex[1].X;
3688 polynode[1].
Y = (
EleArr + ele - 1)->G.Vertex[1].Y;
3689 polynode[1].
Z = (
EleArr + ele - 1)->G.Vertex[1].Z;
3690 polynode[2].
X = (
EleArr + ele - 1)->G.Vertex[2].X;
3691 polynode[2].
Y = (
EleArr + ele - 1)->G.Vertex[2].Y;
3692 polynode[2].
Z = (
EleArr + ele - 1)->G.Vertex[2].Z;
3694 polynode[3].
X = (
EleArr + ele - 1)->G.Vertex[3].X;
3695 polynode[3].
Y = (
EleArr + ele - 1)->G.Vertex[3].Y;
3696 polynode[3].
Z = (
EleArr + ele - 1)->G.Vertex[3].Z;
3701 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) InEle = 1;
3704 printf(
"Ele: %d\n", ele);
3705 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3707 printf(
"nvert: %d\n", nvert);
3708 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
3709 polynode[0].Y, polynode[0].Z);
3710 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
3711 polynode[1].Y, polynode[1].Z);
3712 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
3713 polynode[2].Y, polynode[2].Z);
3715 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
3716 polynode[3].Y, polynode[3].Z);
3718 printf(
"SumOfAngles: %lg, InEle: %d\n", SumOfAngles, InEle);
3722 ptintsct.
X = (
EleArr + ele - 1)->G.Origin.X;
3723 ptintsct.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3724 ptintsct.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3727 NbChUpIonEle[ele]++;
3728 fprintf(fPtIChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", ion,
3729 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, prim, InPrim,
3733 printf(
"# ion: %d\n", ion);
3734 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3735 printf(
"%lg %lg %lg\n", xend, yend, zend);
3736 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3738 printf(
"# Associated primitive: %d\n", prim);
3740 "# Associated element and origin: %d, %lg, %lg, "
3742 ele, (
EleArr + ele - 1)->G.Origin.X,
3743 (
EleArr + ele - 1)->G.Origin.Y,
3744 (
EleArr + ele - 1)->G.Origin.Z);
3745 printf(
"#NbChUpIonEle on element: %d\n",
3747 fprintf(ftmpIF,
"#Element: %d\n", ele);
3748 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X,
3749 polynode[0].Y, polynode[0].Z);
3750 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[1].X,
3751 polynode[1].Y, polynode[1].Z);
3752 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[2].X,
3753 polynode[2].Y, polynode[2].Z);
3755 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[3].X,
3756 polynode[3].Y, polynode[3].Z);
3758 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X,
3759 polynode[0].Y, polynode[0].Z);
3760 fprintf(ftmpIF,
"\n");
3769 "Element cannot be identified ... neBEMKnownCharges\n");
3773 if ((InPrim) && (intersect) && (!extrasect) && (InEle)) {
3786 double distele = 1.0e6;
3787 double mindistele = 1.0e6;
3790 printf(
"prim == (NbPrimitives) ... checking nearest ...\n");
3791 printf(
"nearestprim: %d, mindist: %lg\n", nearestprim,
3795 if (mindist <= 10.0e-6) {
3796 PrimIntsctd = nearestprim;
3807 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3808 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3811 "no vertex element! ... neBEMKnownCharges ...\n");
3887 eleOrigin.
X = (
EleArr + ele - 1)->G.Origin.X;
3888 eleOrigin.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3889 eleOrigin.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3890 distele = (eleOrigin.
X - xend) * (eleOrigin.
X - xend) +
3891 (eleOrigin.
Y - yend) * (eleOrigin.
Y - yend) +
3892 (eleOrigin.
Z - zend) * (eleOrigin.
Z - zend);
3893 distele = pow(distele, 0.5);
3896 mindistele = distele;
3899 if (distele < mindistele) {
3900 mindistele = distele;
3911 "distele: %lg, mindist: %lg, from nearest ele: %d\n",
3912 distele, mindistele, nearestele);
3921 EleIntsctd = nearestele;
3923 ptintsct.
X = (
EleArr + EleIntsctd - 1)->G.Origin.X;
3924 ptintsct.
Y = (
EleArr + EleIntsctd - 1)->G.Origin.Y;
3925 ptintsct.
Z = (
EleArr + EleIntsctd - 1)->G.Origin.Z;
3926 NbChUpIonEle[EleIntsctd]++;
3928 fprintf(fPtIChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", ion,
3929 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3934 printf(
"# ion: %d\n", ion);
3935 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3936 printf(
"%lg %lg %lg\n", xend, yend, zend);
3937 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y, ptintsct.
Z);
3938 printf(
"# Associated primitive: %d\n", PrimIntsctd);
3939 printf(
"# Associated element and origin: %d, %lg, %lg, %lg\n",
3940 EleIntsctd, (
EleArr + EleIntsctd - 1)->G.Origin.X,
3941 (
EleArr + EleIntsctd - 1)->G.Origin.Y,
3942 (
EleArr + EleIntsctd - 1)->G.Origin.Z);
3943 printf(
"#NbChUpIonEle on element: %d\n",
3944 NbChUpIonEle[EleIntsctd]);
3945 fprintf(ftmpIF,
"#Element: %d\n", EleIntsctd);
3946 polynode[0].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3947 polynode[0].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3948 polynode[0].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3949 polynode[1].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3950 polynode[1].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3951 polynode[1].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3952 polynode[2].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3953 polynode[2].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3954 polynode[2].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3956 polynode[3].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3957 polynode[3].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3958 polynode[3].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3960 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3962 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3964 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3967 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[3].X,
3968 polynode[3].Y, polynode[3].Z);
3970 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3972 fprintf(ftmpIF,
"\n");
3981 char ionposdbg[256], inbstr[10];
3982 sprintf(inbstr,
"%d", ion);
3983 strcpy(ionposdbg,
"/tmp/Ion");
3984 strcat(ionposdbg, inbstr);
3985 strcat(ionposdbg,
".out");
3986 FILE *fipd = fopen(ionposdbg,
"w");
3989 "cannot open writable file to debug ion positions ...\n");
3990 printf(
"returning ...\n");
3995 fprintf(fipd,
"#ion: %d %d\n", inb, ion);
3996 fprintf(fipd,
"#last but end position:\n");
3997 fprintf(fipd,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3998 fprintf(fipd,
"#end position:\n");
3999 fprintf(fipd,
"%lg %lg %lg\n\n", xend, yend, zend);
4001 fprintf(fipd,
"#intersected primitive number: %d\n", PrimIntsctd);
4002 if (PrimIntsctd >= 1) {
4003 fprintf(fipd,
"#PrimType: %d\n",
PrimType[PrimIntsctd]);
4004 fprintf(fipd,
"#prim vertices:\n");
4005 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
4007 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][1],
4009 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][2],
4012 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][3],
4015 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
4017 fprintf(fipd,
"\n");
4019 fprintf(fipd,
"#ptintsct:\n");
4020 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4022 fprintf(fipd,
"\n");
4025 fprintf(fipd,
"#intersected element number: %d\n", EleIntsctd);
4026 if (EleIntsctd >= 1) {
4027 int gtype = (
EleArr + EleIntsctd - 1)->G.Type;
4028 fprintf(fipd,
"#EleType: %d\n", gtype);
4029 fprintf(fipd,
"#element vertices:\n");
4030 double x0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
4031 double y0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
4032 double z0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
4033 double x1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
4034 double y1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
4035 double z1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
4036 double x2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
4037 double y2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
4038 double z2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
4039 fprintf(fipd,
"%lg %lg %lg\n", x0, y0, z0);
4040 fprintf(fipd,
"%lg %lg %lg\n", x1, y1, z1);
4041 fprintf(fipd,
"%lg %lg %lg\n", x2, y2, z2);
4043 double x3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
4044 double y3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
4045 double z3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
4046 fprintf(fipd,
"%lg %lg %lg\n", x3, y3, z3);
4048 fprintf(fipd,
"%lg %lg %lg\n", x0, y0, z0);
4049 fprintf(fipd,
"\n");
4051 fprintf(fipd,
"#ptintsct:\n");
4052 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4054 fprintf(fipd,
"\n");
4059 fclose(fPtIChUpMap);
4063 FILE *fEleEIChUpMap = fopen(
"EleE+IChUpMap.out",
"w");
4064 if (fEleEIChUpMap == NULL) {
4065 printf(
"cannot open EleE+IChUpMap.out file for writing ...\n");
4068 for (
int ele = 1; ele <=
NbElements; ++ele) {
4069 (
EleArr + ele - 1)->Assigned +=
4070 ChUpFactor *
Q_I * NbChUpIonEle[ele] / (
EleArr + ele - 1)->G.dA;
4071 fprintf(fEleEIChUpMap,
"%d %lg %lg %lg %d %lg\n", ele,
4072 (
EleArr + ele - 1)->G.Origin.X,
4073 (
EleArr + ele - 1)->G.Origin.Y,
4074 (
EleArr + ele - 1)->G.Origin.Z, NbChUpIonEle[ele],
4075 (
EleArr + ele - 1)->Assigned);
4077 fclose(fEleEIChUpMap);
4085 fclose(ChargingUpInpFile);
4120 clock_t startSolveClock = clock();
4123 neBEMMessage(
"neBEMSolve - TimeStep cannot be less than one!;\n");
4124 neBEMMessage(
" Please put TimeStep = 1 for static problems.\n");
4131 neBEMMessage(
"neBEMSolve - NewBC zero for neBEMState = 8!");
4155 neBEMMessage(
"neBEMSolve - Failure computing new solution");
4166 printf(
"neBEMSolve: Nothing to do ... returning ...\n");
4175 printf(
"neBEMSolve: neBEMSolve can be called only in state 5 / 8 ...\n");
4176 printf(
"returning ...\n");
4182 "neBEMSolve: Approximations were made while computing the influence "
4184 printf(
" Please check the \"%s/Isles.log\" file.\n",
PPOutDir);
4187 clock_t stopSolveClock = clock();
4189 printf(
"to complete solve\n");
4193 clock_t startVoxelClock = clock();
4197 neBEMMessage(
"neBEMSolve - Failure computing VoxelFPR");
4201 clock_t stopVoxelClock = clock();
4203 printf(
"to compute VoxelFPR\n");
4208 clock_t startMapClock = clock();
4216 clock_t stopMapClock = clock();
4218 printf(
"to compute MapFPR\n");
4236 clock_t startFastClock = clock();
4254 printf(
"NbPtSkip: %d\n",
NbPtSkip);
4267 printf(
"NbOfXCells[%d]: %d\n", block,
BlkNbXCells[block]);
4268 printf(
"NbOfYCells[%d]: %d\n", block,
BlkNbYCells[block]);
4269 printf(
"NbOfZCells[%d]: %d\n", block,
BlkNbZCells[block]);
4270 printf(
"LZ[%d]: %le\n", block,
BlkLZ[block]);
4271 printf(
"CornerZ[%d]: %le\n", block,
BlkCrnrZ[block]);
4276 printf(
"OmitVolLX[%d]: %le\n", omit,
OmitVolLX[omit]);
4277 printf(
"OmitVolLY[%d]: %le\n", omit,
OmitVolLY[omit]);
4278 printf(
"OmitVolLZ[%d]: %le\n", omit,
OmitVolLZ[omit]);
4279 printf(
"OmitCrnrX[%d]: %le\n", omit,
OmitVolCrnrX[omit]);
4280 printf(
"OmitCrnrY[%d]: %le\n", omit,
OmitVolCrnrY[omit]);
4281 printf(
"OmitCrnrZ[%d]: %le\n", omit,
OmitVolCrnrZ[omit]);
4284 printf(
"MaxXCells, MaxYCells, MaxZCells: %d, %d, %d\n", MaxXCells,
4285 MaxYCells, MaxZCells);
4301 MaxYCells + 1, 1, MaxZCells + 1);
4303 MaxYCells + 1, 1, MaxZCells + 1);
4305 MaxYCells + 1, 1, MaxZCells + 1);
4307 MaxYCells + 1, 1, MaxZCells + 1);
4314 neBEMMessage(
"neBEMSolve - Failure computing FastVolPF");
4320 int nbXCells, nbYCells, nbZCells;
4322 double xpt, ypt, zpt;
4324 char FastVolPFFile[256];
4326 strcat(FastVolPFFile,
"/FastVolPF.out");
4327 FILE* fFastVolPF = fopen(FastVolPFFile,
"r");
4328 if (fFastVolPF == NULL) {
4333 fscanf(fFastVolPF,
"#block\tX\tY\tZ\tPot\tFX\tFY\tFZ\n");
4340 for (
int i = 1; i <= nbXCells + 1; ++i) {
4341 for (
int j = 1; j <= nbYCells + 1; ++j) {
4342 for (
int k = 1; k <= nbZCells + 1; ++k) {
4343 fscanf(fFastVolPF,
"%d\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n",
4344 &tmpblk, &xpt, &ypt, &zpt, &
FastPot[block][i][j][k],
4346 &
FastFZ[block][i][j][k]);
4354 char FastStgVolPFFile[256];
4355 strcpy(FastStgVolPFFile,
BCOutDir);
4356 strcat(FastStgVolPFFile,
"/FastStgVolPF.out");
4357 FILE *fFastStgVolPF = fopen(FastStgVolPFFile,
"r");
4358 if (fFastStgVolPF == NULL) {
4363 fscanf(fFastStgVolPF,
"#block\tX\tY\tZ\tPot\tFX\tFY\tFZ\n");
4370 for (
int i = 1; i <= nbXCells + 1; ++i) {
4371 for (
int j = 1; j <= nbYCells + 1; ++j) {
4372 for (
int k = 1; k <= nbZCells + 1; ++k) {
4373 fscanf(fFastStgVolPF,
"%d\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n",
4374 &tmpblk, &xpt, &ypt, &zpt, &
FastStgPot[block][i][j][k],
4381 fclose(fFastStgVolPF);
4385 clock_t stopFastClock = clock();
4387 printf(
"to compute / read FastVolPF\n");
4396 clock_t startFastClock = clock();
4433 printf(
"LZ[%d]: %le\n", block,
WtFldBlkLZ[block]);
4447 printf(
"MaxXCells, MaxYCells, MaxZCells: %d, %d, %d\n", MaxXCells,
4448 MaxYCells, MaxZCells);
4453 MaxYCells + 1, 1, MaxZCells + 1);
4455 MaxYCells + 1, 1, MaxZCells + 1);
4457 MaxYCells + 1, 1, MaxZCells + 1);
4459 MaxYCells + 1, 1, MaxZCells + 1);
4464 MaxYCells + 1, 1, MaxZCells + 1);
4466 MaxYCells + 1, 1, MaxZCells + 1);
4468 MaxYCells + 1, 1, MaxZCells + 1);
4470 MaxYCells + 1, 1, MaxZCells + 1);
4477 "neBEMSolve - Failure computing WtFldFastVolPF: not implemented");
4483 int nbXCells, nbYCells, nbZCells;
4485 double xpt, ypt, zpt;
4487 char FastVolPFFile[256];
4489 strcat(FastVolPFFile,
"/WtFldFastVolPF.out");
4490 FILE *fFastVolPF = fopen(FastVolPFFile,
"r");
4491 if (fFastVolPF == NULL) {
4496 fscanf(fFastVolPF,
"#block\tX\tY\tZ\tPot\tFX\tFY\tFZ\n");
4503 for (
int i = 1; i <= nbXCells + 1; ++i) {
4504 for (
int j = 1; j <= nbYCells + 1; ++j) {
4505 for (
int k = 1; k <= nbZCells + 1; ++k) {
4506 fscanf(fFastVolPF,
"%d\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n",
4507 &tmpblk, &xpt, &ypt, &zpt, &
WtFldFastPot[block][i][j][k],
4517 char FastStgVolPFFile[256];
4518 FILE *fFastStgVolPF;
4519 strcpy(FastStgVolPFFile,
BCOutDir);
4520 strcat(FastStgVolPFFile,
"/WtFldFastStgVolPF.out");
4521 fFastStgVolPF = fopen(FastStgVolPFFile,
"r");
4523 if (fFastStgVolPF == NULL) {
4528 fscanf(fFastStgVolPF,
"#block\tX\tY\tZ\tPot\tFX\tFY\tFZ\n");
4535 for (
int i = 1; i <= nbXCells + 1; ++i) {
4536 for (
int j = 1; j <= nbYCells + 1; ++j) {
4537 for (
int k = 1; k <= nbZCells + 1; ++k) {
4538 fscanf(fFastStgVolPF,
"%d\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n",
4539 &tmpblk, &xpt, &ypt, &zpt,
4548 fclose(fFastStgVolPF);
4552 clock_t stopFastClock = clock();
4554 printf(
"to compute / read FastVolPF\n");
4563 printf(
"neBEMField cannot be called before reaching state 9.\n");
4579 fstatus =
PFAtPoint(point, &Pot, field);
4606 static int IdWtField = 0;
4610 "neBEMPrepareWeightingField: Weighting computations only meaningful "
4611 "beyond neBEMState 7 ...\n");
4616 const int MaxWtField = 100;
4618 WtFieldChDen = (
double **)malloc(MaxWtField *
sizeof(
double *));
4620 AvWtChDen = (
double **)malloc(MaxWtField *
sizeof(
double *));
4623 if (IdWtField >= MaxWtField) {
4625 "neBEMPrepareWeightingField: reached MaxWtField weighting fields.\n");
4643 area += (
EleArr + ele - 1)->G.dA;
4652 neBEMMessage(
"neBEMPrepareWeightingField - WeightingFieldSolution");
4667 const int MaxWtField = 100;
4668 for (
int id = 1;
id < MaxWtField; ++id) {
4682 printf(
"neBEMWeightingField cannot be called before reaching state 9.\n");
4697 neBEMMessage(
"neBEMWeightingField - WtFldFastPFAtPoint");
4701 int fstatus =
WtPFAtPoint(point, &potential, field, IdWtField);
4713 double sumcharge = 0.0;
4716 for (
int elem = 1; elem <=
NbElements; ++elem) {
4718 int prim = (
EleArr + elem - 1)->PrimitiveNb;
4724 if (volref + 1 != volume) {
4735 if ((xrpt == 0) && (yrpt == 0) && (zrpt == 0))
4758 "IslesCntr: %d, ExactCntr: %d, FailureCntr: %d, ApproxCntr: %d\n",
4762 printf(
"neBEM ends ... bye!\n");
4775 char strModelCntr[10], strMeshCntr[10], strBCCntr[10], strPPCntr[10];
4779 sprintf(strModelCntr,
"/Model%d",
ModelCntr);
4780 sprintf(strMeshCntr,
"/M%d",
MeshCntr);
4781 sprintf(strBCCntr,
"/BC%d",
BCCntr);
4782 sprintf(strPPCntr,
"/PP%d",
PPCntr);
4861 strcat(subdir,
"/Primitives/");
4868 strcat(subdir,
"/Elements/");
4875 strcat(subdir,
"/GViewDir/");
4889 if (stat(dirname, &st) == 0)
4891 printf(
"Previous %s exists ... using the existing directory ... \n",
4894 sprintf(dirstr,
"mkdir -p %s", dirname);
4897 printf(
"Cannot create dirname %s ... returning ...\n", dirname);
4910 if (stat(dirname, &st) == 0)
4912 printf(
"Previous %s exists ... please check inputs and counters ... \n",
4916 sprintf(dirstr,
"mkdir -p %s", dirname);
4919 printf(
"Cannot create dirname %s ... returning ...\n", dirname);
4928 fprintf(stdout,
"neBEMMessage: %s\n", message);
4934 char PrimitiveFile[256];
4937 strcat(PrimitiveFile,
"/Primitives/StorePrims.out");
4939 FILE *fStrPrm = fopen(PrimitiveFile,
"w");
4940 if (fStrPrm == NULL) {
4941 neBEMMessage(
"WritePrimitives - Could not create file to store primitives");
4950 fprintf(fStrPrm,
"%d\n",
PrimType[prim]);
4954 for (
int vert = 0; vert <
NbVertices[prim]; ++vert) {
4955 fprintf(fStrPrm,
"%le %le %le\n",
XVertex[prim][vert],
4959 fprintf(fStrPrm,
"%le %le %le\n",
XNorm[prim],
YNorm[prim],
ZNorm[prim]);
4960 fprintf(fStrPrm,
"%le\n",
Radius[prim]);
4983 char ElementFile[256];
4986 strcat(ElementFile,
"/Elements/StoreElems.out");
4988 FILE *fStrEle = fopen(ElementFile,
"w");
4989 if (fStrEle == NULL) {
4990 neBEMMessage(
"WriteElements - Could not create file to store elements");
4998 fprintf(fStrEle,
"%d\n",
NbWireSeg[prim]);
5003 for (
int ele = 1; ele <=
NbElements; ++ele) {
5004 fprintf(fStrEle,
"%d %d %d %d %d\n", (
EleArr + ele - 1)->DeviceNb,
5005 (
EleArr + ele - 1)->ComponentNb, (
EleArr + ele - 1)->PrimitiveNb,
5006 (
EleArr + ele - 1)->InterfaceId, (
EleArr + ele - 1)->Id);
5007 fprintf(fStrEle,
"%d %le %le %le %le %le %le\n", (
EleArr + ele - 1)->G.Type,
5008 (
EleArr + ele - 1)->G.Origin.X, (
EleArr + ele - 1)->G.Origin.Y,
5009 (
EleArr + ele - 1)->G.Origin.Z, (
EleArr + ele - 1)->G.LX,
5011 fprintf(fStrEle,
"%le %le %le\n", (
EleArr + ele - 1)->G.DC.XUnit.X,
5012 (
EleArr + ele - 1)->G.DC.XUnit.Y, (
EleArr + ele - 1)->G.DC.XUnit.Z);
5013 fprintf(fStrEle,
"%le %le %le\n", (
EleArr + ele - 1)->G.DC.YUnit.X,
5014 (
EleArr + ele - 1)->G.DC.YUnit.Y, (
EleArr + ele - 1)->G.DC.YUnit.Z);
5015 fprintf(fStrEle,
"%le %le %le\n", (
EleArr + ele - 1)->G.DC.ZUnit.X,
5016 (
EleArr + ele - 1)->G.DC.ZUnit.Y, (
EleArr + ele - 1)->G.DC.ZUnit.Z);
5017 fprintf(fStrEle,
"%d %le\n", (
EleArr + ele - 1)->E.Type,
5018 (
EleArr + ele - 1)->E.Lambda);
5019 fprintf(fStrEle,
"%d %le %le %le %le\n", (
EleArr + ele - 1)->BC.NbOfBCs,
5020 (
EleArr + ele - 1)->BC.CollPt.X, (
EleArr + ele - 1)->BC.CollPt.Y,
5021 (
EleArr + ele - 1)->BC.CollPt.Z, (
EleArr + ele - 1)->BC.Value);
5023 (
EleArr + ele - 1)->Assigned);
5030 fprintf(fStrEle,
"%d %le\n", (
PointKnChArr + pt - 1)->Nb,
5032 fprintf(fStrEle,
"%le %le %le\n", (
PointKnChArr + pt - 1)->P.X,
5037 fprintf(fStrEle,
"%d %le %le\n", (
LineKnChArr + line - 1)->Nb,
5040 fprintf(fStrEle,
"%le %le %le\n", (
LineKnChArr + line - 1)->Start.X,
5043 fprintf(fStrEle,
"%le %le %le\n", (
LineKnChArr + line - 1)->Stop.X,
5048 fprintf(fStrEle,
"%d %d %le\n", (
AreaKnChArr + area - 1)->Nb,
5052 fprintf(fStrEle,
"%le %le %le\n",
5060 fprintf(fStrEle,
"%d %d %le\n", (
VolumeKnChArr + vol - 1)->Nb,
5064 fprintf(fStrEle,
"%le %le %le\n",
5079 char PrimitiveFile[256];
5082 strcat(PrimitiveFile,
"/Primitives/StorePrims.out");
5085 fStrPrm = fopen(PrimitiveFile,
"r");
5086 if (fStrPrm == NULL) {
5087 neBEMMessage(
"ReadPrimitives - Could not open file to read primitives");
5129 fscanf(fStrPrm,
"%d\n", &
PrimType[prim]);
5133 for (
int vert = 0; vert <
NbVertices[prim]; ++vert) {
5134 fscanf(fStrPrm,
"%le %le %le\n", &
XVertex[prim][vert],
5138 fscanf(fStrPrm,
"%le %le %le\n", &
XNorm[prim], &
YNorm[prim], &
ZNorm[prim]);
5139 fscanf(fStrPrm,
"%le\n", &
Radius[prim]);
5163 for (
int volref = 0; volref <=
VolMax; ++volref) {
5168 printf(
"volref: %d\n", volref);
5169 printf(
"shape: %d, material: %d\n",
volShape[volref],
5182 char ElementFile[256];
5185 strcat(ElementFile,
"/Elements/StoreElems.out");
5187 FILE *fStrEle = fopen(ElementFile,
"r");
5188 if (fStrEle == NULL) {
5189 neBEMMessage(
"ReadElements - Could not open file to read elements");
5197 fscanf(fStrEle,
"%d\n", &
NbWireSeg[prim]);
5210 printf(
"neBEMDiscretize: Re-allocating EleArr failed.\n");
5213 printf(
"neBEMDiscretize: Re-allocated EleArr.\n");
5223 neBEMMessage(
"neBEMDiscretize - EleArr malloc; neBEMState mismatch!");
5227 for (
int ele = 1; ele <=
NbElements; ++ele) {
5228 fscanf(fStrEle,
"%hd %d %d %d %d\n", &(
EleArr + ele - 1)->DeviceNb,
5229 &(
EleArr + ele - 1)->ComponentNb, &(
EleArr + ele - 1)->PrimitiveNb,
5230 &(
EleArr + ele - 1)->InterfaceId, &(
EleArr + ele - 1)->Id);
5231 fscanf(fStrEle,
"%hd %le %le %le %le %le %le\n",
5232 &(
EleArr + ele - 1)->G.Type, &(
EleArr + ele - 1)->G.Origin.X,
5233 &(
EleArr + ele - 1)->G.Origin.Y, &(
EleArr + ele - 1)->G.Origin.Z,
5235 &(
EleArr + ele - 1)->G.dA);
5236 fscanf(fStrEle,
"%le %le %le\n", &(
EleArr + ele - 1)->G.DC.XUnit.X,
5237 &(
EleArr + ele - 1)->G.DC.XUnit.Y,
5238 &(
EleArr + ele - 1)->G.DC.XUnit.Z);
5239 fscanf(fStrEle,
"%le %le %le\n", &(
EleArr + ele - 1)->G.DC.YUnit.X,
5240 &(
EleArr + ele - 1)->G.DC.YUnit.Y,
5241 &(
EleArr + ele - 1)->G.DC.YUnit.Z);
5242 fscanf(fStrEle,
"%le %le %le\n", &(
EleArr + ele - 1)->G.DC.ZUnit.X,
5243 &(
EleArr + ele - 1)->G.DC.ZUnit.Y,
5244 &(
EleArr + ele - 1)->G.DC.ZUnit.Z);
5245 fscanf(fStrEle,
"%hd %le\n", &(
EleArr + ele - 1)->E.Type,
5246 &(
EleArr + ele - 1)->E.Lambda);
5247 fscanf(fStrEle,
"%hd %le %le %le %le\n", &(
EleArr + ele - 1)->BC.NbOfBCs,
5248 &(
EleArr + ele - 1)->BC.CollPt.X, &(
EleArr + ele - 1)->BC.CollPt.Y,
5249 &(
EleArr + ele - 1)->BC.CollPt.Z, &(
EleArr + ele - 1)->BC.Value);
5251 &(
EleArr + ele - 1)->Assigned);
5258 fscanf(fStrEle,
"%d %le\n", &(
PointKnChArr + pt - 1)->Nb,
5260 fscanf(fStrEle,
"%le %le %le\n", &(
PointKnChArr + pt - 1)->P.X,
5265 fscanf(fStrEle,
"%d %le %le\n", &(
LineKnChArr + line - 1)->Nb,
5268 fscanf(fStrEle,
"%le %le %le\n", &(
LineKnChArr + line - 1)->Start.X,
5271 fscanf(fStrEle,
"%le %le %le\n", &(
LineKnChArr + line - 1)->Stop.X,
5277 fscanf(fStrEle,
"%d %d %le\n", &(
AreaKnChArr + area - 1)->Nb,
5281 fscanf(fStrEle,
"%le %le %le\n",
5289 fscanf(fStrEle,
"%d %d %le\n", &(
VolumeKnChArr + vol - 1)->Nb,
5293 fscanf(fStrEle,
"%le %le %le\n",
5307 double elapsedTime = ((double)(t1 - t0)) / CLOCKS_PER_SEC;
5308 printf(
"neBEMV%s TimeElapsed ===> %lg seconds ",
neBEMVersion, elapsedTime);
5310 return (elapsedTime);
5316 unsigned int number_of_lines = 0;
5318 FILE *infile = fopen(fname,
"r");
5321 while (EOF != (ch = getc(infile)))
5322 if (
'\n' == ch) ++number_of_lines;
5324 return number_of_lines;
5331 double anglesum = 0.0;
5338 for (
int i = 0; i < n; i++) {
5340 p1.
X = p[i].
X - q.
X;
5341 p1.
Y = p[i].
Y - q.
Y;
5342 p1.
Z = p[i].
Z - q.
Z;
5347 p2.
X = p[i + 1].
X - q.
X;
5348 p2.
Y = p[i + 1].
Y - q.
Y;
5349 p2.
Z = p[i + 1].
Z - q.
Z;
5351 p2.
X = p[0].
X - q.
X;
5352 p2.
Y = p[0].
Y - q.
Y;
5353 p2.
Z = p[0].
Z - q.
Z;
5360 if (m1 * m2 <= 1.0e-12) {
5364 double costheta = (p1.
X * p2.
X + p1.
Y * p2.
Y + p1.
Z * p2.
Z) / (m1 * m2);
5375 anglesum += acos(costheta);
int FastPFAtPoint(Point3D *globalP, double *Potential, Vector3D *globalF)
int WtPFAtPoint(Point3D *globalP, double *Potential, Vector3D *globalF, int IdWtField)
int PFAtPoint(Point3D *globalP, double *Potential, Vector3D *globalF)
int WtFldFastPFAtPoint(Point3D *globalP, double *Potential, Vector3D *globalF)
ISLESGLOBAL int ApproxCntr
ISLESGLOBAL int IslesCntr
ISLESGLOBAL FILE * fIsles
ISLESGLOBAL int FailureCntr
ISLESGLOBAL int ExactCntr
ISLESGLOBAL char ISLESVersion[10]
double GetDistancePoint3D(Point3D *a, Point3D *b)
int neBEMVolumeDescription(int vol, int *shape, int *material, double *epsilon, double *potential, double *charge, int *boundarytype)
Return information about a volume.
int neBEMGetInputsFromFiles(void)
Do-nothing function (no file inputs).
int neBEMSetDefaults(void)
Assign default values to some of the important global variables.
int neBEMGetMirror(int, int *ix, int *jx, double *sx, int *iy, int *jy, double *sy, int *iz, int *jz, double *sz)
int neBEMGetNbPrimitives()
Return the number of primitives.
int neBEMGetBoundingPlanes(int *ixmin, double *cxmin, double *vxmin, int *ixmax, double *cxmax, double *vxmax, int *iymin, double *cymin, double *vymin, int *iymax, double *cymax, double *vymax, int *izmin, double *czmin, double *vzmin, int *izmax, double *czmax, double *vzmax)
int neBEMGetPrimitive(int prim, int *nvertex, double xvert[], double yvert[], double zvert[], double *xnorm, double *ynorm, double *znorm, int *volref1, int *volref2)
Return one primitive at a time.
int neBEMGetPeriodicities(int, int *ix, int *jx, double *sx, int *iy, int *jy, double *sy, int *iz, int *jz, double *sz)
double neBEMVolumeCharge(int volume)
int neBEMBoundaryConditions(void)
int neBEMMessage(const char *message)
int CreateOrUseDir(char dirname[])
int neBEMDiscretize(int **NbElemsOnPrimitives)
int neBEMField(Point3D *point, double *potential, Vector3D *field)
int WritePrimitives(void)
int neBEMGetNbOfLines(const char fname[])
int neBEMReadGeometry(void)
double neBEMChkInPoly(int n, Point3D *p, Point3D q)
double neBEMTimeElapsed(clock_t t0, clock_t t1)
int neBEMInitialize(void)
int CreateDirOrQuit(char dirname[])
void neBEMDeleteAllWeightingFields(void)
void neBEMDeleteWeightingField(int IdWtField)
int neBEMPrepareWeightingField(int nprim, int primlist[])
int neBEMKnownCharges(void)
double neBEMWeightingField(Point3D *point, Vector3D *field, int IdWtField)
INTFACEGLOBAL clock_t stopClock
INTFACEGLOBAL FILE * fgnuPrim
INTFACEGLOBAL int NbThreads
INTFACEGLOBAL FILE * fgnuElem
INTFACEGLOBAL int neBEMState
INTFACEGLOBAL int OptPrintVolumeDetails
INTFACEGLOBAL FILE * fgnuMesh
INTFACEGLOBAL char DeviceInputFile[256]
INTFACEGLOBAL int OptDeviceFile
INTFACEGLOBAL int OptPrintPrimaryDetails
INTFACEGLOBAL clock_t startClock
INTFACEGLOBAL int OptGnuplot
INTFACEGLOBAL int OptReuseDir
int ComputeSolution(void)
int WeightingFieldSolution(int NbPrimsWtField, int PrimListWtField[], double solnarray[])
neBEMGLOBAL Element * EleArr
neBEMGLOBAL double * ApplPot
neBEMGLOBAL double **** FastFY
neBEMGLOBAL int DebugLevel
neBEMGLOBAL int NbVolumes
neBEMGLOBAL int * PeriodicInY
neBEMGLOBAL int * volMaterial
neBEMGLOBAL int OptWtFldReadFastPF
neBEMGLOBAL int OptStaggerFastVol
neBEMGLOBAL double **** FastFZ
neBEMGLOBAL int BoundaryConditions(void)
neBEMGLOBAL double **** WtFldFastStgFZ
neBEMGLOBAL int * NbElmntsOnPrim
neBEMGLOBAL double **** WtFldFastFZ
neBEMGLOBAL double **** FastStgFZ
neBEMGLOBAL double * ZNorm
neBEMGLOBAL char MeshOutDir[256]
neBEMGLOBAL int * MirrorTypeZ
neBEMGLOBAL double **** FastStgPot
neBEMGLOBAL double * OmitVolCrnrZ
neBEMGLOBAL double * MirrorDistYFromOrigin
neBEMGLOBAL int OptStorePrimitives
neBEMGLOBAL int MaxNbVertices
neBEMGLOBAL int * BndPlaneInYMax
neBEMGLOBAL double * XBndPlaneInXMax
neBEMGLOBAL int * WtFldBlkNbYCells
neBEMGLOBAL double * WtFldOmitVolLX
neBEMGLOBAL double ** ZVertex
neBEMGLOBAL double FixedWtFieldZ
neBEMGLOBAL int * NbWireSeg
neBEMGLOBAL double * YBndPlaneInYMin
neBEMGLOBAL int * NbSurfSegX
neBEMGLOBAL int OptWtFldFastVol
neBEMGLOBAL int ** OrgnlToEffPrim
neBEMGLOBAL double **** WtFldFastFX
neBEMGLOBAL double * ZPeriod
neBEMGLOBAL PointKnCh * PointKnChArr
neBEMGLOBAL double * OmitVolLX
neBEMGLOBAL char PPOutDir[256]
neBEMGLOBAL VolumeKnCh * VolumeKnChArr
neBEMGLOBAL int OptStaggerMap
neBEMGLOBAL char neBEMVersion[10]
neBEMGLOBAL double **** WtFldFastPot
neBEMGLOBAL double * WtFldOmitVolCrnrZ
neBEMGLOBAL int OptFormattedFile
neBEMGLOBAL int OptChargingUp
neBEMGLOBAL double * VBndPlaneInZMin
neBEMGLOBAL int * WtFldBlkNbXCells
neBEMGLOBAL int * BndPlaneInXMax
neBEMGLOBAL double * WtFldIgnoreVolCrnrX
neBEMGLOBAL double * XNorm
neBEMGLOBAL double * YBndPlaneInYMax
neBEMGLOBAL double * PrimOriginZ
neBEMGLOBAL double * BlkCrnrZ
neBEMGLOBAL int NbPrimitives
neBEMGLOBAL double **** FastStgFY
neBEMGLOBAL int * NbVertices
neBEMGLOBAL int WireElements(int prim, int nvertex, double xvert[], double yvert[], double zvert[], double radius, int volref1, int volref2, int inttype, double potential, double charge, double lambda, int NbWireSeg)
neBEMGLOBAL int AnalyzePrimitive(int, int *, int *)
neBEMGLOBAL int * PeriodicTypeX
neBEMGLOBAL int OptCreateFastPF
neBEMGLOBAL int NbElements
neBEMGLOBAL double * VBndPlaneInYMax
neBEMGLOBAL double * Lambda
neBEMGLOBAL double * ZBndPlaneInZMax
neBEMGLOBAL double * WtFldOmitVolCrnrY
neBEMGLOBAL int * PeriodicTypeY
neBEMGLOBAL int NbPointsKnCh
neBEMGLOBAL int OptWtFldStaggerFastVol
neBEMGLOBAL double * Epsilon1
neBEMGLOBAL FastAlgoVol FastVol
neBEMGLOBAL double ** YVertex
neBEMGLOBAL int * NbSurfSegZ
neBEMGLOBAL double * PrimOriginY
neBEMGLOBAL double * MirrorDistZFromOrigin
neBEMGLOBAL double * WtFldOmitVolLZ
neBEMGLOBAL AreaKnCh * AreaKnChArr
neBEMGLOBAL double **** WtFldFastStgPot
neBEMGLOBAL DirnCosn3D * PrimDC
neBEMGLOBAL int WtFldNbPtSkip
neBEMGLOBAL int * BndPlaneInZMin
neBEMGLOBAL int PrimAfter
neBEMGLOBAL double * VBndPlaneInXMin
neBEMGLOBAL double * BlkLZ
neBEMGLOBAL double * OmitVolCrnrX
neBEMGLOBAL int NbLinesKnCh
neBEMGLOBAL int NbFloatingConductors
neBEMGLOBAL double * OmitVolLZ
neBEMGLOBAL int NbStgPtSkip
neBEMGLOBAL int * VolRef1
neBEMGLOBAL double * XPeriod
neBEMGLOBAL double * volEpsilon
neBEMGLOBAL double * YNorm
neBEMGLOBAL char ModelOutDir[256]
neBEMGLOBAL int NbVolumesKnCh
neBEMGLOBAL double * volPotential
neBEMGLOBAL double ** XVertex
neBEMGLOBAL double * VBndPlaneInZMax
neBEMGLOBAL double * AvAsgndChDen
neBEMGLOBAL double * IgnoreVolCrnrY
neBEMGLOBAL double * XBndPlaneInXMin
neBEMGLOBAL double FixedWtFieldX
neBEMGLOBAL int OptWtFldCreateFastPF
neBEMGLOBAL int * VolRef2
neBEMGLOBAL char MapVersion[10]
neBEMGLOBAL double * WtFldIgnoreVolLZ
neBEMGLOBAL WtFldFastAlgoVol WtFldFastVol
neBEMGLOBAL double * OmitVolCrnrY
neBEMGLOBAL int * BndPlaneInXMin
neBEMGLOBAL char NativeOutDir[256]
neBEMGLOBAL int * MirrorTypeY
neBEMGLOBAL double **** FastFX
neBEMGLOBAL int NbAreasKnCh
neBEMGLOBAL int * ElementEnd
neBEMGLOBAL double **** WtFldFastFY
neBEMGLOBAL double * AvChDen
neBEMGLOBAL double * WtFldBlkLZ
neBEMGLOBAL int OptFastVol
neBEMGLOBAL double * WtFldBlkCrnrZ
neBEMGLOBAL double **** WtFldFastStgFY
neBEMGLOBAL double **** FastStgFX
neBEMGLOBAL double * Radius
neBEMGLOBAL int * MirrorTypeX
neBEMGLOBAL int * BndPlaneInZMax
neBEMGLOBAL int * InterfaceType
neBEMGLOBAL double * OmitVolLY
neBEMGLOBAL int * BlkNbXCells
neBEMGLOBAL int * PrimType
neBEMGLOBAL int OptReadFastPF
neBEMGLOBAL int * BndPlaneInYMin
neBEMGLOBAL double * PrimLX
neBEMGLOBAL int * BlkNbZCells
neBEMGLOBAL double * WtFldOmitVolLY
neBEMGLOBAL int * WtFldBlkNbZCells
neBEMGLOBAL double FixedWtFieldY
neBEMGLOBAL double * Solution
neBEMGLOBAL int * ElementBgn
neBEMGLOBAL double * PrimOriginX
neBEMGLOBAL int WtFldNbStgPtSkip
neBEMGLOBAL double ** AvWtChDen
neBEMGLOBAL double * IgnoreVolLY
neBEMGLOBAL double FixedWtPotential
neBEMGLOBAL double * WtFldIgnoreVolCrnrY
neBEMGLOBAL double * IgnoreVolLX
neBEMGLOBAL int * PeriodicInZ
neBEMGLOBAL int * PeriodicInX
neBEMGLOBAL double * WtFldIgnoreVolCrnrZ
neBEMGLOBAL double * WtFldIgnoreVolLY
neBEMGLOBAL int OptUnformattedFile
neBEMGLOBAL double LengthScale
neBEMGLOBAL int OptFixedWtField
neBEMGLOBAL double * ZBndPlaneInZMin
neBEMGLOBAL FILE * fMeshLog
neBEMGLOBAL double * IgnoreVolLZ
neBEMGLOBAL double * WtFldOmitVolCrnrX
neBEMGLOBAL double * VBndPlaneInYMin
neBEMGLOBAL int SurfaceElements(int prim, int nvertex, double xvert[], double yvert[], double zvert[], double xnorm, double ynorm, double znorm, int volref1, int volref2, int inttype, double potential, double charge, double lambda, int NbSegX, int NbSegZ)
neBEMGLOBAL double * volCharge
neBEMGLOBAL double **** WtFldFastStgFX
neBEMGLOBAL VoxelVol Voxel
neBEMGLOBAL double ** WtFieldChDen
neBEMGLOBAL double * WtFldIgnoreVolLX
neBEMGLOBAL int OrgnlNbPrimitives
neBEMGLOBAL int * volBoundaryType
neBEMGLOBAL int ModelCntr
neBEMGLOBAL int * PeriodicTypeZ
neBEMGLOBAL char NativePrimDir[256]
neBEMGLOBAL LineKnCh * LineKnChArr
neBEMGLOBAL double **** FastPot
neBEMGLOBAL char DeviceOutDir[256]
neBEMGLOBAL int OptStoreElements
neBEMGLOBAL double * IgnoreVolCrnrX
neBEMGLOBAL char BCOutDir[256]
neBEMGLOBAL double * YPeriod
neBEMGLOBAL double * PrimLZ
neBEMGLOBAL int * volShape
neBEMGLOBAL double * MirrorDistXFromOrigin
neBEMGLOBAL double * VBndPlaneInXMax
neBEMGLOBAL double * Epsilon2
neBEMGLOBAL double * ApplCh
neBEMGLOBAL double * IgnoreVolCrnrZ
neBEMGLOBAL int * BlkNbYCells
neBEMGLOBAL int OptStaggerVoxel
double **** d4tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh, long nwl, long nwh)
int * ivector(long nl, long nh)
double ** dmatrix(long nrl, long nrh, long ncl, long nch)
int ** imatrix(long nrl, long nrh, long ncl, long nch)
double * dvector(long nl, long nh)