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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2950 - (show annotations)
Thu Feb 25 07:33:16 2010 UTC (9 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 4493 byte(s)
more renames in the cookbook.
1
2 ########################################################
3 #
4 # Copyright (c) 2009-2010 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) 2009-2010 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
26 ############################################################FILE HEADER
27 # example03b.py
28 # Model temperature diffusion between a granite intrusion and sandstone
29 # country rock. This is a two dimensional problem with the granite as a
30 # heat source. It creates vtk files.
31 #
32 # This program is MPI safe.
33
34 #######################################################EXTERNAL MODULES
35 #To solve the problem it is necessary to import the modules we require.
36 #This imports everything from the escript library
37 from esys.escript import *
38 # This defines the LinearPDE module as LinearPDE
39 from esys.escript.linearPDEs import LinearPDE
40 # This imports the rectangle domain function from finley.
41 from esys.finley import Rectangle
42 # A useful unit handling package which will make sure all our units
43 # match up in the equations under SI.
44 from esys.escript.unitsSI import *
45
46 #################################################ESTABLISHING VARIABLES
47 #PDE related
48 mx = 600*m #meters - model length
49 my = 600*m #meters - model width
50 ndx = 150 #mesh steps in x direction
51 ndy = 150 #mesh steps in y direction
52 r = 200*m #meters - radius of intrusion
53 ic = [300*m, 0] #centre of intrusion (meters)
54 qH=0.*J/(sec*m**3) #our heat source temperature is now zero
55
56 ## Intrusion Variables - Granite
57 Ti=2273.*Celsius # Kelvin -the starting temperature of our RHS Block
58 rhoi = 2750*kg/m**3 #kg/m^{3} density of granite
59 cpi = 790.*J/(kg*K) #j/Kg.K thermal capacity
60 rhocpi = rhoi*cpi #DENSITY * SPECIFIC HEAT
61 kappai=2.2*W/m/K #watts/m.K thermal conductivity
62 ## Country Rock Variables - Sandstone
63 Tc = 473*Celsius # Kelvin #the starting temperature of our country rock
64 rhoc = 2000*kg/m**3 #kg/m^{3} density
65 cpc = 920.*J/(kg*K) #j/kg.k specific heat
66 rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT
67 kappac = 1.9*W/m/K #watts/m.K thermal conductivity
68
69 #Script/Iteration Related
70 t=0. #our start time, usually zero
71 tend=200.* yr #the time we want to end the simulation
72 outputs = 200 # number of time steps required.
73 h=(tend-t)/outputs #size of time step
74 #user warning
75 print "Expected Number of Output Files is: ", outputs
76 print "Step size is: ", h/day, "days"
77 i=0 #loop counter
78 #the folder to put our outputs in, leave blank "" for script path
79 save_path= os.path.join("data","example03")
80 mkDir(save_path)
81 ########## note this folder path must exist to work ###################
82
83 ################################################ESTABLISHING PARAMETERS
84 #generate domain using rectangle
85 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
86 #extract finite points - the solution points
87 #create the PDE
88 mypde=LinearPDE(model) #assigns a domain to our PDE
89 mypde.setSymmetryOn() #set the fast solver on for symmetry
90 #establish location of boundary between two materials
91 x=Function(model).getX()
92 bound = length(x-ic)-r #where the boundary will be located
93 kappa = kappai*whereNegative(bound)+kappac*(1-whereNegative(bound))
94 rhocp = rhocpi*whereNegative(bound)+rhocpc*(1-whereNegative(bound))
95 #define our PDE coeffs
96 mypde.setValue(A=kappa*kronecker(model),D=rhocp/h)
97 #set initial temperature (make sure we use the right sample points)
98 x=Solution(model).getX()
99 bound = length(x-ic)-r #where the boundary will be located
100 T= Ti*whereNegative(bound)+Tc*(1-whereNegative(bound))
101
102 ########################################################START ITERATION
103 while t<=tend:
104 i+=1 #counter
105 t+=h #current time
106 mypde.setValue(Y=qH+T*rhocp/h)
107 T=mypde.getSolution()
108 saveVTK(os.path.join(save_path,"data.%03d.vtu"%i), T=T)
109 print "time step %s at t=%e days completed."%(i,t/day)
110
111 # use
112 #
113 # cd data/example03
114 # mayavi2 -d data.001.vtu -m Surface
115 #
116 # to visualize the results (mayavi2 must be installed on your system).
117 #

  ViewVC Help
Powered by ViewVC 1.1.26