Skip to content

Commit

Permalink
Renamed VirtualBoundaryType.Dosimetry to VirtualBoundaryType.Internal…
Browse files Browse the repository at this point in the history
…Surface to be more general. I thought this change had been before. Code clean up for PR files. Since most of Vts.Test/MonteCarlo/Tissue were cleaned up, cleaned up all. Need to do another pass.
  • Loading branch information
hayakawa16 committed Aug 28, 2023
1 parent 6f2ae02 commit f766756
Show file tree
Hide file tree
Showing 45 changed files with 536 additions and 510 deletions.
428 changes: 218 additions & 210 deletions src/Vts.Test/MonteCarlo/Detectors/DetectorNATests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public class InclusionWithRefractiveIndexMismatchTests
/// <summary>
/// list of temporary files created by these unit tests
/// </summary>
List<string> listOfTestGeneratedFiles = new List<string>()
readonly List<string> _listOfTestGeneratedFiles = new List<string>()
{
"file.txt", // file that captures screen output of MC simulation
};
[OneTimeTearDown]
public void clear_folders_and_files()
public void Clear_folders_and_files()
{
foreach (var file in listOfTestGeneratedFiles)
foreach (var file in _listOfTestGeneratedFiles)
{
FileIO.FileDelete(file);
}
Expand All @@ -44,10 +44,10 @@ public void clear_folders_and_files()
/// SingleInclusionTissue with InfiniteCylinderTissueRegion
/// </summary>
[OneTimeSetUp]
public void execute_Monte_Carlo()
public void Execute_Monte_Carlo()
{
// delete previously generated files
clear_folders_and_files();
Clear_folders_and_files();

// instantiate common classes
var simulationOptions = new SimulationOptions(
Expand Down Expand Up @@ -106,7 +106,7 @@ public void execute_Monte_Carlo()
1, // radius
new OpticalProperties(0.01, 1.0, 0.8, 1.4)
),
new LayerTissueRegion[]
new ITissueRegion[]
{
new LayerTissueRegion(
new DoubleRange(double.NegativeInfinity, 0.0),
Expand All @@ -133,7 +133,7 @@ public void execute_Monte_Carlo()
1, // radius
new OpticalProperties(0.01, 1.0, 0.8, 1.5) // mismatched n=1.5
),
new LayerTissueRegion[]
new ITissueRegion[]
{
new LayerTissueRegion(
new DoubleRange(double.NegativeInfinity, 0.0),
Expand All @@ -159,47 +159,47 @@ public void execute_Monte_Carlo()

// Diffuse Reflectance
[Test]
public void validate_DAW_voxel_RDiffuse()
public void Validate_DAW_voxel_RDiffuse()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.Rd * _factor - 0.565017749), 0.000000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.Rd * _factor - 0.565017749), 0.000000001);
Assert.Less(Math.Abs(_outputTwoRegionMismatchedTissue.Rd - 0.585135), 0.000001);
}
// Reflection R(angle)
[Test]
public void validate_DAW_voxel_ROfAngle()
public void Validate_DAW_voxel_ROfAngle()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.R_a[0] * _factor - 0.0809612757), 0.0000000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.R_a[0] * _factor - 0.0809612757), 0.0000000001);
Assert.Less(Math.Abs(_outputTwoRegionMismatchedTissue.R_a[0] - 0.083843), 0.000001);
}
// Diffuse Transmittance
[Test]
public void validate_DAW_voxel_TDiffuse()
public void Validate_DAW_voxel_TDiffuse()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.Td * _factor - 0.0228405921), 0.000000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.Td * _factor - 0.0228405921), 0.000000001);
Assert.Less(Math.Abs(_outputTwoRegionMismatchedTissue.Td - 0.028486), 0.000001);
}
// Transmittance Time(angle)
[Test]
public void validate_DAW_voxel_TOfAngle()
public void Validate_DAW_voxel_TOfAngle()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.T_a[0] * _factor - 0.00327282369), 0.00000000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.T_a[0] * _factor - 0.00327282369), 0.00000000001);
Assert.Less(Math.Abs(_outputTwoRegionMismatchedTissue.T_a[0] - 0.004081), 0.000001);
}
// Reflectance R(x,y)
[Test]
public void validate_DAW_voxel_ROfXAndY()
public void Validate_DAW_voxel_ROfXAndY()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.R_xy[198, 201] * _factor - 0.00825301), 0.00000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.R_xy[198, 201] * _factor - 0.00825301), 0.00000001);
Assert.Less(Math.Abs(_outputTwoRegionMismatchedTissue.R_xy[198, 201] - 0.00), 0.000001);
}
// Total Absorption
[Test]
public void validate_DAW_voxel_ATotal()
public void Validate_DAW_voxel_ATotal()
{
Assert.Less(Math.Abs(_outputOneRegionTissue.Atot * _factor - 0.384363881), 0.000000001);
Assert.Less(Math.Abs(_outputTwoRegionMatchedTissue.Atot * _factor - 0.384363881), 0.000000001);
Expand All @@ -208,7 +208,7 @@ public void validate_DAW_voxel_ATotal()

// sanity checks
[Test]
public void validate_DAW_voxel_RDiffuse_plus_ATotal_plus_TDiffuse_equals_one()
public void Validate_DAW_voxel_RDiffuse_plus_ATotal_plus_TDiffuse_equals_one()
{
// no specular because photons started inside tissue
Assert.Less(Math.Abs(_outputOneRegionTissue.Rd +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Validate_IsSurfaceBoundary_returns_correct_value()
Assert.IsTrue(virtualBoundaryType.IsSurfaceVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.pMCDiffuseReflectance;
Assert.IsTrue(virtualBoundaryType.IsSurfaceVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.Dosimetry;
virtualBoundaryType = VirtualBoundaryType.InternalSurface;
Assert.IsTrue(virtualBoundaryType.IsSurfaceVirtualBoundary());
// validate those that are false
virtualBoundaryType = VirtualBoundaryType.GenericVolumeBoundary;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void Validate_IsVolumeBoundary_returns_correct_value()
Assert.IsFalse(virtualBoundaryType.IsVolumeVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.pMCDiffuseReflectance;
Assert.IsFalse(virtualBoundaryType.IsVolumeVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.Dosimetry;
virtualBoundaryType = VirtualBoundaryType.InternalSurface;
Assert.IsFalse(virtualBoundaryType.IsVolumeVirtualBoundary());
// check if enum set to something out of range
virtualBoundaryType = (VirtualBoundaryType)Enum.GetNames(typeof(VirtualBoundaryType)).Length + 1;
Expand Down Expand Up @@ -117,21 +117,21 @@ public void Validate_IsSpecularSurfaceVirtualBoundary_returns_correct_value()
() => virtualBoundaryType.IsSpecularSurfaceVirtualBoundary());
}
/// <summary>
/// Validate method IsDosimetryVirtualBoundary
/// Validate method IsInternalSurfaceVirtualBoundary
/// </summary>
[Test]
public void Validate_IsDosimetryVirtualBoundary_returns_correct_value()
public void Validate_IsInternalSurfaceVirtualBoundary_returns_correct_value()
{
// validate those that are true
var virtualBoundaryType = VirtualBoundaryType.Dosimetry;
Assert.IsTrue(virtualBoundaryType.IsDosimetryVirtualBoundary());
var virtualBoundaryType = VirtualBoundaryType.InternalSurface;
Assert.IsTrue(virtualBoundaryType.IsInternalSurfaceVirtualBoundary());
// validate one that is false
virtualBoundaryType = VirtualBoundaryType.pMCDiffuseReflectance;
Assert.IsFalse(virtualBoundaryType.IsDosimetryVirtualBoundary());
Assert.IsFalse(virtualBoundaryType.IsInternalSurfaceVirtualBoundary());
// check if enum set to something out of range
virtualBoundaryType = (VirtualBoundaryType)Enum.GetNames(typeof(VirtualBoundaryType)).Length + 1;
Assert.Throws<ArgumentOutOfRangeException>(
() => virtualBoundaryType.IsDosimetryVirtualBoundary());
() => virtualBoundaryType.IsInternalSurfaceVirtualBoundary());
}
/// <summary>
/// Validate method IsGenericVolumeVirtualBoundary
Expand Down Expand Up @@ -166,7 +166,7 @@ public void Validate_IspMCVirtualBoundary_returns_correct_value()
Assert.IsFalse(virtualBoundaryType.IspMCVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.SpecularReflectance;
Assert.IsFalse(virtualBoundaryType.IspMCVirtualBoundary());
virtualBoundaryType = VirtualBoundaryType.Dosimetry;
virtualBoundaryType = VirtualBoundaryType.InternalSurface;
Assert.IsFalse(virtualBoundaryType.IspMCVirtualBoundary());
// check if enum set to something out of range
virtualBoundaryType = (VirtualBoundaryType)Enum.GetNames(typeof(VirtualBoundaryType)).Length + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Demonstrate_GetDetectorController_successful_return()
detectorList, null));
Assert.IsInstanceOf<IDetectorController>(
DetectorControllerFactory.GetDetectorController(
VirtualBoundaryType.Dosimetry,
VirtualBoundaryType.InternalSurface,
detectorList, null));
Assert.IsInstanceOf<IDetectorController>(
DetectorControllerFactory.GetDetectorController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Demonstrate_GetVirtualBoundary_successful_return()
tissue, new DetectorController(detectorList)));
Assert.IsInstanceOf<IVirtualBoundary>(
VirtualBoundaryFactory.GetVirtualBoundary(
VirtualBoundaryType.Dosimetry,
VirtualBoundaryType.InternalSurface,
tissue, new DetectorController(detectorList)));
Assert.IsInstanceOf<IVirtualBoundary>(
VirtualBoundaryFactory.GetVirtualBoundary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ public void Validate_CircularAngledFromPoint_source()
Random rng = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
ITissue tissue = new MultiLayerTissue();
var profile = new FlatSourceProfile();
var _radius = 1.0;
const double radius = 1.0;
var pointLocation = new Position(0, 0, -1); // put directly above
var translationFromOrigin = new Position(0, 0, 0);

var ps = new CircularAngledFromPointSource(_radius, profile, pointLocation, translationFromOrigin)
var ps = new CircularAngledFromPointSource(radius, profile, pointLocation, translationFromOrigin)
{
Rng = rng
};
Expand All @@ -143,7 +143,7 @@ public void Validate_CircularAngledFromPoint_source()
(photon.DP.Position.X - translationFromOrigin.X) *
(photon.DP.Position.X - translationFromOrigin.X) +
(photon.DP.Position.Y - translationFromOrigin.Y) *
(photon.DP.Position.Y - translationFromOrigin.Y)) <= _radius);
(photon.DP.Position.Y - translationFromOrigin.Y)) <= radius);
// make sure angle is less than 45 degrees
Assert.IsTrue(photon.DP.Direction.Uz >= 1 / Math.Sqrt(2));
}
Expand All @@ -159,7 +159,7 @@ public void Validate_CircularAngledFromCircle_source()
var profile = new FlatSourceProfile();
var radiusOnTissue = 10.0;
var translationFromOrigin = new Position(0, 0, 0);
var radiusInAir = 0.0;
const double radiusInAir = 0.0;
var circleInAirTranslationFromOrigin = new Position(0, 0, -10);
var circleInAirRotation = new Direction(0, 0, 1); // make perpendicular

Expand Down
37 changes: 21 additions & 16 deletions src/Vts.Test/MonteCarlo/Tissues/BoundedTissueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class BoundedTissueTests
/// Test default constructor
/// </summary>
[Test]
public void validate_default_constructor()
public void Validate_default_constructor()
{
var boundedTissue = new BoundedTissue();
Assert.IsInstanceOf<BoundedTissue>(boundedTissue);
}

[OneTimeSetUp]
public void create_instance_of_class()
public void Create_instance_of_class()
{
_oneLayerTissueBoundedByVoxel = new BoundedTissue(
new CaplessVoxelTissueRegion(
Expand Down Expand Up @@ -75,9 +75,9 @@ public void create_instance_of_class()
/// Validate method GetRegionIndex return correct Boolean
/// </summary>
[Test]
public void verify_GetRegionIndex_method_returns_correct_result()
public void Verify_GetRegionIndex_method_returns_correct_result()
{
int index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 0.5)); // inside voxel
var index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(0, 0, 0.5)); // inside voxel
Assert.AreEqual(1, index);
index = _oneLayerTissueBoundedByVoxel.GetRegionIndex(new Position(2.5, 0, 2.5)); // inside bounding voxel
Assert.AreEqual(3, index);
Expand All @@ -89,9 +89,9 @@ public void verify_GetRegionIndex_method_returns_correct_result()
/// Validate method GetNeighborRegionIndex for oneLayerTissueBoundedByVoxel return correct Boolean
/// </summary>
[Test]
public void verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_correct_when_photon_on_ellipsoid()
public void Verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_correct_when_photon_on_ellipsoid()
{
Photon photon = new Photon( // on side of voxel pointed into it
var photon = new Photon( // on side of voxel pointed into it
new Position(-1.0, 0, 1.0),
new Direction(1.0, 0, 0.0),
1,
Expand All @@ -106,10 +106,10 @@ public void verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_co
/// Validate method GetNeighborRegionIndex for oneLayerTissueBoundedByVoxel return correct Boolean
/// </summary>
[Test]
public void verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_correct_when_photon_bottom_slab()
public void Verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_correct_when_photon_bottom_slab()
{
// on bottom of slab pointed out
Photon photon = new Photon( // have to reinitialize photon so that _onBoundary is set to false
var photon = new Photon( // have to reinitialize photon so that _onBoundary is set to false
new Position(0, 0, 10.0),
new Direction(0.0, 0, 1.0),
1,
Expand All @@ -127,12 +127,12 @@ public void verify_oneLayerTissueBoundedByVoxel_GetNeighborRegionIndex_method_co
/// test just tests isolated method.
/// </summary>
[Test]
public void verify_GetReflectedDirection_method_returns_correct_result()
public void Verify_GetReflectedDirection_method_returns_correct_result()
{
// put photon on boundary of domain to make sure base (MultiLayerTissue) call works
var currentPosition = new Position(0, 0, 0);
var currentDirection = new Direction(1 / Math.Sqrt(2), 0, -1 / Math.Sqrt(2));
Direction reflectedDir = _oneLayerTissueBoundedByVoxel.GetReflectedDirection(
var reflectedDir = _oneLayerTissueBoundedByVoxel.GetReflectedDirection(
currentPosition, currentDirection);
Assert.AreEqual(1 / Math.Sqrt(2), reflectedDir.Ux);
Assert.AreEqual(0, reflectedDir.Uy);
Expand Down Expand Up @@ -164,15 +164,15 @@ public void verify_GetReflectedDirection_method_returns_correct_result()
/// Validate method GetReflectedDirection returns correct direction.
/// </summary>
[Test]
public void verify_GetRefractedDirection_method_returns_correct_result()
public void Verify_GetRefractedDirection_method_returns_correct_result()
{
// put photon on boundary of domain to make sure base (MultiLayerTissue) call works
var currentPosition = new Position(0, 0, 10);
var currentDirection = new Direction(1 / Math.Sqrt(2), 0, -1 / Math.Sqrt(2));
var nCurrent = 1.4;
var nNext = 1.4;
var cosThetaSnell = 1 / Math.Sqrt(2);
Direction refractedDir = _oneLayerTissueBoundedByVoxel.GetRefractedDirection(
var refractedDir = _oneLayerTissueBoundedByVoxel.GetRefractedDirection(
currentPosition, currentDirection, nCurrent, nNext, cosThetaSnell);
Assert.IsTrue(Math.Abs(refractedDir.Ux - 1 / Math.Sqrt(2)) < 1e-6);
Assert.AreEqual(0, refractedDir.Uy);
Expand Down Expand Up @@ -205,11 +205,16 @@ public void verify_GetRefractedDirection_method_returns_correct_result()
/// from GetAngleRelativeToBoundaryNormal are positive to be used successfully by Photon.
/// </summary>
[Test]
public void verify_GetAngleRelativeToBoundaryNormal_method_returns_correct_result()
public void Verify_GetAngleRelativeToBoundaryNormal_method_returns_correct_result()
{
var photon = new Photon();
photon.DP.Position = new Position(0, 0, 0); // put photon on voxel top
photon.DP.Direction = new Direction(0, 0, 1); // direction opposite surface normal
var photon = new Photon
{
DP =
{
Position = new Position(0, 0, 0), // put photon on voxel top
Direction = new Direction(0, 0, 1) // direction opposite surface normal
}
};
var dirCosine = _oneLayerTissueBoundedByVoxel.GetAngleRelativeToBoundaryNormal(photon);
Assert.AreEqual(1, dirCosine);
photon.DP.Position = new Position(0, 0, 10); // put photon on voxel bottom
Expand Down
Loading

0 comments on commit f766756

Please sign in to comment.