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

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: 4271 byte(s)
```First pass of updating copyright notices
```
 1 2 ############################################################################## 3 # 4 # Copyright (c) 2003-2012 by University of Queensland 5 6 # 7 # Primary Business: Queensland, Australia 8 # Licensed under the Open Software License version 3.0 9 10 # 11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC) 12 # Development since 2012 by School of Earth Sciences 13 # 14 ############################################################################## 15 16 __copyright__="""Copyright (c) 2003-2012 by University of Queensland 17 http://www.uq.edu.au 18 Primary Business: Queensland, Australia""" 19 __license__="""Licensed under the Open Software License version 3.0 20 21 __url__= 22 23 # 24 # upwinding test moving a Gaussian hill around 25 # 26 # we solve U_,t - E *u_,ii + v_i u_,i =0 (E is small) 27 # 28 # the solution is given as u(x,t)=1/(4*pi*E*t)^{dim/2} * exp ( - |x-x_0(t)|^2/(4*E*t) ) 29 # 30 # where x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=2 and 31 # 32 # x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=3 33 # 34 # the solution is started from some time T0>0. 35 # 36 # We are using five quality messurements for u_h 37 # 38 # - inf(u_h) > 0 39 # - sup(u_h)/sup(u(x,t)) = sup(u_h)*(4*pi*E*t)^{dim/2} ~ 1 40 # - integrate(u_h) ~ 1 41 # - | x_0h-x_0 | ~ 0 where x_0h = integrate(x*u_h) 42 # - sigma_h/4*E*t ~ 1 where sigma_h=sqrt(integrate(length(x-x0h)**2 * u_h) * (DIM==3 ? sqrt(2./3.) :1 ) 43 # 44 # 45 from esys.escript import * 46 from esys.escript.linearPDEs import LinearSinglePDE, TransportPDE 47 from esys.finley import Rectangle, Brick 48 from esys.weipa import saveVTK 49 from math import pi, ceil 50 NE=128 51 NE=64 52 DIM=2 53 THETA=0.5 54 OMEGA0=1. 55 ALPHA=pi/4 56 T0=0.5*pi 57 T_END=2.5*pi 58 dt=1e-3*10 59 E=1.e-3 60 TEST_SUPG=False or True 61 62 63 def getCenter(t): 64 if DIM==2: 65 x0=[cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5] 66 x0=[-sin(OMEGA0*t)*0.5,cos(OMEGA0*t)*0.5] 67 else: 68 x0=[cos(ALPHA)*cos(OMEGA0*t)*0.5,-sin(OMEGA0*t)*0.5,-sin(ALPHA)*cos(OMEGA0*t)*0.5] 69 return x0 70 def QUALITY(t,u_h): 71 dom=u_h.getDomain() 72 x=dom.getX() 73 a=inf(u_h) 74 b=sup(u_h)*(4*pi*E*t)**(DIM/2.)-1. 75 c=integrate(u_h,Function(dom))-1. 76 x0=getCenter(t) 77 x0h=integrate(x*u_h,Function(dom)) 78 d=length(x0-x0h) 79 sigma_h2=sqrt(integrate(length(x-x0h)**2 * u_h, Function(dom))) 80 if DIM == 3: sigma_h2*=sqrt(2./3.) 81 e=sigma_h2/sqrt(4*E*t)-1 82 # return a,b,c,e,1./(4*pi*E*t)**(DIM/2.) 83 return d,e 84 # return a,b,c,d,e 85 86 87 88 89 if DIM==2: 90 dom=Rectangle(NE,NE) 91 else: 92 dom=Brick(NE,NE,NE) 93 dom.setX(2*dom.getX()-1) 94 95 # set initial value 96 x=dom.getX() 97 u0=1/(4.*pi*E*T0)**(DIM/2.)*exp(-length(dom.getX()-getCenter(T0))**2/(4.*E*T0)) 98 99 print("QUALITY ",QUALITY(T0,u0)) 100 101 x=Function(dom).getX() 102 if DIM == 2: 103 V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0]) 104 else: 105 V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.]) 106 #=================== 107 fc=TransportPDE(dom,num_equations=1,theta=THETA) 108 x=Function(dom).getX() 109 fc.setValue(M=Scalar(1.,Function(dom)),C=V,A=-Scalar(E,Function(dom))*kronecker(dom)) 110 #============== 111 if TEST_SUPG: 112 supg=LinearSinglePDE(dom) 113 supg.setValue(D=1.) 114 supg.setSolverMethod(supg.LUMPING) 115 dt_supg=1./(1./inf(dom.getSize()/length(V))+1./inf(dom.getSize()**2/E))*0.3 116 u_supg=u0*1. 117 118 c=0 119 saveVTK("u.%s.vtu"%c,u=u0) 120 fc.setInitialSolution(u0) 121 t=T0 122 while t