# Contents of /trunk/doc/examples/cookbook/example01a.py

Revision 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 5 months ago) by sshaw
File MIME type: text/x-python
File size: 3857 byte(s)
```fixing tests for cases where required domains not built
```
 1 from __future__ import division, print_function 2 ############################################################################## 3 # 4 # Copyright (c) 2009-2014 by University of Queensland 5 6 # 7 # Primary Business: Queensland, Australia 8 # Licensed under the Open Software License version 3.0 9 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-2014 by University of Queensland 18 http://www.uq.edu.au 19 Primary Business: Queensland, Australia""" 20 __license__="""Licensed under the Open Software License version 3.0 21 22 __url__= 23 24 """ 25 Author: Antony Hallam antony.hallam@uqconnect.edu.au 26 """ 27 ############################################################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 import sys 32 #######################################################EXTERNAL MODULES 33 # 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 from esys.escript.unitsSI import * 36 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE 37 try: 38 from esys.finley import Rectangle 39 HAVE_FINLEY = True 40 except ImportError: 41 print("Finley module not available") 42 HAVE_FINLEY = False 43 44 if HAVE_FINLEY: 45 #################################################ESTABLISHING VARIABLES 46 #Domain related. 47 mx = 500*m #meters - model length 48 my = 100*m #meters - model width 49 ndx = 100 # mesh steps in x direction 50 ndy = 1 # mesh steps in y direction - one dimension means one element 51 boundloc = mx/2 # location of boundary between the two blocks 52 #PDE related 53 rho = 2750. *kg/m**3 #kg/m{3} density of iron 54 cp = 790.*J/(kg*K) # J/Kg.K thermal capacity 55 rhocp = rho*cp 56 kappa = 2.2*W/m/K # watts/m.Kthermal conductivity 57 qH=0 * J/(sec*m**3) # J/(sec.m{3}) no heat source 58 T1=20 * Celsius # initial temperature at Block 1 59 T2=2273. * Celsius # base temperature at Block 2 60 61 62 ################################################ESTABLISHING PARAMETERS 63 t=0 * day # our start time, usually zero 64 tend=50 * yr # - time to end simulation 65 outputs = 200 # number of time steps required. 66 h=(tend-t)/outputs #size of time step 67 #user warning statement 68 print("Expected Number of time outputs is: ", (tend-t)/h) 69 i=0 #loop counter 70 #the folder to put our outputs in, leave blank "" for script path 71 save_path= os.path.join("data","example01") 72 #ensure the dir exists 73 mkDir(save_path, os.path.join(save_path,"tempT")) 74 75 ####################################################DOMAIN CONSTRUCTION 76 blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) 77 78 ###############################################ESCRIPT PDE CONSTRUCTION 79 #... open PDE and set coefficients ... 80 mypde=LinearPDE(blocks) 81 mypde.setSymmetryOn() 82 A=zeros((2,2)) 83 A[0,0]=kappa 84 mypde.setValue(A=A,D=rhocp/h) 85 # ... set initial temperature .... 86 x=Solution(blocks).getX() 87 T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc)) 88 89 ########################################################START ITERATION 90 while t