Exemple #1
0
 /// <summary>
 /// Method to determine statistics about how the photon died.
 /// </summary>
 /// <param name="statistics">SimulationStatistics class where statistics are kept</param>
 /// <param name="dp">PhotonDataPoint</param>
 /// <returns>Updated SimulationStatistics</returns>
 public static SimulationStatistics TrackDeathStatistics(this SimulationStatistics statistics, PhotonDataPoint dp)
 {
     if (dp.StateFlag.HasFlag(PhotonStateType.PseudoReflectedTissueBoundary))
     {
         ++statistics.NumberOfPhotonsOutTopOfTissue;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.PseudoTransmittedTissueBoundary))
     {
         ++statistics.NumberOfPhotonsOutBottomOfTissue;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.Absorbed))
     {
         ++statistics.NumberOfPhotonsAbsorbed;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.PseudoSpecularTissueBoundary))
     {
         ++statistics.NumberOfPhotonsSpecularReflected;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.KilledOverMaximumCollisions))
     {
         ++statistics.NumberOfPhotonsKilledOverMaximumCollisions;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.KilledOverMaximumPathLength))
     {
         ++statistics.NumberOfPhotonsKilledOverMaximumPathLength;
     }
     if (dp.StateFlag.HasFlag(PhotonStateType.KilledRussianRoulette))
     {
         ++statistics.NumberOfPhotonsKilledByRussianRoulette;
     }
     return(statistics);
 }
Exemple #2
0
        public void execute_Monte_Carlo()
        {
            // delete any previously generated files and folders
            clear_folders_and_files();

            _input = new SimulationInput(
                10000, // number needed to get enough photons to Td
                "results",
                new SimulationOptions(
                    0,
                    RandomNumberGeneratorType.MersenneTwister,
                    AbsorptionWeightingType.Analog,
                    PhaseFunctionType.Bidirectional,
                    new List <DatabaseType>()
            {
            },            // databases to be written
                    true, // track statistics
                    0.0,  // RR threshold -> 0 = no RR performed
                    0),
                new DirectionalPointSourceInput(
                    new Position(0.0, 0.0, 0.0),
                    new Direction(0.0, 0.0, 1.0),
                    0
                    ),
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 0.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, _slabThickness),
                    new OpticalProperties(_mua, _musp, _g, 1.0)),         // index matched slab
                new LayerTissueRegion(
                    new DoubleRange(_slabThickness, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 0.0, 1.0))
            }
                    ),
                new List <IDetectorInput>()
            {
                new RDiffuseDetectorInput()
                {
                    TallySecondMoment = true
                },
                new ATotalDetectorInput()
                {
                    TallySecondMoment = true
                },
                new TDiffuseDetectorInput()
                {
                    TallySecondMoment = true
                }
            }
                );
            _output = new MonteCarloSimulation(_input).Run();

            _simulationStatistics = SimulationStatistics.FromFile(_input.OutputName + "/statistics.txt");
        }
Exemple #3
0
        public void execute_Monte_Carlo()
        {
            // delete any previously generated files
            clear_folders_and_files();

            _input = new SimulationInput(
                100,
                "Output",
                new SimulationOptions(
                    0,
                    RandomNumberGeneratorType.MersenneTwister,
                    AbsorptionWeightingType.Analog,
                    PhaseFunctionType.HenyeyGreenstein,
                    new List <DatabaseType>()
            {
            },            // databases to be written
                    true, // track statistics
                    0.0,  // RR threshold -> 0 = no RR performed
                    0),
                new DirectionalPointSourceInput(
                    new Position(0.0, 0.0, 0.0),
                    new Direction(0.0, 0.0, 1.0),
                    1 // start off inside tissue
                    ),
                new MultiLayerTissueInput(
                    new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 20.0),
                    new OpticalProperties(0.01, 1.0, 0.8, 1.4)),
                new LayerTissueRegion(
                    new DoubleRange(20.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                    ),
                new List <IDetectorInput>
            {
                new RDiffuseDetectorInput()
                {
                    TallySecondMoment = true
                },
                new ROfAngleDetectorInput()
                {
                    Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), TallySecondMoment = true
                },
                new ROfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(Math.PI / 2, Math.PI, 2)
                },
                new ROfRhoAndTimeDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101)
                },
                new ROfXAndYDetectorInput()
                {
                    X = new DoubleRange(-10.0, 10.0, 101), Y = new DoubleRange(-10.0, 10.0, 101)
                },
                new ROfRhoAndOmegaDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Omega = new DoubleRange(0.05, 1.0, 20)
                },                                                                                                                 // frequency sampling points (not bins)
                new TDiffuseDetectorInput(),
                new TOfAngleDetectorInput()
                {
                    Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new TOfRhoDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101)
                },
                new TOfRhoAndAngleDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Angle = new DoubleRange(0.0, Math.PI / 2, 2)
                },
                new AOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new ATotalDetectorInput(),
                new FluenceOfRhoAndZDetectorInput()
                {
                    Rho = new DoubleRange(0.0, 10.0, 101), Z = new DoubleRange(0.0, 10.0, 101)
                },
                new FluenceOfRhoAndZAndTimeDetectorInput()
                {
                    Rho  = new DoubleRange(0.0, 10.0, 101),
                    Z    = new DoubleRange(0.0, 10.0, 101),
                    Time = new DoubleRange(0.0, 1.0, 11)
                },
                new RadianceOfRhoAndZAndAngleDetectorInput()
                {
                    Rho   = new DoubleRange(0.0, 10.0, 101),
                    Z     = new DoubleRange(0.0, 10.0, 101),
                    Angle = new DoubleRange(-Math.PI / 2, Math.PI / 2, 5)
                }
            }
                );

            _output = new MonteCarloSimulation(_input).Run();

            _simulationStatistics = SimulationStatistics.FromFile(_input.OutputName + "/statistics.txt");

            _factor = 1.0 - Optics.Specular(
                _input.TissueInput.Regions[0].RegionOP.N,
                _input.TissueInput.Regions[1].RegionOP.N);
        }
Exemple #4
0
        public SimulationStatisticsTest()
        {
            var STATISTICS = "statistics";

            this.clusterNodes = new Mock <IClusterNodes>();
            this.log          = new Mock <ILogger>();
            this.simulationStatisticsStorage = new Mock <IStorageRecords>();
            this.factory = new Mock <IFactory>();
            this.config  = new Mock <IServicesConfig>();
            this.config.SetupGet(x => x.StatisticsStorage)
            .Returns(new StorageConfig {
                DocumentDbCollection = STATISTICS
            });

            this.simulationStatisticsStorage
            .Setup(x => x.Init(It.Is <StorageConfig>(c => c.DocumentDbCollection == STATISTICS)))
            .Returns(this.simulationStatisticsStorage.Object);
            this.factory.Setup(x => x.Resolve <IStorageRecords>()).Returns(this.simulationStatisticsStorage.Object);

            this.target = new SimulationStatistics(
                this.config.Object,
                this.clusterNodes.Object,
                this.factory.Object,
                this.log.Object);

            // Mock storage records
            this.storageRecords = new List <StorageRecord>
            {
                new StorageRecord
                {
                    Id   = $"{SIM_ID}__{NODE_IDS[0]}",
                    Data = JsonConvert.SerializeObject(
                        new SimulationStatisticsRecord
                    {
                        SimulationId = SIM_ID,
                        NodeId       = NODE_IDS[0],
                        Statistics   = new SimulationStatisticsModel
                        {
                            ActiveDevices                 = 5,
                            TotalMessagesSent             = 100,
                            FailedDeviceConnections       = 1,
                            FailedDevicePropertiesUpdates = 2,
                            FailedMessages                = 3
                        }
                    })
                },
                new StorageRecord
                {
                    Id   = $"{SIM_ID}__{NODE_IDS[1]}",
                    Data = JsonConvert.SerializeObject(
                        new SimulationStatisticsRecord
                    {
                        SimulationId = SIM_ID,
                        NodeId       = NODE_IDS[0],
                        Statistics   = new SimulationStatisticsModel
                        {
                            ActiveDevices                 = 10,
                            TotalMessagesSent             = 200,
                            FailedDeviceConnections       = 5,
                            FailedDevicePropertiesUpdates = 6,
                            FailedMessages                = 7
                        }
                    })
                },
            };
        }
        public SimulationStatisticsTest()
        {
            var STATISTICS = "statistics";

            this.clusterNodes = new Mock <IClusterNodes>();
            this.log          = new Mock <ILogger>();
            this.simulationStatisticsStorage = new Mock <IEngine>();
            this.enginesFactory = new Mock <IEngines>();
            this.config         = new Mock <IServicesConfig>();
            this.config.SetupGet(x => x.StatisticsStorage)
            .Returns(new Config {
                CosmosDbSqlCollection = STATISTICS
            });

            this.simulationStatisticsStorage
            .Setup(x => x.Init(It.Is <Config>(c => c.CosmosDbSqlCollection == STATISTICS)))
            .Returns(this.simulationStatisticsStorage.Object);
            this.simulationStatisticsStorage
            .Setup(x => x.BuildRecord(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string id, string json) => new DataRecord {
                Id = id, Data = json
            });

            this.enginesFactory.Setup(x => x.Build(It.IsAny <Config>()))
            .Returns(this.simulationStatisticsStorage.Object);

            this.target = new SimulationStatistics(
                this.config.Object,
                this.clusterNodes.Object,
                this.enginesFactory.Object,
                this.log.Object);

            // Mock storage records
            this.storageRecords = new List <IDataRecord>
            {
                new DataRecord
                {
                    Id   = $"{SIM_ID}__{NODE_IDS[0]}",
                    Data = JsonConvert.SerializeObject(
                        new SimulationStatisticsRecord
                    {
                        SimulationId = SIM_ID,
                        NodeId       = NODE_IDS[0],
                        Statistics   = new SimulationStatisticsModel
                        {
                            ActiveDevices                 = 5,
                            TotalMessagesSent             = 100,
                            FailedDeviceConnections       = 1,
                            FailedDevicePropertiesUpdates = 2,
                            FailedMessages                = 3
                        }
                    })
                },
                new DataRecord
                {
                    Id   = $"{SIM_ID}__{NODE_IDS[1]}",
                    Data = JsonConvert.SerializeObject(
                        new SimulationStatisticsRecord
                    {
                        SimulationId = SIM_ID,
                        NodeId       = NODE_IDS[1],
                        Statistics   = new SimulationStatisticsModel
                        {
                            ActiveDevices                 = 10,
                            TotalMessagesSent             = 200,
                            FailedDeviceConnections       = 5,
                            FailedDevicePropertiesUpdates = 6,
                            FailedMessages                = 7
                        }
                    })
                },
            };
        }