Beispiel #1
0
    def test_matrix_formats(self):

        # Do dense, csr, bsr and csc versions of A all yield the same solver
        A = poisson((7, 7), format='csr')
        cases = [A.tobsr(blocksize=(1, 1))]
        cases.append(A.tocsc())
        cases.append(A.toarray())

        rs_old = ruge_stuben_solver(A, max_coarse=10)
        for AA in cases:
            rs_new = ruge_stuben_solver(AA, max_coarse=10)
            assert(np.abs(np.ravel(rs_old.levels[-1].A.toarray() - rs_new.levels[-1].A.toarray())).max() < 0.01)
            rs_old = rs_new
Beispiel #2
0
    def test_poisson(self):
        cases = []

        cases.append((500,))
        cases.append((250, 250))
        cases.append((25, 25, 25))

        for case in cases:
            A = poisson(case, format='csr')

            np.random.seed(0)  # make tests repeatable

            x = np.random.rand(A.shape[0])
            b = A*np.random.rand(A.shape[0])  # zeros_like(x)

            ml = ruge_stuben_solver(A, max_coarse=50)

            res = []
            x_sol = ml.solve(b, x0=x, maxiter=20, tol=1e-12,
                             residuals=res)
            del x_sol

            avg_convergence_ratio = (res[-1]/res[0])**(1.0/len(res))

            assert(avg_convergence_ratio < 0.20)
Beispiel #3
0
    def test_poisson(self):
        cases = []

        cases.append((500,))
        cases.append((250, 250))
        cases.append((25, 25, 25))

        for case in cases:
            A = poisson(case, format='csr')

            np.random.seed(0)  # make tests repeatable

            x = sp.rand(A.shape[0])
            b = A*sp.rand(A.shape[0])  # zeros_like(x)

            ml = ruge_stuben_solver(A, max_coarse=50)

            res = []
            x_sol = ml.solve(b, x0=x, maxiter=20, tol=1e-12,
                             residuals=res)
            del x_sol

            avg_convergence_ratio = (res[-1]/res[0])**(1.0/len(res))

            assert(avg_convergence_ratio < 0.20)
    def run_cases(self, opts):
        for A in self.cases:
            ml = ruge_stuben_solver(A, max_coarse=10)
            
            np.random.seed(0)  # make tests repeatable

            x = sp.rand(A.shape[0])
            b = A*sp.rand(A.shape[0])  # zeros_like(x)


            res = []
            x_sol = ml.solve(b, x0=x, maxiter=20, tol=1e-12,
                             residuals=res)
            del x_sol

            avg_convergence_ratio = (res[-1]/res[0])**(1.0/len(res))

            assert(avg_convergence_ratio < 0.20)
Beispiel #5
0
import scipy

from pyamg.gallery import stencil_grid
from pyamg.gallery.diffusion import diffusion_stencil_2d
from pyamg.strength import classical_strength_of_connection
from pyamg.classical.classical import ruge_stuben_solver

from convergence_tools import print_cycle_history

if __name__ == '__main__':
    n = 100
    nx = n
    ny = n

    # Rotated Anisotropic Diffusion
    stencil = diffusion_stencil_2d(type='FE',epsilon=0.001,theta=scipy.pi/3)

    A = stencil_grid(stencil, (nx,ny), format='csr')
    S = classical_strength_of_connection(A, 0.0)

    numpy.random.seed(625)
    x = scipy.rand(A.shape[0])
    b = A*scipy.rand(A.shape[0])

    ml = ruge_stuben_solver(A, max_coarse=10)

    resvec = []
    x = ml.solve(b, x0=x, maxiter=20, tol=1e-14, residuals=resvec)

    print_cycle_history(resvec, ml, verbose=True, plotting=True)
Beispiel #6
0
from biofilm.classify import flat
from biofilm.model import media
from solver_diagnostics import solver_diagnostics
import numpy as np

cells = flat.make_image()
boundary = media.make_boundary_layer(cells, 5).flatten()
M = media.make_matrix(cells, boundary, 1.0)
rhs = np.zeros(cells.size)
rhs[boundary] = 1

from pyamg.classical.classical import ruge_stuben_solver
import scipy
from convergence_tools import print_cycle_history

ml = ruge_stuben_solver(M, max_coarse=500)
x0 = np.zeros_like(rhs)#np.linspace(0, 1, cells.shape[0])[:, np.newaxis].repeat(cells.shape[1], axis=1)

resvec = []
x = ml.solve(rhs, x0=x0, maxiter=20, tol=1e-8, residuals=resvec)
print_cycle_history(resvec, ml, verbose=True, plotting=True)

#solver_diagnostics(M)

#from solver_diagnostic import solver_diagnostic
#solver_diagnostic(M)