public void SparseSample_ComplexFloat_Identity()
        {
            NumericsConfiguration.NativeProviderPath = @"C:\Program Files (x86)\Extreme Optimization\Numerical Libraries for .NET\bin\Net40";
            NumericsConfiguration.Providers.RegisterSinglePrecisionProvider();
            NumericsConfiguration.AutoLoadNativeProviders = true;
            CoreImplementations<float>.UseNative();
            Console.WriteLine(CoreImplementations<Complex<float>>.LinearAlgebra.Name);

            SparseCompressedColumnMatrix<Complex<float>> matrixA = Matrix.CreateSparse<Complex<float>>(3, 3);
            matrixA.SetValue(new Complex<float>(1, 0), 0, 0);
            matrixA.SetValue(new Complex<float>(1, 0), 1, 1);
            matrixA.SetValue(new Complex<float>(1, 0), 2, 2);
            Vector<Complex<float>> vectorB = Vector.Create(new Complex<float>(1.0f, 0), new Complex<float>(2.0f, 0), new Complex<float>(3.0f, 0));

            IterativeSparseSolver<Complex<float>> solver = new BiConjugateGradientSolver<Complex<float>>(matrixA);
            DenseVector<Complex<float>> resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);

            // With incomplete LU preconditioner
            solver.Preconditioner = new IncompleteLUPreconditioner<Complex<float>>(matrixA);
            resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
        }
Esempio n. 2
0
        public void SparseSample_ComplexFloat_Identity()
        {
            NumericsConfiguration.NativeProviderPath = @"C:\Program Files (x86)\Extreme Optimization\Numerical Libraries for .NET\bin\Net40";
            NumericsConfiguration.Providers.RegisterSinglePrecisionProvider();
            NumericsConfiguration.AutoLoadNativeProviders = true;
            CoreImplementations <float> .UseNative();

            Console.WriteLine(CoreImplementations <Complex <float> > .LinearAlgebra.Name);

            SparseCompressedColumnMatrix <Complex <float> > matrixA = Matrix.CreateSparse <Complex <float> >(3, 3);

            matrixA.SetValue(new Complex <float>(1, 0), 0, 0);
            matrixA.SetValue(new Complex <float>(1, 0), 1, 1);
            matrixA.SetValue(new Complex <float>(1, 0), 2, 2);
            Vector <Complex <float> > vectorB = Vector.Create(new Complex <float>(1.0f, 0), new Complex <float>(2.0f, 0), new Complex <float>(3.0f, 0));

            IterativeSparseSolver <Complex <float> > solver       = new BiConjugateGradientSolver <Complex <float> >(matrixA);
            DenseVector <Complex <float> >           resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);

            // With incomplete LU preconditioner
            solver.Preconditioner = new IncompleteLUPreconditioner <Complex <float> >(matrixA);
            resultVector          = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
        }
Esempio n. 3
0
        public void ExecuteSample()
        {
            // The line below sets the path where the native assemblies
            // are located. The "XO_LIBRARY_PATH" environment variable
            // points here, too.
            NumericsConfiguration.NativeProviderPath =
                @"C:\Program Files (x86)\Extreme Optimization\Numerical Libraries for .NET\bin\Net40";

            // Register the single precision providers.
            NumericsConfiguration.Providers.RegisterSinglePrecisionProvider();
            NumericsConfiguration.AutoLoadNativeProviders = true;
            CoreImplementations <float> .UseNative();

            // Which provider are we using?
            Console.WriteLine(CoreImplementations <Complex <float> > .LinearAlgebra.Name);

            int N = 228724; // size
            int K = 96;     // non-zeros per column

            // Create some random matrices. Code is below.
            // Use a seed so we can reproduce the same values.
            NumericsConfiguration.DefaultRandomNumberGenerator = new Extreme.Mathematics.Random.MersenneTwister(117);

            var matrixA = CreateSparseRandom(N, K);
            var vectorB = CreateRandom(N);// CreateRandom(N);

            // Now run the solver with and without preconditioner:
            var sw     = Stopwatch.StartNew();
            var solver = new BiConjugateGradientSolver <Complex <float> >(matrixA);

            Console.WriteLine("Starting solve...");
            Vector <Complex <float> > resultVector;

            resultVector = solver.Solve(vectorB);
            sw.Stop();

            Console.WriteLine("Result: {0}", resultVector.GetSlice(0, 10));
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);
            Console.WriteLine("Total time: {0} s", sw.Elapsed.TotalSeconds);

            // With incomplete LU preconditioner
            sw.Restart();
            solver.Preconditioner = new IncompleteLUPreconditioner <Complex <float> >(matrixA);
            resultVector          = solver.Solve(vectorB);
            sw.Stop();

            Console.WriteLine("Result: {0}", resultVector.GetSlice(0, 10));
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
            Console.WriteLine("Total time: {0} s", sw.Elapsed.TotalSeconds);

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
        public void SimpleSample_Double_Identity()
        {
            Console.WriteLine(CoreImplementations<Complex<float>>.LinearAlgebra.Name);
            // We load a sparse matrix and right-hand side from a data file:
            SparseCompressedColumnMatrix<double> matrixA = SparseCompressedColumnMatrix<double>.CreateIdentity(3);
            Vector<double> vectorB = Vector.Create(1.0, 2.0, 3.0);

            IterativeSparseSolver<double> solver = new BiConjugateGradientSolver<double>(matrixA);
            var resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);

            // With incomplete LU preconditioner
            solver.Preconditioner = new IncompleteLUPreconditioner<double>(matrixA);
            resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
        }
Esempio n. 5
0
        public void SimpleSample_Double_Identity()
        {
            Console.WriteLine(CoreImplementations <Complex <float> > .LinearAlgebra.Name);
            // We load a sparse matrix and right-hand side from a data file:
            SparseCompressedColumnMatrix <double> matrixA = SparseCompressedColumnMatrix <double> .CreateIdentity(3);

            Vector <double> vectorB = Vector.Create(1.0, 2.0, 3.0);

            IterativeSparseSolver <double> solver = new BiConjugateGradientSolver <double>(matrixA);
            var resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);

            // With incomplete LU preconditioner
            solver.Preconditioner = new IncompleteLUPreconditioner <double>(matrixA);
            resultVector          = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
        }
Esempio n. 6
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="elements">Список элементов.</param>
        public FEMethod(IEnumerable <Triangle> elements)
        {
            // Узлы с неизвестными потенциалами.
            nullPoints = elements.SelectMany(p => p.Points).Distinct().Where(p => p.Potential == null).ToArray();

            // Идентификаторы узлов с неизвестными потенциалами.
            foreach (var p in nullPoints)
            {
                p.ID = n++;
            }

            // Расчет базисных функций и матрицы коеффициентов.
            foreach (var elem in elements)
            {
                elem.BasicFunctionElement();
            }

            // Построение разреженной СЛАУ.
            timeFill = Stopwatch.StartNew();
            FillSparseMatrix();
            timeFill.Stop();

            // Решение разреженной СЛАУ.
            timeSol = Stopwatch.StartNew();
            var conjugate = new BiConjugateGradientSolver <double>(matrixA);

            conjugate.Preconditioner = new IncompleteLUPreconditioner <double>(matrixA);
            var sol = conjugate.Solve(vectorB);

            timeSol.Stop();

            SetPotential(sol);

            matrixA.Dispose();
            vectorB.Dispose();
            sol.Dispose();
        }