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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2648 - (show annotations)
Mon Sep 7 00:06:15 2009 UTC (11 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 5029 byte(s)
ecording some changes related to Anthony's cookbook.
These tests still do not run.

test_heatref.py is the current problem.
Current problems include:
undefined symbols
a dependence on X somehow.

I've already addressed the matplotlib X thing somewhere else.
Find and apply.


1
2 ########################################################
3 #
4 # Copyright (c) 2003-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) 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 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 ############################################################FILE HEADER
26 # onedheatdiff001.py
27 # Model temperature diffusion in an Iron bar. This is a one dimensional
28 # problem with a single heat source at the LHS
29
30 #######################################################EXTERNAL MODULES
31 #To solve the problem it is necessary to import the modules we require.
32 #This imports everything from the escript library
33 from esys.escript import *
34 # This defines the LinearPDE module as LinearPDE
35 from esys.escript.linearPDEs import LinearPDE
36 # This imports the rectangle domain function from finley.
37 from esys.finley import Rectangle
38 # A useful unit handling package which will make sure all our units
39 # match up in the equations under SI.
40 from esys.escript.unitsSI import *
41 import pylab as pl #Plotting package.
42 import numpy as np #Array package.
43 import os #This package is necessary to handle saving our data.
44 import cblib
45
46
47 #################################################ESTABLISHING VARIABLES
48 #Domain related.
49 mx = 1*m #meters - model length
50 my = .1*m #meters - model width
51 ndx = 100 # mesh steps in x direction
52 ndy = 1 # mesh steps in y direction - one dimension means one element
53
54 #PDE related
55 q=200. * Celsius #Kelvin - our heat source temperature
56 Tref = 0. * Celsius #Kelvin - starting temp of iron bar
57 rho = 7874. *kg/m**3 #kg/m^{3} density of iron
58 cp = 449.*J/(kg*K) #j/Kg.K thermal capacity
59 rhocp = rho*cp
60 kappa = 80.*W/m/K #watts/m.Kthermal conductivity
61
62 #Script/Iteration Related
63 t=0 #our start time, usually zero
64 tend=5.*minute #seconds - time to end simulation
65 outputs = 200 # number of time steps required.
66 h=(tend-t)/outputs #size of time step
67 #user warning statement
68 print "Expected Number of time outputs is: ", (tend-t)/h
69 i=0 #loop counter
70 #the folder to put our outputs in, leave blank "" for script path
71 save_path="data/onedheatdiff001"
72
73 #ensure the dir exists
74 cblib.needdirs([save_path, os.path.join(save_path,"tempT"), os.path.join(save_path, "totT")])
75
76 ################################################ESTABLISHING PARAMETERS
77 #generate domain using rectangle
78 rod = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
79 #extract finite points - the solution points
80 x=rod.getX()
81 #create the PDE
82 mypde=LinearPDE(rod) #assigns a domain to our PDE
83 mypde.setSymmetryOn() #set the fast solver on for symmetry
84 mypde.setValue(A=kappa*kronecker(rod),D=rhocp/h) #define our PDE coeffs
85 qH=q*whereZero(x[0]) #set heat source
86 T=Tref # set initial temperature
87
88 #convert solution points for plotting
89 plx = x.toListOfTuples()
90 plx = np.array(plx) #convert to tuple to numpy array
91 plx = plx[:,0] #extract x locations
92
93 ########################################################START ITERATION
94 while t<=tend:
95 i+=1 #increment the counter
96 t+=h #increment the current time
97 mypde.setValue(Y=qH+rhocp/h*T) #set variable PDE coefficients
98 T=mypde.getSolution() #get the PDE solution
99 totT = rhocp*T #get the total heat solution in the system
100
101 #establish figure 1 for temperature vs x plots
102 tempT = T.toListOfTuples(scalarastuple=False)
103 pl.figure(1) #current figure
104 pl.plot(plx,tempT) #plot solution
105 #define axis extents and title
106 pl.axis([0,1.0,273.14990+0.00008,0.004+273.1499])
107 pl.title("Temperature accross Rod")
108 #save figure to file
109 pl.savefig(os.path.join(save_path+"/tempT","rodpyplot%03d.png") %i)
110 pl.clf() #clear figure
111
112 #establish figure 2 for total temperature vs x plots and repeat
113 tottempT = totT.toListOfTuples(scalarastuple=False)
114 pl.figure(2)
115 pl.plot(plx,tottempT)
116 pl.axis([0,1.0,9.657E08,12000+9.657E08])
117 pl.title("Total temperature accross Rod")
118 pl.savefig(os.path.join(save_path+"/totT","ttrodpyplot%03d.png")%i)
119 pl.clf()
120
121 # compile the *.png files to create two *.avi videos that show T change
122 # with time. This opperation uses linux mencoder. For other operating
123 # systems it is possible to use your favourite video compiler to
124 # convert image files to videos.
125
126 os.system("mencoder mf://"+save_path+"/tempT"+"/*.png -mf type=png:\
127 w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \
128 onedheatdiff001tempT.avi")
129
130 os.system("mencoder mf://"+save_path+"/totT"+"/*.png -mf type=png:\
131 w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \
132 onedheatdiff001totT.avi")

  ViewVC Help
Powered by ViewVC 1.1.26