# Contents of /trunk/doc/examples/cookbook/example01b.py

Revision 2494 - (show annotations)
Thu Jun 25 05:00:57 2009 UTC (10 years, 5 months ago) by ahallam
Original Path: trunk/doc/cookbook/onedheatdiff001.py
File MIME type: text/x-python
File size: 2780 byte(s)
```Many updates to onedheatdiff in example and documentation. Still in need of some TLC however.
```
 1 2 ######################################################## 3 # 4 # Copyright (c) 2003-2009 by University of Queensland 5 # Earth Systems Science Computational Center (ESSCC) 6 7 # 8 # Primary Business: Queensland, Australia 9 # Licensed under the Open Software License version 3.0 10 11 # 12 ######################################################## 13 14 __copyright__="""Copyright (c) 2003-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 20 __url__= 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.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE 29 from esys.finley import Rectangle # This imports the rectangle domain function from finley 30 from esys.escript.unitsSI import * # A useful unit handling package which will make sure all our units match up in the equations. 31 import os #This package is necessary to handle saving our data. 32 #plotting tools 33 #import matplotlib as ptool 34 35 36 ##ESTABLISHING VARIABLES 37 #Domain related. 38 mx = 1*m #meters - model lenght 39 my = .1*m #meters - model width 40 ndx = 100 # steps in x direction 41 ndy = 1 # steps in y direction 42 43 #PDE related 44 q=200. * Celsius #Kelvin - our heat source temperature 45 Tref = 0. * Celsius # Kelvin - starting temp of iron bar 46 rho = 7874. *kg/m**3 #kg/m^{3} density of iron 47 cp = 449.*J/(kg*K) #j/Kg.K thermal capacity 48 rhocp = rho*cp 49 kappa = 80.*W/m/K #watts/m.Kthermal conductivity 50 #Script/Iteration Related 51 t=0 #our start time, usually zero 52 tend=5.*minute #seconds - time to end simulation 53 outputs = 200 # number of time steps required. 54 h=(tend-t)/outputs #size of time step 55 print "Expected Number of time outputs is: ", (tend-t)/h 56 i=0 #loop counter 57 #the folder to put our outputs in, leave blank "" for script path 58 save_path="data/onedheatdiff001" 59 #note this folder path must exist to work 60 61 62 #... generate domain ... 63 rod = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) 64 # extract finite points 65 x=rod.getX() 66 #... open PDE ... 67 mypde=LinearPDE(rod) 68 mypde.setSymmetryOn() 69 mypde.setValue(A=kappa*kronecker(rod),D=rhocp/h) 70 71 # ... set heat source: .... 72 qH=q*whereZero(x[0]) 73 # ... set initial temperature .... 74 T=Tref 75 76 # ... start iteration: 77 while t<=tend: 78 i+=1 79 t+=h 80 mypde.setValue(Y=qH+rhocp/h*T) 81 T=mypde.getSolution() 82 #ptool.plot(T) 83 saveVTK(os.path.join(save_path,"data%03d.xml") %i,sol=T) 84 85