def solvePoisson(nx, ny):
    # Create the DA.

    da = PETSc.DA().create([nx, ny],
                           stencil_width=1,
                           boundary_type=('ghosted', 'ghosted'))

    pde = Poisson2D(da)
    b = pde.formRHS()
    pde.setupSolver()
    print "Solving using", pde.solver_name

    # Solve!
    tic = PETSc.Log().getTime()
    pde.solve(b, pde.x)
    toc = PETSc.Log().getTime()
    time = toc - tic
    timePerGrid = time / nx / ny

    # output performance/convergence information
    its = pde.ksp.getIterationNumber()
    rnorm = pde.ksp.getResidualNorm()
    print "Nx Ny its    ||r||_2     ElapsedTime (s)    Elapsed Time/N_tot"
    print nx, ny, its, rnorm, time, timePerGrid

    rh = pde.ksp.getConvergenceHistory()

    filename = '{0}_{1}x{2}.npz'.format(pde.solver_name, nx, ny)
    np.savez(filename,
             rhist=rh,
             npts=np.array([nx, ny]),
             name=pde.solver_name,
             time=time)
    return pde, time, timePerGrid
示例#2
0
        def __init__(self,
                     filename,
                     verbose=True,
                     showlog=False,
                     *args,
                     **kwargs):

            self.showlog = showlog
            if self.showlog:
                self.log = _PETSc.Log()
                self.log.begin()

            self.modelRunTime = clock()
            self.verbose = verbose

            _ReadYaml.__init__(self, filename)

            _UnstMesh.__init__(self, self.meshFile, *args, **kwargs)

            _WriteMesh.__init__(self)

            # Surface processes initialisation
            _SPMesh.__init__(self, *args, **kwargs)

            # Pit filling algorithm initialisation
            _UnstPit.__init__(self, *args, **kwargs)

            # Get external forces
            _UnstMesh.applyForces(self)
            if MPIrank == 0:
                print('--- Initialisation Phase (%0.02f seconds)' %
                      (clock() - self.modelRunTime))

            return
示例#3
0
def solveDiffusion(nx, ny, inputd):
    # Create the DA and setup the problem
    if inputd.kspType == 'sd':
        U = 0.0
        self = 0.0
        [M, R, row, col, val] = build_A(inputd, self)
        tic = PETSc.Log().getTime()
        U = dsolve.spsolve(M, R, use_umfpack=True)  #Direct solver
        toc = PETSc.Log().getTime()
        its = 1.0
        rnorm = np.linalg.norm(M * U - R)
        pde = 0.0
    else:
        da = PETSc.DA().create([nx, ny],
                               stencil_width=1,
                               boundary_type=('ghosted', 'ghosted'))
        pde = diffusion2D(da)
        pde.setupSolver(inputd)
        print "Solving using", pde.solver_name
        #Now solve
        tic = PETSc.Log().getTime()
        pde.solve(pde.b, pde.x)
        toc = PETSc.Log().getTime()
        its = pde.ksp.getIterationNumber()
        rnorm = pde.ksp.getResidualNorm()
        M = 0.0
        U = M

    # output performance/convergence information
    time = toc - tic
    timePerGrid = time / nx / ny

    #rnorm = np.linalg.norm(M*U-R)

    print "Nx Ny its    ||r||_2     ElapsedTime (s)    Elapsed Time/N_tot"
    print nx, ny, its, rnorm, time, timePerGrid

    return pde, time, timePerGrid, its, rnorm, U, M
示例#4
0
ts.setDM(dm)
ts.setRHSFunction(convdiff_problem.rhs, rhs)
ts.setDuration(100, 1.e10)

# --------------------------------------------------------------------------------
# finish the TS setup
# --------------------------------------------------------------------------------
# set any -ts commend-line options (including those we checked above)
ts.setFromOptions()

# create an initial guess
field = dm.createGlobalVector()
convdiff_problem.create_initial_guess(field)

# have fun (and measure how long fun takes)
log = PETSc.Log()
print(f"Flops logged: {log.getFlops()}")
import cProfile
start = time.clock()
cProfile.run("ts.solve(field)")
end = time.clock()
print(f"Flops logged: {log.getFlops()}")
# and plot
U = dm.createNaturalVector()
dm.globalToNatural(field, U)

# for debugging
lf_ = convdiff_problem.dm.getVecArray(convdiff_problem.local_field)
f_ = convdiff_problem.dm.getVecArray(field)
sol_ = convdiff_problem.dm.getVecArray(ts.getSolution())
rhs_ = convdiff_problem.dm.getVecArray(rhs)
示例#5
0
#OP2.mult(psi0,O2psi0);
#// O2|psi0> is also stored
#//---------------------------------------------------

#//Begining of the Chebyshev recursion
psim = psi0.copy()
psimm1 = psi0.copy()
psimp1 = psi0.copy()

#O2psim1 = O2psi0.copy()
#O2psim2 = O2psi0.copy()
#O2psimp1 = O2psi0.copy()

psitmp = psi0.copy()

T1 = PETSc.Log().getTime()

#//Doing the recursion
for nn in range(chebdeg):

    if (nn == 0):
        #|psi_0>=I|psi>
        psimp1 = psi0.copy()
        psim = psi0.copy()

    elif (nn == 1):
        #|psi_1>=H|psi>
        psimm1 = psim.copy()
        H.mult(psi0, psim)

    else: