408 double zvert[],
double radius,
int volref1,
int volref2,
409 int inttype,
double potential,
double charge,
double lambda,
411 int WireParentObj, WireEType;
413 double WireLambda, WireV;
414 double WireElX, WireElY, WireElZ, WireElL;
418 FILE *fPrim, *fElem, *fgpPrim, *fgpElem;
422 neBEMMessage(
"DiscretizeWire - PrimType in DiscretizeWire");
426 neBEMMessage(
"DiscretizeWire - nvertex in DiscretizeWire");
430 neBEMMessage(
"DiscretizeWire - radius in DiscretizeWire");
434 neBEMMessage(
"DiscretizeWire - NbSegs in DiscretizeWire");
439 printf(
"nvertex: %d\n", nvertex);
440 for (
int vert = 0; vert < nvertex; ++vert) {
441 printf(
"vert: %d, x: %lg, y: %lg, z: %lg\n", vert, xvert[vert],
442 yvert[vert], zvert[vert]);
444 printf(
"radius: %lg\n", radius);
449 snprintf(primstr, 10,
"%d", prim);
458 WireL = sqrt((xvert[1] - xvert[0]) * (xvert[1] - xvert[0])
459 + (yvert[1] - yvert[0]) * (yvert[1] - yvert[0]) +
460 (zvert[1] - zvert[0]) * (zvert[1] - zvert[0]));
462 WireElL = WireL / NbSegs;
467 PrimDirnCosn.
ZUnit.
X = (xvert[1] - xvert[0]) / WireL;
468 PrimDirnCosn.
ZUnit.
Y = (yvert[1] - yvert[0]) / WireL;
469 PrimDirnCosn.
ZUnit.
Z = (zvert[1] - zvert[0]) / WireL;
487 ZUnit.
X = PrimDirnCosn.
ZUnit.
X;
488 ZUnit.
Y = PrimDirnCosn.
ZUnit.
Y;
489 ZUnit.
Z = PrimDirnCosn.
ZUnit.
Z;
521 if (fabs(ZUnit.
X) >= fabs(ZUnit.
Z) && fabs(ZUnit.
Y) >= fabs(ZUnit.
Z)) {
525 }
else if (fabs(ZUnit.
X) >= fabs(ZUnit.
Y) &&
526 fabs(ZUnit.
Z) >= fabs(ZUnit.
Y)) {
542 PrimDirnCosn.
XUnit.
X = XUnit.
X;
543 PrimDirnCosn.
XUnit.
Y = XUnit.
Y;
544 PrimDirnCosn.
XUnit.
Z = XUnit.
Z;
545 PrimDirnCosn.
YUnit.
X = YUnit.
X;
546 PrimDirnCosn.
YUnit.
Y = YUnit.
Y;
547 PrimDirnCosn.
YUnit.
Z = YUnit.
Z;
576 strcat(OutPrim,
"/Primitives/Primitive");
577 strcat(OutPrim, primstr);
578 strcat(OutPrim,
".out");
579 fPrim = fopen(OutPrim,
"w");
584 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
585 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
586 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
587 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
589 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
590 fprintf(fPrim,
"#DirnCosn: \n");
591 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
593 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
595 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
597 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
598 fprintf(fPrim,
"#NbSegs: %d\n", NbSegs);
599 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", WireParentObj, WireEType);
600 fprintf(fPrim,
"#WireR: %lg\tWireL: %lg\n", WireR, WireL);
601 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", WireLambda, WireV);
608 strcat(gpPrim,
"/GViewDir/gpPrim");
609 strcat(gpPrim, primstr);
610 strcat(gpPrim,
".out");
611 fgpPrim = fopen(gpPrim,
"w");
612 if (fgpPrim == NULL) {
617 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[0], yvert[0], zvert[0]);
618 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[1], yvert[1], zvert[1]);
622 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
624 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
631 strcat(OutElem,
"/Elements/ElemOnPrim");
632 strcat(OutElem, primstr);
633 strcat(OutElem,
".out");
634 fElem = fopen(OutElem,
"w");
643 strcat(gpElem,
"/GViewDir/gpElemOnPrim");
644 strcat(gpElem, primstr);
645 strcat(gpElem,
".out");
646 fgpElem = fopen(gpElem,
"w");
647 if (fgpElem == NULL) {
649 if (fElem) fclose(fElem);
654 double xincr = (xvert[1] - xvert[0]) / (
double)NbSegs;
655 double yincr = (yvert[1] - yvert[0]) / (
double)NbSegs;
656 double zincr = (zvert[1] - zvert[0]) / (
double)NbSegs;
659 double xv0, yv0, zv0, xv1, yv1, zv1;
660 for (
int seg = 1; seg <= NbSegs; ++seg) {
661 xv0 = xvert[0] + ((double)seg - 1.0) * xincr;
662 yv0 = yvert[0] + ((double)seg - 1.0) * yincr;
663 zv0 = zvert[0] + ((double)seg - 1.0) * zincr;
664 xv1 = xvert[0] + ((double)seg) * xincr;
665 yv1 = yvert[0] + ((double)seg) * yincr;
666 zv1 = zvert[0] + ((double)seg) * zincr;
667 WireElX = xvert[0] + ((double)seg - 1.0) * xincr + 0.5 * xincr;
668 WireElY = yvert[0] + ((double)seg - 1.0) * yincr + 0.5 * yincr;
669 WireElZ = zvert[0] + ((double)seg - 1.0) * zincr + 0.5 * zincr;
675 neBEMMessage(
"DiscretizeWire - EleCntr more than NbElements!");
676 if (fgpElem) fclose(fgpElem);
677 if (fElem) fclose(fElem);
726 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
727 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
728 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
731 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
732 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\n",
738 fprintf(fElem,
"#DirnCosn: \n");
739 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
742 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
745 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
748 fprintf(fElem,
"#EType\tLambda\n");
751 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
752 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%lg\n",
762 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
772 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
774 fprintf(fPrim,
"Number of elements on primitive: %d\n",
789 double zvert[],
double xnorm,
double ynorm,
double znorm,
790 int volref1,
int volref2,
int inttype,
double potential,
791 double charge,
double lambda,
int NbSegX,
int NbSegZ) {
792 int SurfParentObj, SurfEType;
793 double SurfX, SurfY, SurfZ, SurfLX, SurfLZ;
794 double SurfElX, SurfElY, SurfElZ, SurfElLX, SurfElLZ;
797 char gpElem[256], gpMesh[256];
798 FILE *fPrim, *fElem, *fgpPrim, *fgpElem, *fgpMesh;
801 if ((NbSegX <= 0) || (NbSegZ <= 0)) {
802 printf(
"segmentation input wrong in DiscretizeTriangle ...\n");
807 printf(
"nvertex: %d\n", nvertex);
808 for (
int vert = 0; vert < nvertex; ++vert) {
809 printf(
"vert: %d, x: %lg, y: %lg, z: %lg\n", vert, xvert[vert],
810 yvert[vert], zvert[vert]);
812 printf(
"Normal: %lg, %lg, %lg\n", xnorm, ynorm, znorm);
817 snprintf(primstr, 10,
"%d", prim);
829 if ((SurfEType <= 0) || (SurfEType >= 8)) {
830 printf(
"Wrong SurfEType for prim %d\n", prim);
844 SurfLX = sqrt((xvert[0] - xvert[1]) * (xvert[0] - xvert[1]) +
845 (yvert[0] - yvert[1]) * (yvert[0] - yvert[1]) +
846 (zvert[0] - zvert[1]) * (zvert[0] - zvert[1]));
847 SurfLZ = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
848 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
849 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
851 PrimDirnCosn.
XUnit.
X = (xvert[0] - xvert[1]) / SurfLX;
852 PrimDirnCosn.
XUnit.
Y = (yvert[0] - yvert[1]) / SurfLX;
853 PrimDirnCosn.
XUnit.
Z = (zvert[0] - zvert[1]) / SurfLX;
854 PrimDirnCosn.
ZUnit.
X = (xvert[2] - xvert[1]) / SurfLZ;
855 PrimDirnCosn.
ZUnit.
Y = (yvert[2] - yvert[1]) / SurfLZ;
856 PrimDirnCosn.
ZUnit.
Z = (zvert[2] - zvert[1]) / SurfLZ;
859 if ((fabs(PrimDirnCosn.
YUnit.
X - xnorm) <= 1.0e-3) &&
860 (fabs(PrimDirnCosn.
YUnit.
Y - ynorm) <= 1.0e-3) &&
861 (fabs(PrimDirnCosn.
YUnit.
Z - znorm) <= 1.0e-3))
864 printf(
"First attempt: \n");
871 SurfLX = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
872 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
873 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
874 SurfLZ = sqrt((xvert[0] - xvert[1]) * (xvert[0] - xvert[1]) +
875 (yvert[0] - yvert[1]) * (yvert[0] - yvert[1]) +
876 (zvert[0] - zvert[1]) * (zvert[0] - zvert[1]));
878 PrimDirnCosn.
XUnit.
X = (xvert[2] - xvert[1]) / SurfLX;
879 PrimDirnCosn.
XUnit.
Y = (yvert[2] - yvert[1]) / SurfLX;
880 PrimDirnCosn.
XUnit.
Z = (zvert[2] - zvert[1]) / SurfLX;
881 PrimDirnCosn.
ZUnit.
X = (xvert[0] - xvert[1]) / SurfLZ;
882 PrimDirnCosn.
ZUnit.
Y = (yvert[0] - yvert[1]) / SurfLZ;
883 PrimDirnCosn.
ZUnit.
Z = (zvert[0] - zvert[1]) / SurfLZ;
886 if ((fabs(PrimDirnCosn.
YUnit.
X - xnorm) <= 1.0e-3) &&
887 (fabs(PrimDirnCosn.
YUnit.
Y - ynorm) <= 1.0e-3) &&
888 (fabs(PrimDirnCosn.
YUnit.
Z - znorm) <= 1.0e-3))
891 printf(
"Second attempt: \n");
899 printf(
"Triangle DC problem ... returning ...\n");
922 int tmpVolRef1 =
VolRef1[prim];
930 double SurfLambda = lambda;
931 double SurfV = potential;
937 strcat(OutPrim,
"/Primitives/Primitive");
938 strcat(OutPrim, primstr);
939 strcat(OutPrim,
".out");
940 fPrim = fopen(OutPrim,
"w");
945 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
946 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
947 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
948 fprintf(fPrim,
"Node3: %lg\t%lg\t%lg\n", xvert[2], yvert[2], zvert[2]);
949 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
951 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
952 fprintf(fPrim,
"Norm: %lg\t%lg\t%lg\n", xnorm, ynorm, znorm);
953 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
954 fprintf(fPrim,
"#NbSegX: %d, NbSegZ: %d (check note!)\n", NbSegX, NbSegZ);
955 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", SurfParentObj, SurfEType);
956 fprintf(fPrim,
"#SurfX\tSurfY\tSurfZ\tSurfLX\tSurfLZ (Rt. Corner)\n");
957 fprintf(fPrim,
"%lg\t%lg\t%lg\t%lg\t%lg\n", SurfX, SurfY, SurfZ, SurfLX,
959 fprintf(fPrim,
"#DirnCosn: \n");
960 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
962 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
964 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
966 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", SurfLambda, SurfV);
973 strcat(gpPrim,
"/GViewDir/gpPrim");
974 strcat(gpPrim, primstr);
975 strcat(gpPrim,
".out");
976 fgpPrim = fopen(gpPrim,
"w");
977 if (fgpPrim == NULL) {
982 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[0], yvert[0], zvert[0]);
983 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[1], yvert[1], zvert[1]);
984 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[2], yvert[2], zvert[2]);
985 fprintf(fgpPrim,
"%g\t%g\t%g\n", xvert[0], yvert[0], zvert[0]);
989 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
991 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
998 strcat(OutElem,
"/Elements/ElemOnPrim");
999 strcat(OutElem, primstr);
1000 strcat(OutElem,
".out");
1001 fElem = fopen(OutElem,
"w");
1002 if (fElem == NULL) {
1010 strcat(gpElem,
"/GViewDir/gpElemOnPrim");
1011 strcat(gpElem, primstr);
1012 strcat(gpElem,
".out");
1013 fgpElem = fopen(gpElem,
"w");
1015 if (fgpElem == NULL) {
1017 if (fElem) fclose(fElem);
1022 strcat(gpMesh,
"/GViewDir/gpMeshOnPrim");
1023 strcat(gpMesh, primstr);
1024 strcat(gpMesh,
".out");
1025 fgpMesh = fopen(gpMesh,
"w");
1026 if (fgpMesh == NULL) {
1029 if (fElem) fclose(fElem);
1050 if (NbSegX == NbSegZ) {
1051 SurfElLX = SurfLX / NbSegX;
1052 SurfElLZ = SurfLZ / NbSegZ;
1053 }
else if (NbSegX > NbSegZ) {
1054 if (SurfLX > SurfLZ) {
1055 SurfElLX = SurfLX / NbSegX;
1056 SurfElLZ = SurfLZ / NbSegZ;
1062 SurfElLX = SurfLX / NbSegX;
1063 SurfElLZ = SurfLZ / NbSegZ;
1068 if (SurfLX < SurfLZ) {
1069 SurfElLX = SurfLX / NbSegX;
1070 SurfElLZ = SurfLZ / NbSegZ;
1076 SurfElLX = SurfLX / NbSegX;
1077 SurfElLZ = SurfLZ / NbSegZ;
1086 double AR = SurfElLX / SurfElLZ;
1089 "Using the input, the aspect ratio of the elements on prim: %d\n",
1092 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1093 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1097 double tmpElLZ = SurfElLX / 10.0;
1098 NbSegZ = (int)(SurfLZ / tmpElLZ);
1099 if (NbSegZ <= 0) NbSegZ = 1;
1100 SurfElLZ = SurfLZ / NbSegZ;
1104 double tmpElLX = SurfElLZ * 0.1;
1105 NbSegX = (int)(SurfLX / tmpElLX);
1106 if (NbSegX <= 0) NbSegX = 1;
1107 SurfElLX = SurfLX / NbSegX;
1109 AR = SurfElLX / SurfElLZ;
1111 fprintf(fPrim,
"After analyzing the likely aspect ratio of the elements\n");
1113 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1114 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1126 double xv0, yv0, zv0, xv1, yv1, zv1, xv2, yv2, zv2;
1128 for (
int k = 1; k <= NbSegZ; ++k)
1130 double grad = (SurfLZ / SurfLX);
1131 double zlopt = (k - 1) * SurfElLZ;
1132 double zhipt = (k)*SurfElLZ;
1133 double xlopt = (SurfLZ - zlopt) / grad;
1134 double xhipt = (SurfLZ - zhipt) / grad;
1137 double xtorigin = xhipt;
1138 double ytorigin = 0.0;
1139 double ztorigin = zlopt;
1141 Point3D localDisp, globalDisp;
1143 localDisp.
X = xtorigin;
1144 localDisp.
Y = ytorigin;
1145 localDisp.
Z = ztorigin;
1148 SurfX + globalDisp.
X;
1150 SurfY + globalDisp.
Y;
1151 SurfElZ = SurfZ + globalDisp.
Z;
1157 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 1!");
1158 if (fgpElem) fclose(fgpElem);
1159 if (fgpMesh) fclose(fgpMesh);
1230 printf(
"Primitive nb: %d\n", (
EleArr +
EleCntr - 1)->PrimitiveNb);
1232 printf(
"Element X, Y, Z: %lg %lg %lg\n",
1236 printf(
"Element LX, LZ: %lg %lg\n", (
EleArr +
EleCntr - 1)->G.LX,
1238 printf(
"Element (primitive) X axis dirn cosines: %lg, %lg, %lg\n",
1240 printf(
"Element (primitive) Y axis dirn cosines: %lg, %lg, %lg\n",
1242 printf(
"Element (primitive) Z axis dirn cosines: %lg, %lg, %lg\n",
1250 Point3D localDisp, globalDisp;
1256 printf(
"Element dxl, dxy, dxz: %lg %lg %lg\n", localDisp.
X, localDisp.
Y,
1268 printf(
"Element global dxl, dxy, dxz: %lg %lg %lg\n", globalDisp.
X,
1269 globalDisp.
Y, globalDisp.
Z);
1270 printf(
"Element BCX, BCY, BCZ: %lg %lg %lg\n",
1279 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
1280 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
1281 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
1284 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
1285 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\n",
1291 fprintf(fElem,
"#DirnCosn: \n");
1292 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
1295 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
1298 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
1301 fprintf(fElem,
"#EType\tLambda\n");
1304 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
1305 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%lg\n",
1315 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1331 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv0, yv0, zv0);
1332 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv1, yv1, zv1);
1333 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv2, yv2, zv2);
1334 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", xv0, yv0, zv0);
1342 double RowLX = xhipt;
1343 int NbSegXOnThisRow;
1344 double ElLXOnThisRow;
1345 if (RowLX <= SurfElLX) {
1346 NbSegXOnThisRow = 1;
1347 ElLXOnThisRow = RowLX;
1349 NbSegXOnThisRow = (int)(RowLX / SurfElLX);
1350 ElLXOnThisRow = RowLX / NbSegXOnThisRow;
1352 double x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3;
1353 for (
int i = 1; i <= NbSegXOnThisRow; ++i) {
1354 double xorigin = (i - 1) * ElLXOnThisRow + 0.5 * ElLXOnThisRow;
1355 double yorigin = 0.0;
1356 double zorigin = 0.5 * (zlopt + zhipt);
1363 Point3D localDisp, globalDisp;
1365 localDisp.
X = xorigin;
1366 localDisp.
Y = yorigin;
1367 localDisp.
Z = zorigin;
1369 SurfElX = SurfX + globalDisp.
X;
1370 SurfElY = SurfY + globalDisp.
Y;
1371 SurfElZ = SurfZ + globalDisp.
Z;
1381 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 2!");
1433 Point3D localDisp, globalDisp;
1449 Point3D localDisp, globalDisp;
1464 Point3D localDisp, globalDisp;
1479 Point3D localDisp, globalDisp;
1505 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
1506 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
1507 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
1511 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
1513 fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\n",
1518 fprintf(fElem,
"#DirnCosn: \n");
1519 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
1522 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
1525 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
1528 fprintf(fElem,
"#EType\tLambda\n");
1531 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
1532 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%lg\n",
1542 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1548 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
1549 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x1, y1, z1);
1550 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x2, y2, z2);
1551 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x3, y3, z3);
1552 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
1560 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
1562 fprintf(fPrim,
"Number of elements on primitive: %d\n",
1569 fprintf(
fgnuElem,
" '%s\' w p", gpElem);
1571 fprintf(
fgnuElem,
", \\\n \'%s\' w p", gpElem);
1573 fprintf(
fgnuMesh,
" '%s\' w l", gpMesh);
1574 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1576 fprintf(
fgnuMesh,
", \\\n \'%s\' w l", gpMesh);
1577 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1593 double zvert[],
double xnorm,
double ynorm,
1594 double znorm,
int volref1,
int volref2,
int inttype,
1595 double potential,
double charge,
double lambda,
1596 int NbSegX,
int NbSegZ) {
1597 int SurfParentObj, SurfEType;
1598 double SurfX, SurfY, SurfZ, SurfLX, SurfLZ;
1599 double SurfElX, SurfElY, SurfElZ, SurfElLX, SurfElLZ;
1602 char gpElem[256], gpMesh[256];
1603 FILE *fPrim, *fElem, *fgpPrim, *fgpElem, *fgpMesh;
1606 if ((NbSegX <= 0) || (NbSegZ <= 0)) {
1607 printf(
"segmentation input wrong in DiscretizeRectangle ...\n");
1612 printf(
"nvertex: %d\n", nvertex);
1613 for (
int vert = 0; vert < nvertex; ++vert) {
1614 printf(
"vert: %d, x: %lg, y: %lg, z: %lg\n", vert, xvert[vert],
1615 yvert[vert], zvert[vert]);
1617 printf(
"Normal: %lg, %lg, %lg\n", xnorm, ynorm, znorm);
1622 snprintf(primstr, 10,
"%d", prim);
1638 SurfEType = inttype;
1639 if (SurfEType == 0) {
1640 printf(
"Wrong SurfEType for prim %d\n", prim);
1644 SurfX = 0.25 * (xvert[0] + xvert[1] + xvert[2] + xvert[3]);
1645 SurfY = 0.25 * (yvert[0] + yvert[1] + yvert[2] + yvert[3]);
1646 SurfZ = 0.25 * (zvert[0] + zvert[1] + zvert[2] + zvert[3]);
1648 SurfLX = sqrt((xvert[1] - xvert[0]) * (xvert[1] - xvert[0]) +
1649 (yvert[1] - yvert[0]) * (yvert[1] - yvert[0]) +
1650 (zvert[1] - zvert[0]) * (zvert[1] - zvert[0]));
1651 SurfLZ = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
1652 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
1653 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
1655 PrimDirnCosn.
XUnit.
X = (xvert[1] - xvert[0]) / SurfLX;
1656 PrimDirnCosn.
XUnit.
Y = (yvert[1] - yvert[0]) / SurfLX;
1657 PrimDirnCosn.
XUnit.
Z = (zvert[1] - zvert[0]) / SurfLX;
1658 PrimDirnCosn.
YUnit.
X = xnorm;
1659 PrimDirnCosn.
YUnit.
Y = ynorm;
1660 PrimDirnCosn.
YUnit.
Z = znorm;
1661 PrimDirnCosn.
ZUnit =
1682 double SurfLambda = lambda;
1683 double SurfV = potential;
1689 strcat(OutPrim,
"/Primitives/Primitive");
1690 strcat(OutPrim, primstr);
1691 strcat(OutPrim,
".out");
1692 fPrim = fopen(OutPrim,
"w");
1693 if (fPrim == NULL) {
1697 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
1698 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
1699 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
1700 fprintf(fPrim,
"Node3: %lg\t%lg\t%lg\n", xvert[2], yvert[2], zvert[2]);
1701 fprintf(fPrim,
"Node4: %lg\t%lg\t%lg\n", xvert[3], yvert[3], zvert[3]);
1702 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
1704 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
1705 fprintf(fPrim,
"Norm: %lg\t%lg\t%lg\n", xnorm, ynorm, znorm);
1706 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
1707 fprintf(fPrim,
"#NbSegX: %d, NbSegZ: %d\n", NbSegX, NbSegZ);
1708 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", SurfParentObj, SurfEType);
1709 fprintf(fPrim,
"#SurfX\tSurfY\tSurfZ\tSurfLZ\tSurfLZ\n");
1710 fprintf(fPrim,
"%lg\t%lg\t%lg\t%lg\t%lg\n", SurfX, SurfY, SurfZ, SurfLX,
1714 fprintf(fPrim,
"#DirnCosn: \n");
1715 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
1717 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
1719 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
1721 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", SurfLambda, SurfV);
1728 strcat(gpPrim,
"/GViewDir/gpPrim");
1729 strcat(gpPrim, primstr);
1730 strcat(gpPrim,
".out");
1731 fgpPrim = fopen(gpPrim,
"w");
1732 if (fgpPrim == NULL) {
1737 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[0], yvert[0], zvert[0]);
1738 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[1], yvert[1], zvert[1]);
1739 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[2], yvert[2], zvert[2]);
1740 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[3], yvert[3], zvert[3]);
1741 fprintf(fgpPrim,
"%g\t%g\t%g\n", xvert[0], yvert[0], zvert[0]);
1745 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
1747 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
1754 strcat(OutElem,
"/Elements/ElemOnPrim");
1755 strcat(OutElem, primstr);
1756 strcat(OutElem,
".out");
1757 fElem = fopen(OutElem,
"w");
1759 if (fElem == NULL) {
1768 strcat(gpElem,
"/GViewDir/gpElemOnPrim");
1769 strcat(gpElem, primstr);
1770 strcat(gpElem,
".out");
1771 fgpElem = fopen(gpElem,
"w");
1773 if (fgpElem == NULL) {
1775 if (fElem) fclose(fElem);
1780 strcat(gpMesh,
"/GViewDir/gpMeshOnPrim");
1781 strcat(gpMesh, primstr);
1782 strcat(gpMesh,
".out");
1783 fgpMesh = fopen(gpMesh,
"w");
1784 if (fgpMesh == NULL) {
1803 if (NbSegX == NbSegZ) {
1804 SurfElLX = SurfLX / NbSegX;
1805 SurfElLZ = SurfLZ / NbSegZ;
1806 }
else if (NbSegX > NbSegZ) {
1807 if (SurfLX > SurfLZ) {
1808 SurfElLX = SurfLX / NbSegX;
1809 SurfElLZ = SurfLZ / NbSegZ;
1815 SurfElLX = SurfLX / NbSegX;
1816 SurfElLZ = SurfLZ / NbSegZ;
1821 if (SurfLX < SurfLZ) {
1822 SurfElLX = SurfLX / NbSegX;
1823 SurfElLZ = SurfLZ / NbSegZ;
1829 SurfElLX = SurfLX / NbSegX;
1830 SurfElLZ = SurfLZ / NbSegZ;
1839 double AR = SurfElLX / SurfElLZ;
1842 "Using the input, the aspect ratio of the elements on prim: %d\n",
1845 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1846 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1850 double tmpElLZ = SurfElLX / 10.0;
1851 NbSegZ = (int)(SurfLZ / tmpElLZ);
1852 if (NbSegZ <= 0) NbSegZ = 1;
1853 SurfElLZ = SurfLZ / NbSegZ;
1857 double tmpElLX = SurfElLZ * 0.1;
1858 NbSegX = (int)(SurfLX / tmpElLX);
1859 if (NbSegX <= 0) NbSegX = 1;
1860 SurfElLX = SurfLX / NbSegX;
1862 AR = SurfElLX / SurfElLZ;
1864 fprintf(fPrim,
"After analyzing the aspect ratio of the elements\n");
1866 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1867 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1870 double x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3, xav, zav;
1872 for (
int i = 1; i <= NbSegX; ++i) {
1873 x1 = -SurfLX / 2.0 +
1874 (double)(i - 1) * SurfElLX;
1875 x2 = -SurfLX / 2.0 + (double)(i)*SurfElLX;
1876 xav = 0.5 * (x1 + x2);
1878 for (
int k = 1; k <= NbSegZ; ++k) {
1879 z1 = -SurfLZ / 2.0 + (double)(k - 1) * SurfElLZ;
1880 z2 = -SurfLZ / 2.0 + (double)(k)*SurfElLZ;
1881 zav = 0.5 * (z1 + z2);
1884 Point3D localDisp, globalDisp;
1890 SurfElX = SurfX + globalDisp.
X;
1891 SurfElY = SurfY + globalDisp.
Y;
1892 SurfElZ = SurfZ + globalDisp.
Z;
1898 neBEMMessage(
"DiscretizeRectangle - EleCntr more than NbElements!");
1899 if (fgpMesh) fclose(fgpMesh);
1944 Point3D localDisp, globalDisp;
1960 Point3D localDisp, globalDisp;
1975 Point3D localDisp, globalDisp;
1990 Point3D localDisp, globalDisp;
2016 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
2017 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
2018 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
2022 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
2024 fElem,
"%d\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\n",
2029 fprintf(fElem,
"#DirnCosn: \n");
2030 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
2033 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
2036 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
2039 fprintf(fElem,
"#EType\tLambda\n");
2042 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
2043 fprintf(fElem,
"%d\t%lg\t%lg\t%lg\t%lg\n",
2053 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
2059 fprintf(fgpMesh,
"%g\t%g\t%g\n", x0, y0, z0);
2060 fprintf(fgpMesh,
"%g\t%g\t%g\n", x1, y1, z1);
2061 fprintf(fgpMesh,
"%g\t%g\t%g\n", x2, y2, z2);
2062 fprintf(fgpMesh,
"%g\t%g\t%g\n", x3, y3, z3);
2063 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
2081 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
2083 fprintf(fPrim,
"Number of elements on primitive: %d\n",
2092 fprintf(
fgnuElem,
" '%s\' w p", gpElem);
2094 fprintf(
fgnuElem,
", \\\n \'%s\' w p", gpElem);
2096 fprintf(
fgnuMesh,
" '%s\' w l", gpMesh);
2097 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
2099 fprintf(
fgnuMesh,
", \\\n \'%s\' w l", gpMesh);
2100 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
2243 FILE *KnChInpFile = fopen(
"neBEMInp/neBEMKnCh.inp",
"r");
2244 if (KnChInpFile == NULL) {
2247 "neBEMKnCh.inp absent ... assuming absence of known charges ...\n");
2249 fscanf(KnChInpFile,
"OptKnCh: %d\n", &
OptKnCh);
2250 if (1) printf(
"OptKnCh: %d\n",
OptKnCh);
2252 if (!
OptKnCh) printf(
"OptKnCh = 0 ... assuming no known charges ...\n");
2255 char PointKnChFile[256];
2256 char LineKnChFile[256];
2257 char AreaKnChFile[256];
2258 char VolumeKnChFile[256];
2259 double LScaleFactor;
2262 fscanf(KnChInpFile,
"NbPointsKnCh: %d\n", &
NbPointsKnCh);
2263 fscanf(KnChInpFile,
"PointKnChFile: %s\n", PointKnChFile);
2264 fscanf(KnChInpFile,
"NbLinesKnCh: %d\n", &
NbLinesKnCh);
2265 fscanf(KnChInpFile,
"LineKnChFile: %s\n", LineKnChFile);
2266 fscanf(KnChInpFile,
"NbAreasKnCh: %d\n", &
NbAreasKnCh);
2267 fscanf(KnChInpFile,
"AreaKnChFile: %s\n", AreaKnChFile);
2269 fscanf(KnChInpFile,
"VolumeKnChFile: %s\n", VolumeKnChFile);
2270 fscanf(KnChInpFile,
"LScaleFactor: %lg\n", &LScaleFactor);
2271 fscanf(KnChInpFile,
"KnChFactor: %lg\n", &KnChFactor);
2274 printf(
"PointKnChFile: %s\n", PointKnChFile);
2276 printf(
"LineKnChFile: %s\n", LineKnChFile);
2278 printf(
"AreaKnChFile: %s\n", AreaKnChFile);
2280 printf(
"VolumeKnChFile: %s\n", VolumeKnChFile);
2281 printf(
"LScaleFactor: %lg\n", LScaleFactor);
2282 printf(
"KnChFactor: %lg\n", KnChFactor);
2287 printf(
"No. of points with known charges: %d\n",
NbPointsKnCh);
2289 FILE *fptrPointKnChFile = fopen(PointKnChFile,
"r");
2290 if (fptrPointKnChFile == NULL) {
2292 fclose(KnChInpFile);
2309 fgets(header, 256, fptrPointKnChFile);
2312 fscanf(fptrPointKnChFile,
"%d %lg %lg %lg %lg\n",
2323 printf(
"Nb: %d , X: %lg, Y:%lg, Z:%lg, Assigned:%lg\n",
2330 fclose(fptrPointKnChFile);
2331 if (debugFn) printf(
"done for all points\n");
2336 printf(
"No. of lines with known charges: %d\n",
NbLinesKnCh);
2338 FILE *fptrLineKnChFile = fopen(LineKnChFile,
"r");
2339 if (fptrLineKnChFile == NULL) {
2361 fgets(header, 256, fptrLineKnChFile);
2364 fscanf(fptrLineKnChFile,
"%d %lg %lg %lg %lg %lg %lg %lg %lg\n",
2383 "Nb: %d, X1Y1Z1: %lg %lg %lg X2Y2Z2 %lg %lg %lg R: %lg "
2393 fclose(fptrLineKnChFile);
2394 if (debugFn) printf(
"done for all lines\n");
2399 printf(
"No. of areas with known charges: %d\n",
NbAreasKnCh);
2401 FILE *fptrAreaKnChFile = fopen(AreaKnChFile,
"r");
2402 if (fptrAreaKnChFile == NULL) {
2414 for (
int vert = 1; vert <= (
AreaKnChArr + area - 1)->NbVertices;
2424 fgets(header, 256, fptrAreaKnChFile);
2427 fscanf(fptrAreaKnChFile,
"%d %d %le\n",
2431 for (
int vert = 1; vert <= (
AreaKnChArr + area - 1)->NbVertices;
2433 fscanf(fptrAreaKnChFile,
"%le %le %le\n",
2439 for (
int vert = 1; vert <= (
AreaKnChArr + area - 1)->NbVertices;
2441 (
AreaKnChArr + area - 1)->Vertex[vert].X /= LScaleFactor;
2442 (
AreaKnChArr + area - 1)->Vertex[vert].Y /= LScaleFactor;
2443 (
AreaKnChArr + area - 1)->Vertex[vert].Z /= LScaleFactor;
2446 (LScaleFactor * LScaleFactor);
2450 fclose(fptrAreaKnChFile);
2451 if (debugFn) printf(
"done for all areas\n");
2456 printf(
"No. of volumes with known charges: %d\n",
NbVolumesKnCh);
2458 FILE *fptrVolumeKnChFile = fopen(VolumeKnChFile,
"r");
2459 if (fptrVolumeKnChFile == NULL) {
2460 neBEMMessage(
"VolumeKnCh file absent ... returning\n");
2471 for (
int vert = 1; vert <= (
VolumeKnChArr + volume - 1)->NbVertices;
2478 (LScaleFactor * LScaleFactor * LScaleFactor);
2483 fgets(header, 256, fptrVolumeKnChFile);
2486 fscanf(fptrVolumeKnChFile,
"%d %d %le\n",
2490 for (
int vert = 1; vert <= (
VolumeKnChArr + volume - 1)->NbVertices;
2492 fscanf(fptrVolumeKnChFile,
"%le %le %le\n",
2498 for (
int vert = 1; vert <= (
VolumeKnChArr + volume - 1)->NbVertices;
2500 (
VolumeKnChArr + volume - 1)->Vertex[vert].X /= LScaleFactor;
2501 (
VolumeKnChArr + volume - 1)->Vertex[vert].Y /= LScaleFactor;
2502 (
VolumeKnChArr + volume - 1)->Vertex[vert].Z /= LScaleFactor;
2507 fclose(fptrVolumeKnChFile);
2508 if (debugFn) printf(
"done for all volumes\n");
2513 fclose(KnChInpFile);
2532 for (
int ele = 1; ele <=
NbElements; ++ele) {
2533 printf(
"ele, Assigned charge: %d, %lg\n", ele,
2534 (
EleArr + ele - 1)->Assigned);
2542 FILE *ChargingUpInpFile = fopen(
"neBEMInp/neBEMChargingUp.inp",
"r");
2543 if (ChargingUpInpFile == NULL) {
2545 "neBEMChargingUp.inp absent ... assuming no charging up effect "
2549 fscanf(ChargingUpInpFile,
"OptChargingUp: %d\n", &
OptChargingUp);
2551 printf(
"OptChargingUp = 0 ... assuming no charging up effect ...\n");
2555 char ChargingUpEFile[256];
2556 char ChargingUpIFile[256];
2557 double LScaleFactor;
2560 fscanf(ChargingUpInpFile,
"ChargingUpEFile: %s\n", ChargingUpEFile);
2561 fscanf(ChargingUpInpFile,
"ChargingUpIFile: %s\n", ChargingUpIFile);
2562 fscanf(ChargingUpInpFile,
"LScaleFactor: %lg\n", &LScaleFactor);
2563 fscanf(ChargingUpInpFile,
"ChUpFactor: %lg\n", &ChUpFactor);
2565 printf(
"ChargingUpEFile: %s\n", ChargingUpEFile);
2566 printf(
"ChargingUpIFile: %s\n", ChargingUpIFile);
2567 printf(
"LScaleFactor: %lg\n", LScaleFactor);
2568 printf(
"ChUpFactor: %lg\n", ChUpFactor);
2572 FILE *fptrChargingUpEFile = fopen(ChargingUpEFile,
"r");
2573 if (fptrChargingUpEFile == NULL) {
2574 neBEMMessage(
"ChargingUpE file absent ... returning\n");
2575 fclose(ChargingUpInpFile);
2580 neBEMMessage(
"Too few lines in ChargingUpE ... returning\n");
2581 fclose(fptrChargingUpEFile);
2585 int* NbChUpEonEle = (
int *)malloc((
NbElements + 1) *
sizeof(
int));
2586 for (
int ele = 0; ele <=
NbElements; ++ele) {
2588 NbChUpEonEle[ele] = 0;
2593 fgets(header, 256, fptrChargingUpEFile);
2596 if (debugFn) printf(
"No. of electrons: %d\n", NbOfE);
2598 strcpy(tmpEFile,
"/tmp/ElectronTempFile.out");
2599 FILE *ftmpEF = fopen(tmpEFile,
"w");
2600 if (ftmpEF == NULL) {
2601 printf(
"cannot open temporary output file ... returning ...\n");
2605 FILE *fPtEChUpMap = fopen(
"PtEChUpMap.out",
"w");
2606 if (fPtEChUpMap == NULL) {
2607 printf(
"cannot open PtEChUpMap.out file for writing ...\n");
2614 double xlbend, ylbend, zlbend, xend, yend,
2618 for (
int electron = 1; electron <= NbOfE; ++electron) {
2619 fscanf(fptrChargingUpEFile,
"%c %d %d %lg %lg %lg %lg %lg %lg\n",
2620 &label, &vol, &enb, &xlbend, &xend, &ylbend, ¥d, &zlbend,
2622 xlbend /= LScaleFactor;
2623 xend /= LScaleFactor;
2624 ylbend /= LScaleFactor;
2625 yend /= LScaleFactor;
2626 zlbend /= LScaleFactor;
2627 zend /= LScaleFactor;
2640 double lseg = (xend - xlbend) * (xend - xlbend) +
2641 (yend - ylbend) * (yend - ylbend) +
2642 (zend - zlbend) * (zend - zlbend);
2645 (xend - xlbend) / lseg;
2646 double ygrd = (yend - ylbend) / lseg;
2647 double zgrd = (zend - zlbend) / lseg;
2649 printf(
"\nelectron: %d\n", electron);
2650 printf(
"xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
2652 printf(
"xend: %lg, yend: %lg, zend: %lg\n", xend, yend, zend);
2653 printf(
"xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd, zgrd);
2654 fprintf(ftmpEF,
"#e: %d, label: %c, vol: %d\n", electron, label,
2656 fprintf(ftmpEF,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
2657 fprintf(ftmpEF,
"%lg %lg %lg\n", xend, yend, zend);
2658 fprintf(ftmpEF,
"#xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd,
2660 fprintf(ftmpEF,
"\n");
2677 int PrimIntsctd = -1,
2679 int nearestprim = -1;
2680 double dist = 1.0e6, mindist = 1.0e6;
2686 int intersect = 0, extrasect = 1;
2687 int InPrim = 0, InEle = 0;
2689 printf(
"prim: %d, mindist: %lg, nearestprim: %d\n", prim,
2690 mindist, nearestprim);
2699 printf(
"prim: %d\n", prim);
2700 printf(
"vertex0: %lg, %lg, %lg\n",
XVertex[prim][0],
2702 printf(
"vertex1: %lg, %lg, %lg\n",
XVertex[prim][1],
2704 printf(
"vertex2: %lg, %lg, %lg\n",
XVertex[prim][2],
2707 printf(
"vertex3: %lg, %lg, %lg\n",
XVertex[prim][3],
2710 fprintf(ftmpEF,
"#prim: %d\n", prim);
2711 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][0],
2713 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][1],
2715 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][2],
2718 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][3],
2721 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][0],
2723 fprintf(ftmpEF,
"\n");
2729 double a =
XNorm[prim];
2730 double b =
YNorm[prim];
2731 double c =
ZNorm[prim];
2736 dist = (xend * a + yend * b + zend * c + d) /
2737 sqrt(a * a + b * b + c * c);
2743 if ((prim == 1) && debugFn)
2745 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
2746 mindist, nearestprim);
2755 double norm1 = sqrt(a * a + b * b + c * c);
2756 double norm2 = sqrt(xgrd * xgrd + ygrd * ygrd + zgrd * zgrd);
2758 a * xgrd + b * ygrd + c * zgrd;
2761 intersect = extrasect = 0;
2764 printf(
"a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
2766 printf(
"vector n: ai + bj + ck\n");
2767 printf(
"vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
2769 printf(
"norm1, norm2, (vec n . vec v) denom: %lg, %lg, %lg\n",
2770 norm1, norm2, denom);
2771 printf(
"if vec n . vec v == 0, line and plane parallel\n");
2775 if (fabs(denom) < tol * norm1 * norm2) {
2777 if (fabs(a * xlbend + b * ylbend + c * zlbend + d) <=
2781 ptintsct.
X = xlbend;
2782 ptintsct.
Y = ylbend;
2783 ptintsct.
Z = zlbend;
2793 printf(
"line and plane parallel ...\n");
2794 printf(
"intersect: %d, extrasect: %d\n", intersect,
2796 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2797 ptintsct.
Y, ptintsct.
Z);
2802 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
2809 (fabs(t) > fabs(lseg)))
2812 ptintsct.
X = xlbend + t * xgrd;
2813 ptintsct.
Y = ylbend + t * ygrd;
2814 ptintsct.
Z = zlbend + t * zgrd;
2817 ptintsct.
X = xlbend + t * xgrd;
2818 ptintsct.
Y = ylbend + t * ygrd;
2819 ptintsct.
Z = zlbend + t * zgrd;
2822 printf(
"line and plane NOT parallel ...\n");
2823 printf(
"intersect: %d, extrasect: %d\n", intersect,
2825 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2826 ptintsct.
Y, ptintsct.
Z);
2827 printf(
"t, lseg: %lg, %lg\n", t, lseg);
2829 "for an interesting intersection, lseg > t > 0.0 "
2842 if (dist < mindist) {
2847 printf(
"nearestprim: %d, mindist: %lg\n\n", nearestprim,
2854 if ((intersect == 1) && (extrasect == 0)) {
2875 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) {
2881 printf(
"Prim: %d\n", prim);
2882 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
2884 printf(
"nvert: %d\n", nvert);
2885 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
2886 polynode[0].Y, polynode[0].Z);
2887 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
2888 polynode[1].Y, polynode[1].Z);
2889 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
2890 polynode[2].Y, polynode[2].Z);
2892 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
2893 polynode[3].Y, polynode[3].Z);
2895 printf(
"SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
2910 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
2911 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
2914 "no vertex in element! ... neBEMKnownCharges ...\n");
2915 fclose(fPtEChUpMap);
2919 polynode[0].
X = (
EleArr + ele - 1)->G.Vertex[0].X;
2920 polynode[0].
Y = (
EleArr + ele - 1)->G.Vertex[0].Y;
2921 polynode[0].
Z = (
EleArr + ele - 1)->G.Vertex[0].Z;
2922 polynode[1].
X = (
EleArr + ele - 1)->G.Vertex[1].X;
2923 polynode[1].
Y = (
EleArr + ele - 1)->G.Vertex[1].Y;
2924 polynode[1].
Z = (
EleArr + ele - 1)->G.Vertex[1].Z;
2925 polynode[2].
X = (
EleArr + ele - 1)->G.Vertex[2].X;
2926 polynode[2].
Y = (
EleArr + ele - 1)->G.Vertex[2].Y;
2927 polynode[2].
Z = (
EleArr + ele - 1)->G.Vertex[2].Z;
2929 polynode[3].
X = (
EleArr + ele - 1)->G.Vertex[3].X;
2930 polynode[3].
Y = (
EleArr + ele - 1)->G.Vertex[3].Y;
2931 polynode[3].
Z = (
EleArr + ele - 1)->G.Vertex[3].Z;
2936 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8)
2940 printf(
"Ele: %d\n", ele);
2941 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X,
2942 ptintsct.
Y, ptintsct.
Z);
2943 printf(
"nvert: %d\n", nvert);
2944 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
2945 polynode[0].Y, polynode[0].Z);
2946 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
2947 polynode[1].Y, polynode[1].Z);
2948 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
2949 polynode[2].Y, polynode[2].Z);
2951 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
2952 polynode[3].Y, polynode[3].Z);
2954 printf(
"SumOfAngles: %lg, InEle: %d\n", SumOfAngles,
2959 ptintsct.
X = (
EleArr + ele - 1)->G.Origin.X;
2960 ptintsct.
Y = (
EleArr + ele - 1)->G.Origin.Y;
2961 ptintsct.
Z = (
EleArr + ele - 1)->G.Origin.Z;
2964 NbChUpEonEle[ele]++;
2965 fprintf(fPtEChUpMap,
"%d %lg %lg %lg %d %d %d %d\n",
2966 electron, ptintsct.
X, ptintsct.
Y, ptintsct.
Z,
2967 prim, InPrim, ele, InEle);
2970 printf(
"# electron: %d\n", electron);
2971 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
2972 printf(
"%lg %lg %lg\n", xend, yend, zend);
2973 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
2975 printf(
"# Associated primitive: %d\n", prim);
2977 "# Associated element and origin: %d, %lg, %lg, "
2979 ele, (
EleArr + ele - 1)->G.Origin.X,
2980 (
EleArr + ele - 1)->G.Origin.Y,
2981 (
EleArr + ele - 1)->G.Origin.Z);
2982 printf(
"#NbChUpEonEle on element: %d\n",
2984 fprintf(ftmpEF,
"#Element: %d\n", ele);
2985 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X,
2986 polynode[0].Y, polynode[0].Z);
2987 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[1].X,
2988 polynode[1].Y, polynode[1].Z);
2989 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[2].X,
2990 polynode[2].Y, polynode[2].Z);
2992 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[3].X,
2993 polynode[3].Y, polynode[3].Z);
2995 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X,
2996 polynode[0].Y, polynode[0].Z);
2997 fprintf(ftmpEF,
"\n");
3008 "Element not identified ... neBEMKnownCharges\n");
3014 if ((InPrim) && (intersect) && (!extrasect) &&
3026 double distele = 1.0e6,
3030 printf(
"prim == (NbPrimitives) ... checking nearest ...\n");
3031 printf(
"nearestprim: %d, mindist: %lg\n", nearestprim,
3035 if (mindist <= 10.0e-6) {
3036 PrimIntsctd = nearestprim;
3047 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3048 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3051 "no vertex element! ... neBEMKnownCharges ...\n");
3128 eleOrigin.
X = (
EleArr + ele - 1)->G.Origin.X;
3129 eleOrigin.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3130 eleOrigin.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3131 distele = (eleOrigin.
X - xend) * (eleOrigin.
X - xend) +
3132 (eleOrigin.
Y - yend) * (eleOrigin.
Y - yend) +
3133 (eleOrigin.
Z - zend) * (eleOrigin.
Z - zend);
3134 distele = sqrt(distele);
3137 mindistele = distele;
3140 if (distele < mindistele) {
3141 mindistele = distele;
3152 "distele: %lg, mindistele: %lg,from nearest ele "
3154 distele, mindistele, nearestele);
3163 EleIntsctd = nearestele;
3165 ptintsct.
X = (
EleArr + EleIntsctd - 1)->G.Origin.X;
3166 ptintsct.
Y = (
EleArr + EleIntsctd - 1)->G.Origin.Y;
3167 ptintsct.
Z = (
EleArr + EleIntsctd - 1)->G.Origin.Z;
3168 NbChUpEonEle[EleIntsctd]++;
3170 fprintf(fPtEChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", electron,
3171 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3176 printf(
"# electron: %d\n", electron);
3177 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3178 printf(
"%lg %lg %lg\n", xend, yend, zend);
3179 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y, ptintsct.
Z);
3180 printf(
"# Associated primitive: %d\n", PrimIntsctd);
3181 printf(
"# Associated element and origin: %d, %lg, %lg, %lg\n",
3182 EleIntsctd, (
EleArr + EleIntsctd - 1)->G.Origin.X,
3183 (
EleArr + EleIntsctd - 1)->G.Origin.Y,
3184 (
EleArr + EleIntsctd - 1)->G.Origin.Z);
3185 printf(
"#NbChUpEonEle on element: %d\n",
3186 NbChUpEonEle[EleIntsctd]);
3189 fprintf(ftmpEF,
"#Element: %d\n", EleIntsctd);
3190 polynode[0].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3191 polynode[0].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3192 polynode[0].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3193 polynode[1].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3194 polynode[1].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3195 polynode[1].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3196 polynode[2].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3197 polynode[2].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3198 polynode[2].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3200 polynode[3].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3201 polynode[3].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3202 polynode[3].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3204 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3206 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3208 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3211 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[3].X,
3212 polynode[3].Y, polynode[3].Z);
3214 fprintf(ftmpEF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3216 fprintf(ftmpEF,
"\n");
3223 printf(
"writing file for checking electron positions\n");
3229 snprintf(enbstr, 12,
"%d", electron);
3230 char elecposdbg[256];
3231 strcpy(elecposdbg,
"/tmp/Electron");
3232 strcat(elecposdbg, enbstr);
3233 strcat(elecposdbg,
".out");
3234 FILE *fepd = fopen(elecposdbg,
"w");
3237 "cannot open writable file to debug electron positions "
3239 printf(
"returning ...\n");
3244 fprintf(fepd,
"#electron: %d %d\n", enb,
3246 fprintf(fepd,
"#last but end position:\n");
3247 fprintf(fepd,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3248 fprintf(fepd,
"#end position:\n");
3249 fprintf(fepd,
"%lg %lg %lg\n\n", xend, yend, zend);
3250 fprintf(fepd,
"#intersected primitive number: %d\n", PrimIntsctd);
3251 if (PrimIntsctd >= 1) {
3252 fprintf(fepd,
"#PrimType: %d\n",
PrimType[PrimIntsctd]);
3253 fprintf(fepd,
"#prim vertices:\n");
3254 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
3256 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][1],
3258 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][2],
3261 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][3],
3264 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
3266 fprintf(fepd,
"\n");
3268 fprintf(fepd,
"#ptintsct:\n");
3269 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3271 fprintf(fepd,
"\n");
3273 fprintf(fepd,
"#intersected element number: %d\n", EleIntsctd);
3274 if (EleIntsctd >= 1) {
3275 int gtype = (
EleArr + EleIntsctd - 1)->G.Type;
3276 fprintf(fepd,
"#EleType: %d\n", gtype);
3277 fprintf(fepd,
"#element vertices:\n");
3278 double x0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3279 double y0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3280 double z0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3281 double x1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3282 double y1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3283 double z1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3284 double x2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3285 double y2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3286 double z2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3287 fprintf(fepd,
"%lg %lg %lg\n", x0, y0, z0);
3288 fprintf(fepd,
"%lg %lg %lg\n", x1, y1, z1);
3289 fprintf(fepd,
"%lg %lg %lg\n", x2, y2, z2);
3291 double x3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3292 double y3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3293 double z3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3294 fprintf(fepd,
"%lg %lg %lg\n", x3, y3, z3);
3296 fprintf(fepd,
"%lg %lg %lg\n", x0, y0, z0);
3297 fprintf(fepd,
"\n");
3299 fprintf(fepd,
"#ptintsct:\n");
3300 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3302 fprintf(fepd,
"\n");
3308 printf(
"done writing file for checking electron positions\n");
3310 fclose(fPtEChUpMap);
3311 if (debugFn) printf(
"done for all electrons\n");
3313 FILE *fEleEChUpMap = fopen(
"EleEChUpMap.out",
"w");
3314 if (fEleEChUpMap == NULL) {
3315 printf(
"cannot open EleEChUpMap.out file for writing ...\n");
3318 for (
int ele = 1; ele <=
NbElements; ++ele) {
3319 (
EleArr + ele - 1)->Assigned +=
3320 ChUpFactor *
Q_E * NbChUpEonEle[ele] / (
EleArr + ele - 1)->G.dA;
3321 fprintf(fEleEChUpMap,
"%d %lg %lg %lg %d %lg\n", ele,
3322 (
EleArr + ele - 1)->G.Origin.X,
3323 (
EleArr + ele - 1)->G.Origin.Y,
3324 (
EleArr + ele - 1)->G.Origin.Z, NbChUpEonEle[ele],
3325 (
EleArr + ele - 1)->Assigned);
3327 fclose(fEleEChUpMap);
3334 FILE *fptrChargingUpIFile = fopen(ChargingUpIFile,
"r");
3335 if (fptrChargingUpIFile == NULL) {
3336 neBEMMessage(
"ChargingUpI file absent ... returning\n");
3341 neBEMMessage(
"Too few lines in ChargingUpI ... returning\n");
3342 fclose(fptrChargingUpIFile);
3346 int* NbChUpIonEle = (
int *)malloc((
NbElements + 1) *
sizeof(
int));
3347 for (
int ele = 0; ele <=
NbElements; ++ele) {
3349 NbChUpIonEle[ele] = 0;
3354 fgets(header, 256, fptrChargingUpIFile);
3357 if (debugFn) printf(
"No. of ions: %d\n", NbOfI);
3359 strcpy(tmpIFile,
"/tmp/IonTempFile.out");
3360 FILE *ftmpIF = fopen(tmpIFile,
"w");
3361 if (ftmpIF == NULL) {
3362 printf(
"cannot open temporary ion output file ... returning ...\n");
3366 FILE *fPtIChUpMap = fopen(
"PtIChUpMap.out",
"w");
3367 if (fPtIChUpMap == NULL) {
3368 printf(
"cannot open PtIChUpMap.out file for writing ...\n");
3375 double xlbend, ylbend, zlbend, xend, yend,
3378 for (
int ion = 1; ion <= NbOfI; ++ion) {
3379 fscanf(fptrChargingUpIFile,
"%c %d %d %lg %lg %lg %lg %lg %lg\n",
3380 &label, &vol, &inb, &xlbend, &xend, &ylbend, ¥d, &zlbend,
3382 xlbend /= LScaleFactor;
3383 xend /= LScaleFactor;
3384 ylbend /= LScaleFactor;
3385 yend /= LScaleFactor;
3386 zlbend /= LScaleFactor;
3387 zend /= LScaleFactor;
3400 double lseg = (xend - xlbend) * (xend - xlbend) +
3401 (yend - ylbend) * (yend - ylbend) +
3402 (zend - zlbend) * (zend - zlbend);
3405 (xend - xlbend) / lseg;
3406 double ygrd = (yend - ylbend) / lseg;
3407 double zgrd = (zend - zlbend) / lseg;
3409 printf(
"\nion: %d\n", ion);
3410 printf(
"xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
3412 printf(
"xend: %lg, yend: %lg, zend: %lg\n", xend, yend, zend);
3413 printf(
"xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd, zgrd);
3414 fprintf(ftmpIF,
"#e: %d, label: %c, vol: %d\n", ion, label, vol);
3415 fprintf(ftmpIF,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3416 fprintf(ftmpIF,
"%lg %lg %lg\n", xend, yend, zend);
3417 fprintf(ftmpIF,
"#xgrd: %lg, ygrd: %lg, zgrd: %lg\n", xgrd, ygrd,
3419 fprintf(ftmpIF,
"\n");
3435 int PrimIntsctd = -1,
3437 int nearestprim = -1;
3438 double dist = 1.0e6, mindist = 1.0e6;
3445 int intersect = 0, extrasect = 1;
3446 int InPrim = 0, InEle = 0;
3448 printf(
"prim: %d, mindist: %lg, nearestprim: %d\n", prim,
3449 mindist, nearestprim);
3460 printf(
"prim: %d\n", prim);
3461 printf(
"vertex0: %lg, %lg, %lg\n",
XVertex[prim][0],
3463 printf(
"vertex1: %lg, %lg, %lg\n",
XVertex[prim][1],
3465 printf(
"vertex2: %lg, %lg, %lg\n",
XVertex[prim][2],
3468 printf(
"vertex3: %lg, %lg, %lg\n",
XVertex[prim][3],
3471 fprintf(ftmpIF,
"#prim: %d\n", prim);
3472 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][0],
3474 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][1],
3476 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][2],
3479 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][3],
3482 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][0],
3484 fprintf(ftmpIF,
"\n");
3497 zend *
ZNorm[prim] + d) /
3505 if ((prim == 1) && debugFn)
3507 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
3508 mindist, nearestprim);
3517 double a =
XNorm[prim];
3518 double b =
YNorm[prim];
3519 double c =
ZNorm[prim];
3520 double norm1 = sqrt(a * a + b * b + c * c);
3521 double norm2 = sqrt(xgrd * xgrd + ygrd * ygrd + zgrd * zgrd);
3523 a * xgrd + b * ygrd + c * zgrd;
3526 intersect = extrasect = 0;
3529 printf(
"a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
3531 printf(
"vector n: ai + bj + ck\n");
3532 printf(
"vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
3534 printf(
"norm1, norm2, (vec n . vec v) denom: %lg, %lg, %lg\n",
3535 norm1, norm2, denom);
3536 printf(
"if vec n . vec v == 0, line and plane parallel\n");
3541 tol * norm1 * norm2)
3543 if (a * xlbend + b * ylbend + c * zlbend + d ==
3548 ptintsct.
X = xlbend;
3549 ptintsct.
Y = ylbend;
3550 ptintsct.
Z = zlbend;
3560 printf(
"line and plane parallel ...\n");
3561 printf(
"intersect: %d, extrasect: %d\n", intersect,
3563 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3564 ptintsct.
Y, ptintsct.
Z);
3569 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
3575 if ((t < 0.0) || (fabs(t) > fabs(lseg))) {
3577 ptintsct.
X = xlbend + t * xgrd;
3578 ptintsct.
Y = ylbend + t * ygrd;
3579 ptintsct.
Z = zlbend + t * zgrd;
3582 ptintsct.
X = xlbend + t * xgrd;
3583 ptintsct.
Y = ylbend + t * ygrd;
3584 ptintsct.
Z = zlbend + t * zgrd;
3587 printf(
"line and plane NOT parallel ...\n");
3588 printf(
"intersect: %d, extrasect: %d\n", intersect,
3590 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3591 ptintsct.
Y, ptintsct.
Z);
3592 printf(
"t, lseg: %lg, %lg\n", t, lseg);
3594 "for an interesting intersection, lseg > t > 0.0 "
3606 if (dist < mindist) {
3615 if ((intersect == 1) && (extrasect == 0)) {
3636 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) {
3642 printf(
"Prim: %d\n", prim);
3643 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3645 printf(
"nvert: %d\n", nvert);
3646 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
3647 polynode[0].Y, polynode[0].Z);
3648 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
3649 polynode[1].Y, polynode[1].Z);
3650 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
3651 polynode[2].Y, polynode[2].Z);
3653 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
3654 polynode[3].Y, polynode[3].Z);
3656 printf(
"SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
3659 if (!InPrim)
continue;
3667 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3668 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3671 "no vertex in element! ... neBEMKnownCharges ...\n");
3672 fclose(fPtIChUpMap);
3676 polynode[0].
X = (
EleArr + ele - 1)->G.Vertex[0].X;
3677 polynode[0].
Y = (
EleArr + ele - 1)->G.Vertex[0].Y;
3678 polynode[0].
Z = (
EleArr + ele - 1)->G.Vertex[0].Z;
3679 polynode[1].
X = (
EleArr + ele - 1)->G.Vertex[1].X;
3680 polynode[1].
Y = (
EleArr + ele - 1)->G.Vertex[1].Y;
3681 polynode[1].
Z = (
EleArr + ele - 1)->G.Vertex[1].Z;
3682 polynode[2].
X = (
EleArr + ele - 1)->G.Vertex[2].X;
3683 polynode[2].
Y = (
EleArr + ele - 1)->G.Vertex[2].Y;
3684 polynode[2].
Z = (
EleArr + ele - 1)->G.Vertex[2].Z;
3686 polynode[3].
X = (
EleArr + ele - 1)->G.Vertex[3].X;
3687 polynode[3].
Y = (
EleArr + ele - 1)->G.Vertex[3].Y;
3688 polynode[3].
Z = (
EleArr + ele - 1)->G.Vertex[3].Z;
3693 if (fabs(fabs(SumOfAngles) -
neBEMtwopi) <= 1.0e-8) InEle = 1;
3696 printf(
"Ele: %d\n", ele);
3697 printf(
"ptintsct: %lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3699 printf(
"nvert: %d\n", nvert);
3700 printf(
"polynode0: %lg, %lg, %lg\n", polynode[0].X,
3701 polynode[0].Y, polynode[0].Z);
3702 printf(
"polynode1: %lg, %lg, %lg\n", polynode[1].X,
3703 polynode[1].Y, polynode[1].Z);
3704 printf(
"polynode2: %lg, %lg, %lg\n", polynode[2].X,
3705 polynode[2].Y, polynode[2].Z);
3707 printf(
"polynode3: %lg, %lg, %lg\n", polynode[3].X,
3708 polynode[3].Y, polynode[3].Z);
3710 printf(
"SumOfAngles: %lg, InEle: %d\n", SumOfAngles, InEle);
3714 ptintsct.
X = (
EleArr + ele - 1)->G.Origin.X;
3715 ptintsct.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3716 ptintsct.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3719 NbChUpIonEle[ele]++;
3720 fprintf(fPtIChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", ion,
3721 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, prim, InPrim,
3725 printf(
"# ion: %d\n", ion);
3726 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3727 printf(
"%lg %lg %lg\n", xend, yend, zend);
3728 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y,
3730 printf(
"# Associated primitive: %d\n", prim);
3732 "# Associated element and origin: %d, %lg, %lg, "
3734 ele, (
EleArr + ele - 1)->G.Origin.X,
3735 (
EleArr + ele - 1)->G.Origin.Y,
3736 (
EleArr + ele - 1)->G.Origin.Z);
3737 printf(
"#NbChUpIonEle on element: %d\n",
3739 fprintf(ftmpIF,
"#Element: %d\n", ele);
3740 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X,
3741 polynode[0].Y, polynode[0].Z);
3742 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[1].X,
3743 polynode[1].Y, polynode[1].Z);
3744 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[2].X,
3745 polynode[2].Y, polynode[2].Z);
3747 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[3].X,
3748 polynode[3].Y, polynode[3].Z);
3750 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X,
3751 polynode[0].Y, polynode[0].Z);
3752 fprintf(ftmpIF,
"\n");
3763 "Element cannot be identified ... neBEMKnownCharges\n");
3768 if ((InPrim) && (intersect) && (!extrasect) &&
3780 double distele = 1.0e6,
3784 printf(
"prim == (NbPrimitives) ... checking nearest ...\n");
3785 printf(
"nearestprim: %d, mindist: %lg\n", nearestprim,
3789 if (mindist <= 10.0e-6) {
3790 PrimIntsctd = nearestprim;
3801 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3802 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3805 "no vertex element! ... neBEMKnownCharges ...\n");
3891 eleOrigin.
X = (
EleArr + ele - 1)->G.Origin.X;
3892 eleOrigin.
Y = (
EleArr + ele - 1)->G.Origin.Y;
3893 eleOrigin.
Z = (
EleArr + ele - 1)->G.Origin.Z;
3894 distele = (eleOrigin.
X - xend) * (eleOrigin.
X - xend) +
3895 (eleOrigin.
Y - yend) * (eleOrigin.
Y - yend) +
3896 (eleOrigin.
Z - zend) * (eleOrigin.
Z - zend);
3897 distele = sqrt(distele);
3900 mindistele = distele;
3903 if (distele < mindistele) {
3904 mindistele = distele;
3915 "distele: %lg, mindist: %lg, from nearest ele: %d\n",
3916 distele, mindistele, nearestele);
3925 EleIntsctd = nearestele;
3927 ptintsct.
X = (
EleArr + EleIntsctd - 1)->G.Origin.X;
3928 ptintsct.
Y = (
EleArr + EleIntsctd - 1)->G.Origin.Y;
3929 ptintsct.
Z = (
EleArr + EleIntsctd - 1)->G.Origin.Z;
3930 NbChUpIonEle[EleIntsctd]++;
3932 fprintf(fPtIChUpMap,
"%d %lg %lg %lg %d %d %d %d\n", ion,
3933 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3938 printf(
"# ion: %d\n", ion);
3939 printf(
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
3940 printf(
"%lg %lg %lg\n", xend, yend, zend);
3941 printf(
"%lg, %lg, %lg\n", ptintsct.
X, ptintsct.
Y, ptintsct.
Z);
3942 printf(
"# Associated primitive: %d\n", PrimIntsctd);
3943 printf(
"# Associated element and origin: %d, %lg, %lg, %lg\n",
3944 EleIntsctd, (
EleArr + EleIntsctd - 1)->G.Origin.X,
3945 (
EleArr + EleIntsctd - 1)->G.Origin.Y,
3946 (
EleArr + EleIntsctd - 1)->G.Origin.Z);
3947 printf(
"#NbChUpIonEle on element: %d\n",
3948 NbChUpIonEle[EleIntsctd]);
3949 fprintf(ftmpIF,
"#Element: %d\n", EleIntsctd);
3950 polynode[0].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
3951 polynode[0].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
3952 polynode[0].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
3953 polynode[1].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
3954 polynode[1].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
3955 polynode[1].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
3956 polynode[2].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
3957 polynode[2].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
3958 polynode[2].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
3960 polynode[3].
X = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
3961 polynode[3].
Y = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
3962 polynode[3].
Z = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
3964 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3966 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3968 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3971 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[3].X,
3972 polynode[3].Y, polynode[3].Z);
3974 fprintf(ftmpIF,
"%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3976 fprintf(ftmpIF,
"\n");
3986 snprintf(inbstr, 12,
"%d", ion);
3987 char ionposdbg[256];
3988 strcpy(ionposdbg,
"/tmp/Ion");
3989 strcat(ionposdbg, inbstr);
3990 strcat(ionposdbg,
".out");
3991 FILE *fipd = fopen(ionposdbg,
"w");
3994 "cannot open writable file to debug ion positions ...\n");
3995 printf(
"returning ...\n");
4000 fprintf(fipd,
"#ion: %d %d\n", inb, ion);
4001 fprintf(fipd,
"#last but end position:\n");
4002 fprintf(fipd,
"%lg %lg %lg\n", xlbend, ylbend, zlbend);
4003 fprintf(fipd,
"#end position:\n");
4004 fprintf(fipd,
"%lg %lg %lg\n\n", xend, yend, zend);
4006 fprintf(fipd,
"#intersected primitive number: %d\n", PrimIntsctd);
4007 if (PrimIntsctd >= 1) {
4008 fprintf(fipd,
"#PrimType: %d\n",
PrimType[PrimIntsctd]);
4009 fprintf(fipd,
"#prim vertices:\n");
4010 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
4012 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][1],
4014 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][2],
4017 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][3],
4020 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
4022 fprintf(fipd,
"\n");
4024 fprintf(fipd,
"#ptintsct:\n");
4025 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4027 fprintf(fipd,
"\n");
4030 fprintf(fipd,
"#intersected element number: %d\n", EleIntsctd);
4031 if (EleIntsctd >= 1) {
4032 int gtype = (
EleArr + EleIntsctd - 1)->G.Type;
4033 fprintf(fipd,
"#EleType: %d\n", gtype);
4034 fprintf(fipd,
"#element vertices:\n");
4035 double x0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].X;
4036 double y0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Y;
4037 double z0 = (
EleArr + EleIntsctd - 1)->G.Vertex[0].Z;
4038 double x1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].X;
4039 double y1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Y;
4040 double z1 = (
EleArr + EleIntsctd - 1)->G.Vertex[1].Z;
4041 double x2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].X;
4042 double y2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Y;
4043 double z2 = (
EleArr + EleIntsctd - 1)->G.Vertex[2].Z;
4044 fprintf(fipd,
"%lg %lg %lg\n", x0, y0, z0);
4045 fprintf(fipd,
"%lg %lg %lg\n", x1, y1, z1);
4046 fprintf(fipd,
"%lg %lg %lg\n", x2, y2, z2);
4048 double x3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].X;
4049 double y3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Y;
4050 double z3 = (
EleArr + EleIntsctd - 1)->G.Vertex[3].Z;
4051 fprintf(fipd,
"%lg %lg %lg\n", x3, y3, z3);
4053 fprintf(fipd,
"%lg %lg %lg\n", x0, y0, z0);
4054 fprintf(fipd,
"\n");
4056 fprintf(fipd,
"#ptintsct:\n");
4057 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4059 fprintf(fipd,
"\n");
4064 fclose(fPtIChUpMap);
4068 FILE *fEleEIChUpMap = fopen(
"EleE+IChUpMap.out",
"w");
4069 if (fEleEIChUpMap == NULL) {
4070 printf(
"cannot open EleE+IChUpMap.out file for writing ...\n");
4073 for (
int ele = 1; ele <=
NbElements; ++ele) {
4074 (
EleArr + ele - 1)->Assigned +=
4075 ChUpFactor *
Q_I * NbChUpIonEle[ele] / (
EleArr + ele - 1)->G.dA;
4076 fprintf(fEleEIChUpMap,
"%d %lg %lg %lg %d %lg\n", ele,
4077 (
EleArr + ele - 1)->G.Origin.X,
4078 (
EleArr + ele - 1)->G.Origin.Y,
4079 (
EleArr + ele - 1)->G.Origin.Z, NbChUpIonEle[ele],
4080 (
EleArr + ele - 1)->Assigned);
4082 fclose(fEleEIChUpMap);
4090 fclose(ChargingUpInpFile);