2527 {
2528 int debugFn = 0;
2529
2530
2531 if (debugFn) {
2532 for (
int ele = 1; ele <=
NbElements; ++ele) {
2533 printf("ele, Assigned charge: %d, %lg\n", ele,
2534 (
EleArr + ele - 1)->Assigned);
2535 }
2536 }
2537
2538
2539
2540
2541 {
2542 FILE *ChargingUpInpFile = fopen("neBEMInp/neBEMChargingUp.inp", "r");
2543 if (ChargingUpInpFile == NULL) {
2544 printf(
2545 "neBEMChargingUp.inp absent ... assuming no charging up effect "
2546 "...\n");
2547
2548 } else {
2549 fscanf(ChargingUpInpFile,
"OptChargingUp: %d\n", &
OptChargingUp);
2551 printf("OptChargingUp = 0 ... assuming no charging up effect ...\n");
2553
2555 char ChargingUpEFile[256];
2556 char ChargingUpIFile[256];
2557 double LScaleFactor;
2558 double ChUpFactor;
2559
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);
2564 if (1) {
2565 printf("ChargingUpEFile: %s\n", ChargingUpEFile);
2566 printf("ChargingUpIFile: %s\n", ChargingUpIFile);
2567 printf("LScaleFactor: %lg\n", LScaleFactor);
2568 printf("ChUpFactor: %lg\n", ChUpFactor);
2569 }
2570
2571 {
2572 FILE *fptrChargingUpEFile = fopen(ChargingUpEFile, "r");
2573 if (fptrChargingUpEFile == NULL) {
2574 neBEMMessage(
"ChargingUpE file absent ... returning\n");
2575 fclose(ChargingUpInpFile);
2576 return -10;
2577 }
2579 if (NbOfE <= 1) {
2580 neBEMMessage(
"Too few lines in ChargingUpE ... returning\n");
2581 fclose(fptrChargingUpEFile);
2582 return -11;
2583 }
2584
2585 int* NbChUpEonEle = (
int *)malloc((
NbElements + 1) *
sizeof(
int));
2586 for (
int ele = 0; ele <=
NbElements; ++ele) {
2587
2588 NbChUpEonEle[ele] = 0;
2589 }
2590
2591
2592 char header[256];
2593 fgets(header, 256, fptrChargingUpEFile);
2594
2595 --NbOfE;
2596 if (debugFn) printf("No. of electrons: %d\n", NbOfE);
2597 char tmpEFile[256];
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");
2602 free(NbChUpEonEle);
2603 return -100;
2604 }
2605 FILE *fPtEChUpMap = fopen("PtEChUpMap.out", "w");
2606 if (fPtEChUpMap == NULL) {
2607 printf("cannot open PtEChUpMap.out file for writing ...\n");
2608 fclose(ftmpEF);
2609 return 110;
2610 }
2611
2612 char label;
2613 int vol, enb;
2614 double xlbend, ylbend, zlbend, xend, yend,
2615 zend;
2617 ptintsct;
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,
2621 &zend);
2622 xlbend /= LScaleFactor;
2623 xend /= LScaleFactor;
2624 ylbend /= LScaleFactor;
2625 yend /= LScaleFactor;
2626 zlbend /= LScaleFactor;
2627 zend /= LScaleFactor;
2631
2632
2633
2634
2635
2636
2637 if (xend < xlbend)
2638 {
2639 }
2640 double lseg = (xend - xlbend) * (xend - xlbend) +
2641 (yend - ylbend) * (yend - ylbend) +
2642 (zend - zlbend) * (zend - zlbend);
2644 double xgrd =
2645 (xend - xlbend) / lseg;
2646 double ygrd = (yend - ylbend) / lseg;
2647 double zgrd = (zend - zlbend) / lseg;
2648 if (debugFn) {
2649 printf("\nelectron: %d\n", electron);
2650 printf("xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
2651 zlbend);
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,
2655 vol);
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,
2659 zgrd);
2660 fprintf(ftmpEF, "\n");
2661 }
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676 double SumOfAngles;
2677 int PrimIntsctd = -1,
2678 EleIntsctd = -1;
2679 int nearestprim = -1;
2680 double dist = 1.0e6, mindist = 1.0e6;
2681
2684 continue;
2685
2686 int intersect = 0, extrasect = 1;
2687 int InPrim = 0, InEle = 0;
2688 if (debugFn)
2689 printf("prim: %d, mindist: %lg, nearestprim: %d\n", prim,
2690 mindist, nearestprim);
2691
2692
2693
2694
2695
2696
2698 if (debugFn) {
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],
2709 }
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],
2720 }
2721 fprintf(ftmpEF,
"%lg %lg %lg\n",
XVertex[prim][0],
2723 fprintf(ftmpEF, "\n");
2724 fflush(stdout);
2725 }
2726
2727
2728
2729 double a =
XNorm[prim];
2730 double b =
YNorm[prim];
2731 double c =
ZNorm[prim];
2734
2735
2736 dist = (xend * a + yend * b + zend * c + d) /
2737 sqrt(a * a + b * b + c * c);
2739 if (prim == 1) {
2740 mindist = dist;
2741 nearestprim = prim;
2742 }
2743 if ((prim == 1) && debugFn)
2744 printf(
2745 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
2746 mindist, nearestprim);
2747
2748
2749
2750
2751
2752
2753
2754
2755 double norm1 =
sqrt(a * a + b * b + c * c);
2756 double norm2 =
sqrt(xgrd * xgrd + ygrd * ygrd + zgrd * zgrd);
2757 double denom =
2758 a * xgrd + b * ygrd + c * zgrd;
2759 double tol =
2760 1.0e-16;
2761 intersect = extrasect = 0;
2762
2763 if (debugFn) {
2764 printf("a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
2765 d, dist);
2766 printf("vector n: ai + bj + ck\n");
2767 printf("vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
2768 ygrd, zgrd);
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");
2772 fflush(stdout);
2773 }
2774
2775 if (
fabs(denom) < tol * norm1 * norm2) {
2776
2777 if (
fabs(a * xlbend + b * ylbend + c * zlbend + d) <=
2778 1.0e-16) {
2779 intersect = 1;
2780 extrasect = 0;
2781 ptintsct.
X = xlbend;
2782 ptintsct.
Y = ylbend;
2783 ptintsct.
Z = zlbend;
2784 } else {
2785 intersect = 0;
2786 extrasect = 1;
2789 0.0;
2791 }
2792 if (debugFn) {
2793 printf("line and plane parallel ...\n");
2794 printf("intersect: %d, extrasect: %d\n", intersect,
2795 extrasect);
2796 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2797 ptintsct.
Y, ptintsct.
Z);
2798 }
2799 } else {
2800 intersect = 1;
2801 double t =
2802 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
2803
2804
2805
2806
2807
2808 if ((t < 0.0) ||
2810 {
2811 extrasect = 1;
2812 ptintsct.
X = xlbend + t * xgrd;
2813 ptintsct.
Y = ylbend + t * ygrd;
2814 ptintsct.
Z = zlbend + t * zgrd;
2815 } else {
2816 extrasect = 0;
2817 ptintsct.
X = xlbend + t * xgrd;
2818 ptintsct.
Y = ylbend + t * ygrd;
2819 ptintsct.
Z = zlbend + t * zgrd;
2820 }
2821 if (debugFn) {
2822 printf("line and plane NOT parallel ...\n");
2823 printf("intersect: %d, extrasect: %d\n", intersect,
2824 extrasect);
2825 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
2826 ptintsct.
Y, ptintsct.
Z);
2827 printf("t, lseg: %lg, %lg\n", t, lseg);
2828 printf(
2829 "for an interesting intersection, lseg > t > 0.0 "
2830 "...\n\n");
2831 fflush(stdout);
2832 }
2833 }
2834 }
2835 else {
2836 dist = -1.0;
2837 intersect = 0;
2838 extrasect = 0;
2839 continue;
2840 }
2841
2842 if (dist < mindist) {
2843 mindist = dist;
2844 nearestprim = prim;
2845 }
2846 if (debugFn)
2847 printf("nearestprim: %d, mindist: %lg\n\n", nearestprim,
2848 mindist);
2849
2850
2851
2852
2853
2854 if ((intersect == 1) && (extrasect == 0)) {
2855
2856
2872 }
2873
2876 InPrim = 1;
2877 PrimIntsctd = prim;
2878 }
2879 if (debugFn) {
2880
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);
2891 if (nvert == 4) {
2892 printf("polynode3: %lg, %lg, %lg\n", polynode[3].X,
2893 polynode[3].Y, polynode[3].Z);
2894 }
2895 printf("SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
2896 fflush(stdout);
2897 }
2898
2900 continue;
2901 }
2902
2903
2904
2905 if (InPrim) {
2906 InEle = 0;
2908 ++ele) {
2909 nvert = 0;
2910 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
2911 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
2912 if (!nvert) {
2914 "no vertex in element! ... neBEMKnownCharges ...\n");
2915 fclose(fPtEChUpMap);
2916 return -20;
2917 }
2918
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;
2928 if (nvert == 4) {
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;
2932 }
2933
2934
2937 InEle = 1;
2938 if (debugFn) {
2939
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);
2950 if (nvert == 4) {
2951 printf("polynode3: %lg, %lg, %lg\n", polynode[3].X,
2952 polynode[3].Y, polynode[3].Z);
2953 }
2954 printf("SumOfAngles: %lg, InEle: %d\n", SumOfAngles,
2955 InEle);
2956 fflush(stdout);
2957 }
2958 if (InEle) {
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;
2962
2963 EleIntsctd = ele;
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);
2968
2969 if (debugFn) {
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);
2976 printf(
2977 "# Associated element and origin: %d, %lg, %lg, "
2978 "%lg\n",
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",
2983 NbChUpEonEle[ele]);
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);
2991 if (nvert == 4) {
2992 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[3].X,
2993 polynode[3].Y, polynode[3].Z);
2994 }
2995 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[0].X,
2996 polynode[0].Y, polynode[0].Z);
2997 fprintf(ftmpEF, "\n");
2998 fflush(stdout);
2999 }
3000 break;
3001 }
3002 }
3003
3004 if (InEle)
3005 break;
3006 else {
3008 "Element not identified ... neBEMKnownCharges\n");
3009 return -2;
3010 }
3011 }
3012 }
3013
3014 if ((InPrim) && (intersect) && (!extrasect) &&
3015 (InEle))
3016 break;
3017
3018
3019
3020 if (prim ==
3022 {
3023 int nvert;
3026 double distele = 1.0e6,
3027 mindistele = 1.0e6;
3028
3029 if (debugFn) {
3030 printf("prim == (NbPrimitives) ... checking nearest ...\n");
3031 printf("nearestprim: %d, mindist: %lg\n", nearestprim,
3032 mindist);
3033 }
3034
3035 if (mindist <= 10.0e-6) {
3036 PrimIntsctd = nearestprim;
3037 InPrim = 1;
3038 } else {
3039 InPrim = 0;
3040 InEle = 0;
3041 break;
3042 }
3043
3046 nvert = 0;
3047 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3048 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3049 if (!nvert) {
3051 "no vertex element! ... neBEMKnownCharges ...\n");
3052 return -20;
3053 }
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
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);
3135
3137 mindistele = distele;
3138 nearestele = ele;
3139 }
3140 if (distele < mindistele) {
3141 mindistele = distele;
3142 nearestele = ele;
3143 }
3144
3145 if (debugFn) {
3146
3147
3148
3149
3150
3151 printf(
3152 "distele: %lg, mindistele: %lg,from nearest ele "
3153 "origin: %d\n",
3154 distele, mindistele, nearestele);
3155 fflush(stdout);
3156 }
3157
3158
3159 }
3160
3161
3162
3163 EleIntsctd = nearestele;
3164 InEle = 1;
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]++;
3169
3170 fprintf(fPtEChUpMap, "%d %lg %lg %lg %d %d %d %d\n", electron,
3171 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3172 EleIntsctd, InEle);
3173
3174
3175 if (debugFn) {
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]);
3187 fflush(stdout);
3188
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;
3199 if (nvert == 4) {
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;
3203 }
3204 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3205 polynode[0].Z);
3206 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3207 polynode[1].Z);
3208 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3209 polynode[2].Z);
3210 if (nvert == 4) {
3211 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[3].X,
3212 polynode[3].Y, polynode[3].Z);
3213 }
3214 fprintf(ftmpEF, "%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3215 polynode[0].Z);
3216 fprintf(ftmpEF, "\n");
3217 }
3218 }
3219
3220 }
3221
3222 if (debugFn)
3223 printf("writing file for checking electron positions\n");
3224
3225 if (debugFn)
3226
3227 {
3228 char enbstr[12];
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");
3235 if (fepd == NULL) {
3236 printf(
3237 "cannot open writable file to debug electron positions "
3238 "...\n");
3239 printf("returning ...\n");
3240 return -111;
3241 }
3242
3243
3244 fprintf(fepd, "#electron: %d %d\n", enb,
3245 electron);
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],
3263 }
3264 fprintf(fepd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
3266 fprintf(fepd, "\n");
3267
3268 fprintf(fepd, "#ptintsct:\n");
3269 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3271 fprintf(fepd, "\n");
3272 }
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);
3290 if (gtype == 4) {
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);
3295 }
3296 fprintf(fepd, "%lg %lg %lg\n", x0, y0, z0);
3297 fprintf(fepd, "\n");
3298
3299 fprintf(fepd, "#ptintsct:\n");
3300 fprintf(fepd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
3302 fprintf(fepd, "\n");
3303 }
3304
3305 fclose(fepd);
3306 }
3307 if (debugFn)
3308 printf("done writing file for checking electron positions\n");
3309 }
3310 fclose(fPtEChUpMap);
3311 if (debugFn) printf("done for all electrons\n");
3312
3313 FILE *fEleEChUpMap = fopen("EleEChUpMap.out", "w");
3314 if (fEleEChUpMap == NULL) {
3315 printf("cannot open EleEChUpMap.out file for writing ...\n");
3316 return 111;
3317 }
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);
3326 }
3327 fclose(fEleEChUpMap);
3328
3329 fclose(ftmpEF);
3330 free(NbChUpEonEle);
3331 }
3332
3333 {
3334 FILE *fptrChargingUpIFile = fopen(ChargingUpIFile, "r");
3335 if (fptrChargingUpIFile == NULL) {
3336 neBEMMessage(
"ChargingUpI file absent ... returning\n");
3337 return -10;
3338 }
3340 if (NbOfI <= 1) {
3341 neBEMMessage(
"Too few lines in ChargingUpI ... returning\n");
3342 fclose(fptrChargingUpIFile);
3343 return -11;
3344 }
3345
3346 int* NbChUpIonEle = (
int *)malloc((
NbElements + 1) *
sizeof(
int));
3347 for (
int ele = 0; ele <=
NbElements; ++ele) {
3348
3349 NbChUpIonEle[ele] = 0;
3350 }
3351
3352
3353 char header[256];
3354 fgets(header, 256, fptrChargingUpIFile);
3355
3356 --NbOfI;
3357 if (debugFn) printf("No. of ions: %d\n", NbOfI);
3358 char tmpIFile[256];
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");
3363 free(NbChUpIonEle);
3364 return -100;
3365 }
3366 FILE *fPtIChUpMap = fopen("PtIChUpMap.out", "w");
3367 if (fPtIChUpMap == NULL) {
3368 printf("cannot open PtIChUpMap.out file for writing ...\n");
3369 fclose(ftmpIF);
3370 return 110;
3371 }
3372
3373 char label;
3374 int inb, vol;
3375 double xlbend, ylbend, zlbend, xend, yend,
3376 zend;
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,
3381 &zend);
3382 xlbend /= LScaleFactor;
3383 xend /= LScaleFactor;
3384 ylbend /= LScaleFactor;
3385 yend /= LScaleFactor;
3386 zlbend /= LScaleFactor;
3387 zend /= LScaleFactor;
3391
3392
3393
3394
3395
3396
3397 if (xend < xlbend)
3398 {
3399 }
3400 double lseg = (xend - xlbend) * (xend - xlbend) +
3401 (yend - ylbend) * (yend - ylbend) +
3402 (zend - zlbend) * (zend - zlbend);
3404 double xgrd =
3405 (xend - xlbend) / lseg;
3406 double ygrd = (yend - ylbend) / lseg;
3407 double zgrd = (zend - zlbend) / lseg;
3408 if (debugFn) {
3409 printf("\nion: %d\n", ion);
3410 printf("xlbend: %lg, ylbend: %lg, zlbend: %lg\n", xlbend, ylbend,
3411 zlbend);
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,
3418 zgrd);
3419 fprintf(ftmpIF, "\n");
3420 }
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435 int PrimIntsctd = -1,
3436 EleIntsctd = -1;
3437 int nearestprim = -1;
3438 double dist = 1.0e6, mindist = 1.0e6;
3439 double SumOfAngles;
3440
3443 continue;
3444
3445 int intersect = 0, extrasect = 1;
3446 int InPrim = 0, InEle = 0;
3447 if (debugFn)
3448 printf("prim: %d, mindist: %lg, nearestprim: %d\n", prim,
3449 mindist, nearestprim);
3450
3451
3452
3453
3454
3455
3456
3457
3459 if (debugFn) {
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],
3470 }
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],
3481 }
3482 fprintf(ftmpIF,
"%lg %lg %lg\n",
XVertex[prim][0],
3484 fprintf(ftmpIF, "\n");
3485 fflush(stdout);
3486 }
3487
3488
3489
3493
3494
3495 dist =
3497 zend *
ZNorm[prim] + d) /
3501 if (prim == 1) {
3502 mindist = dist;
3503 nearestprim = prim;
3504 }
3505 if ((prim == 1) && debugFn)
3506 printf(
3507 "after prim == 1 check mindist: %lg, nearestprim: %d\n",
3508 mindist, nearestprim);
3509
3510
3511
3512
3513
3514
3515
3516
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);
3522 double denom =
3523 a * xgrd + b * ygrd + c * zgrd;
3524 double tol =
3525 1.0e-12;
3526 intersect = extrasect = 0;
3527
3528 if (debugFn) {
3529 printf("a, b, c, d, dist: %lg, %lg, %lg, %lg, %lg\n", a, b, c,
3530 d, dist);
3531 printf("vector n: ai + bj + ck\n");
3532 printf("vector v: xgrd, ygrd, zgrd: %lg, %lg, %lg\n", xgrd,
3533 ygrd, zgrd);
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");
3537 fflush(stdout);
3538 }
3539
3541 tol * norm1 * norm2)
3542 {
3543 if (a * xlbend + b * ylbend + c * zlbend + d ==
3544 0.0)
3545 {
3546 intersect = 1;
3547 extrasect = 0;
3548 ptintsct.
X = xlbend;
3549 ptintsct.
Y = ylbend;
3550 ptintsct.
Z = zlbend;
3551 } else {
3552 intersect = 0;
3553 extrasect = 0;
3556 0.0;
3558 }
3559 if (debugFn) {
3560 printf("line and plane parallel ...\n");
3561 printf("intersect: %d, extrasect: %d\n", intersect,
3562 extrasect);
3563 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3564 ptintsct.
Y, ptintsct.
Z);
3565 }
3566 } else {
3567 intersect = 1;
3568 double t =
3569 -(a * xlbend + b * ylbend + c * zlbend + d) / denom;
3570
3571
3572
3573
3574
3575 if ((t < 0.0) || (
fabs(t) >
fabs(lseg))) {
3576 extrasect = 1;
3577 ptintsct.
X = xlbend + t * xgrd;
3578 ptintsct.
Y = ylbend + t * ygrd;
3579 ptintsct.
Z = zlbend + t * zgrd;
3580 } else {
3581 extrasect = 0;
3582 ptintsct.
X = xlbend + t * xgrd;
3583 ptintsct.
Y = ylbend + t * ygrd;
3584 ptintsct.
Z = zlbend + t * zgrd;
3585 }
3586 if (debugFn) {
3587 printf("line and plane NOT parallel ...\n");
3588 printf("intersect: %d, extrasect: %d\n", intersect,
3589 extrasect);
3590 printf(
"intersection point: %lg, %lg, %lg\n", ptintsct.
X,
3591 ptintsct.
Y, ptintsct.
Z);
3592 printf("t, lseg: %lg, %lg\n", t, lseg);
3593 printf(
3594 "for an interesting intersection, lseg > t > 0.0 "
3595 "...\n\n");
3596 fflush(stdout);
3597 }
3598 }
3599 }
3600 else {
3601 dist = -1.0;
3602 intersect = 0;
3603 extrasect = 0;
3604 }
3605
3606 if (dist < mindist) {
3607 mindist = dist;
3608 nearestprim = prim;
3609 }
3610
3611
3612
3613
3614
3615 if ((intersect == 1) && (extrasect == 0)) {
3616
3617
3633 }
3634
3637 InPrim = 1;
3638 PrimIntsctd = prim;
3639 }
3640 if (debugFn) {
3641
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);
3652 if (nvert == 4) {
3653 printf("polynode3: %lg, %lg, %lg\n", polynode[3].X,
3654 polynode[3].Y, polynode[3].Z);
3655 }
3656 printf("SumOfAngles: %lg, InPrim: %d\n", SumOfAngles, InPrim);
3657 fflush(stdout);
3658 }
3659 if (!InPrim) continue;
3660
3661
3662
3663 InEle = 0;
3665 ++ele) {
3666 nvert = 0;
3667 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3668 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3669 if (!nvert) {
3671 "no vertex in element! ... neBEMKnownCharges ...\n");
3672 fclose(fPtIChUpMap);
3673 return -20;
3674 }
3675
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;
3685 if (nvert == 4) {
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;
3689 }
3690
3691
3694 if (debugFn) {
3695
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);
3706 if (nvert == 4) {
3707 printf("polynode3: %lg, %lg, %lg\n", polynode[3].X,
3708 polynode[3].Y, polynode[3].Z);
3709 }
3710 printf("SumOfAngles: %lg, InEle: %d\n", SumOfAngles, InEle);
3711 fflush(stdout);
3712 }
3713 if (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;
3717 EleIntsctd = ele;
3718
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,
3722 ele, InEle);
3723
3724 if (debugFn) {
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);
3731 printf(
3732 "# Associated element and origin: %d, %lg, %lg, "
3733 "%lg\n",
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",
3738 NbChUpIonEle[ele]);
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);
3746 if (nvert == 4) {
3747 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[3].X,
3748 polynode[3].Y, polynode[3].Z);
3749 }
3750 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[0].X,
3751 polynode[0].Y, polynode[0].Z);
3752 fprintf(ftmpIF, "\n");
3753 fflush(stdout);
3754 }
3755 break;
3756 }
3757 }
3758
3759 if (InEle)
3760 break;
3761 else {
3763 "Element cannot be identified ... neBEMKnownCharges\n");
3764 return -2;
3765 }
3766 }
3767
3768 if ((InPrim) && (intersect) && (!extrasect) &&
3769 (InEle))
3770 break;
3771
3772
3773
3774 if (prim ==
3776 {
3777 int nvert;
3780 double distele = 1.0e6,
3781 mindistele = 1.0e6;
3782
3783 if (debugFn) {
3784 printf("prim == (NbPrimitives) ... checking nearest ...\n");
3785 printf("nearestprim: %d, mindist: %lg\n", nearestprim,
3786 mindist);
3787 }
3788
3789 if (mindist <= 10.0e-6) {
3790 PrimIntsctd = nearestprim;
3791 InPrim = 1;
3792 } else {
3793 InPrim = 0;
3794 InEle = 0;
3795 break;
3796 }
3797
3800 nvert = 0;
3801 if ((
EleArr + ele - 1)->G.Type == 3) nvert = 3;
3802 if ((
EleArr + ele - 1)->G.Type == 4) nvert = 4;
3803 if (!nvert) {
3805 "no vertex element! ... neBEMKnownCharges ...\n");
3806 return -20;
3807 }
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
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);
3898
3900 mindistele = distele;
3901 nearestele = ele;
3902 }
3903 if (distele < mindistele) {
3904 mindistele = distele;
3905 nearestele = ele;
3906 }
3907
3908 if (debugFn) {
3909
3910
3911
3912
3913
3914 printf(
3915 "distele: %lg, mindist: %lg, from nearest ele: %d\n",
3916 distele, mindistele, nearestele);
3917 fflush(stdout);
3918 }
3919
3920
3921 }
3922
3923
3924
3925 EleIntsctd = nearestele;
3926 InEle = 1;
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]++;
3931
3932 fprintf(fPtIChUpMap, "%d %lg %lg %lg %d %d %d %d\n", ion,
3933 ptintsct.
X, ptintsct.
Y, ptintsct.
Z, PrimIntsctd, InPrim,
3934 EleIntsctd, InEle);
3935
3936
3937 if (debugFn) {
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;
3959 if (nvert == 4) {
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;
3963 }
3964 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3965 polynode[0].Z);
3966 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[1].X, polynode[1].Y,
3967 polynode[1].Z);
3968 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[2].X, polynode[2].Y,
3969 polynode[2].Z);
3970 if (nvert == 4) {
3971 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[3].X,
3972 polynode[3].Y, polynode[3].Z);
3973 }
3974 fprintf(ftmpIF, "%lg %lg %lg\n", polynode[0].X, polynode[0].Y,
3975 polynode[0].Z);
3976 fprintf(ftmpIF, "\n");
3977 fflush(stdout);
3978 }
3979 }
3980
3981 }
3982
3983 if (debugFn)
3984 {
3985 char inbstr[12];
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");
3992 if (fipd == NULL) {
3993 printf(
3994 "cannot open writable file to debug ion positions ...\n");
3995 printf("returning ...\n");
3996 return -111;
3997 }
3998
3999
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);
4005
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],
4019 }
4020 fprintf(fipd,
"%lg %lg %lg\n",
XVertex[PrimIntsctd][0],
4022 fprintf(fipd, "\n");
4023
4024 fprintf(fipd, "#ptintsct:\n");
4025 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4027 fprintf(fipd, "\n");
4028 }
4029
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);
4047 if (gtype == 4) {
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);
4052 }
4053 fprintf(fipd, "%lg %lg %lg\n", x0, y0, z0);
4054 fprintf(fipd, "\n");
4055
4056 fprintf(fipd, "#ptintsct:\n");
4057 fprintf(fipd,
"%lg %lg %lg\n", ptintsct.
X, ptintsct.
Y,
4059 fprintf(fipd, "\n");
4060 }
4061 fclose(fipd);
4062 }
4063 }
4064 fclose(fPtIChUpMap);
4065
4066
4067
4068 FILE *fEleEIChUpMap = fopen("EleE+IChUpMap.out", "w");
4069 if (fEleEIChUpMap == NULL) {
4070 printf("cannot open EleE+IChUpMap.out file for writing ...\n");
4071 return 111;
4072 }
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);
4081 }
4082 fclose(fEleEIChUpMap);
4083
4084 fclose(ftmpIF);
4085 free(NbChUpIonEle);
4086 }
4087
4088 }
4089
4090 fclose(ChargingUpInpFile);
4091 }
4092
4093 if (debugFn) {
4094
4095 }
4096 }
4097
4098 return (0);
4099}
int neBEMGetNbOfLines(const char fname[])
double neBEMChkInPoly(int n, Point3D *p, Point3D q)
neBEMGLOBAL double * ZNorm
neBEMGLOBAL int OptChargingUp
neBEMGLOBAL double * XNorm
neBEMGLOBAL int NbPrimitives
neBEMGLOBAL double * YNorm
neBEMGLOBAL int * InterfaceType