def test_mismatch_errors(self): ranks = getMPISizeWorld() r = rRectangle(2 * ranks - 1, 2, l0=1., d0=ranks) s = sRectangle(2, 2 * ranks, 2, l0=2., d0=ranks) with self.assertRaises(RuntimeError): #length mismatch self.calculateVariance(r, s) r = rBrick(2 * ranks - 1, 2, 2, l1=2., d0=ranks) s = sBrick(2, 2 * ranks, 2, 2, l1=1., d0=ranks) with self.assertRaises(RuntimeError): #length mismatch self.calculateVariance(r, s) r = rRectangle(2 * ranks - 1, 2, l0=1., l1=2., d0=ranks) s = sBrick(2, 2 * ranks, 2, 2, l0=2., l1=1., d0=ranks) with self.assertRaises(RuntimeError): #dimensionality mismatch self.calculateVariance(r, s) if getMPISizeWorld() > 1: r = rRectangle(2 * ranks - 1, 2, l0=1., d0=ranks) s = sRectangle(2, 2, 2 * ranks, l0=2., d1=ranks) with self.assertRaises(RuntimeError): #subdivision mismatch self.calculateVariance(r, s)
def test_mismatch_errors(self): ranks = getMPISizeWorld() r = rRectangle(2 * ranks - 1, 2, l0=1.0, d0=ranks) s = sRectangle(2, 2 * ranks, 2, l0=2.0, d0=ranks) with self.assertRaises(RuntimeError): # length mismatch self.calculateVariance(r, s) r = rBrick(2 * ranks - 1, 2, 2, l1=2.0, d0=ranks) s = sBrick(2, 2 * ranks, 2, 2, l1=1.0, d0=ranks) with self.assertRaises(RuntimeError): # length mismatch self.calculateVariance(r, s) r = rRectangle(2 * ranks - 1, 2, l0=1.0, l1=2.0, d0=ranks) s = sBrick(2, 2 * ranks, 2, 2, l0=2.0, l1=1.0, d0=ranks) with self.assertRaises(RuntimeError): # dimensionality mismatch self.calculateVariance(r, s) if getMPISizeWorld() > 1: r = rRectangle(2 * ranks - 1, 2, l0=1.0, d0=ranks) s = sRectangle(2, 2, 2 * ranks, l0=2.0, d1=ranks) with self.assertRaises(RuntimeError): # subdivision mismatch self.calculateVariance(r, s)
def test_TriaxialSplits_Brick(self): ranks = getMPISizeWorld() cubes = [8, 27, 64] #could do more, unlikely to test though error_msg = "Brick of order {0} and subdivisions {1} failed to"+\ " interpolate correctly, variance of {2}" subdivs = [0, 0, 0] loop = 3 if ranks not in cubes: if ranks % 2 == 0: subdivs[0] = 2 if (ranks // 2) % 2 == 0: subdivs[1] = 2 subdivs[2] = ranks // 4 elif (ranks // 2) % 3 == 0: subdivs[1] = 3 subdivs[2] = ranks // 6 else: raise unittest.SkipTest("inappropriate number of ranks") elif ranks % 3 == 0: subdivs[0] = 3 if (ranks // 2) % 2 == 0: subdivs[1] = 2 subdivs[2] = ranks // 4 elif (ranks // 2) % 3 == 0: subdivs[1] = 3 subdivs[2] = ranks // 6 else: raise unittest.SkipTest("inappropriate number of ranks") else: raise unittest.SkipTest("inappropriate number of ranks") else: subdivs = [cubes.index(ranks) + 2] * 3 loop = 1 for order in range(2, 11): for i in range(loop): divs = subdivs[i:] + subdivs[:i] r = rBrick(2 * divs[0] * order - 1, 2 * divs[1] * order - 1, 2 * divs[2] * order - 1, d0=divs[0], d1=divs[1], d2=divs[2]) s = sBrick(order, divs[0] * 2, divs[1] * 2, divs[2] * 2, d0=divs[0], d1=divs[1], d2=divs[2]) res = Lsup(self.calculateVariance(s, r)) self.assertLess(res, 1e-10, error_msg.format(order, divs, res))
def test_TriaxialSplits_Brick(self): ranks = getMPISizeWorld() cubes = [8, 27, 64] # could do more, unlikely to test though error_msg = "Brick of order {0} and subdivisions {1} failed to" + " interpolate correctly, variance of {2}" subdivs = [0, 0, 0] loop = 3 if ranks not in cubes: if ranks % 2 == 0: subdivs[0] = 2 if (ranks // 2) % 2 == 0: subdivs[1] = 2 subdivs[2] = ranks // 4 elif (ranks // 2) % 3 == 0: subdivs[1] = 3 subdivs[2] = ranks // 6 else: raise unittest.SkipTest("inappropriate number of ranks") elif ranks % 3 == 0: subdivs[0] = 3 if (ranks // 2) % 2 == 0: subdivs[1] = 2 subdivs[2] = ranks // 4 elif (ranks // 2) % 3 == 0: subdivs[1] = 3 subdivs[2] = ranks // 6 else: raise unittest.SkipTest("inappropriate number of ranks") else: raise unittest.SkipTest("inappropriate number of ranks") else: subdivs = [cubes.index(ranks) + 2] * 3 loop = 1 for order in range(2, 11): for i in range(loop): divs = subdivs[i:] + subdivs[:i] r = rBrick( 2 * divs[0] * order - 1, 2 * divs[1] * order - 1, 2 * divs[2] * order - 1, d0=divs[0], d1=divs[1], d2=divs[2], ) s = sBrick(order, divs[0] * 2, divs[1] * 2, divs[2] * 2, d0=divs[0], d1=divs[1], d2=divs[2]) res = Lsup(self.calculateVariance(s, r)) self.assertLess(res, 1e-10, error_msg.format(order, divs, res))
def createDomains(self, pointsPerDim): """ Creates a pair of domains with the previously supplied information and number of points. :param pointsPerDim: the number of data points (not elements) in each dimension :type pointsPerDim: ``tuple`` of ``int`` """ splitDim = pointsPerDim.index(max(pointsPerDim)) divs = [1] * self.dim divs[splitDim] = self.ranks speckleyElements = [] ripleyElements = [] for i in range(self.dim): points = pointsPerDim[i] if i == splitDim: ripleyElements.append(points + self.ranks - (points % self.ranks) - 1) else: ripleyElements.append(points) speck = ripleyElements[i] / self.order % self.ranks if i == splitDim: if speck != 0: speck = self.ranks - speck speck += ripleyElements[i] / self.order if speck < 2: speck = 2 speckleyElements.append(speck) self.speckleyShape = tuple(speckleyElements) self.ripleyShape = tuple(ripleyElements) if self.dim == 2: l0, l1 = self.lengths ex, ey = speckleyElements self.speckley = sRectangle(self.order, ex, ey, d0=divs[0], d1=divs[1], l0=l0, l1=l1, diracPoints=self.diracPoints, diracTags=self.diracTags) ex, ey = ripleyElements self.ripley = rRectangle(ex, ey, d0=divs[0], d1=divs[1], l0=l0, l1=l1, diracPoints=self.diracPoints, diracTags=self.diracTags) else: l0, l1, l2 = self.lengths ex, ey, ez = speckleyElements self.speckley = sBrick(self.order, ex, ey, ez, d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2, diracPoints=self.diracPoints, diracTags=self.diracTags) ex, ey, ez = ripleyElements self.ripley = rBrick(ex, ey, ez, d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2, diracPoints=self.diracPoints, diracTags=self.diracTags)
def createDomains(self, pointsPerDim): """ Creates a pair of domains with the previously supplied information and number of points. :param pointsPerDim: the number of data points (not elements) in each dimension :type pointsPerDim: ``tuple`` of ``int`` """ splitDim = pointsPerDim.index(max(pointsPerDim)) divs = [1] * self.dim divs[splitDim] = self.ranks speckleyElements = [] ripleyElements = [] for i in range(self.dim): points = pointsPerDim[i] if i == splitDim: ripleyElements.append(points + self.ranks - (points % self.ranks) - 1) else: ripleyElements.append(points) speck = ripleyElements[i] / self.order % self.ranks if i == splitDim: if speck != 0: speck = self.ranks - speck speck += ripleyElements[i] / self.order if speck < 2: speck = 2 speckleyElements.append(speck) self.speckleyShape = tuple(speckleyElements) self.ripleyShape = tuple(ripleyElements) if self.dim == 2: l0, l1 = self.lengths ex, ey = speckleyElements self.speckley = sRectangle( self.order, ex, ey, d0=divs[0], d1=divs[1], l0=l0, l1=l1, diracPoints=self.diracPoints, diracTags=self.diracTags, ) ex, ey = ripleyElements self.ripley = rRectangle( ex, ey, d0=divs[0], d1=divs[1], l0=l0, l1=l1, diracPoints=self.diracPoints, diracTags=self.diracTags ) else: l0, l1, l2 = self.lengths ex, ey, ez = speckleyElements self.speckley = sBrick( self.order, ex, ey, ez, d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2, diracPoints=self.diracPoints, diracTags=self.diracTags, ) ex, ey, ez = ripleyElements self.ripley = rBrick( ex, ey, ez, d0=divs[0], d1=divs[1], d2=divs[2], l0=l0, l1=l1, l2=l2, diracPoints=self.diracPoints, diracTags=self.diracTags, )