/[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 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 5139 byte(s)
fixing tests for cases where required domains not built
1 from __future__ import division, print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2009-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 Author: Antony Hallam antony.hallam@uqconnect.edu.au
26 """
27
28 ############################################################FILE HEADER
29 # example03b.py
30 # Model temperature diffusion between a granite intrusion and sandstone
31 # country rock. This is a two dimensional problem with the granite as a
32 # heat source. It creates vtk files.
33 #
34 # This program is MPI safe.
35
36 #######################################################EXTERNAL MODULES
37 #To solve the problem it is necessary to import the modules we require.
38 #This imports everything from the escript library
39 from esys.escript import *
40 # This defines the LinearPDE module as LinearPDE
41 from esys.escript.linearPDEs import LinearPDE
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 try:
48 # This imports the rectangle domain function
49 from esys.finley import Rectangle
50 HAVE_FINLEY = True
51 except ImportError:
52 print("Finley module not available")
53 HAVE_FINLEY = False
54
55 if HAVE_FINLEY:
56 #################################################ESTABLISHING VARIABLES
57 #PDE related
58 mx = 600*m #meters - model length
59 my = 600*m #meters - model width
60 ndx = 150 #mesh steps in x direction
61 ndy = 150 #mesh steps in y direction
62 r = 200*m #meters - radius of intrusion
63 ic = [300*m, 0] #centre of intrusion (meters)
64 qH=0.*J/(sec*m**3) #our heat source temperature is now zero
65
66 ## Intrusion Variables - Granite
67 Ti=2273.*Celsius # Kelvin -the starting temperature of our RHS Block
68 rhoi = 2750*kg/m**3 #kg/m^{3} density of granite
69 cpi = 790.*J/(kg*K) #j/Kg.K thermal capacity
70 rhocpi = rhoi*cpi #DENSITY * SPECIFIC HEAT
71 kappai=2.2*W/m/K #watts/m.K thermal conductivity
72 ## Country Rock Variables - Sandstone
73 Tc = 473*Celsius # Kelvin #the starting temperature of our country rock
74 rhoc = 2000*kg/m**3 #kg/m^{3} density
75 cpc = 920.*J/(kg*K) #j/kg.k specific heat
76 rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT
77 kappac = 1.9*W/m/K #watts/m.K thermal conductivity
78
79 #Script/Iteration Related
80 t=0. #our start time, usually zero
81 tend=200.* yr #the time we want to end the simulation
82 outputs = 200 # number of time steps required.
83 h=(tend-t)/outputs #size of time step
84 #user warning
85 print("Expected Number of Output Files is: ", outputs)
86 print("Step size is: ", h/day, "days")
87 i=0 #loop counter
88 #the folder to put our outputs in, leave blank "" for script path
89 save_path= os.path.join("data","example03")
90 mkDir(save_path)
91 ########## note this folder path must exist to work ###################
92
93 ################################################ESTABLISHING PARAMETERS
94 #generate domain using rectangle
95 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
96 #extract finite points - the solution points
97 #create the PDE
98 mypde=LinearPDE(model) #assigns a domain to our PDE
99 mypde.setSymmetryOn() #set the fast solver on for symmetry
100 #establish location of boundary between two materials
101 x=Function(model).getX()
102 bound = length(x-ic)-r #where the boundary will be located
103 kappa = kappai*whereNegative(bound)+kappac*(1-whereNegative(bound))
104 rhocp = rhocpi*whereNegative(bound)+rhocpc*(1-whereNegative(bound))
105 #define our PDE coeffs
106 mypde.setValue(A=kappa*kronecker(model),D=rhocp/h)
107 #set initial temperature (make sure we use the right sample points)
108 x=Solution(model).getX()
109 bound = length(x-ic)-r #where the boundary will be located
110 T= Ti*whereNegative(bound)+Tc*(1-whereNegative(bound))
111
112 ########################################################START ITERATION
113 while t<=tend:
114 i+=1 #counter
115 t+=h #current time
116 mypde.setValue(Y=qH+T*rhocp/h)
117 T=mypde.getSolution()
118 saveVTK(os.path.join(save_path,"data.%03d.vtu"%i), T=T)
119 print("time step %s at t=%e days completed."%(i,t/day))
120
121 # use
122 #
123 # cd data/example03
124 # mayavi2 -d data.001.vtu -m Surface
125 #
126 # to visualize the results (mayavi2 must be installed on your system).
127 #

  ViewVC Help
Powered by ViewVC 1.1.26