Exemple #1
0
        public void CompareWithOriginalSparseMatrix()
        {
            var sparseMatrix = new SparseMatrix(3);

            sparseMatrix[0, 0] = -1;
            sparseMatrix[0, 1] = 5;
            sparseMatrix[0, 2] = 6;
            sparseMatrix[1, 0] = 3;
            sparseMatrix[1, 1] = -6;
            sparseMatrix[1, 2] = 1;
            sparseMatrix[2, 0] = 6;
            sparseMatrix[2, 1] = 8;
            sparseMatrix[2, 2] = 9;
            var ilu = new ILU0Preconditioner();

            ilu.Initialize(sparseMatrix);
            var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu));

            for (var i = 0; i < sparseMatrix.RowCount; i++)
            {
                for (var j = 0; j < sparseMatrix.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(sparseMatrix[i, j], original[i, j], 5);
                }
            }
        }
Exemple #2
0
        public void CompareWithOriginalSparseMatrix()
        {
            var sparseMatrix = new SparseMatrix(3);

            sparseMatrix[0, 0] = -1;
            sparseMatrix[0, 1] = 5;
            sparseMatrix[0, 2] = 6;
            sparseMatrix[1, 0] = 3;
            sparseMatrix[1, 1] = -6;
            sparseMatrix[1, 2] = 1;
            sparseMatrix[2, 0] = 6;
            sparseMatrix[2, 1] = 8;
            sparseMatrix[2, 2] = 9;
            var ilu = new ILU0Preconditioner();

            ilu.Initialize(sparseMatrix);
            var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu));

            for (var i = 0; i < sparseMatrix.RowCount; i++)
            {
                for (var j = 0; j < sparseMatrix.ColumnCount; j++)
                {
                    Assert.IsTrue(sparseMatrix[i, j].Real.AlmostEqualNumbersBetween(original[i, j].Real, -Epsilon.Magnitude()), "#01-" + i + "-" + j);
                    Assert.IsTrue(sparseMatrix[i, j].Imaginary.AlmostEqualNumbersBetween(original[i, j].Imaginary, -Epsilon.Magnitude()), "#02-" + i + "-" + j);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Invoke method from <c>Ilutp</c> class.
        /// </summary>
        /// <typeparam name="T">Type of the return value.</typeparam>
        /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
        /// <param name="methodName">Method name.</param>
        /// <returns>Result of the method invocation.</returns>
        static T GetMethod <T>(ILU0Preconditioner ilu, string methodName)
        {
            var type       = ilu.GetType();
            var methodInfo = type.GetMethod(
                methodName,
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
                null,
                CallingConventions.Standard,
                new Type[0],
                null);
            var obj = methodInfo.Invoke(ilu, null);

            return((T)obj);
        }
Exemple #4
0
 /// <summary>
 /// Get lower triangle.
 /// </summary>
 /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
 /// <returns>Lower triangle.</returns>
 static Matrix <float> GetLowerTriangle(ILU0Preconditioner ilu)
 {
     return(GetMethod <Matrix <float> >(ilu, "LowerTriangle"));
 }
Exemple #5
0
 /// <summary>
 /// Get upper triangle.
 /// </summary>
 /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
 /// <returns>Upper triangle.</returns>
 static Matrix <Complex> GetUpperTriangle(ILU0Preconditioner ilu)
 {
     return(GetMethod <Matrix <Complex> >(ilu, "UpperTriangle"));
 }