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

Annotation of /trunk/doc/examples/cookbook/example01b.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2950 - (hide annotations)
Thu Feb 25 07:33:16 2010 UTC (9 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 3459 byte(s)
more renames in the cookbook.
1 ahallam 2401
2     ########################################################
3     #
4 gross 2904 # Copyright (c) 2009 by University of Queensland
5 ahallam 2401 # 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 gross 2904 __copyright__="""Copyright (c) 2009 by University of Queensland
15 ahallam 2401 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 gross 2904 # 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 ahallam 2606 from esys.escript.unitsSI import *
29 gross 2904 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 ahallam 2658 #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 ahallam 2606 import pylab as pl #Plotting package.
35     import numpy as np #Array package.
36 gross 2904 import os, sys #This package is necessary to handle saving our data.
37 ahallam 2401
38 gross 2904 ##ESTABLISHING VARIABLES
39 ahallam 2401 #Domain related.
40 gross 2904 mx = 500*m #meters - model length
41     my = 100*m #meters - model width
42 ahallam 2606 ndx = 100 # mesh steps in x direction
43     ndy = 1 # mesh steps in y direction - one dimension means one element
44 gross 2904 boundloc = mx/2 # location of boundary between the two blocks
45 ahallam 2401 #PDE related
46 ahallam 2494 rho = 7874. *kg/m**3 #kg/m^{3} density of iron
47 gross 2904 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     qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no heat source
51     T1=20 * Celsius # initial temperature at Block 1
52     T2=2273. * Celsius # initial temperature at Block 2
53 ahallam 2606
54 gross 2904 t=0 * day # our start time, usually zero
55     tend=50 * yr # - time to end simulation
56 ahallam 2401 outputs = 200 # number of time steps required.
57     h=(tend-t)/outputs #size of time step
58 ahallam 2606 #user warning statement
59 ahallam 2494 print "Expected Number of time outputs is: ", (tend-t)/h
60 ahallam 2401 i=0 #loop counter
61     #the folder to put our outputs in, leave blank "" for script path
62 gross 2949 save_path= os.path.join("data","example01")
63 jfenwick 2648 #ensure the dir exists
64 gross 2904 mkDir(save_path, os.path.join(save_path,"tempT"))
65 jfenwick 2648
66 gross 2904 #... generate domain ...
67     blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
68     #... open PDE and set coefficients ...
69     mypde=LinearPDE(blocks)
70     mypde.setSymmetryOn()
71     A=zeros((2,2))
72     A[0,0]=kappa
73     mypde.setValue(A=A,D=rhocp/h)
74     # ... set initial temperature ....
75     x=Solution(blocks).getX()
76     T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))
77 ahallam 2401
78 gross 2904 # ... open a collector for the time marks and corresponding total energy
79     t_list=[]
80     E_list=[]
81     # ... start iteration:
82     while t<tend:
83     i+=1
84     t+=h
85     mypde.setValue(Y=qH+rhocp/h*T)
86     T=mypde.getSolution()
87     totE=integrate(rhocp*T)
88     print "time step %s at t=%e days completed. total energy = %e."%(i,t/day,totE)
89     t_list.append(t)
90     E_list.append(totE)
91 ahallam 2401
92 gross 2904 # plot the total energy over time:
93 gross 2950 if getMPIRankWorld() == 0:
94     pl.plot(t_list,E_list)
95     pl.title("Total Energy")
96     pl.axis([0,max(t_list),0,max(E_list)*1.1])
97     pl.savefig(os.path.join(save_path,"totE.png"))

  ViewVC Help
Powered by ViewVC 1.1.26