/[escript]/trunk/doc/examples/cookbook/example01a.py
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/doc/examples/cookbook/onedheatdiff.py revision 2632 by ahallam, Wed Aug 26 22:18:19 2009 UTC trunk/doc/examples/cookbook/example01a.py revision 2977 by ahallam, Tue Mar 9 00:33:28 2010 UTC
# Line 1  Line 1 
1    
2  ########################################################  ########################################################
3  #  #
4  # Copyright (c) 2003-2009 by University of Queensland  # Copyright (c) 2009 by University of Queensland
5  # Earth Systems Science Computational Center (ESSCC)  # Earth Systems Science Computational Center (ESSCC)
6  # http://www.uq.edu.au/esscc  # http://www.uq.edu.au/esscc
7  #  #
# Line 11  Line 11 
11  #  #
12  ########################################################  ########################################################
13    
14  __copyright__="""Copyright (c) 2003-2009 by University of Queensland  __copyright__="""Copyright (c) 2009 by University of Queensland
15  Earth Systems Science Computational Center (ESSCC)  Earth Systems Science Computational Center (ESSCC)
16  http://www.uq.edu.au/esscc  http://www.uq.edu.au/esscc
17  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
# Line 22  __url__="https://launchpad.net/escript-f Line 22  __url__="https://launchpad.net/escript-f
22  """  """
23  Author: Antony Hallam antony.hallam@uqconnect.edu.au  Author: Antony Hallam antony.hallam@uqconnect.edu.au
24  """  """
25    ############################################################FILE HEADER
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 *
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
 import os #This package is necessary to handle saving our data.  
36    
37    #################################################ESTABLISHING VARIABLES
38    #Domain related.
39    mx = 500*m #meters - model length
40    my = 100*m #meters - model width
41    ndx = 100 # mesh steps in x direction
42    ndy = 1 # mesh steps in y direction - one dimension means one element
43    boundloc = mx/2 # location of boundary between the two blocks
44    #PDE related
45    rho = 7874. *kg/m**3 #kg/m^{3} density of iron
46    cp = 449.*J/(kg*K) # J/Kg.K thermal capacity
47    rhocp = rho*cp
48    kappa = 80.*W/m/K   # watts/m.Kthermal conductivity
49    qH=0 * J/(sec*m**3) # J/(sec.m^{3}) no heat source
50    T1=20 * Celsius # initial temperature at Block 1
51    T2=2273. * Celsius # initial temperature at Block 2
52    
53    ################################################ESTABLISHING PARAMETERS
54    t=0 * day  # our start time, usually zero
55    tend=50 * yr # - time to end simulation
56    outputs = 200 # number of time steps required.
57    h=(tend-t)/outputs #size of time step
58    #user warning statement
59    print "Expected Number of time outputs is: ", (tend-t)/h
60    i=0 #loop counter
61    #the folder to put our outputs in, leave blank "" for script path
62    save_path= os.path.join("data","example01")
63    #ensure the dir exists
64    mkDir(save_path, os.path.join(save_path,"tempT"))
65    
66    ####################################################DOMAIN CONSTRUCTION
67    blocks = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
68    
69  ##ESTABLISHING VARIABLES  ###############################################ESCRIPT PDE CONSTRUCTION
 #PDE related  
 q=50.e6 #our heat source temperature  
 Tref=0. #the starting temperature of our iron bar  
 rho=2.6e6  
 eta=0#75.  
 kappa=240.  
 #Script/Iteration Related  
 t=0 #our start time, usually zero  
 tend=5.#the time we want to end the simulation  
 h=0.05 #size of time step  
   
 print "Expected Number of Output Files is: ", (tend-t)/h  
   
 i=0 #loop counter  
 save_path = "data/onedheatdiff" #the folder to put our outputs in, leave blank "" for script path - note this folder path must exist to work  
   
 #... generate domain ...  
 rod = Rectangle(l0=0.05,l1=.01,n0=500, n1=1)  
 # extract finite points  
 x=rod.getX()  
 #... open PDE ...  
 mypde=LinearPDE(rod)  
70  mypde.setSymmetryOn()  mypde.setSymmetryOn()
71  mypde.setValue(A=kappa*kronecker(rod),D=rho/h,d=eta,y=eta*Tref)  A=zeros((2,2))
72  # ... set heat source: ....  A[0,0]=kappa
73    mypde.setValue(A=A,D=rhocp/h)
 qH=q*whereZero(x[0])  
74  # ... set initial temperature ....  # ... set initial temperature ....
75  T=Tref  x=Solution(blocks).getX()
76    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
82        mypde.setValue(Y=qH+rho/h*T)        mypde.setValue(Y=qH+rhocp/h*T)
83        T=mypde.getSolution()        T=mypde.getSolution()
84        print T        totE=integrate(rhocp*T)
85        saveVTK(os.path.join(save_path,"data%03d.vtu") %i,sol=T)        print "time step %s at t=%e days completed. total energy = %e."%(i,t/day,totE)
         
 #~ command = ('mencoder',  
            #~ 'mf://*.png',  
            #~ '-mf',  
            #~ 'type=png:w=800:h=600:fps=25',  
            #~ '-ovc',  
            #~ 'lavc',  
            #~ '-lavcopts',  
            #~ 'vcodec=mpeg4',  
            #~ '-oac',  
            #~ 'copy',  
            #~ '-o',  
            #~ 'output.avi')  
   

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

  ViewVC Help
Powered by ViewVC 1.1.26