<commit_before>"""
Cython implementation of the time stepping functions for
fatiando.seismic.wavefd
"""
import numpy

from libc.math cimport exp, sqrt
# Import Cython definitions for numpy
cimport numpy
cimport cython

DTYPE = numpy.float
ctypedef numpy.float_t double

__all__ = [
    '_apply_damping',
    '_step_elastic_sh',
    '_step_elastic_psv',
    '_xz2ps',
    '_nonreflexive_sh_boundary_conditions',
    '_nonreflexive_psv_boundary_conditions']

@cython.boundscheck(False)
@cython.wraparound(False)
def _xz2ps(
    numpy.ndarray[double, ndim=2] ux not None,
    numpy.ndarray[double, ndim=2] uz not None,
    double[:,::1] p not None,
    double[:,::1] s not None,
    unsigned int nx, unsigned int nz,
    double dx, double dz):
    """
    Convert ux and uz to P and S waves.
    """
    cdef:
        unsigned int i, j
    for i in range(1, nz - 1):
        for j in range(1, nx - 1):
            p[i,j] = (0.5*(uz[i+1,j] - uz[i-1,j])/dz
                      + 0.5*(ux[i,j+1] - ux[i,j-1])/dx)
            s[i,j] = (0.5*(ux[i+1,j] - ux[i-1,j])/dz
                      - 0.5*(uz[i,j+1] - uz[i,j-1])/dx)
    for i in range(nz):
        p[i,nx-1] = p[i,nx-2]
        p[i,0] = p[i,1]
        s[i,nx-1] = s[i,nx-2]
        s[i,0] = s[i,1]
    for j in range(nx):
        p[nz-1,j] = p[nz-2,j]
        p[0,j] = p[1,j]
        s[nz-1,j] = s[nz-2,j]<commit_msg>Calculating P and S from ux uz using 4th order centered diffs<commit_after>"""
Cython implementation of the time stepping functions for
fatiando.seismic.wavefd
"""
import numpy

from libc.math cimport exp, sqrt
# Import Cython definitions for numpy
cimport numpy
cimport cython

DTYPE = numpy.float
ctypedef numpy.float_t double

__all__ = [
    '_apply_damping',
    '_step_elastic_sh',
    '_step_elastic_psv',
    '_xz2ps',
    '_nonreflexive_sh_boundary_conditions',
    '_nonreflexive_psv_boundary_conditions']

@cython.boundscheck(False)
@cython.wraparound(False)
def _xz2ps(
    numpy.ndarray[double, ndim=2] ux not None,
    numpy.ndarray[double, ndim=2] uz not None,
    double[:,::1] p not None,
    double[:,::1] s not None,
    unsigned int nx, unsigned int nz,
    double dx, double dz):
    """
    Convert ux and uz to P and S waves.
    """
    cdef:
        unsigned int i, j
        double tmpx, tmpz
    tmpx = dx*12.
    tmpz = dz*12.
    for i in range(2, nz - 2):
        for j in range(2, nx - 2):
            p[i,j] = (
                (-uz[i+2,j] + 8*uz[i+1,j] - 8*uz[i-1,j] + uz[i-2,j])/tmpz
                + (-ux[i,j+2] + 8*ux[i,j+1] - 8*ux[i,j-1] + ux[i,j-2])/tmpx)
            s[i,j] = (
                (-ux[i+2,j] + 8*ux[i+1,j] - 8*ux[i-1,j] + ux[i-2,j])/tmpz
                - (-uz[i,j+2] + 8*uz[i,j+1] - 8*uz[i,j-1] + uz[i,j-2])/tmpx)
    # Fill in the borders with the same values
    for i in range(nz):
        p[i,nx-2] = p[i,nx-3]
        p[i,nx-1] = p[i,nx-2]
        p[i,1] = p[i,2]
        p[i,0] = p[i,1]
        s[i,nx-2] = s[i,nx-3]
        s[i,nx-1] = s[i,nx-2]
        s[i,1] = s[i,2]
        s[i,0] = s[i,1]
    for j in range(nx):
        p[nz-2,j] = p[nz-3,j]
        p[nz-1,j] = p[nz-2,j]
        p[1,j] = p[2,j]
        p[0,j] = p[1,j]
        s[nz-2,j] = s[nz-3,j]
        s[nz-1,j] = s[nz-2,j]
        s[1,j] = s[2,j]
{'fraction_non_alphanumeric': 0.17721518987341772, 'fraction_numerical': 0.0336523618400741, 'mean_word_length': 2.220675944333996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6787304', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1439, 'n_words': 305}