/[escript]/trunk/finley/test/python/blocktest.py
ViewVC logotype

Contents of /trunk/finley/test/python/blocktest.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3981 - (show annotations)
Fri Sep 21 02:47:54 2012 UTC (7 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 3429 byte(s)
First pass of updating copyright notices
1 #
2 # this script is testing block solvers for PDEs
3 #
4 #
5 # - u_{j,ii} + b*u_j+ a*sum_{k<>j} (u_j-u_k) = F_j
6 #
7 # where a controls the degree of coupling and b the degree of diagonal dominance.
8 # a and b may have any value.
9 #
10 # The domain needs to be a unit square or cube with any type of mesh
11 #
12 #
13 ##############################################################################
14 #
15 # Copyright (c) 2003-2012 by University of Queensland
16 # http://www.uq.edu.au
17 #
18 # Primary Business: Queensland, Australia
19 # Licensed under the Open Software License version 3.0
20 # http://www.opensource.org/licenses/osl-3.0.php
21 #
22 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
23 # Development since 2012 by School of Earth Sciences
24 #
25 ##############################################################################
26
27 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
28 http://www.uq.edu.au
29 Primary Business: Queensland, Australia"""
30 __license__="""Licensed under the Open Software License version 3.0
31 http://www.opensource.org/licenses/osl-3.0.php"""
32 __url__="https://launchpad.net/escript-finley"
33
34 from esys.escript import *
35 from esys.escript.linearPDEs import LinearPDE
36 import esys.finley as finley
37
38 TOL=1.e-8
39
40 def runTest(dom, n=1, a=0, b=0):
41 print("================== TEST : n= %s a=%s b=%s ================"%(n,a,b))
42 DIM=dom.getDim()
43 normal=dom.getNormal()
44 mypde=LinearPDE(dom, numEquations=n, numSolutions=n)
45 x=dom.getX()
46 A=mypde.createCoefficient("A")
47 D=mypde.createCoefficient("D")
48 Y=mypde.createCoefficient("Y")
49 y=mypde.createCoefficient("y")
50 q=mypde.createCoefficient("q")
51 if n==1:
52 u_ref=Scalar(0.,Solution(dom))
53 for j in range(DIM):
54 q+=whereZero(x[j])
55 A[j,j]=1
56 y+=sin(sqrt(2.))*normal[0]
57 Y+=b*x[0]*sin(sqrt(2.))
58 D+=b
59 u_ref=x[0]*sin(sqrt(2.))
60 else:
61 u_ref=Data(0.,(n,),Solution(dom))
62 for i in range(n):
63 for j in range(DIM):
64 q[i]+=whereZero(x[j])
65 A[i,j,i,j]=1
66 if j == i%DIM: y[i]+=sin(i+sqrt(2.))*normal[j]
67 for j in range(n):
68 if i==j:
69 D[i,i]=b+(n-1)*a
70 Y[i]+=b*x[i%DIM]*sin(i+sqrt(2.))
71 else:
72 D[i,j]=-a
73 Y[i]+=a*(x[i%DIM]*sin(i+sqrt(2.))-x[j%DIM]*sin(j+sqrt(2.)))
74 u_ref[i]=x[i%DIM]*sin(i+sqrt(2.))
75
76 # - u_{j,ii} + b*u_i+ a*sum_{k<>j} (u_i-u_k) = F_j
77
78 mypde.setValue(A=A, D=D, y=y, q=q, r=u_ref, Y=Y)
79 mypde.getSolverOptions().setVerbosityOn()
80 mypde.getSolverOptions().setTolerance(TOL)
81 mypde.setSymmetryOn()
82 u=mypde.getSolution()
83 error=Lsup(u-u_ref)/Lsup(u_ref)
84 print("error = ",error)
85 if error > 10*TOL: print("XXXXXXXXXX Error to large ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
86
87 domain=finley.Rectangle(10,20,1,l0=1.,l1=1.0)
88 # or Brick or ReadMesh
89 runTest(dom=domain, n=1, b=0)
90 runTest(dom=domain, n=1, b=5)
91 runTest(dom=domain, n=1, b=50)
92
93 runTest(dom=domain, n=2, a=0, b=0)
94 runTest(dom=domain, n=2, a=5, b=0)
95 runTest(dom=domain, n=2, a=50, b=0)
96
97 runTest(dom=domain, n=2, a=0, b=10)
98 runTest(dom=domain, n=2, a=5, b=10)
99 runTest(dom=domain, n=2, a=50, b=10)
100
101 runTest(dom=domain, n=3, a=0, b=0)
102 runTest(dom=domain, n=3, a=5, b=0)
103 runTest(dom=domain, n=3, a=50, b=0)
104
105 runTest(dom=domain, n=3, a=0, b=10)
106 runTest(dom=domain, n=3, a=5, b=10)
107 runTest(dom=domain, n=3, a=50, b=10)

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26