Example #1
0
        public static IFactorization SpawnFactorization(FactorizersEnum factorizer, CoordinationalMatrix M)
        {
            IFactorization factorization;

            switch (factorizer)

            {
            case FactorizersEnum.IncompleteCholesky:
                return(factorization = new IncompleteCholesky(M));

            case FactorizersEnum.IncompleteLU:
                return(factorization = new IncompleteLU(M));

            case FactorizersEnum.IncompleteLUsq:
                return(factorization = new IncompleteLUsq(M));

            case FactorizersEnum.DiagonalFactorization:
                return(factorization = new DioganalFactorization(M));

            case FactorizersEnum.SimpleFactorization:
                return(factorization = new SimpleFactorization(M));

            case FactorizersEnum.WithoutFactorization:
                return(factorization = null);

            default: return(null);
            }
        }
Example #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 IncompleteLU();

            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.AlmostEqual(original[i, j].Real, -Epsilon.Magnitude()), "#01-" + i + "-" + j);
                    Assert.IsTrue(sparseMatrix[i, j].Imaginary.AlmostEqual(original[i, j].Imaginary, -Epsilon.Magnitude()), "#02-" + i + "-" + j);
                }
            }
        }
        private static T GetMethod <T>(IncompleteLU 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);
        }
Example #4
0
        public void FactorizationU()
        {
            IncompleteLU incompleteLU = new IncompleteLU(FA);
            var          result       = incompleteLU.UMult(new Vector(new double[] { 1, 1, 1 }));

            double[] resultActual = new double[]
            {
                10 + 1 + 2,
                99.0 / 10 + 14.0 / 5,
                872.0 / 99
            };

            for (int i = 0; i < result.Size; i++)
            {
                Assert.Equal(result[i], resultActual[i], 8);
            }
        }
Example #5
0
        public void FactorizationL()
        {
            IncompleteLU incompleteLU = new IncompleteLU(FA);
            var          result       = incompleteLU.LMult(new Vector(new double[] { 1, 1, 1 }));

            double[] resultActual = new double[]
            {
                1,
                1.0 / 10 + 1,
                1.0 / 5 + 28.0 / 99 + 1
            };

            for (int i = 0; i < result.Size; i++)
            {
                Assert.Equal(result[i], resultActual[i], 8);
            }
        }
Example #6
0
        /// <summary>
        /// The main method that uses the IncompleteLU preconditioner.
        /// </summary>
        public void UseSolver()
        {
            // Create a sparse matrix. For now the size will be 10 x 10 elements
            Matrix matrix = CreateMatrix(10);

            // Create the right hand side vector. The size is the same as the matrix
            // and all values will be 2.0.
            Vector rightHandSideVector = new DenseVector(10, 2.0);

            // Create the IncompleteLU preconditioner
            IncompleteLU preconditioner = new IncompleteLU();

            // Create the actual preconditioner
            preconditioner.Initialize(matrix);

            // Now that all is set we can solve the matrix equation.
            Vector solutionVector = preconditioner.Approximate(rightHandSideVector);

            // Another way to get the values is by using the overloaded solve method
            // In this case the solution vector needs to be of the correct size.
            preconditioner.Approximate(rightHandSideVector, solutionVector);
        }
Example #7
0
 /// <summary>
 /// Get lower triangle.
 /// </summary>
 /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
 /// <returns>Lower triangle.</returns>
 private static Matrix GetLowerTriangle(IncompleteLU ilu)
 {
     return(GetMethod <Matrix>(ilu, "LowerTriangle"));
 }
 private static Matrix <double> GetUpperTriangle(IncompleteLU ilu)
 {
     return(GetMethod <Matrix <double> >(ilu, "UpperTriangle"));
 }