/[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 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 2427 byte(s)
fixing tests for cases where required domains not built
1 from __future__ import division
2 from __future__ import print_function
3
4 ##############################################################################
5 #
6 # Copyright (c) 2003-2014 by University of Queensland
7 # http://www.uq.edu.au
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 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
14 # Development 2012-2013 by School of Earth Sciences
15 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
16 #
17 ##############################################################################
18
19 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Open Software License version 3.0
23 http://www.opensource.org/licenses/osl-3.0.php"""
24 __url__="https://launchpad.net/escript-finley"
25
26 # import tools
27 from esys.escript import *
28 from esys.escript.linearPDEs import LinearPDE
29 try:
30 from esys.dudley import Rectangle
31 HAVE_DUDLEY = True
32 except ImportError:
33 HAVE_DUDLEY = False
34 from esys.weipa import saveVTK
35
36 if not HAVE_DUDLEY:
37 print("Dudley module not available")
38 else:
39 # end of simulation time
40 t_end=0.1
41 # time step size:
42 dt=0.01
43 # dimensions:
44 L0=1.;L1=1.
45 # location, size and value of heat source
46 xc=[0.3,0.4]; r=0.1; Qc=3000
47 # material parameter
48 k=1; rhocp=100;
49 # bottom temperature:
50 T_bot=100
51 # generate domain:
52 mydomain=Rectangle(l0=L0,l1=L1,n0=20,n1=20)
53 x=mydomain.getX()
54 # set boundray temperature:
55 T_D=T_bot/L1*(L1-x[1])
56 # set heat source:
57 Q=Qc*whereNegative(length(x-xc)-r)
58 # generate domain:
59 mypde=LinearPDE(mydomain)
60 mypde.setSymmetryOn()
61 # set PDE coefficients:
62 mypde.setValue(A=dt*k*kronecker(mydomain), D=dt*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"%(N,t))
71 # update PDE coefficient:
72 mypde.setValue(Y=dt*rhocp*T+dt*Q)
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

  ViewVC Help
Powered by ViewVC 1.1.26