/[escript]/trunk/escriptcore/py_src/domainCouplers.py
ViewVC logotype

Contents of /trunk/escriptcore/py_src/domainCouplers.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5575 - (show annotations)
Wed Apr 1 03:17:22 2015 UTC (4 years ago) by sshaw
File MIME type: text/x-python
File size: 7266 byte(s)
sphinx now builds python doco including module-level docstrings and class __init__ docstrings, also cleared up some doco errors and added multires documentation
1
2 ##############################################################################
3 #
4 # Copyright (c) 2014-2015 by University of Queensland
5 # http://www.uq.edu.au
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 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 """
18 These domain couplers create a matching domain from each of two different domain
19 families, allowing more simple interpolation across the two. These domains
20 must already support interpolation in at least one direction.
21
22 """
23
24 __copyright__="""Copyright (c) 2014-2015 by University of Queensland
25 http://www.uq.edu.au
26 Primary Business: Queensland, Australia"""
27 __license__="""Licensed under the Open Software License version 3.0
28 http://www.opensource.org/licenses/osl-3.0.php"""
29 __url__="https://launchpad.net/escript-finley"
30
31 from esys.escriptcore.escriptcpp import getMPISizeWorld, MPIBarrierWorld
32 try:
33 from esys.ripley import Rectangle as rRectangle
34 from esys.ripley import Brick as rBrick
35 except ImportError:
36 raise ImportError("Missing required ripley module")
37 try:
38 from esys.speckley import Rectangle as sRectangle
39 from esys.speckley import Brick as sBrick
40 except ImportError:
41 raise ImportError("Missing required ripley module")
42 class SpeckleyToRipley(object):
43 """
44 A class for creating and storing a matching pair of domains from speckley
45 and ripley families.
46 """
47
48 DEFAULT_lengths = (1.,1.,1.)
49 DEFAULT_order = 2
50
51 def __init__(self, dimensions, pointsPerDim, lengths=None, diracPoints=[],
52 diracTags=[], order=None):
53 """
54 Initialises the coupler, creating domains.
55
56 :param dimensions: whether 2-dimensional or 3-dimensional
57 :type dimensions: ``int``
58 :param pointsPerDim: the number of data points (not elements) in each
59 dimension
60 :type pointsPerDim: ``tuple`` of ``int``
61 :param lengths: the length of the domain, defaults to 1 in each dimension
62 :type lengths: ``tuple`` of ``int``
63 :param diracPoints: set of dirac point locations
64 :type diracPoints: ``tuple`` of ``tuple`` of ``float``
65 :param diracTags: tag name for each point in `diracPoints`
66 :type diracTags: ``tuple`` of ``string``
67 :param order: element order of the speckley domain, defaults to 2
68 :type order: ``int``
69 """
70 self.ranks = getMPISizeWorld()
71
72 if dimensions not in [2,3]:
73 raise ValueError("SpeckleyToRipley: requires dimension of 2 or 3")
74 self.dim = dimensions
75
76 if len(pointsPerDim) != dimensions:
77 raise ValueError("SpeckleyToRipley: requires point estimate for each dimension")
78 for point in pointsPerDim:
79 if point < 2:
80 raise ValueError("SpeckleyToRipley: requires at least 2 points per dimension")
81
82 if lengths is None:
83 lengths = self.DEFAULT_lengths[:self.dim]
84 else:
85 if len(lengths) != dimensions:
86 raise ValueError("SpeckleyToRipley: requires length for each dimension")
87 for length in lengths:
88 if length <= 0:
89 raise ValueError("SpeckleyToRipley: requires positive lengths")
90 self.lengths = lengths
91
92 if order is None:
93 order = self.DEFAULT_order
94 self.order = order
95 self.diracPoints = diracPoints
96 self.diracTags = diracTags
97
98 self.createDomains(pointsPerDim)
99
100
101 def createDomains(self, pointsPerDim):
102 """
103 Creates a pair of domains with the previously supplied information and
104 number of points.
105
106 :param pointsPerDim: the number of data points (not elements) in each
107 dimension
108 :type pointsPerDim: ``tuple`` of ``int``
109 """
110
111 splitDim = pointsPerDim.index(max(pointsPerDim))
112 divs = [1]*self.dim
113 divs[splitDim] = self.ranks
114 speckleyElements = []
115 ripleyElements = []
116 for i in range(self.dim):
117 points = pointsPerDim[i]
118 if i == splitDim:
119 ripleyElements.append(points + self.ranks - (points % self.ranks) - 1)
120 else:
121 ripleyElements.append(points)
122 speck = ripleyElements[i]/self.order % self.ranks
123 if i == splitDim:
124 if speck != 0:
125 speck = self.ranks - speck
126 speck += ripleyElements[i]/self.order
127 if speck < 2:
128 speck = 2
129 speckleyElements.append(speck)
130
131 self.speckleyShape = tuple(speckleyElements)
132 self.ripleyShape = tuple(ripleyElements)
133 if self.dim == 2:
134 l0,l1 = self.lengths
135 ex,ey = speckleyElements
136 self.speckley = sRectangle(self.order, ex, ey,
137 d0=divs[0], d1=divs[1], l0=l0, l1=l1,
138 diracPoints=self.diracPoints, diracTags=self.diracTags)
139
140 ex,ey = ripleyElements
141 self.ripley = rRectangle(ex, ey,
142 d0=divs[0], d1=divs[1], l0=l0, l1=l1,
143 diracPoints=self.diracPoints, diracTags=self.diracTags)
144 else:
145 l0,l1,l2 = self.lengths
146 ex,ey,ez = speckleyElements
147 self.speckley = sBrick(self.order, ex, ey, ez,
148 d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2,
149 diracPoints=self.diracPoints, diracTags=self.diracTags)
150
151 ex,ey,ez = ripleyElements
152 self.ripley = rBrick(ex, ey, ez,
153 d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2,
154 diracPoints=self.diracPoints, diracTags=self.diracTags)
155
156 def getShapes(self):
157 """
158 Returns the shape of the domains
159
160 :return: A ``tuple`` of the two shape ``tuples`` in the form
161 (speckley, ripley)
162 :rtype: ``tuple`` of ``tuple`` of ``int``
163 """
164 return (self.speckleyShape, self.ripleyShape)
165
166 def getSpeckleyShape(self):
167 """
168 Returns the shape of the speckley domain
169
170 :return: A ``tuple`` containing the number of elements in each dimension
171 :rtype: ``tuple`` of ``int``
172 """
173 return self.speckleyShape
174
175 def getRipleyShape(self):
176 """
177 Returns the shape of the speckley domain
178
179 :return: A ``tuple`` containing the number of elements in each dimension
180 :rtype: ``tuple`` of ``int``
181 """
182 return self.ripleyShape
183
184 def getDomains(self):
185 return (self.speckley, self.ripley)
186
187 def getSpeckley(self):
188 """
189 Returns the speckley domain
190
191 :return: The speckley domain
192 :rtype: ``SpeckleyDomain``
193 """
194 return self.speckley
195
196 def getRipley(self):
197 """
198 Returns the `ripley` domain
199
200 :return: The `ripley` domain
201 :rtype: ``RipleyDomain``
202 """
203 return self.ripley
204
205

  ViewVC Help
Powered by ViewVC 1.1.26