/// <summary> /// Define SimulationInput to describe homogeneous and two layer tissue /// </summary> /// <returns></returns> private void GenerateReferenceDatabase() { var simulationOptions = new SimulationOptions( 0, RandomNumberGeneratorType.MersenneTwister, AbsorptionWeightingType.Discrete, PhaseFunctionType.HenyeyGreenstein, new List <DatabaseType>() { DatabaseType.pMCDiffuseReflectance }, false, // track statistics 0.0, // RR threshold -> 0 = no RR performed 0); var sourceInput = new DirectionalPointSourceInput( new Position(0.0, 0.0, 0.0), new Direction(0.0, 0.0, 1.0), 1); var detectorInputs = new List <IDetectorInput>() { new ROfRhoDetectorInput() { Rho = new DoubleRange(0.0, 10.0, 101) }, new ROfRhoAndTimeDetectorInput() { Rho = new DoubleRange(0.0, 10.0, 101), Time = new DoubleRange(0.0, 1.0, 101) } }; _referenceInputTwoLayerTissue = new SimulationInput( 100, "", simulationOptions, sourceInput, new MultiLayerTissueInput( new ITissueRegion[] { new LayerRegion( new DoubleRange(double.NegativeInfinity, 0.0), new OpticalProperties(0.0, 1e-10, 1.0, 1.0)), new LayerRegion( new DoubleRange(0.0, _layerThickness), new OpticalProperties(0.01, 1.0, 0.8, 1.4)), new LayerRegion( new DoubleRange(_layerThickness, 20.0), new OpticalProperties(0.01, 1.0, 0.8, 1.4)), new LayerRegion( new DoubleRange(20.0, double.PositiveInfinity), new OpticalProperties(0.0, 1e-10, 1.0, 1.0)) } ), detectorInputs); _factor = 1.0 - Optics.Specular( _referenceInputTwoLayerTissue.TissueInput.Regions[0].RegionOP.N, _referenceInputTwoLayerTissue.TissueInput.Regions[1].RegionOP.N); _referenceOutputTwoLayerTissue = new MonteCarloSimulation(_referenceInputTwoLayerTissue).Run(); _databaseTwoLayerTissue = pMCDatabase.FromFile("DiffuseReflectanceDatabase", "CollisionInfoDatabase"); }
public void validate_only_one_perturbed_region_index_specified() { var tissueInput = new MultiLayerTissueInput(); var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), tissueInput, new List <IDetectorInput>() { new dMCdROfRhodMuaDetectorInput() { Rho = new DoubleRange(0.0, 100.0), // set perturbed ops to reference ops PerturbedOps = new List <OpticalProperties>() { tissueInput.Regions[0].RegionOP, tissueInput.Regions[1].RegionOP, tissueInput.Regions[2].RegionOP }, PerturbedRegionsIndices = new List <int>() { 1, 2 } } } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_top_and_bottom_layers_are_air() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), 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, 100.0), new OpticalProperties(0.01, 1.0, 0.8, 1.4)) } ), new List <IDetectorInput>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void initialize_simulation_input() { // create input with two tissue layers _input = new SimulationInput( 10, "Output", new SimulationOptions(), new DirectionalPointSourceInput(), 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, 1.0), new OpticalProperties(0.01, 1.0, 0.8, 1.4)), new LayerTissueRegion( new DoubleRange(1.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, 0.0, 1.0)) } ), new List <IDetectorInput> { new RDiffuseDetectorInput(), } ); }
public void validate_at_least_one_tissue_layer_defined() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), new SingleVoxelTissueInput( new VoxelTissueRegion(), 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, double.PositiveInfinity), new OpticalProperties(0.0, 1e-10, 1.0, 1.0)) } ), new List <IDetectorInput>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_voxel_has_nonzero_dimensions() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), new SingleVoxelTissueInput( // set ellipsoid axis to 0.0 new VoxelTissueRegion(new DoubleRange(0, 0), new DoubleRange(-10, 10), new DoubleRange(1, 5), new OpticalProperties()), 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>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_voxel_is_within_tissue_layer() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), new SingleVoxelTissueInput( new VoxelTissueRegion(new DoubleRange(-5, 5), new DoubleRange(-5, 5), new DoubleRange(0, 10), // eheck that voxel not at surface new OpticalProperties()), 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>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
private bool ShouldPressButton() { bool lightSignalOn = SimulationInput.PollBoolean(LightsKey); float carUnitOffset = Subscene.Vehicle.CarUnitOffset; if (lightSignalOn) { if (carUnitOffset > VehicleAgentController.ExitsTunnel && !ForgetsToTurnLightsOff) { return(true); } else { return(false); } } else { if (carUnitOffset > VehicleAgentController.EntersTunnelSoon && carUnitOffset < VehicleAgentController.ExitsTunnel) { return(true); } else { return(false); } } }
public static void RunSimulation(SimulationInput input, string outputFolderPath) { var mc = new MonteCarloSimulation(input); // locate root folder for output, creating it if necessary var path = string.IsNullOrEmpty(outputFolderPath) ? Path.GetFullPath(Directory.GetCurrentDirectory()) : Path.GetFullPath(outputFolderPath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // locate destination folder for output, creating it if necessary var resultsFolder = Path.Combine(path, input.OutputName); if (!Directory.Exists(resultsFolder)) { Directory.CreateDirectory(resultsFolder); } mc.SetOutputPathForDatabases(path); SimulationOutput detectorResults = mc.Run(); input.ToFile(Path.Combine(resultsFolder, input.OutputName + ".txt")); foreach (var result in detectorResults.ResultsDictionary.Values) { // save all detector data to the specified folder DetectorIO.WriteDetectorToFile(result, resultsFolder); } }
/// <summary> /// method to read the simulation input from a specified or default file /// </summary> public static SimulationInput ReadSimulationInputFromFile(string inputFile) { try { if (string.IsNullOrEmpty(inputFile)) { logger.Info(" *** No input file specified ***\n\nDefine an input file using mc.exe infile=infile_name.txt"); return(null); } //get the full path for the input file var fullFilePath = Path.GetFullPath(inputFile); string extension = Path.GetExtension(inputFile); if (File.Exists(fullFilePath)) { return(SimulationInput.FromFile(fullFilePath)); } if (File.Exists(fullFilePath + ".txt")) { return(SimulationInput.FromFile(fullFilePath + ".txt")); } //throw a file not found exception throw new FileNotFoundException("\nThe following input file could not be found: " + fullFilePath + " - type mc help=infile for correct syntax"); } catch (Exception e) { Console.WriteLine(e.Message); //Console.WriteLine(VtsJsonSerializer.TraceWriter.GetTraceMessages()); return(null); } }
/// <summary> /// constructor that load excitation simulation AOfRhoAndZ /// </summary> public AOfRhoAndZLoader(string inputFolder, string infile, int fluorescentTissueRegionIndex) { if (infile != "") { var inputPath = ""; if (inputFolder == "") { inputPath = infile; } else { inputPath = inputFolder + @"/" + infile; } var aOfRhoAndZDetector = (AOfRhoAndZDetector) DetectorIO.ReadDetectorFromFile( "AOfRhoAndZ", inputFolder); // use DoubleRange X,Y,Z to match detector dimensions Rho = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Rho; Z = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Z; AOfRhoAndZ = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Mean; var exciteInfile = SimulationInput.FromFile(inputPath); FluorescentTissueRegion = exciteInfile.TissueInput.Regions[fluorescentTissueRegionIndex]; // separate setup of arrays so can unit test method InitializeFluorescentRegionArrays(); SetupRegionIndices(); } else { throw new ArgumentException("infile string is empty"); } }
public void validate_layers_have_ZRange_Count_set_to_2() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), 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, 10.0) { Count = 10 }, new OpticalProperties(0.01, 1.0, 0.8, 1.4)), new LayerTissueRegion( new DoubleRange(10.0, double.PositiveInfinity), new OpticalProperties(0.0, 1e-10, 1.0, 1.0)) } ), new List <IDetectorInput>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_voxel_refractive_index_matches_that_of_surrounding_layer() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), new SingleVoxelTissueInput( new VoxelTissueRegion(new DoubleRange(-5, 5), new DoubleRange(-5, 5), new DoubleRange(1, 2), new OpticalProperties(0.01, 1.0, 0.9, 1.3)), 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>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_ellipsoid_is_within_tissue_layer() { var input = new SimulationInput( 10, "", new SimulationOptions(), new DirectionalPointSourceInput(), new SingleEllipsoidTissueInput( new EllipsoidTissueRegion(new Position(0, 0, 0), 1.0, 1.0, 1.0, new OpticalProperties()), 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>() { } ); var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void execute_Monte_Carlo() { // delete any previously generated files and folders clear_folders_and_files(); _input = new SimulationInput( 10000, // 1e4 needed to get enough photons to Td "results", new SimulationOptions( 0, RandomNumberGeneratorType.MersenneTwister, AbsorptionWeightingType.Continuous, 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( // debug layer // new DoubleRange(0.0, _topLayerThickness), // new OpticalProperties(_mua, _musp, _g, 1.0)), // index matched slab new LayerTissueRegion( new DoubleRange(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(); }
static void Main(string[] args) { var input = new SimulationInput(); SolverMGRTE.ExecuteMGRTE(input); Console.ReadLine(); }
/// <summary> /// Calculates the next simulation step. /// It will read the SimulationInput values and stores in the end the new values to the SimulationOutput. /// </summary> protected override void CalculateNextStep(int timeMs) { _topTrafficLight.SetToGreen(SimulationInput.PollBoolean(_topTrafficLightKey)); _botTrafficLight.SetToGreen(SimulationInput.PollBoolean(_botTrafficLightKey)); _trafficController.CalculateNextStep(timeMs); SimulationOutput.SetValue(_topTrafficSensorKey, _topTrafficLight.IsCarInRange()); SimulationOutput.SetValue(_botTrafficSensorKey, _botTrafficLight.IsCarInRange()); }
public void validate_deserialized_class_is_correct_when_using_FileIO() { new SimulationInput { N = 10 }.ToFile("test.txt"); var iCloned = SimulationInput.FromFile("test.txt"); Assert.AreEqual(iCloned.N, 10); }
private void UpdateInputs() { FieldGeneratorInput = SimulationInput.PollBoolean(FieldGeneratorKey); LaserInput = SimulationInput.PollBoolean(LaserKey); EmitterInput = SimulationInput.PollBoolean(EmitterKey); FocusInput = SimulationInput.PollBoolean(FocusKey); EmitterMotorInput = SimulationInput.PollInteger(EmitterMotorKey); FocusMotorInput = SimulationInput.PollInteger(FocusMotorKey); }
/// <summary> /// Creates an instance of PhotonDatabasePostProcessor for standard (photon) database processing /// </summary> /// <param name="virtualBoundaryType">virtual boundary type</param> /// <param name="detectorInputs">List of IDetectorInputs designating binning</param> /// <param name="photonDatabase">PhotonTerminationDatabase</param> /// <param name="databaseInput">Database information needed for post-processing</param> public PhotonDatabasePostProcessor( VirtualBoundaryType virtualBoundaryType, IList <IDetectorInput> detectorInputs, PhotonDatabase photonDatabase, SimulationInput databaseInput) : this(virtualBoundaryType, detectorInputs, databaseInput) { _photonDatabase = photonDatabase; _ispMCPostProcessor = false; }
public void validate_deserialized_class_is_correct() { var i = new SimulationInput { N = 10 }; var iCloned = i.Clone(); Assert.AreEqual(iCloned.N, 10); }
public SimulationOutput Post([FromBody] SimulationInput input) { var log = new DefaultLogService(); var output = Utilities.RunWithTimeLimit(() => Simulation.Simulate(input), Utilities.GetTimeLimitFromConfig()); if (output.ErrorMessages != null && output.ErrorMessages.Length > 0) { var contents = new LogContents(output.DebugMessages, output.ErrorMessages); faultLogger.Add(DateTime.Now, typeof(JobController).Assembly.GetName().Version.ToString(), input, contents); } return(output); }
public void validate_null_detector_input_is_invalid_when_no_database_specified() { // generate input without any detector inputs and no database specified var input = new SimulationInput() // default constructor has empty list of databases { DetectorInputs = new List <IDetectorInput> { } }; var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void validate_null_detector_input_gets_converted_to_empty_list_correctly() { var si = new SimulationInput( 100, "results", new SimulationOptions(), new Vts.MonteCarlo.Sources.DirectionalPointSourceInput(), new Vts.MonteCarlo.Tissues.MultiLayerTissueInput(), null ); Assert.IsTrue(si.DetectorInputs.Count == 0); }
public static IEnumerable <SimulationInput> ApplyParameterSweeps(SimulationInput input, IEnumerable <ParameterSweep> parameterSweeps) { IEnumerable <SimulationInput> batchInputs = input.AsEnumerable(); foreach (var parameterSweep in parameterSweeps) { var sweepValues = parameterSweep.Values.ToEnumerable <double>(); batchInputs = batchInputs.WithParameterSweep(sweepValues, parameterSweep.Name.ToLower()); } return(batchInputs.ToArray()); }
public SimulationInputViewModel(SimulationInput input) { _simulationInput = input; // use the property to invoke the appropriate change notification _simulationOptionsVM = new SimulationOptionsViewModel(_simulationInput.Options); _outputName = input.OutputName; #if WHITELIST TissueTypeVM = new OptionViewModel <string>("Tissue Type:", true, _simulationInput.TissueInput.TissueType, WhiteList.TissueTypes); #else TissueTypeVM = new OptionViewModel <string>("Tissue Type:", true, _simulationInput.TissueInput.TissueType, new[] { "MultiLayer", "SingleEllipsoid", "SingleVoxel" }); #endif UpdateTissueTypeVM(_simulationInput.TissueInput.TissueType); _simulationOptionsVM.PropertyChanged += (sender, args) => { if (_simulationOptionsVM.TrackStatistics && _simulationOptionsVM.OutputFolder != null) { _simulationInput.OutputName = Path.Combine(_simulationOptionsVM.OutputFolder, _outputName); } }; _tissueTypeVM.PropertyChanged += (sender, args) => { switch (_tissueTypeVM.SelectedValue) { case "MultiLayer": _simulationInput.TissueInput = new MultiLayerTissueInput(); break; case "SingleEllipsoid": _simulationInput.TissueInput = new SingleEllipsoidTissueInput(); break; case "SingleVoxel": _simulationInput.TissueInput = new SingleVoxelTissueInput(); break; default: throw new InvalidEnumArgumentException(StringLookup.GetLocalizedString("Error_NoTissueTypeExists")); } UpdateTissueTypeVM(_simulationInput.TissueInput.TissueType); }; UpdateTissueInputVM(_simulationInput.TissueInput); }
/// <summary> /// Initializes the whole page. Called before the node is added to the tree by the lesson controller. /// </summary> public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson) { _topTrafficLight = GetNode <TrafficControlSystem>("Signalisation/TrafficControlSystemTop"); _topTrafficLight.SetToGreen(SimulationInput.PollBoolean(_topTrafficLightKey)); _botTrafficLight = GetNode <TrafficControlSystem>("Signalisation/TrafficControlSystemBot"); _botTrafficLight.SetToGreen(SimulationInput.PollBoolean(_botTrafficLightKey)); PathController topPath = GetNode <PathController>("DynamicCars/TopPath"); topPath.Setup(_topTrafficLight); PathController botPath = GetNode <PathController>("DynamicCars/BotPath"); botPath.Setup(_botTrafficLight); _trafficController = new TrafficController(topPath, botPath); SpawnTimeGenerator.ResetGenerator(); }
public void validate_angled_source_and_cylindrical_detectors_are_not_defined_together() { // generate input with angled source and cylindrical detector var input = new SimulationInput() { SourceInput = new DirectionalPointSourceInput( new Position(0, 0, 0), new Direction(1.0 / Math.Sqrt(2), 0, 1.0 / Math.Sqrt(2)), 1), DetectorInputs = new List <IDetectorInput> { new ROfRhoDetectorInput() } }; var result = SimulationInputValidation.ValidateInput(input); Assert.IsFalse(result.IsValid); }
public void execute_Monte_Carlo() { // delete previously generated files clear_folders_and_files(); var input = new SimulationInput( 100, "Output", new SimulationOptions( 0, RandomNumberGeneratorType.MersenneTwister, AbsorptionWeightingType.Analog, PhaseFunctionType.HenyeyGreenstein, new List <DatabaseType>() { }, // databases to be written false, // 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 // start in air ), 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 RSpecularDetectorInput(), } ); _specularReflectance = Optics.Specular(input.TissueInput.Regions[0].RegionOP.N, input.TissueInput.Regions[1].RegionOP.N); _output = new MonteCarloSimulation(input).Run(); }
public void validate_dependencies_can_be_constructed_by_providers() { var si = new SimulationInput( 100, "results", new SimulationOptions(), SourceInputProvider.DirectionalPointSourceInput(), TissueInputProvider.MultiLayerTissueInput(), new[] { DetectorInputProvider.RDiffuseDetectorInput() } ); Assert.NotNull(si.SourceInput); Assert.NotNull(si.TissueInput); Assert.NotNull(si.DetectorInputs); Assert.IsTrue(si.DetectorInputs.Count == 1); }