Contents of /branches/diaplayground/poisson.py

Revision 5122 - (show annotations)
Thu Aug 21 04:32:39 2014 UTC (4 years, 7 months ago) by caltinay
File MIME type: text/x-python
File size: 1745 byte(s)
```Fast-forward to latest trunk to be able to use both Paso or cusp.

```
 1 from esys.escript import * 2 from esys.escript.linearPDEs import LinearPDE,SolverOptions 3 from esys.ripley import Rectangle, Brick 4 from time import time 5 6 BLOCKSIZE=1 7 8 dom = Rectangle(l0=1.,l1=1.,n0=299, n1=299) 9 #dom = Brick(l0=1.,l1=1.,n0=51, n1=51, n2=17) 10 x = dom.getX() 11 gammaD = whereZero(x[0])+whereZero(x[1]) 12 13 def solve(target): 14 pde = LinearPDE(dom, numEquations=BLOCKSIZE, numSolutions=BLOCKSIZE) 15 A = pde.createCoefficient("A") 16 q = pde.createCoefficient("q") 17 Y_reduced = pde.createCoefficient("Y_reduced") 18 19 if BLOCKSIZE == 1: 20 A = kronecker(dom) 21 q = gammaD 22 Y_reduced = 1. 23 else: 24 for i in range(BLOCKSIZE): 25 A[i,:,i,:] = kronecker(dom)*(i+1) 26 q[i] = gammaD 27 Y_reduced[i] = 1. 28 29 pde.setValue(A=A, Y_reduced=Y_reduced, q=q) 30 pde.getSolverOptions().setPackage(SolverOptions.PASO) 31 pde.getSolverOptions().setSolverTarget(target) 32 pde.getSolverOptions().setSolverMethod(SolverOptions.PRES20) 33 pde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB) 34 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG) 35 pde.getSolverOptions().setPreconditioner(SolverOptions.NO_PRECONDITIONER) 36 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI) 37 pde.getSolverOptions().setVerbosityOn() 38 #pde.setDebugOn() 39 #rhs=pde.getRightHandSide() 40 #saveDataCSV('/tmp/rhs.csv',rhs=rhs) 41 #pde.getSystem()[0].saveMM('/tmp/poissonripley.mtx') 42 t0=time() 43 print("pde.getSolution()") 44 x = pde.getSolution() 45 t1=time() 46 print("Solver Time: %s"%(t1-t0)) 47 print("Solution: %s..%s"%(inf(x),sup(x))) 48 print(x) 49 50 51 for target in SolverOptions.TARGET_CPU,SolverOptions.TARGET_GPU: 52 solve(target) 53 print("-------") 54