private void btJump_Click(object sender, EventArgs e) { jump = Convert.ToDouble(tbJump.Text); p.Maxtime += jump; // So that the iteration can run after jump int nsteps = (int)(jump / p.Step); // Number of steps int i = 0; // Counter TimeSpan t; string timetaken; // Initialise progressbar progbar.Visible = true; progbar.Value = 1; progbar.Minimum = 1; progbar.Maximum = nsteps; // Calculate time taken for one iteration by averaging 10 rules.Initialise(p); var beginTime = DateTime.Now; for (i = 1; i <= 10; i++) { rules.Iterate(su, sv); } var endTime = DateTime.Now; var elaspedTime = (endTime - beginTime).TotalSeconds; elaspedTime /= 10; t = TimeSpan.FromSeconds(elaspedTime * nsteps); timetaken = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", t.Hours, t.Minutes, t.Seconds, t.Milliseconds); MessageBox.Show(string.Format("This will aproximately {0}", timetaken), "Time to complete", MessageBoxButtons.OK, MessageBoxIcon.Information); // Reinitialise states su.Initialise(su, p, 0); sv.Initialise(sv, p, 1); // Truncatate states probabilistically if using random initial conditions rules.Initialise(p); rules.TruncateGeneral(su); rules.TruncateGeneral(sv); while (i <= nsteps) { // Iterate simulation average = rules.Iterate(su, sv); // Display DisplayFull(fu, su); DisplayFull(fv, sv); pictBoxu.Refresh(); pictBoxv.Refresh(); // Save data to file twu.WriteLine("{0},{1}", (i * p.Step), average[0]); twv.WriteLine("{0},{1}", (i * p.Step), average[1]); // Save images regularly if (cbSave.Checked == true) { if (((i * p.Step) % tsave) == 0) { SavePNG(bu, (i * p.Step), 0); SavePNG(bv, (i * p.Step), 1); } } tbTime.Text = Convert.ToString(i * p.Step); // Display current time progbar.Value = i; // Increment progressbar this.Refresh(); // tbTime doesn't update otherwise i++; } btJump.Enabled = true; }
private void parametersToolStripMenuItem_Click(object sender, EventArgs e) { btStop_Click(sender, e); // Stop everything when user opens parameter window frmParameterBox frmp = new frmParameterBox(); // Save current parameter values frmp.Pdata.Psetname = p.Psetname; frmp.Pdata.Ru = p.Ru; frmp.Pdata.Rv = p.Rv; frmp.Pdata.A = p.A; frmp.Pdata.B = p.B; frmp.Pdata.U0 = p.U0; frmp.Pdata.V0 = p.V0; frmp.Pdata.Step = p.Step; frmp.Pdata.N = p.N; frmp.Pdata.Maxtime = p.Maxtime; // Save changed values // This updates quite a lot of things DialogResult d = frmp.ShowDialog(); if (d == DialogResult.OK) { // Assign user-defined parameters p.Psetname = frmp.Pdata.Psetname; p.Ru = frmp.Pdata.Ru; p.Rv = frmp.Pdata.Rv; p.U0 = frmp.Pdata.U0; p.V0 = frmp.Pdata.V0; p.A = frmp.Pdata.A; p.B = frmp.Pdata.B; p.Step = frmp.Pdata.Step; p.N = frmp.Pdata.N; p.Maxtime = frmp.Pdata.Maxtime; tbTime.Text = "0.00"; btJump.Enabled = true; // Create new state objects su = new State(p); sv = new State(p); // If user changes parameters, update the states & display su.Initialise(su, p, 0); sv.Initialise(sv, p, 1); // Truncatate states probabilistically if using random initial conditions rules.Initialise(p); rules.TruncateGeneral(su); rules.TruncateGeneral(sv); Display(su, sv); // Reinitialise imaging if parameters are changed bu = new Bitmap(bitmapsize, bitmapsize); bv = new Bitmap(bitmapsize, bitmapsize); pictBoxu.Image = bu; pictBoxv.Image = bv; fu = new FastBitmapAccess(bu, p); fv = new FastBitmapAccess(bv, p); DisplayFull(fu, su); DisplayFull(fv, sv); pictBoxu.Refresh(); pictBoxv.Refresh(); // Refresh picture box // Update and display diffusion coefficients diffu = p.Ru * (p.Ru + 1) * p.Step; diffu /= 6; diffv = p.Rv * (p.Rv + 1) * p.Step; diffv /= 6; tbDiffu.Text = Convert.ToString(diffu); tbDiffv.Text = Convert.ToString(diffv); twu.Close(); twv.Close(); // Create directories for averages pathpset[0] = pathpics + "\\" + p.Psetname; pathpset[1] = pathpics + "\\" + p.Psetname; Directory.CreateDirectory(pathpset[0]); Directory.CreateDirectory(pathpset[1]); twu = File.CreateText(string.Format("{0}\\Average_u.csv", pathpset[0])); twv = File.CreateText(string.Format("{0}\\Average_v.csv", pathpset[1])); // Create directories for images pathpset[0] += "\\species_u\\"; pathpset[1] += "\\species_v\\"; Directory.CreateDirectory(pathpset[0]); Directory.CreateDirectory(pathpset[1]); } else if (d == DialogResult.Cancel) { frmp.Close(); } }
private void MACA_Load(object sender, EventArgs e) { frmParameterBox frmp = new frmParameterBox(); DialogResult d = frmp.ShowDialog(); if (d == DialogResult.OK) { // Assign user-defined parameters p.Psetname = frmp.Pdata.Psetname; p.Ru = frmp.Pdata.Ru; p.Rv = frmp.Pdata.Rv; p.U0 = frmp.Pdata.U0; p.V0 = frmp.Pdata.V0; p.A = frmp.Pdata.A; p.B = frmp.Pdata.B; p.Step = frmp.Pdata.Step; p.N = frmp.Pdata.N; p.Maxtime = frmp.Pdata.Maxtime; } // Maximise the main window as default this.WindowState = FormWindowState.Maximized; // Initialise states u, v with parameters p and display them su = new State(p); sv = new State(p); su.Initialise(su, p, 0); sv.Initialise(sv, p, 1); // Truncatate states probabilistically if using random initial conditions rules.Initialise(p); rules.TruncateGeneral(su); rules.TruncateGeneral(sv); Display(su, sv); // Initial imaging bu = new Bitmap(bitmapsize, bitmapsize); // New image of desired size (user specified) bv = new Bitmap(bitmapsize, bitmapsize); // It's scaled acording to the size of p.N pictBoxu.Image = bu; // Assign image to picturebox pictBoxv.Image = bv; fu = new FastBitmapAccess(bu, p); fv = new FastBitmapAccess(bv, p); try { // Update display DisplayFull(fu, su); DisplayFull(fv, sv); pictBoxu.Refresh(); pictBoxv.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); } // Update and display diffusion coefficients diffu = p.Ru * (p.Ru + 1) * p.Step; diffu /= 6; diffv = p.Rv * (p.Rv + 1) * p.Step; diffv /= 6; tbDiffu.Text = Convert.ToString(diffu); tbDiffv.Text = Convert.ToString(diffv); // Create directories for images // if (p.Psetname == null) // p.Psetname = "Basic Configuration"; // if user hits "cancel" upon opening // Create the directory \p.Psetname\ & add the average_u,v.csv files to ti pathpset[0] = pathpics + "\\" + p.Psetname; pathpset[1] = pathpics + "\\" + p.Psetname; Directory.CreateDirectory(pathpset[0]); Directory.CreateDirectory(pathpset[1]); twu = File.CreateText(string.Format("{0}\\Average_u.csv", pathpset[0])); twv = File.CreateText(string.Format("{0}\\Average_v.csv", pathpset[1])); pathpset[0] += "\\species_u\\"; pathpset[1] += "\\species_v\\"; Directory.CreateDirectory(pathpset[0]); Directory.CreateDirectory(pathpset[1]); }