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

Revision 2949 - (show annotations)
Thu Feb 25 05:23:11 2010 UTC (9 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 4600 byte(s)
```renaming examples part 1
```
 1 2 ######################################################## 3 # 4 # Copyright (c) 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) 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.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 #For interactive use, you can comment out the next two lines 32 import matplotlib 33 matplotlib.use('agg') #It's just here for automated testing 34 import pylab as pl #Plotting package. 35 import numpy as np #Array package. 36 import os, sys #This package is necessary to handle saving our data. 37 38 # .. MPI WORLD CHECK 39 if getMPISizeWorld() > 1: 40 import sys 41 print "This example will not run in an MPI world." 42 sys.exit(0) 43 44 ##ESTABLISHING VARIABLES 45 #Domain related. 46 mx = 500*m #meters - model length 47 my = 100*m #meters - model width 48 ndx = 100 # mesh steps in x direction 49 ndy = 1 # mesh steps in y direction - one dimension means one element 50 boundloc = mx/2 # location of boundary between the two blocks 51 #PDE related 52 rho = 7874. *kg/m**3 #kg/m^{3} density of iron 53 cp = 449.*J/(kg*K) # J/Kg.K thermal capacity 54 rhocp = rho*cp 55 kappa = 80.*W/m/K # watts/m.Kthermal conductivity 56 qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no heat source 57 T1=20 * Celsius # initial temperature at Block 1 58 T2=2273. * Celsius # initial temperature at Block 2 59 60 t=0 * day # our start time, usually zero 61 tend=50 * yr # - time to end simulation 62 outputs = 200 # number of time steps required. 63 h=(tend-t)/outputs #size of time step 64 #user warning statement 65 print "Expected Number of time outputs is: ", (tend-t)/h 66 i=0 #loop counter 67 #the folder to put our outputs in, leave blank "" for script path 68 save_path= os.path.join("data","example01") 69 #ensure the dir exists 70 mkDir(save_path, os.path.join(save_path,"tempT")) 71 72 #... generate domain ... 73 blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) 74 #... open PDE and set coefficients ... 75 mypde=LinearPDE(blocks) 76 mypde.setSymmetryOn() 77 A=zeros((2,2)) 78 A[0,0]=kappa 79 mypde.setValue(A=A,D=rhocp/h) 80 # ... set initial temperature .... 81 x=Solution(blocks).getX() 82 T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc)) 83 84 # ... open a collector for the time marks and corresponding total energy 85 t_list=[] 86 E_list=[] 87 # ... convert solution points for plotting 88 plx = x.toListOfTuples() 89 plx = np.array(plx) #convert to tuple to numpy array 90 plx = plx[:,0] #extract x locations 91 # ... start iteration: 92 while t

 ViewVC Help Powered by ViewVC 1.1.26