Skip to content

Commit

Permalink
Downgraded three more validation checks from an exception that stops …
Browse files Browse the repository at this point in the history
…the code, to issuing a warning and continuing on with the simulation.The philosophy here is that if combination of inputs is non-standard but the transport will not error, a warning is issued and the validation result remains true. This allows users to specify inconsistent combinations, e.g. angled source and cylindrical coordinate detectors, receive a warning and have the simulation proceed. If the combination of inputs will cause the transport to error, e.g. defining an embedded ellipsoid that overlaps with a tissue layer, then the input validation fails and the simulation stopped.
  • Loading branch information
hayakawa16 committed Aug 8, 2024
1 parent 2b8a37c commit 5306b4a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ 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
{
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);
}
Expand Down Expand Up @@ -81,29 +84,34 @@ public void Validate_duplicate_detector_name_is_invalid()
}

/// <summary>
/// Test to verify input with cylindrical detector and off axis ellipsoid in tissue is invalid
/// 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
{
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 is invalid
/// </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
Expand All @@ -114,12 +122,17 @@ public void Validate_ellipsoid_tissue_without_cylindrical_symmetry_and_cylindric
},
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 with angled source and cylindrical detectors is invalid
/// 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()
Expand All @@ -131,12 +144,16 @@ public void Validate_angled_source_and_cylindrical_detectors_are_not_defined_tog
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 puts out warning
/// Test to verify input with ellipsoid in tissue and R(fx) detector outputs warning
/// but continues as valid input
/// </summary>
[Test]
Expand All @@ -156,11 +173,11 @@ public void Validate_ellipsoid_tissue_and_ROfFx_detectors_defined_together_issue
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
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"));
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 puts out warning
/// Test to verify input with voxel in tissue and R(fx) detector outputs warning
/// but continues as valid input
/// </summary>
[Test]
Expand All @@ -186,7 +203,7 @@ public void Validate_voxel_tissue_and_ROfFx_detectors_defined_together_issues_wa
Console.SetOut(output);
var result = SimulationInputValidation.ValidateInput(input);
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"));
Assert.That(output.ToString(), Is.EqualTo("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry: user discretion advised\r\n"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ private static ValidationResult ValidateDetectorInput(SimulationInput si)

/// <summary>
/// This method checks the input against combined combinations of options
/// and source, tissue, detector definitions.
/// and source, tissue, detector definitions. The philosophy here is that if the transport will
/// not error, a warning is issued and the validation result remains true. This allows users to
/// specify inconsistent combinations, e.g. angled source and cylindrical coordinate detectors,
/// receive a warning and have the simulation proceed.
/// </summary>
/// <param name="input">input to be validated</param>
/// <returns>An instance of ValidationResult with IsValid set and error message if false</returns>
Expand Down Expand Up @@ -166,19 +169,21 @@ private static ValidationResult ValidateCombinedInputParameters(SimulationInput
{
case true when
ellipsoid.Center.X != 0.0 && ellipsoid.Center.Y != 0.0:
return new ValidationResult(
false,
"Ellipsoid must be centered at (x,y)=(0,0) for cylindrical tallies",
"Change ellipsoid center to (0,0) or specify non-cylindrical type tally");
Console.WriteLine("Warning: off center ellipsoid in tissue with cylindrical detector defined: user discretion advised");
return new ValidationResult(
true,
"Warning: off center ellipsoid in tissue with cylindrical detector defined",
"User discretion advised: change ellipsoid center to (0,0) or specify non-cylindrical type tally");
case true when ellipsoid.Dx != ellipsoid.Dy:
Console.WriteLine("Warning: ellipsoid with Dx != Dy in tissue with cylindrical detector defined: user discretion advised");
return new ValidationResult(
false,
"Ellipsoid must have Dx=Dy for cylindrical tallies",
"Change ellipsoid.Dx to be = to Dy or specify non-cylindrical type tally");
true,
"Warning: ellipsoid with Dx != Dy in tissue with cylindrical detector defined",
"User discretion advised: change ellipsoid.Dx to be = to Dy or specify non-cylindrical type tally");
}

if (detectorInput.TallyType != TallyType.ROfFx) continue;
Console.WriteLine("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry.User discretion advised");
Console.WriteLine("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry: user discretion advised");
return new ValidationResult(
true,
"Warning: R(fx) theory assumes a homogeneous or layered tissue geometry",
Expand All @@ -203,7 +208,7 @@ private static ValidationResult ValidateCombinedInputParameters(SimulationInput
}

if (detectorInput.TallyType != TallyType.ROfFx) continue;
Console.WriteLine("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry.User discretion advised");
Console.WriteLine("Warning: R(fx) theory assumes a homogeneous or layered tissue geometry: user discretion advised");
return new ValidationResult(
true,
"Warning: R(fx) theory assumes a homogeneous or layered tissue geometry",
Expand All @@ -225,10 +230,11 @@ private static ValidationResult ValidateCombinedInputParameters(SimulationInput
source.Direction != new Direction(0,0,1) &&
input.DetectorInputs.Any(detectorInput => detectorInput.TallyDetails.IsCylindricalTally))
{
Console.WriteLine("Warning: Angled source and cylindrical coordinate detector defined: user discretion advised");
return new ValidationResult(
false,
"If source is angled, cannot define cylindrically symmetric detectors",
"Change detector to Cartesian equivalent or define source to be normal");
true,
"Warning: Angled source and cylindrical coordinate detector defined",
"User discretion advised: change detector to Cartesian equivalent or define source to be normal");
}
if (input.DetectorInputs.Where(detectorInput => detectorInput.TallyDetails.IsTransmittanceTally &&
input.TissueInput is MultiLayerTissueInput).Any(detectorInput => ((dynamic)detectorInput).FinalTissueRegionIndex == 0))
Expand Down

0 comments on commit 5306b4a

Please sign in to comment.