Esempio n. 1
0
        /// <summary>
        /// Reads the UI parameters into a RunParams object.
        /// </summary>
        private RunParams GetParamsFromUi()
        {
            RunParams parms = new RunParams();

            parms.GridSize.Width  = Convert.ToInt32(GridSizeX_NUD.Value);
            parms.GridSize.Height = Convert.ToInt32(GridSizeY_NUD.Value);
            parms.LatticeSpacing  = (float)LatticeSpacing_NUD.Value;
            parms.Mass1           = (float)Mass1_NUD.Value;
            parms.Mass2           = (float)Mass2_NUD.Value;

            parms.InitialWavePacketSize    = new Vec2((float)InitialPacketSizeX_NUD.Value, (float)InitialPacketSizeY_NUD.Value);
            parms.InitialWavePacketCenter1 = new Vec2((float)InitialPacketCenter1x_NUD.Value, (float)InitialPacketCenter1y_NUD.Value);
            parms.AtomCenter = new Vec2((float)InitialPacketCenter2x_NUD.Value, (float)InitialPacketCenter2y_NUD.Value);
            parms.InitialWavePacketMomentum1 = new Vec2((float)P1x_NUD.Value, (float)P1y_NUD.Value);
            parms.AtomSize = (float)AtomSize_NUD.Value;

            string shoStateString = (string)SHOState_ComboBox.SelectedItem;

            string[] comps = shoStateString.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            parms.Atom_N  = int.Parse(comps[2]);
            parms.Atom_Lz = int.Parse(comps[comps.Length - 1]);

            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);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public Evolver(RunParams parms, VDelegate V, string outputDir)
        {
            m_gridSizeX            = parms.GridSize.Width;
            m_gridSizeY            = parms.GridSize.Height;
            m_latticeSpacing       = parms.LatticeSpacing;
            m_totalTime            = parms.TotalTime;
            m_deltaT               = parms.TimeStep;
            m_totalNumTimeSteps    = (int)Math.Round(parms.TotalTime / parms.TimeStep) + 1;
            m_currentTimeStepIndex = 0;

            m_mass1     = parms.Mass1;
            m_mass2     = parms.Mass2;
            m_potential = V;

            m_initialMomentum1 = new Vec2(parms.InitialWavePacketMomentum1);
            m_initialPosition1 = new Vec2(parms.InitialWavePacketCenter1);
            m_initialSize1     = new Vec2(parms.InitialWavePacketSize);

            m_initialPosition2 = new Vec2(parms.AtomCenter);
            m_sho_sigma        = parms.AtomSize;
            m_sho_N            = parms.Atom_N;
            m_sho_Lz           = parms.Atom_Lz;

            m_numFramesToSave = parms.NumFramesToSave;
            m_lastSavedFrame  = -1;
            m_outputDir       = outputDir;
            m_multiThread     = parms.MultiThread;

            m_visscherWf = null;
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        // Constructor
        public SolverControl()
        {
            InitializeComponent();
            SHOState_ComboBox.SelectedIndex = 0;

            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 {}
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the UI values from a RunParams object.
        /// </summary>
        private RunParams UpdateUiFromParams(RunParams parms)
        {
            GridSizeX_NUD.Value      = parms.GridSize.Width;
            GridSizeY_NUD.Value      = parms.GridSize.Height;
            LatticeSpacing_NUD.Value = (decimal)parms.LatticeSpacing;
            Mass1_NUD.Value          = (decimal)parms.Mass1;
            Mass2_NUD.Value          = (decimal)parms.Mass2;

            InitialPacketSizeX_NUD.Value    = (decimal)parms.InitialWavePacketSize.X;
            InitialPacketSizeY_NUD.Value    = (decimal)parms.InitialWavePacketSize.Y;
            InitialPacketCenter1x_NUD.Value = (decimal)parms.InitialWavePacketCenter1.X;
            InitialPacketCenter1y_NUD.Value = (decimal)parms.InitialWavePacketCenter1.Y;
            InitialPacketCenter2x_NUD.Value = (decimal)parms.AtomCenter.X;
            InitialPacketCenter2y_NUD.Value = (decimal)parms.AtomCenter.Y;
            P1x_NUD.Value      = (decimal)parms.InitialWavePacketMomentum1.X;
            P1y_NUD.Value      = (decimal)parms.InitialWavePacketMomentum1.Y;
            AtomSize_NUD.Value = (decimal)parms.AtomSize;

            if (parms.Atom_N == 1)
            {
                SHOState_ComboBox.SelectedIndex = 1;
            }
            else if ((parms.Atom_N == 2) && (parms.Atom_Lz == 0))
            {
                SHOState_ComboBox.SelectedIndex = 2;
            }
            else if ((parms.Atom_N == 2) && (parms.Atom_Lz == 2))
            {
                SHOState_ComboBox.SelectedIndex = 3;
            }
            else
            {
                SHOState_ComboBox.SelectedIndex = 0;
            }

            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);
        }
Esempio 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");
             }
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Handles click events from the Run/Stop button.
        /// </summary>
        private void RunStop_Btn_Click(object sender, EventArgs e)
        {
            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();
            }
        }
Esempio n. 8
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("");
            }
        }
Esempio n. 9
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.GridSize.Width = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("GridSizeY"))
                {
                    result.GridSize.Height = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("LatticeSpacing"))
                {
                    result.LatticeSpacing = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("Mass1"))
                {
                    result.Mass1 = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("Mass2"))
                {
                    result.Mass2 = 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("InitialWavePacketCenter1x"))
                {
                    result.InitialWavePacketCenter1.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketCenter1y"))
                {
                    result.InitialWavePacketCenter1.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("AtomCenterX"))
                {
                    result.AtomCenter.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("AtomCenterY"))
                {
                    result.AtomCenter.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketMomentum1x"))
                {
                    result.InitialWavePacketMomentum1.X = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("InitialWavePacketMomentum1y"))
                {
                    result.InitialWavePacketMomentum1.Y = Single.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("Atom_N"))
                {
                    result.Atom_N = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("Atom_Lz"))
                {
                    result.Atom_Lz = int.Parse(line.Split(':')[1]);
                }
                else if (line.Contains("AtomSize"))
                {
                    result.AtomSize = 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"))
                {
                    // Do nothing (This is for backwards compatibility)
                }
                else if (!string.IsNullOrEmpty(line))
                {
                    for (; lineIndex < numLines; lineIndex++)
                    {
                        result.VCode += lines[lineIndex] + "\n";
                    }
                }
            }

            return(result);
        }