public void Create() { var criterium = new ResidualStopCriterium(1e-6f, 50); Assert.IsNotNull(criterium, "There should be a criterium"); Assert.AreEqual(1e-6f, criterium.Maximum, "Incorrect maximum"); Assert.AreEqual(50, criterium.MinimumIterationsBelowMaximum, "Incorrect iteration count"); }
public void Clone() { var criterium = new ResidualStopCriterium(1e-3f, 10); Assert.IsNotNull(criterium, "There should be a criterium"); var clone = criterium.Clone(); Assert.IsInstanceOf(typeof (ResidualStopCriterium), clone, "Wrong criterium type"); var clonedCriterium = clone as ResidualStopCriterium; Assert.IsNotNull(clonedCriterium); // ReSharper disable PossibleNullReferenceException Assert.AreEqual(criterium.Maximum, clonedCriterium.Maximum, "Clone failed"); Assert.AreEqual(criterium.MinimumIterationsBelowMaximum, clonedCriterium.MinimumIterationsBelowMaximum, "Clone failed"); // ReSharper restore PossibleNullReferenceException }
public void ResetMinimumIterationsBelowMaximum() { var criterium = new ResidualStopCriterium(1e-6f, 50); Assert.IsNotNull(criterium, "There should be a criterium"); criterium.ResetMinimumIterationsBelowMaximumToDefault(); Assert.AreEqual(ResidualStopCriterium.DefaultMinimumIterationsBelowMaximum, criterium.MinimumIterationsBelowMaximum, "Incorrect iteration count"); }
public void ResetCalculationState() { var criterium = new ResidualStopCriterium(1e-3f, 10); Assert.IsNotNull(criterium, "There should be a criterium"); var solution = new DenseVector(new[] {new Complex32(0.001f, 1), new Complex32(0.001f, 1), new Complex32(0.002f, 1)}); var source = new DenseVector(new[] {new Complex32(0.001f, 1), new Complex32(0.001f, 1), new Complex32(0.002f, 1)}); var residual = new DenseVector(new[] {new Complex32(1.000f, 0), new Complex32(1.000f, 0), new Complex32(2.001f, 0)}); var status = criterium.DetermineStatus(5, solution, source, residual); Assert.AreEqual(IterationStatus.Continue, status, "Should be running"); criterium.Reset(); Assert.AreEqual(IterationStatus.Continue, criterium.Status, "Should not have started"); }
public void ResetMaximum() { var criterium = new ResidualStopCriterium(1e-6f, 50); Assert.IsNotNull(criterium, "There should be a criterium"); criterium.ResetMaximumResidualToDefault(); Assert.AreEqual(ResidualStopCriterium.DefaultMaximumResidual, criterium.Maximum, "Incorrect maximum"); }
public void DetermineStatusWithSourceNaN() { var criterium = new ResidualStopCriterium(1e-3f, 10); Assert.IsNotNull(criterium, "There should be a criterium"); var solution = new DenseVector(new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1)}); var source = new DenseVector(new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(float.NaN, 1)}); var residual = new DenseVector(new[] {new Complex32(1000.0f, 1), new Complex32(1000.0f, 1), new Complex32(2001.0f, 1)}); var status = criterium.DetermineStatus(5, solution, source, residual); Assert.AreEqual(IterationStatus.Diverged, status, "Should be diverged"); }
public void DetermineStatusWithNonMatchingSourceVectorThrowsArgumentException() { var criterium = new ResidualStopCriterium(1e-6f, 50); Assert.IsNotNull(criterium, "There should be a criterium"); Assert.Throws<ArgumentException>(() => criterium.DetermineStatus( 1, DenseVector.Create(3, i => 4), DenseVector.Create(4, i => 4), DenseVector.Create(3, i => 4))); }
public void DetermineStatusWithIllegalIterationNumberThrowsArgumentOutOfRangeException() { var criterium = new ResidualStopCriterium(1e-6f, 50); Assert.IsNotNull(criterium, "There should be a criterium"); Assert.Throws<ArgumentOutOfRangeException>(() => criterium.DetermineStatus( -1, DenseVector.Create(3, i => 4), DenseVector.Create(3, i => 5), DenseVector.Create(3, i => 6))); }
public void DetermineStatusWithConvergenceAtFirstIteration() { var criterium = new ResidualStopCriterium(); Assert.IsNotNull(criterium, "There should be a criterium"); var solution = new DenseVector(new[] {Complex32.One, Complex32.One, Complex32.One}); var source = new DenseVector(new[] {Complex32.One, Complex32.One, Complex32.One}); var residual = new DenseVector(new[] {Complex32.Zero, Complex32.Zero, Complex32.Zero}); var status = criterium.DetermineStatus(0, solution, source, residual); Assert.AreEqual(IterationStatus.Converged, status, "Should be done"); }
public void DetermineStatus() { var criterium = new ResidualStopCriterium(1e-3f, 10); Assert.IsNotNull(criterium, "There should be a criterium"); // the solution vector isn't actually being used so ... var solution = new DenseVector(new[] {new Complex32(float.NaN, float.NaN), new Complex32(float.NaN, float.NaN), new Complex32(float.NaN, float.NaN)}); // Set the source values var source = new DenseVector(new[] {new Complex32(1.000f, 1), new Complex32(1.000f, 1), new Complex32(2.001f, 1)}); // Set the residual values var residual = new DenseVector(new[] {new Complex32(0.001f, 0), new Complex32(0.001f, 0), new Complex32(0.002f, 0)}); var status = criterium.DetermineStatus(5, solution, source, residual); Assert.AreEqual(IterationStatus.Continue, status, "Should still be running"); var status2 = criterium.DetermineStatus(16, solution, source, residual); Assert.AreEqual(IterationStatus.Converged, status2, "Should be done"); }