/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 4557 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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

  ViewVC Help
Powered by ViewVC 1.1.26