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
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
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
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
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]])
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
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
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
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
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
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
def voigt_voigt_2d(dummy, keys, vals): input = Struct(zip(keys, vals)) output = input return output
def vp_vs_inverse(dummy, keys, vals): input = Struct(zip(keys, vals)) output = input return output
def vp_vs_forward(dummy, keys, vals): input = Struct(zip(keys, vals)) output = input return output
def getstruct(*args): return Struct(zip(sem.mread(*args)))
def Voigt(dummy, keys, vals): input = Struct(zip(keys, vals)) output = input return output