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

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

  ViewVC Help
Powered by ViewVC 1.1.26