Exemplo n.º 1
0
def P_M(model, u, v):
    """
    Vectorial temporaries for TTI.

    Parameters
    ----------
    model: Model
        Model structure
    so: Int
        Space order for discretization
    """
    # Vector for gradients
    st = tuple([None]*model.dim)
    P_I = VectorFunction(name="P_I%s" % u.name, grid=model.grid,
                         space_order=u.space_order, staggered=st)
    M_I = VectorFunction(name="M_I%s" % v.name, grid=model.grid,
                         space_order=v.space_order, staggered=st)
    return P_I, M_I
Exemplo n.º 2
0
def grads(func):
    """
    Gradient shifted by half a grid point, only to be used in combination
    with divs.
    """
    comps = [getattr(func, 'd%s' % d.name)(x0=d + d.spacing/2)
             for d in func.dimensions if d.is_Space]
    st = tuple([None]*func.grid.dim)
    return VectorFunction(name='grad_%s' % func.name, space_order=func.space_order,
                          components=comps, grid=func.grid, staggered=st)
Exemplo n.º 3
0
def test_shifted_div_of_vector(shift, ndim):
    grid = Grid(tuple([11] * ndim))
    v = VectorFunction(name="f", grid=grid, space_order=4)
    df = div(v, shift=shift).evaluate
    ref = 0

    for i, d in enumerate(grid.dimensions):
        x0 = (None if shift is None else d +
              shift[i] * d.spacing if type(shift) is tuple else d +
              shift * d.spacing)
        ref += getattr(v[i], 'd%s' % d.name)(x0=x0)

    assert df == ref.evaluate
Exemplo n.º 4
0
    def __init__(self, function, infile, offset=(0., 0., 0.),
                 toggle_normals=False):
        super().__init__(function, infile, offset=offset,
                         toggle_normals=toggle_normals)

        # Grid with M/2 nodes of padding
        self._pad = self._pad_grid()

        # Axial signed distance function (note the padded grid)
        self._axial = VectorFunction(name='axial', grid=self._pad,
                                     space_order=self._order,
                                     staggered=(None, None, None))

        self._axial_setup()
Exemplo n.º 5
0
 def axial(self):
     """Get the axial distances"""
     m_size = int(self._order/2)
     axial = VectorFunction(name='axial', grid=self._grid,
                            space_order=self._order,
                            staggered=(None, None, None))
     axial[0].data[:] = self._axial[0].data[m_size:-m_size,
                                            m_size:-m_size,
                                            m_size:-m_size]
     axial[1].data[:] = self._axial[1].data[m_size:-m_size,
                                            m_size:-m_size,
                                            m_size:-m_size]
     axial[2].data[:] = self._axial[2].data[m_size:-m_size,
                                            m_size:-m_size,
                                            m_size:-m_size]
     return axial
Exemplo n.º 6
0
def test_shifted_grad_of_vector(shift, ndim):
    grid = Grid(tuple([11] * ndim))
    f = VectorFunction(name="f", grid=grid, space_order=4)
    gf = grad(f, shift=shift).evaluate

    ref = []
    for i in range(len(grid.dimensions)):
        for j, d in enumerate(grid.dimensions):
            x0 = (None if shift is None else d +
                  shift[i][j] * d.spacing if type(shift) is tuple else d +
                  shift * d.spacing)
            ge = getattr(f[i], 'd%s' % d.name)(x0=x0)
            ref.append(ge.evaluate)

    for i, d in enumerate(gf):
        assert d == ref[i]