Beispiel #1
0
class TestMagneticApp2D(unittest.TestCase):

    xdim = 1000.
    zdim = 1000.
    NEX = 100
    NEZ = 100
    TESTTOL = 1e-3

    def setUp(self):
        self.domain = Rectangle(self.NEX, self.NEZ, l0=self.xdim, l1=self.zdim)

    def tearDown(self):
        del self.domain

    def test_pde_answer(self):
        model = MagneticModel2D(self.domain, fixVert=True)
        x = self.domain.getX()
        xmin = inf(x[0])
        xmax = sup(x[0])
        ymin = inf(x[1])
        ymax = sup(x[1])
        xp = 2. * np.pi / (xmax - xmin)
        yp = 2. * np.pi / (ymax - ymin)
        Bh = [1., 0.]
        k = ((xp**2 + yp**2) / xp) * cos(xp * x[0]) * cos(yp * x[1])
        model.setSusceptibility(k)
        outk = model.getSusceptibility()
        kdiff = abs(k - outk)
        self.assertLessEqual(sup(kdiff), self.TESTTOL)
        model.setBackgroundMagneticField(Bh)
        actualanswer = sin(xp * x[0]) * cos(yp * x[1])
        abserror = abs(actualanswer - model.getAnomalyPotential())
        biggesterror = sup(abserror)
        self.assertLessEqual(biggesterror, self.TESTTOL)
Beispiel #2
0
class TestMT2DTMWithAirLayer(unittest.TestCase):

    DEPTH = 3000.
    WIDTH = 1000.
    RHO0 = 100.
    NEX = 100
    NEZ = 300
    STATION_OFFSET = 1000.
    AIR_LAYER = 300.

    TRUE_PHASE = 45.
    TRUE_RHO = 100.
    USEFASTSOLVER = False  # True works not yet

    def setUp(self):
        self.domain = Rectangle(self.NEX,
                                self.NEZ,
                                l0=self.WIDTH,
                                l1=self.DEPTH)
        self.loc = Locator(ReducedFunction(self.domain),
                           [(self.STATION_OFFSET, self.DEPTH - self.AIR_LAYER -
                             self.DEPTH / self.NEZ / 2)])
        self.airLayerMask = whereNonNegative(self.domain.getX()[1] -
                                             self.DEPTH + self.AIR_LAYER)
        self.airLayerMaskCenter = whereNonNegative(
            ReducedFunction(self.domain).getX()[1] - self.DEPTH +
            self.AIR_LAYER)

    def tearDown(self):
        del self.domain
        del self.loc

    def runModel(self, model, PERIODS, TOL):
        for frq in PERIODS:
            Zyx = model.getImpedance(f=frq)
            self.assertIsInstance(Zyx, Data)
            self.assertEqual(Zyx.getShape(), ())
            self.assertEqual(Zyx.getFunctionSpace(),
                             ReducedFunction(self.domain))

            rho = model.getApparentResitivity(frq, Zyx)
            self.assertIsInstance(rho, Data)
            self.assertEqual(rho.getShape(), ())
            self.assertEqual(rho.getFunctionSpace(),
                             ReducedFunction(self.domain))

            phi = model.getPhase(frq, Zyx)
            self.assertIsInstance(phi, Data)
            self.assertEqual(phi.getShape(), ())
            self.assertEqual(phi.getFunctionSpace(),
                             ReducedFunction(self.domain))

            #print(frq, self.loc(rho)[0], self.loc(phi)[0])
            self.assertAlmostEqual(self.loc(rho)[0],
                                   self.TRUE_RHO,
                                   delta=TOL * self.TRUE_RHO)
            self.assertAlmostEqual(self.loc(phi)[0],
                                   self.TRUE_PHASE,
                                   delta=TOL * self.TRUE_PHASE)

    def test_RhoBFloat(self):
        """
        resistivity set on elements, radiation condition
        """
        PERIODS = np.logspace(-2,
                              2,
                              num=5,
                              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))
        model.setResistivity(rho, rho_boundary=self.RHO0)
        self.runModel(model, PERIODS, TOL=1.e-3)

    def test_RhoBDataFixedButtom(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=True,
                            airLayer=self.DEPTH - self.AIR_LAYER,
                            useFastSolver=self.USEFASTSOLVER)
        self.assertEqual(0, Lsup(model.airLayer - self.airLayerMask))
        model.setResistivity(rho)
        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, ))
print("Number of cells in x direction = ", NEX)
print("Number of cells in z direction = ", NEZ)
print("Air layer [m] = ", L_AIR)
print("periods [s] = ", PERIODS)

#==============================================

print("generating mesh ...")
domain=Rectangle(NEX,NEZ,l0=WIDTH,l1=DEPTH)

print("generating conductivity ...")
# you can replace this by an interpolation table read from a CSV file.
z=ReducedFunction(domain).getX()[domain.getDim()-1]
sigma=Scalar(SIGMA0, z.getFunctionSpace())
rho=Scalar(1./SIGMA0, z.getFunctionSpace())
z_top=sup(domain.getX()[domain.getDim()-1])
m_top=0.
for l, s in zip(LAYERS, SIGMA ):
    m2=wherePositive(z-z_top+l)
    m=m2-m_top
    sigma=(1-m)*sigma+m*s
    if s > 0:
       rho=(1-m)*rho+m*1./s
    else:
       rho=(1-m)*rho+m*0. # arbitray number as air_layer is backed out in TM mode.
       
    z_top, m_top=z_top-l, m2
    
print("sigma =", sigma)
print("rho =", rho)
#