nu.value += max(int(-hpddm.optionVal(opt, b'geneo_nu') + 1), (-1)**rankWorld * rankWorld) threshold = hpddm.underlying(max(0, hpddm.optionVal(opt, b'geneo_threshold'))) hpddm.schwarzSolveGEVP(A, MatNeumann, ctypes.byref(nu), threshold) addr = hpddm.optionAddr(opt, b'geneo_nu') addr.contents.value = nu.value else: nu = 1 deflation = numpy.ones((dof, nu), order = 'F', dtype = hpddm.scalar) hpddm.setVectors(hpddm.schwarzPreconditioner(A), nu, deflation) hpddm.initializeCoarseOperator(hpddm.schwarzPreconditioner(A), nu) hpddm.schwarzBuildCoarseOperator(A, hpddm.MPI_Comm.from_address(MPI._addressof(MPI.COMM_WORLD))) hpddm.schwarzCallNumfact(A) if rankWorld != 0: hpddm.optionRemove(opt, b'verbosity') comm = hpddm.getCommunicator(hpddm.schwarzPreconditioner(A)) it = hpddm.solve(A, f, sol, comm) storage = numpy.empty(2 * mu, order = 'F', dtype = hpddm.underlying) hpddm.schwarzComputeError(A, sol, f, storage) if rankWorld == 0: for nu in xrange(mu): if nu == 0: print(' --- error = ', end = '') else: print(' ', end = '') print('{:e} / {:e}'.format(storage[1 + 2 * nu], storage[2 * nu]), end = '') if mu > 1: print(' (rhs #{:d})'.format(nu + 1), end = '') print('') if it > 45: status = 1 else:
lu = scipy.sparse.linalg.spilu(csr.tocsc(), drop_tol = hpddm.optionApp(opt, b'drop_tol'), fill_factor = hpddm.optionApp(opt, b'fill_factor')) @hpddm.precondFunc def precond(y, x, n, m): if m == 1: x._shape_ = (n,) y._shape_ = (n,) x = numpy.ctypeslib.as_array(x, (n,)) y = numpy.ctypeslib.as_array(y, (n,)) else: x._shape_ = (m, n) y._shape_ = (m, n) x = numpy.ctypeslib.as_array(x, (m, n)).transpose() y = numpy.ctypeslib.as_array(y, (m, n)).transpose() x[:] = lu.solve(y[:]) it = hpddm.solve(Mat, precond, f, sol) status = 0 nrmb = numpy.linalg.norm(f, axis = 0) tmp = numpy.empty_like(f) hpddm.csrmv(Mat, sol, tmp) tmp -= f nrmAx = numpy.linalg.norm(tmp, axis = 0) if mu == 1: nrmb = [ nrmb ] nrmAx = [ nrmAx ] for nu in xrange(mu): if nu == 0: print(' --- residual = ', end = '') else: print(' ', end = '')
if nu.value > 0: if hpddm.optionApp(opt, b'nonuniform'): addr.contents.value += max(int(-addr.contents.value + 1), (-1)**rankWorld * rankWorld) hpddm.schwarzSolveGEVP(A, MatNeumann) nu = int(hpddm.optionVal(opt, b'geneo_nu')) else: nu = 1 deflation = numpy.ones((dof, nu), order = 'F', dtype = hpddm.scalar) hpddm.setVectors(hpddm.schwarzPreconditioner(A), nu, deflation) hpddm.initializeCoarseOperator(hpddm.schwarzPreconditioner(A), nu) hpddm.schwarzBuildCoarseOperator(A, hpddm.MPI_Comm.from_address(MPI._addressof(MPI.COMM_WORLD))) hpddm.schwarzCallNumfact(A) if rankWorld != 0: hpddm.optionRemove(opt, b'verbosity') comm = hpddm.getCommunicator(hpddm.schwarzPreconditioner(A)) it = hpddm.solve(A, f, sol, comm) storage = numpy.empty(2 * mu, order = 'F', dtype = hpddm.underlying) hpddm.schwarzComputeResidual(A, sol, f, storage) if rankWorld == 0: for nu in xrange(mu): if nu == 0: print(' --- residual = ', end = '') else: print(' ', end = '') print('{:e} / {:e}'.format(storage[1 + 2 * nu], storage[2 * nu]), end = '') if mu > 1: print(' (rhs #{:d})'.format(nu + 1), end = '') print('') if it > (60 if int(hpddm.optionVal(opt, b'krylov_method')) == 6 else 45): status = 1 else: