using MCSharp; using System; using System.Threading; using System.Runtime.Serialization; using System.Runtime.Remoting.Messaging; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; using System.Data; [Serializable()] class Streamline { // -------------Channels declarations---------------- [NonSerialized] private MCSharp.Channel c; // -------------Queues------------------------------- [NonSerialized] private MCSharp.ThreadQ mcQueueGet; // -------------Masks-------------------------------- [NonSerialized] private MCSharp.BitMask mcBitMaskGetc = new MCSharp.BitMask(); private const int mcMaskGet = 1 << 0; private const int mcMaskc = 1 << 1; private const int mcMaskGetc = mcMaskGet | mcMaskc; // -------------User's code-------------------------- [NonSerialized] public static int n = 10; [NonSerialized] public static int nc= 2 ; [NonSerialized] public static float time = 10.0F; [NonSerialized] public static float dt = 0.1F; [NonSerialized] public static float[,,] dg = new float [ 2, nc, (int)(time/dt) + 3 ]; [NonSerialized] public static int[] ir = new int [ 2 ]; [NonSerialized] public static float[,] ga = new float [ 2, 51 ]; [NonSerialized] public static float[,] p = new float [ 2, 50 ]; [NonSerialized] public static float p0, p0n; [NonSerialized] public static float al, rd, aldt, ad; [NonSerialized] public static float[,] xb = new float [ 2, 51 ]; [NonSerialized] public static float[,] yb = new float [ 2, 51 ]; [NonSerialized] public static float[,,] x1 = new float [ 2, nc, (int)(time/dt) + 3 ]; [NonSerialized] public static float[,,] y1 = new float [ 2, nc, (int)(time/dt) + 3 ]; [NonSerialized] public static float[,] xt = new float [ 2, 51 ]; [NonSerialized] public static float[,] yt = new float [ 2, 51 ]; [NonSerialized] public static float xt0, yt0; [NonSerialized] public static float[,] xtl = new float [ 2, 51 ]; [NonSerialized] public static float[,] ytl = new float [ 2, 51 ]; [NonSerialized] public static float ta; [NonSerialized] public static float epp, epf; [NonSerialized] public static int N_PROCESSORS = 8; [NonSerialized] public static int PROCS_ON_CHAIN = N_PROCESSORS / ( 2 * nc ); [NonSerialized] public static int START_CHAIN_LENGTH = 20; [NonSerialized] public static int START_SIZE = START_CHAIN_LENGTH * PROCS_ON_CHAIN; [NonSerialized] public static int INTERVAL; [NonSerialized] public System.Windows.Forms.TextBox consoleText; [NonSerialized] public System.Windows.Forms.TextBox totalTimeText; public Streamline( System.Windows.Forms.TextBox consoleText, System.Windows.Forms.TextBox totalTimeText ) { initiate(); this.consoleText = consoleText; this.totalTimeText = totalTimeText; } public static void disk( Streamline streamline ) { DateTime a = DateTime.Now; float cst = 0.0F, pfst = 0.0F, ccsr = 0.0F, amzsr = 0.0F; float p0sr = 0.0F, p0nsr = 0.0F, p0sr0 = 0.0F, p0nsr0 = 0.0F, p0sr90 = 0.0F, p0nsr90 = 0.0F, p0sr180 = 0.0F, p0nsr180 = 0.0F, p0sr270 = 0.0F, p0nsr270 = 0.0F; int i, j, k; float[,] ga1 = new float [ 2, 51 ]; float start; float[,,] dg0 = new float [ 2, nc, (int)(time/dt) + 3 ]; float[,,] tb = new float [ 2, nc, (int)(time/dt) + 3 ]; int ir0 = 0; float[,] psr = new float [ 2, 51 ]; float[,] psr0 = new float [ 2, 51 ]; float[,] psr90 = new float [ 2, 51 ]; float[,] psr180 = new float [ 2, 51 ]; float[,] psr270 = new float [ 2, 51 ]; float[] pfsr = new float [ 5000 ]; float[] cf = new float [ 5000 ]; float[] amzf = new float [ 5000 ]; float[] ux = new float [ 1000 ]; float cal0 = 0.0F, cal90 = 0.0F, cal180 = 0.0F, cal270 = 0.0F; int nn; float an; float d0; float[,] xbk = new float [ 2, 10 ]; float[,] ybk = new float [ 2, 10 ]; float alpha1, alpha2; int ki, kj; int ic; float sum; float wx, wy; float wn; float[] c1 = new float [ 50000 ]; int m; int kih, ih; float xvel, xom; float xa, ya; float[] gam = new float [ 105 ]; float ga0; int np, n1; float a5; int ier; float c, amz; float tast; float alper; int lsr = 0, lsr0 = 0, lsr90 = 0, lsr180 = 0, lsr270 = 0; float dt2; float[] pf = new float [ 5000 ]; float[,] vt = new float [ 2, 51 ]; float[,] vt1 = new float [ 2, 51 ]; float[,] vt2 = new float [ 2, 51 ]; float w1, w2; float alold; float xt0old, yt0old; float dz, dze; int ii; float[,,] x = new float [ 2, nc, (int)(time/dt) + 3 ]; float[,,] y = new float [ 2, nc, (int)(time/dt) + 3 ]; float e0, e0e; float xf, yf; float xold, yold; float xc, yc, xp, yp; float ro, roold, roc; float rv; int ie; float sin_al, cos_al; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n + 1; i++ ) { psr [ k, i ] = 0.0F; psr0 [ k, i ] = 0.0F; psr90 [ k, i ] = 0.0F; psr180 [ k, i ] = 0.0F; psr270 [ k, i ] = 0.0F; } for ( k = 0; k < 5000; k++ ) { pfsr [ k ] = 0.0F; cf [ k ] = 0.0F; amzf [ k ] = 0.0F; } for ( k = 0; k < 200; k++ ) ux [ k ] = 0.0F; nn = n + 1; an = n; epp = 0.5F / an; epf = 0.5F / an; al = 5.0F * (float)Math.PI / 180.0F; aldt = 0.0F; rd = 1.0F; ad = 0.0F; d0 = rd / an; for ( i = 0; i < n + 1; i++ ) { xb [ 0, i ] = - ad * (float)Math.Sin ( al ) + ( i + 0.5F ) * rd / an * (float)Math.Cos ( al ); yb [ 0, i ] = ad * (float)Math.Cos ( al ) + ( i + 0.5F ) * rd / an * (float)Math.Sin ( al ); xb [ 1, i ] = - ad * (float)Math.Sin ( al ) - ( i + 0.5F ) * rd / an * (float)Math.Cos ( al ); yb [ 1, i ] = ad * (float)Math.Cos ( al ) - ( i + 0.5F ) * rd / an * (float)Math.Sin ( al ); } for ( i = 0; i < nc; i++ ) { xbk [ 0, i ] = xb [ 0, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0F ) * ( - (float)Math.Sin ( al ) ); ybk [ 0, i ] = yb [ 0, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0F ) * (float)Math.Cos ( al ) ; xbk [ 1, i ] = xb [ 1, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0F ) * (float)Math.Sin ( al ) ; ybk [ 1, i ] = yb [ 1, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0F ) * ( - (float)Math.Cos ( al ) ); } xt0 = - ad * (float)Math.Sin ( al ) + 0.0F; yt0 = ad * (float)Math.Cos ( al ) + 0.0F; for ( i = 0; i < n + 1; i++ ) { xt [ 0, i ] = ( i + 1 ) * rd / an * (float)Math.Cos ( al ); xtl [ 0, i ] = xt [ 0, i ] / ( 1.0F + 1.0F / an ); yt [ 0, i ] = ( i + 1 ) * rd / an * (float)Math.Sin ( al ); if ( Math.Abs ( Math.Sin ( al ) ) > 1.0E-5 ) ytl [ 0, i ] = yt [ 0, i ] / ( 1.0F + 1.0F / an ) / (float)Math.Sin ( al ); else ytl [ 0, i ] = xt [ 0, i ] / ( 1.0F + 1.0F / an ) / (float)Math.Cos ( al ); xt [ 0, i ] = xt [ 0, i ] - ad * (float)Math.Sin ( al ); yt [ 0, i ] = yt [ 0, i ] + ad * (float)Math.Cos ( al ); xt [ 1, i ] = - ( i + 1 ) * rd / an * (float)Math.Cos ( al ); xtl [ 1, i ] = xt [ 1, i ] / ( 1.0F + 1.0F / an ); yt [ 1, i ] = - ( i + 1 ) * rd / an * (float)Math.Sin ( al ); if ( Math.Abs ( Math.Sin ( al ) ) > 1.0E-5 ) ytl [ 1, i ] = yt [ 1, i ] / ( 1.0F + 1.0F / an ) / (float)Math.Sin ( al ); else ytl [ 1, i ] = xt [ 1, i ] / ( 1.0F + 1.0F / an ) / (float)Math.Cos ( al ); xt [ 1, i ] = xt [ 1, i ] - ad * (float)Math.Sin ( al ); yt [ 1, i ] = yt [ 1, i ] + ad * (float)Math.Cos ( al ); } start = 0.0F; if ( Math.Abs ( start - 1.0F ) < 1.0E-5 ) { } else { ir [ 0 ] = 1; ir [ 1 ] = 1; ir0 = 1; } if ( start < 1.0E-5F ) for ( i = 0; i < nc; i++ ) { x1 [ 0, i, 0 ] = xbk [ 0, i ]; y1 [ 0, i, 0 ] = ybk [ 0, i ]; x1 [ 1, i, 0 ] = xbk [ 1, i ]; y1 [ 1, i, 0 ] = ybk [ 1, i ]; } if ( start < 1.0E-5F ) for ( k = 0; k < 2; k++ ) for ( i = 0; i < n + 1; i++ ) ga [ k, i ] = 0.0F; ta = 0.0F; for ( i = 0; i < nc; i++ ) { tb [ 0, i, 0 ] = 0.0F; tb [ 1, i, 0 ] = 0.0F; } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < (int)(time/dt) + 3; i++ ) { dg0 [ k, j, i ] = 0.0F; dg [ k, j, i ] = 0.0F; } for ( i = 0; i < 5000; i++ ) pf [ i ] = 0.0F; while ( ta <= time ) { ta += dt; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) ga1 [ k, i ] = ga [ k, i ]; for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir [ k ]; i++ ) { tb [ k, j, ir[k]-i ] = tb [ k, j, ir[k]-i-1 ]; dg0[ k, j, ir[k]-i ] = dg0[ k, j, ir[k]-i-1 ]; } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir[k]; i++ ) tb [ k, j, i ] = tb [ k, j, i ] + dt; alpha1 = al; xb [ 0, n ] = xt [ 0, n - 1 ] + 0.5F * rd * (float)Math.Cos ( alpha1 ) / an; yb [ 0, n ] = yt [ 0, n - 1 ] + 0.5F * rd * (float)Math.Sin ( alpha1 ) / an; alpha2 = al + (float)Math.PI; xb [ 1, n ] = xt [ 1, n - 1 ] + 0.5F * rd * (float)Math.Cos ( alpha2 ) / an; yb [ 1, n ] = yt [ 1, n - 1 ] + 0.5F * rd * (float)Math.Sin ( alpha2 ) / an; k = 0; for ( ki = 0; ki < 2; ki++ ) for ( i = 0; i < n + 1; i++ ) { for ( kj = 0; kj < 2; kj++ ) for ( j = 0; j < n; j++ ) { if ( i == n ) { sum = 0.0F; for ( ic = 0; ic < nc; ic++ ) { speed ( xbk[ki,ic], ybk[ki,ic], xt[kj,j], yt[kj,j], out wx, out wy ); sum = sum - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); } c1 [ k ] = sum; } else { speed ( xb[ki,i], yb[ki,i], xt[kj,j], yt[kj,j], out wx, out wy ); c1 [ k ] = - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); } k++; } if ( i == n ) { sum = 0.0F; for ( ic = 0; ic < nc; ic++ ) { speed ( xbk[ki,ic], ybk[ki,ic], xt0, yt0, out wx, out wy ); sum = sum - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); } c1 [ k ] = sum; } else { speed ( xb[ki,i], yb[ki,i], xt0, yt0, out wx, out wy ); c1 [ k ] = - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); } k++; if ( i == n ) c1 [ k ] = nc; else c1 [ k ] = 1.0F; k++; } m = 0; for ( kih = 0; kih < 2; kih++ ) for ( ih = 0; ih < n; ih++ ) { xvel = vel ( ta ) * (float)Math.Sin ( al ); xom = aldt * (float)Math.Sqrt ( Math.Pow ( xt [ kih, ih ] - xt0, 2 ) + Math.Pow ( yt [ kih, ih ] - yt0, 2 ) ); if ( kih == 1 ) xom = -xom; ga [ kih, ih ] = xvel + xom; for ( k = 0; k < 2; k++ ) for ( ic = 0; ic < nc; ic++ ) for ( i = 0; i < ir [ k ] - 1; i++ ) { xa = x1 [ k, ic, i + 1 ]; ya = y1 [ k, ic, i + 1 ]; speedf ( xa, ya, xt[kih,ih], yt[kih,ih], out wx, out wy ); ga [ kih, ih ] = ga [ kih, ih ] - ( - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ) ) * dg [ k, ic, i]; } gam [ m ] = ga [ kih, ih ]; m++; } ga0 = vel ( ta ) * (float)Math.Sin ( al ) + aldt * (float)Math.Sqrt ( Math.Pow ( xt0 - xt0, 2 ) + Math.Pow ( yt0 - yt0, 2 ) ); for ( k = 0; k < 2; k++ ) for ( ic = 0; ic < nc; ic++ ) for ( i = 0; i < ir [ k ] - 1; i++ ) { speedf ( x1[k,ic,i+1], y1[k,ic,i+1], xt0, yt0, out wx, out wy ); ga0 = ga0 - ( - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ) ) * dg [ k, ic, i ]; } gam [ m ] = ga0; m++; gam [ m ] = 0.0F; for ( k = 0; k < 2; k++ ) for ( ic = 0; ic < nc; ic++ ) for ( i = 0; i < ir [ k ] - 1; i++ ) gam [ m ] = gam [ m ] - dg [ k, ic, i ]; np = 2 * n + 2; n1 = 1; a5 = 1.0E-5F; GELG ( gam, c1, np, n1, a5, out ier ); for ( k = 0; k < 2 * n + 2; k++ ) if ( k <= n ) ga [ 0, k ] = gam [ k ]; else ga [ 1, k - n - 1 ] = gam [ k ]; for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir [ k ]; i++ ) dg [ k, j, ir [ k ] - i ] = dg [ k, j, ir [ k ] - i - 1 ]; for ( i = 0; i < nc; i++ ) { dg [ 0, i, 0 ] = ga [ 0, n ]; dg [ 1, i, 0 ] = ga [ 1, n ]; dg0[ 0, i, 0 ] = ga [ 0, n ]; dg0[ 1, i, 0 ] = ga [ 1, n ]; } for ( i = 0; i < nc; i++ ) { x1 [ 0, i, 0 ] = xbk [ 0, i ]; y1 [ 0, i, 0 ] = ybk [ 0, i ]; x1 [ 1, i, 0 ] = xbk [ 1, i ]; y1 [ 1, i, 0 ] = ybk [ 1, i ]; } sum = 0.0F; for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < ir [ k ]; i++ ) sum += dg [ k, j, i ]; for ( k = 0; k < 2; k++ ) for ( j = 0; j < n; j++ ) sum += ga [ k, j ]; for ( k = 0; k < 2; k++ ) for ( j = 0; j < n; j++ ) { ospeed ( xt [ k, j ], yt [ k, j ], out wx, out wy ); wn = - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); } ospeed ( xt0, yt0, out wx, out wy ); wn = - wx * (float)Math.Sin ( al ) + wy * (float)Math.Cos ( al ); AER ( ga1, out c, out amz ); streamline.consoleText.AppendText( " I=" + ir0 + " T=" + ta + " C=" + c + " amz=" + amz + "\r\n" ); streamline.totalTimeText.Text = DateTime.Now.Subtract( a ).ToString(); /* Console.WriteLine ( " I=" + ir0 + " T=" + ta + " C=" + c + " amz=" + amz + "\n" ); */ tast = 40.0F; if ( ta >= tast && cst < 1.0E-5F ) { cst = 1.0F; lsr = 1; lsr0 = 1; lsr90 = 1; lsr180 = 1; lsr270 = 1; } if ( ta >= tast && (float)Math.Abs ( cst - 1.0F ) < 1.0E-5F ) { alper = al; while ( alper >= 2.0F * (float)Math.PI ) alper = alper - 2.0F * (float)Math.PI; dt2 = dt / 2.0F; if ( - dt2 <= alper && alper <= dt2 ) { p0sr0 = ( p0sr0 * ( lsr0 - 1 ) + p0 ) / lsr0; p0nsr0 = ( p0nsr0 * ( lsr0 - 1 ) + p0n ) / lsr0; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) psr0 [ k, i ] = ( psr0 [ k, i ] * ( lsr0 - 1 ) + p [ k, i ] ) / lsr0; lsr0++; if ( cal0 < 1.0E-5F ) { cal0 = 1.0F; } } if ( (float)Math.PI / 2.0F - dt2 <= alper && alper <= (float)Math.PI / 2.0F + dt2 ) { p0sr90 = ( p0sr90 * ( lsr90 - 1 ) + p0 ) / lsr90; p0nsr90 = ( p0nsr90 * ( lsr90 - 1 ) + p0n ) / lsr90; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) psr90 [ k, i ] = ( psr90 [ k, i ] * ( lsr90 - 1 ) + p [ k, i ] ) / lsr90; lsr90++; if ( cal90 < 1.0E-5F ) { cal90 = 1.0F; } } if ( (float)Math.PI - dt2 <= alper && alper <= (float)Math.PI + dt2 ) { p0sr180 = ( p0sr180 * ( lsr180 - 1 ) + p0 ) / lsr180; p0nsr180 = ( p0nsr180 * ( lsr180 - 1 ) + p0n ) / lsr180; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) psr180 [ k, i ] = ( psr180 [ k, i ] * ( lsr180 - 1 ) + p [ k, i ] ) / lsr180; lsr180++; if ( cal180 < 1.0E-5F ) { cal180 = 1.0F; } } if ( 3.0F * (float)Math.PI / 2.0F - dt2 <= alper && alper <= 3.0F * (float)Math.PI / 2.0F + dt2 ) { p0sr270 = ( p0sr270 * ( lsr270 - 1 ) + p0 ) / lsr270; p0nsr270 = ( p0nsr270 * ( lsr270 - 1 ) + p0n ) / lsr270; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) psr270 [ k, i ] = ( psr270 [ k, i ] * ( lsr270 - 1 ) + p [ k, i ] ) / lsr270; lsr270++; if ( cal270 < 1.0E-5F ) { cal270 = 1.0F; } } ccsr = ( ccsr * ( lsr - 1 ) + c ) / lsr; amzsr = ( amzsr * ( lsr - 1 ) + amz ) / lsr; p0sr = ( p0sr * ( lsr - 1 ) + p0 ) / lsr; p0nsr = ( p0nsr * ( lsr - 1 ) + p0n ) / lsr; for ( k = 0; k < 2; k++ ) for ( i = 0; i < n; i++ ) psr [ k, i ] = ( psr [ k, i ] * ( lsr - 1 ) + p [ k, i ] ) / lsr; if ( (float)Math.Abs ( pfst - 1.0F ) < 1.0E-5F ) for ( i = 0; i < 100; i++ ) pfsr [ i ] = ( pfsr [ i ] * ( lsr - 1 ) + pf [ i ] ) / lsr; for ( k = 1; k <= 200; k++ ) { ospeed ( 0.1F * k, 0.0F, out wx, out wy ); ux [ k ] = ( ux [ k ] * ( lsr - 1 ) + wx ) / lsr; } lsr++; } for ( k = 0; k < 2; k++ ) for ( ie = 0; ie < n; ie++ ) { ospeed ( xt [ k, ie ], yt [ k, ie ], out w1, out w2 ); vt [ k, ie ] = w1 * (float)Math.Cos ( al ) + w2 * (float)Math.Sin ( al ); vt1 [ k, ie ] = vt [ k, ie ] - n * ( ga [ k, ie ] + ga [ k, ie + 1 ] ) / 4.0F / rd; vt2 [ k, ie ] = vt [ k, ie ] + n * ( ga [ k, ie ] + ga [ k, ie + 1 ] ) / 4.0F / rd; } alold = al; al = al + aldt * dt; while ( al > 2.0F * (float)Math.PI ) al = al - 2.0F * (float)Math.PI; while ( al < - 2.0F * (float)Math.PI ) al = al + 2.0F * (float)Math.PI; if ( ta < 1.0F ) aldt = 0.0F; else aldt = aldt + 0.4F * ( amz - 0.01F / 0.4F * aldt ) * dt; for ( i = 0; i < n + 1; i++ ) { xb [ 0, i ] = - ad * (float)Math.Sin ( al ) + ( i + 0.5F ) * rd / an * (float)Math.Cos ( al ); yb [ 0, i ] = ad * (float)Math.Cos ( al ) + ( i + 0.5F ) * rd / an * (float)Math.Sin ( al ); xb [ 1, i ] = - ad * (float)Math.Sin ( al ) - ( i + 0.5F ) * rd / an * (float)Math.Cos ( al ); yb [ 1, i ] = ad * (float)Math.Cos ( al ) - ( i + 0.5F ) * rd / an * (float)Math.Sin ( al ); } for ( i = 0; i < nc; i++ ) { xbk [ 0, i ] = xb [ 0, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0f ) * ( - (float)Math.Sin ( al ) ); ybk [ 0, i ] = yb [ 0, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0f ) * (float)Math.Cos ( al ) ; xbk [ 1, i ] = xb [ 1, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0f ) * (float)Math.Sin ( al ) ; ybk [ 1, i ] = yb [ 1, n ] + ( i + 1 - 0.5F * ( nc + 1.0F ) ) * d0 / ( nc - 1.0f ) * ( - (float)Math.Cos ( al ) ); } xt0old = xt0; yt0old = yt0; xt0 = - ad * (float)Math.Sin ( al ); yt0 = ad * (float)Math.Cos ( al ); for ( i = 0; i < n + 1; i++ ) { xt [ 0, i ] = - ad * (float)Math.Sin ( al ) + ( i + 1 ) * rd / an * (float)Math.Cos ( al ); yt [ 0, i ] = ad * (float)Math.Cos ( al ) + ( i + 1 ) * rd / an * (float)Math.Sin ( al ); xt [ 1, i ] = - ad * (float)Math.Sin ( al ) - ( i + 1 ) * rd / an * (float)Math.Cos ( al ); yt [ 1, i ] = ad * (float)Math.Cos ( al ) - ( i + 1 ) * rd / an * (float)Math.Sin ( al ); } dz = 1.0F; dze = 0.5F; sin_al = (float)Math.Sin ( al ); cos_al = (float)Math.Cos ( al ); if ( ir [ 0 ] < START_SIZE ) { for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < ir [ k ]; i++ ) { ii = ir [ k ] - i - 1; ospeed ( x1 [ k, j, ii ], y1 [ k, j, ii ], out w1, out w2 ); x [ k, j, ii + 1 ] = x1 [ k, j, ii ] + dt * w1; y [ k, j, ii + 1 ] = y1 [ k, j, ii ] + dt * w2; e0 = dz * rd / n; e0e = dze * rd / n; xf = x [ k, j, ii + 1 ] - xt0; yf = y [ k, j, ii + 1 ] - yt0; xold = x1 [ k, j, ii ] - xt0old; yold = y1 [ k, j, ii ] - yt0old; xc = x1 [ k, j, ii ] - xt0; yc = y1 [ k, j, ii ] - yt0; xp = cos_al * ( xf * cos_al + yf * sin_al ); yp = sin_al * ( xf * cos_al + yf * sin_al ); ro = - xf * sin_al + yf * cos_al; roold = - xold * (float)Math.Sin ( alold ) + yold * (float)Math.Cos ( alold ); roc = - xc * sin_al + yc * cos_al; if ( ii == 0 ) roold = ro; rv = (float)Math.Sqrt ( xf * xf + yf * yf ); if ( rv < ( rd + e0e ) ) { if ( rv < rd ) e0 = dz * rd / n; if ( (float)Math.Abs ( ro ) < e0 || ro * roold < 0.0F ) if ( roold > 0.0F ) { x [ k, j, ii + 1 ] = xt0 + xp - e0 * sin_al; y [ k, j, ii + 1 ] = yt0 + yp + e0 * cos_al; } else { x [ k, j, ii + 1 ] = xt0 + xp + e0 * sin_al; y [ k, j, ii + 1 ] = yt0 + yp - e0 * cos_al; } } } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir [ k ] + 1; i++ ) { x1 [ k, j, i ] = x [ k, j, i ]; y1 [ k, j, i ] = y [ k, j, i ]; } } else { if ( ir [ 0 ] % PROCS_ON_CHAIN == 0 ) INTERVAL = ir [ 0 ] / PROCS_ON_CHAIN; else INTERVAL = ir [ 0 ] / PROCS_ON_CHAIN + 1; for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < PROCS_ON_CHAIN; i++ ) MCSharp.TCP.DeliverMovableMethod( streamline, "Compute_X_Y", new object[] { k, j, i, INTERVAL, n, nc, ir [ 0 ], dt, rd, ta, epp, epf, xt0, yt0, xt0old, yt0old, sin_al, cos_al, alold, new ArrayWrapper( dg ), new ArrayWrapper( ga ), new ArrayWrapper( xb ), new ArrayWrapper( yb ), new ArrayWrapper( x1 ), new ArrayWrapper( y1 ), streamline.c } ); for ( i = 0; i < 2 * nc * PROCS_ON_CHAIN; i++ ) streamline.Get( x, y ); for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir [ k ] + 1; i++ ) { x1 [ k, j, i ] = x [ k, j, i ]; y1 [ k, j, i ] = y [ k, j, i ]; } } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 1; i < ir [ k ]; i++ ) dg [ k, j, i ] = dg0 [ k, j, i ]; ir0++; ir [ 0 ]++; ir [ 1 ]++; } streamline.consoleText.AppendText( "____________________________________________________\r\n" ); streamline.consoleText.AppendText( " Done!\r\n" ); } public static void AER( float[,] ga1, out float c, out float amz ) { int i, k; int ie; float gg_1 = 0.0F, gg; float gg_2 = 0.0F; float gas; float wn, wt, wte; float dy; c = 0.0F; amz = 0.0F; for ( i = 0; i < nc; i++ ) { gg_1 -= dg [ 0, i, 0 ]; gg_2 += dg [ 1, i, 0 ]; } for ( ie = 0; ie < n; ie++ ) { gg = gg_1; for ( i = ie + 1; i < n; i++ ) gg = gg - ga [ 0, i ] + ga1 [ 0, i ]; ospeed ( xt [ 0, ie ], yt [ 0, ie ], out wn, out wt ); if ( ie <= n - 2 ) gas = - ( ga [ 0, ie ] + ga [ 0, ie + 1 ] ) / 2.0F; else gas = - ga [ 0, n - 1 ]; wte = wn * (float)Math.Cos ( al ) + wt * (float)Math.Sin( al ); p [ 0, ie ] = -1.0F / dt * ( ( wte + aldt * ad ) * gas * dt * n / rd - gg ); } for ( ie = 0; ie < n; ie++ ) { gg = gg_2; for ( i = ie + 1; i < n; i++ ) gg = gg + ga [ 1, i ] - ga1 [ 1, i ]; ospeed ( xt [ 1, ie ], yt [ 1, ie ], out wn, out wt ); if ( ie <= n - 2 ) gas = ( ga [ 1, ie ] + ga [ 1, ie + 1 ] ) / 2.0F; else gas = ga [ 1, n - 1 ]; wte = - wn * (float)Math.Cos ( al ) - wt * (float)Math.Sin( al ); p [ 1, ie ] = -1.0F / dt * ( ( wte - aldt * ad ) * gas * dt * n / rd - gg ); } gg = gg_1; for ( i = 0; i < n; i++ ) gg = gg - ga [ 0, i ] + ga1 [ 0, i ]; ospeed ( xt0, yt0, out wn, out wt ); gas = - ( ga [ 0, 0 ] + ga [ 1, 0 ] ) / 2.0F; wte = wn * (float)Math.Cos ( al ) + wt * (float)Math.Sin( al ); p0 = -1.0F / dt * ( ( wte + aldt * ad ) * gas * dt * n / rd - gg ); gg = gg_2; for ( i = 0; i < n; i++ ) gg = gg + ga [ 1, i ] - ga1 [ 1, i ]; gas = ( ga [ 0, 0 ] + ga [ 1, 0 ] ) / 2.0F; wte = - wn * (float)Math.Cos ( al ) - wt * (float)Math.Sin( al ); p0n = -1.0F / dt * ( ( wte - aldt * ad ) * gas * dt * n / rd - gg ); dy = ytl [ 0, n - 1 ] - ytl [ 0, n - 2 ]; for ( k = 0; k < 2; k++ ) for ( ie = 0; ie < n - 1; ie++ ) { c += p [ k, ie ] / 2.0F * dy; amz += p [ k, ie ] / 2.0F * dy * ytl [ k, ie ]; } for ( k = 0; k < 2; k++ ) { c += p [ k, n - 1 ] / 4.0F * dy; amz += p [ k, n - 1 ] / 4.0F * dy * ytl [ k, n - 1 ]; } c += p0 / 2.0F * dy; p [ 0, n ] = 0.0F; p [ 1, n ] = 0.0F; c = 2.0F * c; amz = -2.0F * amz; } static void ospeed( float xx, float yy, out float w1, out float w2 ) { int k, m, j, i; float wx, wy; w1 = 0.0F; w2 = 0.0F; for ( k = 0; k < 2; k++ ) for ( m = 0; m < n; m++ ) { speed ( xb[k,m], yb[k,m], xx, yy, out wx, out wy ); w1 += wx * ga [ k, m ]; w2 += wy * ga [ k, m ]; } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < ir [ k ]; i++ ) { if ( i == 0 ) speed ( x1[k,j,i], y1[k,j,i], xx, yy, out wx, out wy ); else speedf ( x1[k,j,i], y1[k,j,i], xx, yy, out wx, out wy ); w1 += wx * dg [ k, j, i ]; w2 += wy * dg [ k, j, i ]; } w1 += vel ( ta ); } static void speed( float xb, float yb, float xt, float yt, out float wx, out float wy ) { float ro; float xm, ym; float wxm, wym; ro = ( xb - xt ) * ( xb - xt ) + ( yb - yt ) * ( yb - yt ); ro = (float) Math.Sqrt ( ro ); if ( ro > epp ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } else if ( ro > 0.0F ) { xm = xb + epp / ro * ( xt - xb ); ym = yb + epp / ro * ( yt - yb ); speed2 ( xb, yb, xm, ym, out wxm, out wym ); wx = ro / epp * wxm; wy = ro / epp * wym; } else { wx = 0.0F; wy = 0.0F; } } static void speed2( float xb, float yb, float xt, float yt, out float wx, out float wy ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } static void speedf ( float xb, float yb, float xt, float yt, out float wx, out float wy ) { float ro; float xm, ym; float wxm, wym; ro = ( xb - xt ) * ( xb - xt ) + ( yb - yt ) * ( yb - yt ); ro = (float) Math.Sqrt ( ro ); if ( ro > epf ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } else if ( ro > 0.0F ) { xm = xb + epf / ro * ( xt - xb ); ym = yb + epf / ro * ( yt - yb ); speed2f ( xb, yb, xm, ym, out wxm, out wym ); wx = ro / epf * wxm; wy = ro / epf * wym; } else { wx = 0.0F; wy = 0.0F; } } static void speed2f( float xb, float yb, float xt, float yt, out float wx, out float wy ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } static float vel( float t ) { if ( t <= 1.0F ) return ( 1.0F - ( 1.0F - t ) * ( 1.0F - t ) ); else return ( 1.0F ); } static void GELG( float[] R, float[] A, int m, int n, float eps, out int ier ) { double piv, pivi; int mm, nm; int i = 0, j, l, k, ii, ll; double tb; double tol; int lst, lend; int ist; if ( m <= 0 ) { ier = -1; return; } ier = 0; piv = 0.0; mm = m * m; nm = n * m; for ( l = 1; l <= mm; l++ ) { tb = Math.Abs ( A [ l - 1 ] ); if ( tb - piv > 0 ) { piv = tb; i = l; } } tol = eps * piv; lst = 1; for ( k = 1; k <= m; k++ ) { if ( piv <= 0.0 ) { ier = -1; return; } if ( ier == 0 ) if ( piv - tol <= 0.0 ) ier = k - 1; pivi = 1.0 / A [ i - 1 ]; j = ( i - 1 ) / m; i = i - j * m - k; j = j + 1 - k; for ( l = k; l <= nm; l += m ) { ll = l + i; tb = pivi * R [ ll - 1 ]; R [ ll - 1 ] = R [ l - 1 ]; R [ l - 1 ] = (float)tb; } if ( k - m >= 0 ) break; lend = lst + m - k; if ( j > 0 ) { ii = j * m; for ( l = lst; l <= lend; l++ ) { tb = A [ l - 1 ]; ll = l + ii; A [ l - 1 ] = A [ ll - 1 ]; A [ ll - 1 ] = (float)tb; } } for ( l = lst; l <= mm; l += m ) { ll = l + i; tb = pivi * A [ ll - 1 ]; A [ ll - 1 ] = A [ l - 1 ]; A [ l - 1 ] = (float)tb; } A [ lst - 1 ] = j; piv = 0.0; lst++; j = 0; for ( ii = lst; ii <= lend; ii++ ) { pivi = - A [ ii - 1 ]; ist = ii + m; j++; for ( l = ist; l <= mm; l += m ) { ll = l - j; A [ l - 1 ] = (float) ( A [ l - 1 ] + pivi * A [ ll - 1 ] ); tb = Math.Abs ( A [ l - 1 ] ); if ( tb - piv > 0 ) { piv = tb; i = l; } } for ( l = k; l <= nm; l += m ) { ll = l + j; R [ ll - 1 ] = (float) ( R [ ll - 1 ] + pivi * R [ l - 1 ] ); } } lst = lst + m; } if ( m - 1 > 0 ) { ist = mm + m; lst = m + 1; for ( i = 2; i <= m; i++ ) { ii = lst - i; ist = ist - lst; l = ist - m; l = (int) ( A [ l - 1 ] + 0.5 ); for ( j = ii; j <= nm; j += m ) { tb = R [ j - 1 ]; ll = j; for ( k = ist; k <= mm; k += m ) { ll++; tb = tb - A [ k - 1 ] * R [ ll - 1 ]; } k = j + l; R [ j - 1 ] = R [ k - 1]; R [ k - 1 ] = (float) tb; } } } else if ( m - 1 < 0 ) ier = -1; } public void Compute_X_Y( int k, int j, int i, int interval, int n, int nc,int irk, float dt, float rd, float ta, float epp, float epf, float xt0, float yt0, float xt0old, float yt0old, float sin_al, float cos_al, float alold, ArrayWrapper aw_dg, ArrayWrapper aw_ga, ArrayWrapper aw_xb, ArrayWrapper aw_yb, ArrayWrapper aw_x1, ArrayWrapper aw_y1, Channel c ) { // Retreiving objects from wrappers float[,,] dg = (float[,,]) aw_dg.a; float[,] ga = (float[,]) aw_ga.a; float[,] xb = (float[,]) aw_xb.a; float[,] yb = (float[,]) aw_yb.a; float[,,] x1 = (float[,,]) aw_x1.a; float[,,] y1 = (float[,,]) aw_y1.a; // end of retreiving int i_; int i1, i2; int ii; float w1, w2; float e0, e0e; float xf, yf; float xold, yold; float xc, yc, xp, yp; float ro, roold, roc, rv; float[] x = new float [ interval + 1 ]; float[] y = new float [ interval + 1 ]; i1 = i * interval; if ( i1 + interval < irk ) i2 = i1 + interval; else i2 = irk; for ( i_ = i1; i_ < i2; i_++ ) { ii = i2 - ( i_ - i1 ) - 1; ospeedPAR ( n, nc, irk, ta, epp, epf, dg, ga, xb, yb, x1, y1, x1 [ k, j, ii ], y1 [ k, j, ii ], out w1, out w2 ); x [ ii + 1 - i1 ] = x1 [ k, j, ii ] + dt * w1; y [ ii + 1 - i1 ] = y1 [ k, j, ii ] + dt * w2; e0 = rd / n; e0e = 0.5F * rd / n; xf = x [ ii + 1 - i1 ] - xt0; yf = y [ ii + 1 - i1 ] - yt0; xold = x1 [ k, j, ii ] - xt0old; yold = y1 [ k, j, ii ] - yt0old; xc = x1 [ k, j, ii ] - xt0; yc = y1 [ k, j, ii ] - yt0; xp = cos_al * ( xf * cos_al + yf * sin_al ); yp = sin_al * ( xf * cos_al + yf * sin_al ); ro = - xf * sin_al + yf * cos_al; roold = - xold * (float)Math.Sin ( alold ) + yold * (float)Math.Cos ( alold ); roc = - xc * sin_al + yc * cos_al; if ( i == 0 && ii == 0 ) roold = ro; rv = (float)Math.Sqrt ( xf * xf + yf * yf ); if ( rv < ( rd + e0e ) ) { if ( rv < rd ) e0 = rd / n; if ( (float)Math.Abs ( ro ) < e0 || ro * roold < 0.0F ) if ( roold > 0.0F ) { x [ ii + 1 - i1 ] = xt0 + xp - e0 * sin_al; y [ ii + 1 - i1 ] = yt0 + yp + e0 * cos_al; } else { x [ ii + 1 - i1 ] = xt0 + xp + e0 * sin_al; y [ ii + 1 - i1 ] = yt0 + yp - e0 * cos_al; } } } c.Send( k, j, i1, i2, x, y ); } void ospeedPAR( int n, int nc, int irk, float ta, float epp, float epf, float[,,] dg, float[,] ga, float[,] xb, float[,] yb, float[,,] x1, float[,,] y1, float xx, float yy, out float w1, out float w2 ) { int k, m, j, i; float wx, wy; w1 = 0.0F; w2 = 0.0F; for ( k = 0; k < 2; k++ ) for ( m = 0; m < n; m++ ) { speedPAR ( epp, xb[k,m], yb[k,m], xx, yy, out wx, out wy ); w1 += wx * ga [ k, m ]; w2 += wy * ga [ k, m ]; } for ( k = 0; k < 2; k++ ) for ( j = 0; j < nc; j++ ) for ( i = 0; i < ir [ k ]; i++ ) { if ( i == 0 ) speedPAR ( epp, x1[k,j,i], y1[k,j,i], xx, yy, out wx, out wy ); else speedfPAR ( epf, x1[k,j,i], y1[k,j,i], xx, yy, out wx, out wy ); w1 += wx * dg [ k, j, i ]; w2 += wy * dg [ k, j, i ]; } w1 += vel ( ta ); } void speedPAR( float epp, float xb, float yb, float xt, float yt, out float wx, out float wy ) { float ro; float xm, ym; float wxm, wym; ro = ( xb - xt ) * ( xb - xt ) + ( yb - yt ) * ( yb - yt ); ro = (float) Math.Sqrt ( ro ); if ( ro > epp ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } else if ( ro > 0.0F ) { xm = xb + epp / ro * ( xt - xb ); ym = yb + epp / ro * ( yt - yb ); speed2 ( xb, yb, xm, ym, out wxm, out wym ); wx = ro / epp * wxm; wy = ro / epp * wym; } else { wx = 0.0F; wy = 0.0F; } } void speedfPAR ( float epf, float xb, float yb, float xt, float yt, out float wx, out float wy ) { float ro; float xm, ym; float wxm, wym; ro = ( xb - xt ) * ( xb - xt ) + ( yb - yt ) * ( yb - yt ); ro = (float) Math.Sqrt ( ro ); if ( ro > epf ) { wx = - ( yt - yb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; wy = ( xt - xb ) / ( (float)Math.Pow ( xt - xb, 2 ) + (float)Math.Pow ( yt - yb, 2 ) ) / 2.0F / (float)Math.PI; } else if ( ro > 0.0F ) { xm = xb + epf / ro * ( xt - xb ); ym = yb + epf / ro * ( yt - yb ); speed2f ( xb, yb, xm, ym, out wxm, out wym ); wx = ro / epf * wxm; wy = ro / epf * wym; } else { wx = 0.0F; wy = 0.0F; } } // -------------MCSharp's functions------------------ public Streamline() { initiate(); } public Streamline( SerializationInfo info, StreamingContext context ) { initiate(); n = (int) info.GetValue( "0", typeof( int ) ); nc = (int) info.GetValue( "1", typeof( int ) ); time = (float) info.GetValue( "2", typeof( float ) ); dt = (float) info.GetValue( "3", typeof( float ) ); dg = (float[,,]) info.GetValue( "4", typeof( float[,,] ) ); ir = (int[]) info.GetValue( "5", typeof( int[] ) ); ga = (float[,]) info.GetValue( "6", typeof( float[,] ) ); p = (float[,]) info.GetValue( "7", typeof( float[,] ) ); p0 = (float) info.GetValue( "8", typeof( float ) ); p0n = (float) info.GetValue( "9", typeof( float ) ); al = (float) info.GetValue( "10", typeof( float ) ); rd = (float) info.GetValue( "11", typeof( float ) ); aldt = (float) info.GetValue( "12", typeof( float ) ); ad = (float) info.GetValue( "13", typeof( float ) ); xb = (float[,]) info.GetValue( "14", typeof( float[,] ) ); yb = (float[,]) info.GetValue( "15", typeof( float[,] ) ); x1 = (float[,,]) info.GetValue( "16", typeof( float[,,] ) ); y1 = (float[,,]) info.GetValue( "17", typeof( float[,,] ) ); xt = (float[,]) info.GetValue( "18", typeof( float[,] ) ); yt = (float[,]) info.GetValue( "19", typeof( float[,] ) ); xt0 = (float) info.GetValue( "20", typeof( float ) ); yt0 = (float) info.GetValue( "21", typeof( float ) ); xtl = (float[,]) info.GetValue( "22", typeof( float[,] ) ); ytl = (float[,]) info.GetValue( "23", typeof( float[,] ) ); ta = (float) info.GetValue( "24", typeof( float ) ); epp = (float) info.GetValue( "25", typeof( float ) ); epf = (float) info.GetValue( "26", typeof( float ) ); N_PROCESSORS = (int) info.GetValue( "27", typeof( int ) ); PROCS_ON_CHAIN = (int) info.GetValue( "28", typeof( int ) ); START_CHAIN_LENGTH = (int) info.GetValue( "29", typeof( int ) ); START_SIZE = (int) info.GetValue( "30", typeof( int ) ); INTERVAL = (int) info.GetValue( "31", typeof( int ) ); } public void GetObjectData( SerializationInfo info, StreamingContext context ) { info.AddValue( "0", n, n.GetType() ); info.AddValue( "1", nc, nc.GetType() ); info.AddValue( "2", time, time.GetType() ); info.AddValue( "3", dt, dt.GetType() ); info.AddValue( "4", dg, dg.GetType() ); info.AddValue( "5", ir, ir.GetType() ); info.AddValue( "6", ga, ga.GetType() ); info.AddValue( "7", p, p.GetType() ); info.AddValue( "8", p0, p0.GetType() ); info.AddValue( "9", p0n, p0n.GetType() ); info.AddValue( "10", al, al.GetType() ); info.AddValue( "11", rd, rd.GetType() ); info.AddValue( "12", aldt, aldt.GetType() ); info.AddValue( "13", ad, ad.GetType() ); info.AddValue( "14", xb, xb.GetType() ); info.AddValue( "15", yb, yb.GetType() ); info.AddValue( "16", x1, x1.GetType() ); info.AddValue( "17", y1, y1.GetType() ); info.AddValue( "18", xt, xt.GetType() ); info.AddValue( "19", yt, yt.GetType() ); info.AddValue( "20", xt0, xt0.GetType() ); info.AddValue( "21", yt0, yt0.GetType() ); info.AddValue( "22", xtl, xtl.GetType() ); info.AddValue( "23", ytl, ytl.GetType() ); info.AddValue( "24", ta, ta.GetType() ); info.AddValue( "25", epp, epp.GetType() ); info.AddValue( "26", epf, epf.GetType() ); info.AddValue( "27", N_PROCESSORS, N_PROCESSORS.GetType() ); info.AddValue( "28", PROCS_ON_CHAIN, PROCS_ON_CHAIN.GetType() ); info.AddValue( "29", START_CHAIN_LENGTH, START_CHAIN_LENGTH.GetType() ); info.AddValue( "30", START_SIZE, START_SIZE.GetType() ); info.AddValue( "31", INTERVAL, INTERVAL.GetType() ); } public void initiate() { LocalHost mcLocalHost = LocalHost.CurrentHost; Monitor.Enter( mcLocalHost.objects ); int mcObjectNumber = mcLocalHost.objects.Count + 1; mcLocalHost.objects.Add( mcObjectNumber, this ); Monitor.Exit( mcLocalHost.objects ); c = new Channel( this, mcObjectNumber, "mcChannelc" ); mcQueueGet = new MCSharp.ThreadQ(); } private void scan() { if ( mcBitMaskGetc.match( mcMaskGetc ) ) mcQueueGet.wakeup(); } // -------------Channels----------------------------- [OneWay] public void mcChannelc( int k, int j, int i1, int i2, float[] x_, float[] y_ ) { lock( mcQueueGet ) { c.Enqueue( new object[] { k, j, i1, i2, x_, y_ } ); if ( !mcBitMaskGetc.match( mcMaskc ) ) { mcBitMaskGetc.set( mcMaskc ); scan(); } } } public void Get( float[,,] x, float[,,] y ) { Monitor.Enter( mcQueueGet ); if ( !mcBitMaskGetc.match( mcMaskGet ) ) goto now; later: mcQueueGet.yield( mcQueueGet ); if ( mcQueueGet.empty ) mcBitMaskGetc.clear( mcMaskGet ); now: if ( mcBitMaskGetc.match( mcMaskc ) ) { object[] o = (object[]) c.Dequeue(); int k = (int) o [0]; int j = (int) o [1]; int i1 = (int) o [2]; int i2 = (int) o [3]; float[] x_ = (float[]) o [4]; float[] y_ = (float[]) o [5]; if ( c.Count == 0 ) mcBitMaskGetc.clear( mcMaskc ); scan(); Monitor.Exit( mcQueueGet ); { int i; for ( i = i1 + 1; i <= i2; i++ ) { x [ k, j, i ] = x_ [ i - i1 ]; y [ k, j, i ] = y_ [ i - i1 ]; } } } else { mcBitMaskGetc.set( mcMaskGet ); goto later; } } } public class StreamLineForm : System.Windows.Forms.Form { private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.NumericUpDown nNumeric; private System.Windows.Forms.NumericUpDown ncNumeric; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox timeText; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox dtText; private System.Windows.Forms.Label label5; private System.Windows.Forms.NumericUpDown N_PROCESSORSText; private System.Windows.Forms.Label label6; private System.Windows.Forms.NumericUpDown START_CHAIN_LENGTHText; private System.Windows.Forms.TextBox consoleText; private System.Windows.Forms.Button calculateButton; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; private System.Windows.Forms.TextBox totalTimeText; private System.ComponentModel.Container components = null; public StreamLineForm() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.dtText = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.timeText = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.ncNumeric = new System.Windows.Forms.NumericUpDown(); this.nNumeric = new System.Windows.Forms.NumericUpDown(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.START_CHAIN_LENGTHText = new System.Windows.Forms.NumericUpDown(); this.label6 = new System.Windows.Forms.Label(); this.N_PROCESSORSText = new System.Windows.Forms.NumericUpDown(); this.label5 = new System.Windows.Forms.Label(); this.consoleText = new System.Windows.Forms.TextBox(); this.calculateButton = new System.Windows.Forms.Button(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.totalTimeText = new System.Windows.Forms.TextBox(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ncNumeric)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nNumeric)).BeginInit(); this.tabPage2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.START_CHAIN_LENGTHText)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.N_PROCESSORSText)).BeginInit(); this.SuspendLayout(); // // tabControl1 // this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] { this.tabPage1, this.tabPage2}); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(384, 152); this.tabControl1.TabIndex = 0; // // tabPage1 // this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] { this.dtText, this.label4, this.timeText, this.label3, this.ncNumeric, this.nNumeric, this.label2, this.label1}); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Size = new System.Drawing.Size(376, 126); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "Основные параметры"; // // dtText // this.dtText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dtText.Location = new System.Drawing.Point(184, 96); this.dtText.Name = "dtText"; this.dtText.Size = new System.Drawing.Size(56, 20); this.dtText.TabIndex = 9; double tmpdtText = 0.1; this.dtText.Text = "" + tmpdtText; // // label4 // this.label4.Location = new System.Drawing.Point(16, 96); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(160, 23); this.label4.TabIndex = 8; this.label4.Text = "Шаг по времени:"; // // timeText // this.timeText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.timeText.Location = new System.Drawing.Point(184, 72); this.timeText.Name = "timeText"; this.timeText.Size = new System.Drawing.Size(56, 20); this.timeText.TabIndex = 7; double tmptimeText = 10.0; this.timeText.Text = "" + tmptimeText; // // label3 // this.label3.Location = new System.Drawing.Point(16, 72); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(160, 23); this.label3.TabIndex = 6; this.label3.Text = "Время расчета:"; // // ncNumeric // this.ncNumeric.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.ncNumeric.Location = new System.Drawing.Point(184, 40); this.ncNumeric.Maximum = new System.Decimal(new int[] { 1000, 0, 0, 0}); this.ncNumeric.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.ncNumeric.Name = "ncNumeric"; this.ncNumeric.Size = new System.Drawing.Size(56, 20); this.ncNumeric.TabIndex = 5; this.ncNumeric.Value = new System.Decimal(new int[] { 2, 0, 0, 0}); // // nNumeric // this.nNumeric.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.nNumeric.Location = new System.Drawing.Point(184, 16); this.nNumeric.Maximum = new System.Decimal(new int[] { 1000, 0, 0, 0}); this.nNumeric.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.nNumeric.Name = "nNumeric"; this.nNumeric.Size = new System.Drawing.Size(56, 20); this.nNumeric.TabIndex = 4; this.nNumeric.Value = new System.Decimal(new int[] { 10, 0, 0, 0}); // // label2 // this.label2.Location = new System.Drawing.Point(16, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(160, 32); this.label2.TabIndex = 2; this.label2.Text = "Число вихревых цепочек, сходящих с кромки:"; // // label1 // this.label1.Location = new System.Drawing.Point(16, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(160, 16); this.label1.TabIndex = 1; this.label1.Text = "Число суммарных вихрей:"; // // tabPage2 // this.tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] { this.START_CHAIN_LENGTHText, this.label6, this.N_PROCESSORSText, this.label5}); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Size = new System.Drawing.Size(376, 126); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Дополнительные параметры "; // // START_CHAIN_LENGTHText // this.START_CHAIN_LENGTHText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.START_CHAIN_LENGTHText.Location = new System.Drawing.Point(184, 40); this.START_CHAIN_LENGTHText.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.START_CHAIN_LENGTHText.Name = "START_CHAIN_LENGTHText"; this.START_CHAIN_LENGTHText.Size = new System.Drawing.Size(56, 20); this.START_CHAIN_LENGTHText.TabIndex = 3; this.START_CHAIN_LENGTHText.Value = new System.Decimal(new int[] { 50, 0, 0, 0}); // // label6 // this.label6.Location = new System.Drawing.Point(16, 40); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(128, 32); this.label6.TabIndex = 2; this.label6.Text = "Начальная длина цепочки:"; // // N_PROCESSORSText // this.N_PROCESSORSText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.N_PROCESSORSText.Location = new System.Drawing.Point(184, 16); this.N_PROCESSORSText.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.N_PROCESSORSText.Name = "N_PROCESSORSText"; this.N_PROCESSORSText.Size = new System.Drawing.Size(56, 20); this.N_PROCESSORSText.TabIndex = 1; this.N_PROCESSORSText.Value = new System.Decimal(new int[] { 4, 0, 0, 0}); // // label5 // this.label5.Location = new System.Drawing.Point(16, 16); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(144, 23); this.label5.TabIndex = 0; this.label5.Text = "Количество процессоров:"; // // consoleText // this.consoleText.BackColor = System.Drawing.Color.White; this.consoleText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.consoleText.Location = new System.Drawing.Point(0, 176); this.consoleText.Multiline = true; this.consoleText.Name = "consoleText"; this.consoleText.ReadOnly = true; this.consoleText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.consoleText.Size = new System.Drawing.Size(384, 152); this.consoleText.TabIndex = 1; this.consoleText.Text = ""; this.consoleText.MaxLength = 0; // // calculateButton // this.calculateButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.calculateButton.Location = new System.Drawing.Point(304, 152); this.calculateButton.Name = "calculateButton"; this.calculateButton.Size = new System.Drawing.Size(80, 23); this.calculateButton.TabIndex = 2; this.calculateButton.Text = "Посчитать"; this.calculateButton.Click += new System.EventHandler(this.calculateButton_Click); // // label7 // this.label7.BackColor = System.Drawing.Color.SteelBlue; this.label7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label7.ForeColor = System.Drawing.Color.White; this.label7.Location = new System.Drawing.Point(0, 160); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(200, 16); this.label7.TabIndex = 3; this.label7.Text = "Результаты:"; this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // label8 // this.label8.BackColor = System.Drawing.Color.SteelBlue; this.label8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label8.ForeColor = System.Drawing.Color.White; this.label8.Location = new System.Drawing.Point(0, 336); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(200, 16); this.label8.TabIndex = 4; this.label8.Text = "Время вычисления:"; this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // totalTimeText // this.totalTimeText.BackColor = System.Drawing.Color.White; this.totalTimeText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.totalTimeText.Location = new System.Drawing.Point(0, 352); this.totalTimeText.Name = "totalTimeText"; this.totalTimeText.ReadOnly = true; this.totalTimeText.Size = new System.Drawing.Size(384, 20); this.totalTimeText.TabIndex = 5; this.totalTimeText.Text = ""; // // StreamLineForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(386, 375); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.totalTimeText, this.label8, this.label7, this.calculateButton, this.consoleText, this.tabControl1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "StreamLineForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Параметры StreamLine"; this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.ncNumeric)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nNumeric)).EndInit(); this.tabPage2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.START_CHAIN_LENGTHText)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.N_PROCESSORSText)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// public static void Main( String[] args ) { MCSharp.Session.Init( args ); Application.Run(new StreamLineForm()); MCSharp.Session.FinalizeIt(); } public void RunCalculationsInThread() { totalTimeText.Text = ""; consoleText.Text = ""; calculateButton.Enabled = false; Streamline streamline = new Streamline( this.consoleText, this.totalTimeText ); // initializing parameters int n = (int) nNumeric.Value; int nc = (int) ncNumeric.Value; float time = float.Parse( timeText.Text ); float dt = float.Parse( dtText.Text ); int N_PROCESSORS = (int) N_PROCESSORSText.Value; int START_CHAIN_LENGTH = (int) START_CHAIN_LENGTHText.Value; Streamline.n = n; Streamline.nc = nc; Streamline.time = time; Streamline.dt = dt; Streamline.N_PROCESSORS = N_PROCESSORS; Streamline.START_CHAIN_LENGTH = START_CHAIN_LENGTH; Streamline.dg = new float [ 2, nc, (int)(time/dt) + 3 ]; // depending parameters Streamline.x1 = new float [ 2, nc, (int)(time/dt) + 3 ]; Streamline.y1 = new float [ 2, nc, (int)(time/dt) + 3 ]; Streamline.PROCS_ON_CHAIN = N_PROCESSORS / ( 2 * nc ); Streamline.START_SIZE = START_CHAIN_LENGTH * Streamline.PROCS_ON_CHAIN; DateTime dt1 = DateTime.Now; Streamline.disk( streamline ); DateTime dt2 = DateTime.Now; TimeSpan dt2_1 = dt2.Subtract ( dt1 ); totalTimeText.Text = dt2_1.ToString(); calculateButton.Enabled = true; } Thread calculatingThread; private void calculateButton_Click(object sender, System.EventArgs e) { try { calculatingThread = new Thread( new ThreadStart( RunCalculationsInThread ) ); calculatingThread.Start(); } catch ( ThreadAbortException ) {} } protected override void OnClosed( EventArgs e ) { if ( calculatingThread != null ) { try { calculatingThread.Abort(); } catch {}; } } }