/[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 3892 - (hide annotations)
Tue Apr 10 08:57:23 2012 UTC (7 years ago) by jfenwick
File MIME type: text/x-python
File size: 3418 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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