示例#1
0
文件: base.py 项目: wangyf/seisflows
    def check_mesh_properties(self, path=None):
        if not path:
            path = PATH.MODEL_INIT
        if not exists(path):
            raise Exception

        # count slices and grid points
        key = self.parameters[0]
        iproc = 0
        ngll = []
        while True:
            dummy = self.io.read_slice(path, key, iproc)[0]
            ngll += [len(dummy)]
            iproc += 1
            if not exists('%s/proc%06d_%s.bin' % (path, iproc, key)):
                break
        nproc = iproc

        # create coordinate pointers
        coords = Struct()
        for key in ['x', 'y', 'z']:
            coords[key] = partial(self.io.read_slice, self, path, key)

        self._mesh_properties = Struct([['nproc', nproc], ['ngll', ngll],
                                        ['path', path], ['coords', coords]])
示例#2
0
文件: base.py 项目: xyuan/seisflows
    def check_mesh_properties(self, path=None):
        """ path contains binary files such as:
            proc000000_z.bin, proc000000_x.bin, proc000000_vs.bin
            proc000000_vp.bin, proc000000_rho.bin, proc000001_z.bin,
            proc000001_x.bin, proc000001_vs.bin ...
            These will be read to get the number of processors used, the number
            of gll points and the coordinates of those points
        """
        if not path:
            path = PATH.MODEL_INIT
        if not exists(path):
            raise Exception

        # count slices (number of processors used to create the mesh) and grid
        # points
        key = self.parameters[0]
        iproc = 0
        ngll = []
        while True:
            dummy = self.io.read_slice(path, key, iproc)[0]
            ngll += [len(dummy)]
            iproc += 1
            if not exists('%s/proc%06d_%s.bin' % (path, iproc, key)):
                break
        nproc = iproc

        # create coordinate pointers
        coords = Struct()
        for key in ['x', 'y', 'z']:
            # The following define coords['x'] as the function io.read_slice
            # when called with path, 'x'. It is not executed
            coords[key] = partial(self.io.read_slice, self, path, key)

        self._mesh_properties = Struct([['nproc', nproc], ['ngll', ngll],
                                        ['path', path], ['coords', coords]])
示例#3
0
def kernel_map_alpha_beta(self, model, kernels):
    output = Struct()

    vp = model.vp
    vs = model.vs

    rho_alpha = (1. / 4.) * 310. * vp**(-3. / 4.)
    rho_beta = 0.

    output.vp = [kernels.vp + rho_alpha * kernels.rho]
    output.vs = [kernels.vs]

    return output
示例#4
0
def map(model, kernels):
    output = Struct()

    vp = model.vp
    vs = model.vs
    rho = model.rho
    kappa = rho * vp**2.
    mu = rho * vs**2.

    output.lame1 = [(1. - (2. / 3.) * (mu / kappa)) * kernels.kappa]
    output.lame2 = [kernels.mu + (2. / 3.) * (mu / kappa) * kernels.kappa]
    output.rho = [rho]

    return output
示例#5
0
def kernel_map_kappa_mu(self, model, kernels):
    output = Struct()

    vp = model.vp
    vs = model.vs
    rho = model.rho

    rho_kappa = (1. / 9.) * 310.**(8. / 9.) * (rho * vp**2.)**(-8. / 9.)
    rho_mu = (4. / 27.) * 310.**(8. / 9.) * (rho * vp**2.)**(-8. / 9.)

    output.kappa = [kernels.kappa + rho_kappa * kernels.rho]
    output.mu = [kernels.mu + rho_mu * kernels.mu]
    output.rho = [kernels.rho]

    return output
示例#6
0
def kernel_map_phi_beta(self, model, kernels):
    output = Struct()

    vp = model.vp
    vs = model.vs
    rho = model.rho

    rho_bulk_c = (1. / 4.) * 310. * (vp / rho)**0.5 * (vp**2.)**(-7. / 8.)
    rho_bulk_beta = (1. / 3.) * 310. * (vs / rho)**0.5 * (vp**2.)**(-7. / 8.)

    output.kappa = [kernels.bulk_c + rho_bulk_c * kernels.rho]
    output.mu = [kernels.bulk_beta + rho_bulk_beta * kernels.rho]
    output.rho = [kernels.rho]

    return output
示例#7
0
    def scan(self, fmtlist, origin=0, contiguous=1):
        """
        Take a list of formats:
            [[fmt, origin, offset, description], [...], ...]
        and returns a dictionary:
            {description: value, ...}
        """
        # reads binary file
        self.file.seek(origin)

        position = 0
        h = Struct()

        for item in fmtlist:
            fmt = item[0]
            length = item[1]
            offset = item[2]
            name = item[3]

            if not contiguous:
                self.file.seek(offset - position, 1)
                position = offset + mysize(fmt)

            # if length is 1:
            #   h[name] = self.read(fmt,length)[0]
            # else:
            #   h[name] = self.read(fmt,length)
            h[name] = self.read(fmt, length)[0]

        return h
示例#8
0
def rho_gardner(dummy, keys, vals):
    input = Struct(zip(keys, vals))

    vp = input.vp
    vs = input.vs

    rho = 310. * vp**0.25

    rho_water = 1050

    thresh = 1.0e-3

    rho[vs < thresh] = rho_water

    return rho
示例#9
0
def thomsen_voigt_2d(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    vp = input.vp
    vs = input.vs
    rho = input.rho
    epslion = input.epsilon
    delta = input.delta

    output.c11 = rho * vp**2. * (1. + 2. * epsilon)
    output.c12 = rho * vp**2. * (1. + 2. * epsilon) - 2. * rho * vs**2. * (
        1. + 2. * epsilon)
    output.c13 = rho * vp**2. * (1. + 2. * delta) - 2. * rho * vs**2.
    output.c33 = rho * vp**2.
    output.c55 = rho * vs**2.

    return output
示例#10
0
def lambda_mu_inverse(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    lame1 = input.lame1
    lame2 = input.lame2
    rho = input.rho

    output.vp = ((lame1 + 2. * lame2) / rho)**0.5
    output.vs = (lame2 / rho)**0.5
    output.rho = rho

    return output
示例#11
0
def lambda_mu_forward(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    vp = input.vp
    vs = input.vs
    rho = input.rho

    output.lame1 = rho * (vp**2. - 2. * vs**2.)
    output.lame2 = rho * vs**2.
    output.rho = rho

    return output
示例#12
0
def kappa_mu_inverse(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    kappa = input.kappa
    mu = input.mu
    rho = input.rho

    output.vp = ((kappa + (4. / 3.) * mu) / rho)**0.5
    output.vs = (mu / rho)**0.5
    output.rho = rho

    return output
示例#13
0
def kappa_mu_forward(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    vp = input.vp
    vs = input.vs
    rho = input.rho

    output.kappa = rho * (vp**2. - (4. / 3.) * vs**2.)
    output.mu = rho * vs**2.
    output.rho = rho

    return output
示例#14
0
def phi_beta_gardner_inverse(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    phi = input.phi
    beta = input.beta
    alpha = (phi**2. + (4. / 3.) * beta**2.)**0.5

    output.rho = 310. * alpha**0.25
    output.vp = alpha
    output.vs = beta

    return output
示例#15
0
def phi_beta_gardner_forward(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    vp = input.vp
    vs = input.vs
    rho = input.rho

    kappa = rho * (vp**2. - (4. / 3.) * vs**2.)

    output.rho = rho
    output.bulk_c = (kappa / rho)**0.5
    output.bulk_beta = vs

    return output
示例#16
0
    def check_mesh_properties(self, path=None, parameters=None):
        if not hasattr(self, '_mesh_properties'):
            if not path:
                path = PATH.MODEL_INIT

            if not parameters:
                parameters = self.parameters

            nproc = 0
            ngll = []
            while True:
                dummy = loadbin(path, nproc, 'reg1_' + parameters[0])
                ngll += [len(dummy)]
                nproc += 1
                if not exists('%s/proc%06d_reg1_%s.bin' %
                              (path, nproc, parameters[0])):
                    break

            self._mesh_properties = Struct([['nproc', nproc], ['ngll', ngll]])

        return self._mesh_properties
示例#17
0
def phi_beta_inverse(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    phi = input.bulk_c
    vs = input.bulk_beta
    rho = input.rho

    kappa = rho * phi**2.
    mu = rho * vs**2.

    output.vp = ((kappa + (4. / 3.) * mu) / rho)**0.5
    output.vs = vs
    output.rho = rho

    return output
示例#18
0
def getstruct(*args):
    return Struct(zip(sem.mread(*args)))
示例#19
0
def vp_vs_forward(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = input
    return output
示例#20
0
def vp_vs_inverse(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = input
    return output
示例#21
0
def Voigt(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = input
    return output
示例#22
0
def voigt_voigt_2d(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = input
    return output
示例#23
0
def tti_voight_2d(dummy, keys, vals):
    input = Struct(zip(keys, vals))
    output = Struct()

    vp = input.vp
    vs = input.vs
    rho = input.rho
    epsilon = input.epsilon
    delta = input.delta
    theta = input.theta

    c11 = rho * vp**2. * (1. + 2. * epsilon)
    c12 = rho * vp**2. * (1. + 2. * epsilon) - 2. * rho * vs**2. * (
        1. + 2. * epsilon)
    c13 = rho * vp**2. * (1. + 2. * delta) - 2. * rho * vs**2.
    c33 = rho * vp**2.
    c55 = rho * vs**2.

    sint = sin(PI / 180. * theta)
    cost = cos(PI / 180. * theta)
    sin2t = sin(2. * PI / 180. * theta)
    cos2t = cos(2. * PI / 180. * theta)

    output.c11 = c11 * cost**4 + c33 * sint**4 + 2 * c13 * sint**2 * cost**2 + c55 * sin2t**2
    output.c12 = 1.e-6
    output.c13 = c13 * (cost**4 + sint**4) + (
        c11 + c33) * sint**2 * cost**2 - c55 * sin2t**2
    output.c15 = ((c11 - c13) * cost**2 +
                  (c13 - c33) * sint**2) * sint * cost - c55 * sin2t * cos2t
    output.c23 = 1.e-6
    output.c25 = 0.0
    output.c33 = c11 * sint**4 + c33 * cost**4 + 2 * c13 * sint**2 * cost**2 + c55 * sin2t**2
    output.c35 = ((c11 - c13) * sint**2 +
                  (c13 - c33) * cost**2) * sint * cost + c55 * sin2t * cos2t
    output.c55 = (c11 - 2. * c13 + c33) * sint**2 * cost**2 + c55 * cos2t**2

    return output