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_getPotential3dSchlumberger(self): numElectrodes = 12 directionVector = [1., 0.] midPoint = [] totalApparentResVal = 130. current = 0.5 interval_a = 5 interval_n = 5 if not HAVE_GMSH: raise unittest.SkipTest("gmsh required for test") lc = 10.0 bufferThickness = 100 extents = [200, 200, 200] midPoint = [0, 0] lcDiv = 10.0 electrodes = [] start = [] start.append(midPoint[0] - (( (numElectrodes - 1) * interval_a) / 2. * directionVector[0])) start.append(midPoint[1] - (( (numElectrodes - 1) * interval_a) / 2. * directionVector[1])) electrodeTags = [] electrodeLst = [] for i in range(numElectrodes): electrodes.append([ start[0] + (directionVector[0] * i * interval_a), start[1] + (directionVector[1] * i * interval_a), 0 ]) electrodeTags.append("e%d" % i) runName = os.path.join(WORKDIR, "dcResSchlum%d-%d" % (lc, lc / lcDiv)) filename = os.path.join(TEST_DATA_ROOT, "schlum.geo") meshname = os.path.join(TEST_DATA_ROOT, "dcResSchlum10-1.msh") verbosity = 3 gmshGeo2Msh(filename, meshname, 3, 1, verbosity) dom = ReadGmsh(meshname, 3, diracTags=electrodeTags, diracPoints=electrodes) if mpirank == 0: os.unlink(meshname) primaryConductivity = Scalar(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Scalar(1 / 130., ContinuousFunction(dom)) schs = SchlumbergerSurvey(dom, primaryConductivity, secondaryConductivity, current, interval_a, interval_n, midPoint, directionVector, numElectrodes) potentials = schs.getPotentialAnalytic() totalApparentRes = schs.getApparentResistivity(potentials[2]) for i in totalApparentRes: for j in i: res_a = abs(j - totalApparentResVal) res_b = 0.1 * totalApparentResVal self.assertLess( res_a, res_b, "result of %g greater than tolerance of %g" % (res_a, res_b))
def read(self, filename, FS, expected, zipped = False): first = [0 for i in expected] reverse = [0 for i in expected] scale = [1 for i in expected] if not zipped: return readBinaryGrid(filename, FS, (), 50000, self.byteorder, self.datatype, first, expected, scale, reverse) if not HAVE_UNZIP: raise unittest.SkipTest("unzip library not available (boost_iostreams)") return ripleycpp._readBinaryGridFromZipped(filename, FS, (), 50000, self.byteorder, self.datatype, first, expected, scale, reverse)
def setUp(self): self.order = 2 d1 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0) d2 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0) d2.setX(d2.getX() + [0.5, 0.]) if getMPISizeWorld() > 1: with self.assertRaises(NotImplementedError) as pkg: self.domain = JoinFaces([d1, d2], optimize=False) e = pkg.exception if FINLEY_MERGE_ERROR not in str(e): raise e raise unittest.SkipTest(FINLEY_MERGE_ERROR) else: self.domain = JoinFaces([d1, d2], optimize=False)
def test_segy_writer2(self): sw = SimpleSEGYWriter(receiver_group=[(0., 0.), (1., -1.), (2., -2)], source=(3, 3), sampling_interval=10 * U.msec, text="testing") self.assertRaises(ValueError, sw.addRecord, [1]) for i in range(411): # Create some random data. data = np.random.ranf(3) sw.addRecord(data) try: sw.write(os.path.join(WORKDIR, "test2.sgy")) except Exception as e: if str(e) == writeFailMessage: raise unittest.SkipTest("obspy not installed") raise e
def test_MultiDimSplit_Rectangle(self): ranks = getMPISizeWorld() squares = [4, 9, 16, 25, 36] #could do more, unlikely to test though subdivs = [0, 0] loop = 0 if ranks not in squares: if ranks % 3 == 0: subdivs[0] = 3 subdivs[1] = ranks // 3 loop = 2 elif ranks % 2 == 0: subdivs[0] = 2 subdivs[1] = ranks // 2 loop = 1 else: raise unittest.SkipTest("inappropriate number of ranks") else: subdivs = [squares.index(ranks) + 2] * 2 loop = 2 for order in range(2, 11): divs = subdivs[:] for i in range(loop): r = rRectangle(2 * divs[0] * order - 1, 2 * divs[1] * order - 1, d0=divs[0], d1=divs[1]) s = sRectangle(order, divs[0] * 2, divs[1] * 2, d0=divs[0], d1=divs[1]) d = self.calculateVariance(s, r) res = Lsup(d) self.assertLess( res, 1e-10, "".join([ "Rectangles of order %d with " % order, "subdivisons %s " % divs, "failed to interpolate correctly", ", variance of %g" % res ])) divs.append(divs.pop(0))
def test_getPotentialPolDip(self): structured = False totalApparentRes = 130. if structured: extents = [100, 100, 100] dom = Brick(25, 25, 25, l0=extents[0], l1=extents[1], l2=-extents[2]) else: if not HAVE_GMSH: raise unittest.SkipTest("gmsh required for test") extents = [100, 100, 100] electrodes = [] tags = [] tags.append("e0") tags.append("e1") tags.append("e2") tags.append("e3") tags.append("e4") tags.append("e5") tags.append("e6") tags.append("e7") tags.append("e8") tags.append("e9") tags.append("e10") tags.append("e11") electrodes.append([-22.0, 0.0, 0]) electrodes.append([-18.0, 0.0, 0]) electrodes.append([-14.0, 0.0, 0]) electrodes.append([-10.0, 0.0, 0]) electrodes.append([-6.0, 0.0, 0]) electrodes.append([-2.0, 0.0, 0]) electrodes.append([2.0, 0.0, 0]) electrodes.append([6.0, 0.0, 0]) electrodes.append([10.0, 0.0, 0]) electrodes.append([14.0, 0.0, 0]) electrodes.append([18.0, 0.0, 0]) electrodes.append([22.0, 0.0, 0]) filename = os.path.join(TEST_DATA_ROOT, "dip.geo") meshname = os.path.join(TEST_DATA_ROOT, "dcRespoldip10-1.msh") verbosity = 3 gmshGeo2Msh(filename, meshname, 3, 1, verbosity) dom = ReadGmsh(meshname, 3, diracTags=tags, diracPoints=electrodes) if mpirank == 0: os.unlink(meshname) n = 5 totalApparentResVal = 130. primaryConductivity = Scalar(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Scalar(1 / 130., ContinuousFunction(dom)) current = 1000. numElectrodes = 12 # a=(.8*extents[0])/numElectrodes a = 4 midPoint = [0, 0] directionVector = [1., 0.] poldips = PoleDipoleSurvey(dom, primaryConductivity, secondaryConductivity, current, a, n, midPoint, directionVector, numElectrodes) poldips.getPotential() primaryApparentRes = poldips.getApparentResistivityPrimary() SecondaryApparentRes = poldips.getApparentResistivitySecondary() totalApparentRes = poldips.getApparentResistivityTotal() for i in totalApparentRes: for j in i: res_a = abs(j - totalApparentResVal) res_b = 0.1 * totalApparentResVal self.assertLess( res_a, res_b, "result of %g greater than tolerance of %g" % (res_a, res_b))