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 |
|
|
|
#set the subdirectory path |
|
|
sys.path.insert(0,'cblib') |
|
|
#import all examples to library |
|
|
from wavesolver2d import * |
|
|
#exit subdirectory |
|
|
del sys.path[0] |
|
21 |
|
""" |
22 |
|
Author: Antony Hallam antony.hallam@uqconnect.edu.au |
23 |
|
""" |
24 |
|
|
25 |
|
from esys.pycad import * |
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 * |
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 * |
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 |