/[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 4853 - (hide annotations)
Wed Apr 9 05:41:57 2014 UTC (5 years, 6 months ago) by jfenwick
File MIME type: text/x-python
File size: 3589 byte(s)
Added import division and changed a few / to //

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