/[escript]/trunk/doc/examples/cookbook/onedheatdiffbase.py
ViewVC logotype

Contents of /trunk/doc/examples/cookbook/onedheatdiffbase.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2904 - (show annotations)
Tue Feb 2 04:21:52 2010 UTC (9 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 2825 byte(s)
more revision on cookbook: example 1 and 2 have been swapped.
1
2 ########################################################
3 #
4 # Copyright (c) 2009 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2009 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 Author: Antony Hallam antony.hallam@uqconnect.edu.au
24 """
25
26 # To solve the problem it is necessary to import the modules we require.
27 from esys.escript import * # This imports everything from the escript library
28 from esys.escript.unitsSI import *
29 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
30 from esys.finley import Rectangle # This imports the rectangle domain function from finley
31
32 ##ESTABLISHING VARIABLES
33 #Domain related.
34 mx = 500*m #meters - model length
35 my = 100*m #meters - model width
36 ndx = 100 # mesh steps in x direction
37 ndy = 1 # mesh steps in y direction - one dimension means one element
38 boundloc = mx/2 # location of boundary between the two blocks
39 #PDE related
40 rho = 7874. *kg/m**3 #kg/m^{3} density of iron
41 cp = 449.*J/(kg*K) # J/Kg.K thermal capacity
42 rhocp = rho*cp
43 kappa = 80.*W/m/K # watts/m.Kthermal conductivity
44 qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no heat source
45 T1=20 * Celsius # initial temperature at Block 1
46 T2=2273. * Celsius # initial temperature at Block 2
47
48 t=0 * day # our start time, usually zero
49 tend=50 * yr # - time to end simulation
50 outputs = 200 # number of time steps required.
51 h=(tend-t)/outputs #size of time step
52 #user warning statement
53 print "Expected Number of time outputs is: ", (tend-t)/h
54 i=0 #loop counter
55 #the folder to put our outputs in, leave blank "" for script path
56 save_path= os.path.join("data","onedheatdiff001")
57 #ensure the dir exists
58 mkDir(save_path, os.path.join(save_path,"tempT"))
59
60 #... generate domain ...
61 blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
62 #... open PDE and set coefficients ...
63 mypde=LinearPDE(blocks)
64 mypde.setSymmetryOn()
65 A=zeros((2,2))
66 A[0,0]=kappa
67 mypde.setValue(A=A,D=rhocp/h)
68 # ... set initial temperature ....
69 x=Solution(blocks).getX()
70 T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))
71
72 # ... start iteration:
73 while t<tend:
74 i+=1
75 t+=h
76 mypde.setValue(Y=qH+rhocp/h*T)
77 T=mypde.getSolution()
78 totE=integrate(rhocp*T)
79 print "time step %s at t=%e days completed. total energy = %e."%(i,t/day,totE)

  ViewVC Help
Powered by ViewVC 1.1.26