Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13 rfx tallies assume a homogeneous or layered tissue geometry #162

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fdb09c8
Modified the SimulationInputValidation code to allow user specifying …
hayakawa16 Sep 13, 2023
59f858b
Some more code cleanup.
hayakawa16 Sep 15, 2023
1634d11
Merge branch 'master' into 13-rfx-tallies-assume-a-homogeneous-or-lay…
hayakawa16 Nov 3, 2023
277b131
Merge branch 'master' into 13-rfx-tallies-assume-a-homogeneous-or-lay…
hayakawa16 Jan 11, 2024
868bad9
Merge branch 'master' into 13-rfx-tallies-assume-a-homogeneous-or-lay…
hayakawa16 Apr 17, 2024
6443ae1
Merge branch 'master' into 13-rfx-tallies-assume-a-homogeneous-or-lay…
hayakawa16 Aug 8, 2024
0b3839f
Modified validation code check of non-layered or non-homogeneous tiss…
hayakawa16 Aug 8, 2024
2b8a37c
Merge branch 'master' into 13-rfx-tallies-assume-a-homogeneous-or-lay…
hayakawa16 Aug 8, 2024
5306b4a
Downgraded three more validation checks from an exception that stops …
hayakawa16 Aug 8, 2024
9331e5a
Found another validation check that could be downgraded to warning. …
hayakawa16 Aug 8, 2024
89e1b62
Modfied one of the floating point comparisons using a range. The oth…
hayakawa16 Aug 22, 2024
08b3354
Fixed unused usings, code cleanup, cognitive complexity in one place …
hayakawa16 Aug 22, 2024
ecc056f
Reduced complexity some more. Gave in and modified floating point ch…
hayakawa16 Aug 22, 2024
08daa7a
Reduced complexity in another place.
hayakawa16 Aug 22, 2024
16412e2
Reduced complexity some more. And renamed Incapabilities to Capabili…
hayakawa16 Aug 22, 2024
b084325
Added unit test for existing code that wasn't covered before.
hayakawa16 Aug 23, 2024
db40c98
Added more unit tests
hayakawa16 Aug 23, 2024
648b186
Removed unused usings. Wrote more unit tests.
hayakawa16 Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Vts.Common;
using Vts.Modeling.ForwardSolvers;
using Vts.MonteCarlo;
using Vts.MonteCarlo.Detectors;
using Vts.MonteCarlo.Sources;
Expand All @@ -12,133 +14,237 @@ namespace Vts.Test.MonteCarlo.DataStructuresValidation
[TestFixture]
public class SimulationInputValidationTests
{
/// <summary>
/// Test to verify input with no detectors nor database specified is invalid
/// </summary>
[Test]
public void validate_null_detector_input_is_invalid_when_no_database_specified()
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> {}
DetectorInputs = new List<IDetectorInput>()
};
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
}

/// <summary>
/// Test to verify input with database specified and no detectors specified is valid
/// </summary>
[Test]
public void validate_null_detector_input_is_valid_when_database_specified()
public void Validate_null_detector_input_is_valid_when_database_specified()
{
// generate input without any detector inputs but with database specified
var input = new SimulationInput()
var input = new SimulationInput
{
DetectorInputs = new List<IDetectorInput> {}
DetectorInputs = new List<IDetectorInput>(),
Options =
{
Databases = new List<DatabaseType> {DatabaseType.DiffuseReflectance}
}
};
input.Options.Databases = new List<DatabaseType> {DatabaseType.DiffuseReflectance};
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsTrue(result.IsValid);
}

/// <summary>
/// Test to verify input with detector, Radiance(x,y,z,theta,phi) and CAW is invalid
/// because not implemented
/// </summary>
[Test]
public void validate_detector_input_not_implemented_is_invalid()
public void Validate_detector_input_not_implemented_is_invalid()
{
// generate input with detector input not implemented yet
var input = new SimulationInput()
var input = new SimulationInput
{
Options = new SimulationOptions() { AbsorptionWeightingType = AbsorptionWeightingType.Continuous},
Options = new SimulationOptions { AbsorptionWeightingType = AbsorptionWeightingType.Continuous},
DetectorInputs = new List<IDetectorInput> { new RadianceOfXAndYAndZAndThetaAndPhiDetectorInput()}
};
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
}

/// <summary>
/// Test to verify that input with two detectors with the same Name is invalid
/// </summary>
[Test]
public void validate_duplicate_detector_name_is_invalid()
public void Validate_duplicate_detector_name_is_invalid()
{
// generate input with detector input with duplicate names
var input = new SimulationInput()
var input = new SimulationInput
{
DetectorInputs = new List<IDetectorInput> {
new ROfRhoDetectorInput() {Name = "ROfRho1"},
new ROfRhoDetectorInput() {Name = "ROfRho1"}
new ROfRhoDetectorInput {Name = "ROfRho1"},
new ROfRhoDetectorInput {Name = "ROfRho1"}
}
};
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
}

/// <summary>
/// Test to verify input with cylindrical detector and off axis ellipsoid in tissue outputs warning
/// but continues as valid input
/// </summary>
[Test]
public void validate_ellipsoid_tissue_with_off_zaxis_center_and_cylindrical_detectors_are_not_defined_together()
public void Validate_ellipsoid_tissue_with_off_zaxis_center_and_cylindrical_detectors_issues_warning()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
var input = new SimulationInput
{
TissueInput = new SingleEllipsoidTissueInput()
TissueInput = new SingleEllipsoidTissueInput
{
EllipsoidRegion = new EllipsoidTissueRegion() {Center = new Position(1, 1, 0)}
EllipsoidRegion = new EllipsoidTissueRegion {Center = new Position(1, 1, 5)}
},
DetectorInputs = new List<IDetectorInput> {new ROfRhoDetectorInput()}
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: off center ellipsoid in tissue with cylindrical detector defined: user discretion advised\r\n"));
}

/// <summary>
/// Test to verify input cylindrical detector and ellipsoid in tissue issues warning
/// but continues as valid input
/// </summary>
[Test]
public void validate_ellipsoid_tissue_without_cylindrical_symmetry_and_cylindrical_detectors_are_not_defined_together()
public void Validate_ellipsoid_tissue_without_cylindrical_symmetry_and_cylindrical_detectors_issues_warning()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
var input = new SimulationInput
{
TissueInput = new SingleEllipsoidTissueInput()
TissueInput = new SingleEllipsoidTissueInput
{
EllipsoidRegion = new EllipsoidTissueRegion() { Dx = 1.0, Dy = 2.0 }
EllipsoidRegion = new EllipsoidTissueRegion { Dx = 1.0, Dy = 2.0 }
},
DetectorInputs = new List<IDetectorInput> { new ROfRhoDetectorInput() }
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: ellipsoid with Dx != Dy in tissue with cylindrical detector defined: user discretion advised\r\n"));
}

/// <summary>
/// Test to verify input cylindrical detector and voxel in tissue issues warning
/// but continues as valid input
/// </summary>
[Test]
public void validate_angled_source_and_cylindrical_detectors_are_not_defined_together()
public void Validate_voxel_tissue_and_cylindrical_detectors_issues_warning()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput
{
TissueInput = new SingleVoxelTissueInput
{
VoxelRegion = new VoxelTissueRegion
{
X = new DoubleRange(-1.0, 1.0, 2),
Y = new DoubleRange(-1.0, 1.0,2),
Z = new DoubleRange(0.01, 1, 2)
}
},
DetectorInputs = new List<IDetectorInput> { new ROfRhoDetectorInput() }
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: voxel in tissue with cylindrical detector defined: user discretion advised\r\n"));
}

/// <summary>
/// Test to verify input with angled source and cylindrical detectors outputs warning
/// but continues as valid input
/// </summary>
[Test]
public void Validate_angled_source_and_cylindrical_detectors_are_not_defined_together()
{
// generate input with angled source and cylindrical detector
var input = new SimulationInput()
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() }
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: Angled source and cylindrical coordinate detector defined: user discretion advised\r\n"));
}

/// <summary>
/// Test to verify input with ellipsoid in tissue and R(fx) detector outputs warning
/// but continues as valid input
/// </summary>
[Test]
public void validate_ellipsoid_tissue_and_ROfFx_detectors_are_not_defined_together()
public void Validate_ellipsoid_tissue_and_ROfFx_detectors_defined_together_issues_warning()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
var input = new SimulationInput
{
TissueInput = new SingleEllipsoidTissueInput()
TissueInput = new SingleEllipsoidTissueInput
{
EllipsoidRegion = new EllipsoidTissueRegion() { Dx = 1.0, Dy = 2.0 }
EllipsoidRegion = new EllipsoidTissueRegion { Dx = 1.0, Dy = 2.0 }
},
DetectorInputs = new List<IDetectorInput> { new ROfFxDetectorInput() }
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry: user discretion advised\r\n"));
}

/// <summary>
/// Test to verify input with voxel in tissue and R(fx) detector outputs warning
/// but continues as valid input
/// </summary>
[Test]
public void validate_voxel_tissue_and_ROfFx_detectors_are_not_defined_together()
public void Validate_voxel_tissue_and_ROfFx_detectors_defined_together_issues_warning()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
var input = new SimulationInput
{
TissueInput = new SingleVoxelTissueInput()
TissueInput = new SingleVoxelTissueInput
{
VoxelRegion = new VoxelTissueRegion()
// make sure voxel defined so validation doesn't error on voxel geometry
VoxelRegion = new VoxelTissueRegion
{
X = new DoubleRange(-5,5,2),
Y = new DoubleRange(-5,5,2),
Z = new DoubleRange(1,6,2)
}
},
DetectorInputs = new List<IDetectorInput> { new ROfFxDetectorInput() }
};
// set to catch Console output
var output = new StringWriter();
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.IsValid); // only warning
Assert.That(output.ToString(), Is.EqualTo("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry: user discretion advised\r\n"));

}

/// <summary>
/// Test to verify input with negative optical properties is invalid
/// </summary>
[Test]
public void validate_tissue_optical_properties_are_non_negative()
public void Validate_tissue_optical_properties_are_non_negative()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
var input = new SimulationInput
{
TissueInput = new MultiLayerTissueInput(
new ITissueRegion[]
Expand Down
Loading
Loading