791 {
792 int SurfParentObj, SurfEType;
793 double SurfX, SurfY, SurfZ, SurfLX, SurfLZ;
794 double SurfElX, SurfElY, SurfElZ, SurfElLX, SurfElLZ;
796 char primstr[10];
797 char gpElem[256], gpMesh[256];
798 FILE *fPrim, *fElem, *fgpPrim, *fgpElem, *fgpMesh;
799
800
801 if ((NbSegX <= 0) || (NbSegZ <= 0)) {
802 printf("segmentation input wrong in DiscretizeTriangle ...\n");
803 return -1;
804 }
805
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]);
811 }
812 printf("Normal: %lg, %lg, %lg\n", xnorm, ynorm, znorm);
813 }
814
815
816 sprintf(primstr, "%d", prim);
817
818
819 fPrim = NULL;
820 fElem = NULL;
821 fgpMesh = NULL;
822 fgpElem = NULL;
823
824
825
826 SurfParentObj = 1;
827 SurfEType = inttype;
828 if ((SurfEType <= 0) || (SurfEType >= 8)) {
829 printf("Wrong SurfEType for prim %d\n", prim);
830 exit(-1);
831 }
832
833 SurfX = xvert[1];
834 SurfY = yvert[1];
835 SurfZ = zvert[1];
836
837
838
839 int flagDC = 0;
840
841
842
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]));
849
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))
861 flagDC = 1;
863 printf("First attempt: \n");
865 printf("\n");
866 }
867
868 if (!flagDC)
869 {
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]));
876
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))
888 flagDC = 2;
890 printf("Second attempt: \n");
892 printf("\n");
893 }
894 }
895
896 if (!flagDC)
897 {
898 printf("Triangle DC problem ... returning ...\n");
899
900 return -1;
901 }
902
903
913
914
920 if (flagDC == 1) {
921 int tmpVolRef1 =
VolRef1[prim];
927 }
928
929 double SurfLambda = lambda;
930 double SurfV = potential;
931
932
934 char OutPrim[256];
936 strcat(OutPrim, "/Primitives/Primitive");
937 strcat(OutPrim, primstr);
938 strcat(OutPrim, ".out");
939 fPrim = fopen(OutPrim, "w");
940 if (fPrim == NULL) {
942 return -1;
943 }
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,
957 SurfLZ);
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);
966 }
967
968
970 char gpPrim[256];
972 strcat(gpPrim, "/GViewDir/gpPrim");
973 strcat(gpPrim, primstr);
974 strcat(gpPrim, ".out");
975 fgpPrim = fopen(gpPrim, "w");
976 if (fgpPrim == NULL) {
978 return -1;
979 }
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]);
984 fclose(fgpPrim);
985
986 if (prim == 1)
987 fprintf(
fgnuPrim,
" '%s\' w l", gpPrim);
988 else
989 fprintf(
fgnuPrim,
", \\\n \'%s\' w l", gpPrim);
990 }
991
992
994 char OutElem[256];
996 strcat(OutElem, "/Elements/ElemOnPrim");
997 strcat(OutElem, primstr);
998 strcat(OutElem, ".out");
999 fElem = fopen(OutElem, "w");
1000 if (fElem == NULL) {
1002 return -1;
1003 }
1004 }
1005
1008 strcat(gpElem, "/GViewDir/gpElemOnPrim");
1009 strcat(gpElem, primstr);
1010 strcat(gpElem, ".out");
1011 fgpElem = fopen(gpElem, "w");
1012
1013 if (fgpElem == NULL) {
1015 if (fElem) fclose(fElem);
1016 return -1;
1017 }
1018
1020 strcat(gpMesh, "/GViewDir/gpMeshOnPrim");
1021 strcat(gpMesh, primstr);
1022 strcat(gpMesh, ".out");
1023 fgpMesh = fopen(gpMesh, "w");
1024 if (fgpMesh == NULL) {
1026 fclose(fgpElem);
1027 if (fElem) fclose(fElem);
1028 return -1;
1029 }
1030 }
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
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;
1055 } else
1056 {
1057 int tmp = NbSegZ;
1058 NbSegZ = NbSegX;
1059 NbSegX = tmp;
1060 SurfElLX = SurfLX / NbSegX;
1061 SurfElLZ = SurfLZ / NbSegZ;
1062 }
1063 }
1064 else
1065 {
1066 if (SurfLX < SurfLZ) {
1067 SurfElLX = SurfLX / NbSegX;
1068 SurfElLZ = SurfLZ / NbSegZ;
1069 } else
1070 {
1071 int tmp = NbSegZ;
1072 NbSegZ = NbSegX;
1073 NbSegX = tmp;
1074 SurfElLX = SurfLX / NbSegX;
1075 SurfElLZ = SurfLZ / NbSegZ;
1076 }
1077 }
1078
1079
1080
1081
1082
1083
1084 double AR = SurfElLX / SurfElLZ;
1086 fprintf(fPrim,
1087 "Using the input, the aspect ratio of the elements on prim: %d\n",
1088 prim);
1089 fprintf(fPrim,
1090 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1091 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1092 }
1093 if (AR > 10.0)
1094 {
1095 double tmpElLZ = SurfElLX / 10.0;
1096 NbSegZ = (int)(SurfLZ / tmpElLZ);
1097 if (NbSegZ <= 0) NbSegZ = 1;
1098 SurfElLZ = SurfLZ / NbSegZ;
1099 }
1100 if (AR < 0.1)
1101 {
1102 double tmpElLX = SurfElLZ * 0.1;
1103 NbSegX = (int)(SurfLX / tmpElLX);
1104 if (NbSegX <= 0) NbSegX = 1;
1105 SurfElLX = SurfLX / NbSegX;
1106 }
1107 AR = SurfElLX / SurfElLZ;
1109 fprintf(fPrim, "After analyzing the likely aspect ratio of the elements\n");
1110 fprintf(fPrim,
1111 "NbSegX: %d, SurfElLX: %lg, NbSegZ: %d, SurfElLZ: %lg, AR: %lg\n",
1112 NbSegX, SurfElLX, NbSegZ, SurfElLZ, AR);
1113 }
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124 double xv0, yv0, zv0, xv1, yv1, zv1, xv2, yv2, zv2;
1126 for (int k = 1; k <= NbSegZ; ++k)
1127 {
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;
1133
1134
1135 double xtorigin = xhipt;
1136 double ytorigin = 0.0;
1137 double ztorigin = zlopt;
1138 {
1139 Point3D localDisp, globalDisp;
1140
1141 localDisp.
X = xtorigin;
1142 localDisp.
Y = ytorigin;
1143 localDisp.
Z = ztorigin;
1145 SurfElX =
1146 SurfX + globalDisp.
X;
1147 SurfElY =
1148 SurfY + globalDisp.
Y;
1149 SurfElZ = SurfZ + globalDisp.
Z;
1150 }
1151
1152
1155 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 1!");
1156 if (fgpElem) fclose(fgpElem);
1157 if (fgpMesh) fclose(fgpMesh);
1158 return -1;
1159 }
1160
1162 1;
1170
1171
1173 xlopt - xhipt;
1176 zhipt - zlopt;
1179
1180
1194
1195
1197
1213
1226
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",
1242 }
1243
1245 double dyl = 0.0;
1247 {
1248 Point3D localDisp, globalDisp;
1249
1254 printf(
"Element dxl, dxy, dxz: %lg %lg %lg\n", localDisp.
X, localDisp.
Y,
1256 }
1257
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",
1272 }
1273 }
1274
1275
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",
1309 }
1310
1311
1313 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1316
1317
1318
1328
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);
1333 }
1334
1335 if (k == NbSegZ)
1336 continue;
1337
1338
1339
1340 double RowLX = xhipt;
1341 int NbSegXOnThisRow;
1342 double ElLXOnThisRow;
1343 if (RowLX <= SurfElLX) {
1344 NbSegXOnThisRow = 1;
1345 ElLXOnThisRow = RowLX;
1346 } else {
1347 NbSegXOnThisRow = (int)(RowLX / SurfElLX);
1348 ElLXOnThisRow = RowLX / NbSegXOnThisRow;
1349 }
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);
1355
1356
1357
1358
1359
1360 {
1361 Point3D localDisp, globalDisp;
1362
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;
1370 }
1371
1372
1373
1374
1375
1376
1379 neBEMMessage(
"DiscretizeTriangle - EleCntr more than NbElements 2!");
1380 return -1;
1381 }
1382
1384 1;
1395 zhipt - zlopt;
1398
1399
1400
1414
1415
1417
1421
1422
1423
1424
1425
1426 x0 = -0.5 *
1428 y0 = 0.0;
1430 {
1431 Point3D localDisp, globalDisp;
1432
1441 }
1442
1444 y1 = 0.0;
1446 {
1447 Point3D localDisp, globalDisp;
1448
1456 }
1457
1459 y2 = 0.0;
1461 {
1462 Point3D localDisp, globalDisp;
1463
1471 }
1472
1474 y3 = 0.0;
1476 {
1477 Point3D localDisp, globalDisp;
1478
1486 }
1487
1488
1501
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");
1510 fprintf(
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",
1536 }
1537
1538
1540 fprintf(fgpElem,
"%g\t%g\t%g\n", (
EleArr +
EleCntr - 1)->BC.CollPt.X,
1543 }
1544
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);
1551 }
1552 }
1553 }
1556
1558 fprintf(fPrim,
"Element begin: %d, Element end: %d\n",
ElementBgn[prim],
1560 fprintf(fPrim, "Number of elements on primitive: %d\n",
1562 fclose(fPrim);
1563 }
1564
1566 if (prim == 1)
1567 fprintf(
fgnuElem,
" '%s\' w p", gpElem);
1568 else
1569 fprintf(
fgnuElem,
", \\\n \'%s\' w p", gpElem);
1570 if (prim == 1) {
1571 fprintf(
fgnuMesh,
" '%s\' w l", gpMesh);
1572 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1573 } else {
1574 fprintf(
fgnuMesh,
", \\\n \'%s\' w l", gpMesh);
1575 fprintf(
fgnuMesh,
", \\\n \'%s\' w p ps 1", gpElem);
1576 }
1577
1578 fclose(fgpElem);
1579 fclose(fgpMesh);
1580 }
1581
1583
1584 return (0);
1585}
int PrintDirnCosn3D(DirnCosn3D A)
DoubleAc fabs(const DoubleAc &f)
neBEMGLOBAL int DebugLevel
neBEMGLOBAL double * Epsilon1
neBEMGLOBAL int * VolRef1
neBEMGLOBAL int * VolRef2
neBEMGLOBAL double * Epsilon2