# Contents of /trunk/finley/test/python/FCT_test2.py

Revision 1476 - (show annotations)
Mon Apr 7 23:38:50 2008 UTC (11 years, 5 months ago) by gross
File MIME type: text/x-python
File size: 3406 byte(s)
```Jacobian-free Newton method added to Paso
```
 1 # 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 from esys.escript import * 24 from esys.escript.linearPDEs import LinearSinglePDE, TransportPDE 25 from esys.finley import Rectangle, Brick 26 from math import pi, ceil 27 NE=128 28 NE=64 29 DIM=2 30 THETA=0.5 31 OMEGA0=1. 32 ALPHA=pi/4 33 T0=0.5*pi 34 T_END=2.5*pi 35 dt=1e-3*10 36 E=1.e-3 37 TEST_SUPG=False or True 38 39 40 def getCenter(t): 41 if DIM==2: 42 x0=[cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5] 43 x0=[-sin(OMEGA0*t)*0.5,cos(OMEGA0*t)*0.5] 44 else: 45 x0=[cos(ALPHA)*cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5,-sin(ALPHA)*cos(OMEGA0*t)*0.5] 46 return x0 47 def QUALITY(t,u_h): 48 dom=u_h.getDomain() 49 x=dom.getX() 50 a=inf(u_h) 51 b=sup(u_h)*(4*pi*E*t)**(DIM/2.)-1. 52 c=integrate(u_h,Function(dom))-1. 53 x0=getCenter(t) 54 x0h=integrate(x*u_h,Function(dom)) 55 d=length(x0-x0h) 56 sigma_h2=sqrt(integrate(length(x-x0h)**2 * u_h, Function(dom))) 57 if DIM == 3: sigma_h2*=sqrt(2./3.) 58 e=sigma_h2/sqrt(4*E*t)-1 59 # return a,b,c,e,1./(4*pi*E*t)**(DIM/2.) 60 return d,e 61 # return a,b,c,d,e 62 63 64 65 66 if DIM==2: 67 dom=Rectangle(NE,NE) 68 else: 69 dom=Brick(NE,NE,NE) 70 dom.setX(2*dom.getX()-1) 71 72 # set initial value 73 x=dom.getX() 74 u0=1/(4.*pi*E*T0)**(DIM/2.)*exp(-length(dom.getX()-getCenter(T0))**2/(4.*E*T0)) 75 76 print "QUALITY ",QUALITY(T0,u0) 77 78 x=Function(dom).getX() 79 if DIM == 2: 80 V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0]) 81 else: 82 V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.]) 83 #=================== 84 fc=TransportPDE(dom,num_equations=1,theta=THETA) 85 x=Function(dom).getX() 86 fc.setValue(M=Scalar(1.,Function(dom)),C=V,A=-Scalar(E,Function(dom))*kronecker(dom)) 87 #============== 88 if TEST_SUPG: 89 supg=LinearSinglePDE(dom) 90 supg.setValue(D=1.) 91 supg.setSolverMethod(supg.LUMPING) 92 dt_supg=1./(1./inf(dom.getSize()/length(V))+1./inf(dom.getSize()**2/E))*0.3 93 u_supg=u0*1. 94 95 c=0 96 saveVTK("u.%s.xml"%c,u=u0) 97 fc.setInitialSolution(u0) 98 t=T0 99 while t