Beispiel #1
0
        public void Run(SparseMatrix A, int m, bool symmetric)
        {
            var solver = new Spectra(A, symmetric)
            {
                Tolerance           = 1e-6,
                ComputeEigenVectors = true,
                ArnoldiCount        = m * 3
            };

            var timer = Stopwatch.StartNew();

            var result = solver.SolveStandard(m, 0.0);

            //var result = solver.SolveStandard(m, Spectrum.SmallestMagnitude);

            //var result = solver.SolveStandard(m, 8.0);
            //var result = solver.SolveStandard(m, Spectrum.LargestMagnitude);

            timer.Stop();

            Display.Time(timer.ElapsedTicks);

            result.EnsureSuccess();

            if (Helper.CheckResiduals(A, result, symmetric, false))
            {
                Display.Ok("OK");
            }
            else
            {
                Display.Warning("residual error too large");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Example program that illustrates how to solve a real symmetric standard eigenvalue
        /// problem in shift and invert mode.
        /// </summary>
        /// <remarks>
        /// MODULE LSymShf.cc
        ///
        /// In this example we try to solve A*x = x*lambda in shift and invert mode, where A is
        /// derived from the central difference discretization of the one-dimensional Laplacian
        /// on [0, 1] with zero Dirichlet boundary conditions.
        ///
        /// The SuperLU package is called to solve some linear systems involving (A-sigma*I).
        /// This is needed to implement the shift and invert strategy.
        /// </remarks>
        static void LSymShf()
        {
            int n = 100; // Dimension of the problem.

            // Creating a 100x100 matrix.
            var A = Symmetrize(Generate.SymmetricMatrixB(n));

            // Defining what we need: the four eigenvectors of A nearest to 1.0.
            var prob = new Spectra(A, true)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveStandard(4, 1.0);

            // Printing solution.
            Solution.Symmetric(A, (SpectraResult)result, true);
        }
Beispiel #3
0
        /// <summary>
        /// Example program that illustrates how to solve a real symmetric standard eigenvalue
        /// problem in regular mode.
        /// </summary>
        /// <remarks>
        /// MODULE LSymReg.cc
        ///
        /// In this example we try to solve A*x = x*lambda in regular  mode, where A is derived
        /// from the standard central difference  discretization of the 2-dimensional Laplacian
        /// on the unit square with zero Dirichlet boundary conditions.
        /// </remarks>
        static void LSymReg()
        {
            int nx = 10;

            // Creating a 100x100 matrix.
            var A = Symmetrize(Generate.SymmetricMatrixA(nx));

            // Defining what we need: the four eigenvectors of A with smallest magnitude.
            var prob = new Spectra(A, true)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveStandard(2, Spectrum.SmallestMagnitude);

            // Printing solution.
            Solution.Symmetric(A, (SpectraResult)result, false);
        }
Beispiel #4
0
        /// <summary>
        /// Example program that illustrates how to solve a real nonsymmetric standard eigenvalue
        /// problem in shift and invert mode.
        /// </summary>
        /// <remarks>
        /// MODULE LNSymShf.cc
        ///
        /// In this example we try to solve A*x = x*lambda in shift and invert mode, where A is
        /// derived from 2-D Brusselator Wave Model. The shift is a real number.
        ///
        /// The SuperLU package is called to solve some linear systems involving (A-sigma*I).
        /// </remarks>
        static void LNSymShf()
        {
            int n = 200; // Dimension of the problem.

            // Creating a 200x200 matrix.
            var A = Generate.BrusselatorMatrix(1.0, 0.004, 0.008, 2.0, 5.45, n);

            // Defining what we need: the four eigenvectors of BWM nearest to 0.0.
            var prob = new Spectra(A)
            {
                ComputeEigenVectors = true, ArnoldiCount = 30
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveStandard(4, 0.0, Spectrum.LargestMagnitude);

            // Printing solution.
            Solution.General(A, (SpectraResult)result, true);
        }
Beispiel #5
0
        /// <summary>
        /// Example program that illustrates how to solve a real nonsymmetric standard eigenvalue
        /// problem in regular mode.
        /// </summary>
        /// <remarks>
        /// MODULE LNSymReg.cc
        ///
        /// In this example we try to solve A*x = x*lambda in regular mode, where A is derived from
        /// the standard central difference discretization of the 2-dimensional convection-diffusion
        /// operator
        ///                    (Laplacian u) + rho*(du/dx)
        /// on a unit square with zero Dirichlet boundary conditions.
        /// </remarks>
        static void LNSymReg()
        {
            int nx = 10;

            // Creating a 100x100 matrix.
            var A = Generate.BlockTridMatrix(nx);

            // Defining what we need: the four eigenvectors of A with largest magnitude.
            var prob = new Spectra(A)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveStandard(4, Spectrum.LargestMagnitude);

            // Printing solution.
            Solution.General(A, (SpectraResult)result, false);
        }