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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (19 months, 1 week ago) by jfenwick
File MIME type: text/x-python
File size: 4374 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

  ViewVC Help
Powered by ViewVC 1.1.26