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

Revision 3793 - (show annotations)
Wed Feb 1 07:39:43 2012 UTC (7 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 3070 byte(s)
new implementation of FCT solver with some modifications to the python interface
 1 2 ######################################################## 3 # 4 # Copyright (c) 2003-2010 by University of Queensland 5 # Earth Systems Science Computational Center (ESSCC) 6 7 # 8 # Primary Business: Queensland, Australia 9 # Licensed under the Open Software License version 3.0 10 11 # 12 ######################################################## 13 14 __copyright__="""Copyright (c) 2003-2010 by University of Queensland 15 Earth Systems Science Computational Center (ESSCC) 16 http://www.uq.edu.au/esscc 17 Primary Business: Queensland, Australia""" 18 __license__="""Licensed under the Open Software License version 3.0 19 20 __url__= 21 22 # 23 # upwinding test moving a Gaussian hill around 24 # 25 # we solve U_,t + v_i u_,i =0 26 # 27 # the solution is given as u(x,t)=1/(4*pi*E*t)^{dim/2} * exp ( - |x-x_0(t)|^2/(4*E*t) ) 28 # 29 # where x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=2 and 30 # 31 # x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=3 32 # 33 # the solution is started from some time T0>0. 34 # 35 # We are using five quality messurements for u_h 36 # 37 # - inf(u_h) > 0 38 # - sup(u_h)/sup(u(x,t)) = sup(u_h)*(4*pi*E*t)^{dim/2} ~ 1 39 # - integrate(u_h) ~ 1 40 # - | x_0h-x_0 | ~ 0 where x_0h = integrate(x*u_h) 41 # - sigma_h/4*E*t ~ 1 where sigma_h=sqrt(integrate(length(x-x0h)**2 * u_h) * (DIM==3 ? sqrt(2./3.) :1 ) 42 # 43 # 44 from esys.escript import * 45 from esys.escript.linearPDEs import TransportPDE 46 #from esys.finley import Rectangle, Brick 47 from esys.ripley import Rectangle, Brick 48 from esys.weipa import saveVTK 49 from math import pi, ceil 50 NE=128 51 #NE=4 52 DIM=2 53 THETA=0.5 54 OMEGA0=1. 55 ALPHA=pi/4 56 T0=0 57 T_END=2.*pi 58 dt=1e-3*10*10 59 E=1.e-3 60 61 62 if DIM==2: 63 dom=Rectangle(NE,NE) 64 else: 65 dom=Brick(NE,NE,NE) 66 u0=dom.getX()[0] 67 # saveVTK("u.%s.vtu"%0,u=u0) 68 # print "XX"*80 69 #dom.setX(2*dom.getX()-1) 70 71 # set initial value 72 x=dom.getX() 73 r=sqrt(x[0]**2+(x[1]-1./3.)**2) 74 u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5)) 75 76 x=Function(dom).getX() 77 if DIM == 2: 78 V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0]) 79 else: 80 V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.]) 81 #=================== 82 fc=TransportPDE(dom,numEquations=1) 83 fc.getSolverOptions().setVerbosityOn() 84 fc.getSolverOptions().setODESolver(fc.getSolverOptions().LINEAR_CRANK_NICOLSON) 85 fc.getSolverOptions().setODESolver(fc.getSolverOptions().CRANK_NICOLSON) 86 fc.getSolverOptions().setODESolver(fc.getSolverOptions().BACKWARD_EULER) 87 x=Function(dom).getX() 88 fc.setValue(M=1,C=V) 89 90 c=0 91 saveVTK("u.%s.vtu"%c,u=u0) 92 fc.setInitialSolution(u0) 93 dt=fc.getSafeTimeStepSize() * 20. 94 print "dt = ",dt 95 t=T0 96 print("QUALITY FCT: time = %s pi"%(t/pi),inf(u0),sup(u0),integrate(u0)) 97 while t