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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3892 - (hide annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 10 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 ahallam 2401
2     ########################################################
3     #
4 jfenwick 2881 # Copyright (c) 2009-2010 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 jfenwick 2881 __copyright__="""Copyright (c) 2009-2010 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 ahallam 2606 ############################################################FILE HEADER
27 gross 2950 # example03b.py
28 ahallam 2606 # Model temperature diffusion between a granite intrusion and sandstone
29     # country rock. This is a two dimensional problem with the granite as a
30 gross 2931 # heat source. It creates vtk files.
31     #
32     # This program is MPI safe.
33 ahallam 2606
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 jfenwick 3259 # This imports the rectangle domain function
41 caltinay 3346 from esys.finley import Rectangle
42     # This imports the VTK file saver function
43     from esys.weipa import saveVTK
44 ahallam 2606 # A useful unit handling package which will make sure all our units
45     # match up in the equations under SI.
46 ahallam 2658 from esys.escript.unitsSI import *
47 ahallam 2401
48 ahallam 2606 #################################################ESTABLISHING VARIABLES
49 ahallam 2401 #PDE related
50 ahallam 2606 mx = 600*m #meters - model length
51     my = 600*m #meters - model width
52 gross 2931 ndx = 150 #mesh steps in x direction
53     ndy = 150 #mesh steps in y direction
54 ahallam 2606 r = 200*m #meters - radius of intrusion
55 gross 2931 ic = [300*m, 0] #centre of intrusion (meters)
56     qH=0.*J/(sec*m**3) #our heat source temperature is now zero
57 ahallam 2401
58     ## Intrusion Variables - Granite
59 ahallam 2606 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 ahallam 2401 rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT
69 ahallam 2606 kappac = 1.9*W/m/K #watts/m.K thermal conductivity
70 ahallam 2401
71     #Script/Iteration Related
72     t=0. #our start time, usually zero
73 gross 2931 tend=200.* yr #the time we want to end the simulation
74 ahallam 2401 outputs = 200 # number of time steps required.
75     h=(tend-t)/outputs #size of time step
76 ahallam 2606 #user warning
77 jfenwick 3892 print("Expected Number of Output Files is: ", outputs)
78     print("Step size is: ", h/day, "days")
79 ahallam 2401 i=0 #loop counter
80 ahallam 2606 #the folder to put our outputs in, leave blank "" for script path
81 gross 2950 save_path= os.path.join("data","example03")
82 gross 2904 mkDir(save_path)
83 ahallam 2606 ########## note this folder path must exist to work ###################
84 ahallam 2401
85 ahallam 2606 ################################################ESTABLISHING PARAMETERS
86     #generate domain using rectangle
87 ahallam 2401 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
88 ahallam 2606 #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 gross 2931 x=Function(model).getX()
94 ahallam 2401 bound = length(x-ic)-r #where the boundary will be located
95 gross 2931 kappa = kappai*whereNegative(bound)+kappac*(1-whereNegative(bound))
96     rhocp = rhocpi*whereNegative(bound)+rhocpc*(1-whereNegative(bound))
97 ahallam 2606 #define our PDE coeffs
98 gross 2931 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 ahallam 2401
104 ahallam 2658 ########################################################START ITERATION
105 ahallam 2401 while t<=tend:
106 ahallam 2645 i+=1 #counter
107 gross 2931 t+=h #current time
108     mypde.setValue(Y=qH+T*rhocp/h)
109 ahallam 2401 T=mypde.getSolution()
110 gross 2931 saveVTK(os.path.join(save_path,"data.%03d.vtu"%i), T=T)
111 jfenwick 3892 print("time step %s at t=%e days completed."%(i,t/day))
112 caltinay 2534
113 gross 2931 # use
114     #
115 gross 2950 # cd data/example03
116 gross 2931 # 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