/[escript]/trunk/doc/examples/geotutorial/forward_euler.py
ViewVC logotype

Contents of /trunk/doc/examples/geotutorial/forward_euler.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 6 months ago) by sshaw
File MIME type: text/x-python
File size: 2526 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 ##############################################################################
2 #
3 # Copyright (c) 2003-2015 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15 from __future__ import division, print_function
16
17 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 # import tools
25 from esys.escript import *
26 from esys.escript.linearPDEs import LinearPDE
27 try:
28 from esys.dudley import Rectangle
29 HAVE_DUDLEY = True
30 except ImportError:
31 HAVE_DUDLEY = False
32 from esys.weipa import saveVTK
33
34 if not HAVE_DUDLEY:
35 print("Dudley module not available")
36 else:
37 # end of simulation time
38 t_end=0.1
39 # dimensions:
40 L0=1.;L1=1.
41 # location, size and value of heat source
42 xc=[0.3,0.4]; r=0.1; Qc=3000
43 # material parameter
44 k=1.; rhocp=100;
45 # bottom temperature:
46 T_bot=100
47 # generate domain:
48 mydomain=Rectangle(l0=L0,l1=L1,n0=20,n1=20)
49 x=mydomain.getX()
50 # set boundray temperature:
51 T_D=T_bot/L1*(L1-x[1])
52 # set heat source:
53 Q=Qc*whereNegative(length(x-xc)-r)
54 # time step size:
55 dt=0.01
56 # or use adaptive choice dt=0.05*inf(rhocp*mydomain.getSize()**2/k)
57 print("time step size = %s"%dt)
58 # generate domain:
59 mypde=LinearPDE(mydomain)
60 mypde.setSymmetryOn()
61 # set PDE coefficients:
62 mypde.setValue(D=rhocp,
63 r=T_D, q=whereZero(x[1])+whereZero(x[1]-L1))
64 # initial temperature
65 T=T_D
66 # step counter and time marker:
67 N=0; t=0
68 # stop when t_end is reached:
69 while t<t_end:
70 print("time step %d, t=%s, T_max=%s"%(N, t, Lsup(T)))
71 # update PDE coefficient:
72 mypde.setValue(Y=rhocp*T+dt*Q, X=-k*dt*grad(T))
73 # new temperature:
74 T=mypde.getSolution()
75 # save as VTK for visualisation:
76 # saveVTK("u.%s.vtu"%N,T=T)
77 # increase counter and marker:
78 N+=1; t+=dt
79

  ViewVC Help
Powered by ViewVC 1.1.26