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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2658 - (show annotations)
Thu Sep 10 02:58:44 2009 UTC (10 years, 9 months ago) by ahallam
File MIME type: text/x-python
File size: 3211 byte(s)
Updates to all files scripts to support MPI testing proceedure. Updates to cookbook, new section on functino spaces/domains (needs work). Finalising first 3 chapters for editing.
1 ########################################################
2 #
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 __copyright__="""Copyright (c) 2003-2009 by University of Queensland
14 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 """
22 Author: Antony Hallam antony.hallam@uqconnect.edu.au
23 """
24
25 from esys.pycad import CurveLoop
26 import numpy as np
27 # To run the function it is necessary to import the modules we
28 # require.
29 # This imports everything from the escript library
30 #from esys.escript import Locator
31 # 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 Locator
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
78
79 # joel wrote this to create directories for you
80 import os
81 def needdirs(dirlist):
82 for name in dirlist:
83 if name == '':
84 continue
85 if not os.path.exists(name):
86 try:
87 os.makedirs(name)
88 except OSError:
89 if not os.path.exists(save_path):
90 raise

  ViewVC Help
Powered by ViewVC 1.1.26