Пример #1
0
def __add_tests(suite, modulename):
    import inspect
    clsmembers = inspect.getmembers(sys.modules[modulename], inspect.isclass)
    for name, cls in clsmembers:
        if modulename == cls.__module__ and name.startswith("Test") \
                and issubclass(cls, unittest.TestCase):
            suite.addTest(unittest.makeSuite(cls))
Пример #2
0
def run_tests(modulename, classes=[], exit_on_failure=False):
    rank = getMPIRankWorld()
    stream = sys.stderr  #default
    verb = 2
    if rank > 0:
        stream = open(os.devnull, 'w')
        verb = 0

    suite = unittest.TestSuite()
    if len(classes) == 0:
        __add_tests(suite, modulename)
    else:
        for test_class in classes:
            suite.addTest(unittest.makeSuite(test_class))
    s = unittest.TextTestRunner(stream=stream, verbosity=verb).run(suite)
    if exit_on_failure and not s.wasSuccessful():
        sys.stderr.flush()
        MPIBarrierWorld()
        sys.exit(1)
    return s
Пример #3
0
        self.runModel(model, PERIODS, TOL=1.e-1)

    def test_RhoBDataFailed(self):
        """
        resistivity set on elements, no value on boundary but interpolation is not possible fixed bottom 
        """
        PERIODS = np.logspace(2,
                              3,
                              num=3,
                              endpoint=True,
                              base=10.0,
                              dtype=float)
        rho = self.airLayerMaskCenter * 9999999 + (
            1 - self.airLayerMaskCenter) * self.RHO0
        model = MT2DTMModel(self.domain,
                            fixBottom=False,
                            airLayer=self.DEPTH - self.AIR_LAYER,
                            useFastSolver=self.USEFASTSOLVER)
        self.assertEqual(0, Lsup(model.airLayer - self.airLayerMask))
        self.assertRaises(RuntimeError, model.setResistivity, *(rho, ))


if __name__ == '__main__':

    mySuite = unittest.TestSuite()
    mySuite.addTest(unittest.makeSuite(TestMT2DTE))
    mySuite.addTest(unittest.makeSuite(TestMT2DTMNoAirLayer))
    mySuite.addTest(unittest.makeSuite(TestMT2DTMWithAirLayer))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(mySuite)
Пример #4
0
        xmin = inf(x[0])
        xmax = sup(x[0])
        ymin = inf(x[1])
        ymax = sup(x[1])
        zmin = inf(x[2])
        zmax = sup(x[2])
        xp = 2. * np.pi / (xmax - xmin)
        yp = 2. * np.pi / (ymax - ymin)
        zp = 2. * np.pi / (zmax - zmin)
        Bh = [1., 0., 0.]
        k = ((xp**2 + yp**2 + zp**2) / xp) * cos(xp * x[0]) * sin(
            yp * x[1]) * cos(zp * x[2])
        model.setSusceptibility(k)
        outk = model.getSusceptibility()
        kdiff = abs(k - outk)
        self.assertLessEqual(sup(kdiff), self.TESTTOL)
        model.setBackgroundMagneticField(Bh)
        actualanswer = sin(xp * x[0]) * sin(yp * x[1]) * cos(zp * x[2])
        abserror = abs(actualanswer - model.getAnomalyPotential())
        biggesterror = sup(abserror)
        self.assertLessEqual(biggesterror, self.TESTTOL)


if __name__ == '__main__':

    mySuite = unittest.TestSuite()
    mySuite.addTest(unittest.makeSuite(TestMagneticApp2D))
    mySuite.addTest(unittest.makeSuite(TestMagneticApp3D))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(mySuite)
Пример #5
0
        xmax = sup(x[0])
        ymin = inf(x[1])
        ymax = sup(x[1])
        zmin = inf(x[2])
        zmax = sup(x[2])
        xp = 2. * np.pi / (xmax - xmin)
        yp = 2. * np.pi / (ymax - ymin)
        zp = 2. * np.pi / (zmax - zmin)
        Dens = (xp**2 + yp**2 + zp**2) * cos(xp * x[0]) * cos(yp * x[1]) * sin(
            zp * x[2]) / (4.0 * np.pi * U.Gravitational_Constant)
        model.setDensity(Dens)
        outdens = model.getDensity()
        densdiff = abs(Dens - outdens)
        self.assertLessEqual(sup(densdiff), self.TESTTOL)
        actualanswer = -cos(xp * x[0]) * cos(yp * x[1]) * sin(zp * x[2])
        abserror = abs(actualanswer - model.getGravityPotential())
        biggesterror = sup(abserror)
        self.assertLessEqual(biggesterror, self.TESTTOL)
        gz = model.getzGravity()
        actualgz = -zp * cos(xp * x[0]) * cos(yp * x[1]) * cos(zp * x[2])
        errorgz = abs(gz - actualgz)
        self.assertLessEqual(sup(errorgz), self.TESTTOL * 100.)


if __name__ == '__main__':

    mySuite = unittest.TestSuite()
    mySuite.addTest(unittest.makeSuite(TestGravityApp))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(mySuite)
Пример #6
0
      self.__test_3DT(my_dom,7,1./sqrt(EPSILON))
   def test_Tet3D_macro_integorder8(self):
      my_dom = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"tet10_macro.fly"),optimize=False,integrationOrder=8)
      self.__test_3DT(my_dom,8,1./sqrt(EPSILON))
   def test_Tet3D_macro_integorder9(self):
      my_dom = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"tet10_macro.fly"),optimize=False,integrationOrder=9)
      self.__test_3DT(my_dom,9,1./sqrt(EPSILON))
   def test_Tet3D_macro_integorder10(self):
      my_dom = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"tet10_macro.fly"),optimize=False,integrationOrder=10)
      self.__test_3DT(my_dom,10,1./sqrt(EPSILON))

if __name__ == '__main__':
   suite = unittest.TestSuite()

   if getMPISizeWorld() == 1: 
        suite.addTest(unittest.makeSuite(Test_Generators))
   else:
        print("Test_Generators is dropped as number of processors >1")

   if getMPISizeWorld() == 1: 
        suite.addTest(unittest.makeSuite(Test_GMSHReader))
   else:
        print("Test_GMSHReader is dropped as number of processors >1")

   if getMPISizeWorld() == 1: 
        suite.addTest(unittest.makeSuite(Test_Reader))
   else:
        print("Test_Reader is dropped as number of processors >1")

   suite.addTest(unittest.makeSuite(Test_Integration))
   s=unittest.TextTestRunner(verbosity=2).run(suite)
Пример #7
0
        L_PML = self.DX * self.NE_PML
        pml_condition = PMLCondition(sigma0=self.S0,
                                     Lleft=[L_PML, L_PML],
                                     Lright=[L_PML, L_PML],
                                     m=4)
        # sonic wave model
        wave = SonicWaveInFrequencyDomain(self.domain,
                                          vp=self.VP,
                                          pml_condition=pml_condition)
        wave.setFrequency(Frequency)
        # set source and get wave response:
        u = wave.getWave(self.source)

        r = np.array([
            sqrt((x[0] - self.sourceX[0])**2 + (x[1] - self.sourceX[1])**2)
            for x in self.loc.getX()
        ])
        uu2 = -scipy.special.hankel2(0, k * r) * 1j / 4
        uu = np.array(self.loc(u))
        errorA = max(abs(uu2 - uu))
        A = max(abs(uu2))
        self.assertLessEqual(errorA, A * self.TESTTOL)


if __name__ == '__main__':

    mySuite = unittest.TestSuite()
    mySuite.addTest(unittest.makeSuite(TestSeismic2D))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(mySuite)