Esempio n. 1
0
        public void validate_photon_database_postprocessor_ROfRhoAndTime_results()
        {
            // DAW postprocssing
            var DAWinput          = GenerateReferenceDAWInput();
            var onTheFlyDAWOutput = new MonteCarloSimulation(DAWinput).Run();

            var DAWdatabase      = PhotonDatabase.FromFile("DiffuseReflectanceDatabase");
            var DAWpostProcessor = new PhotonDatabasePostProcessor(
                VirtualBoundaryType.DiffuseReflectance,
                _detectorInputs,
                DAWdatabase,
                onTheFlyDAWOutput.Input);
            var postProcessedDAWOutput = DAWpostProcessor.Run();

            ValidateROfRhoAndTime(onTheFlyDAWOutput, postProcessedDAWOutput);

            // CAW postprocessing
            var CAWinput          = GenerateReferenceCAWInput();
            var onTheFlyCAWOutput = new MonteCarloSimulation(CAWinput).Run();

            var CAWdatabase      = PhotonDatabase.FromFile("DiffuseReflectanceDatabase");
            var CAWpostProcessor = new PhotonDatabasePostProcessor(
                VirtualBoundaryType.DiffuseReflectance,
                _detectorInputs,
                CAWdatabase,
                onTheFlyCAWOutput.Input);
            var postProcessedCAWOutput = CAWpostProcessor.Run();

            ValidateROfRhoAndTime(onTheFlyCAWOutput, postProcessedCAWOutput);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to read photon database from file
        /// </summary>
        /// <param name="virtualBoundaryType">VB type</param>
        /// <param name="filePath">path to database file</param>
        /// <returns>PhotonDatabase read</returns>
        public static PhotonDatabase GetPhotonDatabase(
            VirtualBoundaryType virtualBoundaryType, string filePath)
        {
            string dbFilename;

            switch (virtualBoundaryType)
            {
            case VirtualBoundaryType.DiffuseReflectance:
                dbFilename = Path.Combine(filePath, "DiffuseReflectanceDatabase");
                break;

            case VirtualBoundaryType.DiffuseTransmittance:
                dbFilename = Path.Combine(filePath, "DiffuseTransmittanceDatabase");
                break;

            case VirtualBoundaryType.SpecularReflectance:
                dbFilename = Path.Combine(filePath, "SpecularReflectanceDatabase");
                break;

            case VirtualBoundaryType.pMCDiffuseReflectance:     //pMC uses same exit db as regular post-processing
                dbFilename = Path.Combine(filePath, "DiffuseReflectanceDatabase");
                break;

            default:
                return(null);
            }
            if (!File.Exists(dbFilename))
            {
                throw new FileNotFoundException("\nThe database file could not be found: " + dbFilename);
            }
            return(PhotonDatabase.FromFile(dbFilename));
        }
Esempio n. 3
0
        public void validate_PhotonDatabase_deserialized_class_is_correct_when_using_WriteToFile()
        {
            // test serialization
            new SimulationInput().ToFile("SimulationInputTest.txt");

            string databaseFilename = "testphotondatabase";

            using (var dbWriter = new PhotonDatabaseWriter(
                       VirtualBoundaryType.DiffuseReflectance, databaseFilename))
            {
                dbWriter.Write(new PhotonDataPoint(
                                   new Position(1, 2, 3),
                                   new Direction(0, 0, 1),
                                   1.0, // weight
                                   10,  // time
                                   PhotonStateType.None));

                dbWriter.Write(new PhotonDataPoint(
                                   new Position(4, 5, 6),
                                   new Direction(1, 0, 0),
                                   0.50,
                                   100,
                                   PhotonStateType.None));
            }

            // read the database from file, and verify the correct number of photons were written
            var dbCloned = PhotonDatabase.FromFile(databaseFilename);

            Assert.AreEqual(dbCloned.NumberOfElements, 2);

            // manually enumerate through the first two elements (same as foreach)
            // PhotonDatabase is designed so you don't have to have the whole thing
            // in memory, so .ToArray() loses the benefits of the lazy-load data points
            var enumerator = dbCloned.DataPoints.GetEnumerator();

            // advance to the first point and test that the point is valid
            enumerator.MoveNext();
            var dp1 = enumerator.Current;

            Assert.AreEqual(dp1.Position, new Position(1, 2, 3));
            Assert.AreEqual(dp1.Direction, new Direction(0, 0, 1));
            Assert.AreEqual(dp1.Weight, 1.0);
            Assert.AreEqual(dp1.TotalTime, 10);
            Assert.IsTrue(dp1.StateFlag.HasFlag(PhotonStateType.None));

            // advance to the second point and test that the point is valid
            enumerator.MoveNext();
            var dp2 = enumerator.Current;

            Assert.AreEqual(dp2.Position, new Position(4, 5, 6));
            Assert.AreEqual(dp2.Direction, new Direction(1, 0, 0));
            Assert.AreEqual(dp2.Weight, 0.5);
            Assert.AreEqual(dp2.TotalTime, 100);
            Assert.IsTrue(dp2.StateFlag.HasFlag(PhotonStateType.None));
        }