/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 2059 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



1
2 from __future__ import print_function
3 ########################################################
4 #
5 # Copyright (c) 2003-2010 by University of Queensland
6 # Earth Systems Science Computational Center (ESSCC)
7 # http://www.uq.edu.au/esscc
8 #
9 # Primary Business: Queensland, Australia
10 # Licensed under the Open Software License version 3.0
11 # http://www.opensource.org/licenses/osl-3.0.php
12 #
13 ########################################################
14
15 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
16 Earth Systems Science Computational Center (ESSCC)
17 http://www.uq.edu.au/esscc
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 # import tools
24 from esys.escript import *
25 from esys.escript.linearPDEs import LinearPDE
26 from esys.dudley import Rectangle
27 from esys.weipa import saveVTK
28 # end of simulation time
29 t_end=0.1
30 # dimensions:
31 L0=1.;L1=1.
32 # location, size and value of heat source
33 xc=[0.3,0.4]; r=0.1; Qc=3000
34 # material parameter
35 k=1.; rhocp=100;
36 # bottom temperature:
37 T_bot=100
38 # generate domain:
39 mydomain=Rectangle(l0=L0,l1=L1,n0=20,n1=20)
40 x=mydomain.getX()
41 # set boundray temperature:
42 T_D=T_bot/L1*(L1-x[1])
43 # set heat source:
44 Q=Qc*whereNegative(length(x-xc)-r)
45 # time step size:
46 dt=0.01
47 # or use adaptive choice dt=0.05*inf(rhocp*mydomain.getSize()**2/k)
48 print("time step size = ",dt)
49 # generate domain:
50 mypde=LinearPDE(mydomain)
51 mypde.setSymmetryOn()
52 # set PDE coefficients:
53 mypde.setValue(D=rhocp,
54 r=T_D, q=whereZero(x[1])+whereZero(x[1]-L1))
55 # initial temperature
56 T=T_D
57 # step counter and time marker:
58 N=0; t=0
59 # stop when t_end is reached:
60 while t<t_end:
61 print(N,"-th time step t=",t," T_max=", Lsup(T))
62 # update PDE coefficient:
63 mypde.setValue(Y=rhocp*T+dt*Q, X=-k*dt*grad(T))
64 # new temperature:
65 T=mypde.getSolution()
66 # save as VTK for visualisation:
67 # saveVTK("u.%s.vtu"%N,T=T)
68 # increase counter and marker:
69 N+=1; t+=dt

  ViewVC Help
Powered by ViewVC 1.1.26