private float ComputeCharge(int x, int y, Electrons electrons_) { float result = 0; for (int i = 0; i < electrons_.electrons_x_.Length; i++) { result += (float)(1 / (float)Len(x, y, electrons_.electrons_x_[i], electrons_.electrons_y_[i]) * electrons_.electrons_charge_[i]); if (x == electrons_.electrons_x_[i] && y == electrons_.electrons_y_[i]) { return(0); } } return(result); }
private void GenerateElectrons() { electrons = new Electrons(); Random rand = new Random(); for (int i = 0; i < electron_count; i++) { int x = rand.Next(0, drawing_panel.Width); int y = rand.Next(0, drawing_panel.Height); int move_x = rand.Next(-10, 10); int move_y = rand.Next(-10, 10); short charge = rand.Next(0, 10) % 2 == 0 ? (short)-1 : (short)1; electrons.Add(x, y, move_x, move_y, charge); } CreateColorValues(); electrons.MakeArrays(); }
private static void SolveByGpu(Electrons electrons_, int width, int height, out byte[] snoop, out string str, byte[] r, byte[] g, byte[] b) { Stopwatch sw = new Stopwatch(); var gpu = Gpu.Default; var lp = new LaunchParam(128, 1024, r.Length * 3 /*+electrons_.electrons_y_.Length*2*sizeof(int)*/); int[] electron_x; int[] electron_y; int[] electron_move_x; int[] electron_move_y; short[] charge; electrons_.ToArray(out electron_x, out electron_y, out electron_move_x, out electron_move_y, out charge); // int[][] par = new int[4][] { electron_x, electron_y, electron_move_x, electron_move_y }; var result_r = new byte[4 * width * height]; int dwidth = width; int dheight = height; sw.Start(); /// gpu.Launch(Kernel, lp, result_r, electron_x, electron_y, electron_move_x, electron_move_y, charge, dwidth, dheight, r, g, b); sw.Stop(); //Session sesja = new Session(gpu); //sesja.Scan<int[]>(par,par,) /// electrons_.FromArray(electron_x, electron_y, electron_move_x, electron_move_y, charge); snoop = result_r; str = sw.ElapsedMilliseconds.ToString() + " ms"; }