/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 5139 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 from __future__ import division, print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
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-2018 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Apache License, version 2.0
21 http://www.apache.org/licenses/LICENSE-2.0"""
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 import os
48 try:
49 # This imports the rectangle domain function
50 from esys.finley import Rectangle
51 HAVE_FINLEY = True
52 except ImportError:
53 print("Finley module not available")
54 HAVE_FINLEY = False
55
56 if HAVE_FINLEY:
57 #################################################ESTABLISHING VARIABLES
58 #PDE related
59 mx = 600*m #meters - model length
60 my = 600*m #meters - model width
61 ndx = 150 #mesh steps in x direction
62 ndy = 150 #mesh steps in y direction
63 r = 200*m #meters - radius of intrusion
64 ic = [300*m, 0] #centre of intrusion (meters)
65 qH=0.*J/(sec*m**3) #our heat source temperature is now zero
66
67 ## Intrusion Variables - Granite
68 Ti=2273.*Celsius # Kelvin -the starting temperature of our RHS Block
69 rhoi = 2750*kg/m**3 #kg/m^{3} density of granite
70 cpi = 790.*J/(kg*K) #j/Kg.K thermal capacity
71 rhocpi = rhoi*cpi #DENSITY * SPECIFIC HEAT
72 kappai=2.2*W/m/K #watts/m.K thermal conductivity
73 ## Country Rock Variables - Sandstone
74 Tc = 473*Celsius # Kelvin #the starting temperature of our country rock
75 rhoc = 2000*kg/m**3 #kg/m^{3} density
76 cpc = 920.*J/(kg*K) #j/kg.k specific heat
77 rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT
78 kappac = 1.9*W/m/K #watts/m.K thermal conductivity
79
80 #Script/Iteration Related
81 t=0. #our start time, usually zero
82 tend=200.* yr #the time we want to end the simulation
83 outputs = 200 # number of time steps required.
84 h=(tend-t)/outputs #size of time step
85 #user warning
86 print("Expected Number of Output Files is: ", outputs)
87 print("Step size is: ", h/day, "days")
88 i=0 #loop counter
89 #the folder to put our outputs in, leave blank "" for script path
90 save_path= os.path.join("data","example03")
91 mkDir(save_path)
92 ########## note this folder path must exist to work ###################
93
94 ################################################ESTABLISHING PARAMETERS
95 #generate domain using rectangle
96 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
97 #extract finite points - the solution points
98 #create the PDE
99 mypde=LinearPDE(model) #assigns a domain to our PDE
100 mypde.setSymmetryOn() #set the fast solver on for symmetry
101 #establish location of boundary between two materials
102 x=Function(model).getX()
103 bound = length(x-ic)-r #where the boundary will be located
104 kappa = kappai*whereNegative(bound)+kappac*(1-whereNegative(bound))
105 rhocp = rhocpi*whereNegative(bound)+rhocpc*(1-whereNegative(bound))
106 #define our PDE coeffs
107 mypde.setValue(A=kappa*kronecker(model),D=rhocp/h)
108 #set initial temperature (make sure we use the right sample points)
109 x=Solution(model).getX()
110 bound = length(x-ic)-r #where the boundary will be located
111 T= Ti*whereNegative(bound)+Tc*(1-whereNegative(bound))
112
113 ########################################################START ITERATION
114 while t<=tend:
115 i+=1 #counter
116 t+=h #current time
117 mypde.setValue(Y=qH+T*rhocp/h)
118 T=mypde.getSolution()
119 saveVTK(os.path.join(save_path,"data.%03d.vtu"%i), T=T)
120 print("time step %s at t=%e days completed."%(i,t/day))
121
122 # use
123 #
124 # cd data/example03
125 # mayavi2 -d data.001.vtu -m Surface
126 #
127 # to visualize the results (mayavi2 must be installed on your system).
128 #

  ViewVC Help
Powered by ViewVC 1.1.26