예제 #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);
        }
예제 #3
0
        /// <summary>
        /// Reads density values from a vtk stream.
        /// </summary>
        private static ProbabilityDensity FromVtkStream(BinaryReader br, int sizeX, int sizeY, float latticeSpacing)
        {
            ProbabilityDensity result = new ProbabilityDensity(sizeX, sizeY, latticeSpacing);

            unsafe
            {
                // For performance, we keep a temporary float value with pointers to its bytes
                float floatVal    = 0.0f;
                byte *floatBytes0 = (byte *)(&floatVal);
                byte *floatBytes1 = floatBytes0 + 1;
                byte *floatBytes2 = floatBytes0 + 2;
                byte *floatBytes3 = floatBytes0 + 3;

                // Read the density values
                ReadTextLine(br);
                ReadTextLine(br);
                byte[] bytePlane = br.ReadBytes(sizeX * sizeY * 4);

                int n = 0;
                for (int y = 0; y < sizeY; y++)
                {
                    float[] dataY = result.Data[y];
                    for (int x = 0; x < sizeX; x++)
                    {
                        *floatBytes3 = bytePlane[n];
                        *floatBytes2 = bytePlane[n + 1];
                        *floatBytes1 = bytePlane[n + 2];
                        *floatBytes0 = bytePlane[n + 3];
                        dataY[x] = floatVal;
                        n       += 4;
                    }
                }
            }

            return(result);
        }
예제 #4
0
파일: Cropper.cs 프로젝트: aarongrisez/TDSE
        /// <summary>
        /// Crops a wavefunction.
        /// </summary>
        public static ProbabilityDensity Crop(ProbabilityDensity inputDensity, int xminCrop, int xmaxCrop, int yminCrop, int ymaxCrop)
        {
            float[][] modData = Crop(inputDensity.Data, xminCrop, xmaxCrop, yminCrop, ymaxCrop);

            return(new ProbabilityDensity(modData, inputDensity.LatticeSpacing));
        }