15#define MyPI 3.14159265358979323846
34 double zvert[],
double xnorm,
double ynorm,
double znorm,
35 int volref1,
int volref2,
int inttype,
double potential,
36 double charge,
double lambda,
int NbSegX,
int NbSegZ) {
51 ynorm, znorm, volref1, volref2, inttype,
52 potential, charge, lambda, NbSegX, NbSegZ);
62 ynorm, znorm, volref1, volref2, inttype,
63 potential, charge, lambda, NbSegX, NbSegZ);
72 printf(
"nvertex out of bounds in SurfaceElements ... exiting ...\n");
82int WireElements(
int prim,
int nvertex,
double xvert[],
double yvert[],
83 double zvert[],
double radius,
int volref1,
int volref2,
84 int inttype,
double potential,
double charge,
double lambda,
91 DiscretizeWire(prim, nvertex, xvert, yvert, zvert, radius, volref1,
92 volref2, inttype, potential, charge, lambda, NbSegs);
101 printf(
"nvertex out of bounds in WireElements ... exiting ...\n");
179 fprintf(
fMeshLog,
"Wire element too small on primitive %d!\n", prim);
184 double ellength = lWire / (double)nb;
192 fprintf(
fMeshLog,
"Wire element very small on primitive %d!\n", prim);
198 fprintf(
fMeshLog,
"Too many elements on wire primitive %d!\n", prim);
199 fprintf(
fMeshLog,
"Number of elements reduced to maximum allowed %d\n",
205 fprintf(
fMeshLog,
"Number of elements on wire primitive %d is %d.\n\n",
216 double ellength = lWire / (double)nb;
221 fprintf(
fMeshLog,
"Fatal: Wire element too small on primitive %d!\n",
226 nb = (int)(lWire / (2.0 *
MINDIST));
229 fprintf(
fMeshLog,
"Fatal: Wire element too small on primitive %d!\n",
236 fprintf(
fMeshLog,
"Number of elements on wire primitive %d is %d.\n\n",
247 int nb1 = *NbSegCoord1, nb2 = *NbSegCoord2;
249 if ((nb1 < 1) || (nb2 < 1))
277 fprintf(
fMeshLog,
"Length1 too small on primitive %d!\n", prim);
282 double ellength = l1 / (double)nb1;
288 fprintf(
fMeshLog,
"Length1 very small on primitive %d!\n", prim);
295 fprintf(
fMeshLog,
"Too many elements on Length1 for primitive %d!\n",
297 fprintf(
fMeshLog,
"Number of elements reduced to maximum allowed %d\n",
307 fprintf(
fMeshLog,
"Length2 element too small on primitive %d!\n", prim);
312 double ellength = l2 / (double)nb2;
318 fprintf(
fMeshLog,
"Length2 element very small on primitive %d!\n",
326 fprintf(
fMeshLog,
"Too many elements on Length2 of primitive %d!\n",
328 fprintf(
fMeshLog,
"Number of elements reduced to maximum allowed %d\n",
337 "Number of elements on surface primitive %d is %d X %d.\n\n", prim,
338 *NbSegCoord1, *NbSegCoord2);
365 double ellength1 = l1 / (double)nb1;
366 double ellength2 = l2 / (double)nb2;
370 fprintf(
fMeshLog,
"Fatal: Side length l1 too small! prim: %d\n", prim);
371 }
else if (ellength1 <
MINDIST)
373 nb1 = (int)(l1 / (2.0 *
MINDIST));
376 fprintf(
fMeshLog,
"Fatal: Side length l1 too small on primitive %d!\n",
383 fprintf(
fMeshLog,
"Fatal: Side length l2 too small! prim: %d\n", prim);
384 }
else if (ellength2 <
MINDIST)
386 nb2 = (int)(l2 / (2.0 *
MINDIST));
389 fprintf(
fMeshLog,
"Fatal: Side length l2 too small on primitive %d!\n",
398 "Number of elements on surface primitive %d is %d X %d.\n\n", prim,
399 *NbSegCoord1, *NbSegCoord2);
402 if ((nb1 > 0) && (nb2 > 0))
410 double zvert[],
double radius,
int volref1,
int volref2,
411 int inttype,
double potential,
double charge,
double lambda,
413 int WireParentObj, WireEType;
415 double WireLambda, WireV;
416 double WireElX, WireElY, WireElZ, WireElL;
420 FILE *fPrim, *fElem, *fgpPrim, *fgpElem;
424 neBEMMessage(
"DiscretizeWire - PrimType in DiscretizeWire");
428 neBEMMessage(
"DiscretizeWire - nvertex in DiscretizeWire");
432 neBEMMessage(
"DiscretizeWire - radius in DiscretizeWire");
436 neBEMMessage(
"DiscretizeWire - NbSegs in DiscretizeWire");
441 printf(
"nvertex: %d\n", nvertex);
442 for (
int vert = 0; vert < nvertex; ++vert) {
443 printf(
"vert: %d, x: %lg, y: %lg, z: %lg\n", vert, xvert[vert],
444 yvert[vert], zvert[vert]);
446 printf(
"radius: %lg\n", radius);
450 sprintf(primstr,
"%d", prim);
459 WireL = sqrt((xvert[1] - xvert[0]) * (xvert[1] - xvert[0])
460 + (yvert[1] - yvert[0]) * (yvert[1] - yvert[0]) +
461 (zvert[1] - zvert[0]) * (zvert[1] - zvert[0]));
463 WireElL = WireL / NbSegs;
468 PrimDirnCosn.
ZUnit.
X = (xvert[1] - xvert[0]) / WireL;
469 PrimDirnCosn.
ZUnit.
Y = (yvert[1] - yvert[0]) / WireL;
470 PrimDirnCosn.
ZUnit.
Z = (zvert[1] - zvert[0]) / WireL;
488 ZUnit.
X = PrimDirnCosn.
ZUnit.
X;
489 ZUnit.
Y = PrimDirnCosn.
ZUnit.
Y;
490 ZUnit.
Z = PrimDirnCosn.
ZUnit.
Z;
522 if (fabs(ZUnit.
X) >= fabs(ZUnit.
Z) && fabs(ZUnit.
Y) >= fabs(ZUnit.
Z)) {
526 }
else if (fabs(ZUnit.
X) >= fabs(ZUnit.
Y) &&
527 fabs(ZUnit.
Z) >= fabs(ZUnit.
Y)) {
543 PrimDirnCosn.
XUnit.
X = XUnit.
X;
544 PrimDirnCosn.
XUnit.
Y = XUnit.
Y;
545 PrimDirnCosn.
XUnit.
Z = XUnit.
Z;
546 PrimDirnCosn.
YUnit.
X = YUnit.
X;
547 PrimDirnCosn.
YUnit.
Y = YUnit.
Y;
548 PrimDirnCosn.
YUnit.
Z = YUnit.
Z;
577 strcat(OutPrim,
"/Primitives/Primitive");
578 strcat(OutPrim, primstr);
579 strcat(OutPrim,
".out");
580 fPrim = fopen(OutPrim,
"w");
585 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
586 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
587 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
588 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
590 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
591 fprintf(fPrim,
"#DirnCosn: \n");
592 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
594 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
596 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
598 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
599 fprintf(fPrim,
"#NbSegs: %d\n", NbSegs);
600 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", WireParentObj, WireEType);
601 fprintf(fPrim,
"#WireR: %lg\tWireL: %lg\n", WireR, WireL);
602 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", WireLambda, WireV);
609 strcat(gpPrim,
"/GViewDir/gpPrim");
610 strcat(gpPrim, primstr);
611 strcat(gpPrim,
".out");
612 fgpPrim = fopen(gpPrim,
"w");
613 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);
816 sprintf(primstr,
"%d", prim);
828 if ((SurfEType <= 0) || (SurfEType >= 8)) {
829 printf(
"Wrong SurfEType for prim %d\n", prim);
843 SurfLX = sqrt((xvert[0] - xvert[1]) * (xvert[0] - xvert[1]) +
844 (yvert[0] - yvert[1]) * (yvert[0] - yvert[1]) +
845 (zvert[0] - zvert[1]) * (zvert[0] - zvert[1]));
846 SurfLZ = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
847 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
848 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
850 PrimDirnCosn.
XUnit.
X = (xvert[0] - xvert[1]) / SurfLX;
851 PrimDirnCosn.
XUnit.
Y = (yvert[0] - yvert[1]) / SurfLX;
852 PrimDirnCosn.
XUnit.
Z = (zvert[0] - zvert[1]) / SurfLX;
853 PrimDirnCosn.
ZUnit.
X = (xvert[2] - xvert[1]) / SurfLZ;
854 PrimDirnCosn.
ZUnit.
Y = (yvert[2] - yvert[1]) / SurfLZ;
855 PrimDirnCosn.
ZUnit.
Z = (zvert[2] - zvert[1]) / SurfLZ;
858 if ((fabs(PrimDirnCosn.
YUnit.
X - xnorm) <= 1.0e-3) &&
859 (fabs(PrimDirnCosn.
YUnit.
Y - ynorm) <= 1.0e-3) &&
860 (fabs(PrimDirnCosn.
YUnit.
Z - znorm) <= 1.0e-3))
863 printf(
"First attempt: \n");
870 SurfLX = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
871 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
872 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
873 SurfLZ = sqrt((xvert[0] - xvert[1]) * (xvert[0] - xvert[1]) +
874 (yvert[0] - yvert[1]) * (yvert[0] - yvert[1]) +
875 (zvert[0] - zvert[1]) * (zvert[0] - zvert[1]));
877 PrimDirnCosn.
XUnit.
X = (xvert[2] - xvert[1]) / SurfLX;
878 PrimDirnCosn.
XUnit.
Y = (yvert[2] - yvert[1]) / SurfLX;
879 PrimDirnCosn.
XUnit.
Z = (zvert[2] - zvert[1]) / SurfLX;
880 PrimDirnCosn.
ZUnit.
X = (xvert[0] - xvert[1]) / SurfLZ;
881 PrimDirnCosn.
ZUnit.
Y = (yvert[0] - yvert[1]) / SurfLZ;
882 PrimDirnCosn.
ZUnit.
Z = (zvert[0] - zvert[1]) / SurfLZ;
885 if ((fabs(PrimDirnCosn.
YUnit.
X - xnorm) <= 1.0e-3) &&
886 (fabs(PrimDirnCosn.
YUnit.
Y - ynorm) <= 1.0e-3) &&
887 (fabs(PrimDirnCosn.
YUnit.
Z - znorm) <= 1.0e-3))
890 printf(
"Second attempt: \n");
898 printf(
"Triangle DC problem ... returning ...\n");
921 int tmpVolRef1 =
VolRef1[prim];
929 double SurfLambda = lambda;
930 double SurfV = potential;
936 strcat(OutPrim,
"/Primitives/Primitive");
937 strcat(OutPrim, primstr);
938 strcat(OutPrim,
".out");
939 fPrim = fopen(OutPrim,
"w");
944 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
945 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
946 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
947 fprintf(fPrim,
"Node3: %lg\t%lg\t%lg\n", xvert[2], yvert[2], zvert[2]);
948 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
950 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
951 fprintf(fPrim,
"Norm: %lg\t%lg\t%lg\n", xnorm, ynorm, znorm);
952 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
953 fprintf(fPrim,
"#NbSegX: %d, NbSegZ: %d (check note!)\n", NbSegX, NbSegZ);
954 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", SurfParentObj, SurfEType);
955 fprintf(fPrim,
"#SurfX\tSurfY\tSurfZ\tSurfLX\tSurfLZ (Rt. Corner)\n");
956 fprintf(fPrim,
"%lg\t%lg\t%lg\t%lg\t%lg\n", SurfX, SurfY, SurfZ, SurfLX,
958 fprintf(fPrim,
"#DirnCosn: \n");
959 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
961 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
963 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
965 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", SurfLambda, SurfV);
972 strcat(gpPrim,
"/GViewDir/gpPrim");
973 strcat(gpPrim, primstr);
974 strcat(gpPrim,
".out");
975 fgpPrim = fopen(gpPrim,
"w");
976 if (fgpPrim == NULL) {
980 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[0], yvert[0], zvert[0]);
981 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[1], yvert[1], zvert[1]);
982 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[2], yvert[2], zvert[2]);
983 fprintf(fgpPrim,
"%g\t%g\t%g\n", xvert[0], yvert[0], zvert[0]);
987 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
989 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
996 strcat(OutElem,
"/Elements/ElemOnPrim");
997 strcat(OutElem, primstr);
998 strcat(OutElem,
".out");
999 fElem = fopen(OutElem,
"w");
1000 if (fElem == NULL) {
1008 strcat(gpElem,
"/GViewDir/gpElemOnPrim");
1009 strcat(gpElem, primstr);
1010 strcat(gpElem,
".out");
1011 fgpElem = fopen(gpElem,
"w");
1013 if (fgpElem == NULL) {
1015 if (fElem) fclose(fElem);
1020 strcat(gpMesh,
"/GViewDir/gpMeshOnPrim");
1021 strcat(gpMesh, primstr);
1022 strcat(gpMesh,
".out");
1023 fgpMesh = fopen(gpMesh,
"w");
1024 if (fgpMesh == NULL) {
1027 if (fElem) fclose(fElem);
1048 if (NbSegX == NbSegZ) {
1049 SurfElLX = SurfLX / NbSegX;
1050 SurfElLZ = SurfLZ / NbSegZ;
1051 }
else if (NbSegX > NbSegZ) {
1052 if (SurfLX > SurfLZ) {
1053 SurfElLX = SurfLX / NbSegX;
1054 SurfElLZ = SurfLZ / NbSegZ;
1060 SurfElLX = SurfLX / NbSegX;
1061 SurfElLZ = SurfLZ / NbSegZ;
1066 if (SurfLX < SurfLZ) {
1067 SurfElLX = SurfLX / NbSegX;
1068 SurfElLZ = SurfLZ / NbSegZ;
1074 SurfElLX = SurfLX / NbSegX;
1075 SurfElLZ = SurfLZ / NbSegZ;
1084 double AR = SurfElLX / SurfElLZ;
1087 "Using the input, the aspect ratio of the elements on prim: %d\n",
1090 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1091 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1095 double tmpElLZ = SurfElLX / 10.0;
1096 NbSegZ = (int)(SurfLZ / tmpElLZ);
1097 if (NbSegZ <= 0) NbSegZ = 1;
1098 SurfElLZ = SurfLZ / NbSegZ;
1102 double tmpElLX = SurfElLZ * 0.1;
1103 NbSegX = (int)(SurfLX / tmpElLX);
1104 if (NbSegX <= 0) NbSegX = 1;
1105 SurfElLX = SurfLX / NbSegX;
1107 AR = SurfElLX / SurfElLZ;
1109 fprintf(fPrim,
"After analyzing the likely aspect ratio of the elements\n");
1111 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1112 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1124 double xv0, yv0, zv0, xv1, yv1, zv1, xv2, yv2, zv2;
1126 for (
int k = 1; k <= NbSegZ; ++k)
1128 double grad = (SurfLZ / SurfLX);
1129 double zlopt = (k - 1) * SurfElLZ;
1130 double zhipt = (k)*SurfElLZ;
1131 double xlopt = (SurfLZ - zlopt) / grad;
1132 double xhipt = (SurfLZ - zhipt) / grad;
1135 double xtorigin = xhipt;
1136 double ytorigin = 0.0;
1137 double ztorigin = zlopt;
1139 Point3D localDisp, globalDisp;
1141 localDisp.
X = xtorigin;
1142 localDisp.
Y = ytorigin;
1143 localDisp.
Z = ztorigin;
1146 SurfX + globalDisp.
X;
1148 SurfY + globalDisp.
Y;
1149 SurfElZ = SurfZ + globalDisp.
Z;
1155 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 1!");
1156 if (fgpElem) fclose(fgpElem);
1157 if (fgpMesh) fclose(fgpMesh);
1228 printf(
"Primitive nb: %d\n", (
EleArr +
EleCntr - 1)->PrimitiveNb);
1230 printf(
"Element X, Y, Z: %lg %lg %lg\n",
1234 printf(
"Element LX, LZ: %lg %lg\n", (
EleArr +
EleCntr - 1)->G.LX,
1236 printf(
"Element (primitive) X axis dirn cosines: %lg, %lg, %lg\n",
1238 printf(
"Element (primitive) Y axis dirn cosines: %lg, %lg, %lg\n",
1240 printf(
"Element (primitive) Z axis dirn cosines: %lg, %lg, %lg\n",
1248 Point3D localDisp, globalDisp;
1254 printf(
"Element dxl, dxy, dxz: %lg %lg %lg\n", localDisp.
X, localDisp.
Y,
1266 printf(
"Element global dxl, dxy, dxz: %lg %lg %lg\n", globalDisp.
X,
1267 globalDisp.
Y, globalDisp.
Z);
1268 printf(
"Element BCX, BCY, BCZ: %lg %lg %lg\n",
1277 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
1278 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
1279 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
1282 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
1283 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\n",
1289 fprintf(fElem,
"#DirnCosn: \n");
1290 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
1293 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
1296 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
1299 fprintf(fElem,
"#EType\tLambda\n");
1302 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
1303 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%lg\n",
1313 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1329 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv0, yv0, zv0);
1330 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv1, yv1, zv1);
1331 fprintf(fgpMesh,
"%g\t%g\t%g\n", xv2, yv2, zv2);
1332 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", xv0, yv0, zv0);
1340 double RowLX = xhipt;
1341 int NbSegXOnThisRow;
1342 double ElLXOnThisRow;
1343 if (RowLX <= SurfElLX) {
1344 NbSegXOnThisRow = 1;
1345 ElLXOnThisRow = RowLX;
1347 NbSegXOnThisRow = (int)(RowLX / SurfElLX);
1348 ElLXOnThisRow = RowLX / NbSegXOnThisRow;
1350 double x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3;
1351 for (
int i = 1; i <= NbSegXOnThisRow; ++i) {
1352 double xorigin = (i - 1) * ElLXOnThisRow + 0.5 * ElLXOnThisRow;
1353 double yorigin = 0.0;
1354 double zorigin = 0.5 * (zlopt + zhipt);
1361 Point3D localDisp, globalDisp;
1363 localDisp.
X = xorigin;
1364 localDisp.
Y = yorigin;
1365 localDisp.
Z = zorigin;
1367 SurfElX = SurfX + globalDisp.
X;
1368 SurfElY = SurfY + globalDisp.
Y;
1369 SurfElZ = SurfZ + globalDisp.
Z;
1379 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 2!");
1431 Point3D localDisp, globalDisp;
1447 Point3D localDisp, globalDisp;
1462 Point3D localDisp, globalDisp;
1477 Point3D localDisp, globalDisp;
1503 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
1504 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
1505 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
1509 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
1511 fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\t%.16lg\n",
1516 fprintf(fElem,
"#DirnCosn: \n");
1517 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
1520 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
1523 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
1526 fprintf(fElem,
"#EType\tLambda\n");
1529 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
1530 fprintf(fElem,
"%d\t%.16lg\t%.16lg\t%.16lg\t%lg\n",
1540 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1546 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
1547 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x1, y1, z1);
1548 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x2, y2, z2);
1549 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x3, y3, z3);
1550 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
1558 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
1560 fprintf(fPrim,
"Number of elements on primitive: %d\n",
1567 fprintf(
fgnuElem,
" '%s\' w p", gpElem);
1569 fprintf(
fgnuElem,
", \\\n \'%s\' w p", gpElem);
1571 fprintf(
fgnuMesh,
" '%s\' w l", gpMesh);
1572 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1574 fprintf(
fgnuMesh,
", \\\n \'%s\' w l", gpMesh);
1575 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1591 double zvert[],
double xnorm,
double ynorm,
1592 double znorm,
int volref1,
int volref2,
int inttype,
1593 double potential,
double charge,
double lambda,
1594 int NbSegX,
int NbSegZ) {
1595 int SurfParentObj, SurfEType;
1596 double SurfX, SurfY, SurfZ, SurfLX, SurfLZ;
1597 double SurfElX, SurfElY, SurfElZ, SurfElLX, SurfElLZ;
1600 char gpElem[256], gpMesh[256];
1601 FILE *fPrim, *fElem, *fgpPrim, *fgpElem, *fgpMesh;
1604 if ((NbSegX <= 0) || (NbSegZ <= 0)) {
1605 printf(
"segmentation input wrong in DiscretizeRectangle ...\n");
1610 printf(
"nvertex: %d\n", nvertex);
1611 for (
int vert = 0; vert < nvertex; ++vert) {
1612 printf(
"vert: %d, x: %lg, y: %lg, z: %lg\n", vert, xvert[vert],
1613 yvert[vert], zvert[vert]);
1615 printf(
"Normal: %lg, %lg, %lg\n", xnorm, ynorm, znorm);
1619 sprintf(primstr,
"%d", prim);
1635 SurfEType = inttype;
1636 if (SurfEType == 0) {
1637 printf(
"Wrong SurfEType for prim %d\n", prim);
1641 SurfX = 0.25 * (xvert[0] + xvert[1] + xvert[2] + xvert[3]);
1642 SurfY = 0.25 * (yvert[0] + yvert[1] + yvert[2] + yvert[3]);
1643 SurfZ = 0.25 * (zvert[0] + zvert[1] + zvert[2] + zvert[3]);
1645 SurfLX = sqrt((xvert[1] - xvert[0]) * (xvert[1] - xvert[0]) +
1646 (yvert[1] - yvert[0]) * (yvert[1] - yvert[0]) +
1647 (zvert[1] - zvert[0]) * (zvert[1] - zvert[0]));
1648 SurfLZ = sqrt((xvert[2] - xvert[1]) * (xvert[2] - xvert[1]) +
1649 (yvert[2] - yvert[1]) * (yvert[2] - yvert[1]) +
1650 (zvert[2] - zvert[1]) * (zvert[2] - zvert[1]));
1652 PrimDirnCosn.
XUnit.
X = (xvert[1] - xvert[0]) / SurfLX;
1653 PrimDirnCosn.
XUnit.
Y = (yvert[1] - yvert[0]) / SurfLX;
1654 PrimDirnCosn.
XUnit.
Z = (zvert[1] - zvert[0]) / SurfLX;
1655 PrimDirnCosn.
YUnit.
X = xnorm;
1656 PrimDirnCosn.
YUnit.
Y = ynorm;
1657 PrimDirnCosn.
YUnit.
Z = znorm;
1658 PrimDirnCosn.
ZUnit =
1679 double SurfLambda = lambda;
1680 double SurfV = potential;
1686 strcat(OutPrim,
"/Primitives/Primitive");
1687 strcat(OutPrim, primstr);
1688 strcat(OutPrim,
".out");
1689 fPrim = fopen(OutPrim,
"w");
1690 if (fPrim == NULL) {
1694 fprintf(fPrim,
"#prim: %d, nvertex: %d\n", prim, nvertex);
1695 fprintf(fPrim,
"Node1: %lg\t%lg\t%lg\n", xvert[0], yvert[0], zvert[0]);
1696 fprintf(fPrim,
"Node2: %lg\t%lg\t%lg\n", xvert[1], yvert[1], zvert[1]);
1697 fprintf(fPrim,
"Node3: %lg\t%lg\t%lg\n", xvert[2], yvert[2], zvert[2]);
1698 fprintf(fPrim,
"Node4: %lg\t%lg\t%lg\n", xvert[3], yvert[3], zvert[3]);
1699 fprintf(fPrim,
"PrimOrigin: %lg\t%lg\t%lg\n",
PrimOriginX[prim],
1701 fprintf(fPrim,
"Primitive lengths: %lg\t%lg\n",
PrimLX[prim],
PrimLZ[prim]);
1702 fprintf(fPrim,
"Norm: %lg\t%lg\t%lg\n", xnorm, ynorm, znorm);
1703 fprintf(fPrim,
"#volref1: %d, volref2: %d\n", volref1, volref2);
1704 fprintf(fPrim,
"#NbSegX: %d, NbSegZ: %d\n", NbSegX, NbSegZ);
1705 fprintf(fPrim,
"#ParentObj: %d\tEType: %d\n", SurfParentObj, SurfEType);
1706 fprintf(fPrim,
"#SurfX\tSurfY\tSurfZ\tSurfLZ\tSurfLZ\n");
1707 fprintf(fPrim,
"%lg\t%lg\t%lg\t%lg\t%lg\n", SurfX, SurfY, SurfZ, SurfLX,
1711 fprintf(fPrim,
"#DirnCosn: \n");
1712 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
XUnit.
X,
1714 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
YUnit.
X,
1716 fprintf(fPrim,
"%lg, %lg, %lg\n", PrimDirnCosn.
ZUnit.
X,
1718 fprintf(fPrim,
"#SurfLambda: %lg\tSurfV: %lg\n", SurfLambda, SurfV);
1725 strcat(gpPrim,
"/GViewDir/gpPrim");
1726 strcat(gpPrim, primstr);
1727 strcat(gpPrim,
".out");
1728 fgpPrim = fopen(gpPrim,
"w");
1729 if (fgpPrim == NULL) {
1733 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[0], yvert[0], zvert[0]);
1734 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[1], yvert[1], zvert[1]);
1735 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[2], yvert[2], zvert[2]);
1736 fprintf(fgpPrim,
"%g\t%g\t%g\n\n", xvert[3], yvert[3], zvert[3]);
1737 fprintf(fgpPrim,
"%g\t%g\t%g\n", xvert[0], yvert[0], zvert[0]);
1741 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
1743 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
1750 strcat(OutElem,
"/Elements/ElemOnPrim");
1751 strcat(OutElem, primstr);
1752 strcat(OutElem,
".out");
1753 fElem = fopen(OutElem,
"w");
1755 if (fElem == NULL) {
1764 strcat(gpElem,
"/GViewDir/gpElemOnPrim");
1765 strcat(gpElem, primstr);
1766 strcat(gpElem,
".out");
1767 fgpElem = fopen(gpElem,
"w");
1769 if (fgpElem == NULL) {
1771 if (fElem) fclose(fElem);
1776 strcat(gpMesh,
"/GViewDir/gpMeshOnPrim");
1777 strcat(gpMesh, primstr);
1778 strcat(gpMesh,
".out");
1779 fgpMesh = fopen(gpMesh,
"w");
1780 if (fgpMesh == NULL) {
1799 if (NbSegX == NbSegZ) {
1800 SurfElLX = SurfLX / NbSegX;
1801 SurfElLZ = SurfLZ / NbSegZ;
1802 }
else if (NbSegX > NbSegZ) {
1803 if (SurfLX > SurfLZ) {
1804 SurfElLX = SurfLX / NbSegX;
1805 SurfElLZ = SurfLZ / NbSegZ;
1811 SurfElLX = SurfLX / NbSegX;
1812 SurfElLZ = SurfLZ / NbSegZ;
1817 if (SurfLX < SurfLZ) {
1818 SurfElLX = SurfLX / NbSegX;
1819 SurfElLZ = SurfLZ / NbSegZ;
1825 SurfElLX = SurfLX / NbSegX;
1826 SurfElLZ = SurfLZ / NbSegZ;
1835 double AR = SurfElLX / SurfElLZ;
1838 "Using the input, the aspect ratio of the elements on prim: %d\n",
1841 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1842 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1846 double tmpElLZ = SurfElLX / 10.0;
1847 NbSegZ = (int)(SurfLZ / tmpElLZ);
1848 if (NbSegZ <= 0) NbSegZ = 1;
1849 SurfElLZ = SurfLZ / NbSegZ;
1853 double tmpElLX = SurfElLZ * 0.1;
1854 NbSegX = (int)(SurfLX / tmpElLX);
1855 if (NbSegX <= 0) NbSegX = 1;
1856 SurfElLX = SurfLX / NbSegX;
1858 AR = SurfElLX / SurfElLZ;
1860 fprintf(fPrim,
"After analyzing the aspect ratio of the elements\n");
1862 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1863 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1866 double x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3, xav, zav;
1868 for (
int i = 1; i <= NbSegX; ++i) {
1869 x1 = -SurfLX / 2.0 +
1870 (double)(i - 1) * SurfElLX;
1871 x2 = -SurfLX / 2.0 + (double)(i)*SurfElLX;
1872 xav = 0.5 * (x1 + x2);
1874 for (
int k = 1; k <= NbSegZ; ++k) {
1875 z1 = -SurfLZ / 2.0 + (double)(k - 1) * SurfElLZ;
1876 z2 = -SurfLZ / 2.0 + (double)(k)*SurfElLZ;
1877 zav = 0.5 * (z1 + z2);
1880 Point3D localDisp, globalDisp;
1886 SurfElX = SurfX + globalDisp.
X;
1887 SurfElY = SurfY + globalDisp.
Y;
1888 SurfElZ = SurfZ + globalDisp.
Z;
1894 neBEMMessage(
"DiscretizeRectangle - EleCntr more than NbElements!");
1895 if (fgpMesh) fclose(fgpMesh);
1940 Point3D localDisp, globalDisp;
1956 Point3D localDisp, globalDisp;
1971 Point3D localDisp, globalDisp;
1986 Point3D localDisp, globalDisp;
2012 fprintf(fElem,
"##Element Counter: %d\n",
EleCntr);
2013 fprintf(fElem,
"#DevNb\tCompNb\tPrimNb\tId\n");
2014 fprintf(fElem,
"%d\t%d\t%d\t%d\n", (
EleArr +
EleCntr - 1)->DeviceNb,
2018 fprintf(fElem,
"#GType\tX\tY\tZ\tLX\tLZ\tdA\n");
2020 fElem,
"%d\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\n",
2025 fprintf(fElem,
"#DirnCosn: \n");
2026 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.XUnit.X,
2029 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.YUnit.X,
2032 fprintf(fElem,
"%lg, %lg, %lg\n", (
EleArr +
EleCntr - 1)->G.DC.ZUnit.X,
2035 fprintf(fElem,
"#EType\tLambda\n");
2038 fprintf(fElem,
"#NbBCs\tCPX\tCPY\tCPZ\tValue\n");
2039 fprintf(fElem,
"%d\t%lg\t%lg\t%lg\t%lg\n",
2049 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
2055 fprintf(fgpMesh,
"%g\t%g\t%g\n", x0, y0, z0);
2056 fprintf(fgpMesh,
"%g\t%g\t%g\n", x1, y1, z1);
2057 fprintf(fgpMesh,
"%g\t%g\t%g\n", x2, y2, z2);
2058 fprintf(fgpMesh,
"%g\t%g\t%g\n", x3, y3, z3);
2059 fprintf(fgpMesh,
"%g\t%g\t%g\n\n", x0, y0, z0);
2077 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
2079 fprintf(fPrim,
"Number of elements on primitive: %d\n",
2088 fprintf(
fgnuElem,
" '%s\' w p", gpElem);
2090 fprintf(
fgnuElem,
", \\\n \'%s\' w p", gpElem);
2092 fprintf(
fgnuMesh,
" '%s\' w l", gpMesh);
2093 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
2095 fprintf(
fgnuMesh,
", \\\n \'%s\' w l", gpMesh);
2096 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
2107 double [],
double [],
double ,
2111 double ,
int NbSegX,
int NbSegZ) {
2113 if ((NbSegX <= 0) || (NbSegZ <= 0)) {
2114 printf(
"segmentation input wrong in DiscretizePolygon ...\n");
2129 for (
int ele = 1; ele <=
NbElements; ++ele) {
2130 int prim = (
EleArr + ele - 1)->PrimitiveNb;
2140 printf(
"Primitive out of range in BoundaryConditions ... returning\n");
int DiscretizePolygon(int, int, double[], double[], double[], double, double, double, int, int, int, double, double, double, int NbSegX, int NbSegZ)
int DiscretizeRectangle(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)
int BoundaryConditions(void)
Point3D RotatePoint3D(Point3D *A, DirnCosn3D *DC, int Sense)
Vector3D UnitVector3D(Vector3D *v)
Vector3D Vector3DCrossProduct(Vector3D *A, Vector3D *B)
int PrintDirnCosn3D(DirnCosn3D A)
int neBEMMessage(const char *message)
INTFACEGLOBAL int OptPrimitiveFiles
INTFACEGLOBAL FILE * fgnuPrim
INTFACEGLOBAL FILE * fgnuElem
INTFACEGLOBAL FILE * fgnuMesh
INTFACEGLOBAL int OptGnuplotPrimitives
INTFACEGLOBAL int OptPrintVertexAndNormal
INTFACEGLOBAL int OptElementFiles
INTFACEGLOBAL int OptGnuplot
INTFACEGLOBAL int OptGnuplotElements
neBEMGLOBAL Element * EleArr
neBEMGLOBAL double * ApplPot
neBEMGLOBAL int DebugLevel
neBEMGLOBAL int * NbElmntsOnPrim
neBEMGLOBAL char MeshOutDir[256]
neBEMGLOBAL double ** ZVertex
neBEMGLOBAL double ElementLengthRqstd
neBEMGLOBAL double * PrimOriginZ
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 NbElements
neBEMGLOBAL double * Epsilon1
neBEMGLOBAL double ** YVertex
neBEMGLOBAL double * PrimOriginY
neBEMGLOBAL DirnCosn3D * PrimDC
neBEMGLOBAL int AnalyzeSurface(int, int *, int *)
neBEMGLOBAL int * VolRef1
neBEMGLOBAL char ModelOutDir[256]
neBEMGLOBAL double ** XVertex
neBEMGLOBAL int * VolRef2
neBEMGLOBAL int * ElementEnd
neBEMGLOBAL int * PrimType
neBEMGLOBAL double * PrimLX
neBEMGLOBAL int DiscretizeWire(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 NbSegs)
neBEMGLOBAL double * Solution
neBEMGLOBAL int * ElementBgn
neBEMGLOBAL double * PrimOriginX
neBEMGLOBAL FILE * fMeshLog
neBEMGLOBAL int MaxNbElementsOnLength
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 int DiscretizeRectangle(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 int AnalyzeWire(int, int *)
neBEMGLOBAL double * PrimLZ
neBEMGLOBAL double * Epsilon2
neBEMGLOBAL int DiscretizeTriangle(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 int MinNbElementsOnLength