00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <IKOR/general.h>
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 int Least_Norm (MATRIX *B, MATRIX *H, FILE *datafp)
00032 {
00033 int i, j=0;
00034
00035
00036 for (i=0; i<H->rows; i++) H->p[i][0] = 0.0;
00037 for (j=0; j<B->cols; j++)
00038 for (i=0; i<B->rows; i++)
00039 if (i==j)
00040 B->p[i][j] = 1.0;
00041 else
00042 B->p[i][j] = ZERO;
00043
00044 if (DEBUG) {
00045 fmat_pr(datafp,"Least Norm B", B);
00046 fmat_pr(datafp,"Least Norm H", H);
00047 }
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int Least_Flow (MATRIX *B, MATRIX *H, MATRIX *Qarray, FILE* datafp)
00065 {
00066 int i, j;
00067
00068 for (i=0; i<H->rows; i++) H->p[i][0] = 0.0;
00069 for (j=0; j<B->cols; j++)
00070 for (i=0; i<B->rows; i++)
00071
00072
00073 if (i==j) B->p[i][i] = calc_flow(i, Qarray->p[i][0], 1.0, -1.0,
00074 (MATRIX *) 0);
00075 else B->p[i][j] = ZERO;
00076
00077
00078 if (DEBUG) {
00079 fmat_pr(datafp,"Least FLOW B", B);
00080 fmat_pr(datafp,"Least FLOW H", H);
00081 }
00082 }
00083
00084
00085 float calc_flow(int index, float Q, float dq, float distance, MATRIX *old)
00086 {
00087 static float FLOW=ZERO, totaltime = ZERO;
00088 float numerator, denominator, dFLOW, time;
00089
00090 dq = fabs(dq);
00091 switch (index) {
00092 case 0 :
00093 Q = 1.5479 - Q;
00094 numerator = 0.386 * sin(Q);
00095 denominator = sqrt( 1.29 - .769 * cos(Q) );
00096 dFLOW = numerator / denominator;
00097 if (dq<ZERO) dFLOW *= dq * 4.28;
00098 else dFLOW *= dq * 2.60;
00099 break;
00100 case 1 :
00101 Q = 1.360 - (Q - PI/2);
00102 numerator = 0.574 * sin(Q);
00103 denominator = sqrt( 2.05 - 1.15 * cos(Q) );
00104 dFLOW = numerator / denominator;
00105 if (dq<ZERO) dFLOW *= dq * 4.82;
00106 else dFLOW *= dq * 2.68;
00107 break;
00108 case 2 :
00109 if (dq>ZERO) dFLOW = dq * .838;
00110 else dFLOW = dq * .429;
00111 break;
00112 case 3 :
00113 Q = 0.546 - (Q); dq = -dq;
00114 numerator = 0.190 * sin(Q);
00115 denominator = sqrt( 0.82 - 0.38 * cos(Q) );
00116 dFLOW = numerator / denominator;
00117 if (dq<ZERO) dFLOW *= dq * 2.10;
00118 else dFLOW *= dq * 1.73;
00119 break;
00120 case 4 :
00121 dFLOW = .05500 * dq;
00122 break;
00123 case 5 :
00124 dFLOW = .00688 * dq;
00125 break;
00126 }
00127
00128
00129 if (distance >= ZERO) {
00130 time = distance/(60*SPEED);
00131
00132 FLOW += SQUARE(fabs(dFLOW)/time);
00133
00134 if (index==0) fprintf(FLWfile, "%7.5f", totaltime);
00135
00136 fprintf(FLWfile, " %11.8f", (time)?(fabs(dFLOW)/time):ZERO);
00137 if (DEBUG) {
00138 fprintf(datafp, "dFLOW[%d]: %10.4f dF/dt: %13.8f\n", index, fabs(dFLOW),
00139 fabs(dFLOW)/time);
00140 if (index == 5)
00141 fprintf(datafp, "FLOW: %f TIME: %f DISTANCE: %f\nFLOWRATE: %f\n",
00142 FLOW, time, distance, (time)?FLOW/time:0.0);
00143 }
00144 if (index==5){
00145 fprintf(FLWfile, " %11.6f\n", (time)?FLOW:ZERO);
00146 fprintf(distfp, "%f \n", distance);
00147 FLOW = 0.0;
00148 totaltime += time;
00149 }
00150 }
00151
00152 return (fabs(dFLOW));
00153 }