# Diff of /trunk/finley/test/python/SolveTest.py

revision 115 by jgs, Fri Mar 4 07:12:47 2005 UTC revision 126 by jgs, Fri Jul 22 03:53:08 2005 UTC
# Line 17  Line 17
17  from esys.escript import *  from esys.escript import *
18  from esys.linearPDEs import *  from esys.linearPDEs import *
19  import esys.finley as pdelib  import esys.finley as pdelib
20    from time import time
21
22  from numarray import *  from numarray import *
23
24  # these values are currently fixed:  # these values are currently fixed:
25  len_x0=1.  len_x0=1.
26  alpha=0.1  alpha=10.
27    tm=0
28
29  #############################################################################################################3  #############################################################################################################3
30  def solveVector(numDim, totalNumElem, len_x0, alpha, solver_method,prec):  def solveVector(numDim, totalNumElem, len_x0, alpha, solver_method,prec):
31
32        if prec=="":
33            prec_id=0
34        else:
35           prec_id=eval("LinearPDE.%s"%prec)
36        solver_method_id=eval("LinearPDE.%s"%solver_method)
37      print "Vector solver:"      print "Vector solver:"
38      recDim=array([len_x0,1.,1.])      recDim=array([len_x0,1.,1.])
39      # Define Computational Domain      # Define Computational Domain
# Line 74  def solveVector(numDim, totalNumElem, le Line 81  def solveVector(numDim, totalNumElem, le
81      # Build the pdelib System Matrix and RHS      # Build the pdelib System Matrix and RHS
82      mypde=LinearPDE(mesh)      mypde=LinearPDE(mesh)
83      mypde.setValue(A = A, Y = - 2 * alpha * (meshDim - 1)*ones(meshDim), q = bndryMask, r = u)      mypde.setValue(A = A, Y = - 2 * alpha * (meshDim - 1)*ones(meshDim), q = bndryMask, r = u)
84      mypde.setSolverMethod(solver_method)      mypde.setSolverMethod(solver_method_id)
85        # mypde.getOperator().saveMM("g.mm")
86
87      # Solve for Approximate Solution      # Solve for Approximate Solution
88      u_approx = mypde.getSolution(preconditioner=prec,iter_max=10000)      tm=time()
89        u_approx = mypde.getSolution(preconditioner=prec_id,iter_max=10000)
90        tm=time()-tm
91
92      # Report Results      # Report Results
93      error=Lsup(u - u_approx)/Lsup(u)      error=Lsup(u - u_approx)/Lsup(u)
94      print "    error L^sup Norm : ", error      print "@@ Vector %d : %d : %s(%s): error L^sup Norm : %e, time %e"%(mypde.getDim(),totElem,solver_method,prec,error,tm)
print "    residual L^sup Norm : ", Lsup(mypde.getResidual(u_approx))
95
96      return error      return error
97
# Line 90  def solveVector(numDim, totalNumElem, le Line 99  def solveVector(numDim, totalNumElem, le
99
100  def solveScalar(numDim, totalNumElem, len_x0, alpha, solver_method,prec):  def solveScalar(numDim, totalNumElem, len_x0, alpha, solver_method,prec):
101
102        if prec=="":
103            prec_id=0
104        else:
105           prec_id=eval("LinearPDE.%s"%prec)
106        solver_method_id=eval("LinearPDE.%s"%solver_method)
107      print "Scalar solver:"      print "Scalar solver:"
108      recDim=array([len_x0,1.,1.])      recDim=array([len_x0,1.,1.])
109      # Define Computational Domain      # Define Computational Domain
# Line 128  def solveScalar(numDim, totalNumElem, le Line 142  def solveScalar(numDim, totalNumElem, le
142      # Build the pdelib System Matrix and RHS      # Build the pdelib System Matrix and RHS
143      mypde=LinearPDE(mesh)      mypde=LinearPDE(mesh)
144      mypde.setValue(A = identity(numDim), D = alpha, Y = alpha * u - 2 * meshDim, q = bndryMask, r = u)      mypde.setValue(A = identity(numDim), D = alpha, Y = alpha * u - 2 * meshDim, q = bndryMask, r = u)
145      mypde.setSolverMethod(solver_method)      mypde.setSolverMethod(solver_method_id)
146
147      # Solve for Approximate Solution      # Solve for Approximate Solution
148      u_approx = mypde.getSolution(preconditioner=prec,iter_max=10000)      tm=time()
149        u_approx = mypde.getSolution(preconditioner=prec_id,iter_max=10000)
150        tm=time()-tm
151
152      # Report Results      # Report Results
153      error=Lsup(u - u_approx)/Lsup(u)      error=Lsup(u - u_approx)/Lsup(u)
154      print "    error L^sup Norm : ", error      print "@@ Scalar %d : %d : %s(%s): error L^sup Norm : %e, time %e"%(mypde.getDim(),totElem,solver_method,prec,error,tm)
print "    residual L^sup Norm : ", Lsup(mypde.getResidual(u_approx))
155
156      return error      return error
157
# Line 146  def solveScalar(numDim, totalNumElem, le Line 161  def solveScalar(numDim, totalNumElem, le
161  print "Test is started:"  print "Test is started:"
162  print "----------------"  print "----------------"
163  error=0.  error=0.
164  # for numDim in [2,3]:  for numDim in [2, 3]:
165  for numDim in [3]:     # for totalNumElem in [51200]:
166     for totalNumElem in [100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400]:     for totalNumElem in [100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400,204800]:
167        # for problem in [solveScalar,solveVector]:        for problem in [solveScalar,solveVector]:
168        for problem in [solveScalar]:        #for problem in [solveVector]:
169           # for solver_method in [ LinearPDE.PRES20, LinearPDE.PCG, LinearPDE.DIRECT, LinearPDE.BICGSTAB]:           # error=max([problem(numDim, totalNumElem, len_x0, alpha,"PCG",""),error])
170           for solver_method in [ LinearPDE.PCG ]:           error=max([problem(numDim, totalNumElem, len_x0, alpha,"DIRECT",""),error])
171              # for prec in [ LinearPDE.JACOBI, LinearPDE.ILU0 ]:           #if totalNumElem*2**numDim*numDim< 200000: error=max([problem(numDim, totalNumElem, len_x0, alpha,"DIRECT",""),error])
172              for prec in [ LinearPDE.ILU0 ]:           # for solver_method in [ "PCG" ]:
173                 error=max([problem(numDim, totalNumElem, len_x0, alpha, solver_method,prec),error])           #    for prec in [ "JACOBI", "ILU0" ]:
174             #       error=max([problem(numDim, totalNumElem, len_x0, alpha, solver_method,prec),error])
175  print "----------------"  print "----------------"
176  print "maximum error over all tests is ",error  print "maximum error over all tests is ",error
177  print "----------------"  print "----------------"

Legend:
 Removed from v.115 changed lines Added in v.126