Пример #1
0
    def test_solver(self):
        A, rhs = make_problem(100)

        for stype in ('bicgstab', 'lgmres'):
            for rtype in ('spai0', 'ilu0'):
                P = amg.amgcl(A, prm={'relax.type': rtype})
                # Setup solver
                solve = amg.solver(P, prm=dict(type=stype, tol=1e-3, maxiter=1000))

                # Solve
                x = solve(rhs)
Пример #2
0
    def test_solver(self):
        A, rhs = make_problem(100)

        for stype in ('bicgstab', 'lgmres'):
            for rtype in ('spai0', 'ilu0'):
                P = amg.amgcl(A, prm={'relax.type': rtype})
                # Setup solver
                solve = amg.solver(P,
                                   prm=dict(type=stype, tol=1e-3,
                                            maxiter=1000))

                # Solve
                x = solve(rhs)
Пример #3
0
    def test_solver(self):
        A, rhs = make_problem(100)

        for stype in ('bicgstab', 'lgmres'):
            for rtype in ('spai0', 'ilu0'):
                for P in (
                        amg.amg(A, prm={'relax.type': rtype}),
                        amg.relaxation(A, prm={'type': rtype})
                        ):
                    # Setup solver
                    solve = amg.solver(P, prm=dict(type=stype, tol=1e-3, maxiter=1000))

                    # Solve
                    x = solve(rhs)

                    # Check residual
                    self.assertTrue(norm(rhs - A * x) / norm(rhs) < 1e-3)

                    # Solve again, now provide system matrix explicitly
                    x = solve(A, rhs)

                    # Check residual
                    self.assertTrue(norm(rhs - A * x) / norm(rhs) < 1e-3)
Пример #4
0
    def test_solver(self):
        A, rhs = make_problem(100)

        for stype in ('bicgstab', 'lgmres'):
            for rtype in ('spai0', 'ilu0'):
                for P in (amg.amg(A, prm={'relax.type': rtype}),
                          amg.relaxation(A, prm={'type': rtype})):
                    # Setup solver
                    solve = amg.solver(P,
                                       prm=dict(type=stype,
                                                tol=1e-3,
                                                maxiter=1000))

                    # Solve
                    x = solve(rhs)

                    # Check residual
                    self.assertTrue(norm(rhs - A * x) / norm(rhs) < 1e-3)

                    # Solve again, now provide system matrix explicitly
                    x = solve(A, rhs)

                    # Check residual
                    self.assertTrue(norm(rhs - A * x) / norm(rhs) < 1e-3)
Пример #5
0
#----------------------------------------------------------------------------
if args.A:
    with timeit('Read problem'):
        A = mmread(args.A)
        f = mmread(args.f).flatten() if args.f else ones(A.rows())
else:
    with timeit('Generate problem'):
        A,f = make_poisson(args.n)

# Parse parameters
p_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.p)}
s_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.s)}

# Create solver/preconditioner pair
with timeit('Setup solver'):
    S = amg.solver(amg.relaxation(A, p_prm) if args.single else amg.amg(A, p_prm), s_prm)
print(S)

# Solve the system for the RHS
with timeit('Solve the problem'):
    x = S(f)

error = np.linalg.norm(f - A * x) / np.linalg.norm(f)
print("{0.iters}: {0.error:.6e} / {1:.6e}".format(S, error))

# Save the solution
if args.x:
    with timeit('Save the result'):
        mmwrite(args.x, x.reshape((-1,1)))

timeit.report()
Пример #6
0
uv0 = np.zeros(basis["u"].N)
inlet_dofs = basis["u"].get_dofs(mesh.boundaries["inlet"]).all("u^1")
inlet_y_lim = [p.x[1] for p in channel.lines[3].points[::-1]]
monic = np.polynomial.polynomial.Polynomial.fromroots(inlet_y_lim)
uv0[inlet_dofs] = -6 * monic(basis["u"].doflocs[1, inlet_dofs]) / inlet_y_lim[1] ** 2


def embed(xy: np.ndarray) -> np.ndarray:
    return np.pad(xy, ((0, 0), (0, 1)), "constant")


solvers = [
    pyamgcl.solver(
        pyamgcl.amg(
            skfem.condense(K_lhs, D=dirichlet["u"], expand=False),
            {"coarsening.type": "aggregation", "relax.type": "ilu0"},
        ),
        {"type": "cg"},
    ),
    pyamgcl.solver(
        pyamgcl.amg(skfem.condense(L["p"], D=dirichlet["p"], expand=False)),
        {"type": "cg"},
    ),
    pyamgcl.solver(
        pyamgcl.amg(
            skfem.condense(M / dt, D=dirichlet["u"], expand=False),
            {"relax.type": "gauss_seidel"},
        ),
        {"type": "cg"},
    ),
]
Пример #7
0
#----------------------------------------------------------------------------
if args.A:
    with timeit('Read problem'):
        A = mmread(args.A)
        f = mmread(args.f).flatten() if args.f else np.ones(A.shape[0])
else:
    with timeit('Generate problem'):
        A,f = make_poisson_3d(args.n)

# Parse parameters
p_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.p)}
s_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.s)}

# Create solver/preconditioner pair
with timeit('Setup solver'):
    S = amg.solver(amg.amgcl(A, p_prm), s_prm)
print(S)

# Solve the system for the RHS
with timeit('Solve the problem'):
    x = S(f)

error = np.linalg.norm(f - A * x) / np.linalg.norm(f)
print("{0.iters}: {0.error:.6e} / {1:.6e}".format(S, error))

# Save the solution
if args.x:
    with timeit('Save the result'):
        mmwrite(args.x, x.reshape((-1,1)))

timeit.report()
Пример #8
0
#----------------------------------------------------------------------------
if args.A:
    with timeit('Read problem'):
        A = mmread(args.A)
        f = mmread(args.f).flatten() if args.f else np.ones(A.shape[0])
else:
    with timeit('Generate problem'):
        A, f = make_poisson_3d(args.n)

# Parse parameters
p_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.p)}
s_prm = {p[0]: p[1] for p in map(lambda s: s.split('='), args.s)}

# Create solver/preconditioner pair
with timeit('Setup solver'):
    S = amg.solver(amg.amgcl(A, p_prm), s_prm)
print(S)

# Solve the system for the RHS
with timeit('Solve the problem'):
    x = S(f)

error = np.linalg.norm(f - A * x) / np.linalg.norm(f)
print("{0.iters}: {0.error:.6e} / {1:.6e}".format(S, error))

# Save the solution
if args.x:
    with timeit('Save the result'):
        mmwrite(args.x, x.reshape((-1, 1)))

timeit.report()