Exemplo n.º 1
0
def test_layer_matrix_for_love_waves(beta, rho, h, w, c):
    """ Test the method for returning the layer matrix for Love Waves. """

    layer = Layer(alpha=None, beta=beta, rho=rho, h=h)

    # formulas from Oldrich Novotny -- Seismic Surface Waves
    k = w / c
    mu = rho * beta**2
    s = np.lib.scimath.sqrt((w / beta)**2 - k**2)
    Q = h * s

    a11 = np.cos(Q)

    if c == beta:
        a12 = 0
    else:
        a12 = np.sin(Q) / mu / s

    a21 = -mu * s * np.sin(Q)
    a22 = np.cos(Q)

    layer_matrix = layer.layer_matrix_love(omega=w, c=c)

    assert layer_matrix.shape == (2, 2)
    assert layer_matrix[0, 0] == a11
    assert layer_matrix[0, 1] == a12
    assert layer_matrix[1, 0] == a21
    assert layer_matrix[1, 1] == a22
Exemplo n.º 2
0
def test_layer_matrix_for_rayleigh_waves(alpha, beta, rho, h, w, c):
    """ Test the method for returning the layer matrix for Rayleigh Waves. """

    layer = Layer(alpha=alpha, beta=beta, rho=rho, h=h)

    # formulas from Oldrich Novotny -- Seismic Surface Waves
    k = w / c
    r = np.lib.scimath.sqrt((c / alpha)**2 - 1)
    s = np.lib.scimath.sqrt((c / beta)**2 - 1)
    gamma = 2 * (beta / c)**2
    delta = gamma - 1
    P = k * r * h
    Q = k * s * h

    a11 = a44 = gamma * np.cos(P) - delta * np.cos(Q)

    if c == alpha:
        a12 = a34 = gamma * s * np.sin(Q)
        a14 = s * np.sin(Q) / rho
        a32 = rho * gamma**2 * s * np.sin(Q)
    else:
        a12 = a34 = delta / r * np.sin(P) + gamma * s * np.sin(Q)
        a14 = (np.sin(P) / r + s * np.sin(Q)) / rho
        a32 = rho * (delta**2 / r * np.sin(P) + gamma**2 * s * np.sin(Q))

    if c == beta:
        a21 = a43 = gamma * r * np.sin(P)
        a23 = -r * np.sin(P) / rho
        a41 = -rho * gamma**2 * r * np.sin(P)
    else:
        a21 = a43 = gamma * r * np.sin(P) + delta / s * np.sin(Q)
        a23 = -(r * np.sin(P) + np.sin(Q) / s) / rho
        a41 = -rho * (gamma**2 * r * np.sin(P) + delta**2 / s * np.sin(Q))

    a13 = a24 = -(np.cos(P) - np.cos(Q)) / rho
    a22 = a33 = -delta * np.cos(P) + gamma * np.cos(Q)
    a31 = a42 = rho * gamma * delta * (np.cos(P) - np.cos(Q))

    layer_matrix = layer.layer_matrix_rayleigh(w, c)

    assert layer_matrix.shape == (4, 4)
    assert layer_matrix[0, 0] == a11
    assert layer_matrix[0, 1] == a12
    assert layer_matrix[0, 2] == a13
    assert layer_matrix[0, 3] == a14
    assert layer_matrix[1, 0] == a21
    assert layer_matrix[1, 1] == a22
    assert layer_matrix[1, 2] == a23
    assert layer_matrix[1, 3] == a24
    assert layer_matrix[2, 0] == a31
    assert layer_matrix[2, 1] == a32
    assert layer_matrix[2, 2] == a33
    assert layer_matrix[2, 3] == a34
    assert layer_matrix[3, 0] == a41
    assert layer_matrix[3, 1] == a42
    assert layer_matrix[3, 2] == a43
    assert layer_matrix[3, 3] == a44
Exemplo n.º 3
0
def test_layer_parameter_lines():
    """ Test the parameter_lines method. """

    l = Layer(100, 50, 1000, h=5)
    a, b, r, q = l.parameter_lines(dz=1)

    # returns constant curves, not including the last point
    assert np.alltrue(a == np.array([100] * 5))
    assert np.alltrue(b == np.array([50] * 5))
    assert np.alltrue(r == np.array([1000] * 5))
    assert np.alltrue(q == 0)
Exemplo n.º 4
0
def test_layer_creation():
    """ Test creation of Layers. """

    l = Layer(alpha=200, beta=100, rho=1500, h=10, Q=100)

    # when created, layers save the parameters
    assert l.alpha == 200
    assert l.beta == 100
    assert l.rho == 1500
    assert l.h == 10
    assert l.Q == 100

    # should not allow creating layers where beta > alpha
    with pytest.raises(ValueError):
        l = Layer(alpha=100, beta=200, rho=1000, h=5)
Exemplo n.º 5
0
def test_adding_layers(hlm):
    """ Test the process of adding layers to the HLM. """

    hlm.add_layer(alpha=250, beta=100, rho=1300, h=5)

    # HLM stores layers in the layers property
    assert len(hlm.layers) == 1

    # the layers are accessible via that property
    l0 = hlm.layers[0]
    assert isinstance(l0, Layer)
    assert l0.alpha == 250
    assert l0.beta == 100
    assert l0.rho == 1300
    assert l0.h == 5

    # the attribute is read only, so the layers are only added via the method
    with pytest.raises(AttributeError):
        hlm.layers.append(Layer(100, 50, 1000, 10))

    # adding another layer works the same
    hlm.add_layer(alpha=300, beta=200, rho=1000, h=10)
    assert len(hlm.layers) == 2
    l1 = hlm.layers[-1]
    assert l1.alpha == 300
    assert l1.beta == 200
    assert l1.rho == 1000
    assert l1.h == 10
Exemplo n.º 6
0
    def add_layer(self, alpha, beta, rho, h, Q=0):
        """ Add a layer on top of the HLM.

        The layers are added on top! So the model is always created from bottom to top:
        first the half-space is created (HLM object itself), then new layers are
        added on top until the model is finished.

        Args:
            alpha (float): P-wave velocity in m / s.
            beta (float): S-wave velocity in m / s.
            rho (float): Density in kg / m^3.
            h (float): Thickness in m.

        """

        layer = Layer(alpha=alpha, beta=beta, rho=rho, h=h, Q=Q)
        self._layers.append(layer)
Exemplo n.º 7
0
    def add_layer(self, *, vp=None, vs=300, rho=None, h=10, q=None):
        """ Add a layer on top of the medium. """

        self._layers.append(Layer(vp=vp, vs=vs, rho=rho, h=h, q=q))