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

Copyright dates update

1 sshaw 5288 from __future__ import division, print_function
2 jfenwick 3981 ##############################################################################
3 ahallam 2392 #
4 jfenwick 6651 # Copyright (c) 2009-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ahallam 2392 #
7     # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ahallam 2392 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ahallam 2392
17 jfenwick 6651 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 ahallam 2392 Primary Business: Queensland, Australia"""
20 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
21     http://www.apache.org/licenses/LICENSE-2.0"""
22 ahallam 2392 __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 sshaw 5288 import sys
32 ahallam 2977 #######################################################EXTERNAL MODULES
33 ahallam 2392 # To solve the problem it is necessary to import the modules we require.
34 jfenwick 6094 import os
35 ahallam 2392 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 sshaw 5288 try:
39     from esys.finley import Rectangle
40     HAVE_FINLEY = True
41     except ImportError:
42     print("Finley module not available")
43     HAVE_FINLEY = False
44    
45     if HAVE_FINLEY:
46     #################################################ESTABLISHING VARIABLES
47     #Domain related.
48     mx = 500*m #meters - model length
49     my = 100*m #meters - model width
50     ndx = 100 # mesh steps in x direction
51     ndy = 1 # mesh steps in y direction - one dimension means one element
52     boundloc = mx/2 # location of boundary between the two blocks
53     #PDE related
54     rho = 2750. *kg/m**3 #kg/m{3} density of iron
55     cp = 790.*J/(kg*K) # J/Kg.K thermal capacity
56     rhocp = rho*cp
57     kappa = 2.2*W/m/K # watts/m.Kthermal conductivity
58     qH=0 * J/(sec*m**3) # J/(sec.m{3}) no heat source
59     T1=20 * Celsius # initial temperature at Block 1
60     T2=2273. * Celsius # base temperature at Block 2
61 ahallam 2392
62    
63 sshaw 5288 ################################################ESTABLISHING PARAMETERS
64     t=0 * day # our start time, usually zero
65     tend=50 * yr # - time to end simulation
66     outputs = 200 # number of time steps required.
67     h=(tend-t)/outputs #size of time step
68     #user warning statement
69     print("Expected Number of time outputs is: ", (tend-t)/h)
70     i=0 #loop counter
71     #the folder to put our outputs in, leave blank "" for script path
72     save_path= os.path.join("data","example01")
73     #ensure the dir exists
74     mkDir(save_path, os.path.join(save_path,"tempT"))
75 ahallam 3374
76 sshaw 5288 ####################################################DOMAIN CONSTRUCTION
77     blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
78 ahallam 2392
79 sshaw 5288 ###############################################ESCRIPT PDE CONSTRUCTION
80     #... open PDE and set coefficients ...
81     mypde=LinearPDE(blocks)
82     mypde.setSymmetryOn()
83     A=zeros((2,2))
84     A[0,0]=kappa
85     mypde.setValue(A=A,D=rhocp/h)
86     # ... set initial temperature ....
87     x=Solution(blocks).getX()
88     T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))
89 ahallam 2977
90 sshaw 5288 ########################################################START ITERATION
91     while t<tend:
92     i+=1
93     t+=h
94     mypde.setValue(Y=qH+rhocp/h*T)
95     T=mypde.getSolution()
96     totE=integrate(rhocp*T)
97     print("time step %s at t=%e days completed. total energy = %e."%(i,t/day,totE))

  ViewVC Help
Powered by ViewVC 1.1.26