Exemplo n.º 1
0
        /// <summary>
        /// Handles click events from the Run/Stop button.
        /// </summary>
        private void RunStop_Btn_Click(object sender, EventArgs e)
        {
            // Sanity check the inputs
            if (2 * DampingBorderWidth_NUD.Value > Math.Min(GridSizeX_NUD.Value, Math.Min(GridSizeY_NUD.Value, GridSizeZ_NUD.Value)))
            {
                MessageBox.Show("Damping border must be less than half the minimum grid dimension.");
                return;
            }

            if (RunStop_Btn.Text == "Stop")
            {
                RunStop_Btn.Enabled     = false;
                PauseResume_Btn.Enabled = false;

                m_evolver.Cancel();
            }
            else
            {
                RunStop_Btn.Text        = "Stop";
                PauseResume_Btn.Enabled = true;
                Main_ProgressBar.Value  = 0;
                EnableInputs(false);

                m_params = GetParamsFromUi();
                Properties.Settings.Default.LastRunParams = m_params.ToString();
                Properties.Settings.Default.Save();
                CreateAnimationFrames();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the UI values from a RunParams object.
        /// </summary>
        private RunParams UpdateUiFromParams(RunParams parms)
        {
            GridSizeX_NUD.Value = parms.GridSpec.SizeX;
            GridSizeY_NUD.Value = parms.GridSpec.SizeY;
            GridSizeZ_NUD.Value = parms.GridSpec.SizeZ;

            LatticeSpacing_NUD.Value = (decimal)parms.LatticeSpacing;
            Mass_NUD.Value           = (decimal)parms.ParticleMass;

            InitialPacketSizeX_NUD.Value   = (decimal)parms.InitialWavePacketSize.X;
            InitialPacketSizeY_NUD.Value   = (decimal)parms.InitialWavePacketSize.Y;
            InitialPacketSizeZ_NUD.Value   = (decimal)parms.InitialWavePacketSize.Z;
            InitialPacketCenterX_NUD.Value = (decimal)parms.InitialWavePacketCenter.X;
            InitialPacketCenterY_NUD.Value = (decimal)parms.InitialWavePacketCenter.Y;
            InitialPacketCenterZ_NUD.Value = (decimal)parms.InitialWavePacketCenter.Z;
            InitialMomentumX_NUD.Value     = (decimal)parms.InitialWavePacketMomentum.X;
            InitialMomentumY_NUD.Value     = (decimal)parms.InitialWavePacketMomentum.Y;
            InitialMomentumZ_NUD.Value     = (decimal)parms.InitialWavePacketMomentum.Z;

            DampingBorderWidth_NUD.Value = parms.DampingBorderWidth;
            DampingFactor_NUD.Value      = (decimal)parms.DampingFactor;

            TimeStep_NUD.Value  = (decimal)parms.TimeStep;
            TotalTime_NUD.Value = (decimal)parms.TotalTime;
            NumFrames_NUD.Value = (decimal)parms.NumFramesToSave;

            MultiThread_CheckBox.Checked = parms.MultiThread;

            m_VBuilder.SetCode(parms.VCode);

            return(parms);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the UI parameters into a RunParams object.
        /// </summary>
        private RunParams GetParamsFromUi()
        {
            RunParams parms = new RunParams();

            parms.GridSpec.SizeX = Convert.ToInt32(GridSizeX_NUD.Value);
            parms.GridSpec.SizeY = Convert.ToInt32(GridSizeY_NUD.Value);
            parms.GridSpec.SizeZ = Convert.ToInt32(GridSizeZ_NUD.Value);

            parms.LatticeSpacing = (float)LatticeSpacing_NUD.Value;
            parms.ParticleMass   = (float)Mass_NUD.Value;

            parms.InitialWavePacketSize     = new Vec3((float)InitialPacketSizeX_NUD.Value, (float)InitialPacketSizeY_NUD.Value, (float)InitialPacketSizeZ_NUD.Value);
            parms.InitialWavePacketCenter   = new Vec3((float)InitialPacketCenterX_NUD.Value, (float)InitialPacketCenterY_NUD.Value, (float)InitialPacketCenterZ_NUD.Value);
            parms.InitialWavePacketMomentum = new Vec3((float)InitialMomentumX_NUD.Value, (float)InitialMomentumY_NUD.Value, (float)InitialMomentumZ_NUD.Value);
            parms.DampingBorderWidth        = (int)DampingBorderWidth_NUD.Value;
            parms.DampingFactor             = (float)DampingFactor_NUD.Value;

            parms.TimeStep        = (float)TimeStep_NUD.Value;
            parms.TotalTime       = (float)TotalTime_NUD.Value;
            parms.NumFramesToSave = (int)NumFrames_NUD.Value;

            parms.MultiThread = MultiThread_CheckBox.Checked;

            parms.VCode = RunParams.FromString(Properties.Settings.Default.LastRunParams).VCode;

            return(parms);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the last-saved code.
        /// </summary>
        private void LoadLastSavedCode()
        {
            string errorMessages = SetCode(RunParams.FromString(Properties.Settings.Default.LastRunParams).VCode);

            if (!string.IsNullOrEmpty(errorMessages))
            {
                SetCode(DefaultSnippet);
            }
        }
Exemplo n.º 5
0
        // Constructor
        public SolverControl()
        {
            InitializeComponent();
            m_VBuilder = new VCodeBuilder(); // Also loads the last-used code snippet

            // Load the last-used params
            if (!string.IsNullOrEmpty(Properties.Settings.Default.LastRunParams))
            {
                try
                {
                    UpdateUiFromParams(RunParams.FromString(Properties.Settings.Default.LastRunParams));
                }
                catch {}
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Handler for drag-drop events
 /// </summary>
 private void OnDragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         if (files.Length > 0)
         {
             try
             {
                 string    fileContents = File.ReadAllText(files[0]);
                 RunParams parms        = RunParams.FromString(fileContents);
                 UpdateUiFromParams(parms);
             }
             catch
             {
                 MessageBox.Show("Invalid parameter file");
             }
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Sets and saves the V-code.
        /// </summary>
        public string SetCode(string code)
        {
            // Try to compile the given code
            string   errorMessages;
            Assembly assembly = CompileCode(AddBoilerplateCode(code), out errorMessages);

            // Check for compilation errors
            if (assembly == null)
            {
                return(string.IsNullOrEmpty(errorMessages) ? "Unknown compilation error." : errorMessages);
            }
            else
            {
                // Accept the given code
                Code_TextBox.Text = code;
                m_vCalcMethodInfo = assembly.GetTypes()[0].GetMethod("V", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

                RunParams parms = RunParams.FromString(Properties.Settings.Default.LastRunParams);
                parms.VCode = code;
                Properties.Settings.Default.LastRunParams = parms.ToString();
                Properties.Settings.Default.Save();
                return("");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a RunParams instance from its string representation.
        /// </summary>
        public static RunParams FromString(string stringRep)
        {
            RunParams result = new RunParams();

            string[] lines = stringRep.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            int numLines = lines.Length;

            for (int lineIndex = 0; lineIndex < numLines; lineIndex++)
            {
                string line = lines[lineIndex];

                if (line.Contains("GridSizeX"))
                {
                    result.GridSpec.SizeX = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("GridSizeY"))
                {
                    result.GridSpec.SizeY = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("GridSizeZ"))
                {
                    result.GridSpec.SizeZ = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("LatticeSpacing"))
                {
                    result.LatticeSpacing = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("ParticleMass"))
                {
                    result.ParticleMass = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketSizeX"))
                {
                    result.InitialWavePacketSize.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketSizeY"))
                {
                    result.InitialWavePacketSize.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketSizeZ"))
                {
                    result.InitialWavePacketSize.Z = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketCenterX"))
                {
                    result.InitialWavePacketCenter.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketCenterY"))
                {
                    result.InitialWavePacketCenter.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketCenterZ"))
                {
                    result.InitialWavePacketCenter.Z = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketMomentumX"))
                {
                    result.InitialWavePacketMomentum.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketMomentumY"))
                {
                    result.InitialWavePacketMomentum.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketMomentumZ"))
                {
                    result.InitialWavePacketMomentum.Z = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("DampingBorderWidth"))
                {
                    result.DampingBorderWidth = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("DampingFactor"))
                {
                    result.DampingFactor = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("TimeStep"))
                {
                    result.TimeStep = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("TotalTime"))
                {
                    result.TotalTime = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("NumFramesToSave"))
                {
                    result.NumFramesToSave = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("MultiThread"))
                {
                    result.MultiThread = bool.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("SaveFormat"))
                {
                    result.SaveFormat = (WaveFunction.WfSaveFormat)Enum.Parse(typeof(WaveFunction.WfSaveFormat), line.Split(':')[1], true);
                }
                else if (!string.IsNullOrEmpty(line))
                {
                    for (; lineIndex < numLines; lineIndex++)
                    {
                        result.VCode += lines[lineIndex] + "\n";
                    }
                }
            }

            return(result);
        }