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

Diff of /trunk/doc/examples/cookbook/twodheatdiff001.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2657 by jfenwick, Mon Sep 7 00:06:15 2009 UTC revision 2658 by ahallam, Thu Sep 10 02:58:44 2009 UTC
# Line 39  from esys.escript.linearPDEs import Line Line 39  from esys.escript.linearPDEs import Line
39  from esys.finley import Rectangle  from esys.finley import Rectangle
40  # A useful unit handling package which will make sure all our units  # A useful unit handling package which will make sure all our units
41  # match up in the equations under SI.  # match up in the equations under SI.
42  from esys.escript.unitsSI import *  from esys.escript.unitsSI import *
43    #For interactive use, you can comment out the next two lines
44    import matplotlib
45    matplotlib.use('agg') #It's just here for automated testing
46  import pylab as pl #Plotting package.  import pylab as pl #Plotting package.
47  import numpy as np #Array package.  import numpy as np #Array package.
48  import os #This package is necessary to handle saving our data.  import os #This package is necessary to handle saving our data.
49  from cblib import toXYTuple, needdirs  from cblib import toXYTuple, needdirs
50    
51    ########################################################MPI WORLD CHECK
52    if getMPISizeWorld() > 1:
53        import sys
54        print "This example will not run in an MPI world."
55        sys.exit(0)
56    
57  #################################################ESTABLISHING VARIABLES  #################################################ESTABLISHING VARIABLES
58  #PDE related  #PDE related
59  mx = 600*m #meters - model length  mx = 600*m #meters - model length
# Line 80  print "Expected Number of Output Files i Line 89  print "Expected Number of Output Files i
89  print "Step size is: ", h/(24.*60*60), "days"  print "Step size is: ", h/(24.*60*60), "days"
90  i=0 #loop counter  i=0 #loop counter
91  #the folder to put our outputs in, leave blank "" for script path  #the folder to put our outputs in, leave blank "" for script path
92  save_path="data/twodheatdiff"  save_path= os.path.join("data","twodheatdiff")
93  needdirs([save_path])  needdirs([save_path])
94  ########## note this folder path must exist to work ###################  ########## note this folder path must exist to work ###################
95    
# Line 110  coordX, coordY = toXYTuple(coords) Line 119  coordX, coordY = toXYTuple(coords)
119  xi = np.linspace(0.0,mx,100)  xi = np.linspace(0.0,mx,100)
120  yi = np.linspace(0.0,my,100)  yi = np.linspace(0.0,my,100)
121    
122  #... start iteration:  ########################################################START ITERATION
123  while t<=tend:  while t<=tend:
124        i+=1 #counter        i+=1 #counter
125        t+=h #curretn time        t+=h #curretn time
# Line 120  while t<=tend: Line 129  while t<=tend:
129        tempT = T.toListOfTuples(scalarastuple=False)        tempT = T.toListOfTuples(scalarastuple=False)
130        # grid the data.        # grid the data.
131        zi = pl.matplotlib.mlab.griddata(coordX,coordY,tempT,xi,yi)        zi = pl.matplotlib.mlab.griddata(coordX,coordY,tempT,xi,yi)
132        # contour the gridded data, plotting dots at the randomly spaced data points.        # contour the gridded data, plotting dots at the
133          # randomly spaced data points.
134        pl.matplotlib.pyplot.autumn()        pl.matplotlib.pyplot.autumn()
135        pl.contourf(xi,yi,zi,10)        pl.contourf(xi,yi,zi,10)
136        CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')        CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')
# Line 129  while t<=tend: Line 139  while t<=tend:
139        pl.title("Heat diffusion from an intrusion.")        pl.title("Heat diffusion from an intrusion.")
140        pl.xlabel("Horizontal Displacement (m)")        pl.xlabel("Horizontal Displacement (m)")
141        pl.ylabel("Depth (m)")        pl.ylabel("Depth (m)")
142        pl.savefig(os.path.join(save_path,"heatrefraction%03d.png") %i)        if getMPIRankWorld() == 0:
143              pl.savefig(os.path.join(save_path,\
144                                       "heatrefraction%03d.png"%i))
145        pl.clf()                    pl.clf()            
146    
147  # compile the *.png files to create an *.avi video that shows T change  # compile the *.png files to create an *.avi video that shows T change

Legend:
Removed from v.2657  
changed lines
  Added in v.2658

  ViewVC Help
Powered by ViewVC 1.1.26