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

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

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

revision 2644 by ahallam, Thu Aug 27 04:03:32 2009 UTC revision 2645 by ahallam, Thu Sep 3 02:20:33 2009 UTC
# Line 1  Line 1 
1  # This is the cookbook library for generic scripts.  ########################################################
2  # Imports come from the folder cblib and contain script definitions.  #
3    # Copyright (c) 2003-2009 by University of Queensland
4    # Earth Systems Science Computational Center (ESSCC)
5    # http://www.uq.edu.au/esscc
6    #
7    # Primary Business: Queensland, Australia
8    # Licensed under the Open Software License version 3.0
9    # http://www.opensource.org/licenses/osl-3.0.php
10    #
11    ########################################################
12    
13  import sys  __copyright__="""Copyright (c) 2003-2009 by University of Queensland
14  import os  Earth Systems Science Computational Center (ESSCC)
15    http://www.uq.edu.au/esscc
16    Primary Business: Queensland, Australia"""
17    __license__="""Licensed under the Open Software License version 3.0
18    http://www.opensource.org/licenses/osl-3.0.php"""
19    __url__="https://launchpad.net/escript-finley"
20    
21  #set the subdirectory path  """
22  sys.path.insert(0,'cblib')  Author: Antony Hallam antony.hallam@uqconnect.edu.au
23  #import all examples to library  """
24  from wavesolver2d import *  
25  from wavesolver2df import *  from esys.pycad import *
26  from phones import *  import numpy as np
27  from getLoopCoords import *  # To run the function it is necessary to import the modules we
28  from toQuivLocs import *  # require.
29  from toXYTuple import *  # This imports everything from the escript library
30  #exit subdirectory  from esys.escript import *
31  del sys.path[0]  # numpy for array handling
32    import numpy as np
33    # pylab for matplotlib and plotting
34    import pylab as pl
35    # tools for dealing with PDEs - contains locator
36    from esys.escript.pdetools import *
37    
38    # routine to find consecutive coordinates of a loop in pycad
39    def getLoopCoords(loop):
40        # return all construction points of input
41        temp = loop.getConstructionPoints()
42        #create a numpy array for xyz components or construction points
43        coords = np.zeros([len(temp),3],float)
44        #place construction points in array
45        for i in range(0,len(temp)):
46            coords[i,:]=temp[i].getCoordinates()
47        #return a numpy array
48        return coords
49        
50    # Calculate the location of quivers for a matplotlib plot
51    # quivshape :: [x,y] :: number of quivers in x and y direction
52    # lenxax :: length of model along x
53    # lenyax :: length of model along y
54    # qu :: gradient of escript solution ie grad(T)
55    def toQuivLocs(quivshape,lenxax,lenyax,qu):
56        numquiv = quivshape[0]*quivshape[1] # total number of quivers
57        dx = lenxax/quivshape[0]+1. # quiver x spacing
58        dy = lenyax/quivshape[1]+1. # quiver y spacing
59        qulocs=np.zeros([numquiv,2],float) # memory for quiver locations
60        # fill qulocs
61        for i in range(0,quivshape[0]-1):
62            for j in range(0,quivshape[1]-1):
63                qulocs[i*quivshape[0]+j,:] = [dx+dx*i,dy+dy*j]
64        # retreive values for quivers direction and shape from qu
65        quL = Locator(qu.getFunctionSpace(),qulocs.tolist())
66        qu = quL(qu) #array of dx,dy for quivers
67        qu = np.array(qu) #turn into a numpy array
68        qulocs = quL.getX() #returns actual locations from data
69        qulocs = np.array(qulocs) #turn into a numpy array
70        return qu,qulocs    
71    
72    # Extract the X and Y coordinates of an array
73    # coords :: escript coordiantes from .getX function
74    def toXYTuple(coords):
75        coords = np.array(coords.toListOfTuples()) #convert to Tuple
76        coordX = coords[:,0]; coordY = coords[:,1] #X and Y components.
77        return coordX,coordY

Legend:
Removed from v.2644  
changed lines
  Added in v.2645

  ViewVC Help
Powered by ViewVC 1.1.26