コード例 #1
0
ファイル: Cropper.cs プロジェクト: aarongrisez/TDSE
        /// <summary>
        /// Worker method.
        /// </summary>
        protected override void WorkerMethod()
        {
            string[] vtkFiles = Directory.GetFiles(m_inputDir, "*.vtk");
            if ((vtkFiles == null) || (vtkFiles.Length == 0))
            {
                return;
            }

            m_outputDir = CreateOutputDir(m_inputDir);
            string paramsFile = Path.Combine(m_inputDir, "Params.txt");

            if (File.Exists(paramsFile))
            {
                File.Copy(paramsFile, Path.Combine(m_outputDir, Path.GetFileName(paramsFile)));
            }

            m_numFilesToProcess = vtkFiles.Length;
            int chunkSize = Environment.ProcessorCount;

            for (int iStart = 0; iStart < m_numFilesToProcess; iStart += chunkSize)
            {
                int iEnd = Math.Min(iStart + chunkSize, m_numFilesToProcess);
                Parallel.For(iStart, iEnd, i =>
                {
                    // Crop one file, and save the result
                    string inputFile           = vtkFiles[i];
                    ProbabilityDensity[] probs = ProbabilityDensity.ReadFromVtkFile(inputFile);
                    probs[0] = Crop(probs[0], m_xminCrop, m_xmaxCrop, m_yminCrop, m_ymaxCrop);
                    probs[1] = Crop(probs[1], m_xminCrop, m_xmaxCrop, m_yminCrop, m_ymaxCrop);

                    string outFile = Path.Combine(m_outputDir, Path.GetFileName(inputFile));
                    ProbabilityDensity.SaveToVtkFile(probs, outFile);
                });

                // Report progress to the caller
                m_currentFileIndex = iEnd - 1;
                ReportProgress();
                if (IsCancelled)
                {
                    return;
                }
            }
        }
コード例 #2
0
ファイル: Evolver.cs プロジェクト: aarongrisez/TDSE
        /// <summary>
        /// Saves the current probability densities to a vtk file.
        /// </summary>
        private void SaveOutputFile(string fileSpec)
        {
            float time = m_currentTimeStepIndex * m_deltaT;

            ProbabilityDensity prob1 = GetSingleParticleProbability(1, time);

            if (prob1 == null)
            {
                return;
            }
            System.Diagnostics.Trace.WriteLine(prob1.Norm().ToString());

            ProbabilityDensity prob2 = GetSingleParticleProbability(2, time);

            if (prob2 == null)
            {
                return;
            }
            System.Diagnostics.Trace.WriteLine("          " + prob2.Norm().ToString());

            ProbabilityDensity.SaveToVtkFile(new ProbabilityDensity[] { prob1, prob2 }, fileSpec);
        }