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

revision 2949 by gross, Thu Feb 25 05:23:11 2010 UTC revision 2977 by ahallam, Tue Mar 9 00:33:28 2010 UTC
22  """  """
23  Author: Antony Hallam antony.hallam@uqconnect.edu.au  Author: Antony Hallam antony.hallam@uqconnect.edu.au
24  """  """
26    # example01a.py
27    # Model temperature diffusion between two granite blocks of unequal
28    # initial temperature. Solve for total energy in the system.
29
30    #######################################################EXTERNAL MODULES
31  # To solve the problem it is necessary to import the modules we require.  # To solve the problem it is necessary to import the modules we require.
32  from esys.escript import * # This imports everything from the escript library  from esys.escript import * # This imports everything from the escript library
33  from esys.escript.unitsSI import *  from esys.escript.unitsSI import *
34  from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE  from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
35  from esys.finley import Rectangle # This imports the rectangle domain function from finley  from esys.finley import Rectangle # This imports the rectangle domain function from finley
36
37  ##ESTABLISHING VARIABLES  #################################################ESTABLISHING VARIABLES
38  #Domain related.  #Domain related.
39  mx = 500*m #meters - model length  mx = 500*m #meters - model length
40  my = 100*m #meters - model width  my = 100*m #meters - model width
# Line 45  qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no h Line 50  qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no h
50  T1=20 * Celsius # initial temperature at Block 1  T1=20 * Celsius # initial temperature at Block 1
51  T2=2273. * Celsius # initial temperature at Block 2  T2=2273. * Celsius # initial temperature at Block 2
52
53    ################################################ESTABLISHING PARAMETERS
54  t=0 * day  # our start time, usually zero  t=0 * day  # our start time, usually zero
55  tend=50 * yr # - time to end simulation  tend=50 * yr # - time to end simulation
56  outputs = 200 # number of time steps required.  outputs = 200 # number of time steps required.
# Line 57  save_path= os.path.join("data","example0 Line 63  save_path= os.path.join("data","example0
63  #ensure the dir exists  #ensure the dir exists
64  mkDir(save_path, os.path.join(save_path,"tempT"))  mkDir(save_path, os.path.join(save_path,"tempT"))
65
66  #... generate domain ...  ####################################################DOMAIN CONSTRUCTION
67  blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)  blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
68  #... open PDE and set coefficients ...
69  mypde=LinearPDE(blocks)  ###############################################ESCRIPT PDE CONSTRUCTION
70  mypde.setSymmetryOn()  mypde.setSymmetryOn()
71  A=zeros((2,2))  A=zeros((2,2))
72  A[0,0]=kappa  A[0,0]=kappa
# Line 69  mypde.setValue(A=A,D=rhocp/h) Line 75  mypde.setValue(A=A,D=rhocp/h)
75  x=Solution(blocks).getX()  x=Solution(blocks).getX()
76  T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))  T= T1*whereNegative(x[0]-boundloc)+T2*(1-whereNegative(x[0]-boundloc))
77
78  # ... start iteration:  ########################################################START ITERATION
79  while t<tend:  while t<tend:
80        i+=1        i+=1
81        t+=h        t+=h

Legend:
 Removed from v.2949 changed lines Added in v.2977