How to use the pyamg.aggregation function in pyamg

To help you get started, we’ve selected a few pyamg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zerothi / sisl / toolbox / TranSiesta / Poisson / poisson_explicit.py View on Github external
def pyamg_solve(A, b, tolerance=1e-12):
    print("\nSetting up pyamg solver...")
    ml = pyamg.aggregation.smoothed_aggregation_solver(A, max_levels=1000)
    print(ml)
    M = ml.aspreconditioner(cycle='W') # pre-conditioner
    residuals = []
    def callback(x):
        # residuals calculated in the solve function is a pre-conditioned residual
        #residuals.append(np.linalg.norm(b - A.dot(x)) ** 0.5)
        print("    {:4d}  residual = {:.5e}   x0-residual = {:.5e}".format(len(residuals) - 1, residuals[-1], residuals[-1] / residuals[0]))
    x = ml.solve(b, tol=tolerance, callback=callback, residuals=residuals, accel="cg", maxiter=1e7)
    print('Done solving the Poisson equation!')
    return x