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

Annotation of /trunk/finley/test/python/FCT_test2.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1410 - (hide annotations)
Thu Feb 7 04:24:00 2008 UTC (11 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 3402 byte(s)
a new version of the algebric upwinding a. flux limiter
1 gross 1400 #
2     # upwinding test moving a Gaussian hill around
3     #
4     # we solve U_,t - E *u_,ii + v_i u_,i =0 (E is small)
5     #
6     # the solution is given as u(x,t)=1/(4*pi*E*t)^{dim/2} * exp ( - |x-x_0(t)|^2/(4*E*t) )
7     #
8     # where x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=2 and
9     #
10     # x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=3
11     #
12     # the solution is started from some time T0>0.
13     #
14     # We are using five quality messurements for u_h
15     #
16     # - inf(u_h) > 0
17     # - sup(u_h)/sup(u(x,t)) = sup(u_h)*(4*pi*E*t)^{dim/2} ~ 1
18     # - integrate(u_h) ~ 1
19     # - | x_0h-x_0 | ~ 0 where x_0h = integrate(x*u_h)
20     # - sigma_h/4*E*t ~ 1 where sigma_h=sqrt(integrate(length(x-x0h)**2 * u_h) * (DIM==3 ? sqrt(2./3.) :1 )
21     #
22     #
23 gross 1410 from esys.escript import *
24     from esys.escript.linearPDEs import LinearSinglePDE, TransportPDE
25     from esys.finley import Rectangle, Brick
26 gross 1400 from math import pi, ceil
27 gross 1410 NE=128
28 gross 1400 DIM=2
29     THETA=0.5
30     OMEGA0=1.
31     ALPHA=pi/4
32     T0=0.5*pi
33 gross 1410 T_END=2.5*pi
34     dt=1e-3*10
35     E=1.e-3
36     TEST_SUPG=False # or True
37 gross 1400
38 gross 1410
39 gross 1400 def getCenter(t):
40     if DIM==2:
41     x0=[cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5]
42 gross 1410 x0=[-sin(OMEGA0*t)*0.5,cos(OMEGA0*t)*0.5]
43 gross 1400 else:
44     x0=[cos(ALPHA)*cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5,-sin(ALPHA)*cos(OMEGA0*t)*0.5]
45     return x0
46     def QUALITY(t,u_h):
47     dom=u_h.getDomain()
48     x=dom.getX()
49     a=inf(u_h)
50     b=sup(u_h)*(4*pi*E*t)**(DIM/2.)-1.
51     c=integrate(u_h,Function(dom))-1.
52     x0=getCenter(t)
53     x0h=integrate(x*u_h,Function(dom))
54     d=length(x0-x0h)
55     sigma_h2=sqrt(integrate(length(x-x0h)**2 * u_h, Function(dom)))
56     if DIM == 3: sigma_h2*=sqrt(2./3.)
57     e=sigma_h2/sqrt(4*E*t)-1
58 gross 1410 # return a,b,c,e,1./(4*pi*E*t)**(DIM/2.)
59     return b, d
60     # return a,b,c,d,e
61 gross 1400
62    
63 gross 1368
64    
65 gross 1400 if DIM==2:
66     dom=Rectangle(NE,NE)
67     else:
68     dom=Brick(NE,NE,NE)
69     dom.setX(2*dom.getX()-1)
70    
71     # set initial value
72 gross 1370 x=dom.getX()
73 gross 1400 u0=1/(4.*pi*E*T0)**(DIM/2.)*exp(-length(dom.getX()-getCenter(T0))**2/(4.*E*T0))
74 gross 1371
75 gross 1400 print "QUALITY ",QUALITY(T0,u0)
76    
77     x=Function(dom).getX()
78     if DIM == 2:
79 gross 1410 V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0])
80 gross 1400 else:
81     V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.])
82     #===================
83     fc=TransportPDE(dom,num_equations=1,theta=THETA)
84     x=Function(dom).getX()
85     fc.setValue(M=Scalar(1.,Function(dom)),C=V,A=-Scalar(E,Function(dom))*kronecker(dom))
86     #==============
87     if TEST_SUPG:
88     supg=LinearSinglePDE(dom)
89     supg.setValue(D=1.)
90     supg.setSolverMethod(supg.LUMPING)
91     dt_supg=1./(1./inf(dom.getSize()/length(V))+1./inf(dom.getSize()**2/E))*0.3
92     u_supg=u0*1.
93    
94 gross 1370 c=0
95 gross 1400 saveVTK("u.%s.xml"%c,u=u0)
96     fc.setInitialSolution(u0)
97     t=T0
98 gross 1410 while t<T_END:
99 gross 1370 print "time step t=",t+dt
100     u=fc.solve(dt)
101 gross 1400 if TEST_SUPG:
102     #========== supg tests ================
103     nn=max(ceil(dt/dt_supg),1.)
104     dt2=dt/nn
105     nnn=0
106     while nnn<nn :
107     supg.setValue(X=-dt2/2*E*grad(u_supg),Y=u_supg+dt2/2*inner(V,grad(u_supg)))
108     u2=supg.getSolution()
109     supg.setValue(X=-dt2*E*grad(u2),Y=u_supg+dt2*inner(V,grad(u2)))
110     u_supg=supg.getSolution()
111     nnn+=1
112 gross 1370 c+=1
113     t+=dt
114 gross 1410 print "QUALITY FCT: time = %s pi"%(t/pi),QUALITY(t,u)
115 gross 1400 if TEST_SUPG:
116     print "QUALITY SUPG: ",QUALITY(t,u_supg)
117     # saveVTK("u.%s.xml"%c,u=u,u_supg=u_supg)
118     else:
119     # saveVTK("u.%s.xml"%c,u=u)
120     pass
121     # if c == 20: 1/0

  ViewVC Help
Powered by ViewVC 1.1.26