예제 #1
0
        /// <summary>
        /// Handles Progress events from the Evolver.
        /// </summary>
        void Evolver_ProgressEvent(TdseUtils.Proc sender)
        {
            Evolver evolver = (Evolver)sender;

            // If the current frame is a keyframe, then save it.
            double frameInterval = (m_params.NumFramesToSave <= 1) ? 1 : m_params.TotalTime / (m_params.NumFramesToSave - 1);

            if (evolver.CurrentTimeStepIndex == (int)Math.Round((m_lastSavedFrame + 1) * frameInterval / m_params.TimeStep))
            {
                if (m_lastSavedFrame + 1 < m_params.NumFramesToSave)
                {
                    string outFile = Path.Combine(m_outputDir, "Frame_" + (m_lastSavedFrame + 1).ToString("D4") + ".vtk");
                    evolver.Wf.SaveToVtkFile(outFile, m_params.SaveFormat);
                }
                m_lastSavedFrame++;
            }

            // Update the progress bar
            int val = (100 * evolver.CurrentTimeStepIndex) / (evolver.TotalNumTimeSteps);

            if (Main_ProgressBar.Value != val)
            {
                Main_ProgressBar.Value = val;                  // Workaround for slow ProgressBar updates
                Main_ProgressBar.Value = Math.Max(0, val - 1); //
                Main_ProgressBar.Value = val;                  //
            }
        }
예제 #2
0
        /// <summary>
        /// Evolves the wavefunction and saves keyframes to disk.
        /// </summary>
        private void CreateAnimationFrames()
        {
            // Get a fresh output directory
            m_outputDir = CreateOutputDir();

            // Write the run parameters to a file
            string paramsFile = Path.Combine(m_outputDir, "Params.txt");

            File.WriteAllText(paramsFile, m_params.ToString().Replace("\n", "\r\n"));


            // Create the initial wavefunction
            WaveFunction wf = WaveFunctionUtils.CreateGaussianWavePacket(
                m_params.GridSizeX, m_params.GridSizeY, m_params.LatticeSpacing, m_params.ParticleMass,
                m_params.InitialWavePacketCenter,
                m_params.InitialWavePacketSize,
                m_params.InitialWavePacketMomentum,
                m_params.MultiThread
                );

            // Save the initial wf as Frame 0
            wf.SaveToVtkFile(Path.Combine(m_outputDir, "Frame_0000.vtk"), m_params.SaveFormat);
            m_lastSavedFrame = 0;


            // Create an Evolver and run it in the background
            Evolver.VDelegate V = (x, y, t, m, sx, sy) => { return(m_VBuilder.V(x, y, t, m, sx, sy)); };

            m_evolver = new Evolver(wf, m_params.TotalTime, m_params.TimeStep, V, false, m_params.ParticleMass, 1,
                                    m_params.DampingBorderWidth, m_params.DampingFactor, m_params.MultiThread);
            m_evolver.ProgressEvent   += Evolver_ProgressEvent;
            m_evolver.CompletionEvent += Evolver_CompletionEvent;

            m_evolver.RunInBackground();
        }