public void validate_FluenceOfRhoAndZAndTime_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testfluenceofrhoandzandtime"; IDetectorInput detectorInput = new FluenceOfRhoAndZAndTimeDetectorInput() { Rho = new DoubleRange(0, 10, 3), Z = new DoubleRange(0, 10, 3), Time = new DoubleRange(0, 1, 4), TallySecondMoment = true, Name = detectorName, }; var detector = (FluenceOfRhoAndZAndTimeDetector)detectorInput.CreateDetector(); detector.Mean = new double[, , ] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (FluenceOfRhoAndZAndTimeDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0, 0, 0], 1); Assert.AreEqual(dcloned.Mean[0, 0, 1], 2); Assert.AreEqual(dcloned.Mean[0, 0, 2], 3); Assert.AreEqual(dcloned.Mean[0, 1, 0], 4); Assert.AreEqual(dcloned.Mean[0, 1, 1], 5); Assert.AreEqual(dcloned.Mean[0, 1, 2], 6); Assert.AreEqual(dcloned.Mean[1, 0, 0], 7); Assert.AreEqual(dcloned.Mean[1, 0, 1], 8); Assert.AreEqual(dcloned.Mean[1, 0, 2], 9); Assert.AreEqual(dcloned.Mean[1, 1, 0], 10); Assert.AreEqual(dcloned.Mean[1, 1, 1], 11); Assert.AreEqual(dcloned.Mean[1, 1, 2], 12); }
/// <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_pMCROfRhoDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testpmcrofrho"; IDetectorInput detectorInput = new pMCROfRhoDetectorInput() { Rho = new DoubleRange(0, 10, 4), PerturbedOps = new List <OpticalProperties>() { new OpticalProperties() }, PerturbedRegionsIndices = new List <int>() { 1 }, TallySecondMoment = true, // tally SecondMoment Name = detectorName, }; var detector = (pMCROfRhoDetector)detectorInput.CreateDetector(); detector.Mean = new double[] { 100, 200, 300 }; detector.SecondMoment = new double[] { 50, 150, 250 }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (pMCROfRhoDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); // ckh: not sure how I would read in 2nd moment data in detector + "_2" Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0], 100); Assert.AreEqual(dcloned.Mean[1], 200); Assert.AreEqual(dcloned.Mean[2], 300); }
public void validate_pMCROfRhoAndTimeDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testpmcrofrhoandtime"; IDetectorInput detectorInput = new pMCROfRhoAndTimeDetectorInput() { Rho = new DoubleRange(0, 10, 3), Time = new DoubleRange(0, 1, 4), PerturbedOps = new List <OpticalProperties>() { new OpticalProperties() }, PerturbedRegionsIndices = new List <int>() { 1 }, TallySecondMoment = true, // tally SecondMoment Name = detectorName, }; var detector = (pMCROfRhoAndTimeDetector)detectorInput.CreateDetector(); detector.Mean = new double[, ] { { 1, 2, 3 }, { 4, 5, 6 } }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (pMCROfRhoAndTimeDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0, 0], 1); Assert.AreEqual(dcloned.Mean[0, 1], 2); Assert.AreEqual(dcloned.Mean[0, 2], 3); Assert.AreEqual(dcloned.Mean[1, 0], 4); Assert.AreEqual(dcloned.Mean[1, 1], 5); Assert.AreEqual(dcloned.Mean[1, 2], 6); }
public void validate_AOfRhoAndZDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testaofrhoandz"; IDetectorInput detectorInput = new AOfRhoAndZDetectorInput() { Rho = new DoubleRange(0, 10, 3), Z = new DoubleRange(0, 1, 4), TallySecondMoment = false, Name = detectorName, }; var detector = (AOfRhoAndZDetector)detectorInput.CreateDetector(); detector.Mean = new double[, ] { { 1, 2, 3 }, { 4, 5, 6 } }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (AOfRhoAndZDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0, 0], 1); Assert.AreEqual(dcloned.Mean[0, 1], 2); Assert.AreEqual(dcloned.Mean[0, 2], 3); Assert.AreEqual(dcloned.Mean[1, 0], 4); Assert.AreEqual(dcloned.Mean[1, 1], 5); Assert.AreEqual(dcloned.Mean[1, 2], 6); }
public void validate_TDiffuseDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testtdiffuse"; IDetectorInput detectorInput = new TDiffuseDetectorInput() { TallySecondMoment = false, Name = detectorName }; var detector = (TDiffuseDetector)detectorInput.CreateDetector(); detector.Mean = 100; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (TDiffuseDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean, 100); }
/// <summary> /// constructor that load excitation simulation AOfXAndYAndZ /// </summary> public AOfXAndYAndZLoader(string inputFolder, string infile, int fluorescentTissueRegionIndex) { if (infile != "") { var inputPath = ""; if (inputFolder == "") { inputPath = infile; } else { inputPath = inputFolder + @"/" + infile; } var aOfXAndYAndZDetector = (AOfXAndYAndZDetector)DetectorIO.ReadDetectorFromFile( "AOfXAndYAndZ", inputFolder); // use DoubleRange X,Y,Z to match detector dimensions X = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).X; Y = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Y; Z = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Z; AOfXAndYAndZ = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Mean; var exciteInfile = SimulationInput.FromFile(inputPath); FluorescentTissueRegion = exciteInfile.TissueInput.Regions[fluorescentTissueRegionIndex]; BoundedTissueRegion = null; // check if tissue bounded CH: can this be made more generic? if (exciteInfile.TissueInput.TissueType == "BoundingCylinder") { var cylinderIndex = exciteInfile.TissueInput.Regions.Length - 1; CaplessCylinderTissueRegion boundingCylinder = (CaplessCylinderTissueRegion)exciteInfile.TissueInput.Regions[cylinderIndex]; BoundedTissueRegion = new CaplessCylinderTissueRegion( boundingCylinder.Center, boundingCylinder.Radius, boundingCylinder.Height, boundingCylinder.RegionOP); } // separate setup of arrays so can unit test method InitializeFluorescentRegionArrays(); SetupRegionIndices(); } else { throw new ArgumentException("infile string is empty"); } }
public void validate_ROfRhoDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testrofrho"; IDetectorInput detectorInput = new ROfRhoDetectorInput() { Rho = new DoubleRange(0, 10, 4), TallySecondMoment = false, Name = detectorName }; var detector = (ROfRhoDetector)detectorInput.CreateDetector(); detector.Mean = new double[] { 100, 200, 300 }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (ROfRhoDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0], 100); Assert.AreEqual(dcloned.Mean[1], 200); Assert.AreEqual(dcloned.Mean[2], 300); }
public void validate_RDiffuseDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testrdiffuse"; IDetectorInput detectorInput = new RDiffuseDetectorInput() { TallySecondMoment = true, Name = detectorName }; var detector = (RDiffuseDetector)detectorInput.CreateDetector(); detector.Mean = 100; detector.SecondMoment = 50; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (RDiffuseDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean, 100); Assert.AreEqual(dcloned.SecondMoment, 50); // 0D detectors 2nd moment written to .txt file }
public void validate_output_folders_and_files_correct_when_using_geninfile_infile() { string[] arguments = new string[] { "infile=infile_PostProcessor_pMC_ROfRhoROfRhoAndTime.txt" }; Program.Main(arguments); Assert.IsTrue(Directory.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime")); // verify infile gets written to output folder Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/PostProcessor_pMC_ROfRhoROfRhoAndTime.txt")); // verify detectors specified in MCPP infile get written Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoReference.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoReference")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoReference_2")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus1p5.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus1p5")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus1p5_2")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus0p5.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus0p5")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRho_mus0p5_2")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoAndTime_mus1p5.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoAndTime_mus1p5")); Assert.IsFalse(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/pMCROfRhoAndTime_mus1p5_2")); // added regular detectors into this infile in PPInputProvider -> verify they are there Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/ROfRho.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/ROfRho")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/ROfRhoAndTime.txt")); Assert.IsTrue(File.Exists("PostProcessor_pMC_ROfRhoROfRhoAndTime/ROfRhoAndTime")); // check that can read detectors in var readDetector = DetectorIO.ReadDetectorFromFile( "pMCROfRhoReference", "PostProcessor_pMC_ROfRhoROfRhoAndTime"); Assert.IsInstanceOf <IDetector>(readDetector); readDetector = DetectorIO.ReadDetectorFromFile( "pMCROfRhoAndTime_mus1p5", "PostProcessor_pMC_ROfRhoROfRhoAndTime"); Assert.IsInstanceOf <IDetector>(readDetector); readDetector = DetectorIO.ReadDetectorFromFile( "ROfRho", "PostProcessor_pMC_ROfRhoROfRhoAndTime"); Assert.IsInstanceOf <IDetector>(readDetector); readDetector = DetectorIO.ReadDetectorFromFile( "ROfRhoAndTime", "PostProcessor_pMC_ROfRhoROfRhoAndTime"); Assert.IsInstanceOf <IDetector>(readDetector); }
public void validate_ROfRhoAndOmegaDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testrofrhoandomega"; IDetectorInput detectorInput = new ROfRhoAndOmegaDetectorInput() { Rho = new DoubleRange(0, 10, 3), Omega = new DoubleRange(0, 1, 4), TallySecondMoment = true, // tally Second Moment Name = detectorName, }; var detector = (ROfRhoAndOmegaDetector)detectorInput.CreateDetector(); detector.Mean = new Complex[, ] { { 1 + Complex.ImaginaryOne * 1, 2 + Complex.ImaginaryOne * 2, 3 + Complex.ImaginaryOne * 3, 4 + Complex.ImaginaryOne * 4 }, { 5 + Complex.ImaginaryOne * 5, 6 + Complex.ImaginaryOne * 6, 7 + Complex.ImaginaryOne * 7, 8 + Complex.ImaginaryOne * 8 } }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (ROfRhoAndOmegaDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0, 0], 1 + Complex.ImaginaryOne * 1); Assert.AreEqual(dcloned.Mean[0, 1], 2 + Complex.ImaginaryOne * 2); Assert.AreEqual(dcloned.Mean[0, 2], 3 + Complex.ImaginaryOne * 3); Assert.AreEqual(dcloned.Mean[0, 3], 4 + Complex.ImaginaryOne * 4); Assert.AreEqual(dcloned.Mean[1, 0], 5 + Complex.ImaginaryOne * 5); Assert.AreEqual(dcloned.Mean[1, 1], 6 + Complex.ImaginaryOne * 6); Assert.AreEqual(dcloned.Mean[1, 2], 7 + Complex.ImaginaryOne * 7); Assert.AreEqual(dcloned.Mean[1, 3], 8 + Complex.ImaginaryOne * 8); }
public void demonstrate_user_defined_detector_usage() { DetectorFactory.RegisterDetector(typeof(ROfXDetectorInput), typeof(ROfXDetector)); var detectorInput = new ROfXDetectorInput { TallyType = "ROfX", Name = "My First R(x) Detector", TallySecondMoment = true, X = new DoubleRange(0, 10, 101), }; var simInput = new SimulationInput { DetectorInputs = new[] { detectorInput }, N = 100, }; var sim = simInput.CreateSimulation(); var results = sim.Run(); IDetector detector; var detectorExists = results.ResultsDictionary.TryGetValue(detectorInput.Name, out detector); Assert.IsTrue(detectorExists); var firstValue = ((ROfXDetector)detector).Mean.FirstOrDefault(); Assert.IsTrue(firstValue != 0); DetectorIO.WriteDetectorToFile(detector, "user_defined_detector"); var deserializedDetector = DetectorIO.ReadDetectorFromFile("user_defined_detector", ""); }
public void validate_ReflectedMTOfRhoAndSubregionHistDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile() { string detectorName = "testreflectedmtofrhoandsubregionhist"; var tissue = new MultiLayerTissue( 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.7, 1.33)), new LayerTissueRegion( new DoubleRange(100.0, double.PositiveInfinity), new OpticalProperties(0.0, 1e-10, 1.0, 1.0)) } ); IDetectorInput detectorInput = new ReflectedMTOfRhoAndSubregionHistDetectorInput() { Rho = new DoubleRange(0, 10, 3), MTBins = new DoubleRange(0, 10, 3), FractionalMTBins = new DoubleRange(0, 1, 2), TallySecondMoment = true, // tally SecondMoment Name = detectorName, }; var detector = (ReflectedMTOfRhoAndSubregionHistDetector)detectorInput.CreateDetector(); // need to initialize detector so that NumSubregions gets set detector.Initialize(tissue, null); // Mean has dimensions [Rho.Count - 1, MTBins.Count - 1] detector.Mean = new double[, ] { { 1, 2 }, { 3, 4 } }; // FractionalMT has dimensions [Rho.Count - 1, MTBins.Count - 1, NumSubregions, FractionalMTBins.Count + 1]=[2,2,3,3] detector.FractionalMT = new double[, , , ] { { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } } }, { { { 19, 20, 21 }, { 22, 23, 24 }, { 25, 26, 27 } }, { { 28, 29, 30 }, { 31, 32, 33 }, { 34, 35, 36 } } } }; DetectorIO.WriteDetectorToFile(detector, ""); var dcloned = (ReflectedMTOfRhoAndSubregionHistDetector)DetectorIO.ReadDetectorFromFile(detectorName, ""); Assert.AreEqual(dcloned.Name, detectorName); Assert.AreEqual(dcloned.Mean[0, 0], 1); Assert.AreEqual(dcloned.Mean[0, 1], 2); Assert.AreEqual(dcloned.Mean[1, 0], 3); Assert.AreEqual(dcloned.Mean[1, 1], 4); Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 0], 1); Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 1], 2); Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 2], 3); Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 0], 4); Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 1], 5); Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 2], 6); Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 0], 7); Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 1], 8); Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 2], 9); Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 0], 10); Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 1], 11); Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 2], 12); Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 0], 13); Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 1], 14); Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 2], 15); Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 0], 16); Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 1], 17); Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 2], 18); Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 0], 19); Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 1], 20); Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 2], 21); Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 0], 22); Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 1], 23); Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 2], 24); Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 0], 25); Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 1], 26); Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 2], 27); Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 0], 28); Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 1], 29); Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 2], 30); Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 0], 31); Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 1], 32); Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 2], 33); Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 0], 34); Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 1], 35); Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 2], 36); }