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