1 |
# $Id$ |
2 |
import sys |
3 |
import os |
4 |
import unittest |
5 |
|
6 |
from esys.escript import * |
7 |
from esys.linearPDEs import * |
8 |
from esys.finley import * |
9 |
|
10 |
import numarray |
11 |
|
12 |
# |
13 |
# this test the assemblage of problems with periodic boundary conditions: |
14 |
# |
15 |
numElements=15 |
16 |
sml=0.1 |
17 |
# |
18 |
# test solution is u_ex=sin(2*Pi*n*x0)*...*sin(2*Pi*n*x_dim) |
19 |
# |
20 |
def TheTest(msh,constraints,reduce): |
21 |
n=ContinuousFunction(msh) |
22 |
x=n.getX() |
23 |
# set a test problem: |
24 |
u_ex=Scalar(1,what=n) |
25 |
for i in range(msh.getDim()): |
26 |
u_ex*=sin(2*Pi*x[i]) |
27 |
mypde=LinearPDE(msh) |
28 |
mypde.setValue(A=numarray.identity(msh.getDim()),D=sml,Y=(sml+4*Pi**2*msh.getDim())*u_ex,q=constraints,r=u_ex) |
29 |
mypde.setSymmetryOn() |
30 |
mypde.setDebugOn() |
31 |
mypde.setReducedOrderTo(reduce) |
32 |
return Lsup(mypde.getSolution()-u_ex)/Lsup(u_ex) |
33 |
|
34 |
max_error=0 |
35 |
max_text="none" |
36 |
for onElements in [False,True]: |
37 |
if onElements==True: |
38 |
onElmtext=", with elements on faces" |
39 |
else: |
40 |
onElmtext="" |
41 |
for order in [1,2]: |
42 |
for reduce in [False,True]: |
43 |
if reduce==True: |
44 |
redtext=",reduced" |
45 |
else: |
46 |
redtext="" |
47 |
for dim in [2,3]: |
48 |
if dim==2: |
49 |
# for i0 in [True,False]: |
50 |
# for i1 in [True,False]: |
51 |
for i0 in [True,True]: |
52 |
for i1 in [True,True]: |
53 |
msh=Rectangle(numElements,numElements,order,periodic0=i0,periodic1=i1,useElementsOnFace=onElements) |
54 |
n=ContinuousFunction(msh) |
55 |
x=n.getX() |
56 |
c=Scalar(0,what=n) |
57 |
if i0==False: |
58 |
c+=x[0].whereZero()+(x[0]-1.).whereZero() |
59 |
if i1==False: |
60 |
c+=x[1].whereZero()+(x[1]-1.).whereZero() |
61 |
error=TheTest(msh,c,reduce) |
62 |
text="Rectangle order = %d%s%s, periodic0= %d, periodic1= %d: error= %f"%(order,redtext,onElmtext,i0,i1,error) |
63 |
print "@@ ",text |
64 |
if error>max_error: |
65 |
max_error=error |
66 |
max_text=text |
67 |
elif dim==3: |
68 |
for i0 in [True,False]: |
69 |
for i1 in [True,False]: |
70 |
for i2 in [True,False]: |
71 |
msh=Brick(numElements,numElements,numElements,order,periodic0=i0,periodic1=i1,periodic2=i2,useElementsOnFace=onElements) |
72 |
n=ContinuousFunction(msh) |
73 |
x=n.getX() |
74 |
c=Scalar(0,what=n) |
75 |
if i0==False: |
76 |
c+=x[0].whereZero()+(x[0]-1.).whereZero() |
77 |
if i1==False: |
78 |
c+=x[1].whereZero()+(x[1]-1.).whereZero() |
79 |
if i2==False: |
80 |
c+=x[2].whereZero()+(x[2]-1.).whereZero() |
81 |
error=TheTest(msh,c,reduce) |
82 |
text="Brick order = %d%s%s, periodic0= %d, periodic1= %d, periodic2= %d: error= %f"%(order,redtext,onElmtext,i0,i1,i2,error) |
83 |
print "@@ ",text |
84 |
if error>max_error: |
85 |
max_error=error |
86 |
max_text=text |
87 |
|
88 |
print "@@@@ maximum error for :",max_text |