Skip to content

Commit

Permalink
Merge pull request #160 from VirtualPhotonics/feature/88-sda-forward-…
Browse files Browse the repository at this point in the history
…solvers-need-check-on-optical-properties-to-make-sure-solution-is-valid

Added warning if diffusion parameters are such that mua>=musp.
  • Loading branch information
hayakawa16 authored Aug 8, 2024
2 parents cdc7b3b + 337e86a commit 378f604
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.IO;
using NUnit.Framework;
using Vts.Modeling.ForwardSolvers;

namespace Vts.Test.Unit.Modeling.ForwardSolvers
{
[TestFixture]
public class DiffusionParametersTests
{
/// <summary>
/// Test to verify results of Create Method
/// </summary>
[Test]
public void Validate_Create_method_results()
{
// test SDA
var ops = new OpticalProperties(0.01, 1.0, 0.8, 1.4);
var diffusionParameters = DiffusionParameters.Create(
ops,
ForwardModel.SDA);
Assert.IsTrue(Math.Abs(2.950078 - diffusionParameters.A) < 1e-6);
Assert.IsTrue(Math.Abs(0.330033 - diffusionParameters.D) < 1e-6);
Assert.IsTrue(Math.Abs(214.13747 - diffusionParameters.cn) < 1e-4);
Assert.IsTrue(Math.Abs(0.8 - diffusionParameters.gTilde) < 1e-6);
Assert.IsTrue(Math.Abs(0.01 - diffusionParameters.mua) < 1e-6);
Assert.IsTrue(Math.Abs(0.174068 - diffusionParameters.mueff) < 1e-6);
Assert.IsTrue(Math.Abs(1.0 - diffusionParameters.musTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.01 - diffusionParameters.mutTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.01 - diffusionParameters.mutr) < 1e-6);
Assert.IsTrue(Math.Abs(1.947246 - diffusionParameters.zb) < 1e-6);
Assert.IsTrue(Math.Abs(0.990099 - diffusionParameters.zp) < 1e-6);
// test deltaP1=
diffusionParameters = DiffusionParameters.Create(
ops,
ForwardModel.DeltaPOne);
Assert.IsTrue(Math.Abs(2.950078 - diffusionParameters.A) < 1e-6);
Assert.IsTrue(Math.Abs(0.330033 - diffusionParameters.D) < 1e-6);
Assert.IsTrue(Math.Abs(214.13747 - diffusionParameters.cn) < 1e-4);
Assert.IsTrue(Math.Abs(0.444444 - diffusionParameters.gTilde) < 1e-6);
Assert.IsTrue(Math.Abs(0.01 - diffusionParameters.mua) < 1e-6);
Assert.IsTrue(Math.Abs(0.174068 - diffusionParameters.mueff) < 1e-6);
Assert.IsTrue(Math.Abs(1.799999 - diffusionParameters.musTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.809999 - diffusionParameters.mutTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.01 - diffusionParameters.mutr) < 1e-6);
Assert.IsTrue(Math.Abs(1.947246 - diffusionParameters.zb) < 1e-6);
Assert.IsTrue(Math.Abs(0.552486 - diffusionParameters.zp) < 1e-6);
// add test to test warning if Mua >= Musp
ops = new OpticalProperties(1.0, 1.0, 0.8, 1.4);
var output = new StringWriter();
Console.SetOut(output);
diffusionParameters = DiffusionParameters.Create(
ops,
ForwardModel.SDA);
Assert.IsTrue(diffusionParameters != null);
Assert.That(output.ToString(), Is.EqualTo("Warning: Mua >= Musp\r\n"));
}

/// <summary>
/// Test to verify results of Copy Method
/// </summary>
[Test]
public void Validate_Copy_method_results()
{
// set diffusion parameters
var ops = new OpticalProperties(0.01, 1.0, 0.8, 1.4);
var originalDiffusionParameters = DiffusionParameters.Create(
ops,
ForwardModel.SDA);
// copy the parameters
var diffusionParameters = DiffusionParameters.Copy(originalDiffusionParameters);
Assert.IsTrue(Math.Abs(2.950078 - diffusionParameters.A) < 1e-6);
Assert.IsTrue(Math.Abs(0.330033 - diffusionParameters.D) < 1e-6);
Assert.IsTrue(Math.Abs(214.13747 - diffusionParameters.cn) < 1e-4);
Assert.IsTrue(Math.Abs(0.8 - diffusionParameters.gTilde) < 1e-6);
Assert.IsTrue(Math.Abs(0.01 - diffusionParameters.mua) < 1e-6);
Assert.IsTrue(Math.Abs(0.174068 - diffusionParameters.mueff) < 1e-6);
Assert.IsTrue(Math.Abs(1.0 - diffusionParameters.musTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.01 - diffusionParameters.mutTilde) < 1e-6);
Assert.IsTrue(Math.Abs(1.01 - diffusionParameters.mutr) < 1e-6);
Assert.IsTrue(Math.Abs(1.947246 - diffusionParameters.zb) < 1e-6);
Assert.IsTrue(Math.Abs(0.990099 - diffusionParameters.zp) < 1e-6);
}
}
}
3 changes: 3 additions & 0 deletions src/Vts/Modeling/ForwardSolvers/DiffusionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static DiffusionParameters Create(OpticalProperties op, ForwardModel fm)
var tempMutTilde = op.Mua + tempMusTilde;
var tempZp = 1 / tempMutTilde;

// put out warning if mus' on order of mua
if (op.Mua >= op.Musp) Console.WriteLine("Warning: Mua >= Musp");

return new DiffusionParameters(tempA, tempMueff, tempZb, tempZp, tempMutTilde, tempMusTilde, tempMutr, tempGTilde, tempD, tempCn, tempMua);
}

Expand Down

0 comments on commit 378f604

Please sign in to comment.