/[escript]/trunk/dudley/test/python/tp.py
ViewVC logotype

Contents of /trunk/dudley/test/python/tp.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (4 years, 5 months ago) by sshaw
File MIME type: text/x-python
File size: 2869 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
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-2013 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 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 from esys.escript import *
24 from esys.escript.linearPDEs import LinearPDE, TransportPDE
25 from esys.dudley import Rectangle
26 from esys.weipa import saveVTK
27
28 # dom=Rectangle(12,8,l0=1.5)
29 # dom=Rectangle(24,16,l0=1.5)
30 dom=Rectangle(48,32,l0=1.5)
31 # dom=Rectangle(8*48,8*32,l0=1.5)
32 # dom=Rectangle(120,80,l0=1.5)
33 V=Scalar(1.,Function(dom))*[-1.,0]
34 THETA=0.
35 fc=TransportPDE(dom,num_equations=1,theta=THETA)
36 fc.setTolerance(1.e-12)
37 fc.setValue(M=Scalar(1.,Function(dom)),C=V)
38 x=dom.getX()
39 x_0=[0.5,0.5]
40 sigma=0.075
41 u0=1.
42 for i in range(dom.getDim()):
43 u0=u0*exp(-(x[i]-x_0[i])**2/sigma**2)
44
45 u0=whereNonPositive(abs(x[0]-0.4)-0.2)*whereNonPositive(abs(x[1]-0.5)-0.2)
46 # f1=0.5
47 # f2=2.
48 # u0=f2*clip(x[0]-0.5,0.)-clip(0.5-x[0],0.)*f1+f1*0.5
49 # u0=exp(-3*(x[0]-2.)**2)
50 # u0=x[0]
51 u0/=Lsup(u0)
52 c=0
53 saveVTK("u.%s.vtu"%c,u=u0)
54 fc.setInitialSolution(u0)
55
56 t_end=0.6
57 dt=2.49999e-2*0+6.2499999e-02/4
58 dt_out=2.49999e-2*0+6.2499999e-02/4
59 c_stop=1
60 n_out=int(t_end/dt+0.5)
61 print(n_out)
62 t=0.
63 t_out=0
64 c_out=0
65 c=0
66 print(t,": range u",inf(u0),sup(u0),integrate(u0,Function(dom)))
67 while t<t_end and c< c_stop:
68 print("time step t=",t+dt)
69 u=fc.solve(dt)
70 print(t+dt,": range u",inf(u),sup(u),integrate(u,Function(dom)))
71 c+=1
72 t+=dt
73 if t>=t_out+dt_out:
74 c_out,t_out=c_out+1,t_out+dt_out
75 saveVTK("u.%s.vtu"%c_out,u=u)
76 print("write time step ",c,"(t=%s) to file u.%s.vtu"%(t,c_out))
77
78 if True:
79 pde=LinearPDE(dom)
80 pde.setValue(D=1.,C=-THETA*dt*V)
81 pde.setTolerance(1e-12)
82 t=0.
83 t_out=0
84 c_out=0
85 c=0
86 u=u0
87 print(t,": range u2",inf(u0),sup(u0),integrate(u0,Function(dom)))
88 while t<t_end and c< c_stop:
89 print("time step t=",t+dt)
90 pde.setValue(Y=u+(1.-THETA)*dt*inner(V,grad(u)))
91 u=pde.getSolution(verbose=True)
92 print(t+dt,": range u2",inf(u),sup(u),integrate(u,Function(dom)))
93 c+=1
94 t+=dt
95 if t>=t_out+dt_out:
96 c_out,t_out=c_out+1,t_out+dt_out
97 saveVTK("u2.%s.vtu"%c_out,u=u)
98 print("write time step ",c,"(t=%s) to file u2.%s.vtu"%(t,c_out))

  ViewVC Help
Powered by ViewVC 1.1.26