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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4154 - (hide annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 3490 byte(s)
Round 1 of copyright fixes
1 ahallam 2392
2 jfenwick 3892 from __future__ import print_function
3 jfenwick 3981 ##############################################################################
4 ahallam 2392 #
5 jfenwick 4154 # Copyright (c) 2009-2013 by University of Queensland
6 jfenwick 3981 # http://www.uq.edu.au
7 ahallam 2392 #
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 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13     # Development since 2012 by School of Earth Sciences
14     #
15     ##############################################################################
16 ahallam 2392
17 jfenwick 4154 __copyright__="""Copyright (c) 2009-2013 by University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 ahallam 2392 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 ahallam 2977 ############################################################FILE HEADER
28     # example01a.py
29     # Model temperature diffusion between two granite blocks of unequal
30     # initial temperature. Solve for total energy in the system.
31 ahallam 2392
32 ahallam 2977 #######################################################EXTERNAL MODULES
33 ahallam 2392 # To solve the problem it is necessary to import the modules we require.
34     from esys.escript import * # This imports everything from the escript library
35 gross 2904 from esys.escript.unitsSI import *
36 ahallam 2392 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
37 jfenwick 3259 from esys.finley import Rectangle # This imports the rectangle domain function
38 ahallam 2392
39 ahallam 2977 #################################################ESTABLISHING VARIABLES
40 gross 2904 #Domain related.
41     mx = 500*m #meters - model length
42     my = 100*m #meters - model width
43     ndx = 100 # mesh steps in x direction
44     ndy = 1 # mesh steps in y direction - one dimension means one element
45     boundloc = mx/2 # location of boundary between the two blocks
46 ahallam 2392 #PDE related
47 ahallam 3374 rho = 2750. *kg/m**3 #kg/m{3} density of iron
48     cp = 790.*J/(kg*K) # J/Kg.K thermal capacity
49     rhocp = rho*cp
50     kappa = 2.2*W/m/K # watts/m.Kthermal conductivity
51     qH=0 * J/(sec*m**3) # J/(sec.m{3}) no heat source
52 gross 2904 T1=20 * Celsius # initial temperature at Block 1
53 ahallam 3374 T2=2273. * Celsius # base temperature at Block 2
54 ahallam 2392
55 ahallam 3374
56 ahallam 2977 ################################################ESTABLISHING PARAMETERS
57 gross 2904 t=0 * day # our start time, usually zero
58     tend=50 * yr # - time to end simulation
59     outputs = 200 # number of time steps required.
60     h=(tend-t)/outputs #size of time step
61     #user warning statement
62 jfenwick 3892 print("Expected Number of time outputs is: ", (tend-t)/h)
63 gross 2904 i=0 #loop counter
64     #the folder to put our outputs in, leave blank "" for script path
65 gross 2949 save_path= os.path.join("data","example01")
66 gross 2904 #ensure the dir exists
67     mkDir(save_path, os.path.join(save_path,"tempT"))
68 ahallam 2392
69 ahallam 2977 ####################################################DOMAIN CONSTRUCTION
70 gross 2904 blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
71 ahallam 2977
72     ###############################################ESCRIPT PDE CONSTRUCTION
73 artak 2980 #... open PDE and set coefficients ...
74     mypde=LinearPDE(blocks)
75 ahallam 2392 mypde.setSymmetryOn()
76 gross 2904 A=zeros((2,2))
77     A[0,0]=kappa
78     mypde.setValue(A=A,D=rhocp/h)
79 ahallam 2392 # ... set initial temperature ....
80 gross 2904 x=Solution(blocks).getX()
81     T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))
82 ahallam 2392
83 ahallam 2977 ########################################################START ITERATION
84 gross 2904 while t<tend:
85 ahallam 2392 i+=1
86     t+=h
87 gross 2904 mypde.setValue(Y=qH+rhocp/h*T)
88 ahallam 2392 T=mypde.getSolution()
89 gross 2904 totE=integrate(rhocp*T)
90 jfenwick 3892 print("time step %s at t=%e days completed. total energy = %e."%(i,t/day,totE))

  ViewVC Help
Powered by ViewVC 1.1.26