Ejemplo n.º 1
0
    def check_solver_parameter_files(self):
        """ Checks solver parameters
        """
        nt = getpar('nt', cast=int)
        dt = getpar('deltat', cast=float)
        f0 = getpar('f0', file='DATA/SOURCE', cast=float)

        if nt != PAR.NT:
            if self.getnode == 0: print "WARNING: nt != PAR.NT"
            setpar('nt', PAR.NT)

        if dt != PAR.DT:
            if self.getnode == 0: print "WARNING: dt != PAR.DT"
            setpar('deltat', PAR.DT)

        if f0 != PAR.F0:
            if self.getnode == 0: print "WARNING: f0 != PAR.F0"
            setpar('f0', PAR.F0, file='DATA/SOURCE')

        if self.mesh_properties.nproc != PAR.NPROC:
            if self.getnode == 0:
                print 'Warning: mesh_properties.nproc != PAR.NPROC'

        if 'MULTIPLES' in PAR:
            if PAR.MULTIPLES:
                setpar('absorbtop', '.false.')
            else:
                setpar('absorbtop', '.true.')
Ejemplo n.º 2
0
 def forward(self):
     """ Calls SPECFEM2D forward solver
     """
     setpar('SIMULATION_TYPE', '1')
     setpar('SAVE_FORWARD', '.true.')
     self.mpirun('bin/xmeshfem2D')
     self.mpirun('bin/xspecfem2D')
Ejemplo n.º 3
0
 def write_receivers(self):
     unix.cd(self.getpath)
     key = 'use_existing_STATIONS'
     val = '.true.'
     setpar(key, val)
     _, h = preprocess.load('traces/obs')
     solvertools.write_receivers(h.nr, h.rx, h.rz)
Ejemplo n.º 4
0
 def forward(self):
     """ Calls SPECFEM3D forward solver
     """
     setpar('SIMULATION_TYPE', '1')
     setpar('SAVE_FORWARD', '.true.')
     self.call('bin/xgenerate_databases')
     self.call('bin/xspecfem3D')
Ejemplo n.º 5
0
    def check_solver_parameter_files(self):
        """ Checks solver parameters
        """
        nt = getpar('nt', cast=int)
        dt = getpar('deltat', cast=float)
        f0 = getpar('f0', file='DATA/SOURCE', cast=float)

        if nt != PAR.NT:
            if system.getnode() == 0: print "WARNING: nt != PAR.NT"
            setpar('nt', PAR.NT)

        if dt != PAR.DT:
            if system.getnode() == 0: print "WARNING: dt != PAR.DT"
            setpar('deltat', PAR.DT)
        
        if f0 != PAR.F0:
            if system.getnode() == 0: print "WARNING: f0 != PAR.F0"
            setpar('f0', PAR.F0, file='DATA/SOURCE')

        if self.mesh.nproc != PAR.NPROC:
            if system.getnode() == 0:
                print 'WARNING: mesh.nproc != PAR.NPROC'


        if 'MULTIPLES' in PAR:
            if PAR.MULTIPLES:
                setpar('absorbtop', '.false.')
            else:
                setpar('absorbtop', '.true.')
Ejemplo n.º 6
0
 def forward(self):
     """ Calls SPECFEM2D forward solver
     """
     setpar('SIMULATION_TYPE', '1')
     setpar('SAVE_FORWARD', '.true.')
     self.mpirun('bin/xmeshfem2D')
     self.mpirun('bin/xspecfem2D')
Ejemplo n.º 7
0
 def forward(self):
     """ Calls SPECFEM3D forward solver
     """
     setpar('SIMULATION_TYPE', '1')
     setpar('SAVE_FORWARD', '.true.')
     self.mpirun('bin/xgenerate_databases')
     self.mpirun('bin/xspecfem3D')
Ejemplo n.º 8
0
 def write_receivers(self):
     unix.cd(self.getpath)
     key = 'use_existing_STATIONS'
     val = '.true.'
     setpar(key, val)
     _, h = preprocess.load('traces/obs')
     solvertools.write_receivers(h.nr, h.rx, h.rz)
Ejemplo n.º 9
0
 def adjoint(self):
     """ Calls SPECFEM3D adjoint solver
     """
     setpar('SIMULATION_TYPE', '3')
     setpar('SAVE_FORWARD', '.false.')
     unix.rm('SEM')
     unix.ln('traces/adj', 'SEM')
     self.call('bin/xspecfem3D')
Ejemplo n.º 10
0
 def adjoint(self):
     """ Calls SPECFEM3D adjoint solver
     """
     setpar('SIMULATION_TYPE', '3')
     setpar('SAVE_FORWARD', '.false.')
     unix.rm('SEM')
     unix.ln('traces/adj', 'SEM')
     self.mpirun('bin/xspecfem3D')
Ejemplo n.º 11
0
    def adjoint(self):
        """ Calls SPECFEM3D adjoint solver
        """
        setpar('SIMULATION_TYPE', '3')
        setpar('SAVE_FORWARD', '.false.')
        unix.rm('SEM')
        unix.ln('traces/adj', 'SEM')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        # work around SPECFEM3D conflicting name conventions
        self.rename_data()
Ejemplo n.º 12
0
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.getpath)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        self.call('bin/xspecfem3D')

        unix.mv(self.data_wildcard, 'traces/obs')
        self.export_traces(PATH.OUTPUT, 'traces/obs')
Ejemplo n.º 13
0
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.getpath)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        self.mpirun('bin/xspecfem3D')

        unix.mv(self.data_wildcard, 'traces/obs')
        self.export_traces(PATH.OUTPUT, 'traces/obs')
Ejemplo n.º 14
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xgenerate_databases')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = path
            unix.mv(src, dst)
Ejemplo n.º 15
0
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.getpath)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = 'traces/obs'
            unix.mv(src, dst)
Ejemplo n.º 16
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM2D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')

        if PAR.WITH_MPI:
            call_solver(system.mpiexec(), 'bin/xmeshfem2D')
            call_solver(system.mpiexec(), 'bin/xspecfem2D')
        else:
            call_solver_nompi('bin/xmeshfem2D')
            call_solver_nompi('bin/xspecfem2D')

        if PAR.FORMAT in ['SU', 'su']:
            filenames = glob('OUTPUT_FILES/*.su')
            unix.mv(filenames, path)
Ejemplo n.º 17
0
    def check_solver_parameter_files(self):
        """ Checks solver parameters
        """
        nt = getpar('NSTEP', cast=int)
        dt = getpar('DT', cast=float)

        if nt != PAR.NT:
            if self.getnode == 0: print "WARNING: nt != PAR.NT"
            setpar('NSTEP', PAR.NT)

        if dt != PAR.DT:
            if self.getnode == 0: print "WARNING: dt != PAR.DT"
            setpar('DT', PAR.DT)

        if self.mesh.nproc != PAR.NPROC:
            if self.getnode == 0:
                print 'Warning: mesh.nproc != PAR.NPROC'

        if 'MULTIPLES' in PAR:
            raise NotImplementedError
Ejemplo n.º 18
0
    def adjoint(self):
        """ Calls SPECFEM2D adjoint solver
        """
        setpar('SIMULATION_TYPE', '3')
        setpar('SAVE_FORWARD', '.false.')
        unix.rm('SEM')
        unix.ln('traces/adj', 'SEM')

        # hack to deal with SPECFEM2D's use of different name conventions for
        # regular traces and 'adjoint' traces
        if PAR.FORMAT in ['SU', 'su']:
            files = glob('traces/adj/*.su')
            unix.rename('.su', '.su.adj', files)

        if PAR.WITH_MPI:
            call_solver(system.mpiexec(), 'bin/xmeshfem2D')
            call_solver(system.mpiexec(), 'bin/xspecfem2D')
        else:
            call_solver_nompi('bin/xmeshfem2D')
            call_solver_nompi('bin/xspecfem2D')
Ejemplo n.º 19
0
    def check_solver_parameter_files(self):
        """ Checks solver parameters
        """
        nt = getpar('NSTEP', cast=int)
        dt = getpar('DT', cast=float)

        if nt != PAR.NT:
            if self.getnode == 0: print "WARNING: nt != PAR.NT"
            setpar('NSTEP', PAR.NT)

        if dt != PAR.DT:
            if self.getnode == 0: print "WARNING: dt != PAR.DT"
            setpar('DT', PAR.DT)

        if self.mesh_properties.nproc != PAR.NPROC:
            if self.getnode == 0:
                print 'Warning: mesh_properties.nproc != PAR.NPROC'

        if 'MULTIPLES' in PAR:
            raise NotImplementedError
Ejemplo n.º 20
0
def write_sources(PAR, h, path='.'):
    """ Writes source information to text file
    """
    file = findpath('seistools') + '/' + 'specfem3d/FORCESOLUTION'
    with open(file, 'r') as f:
        lines = f.readlines()

    file = 'DATA/FORCESOURCE'
    _writelines(file, lines)

    # adjust coordinates
    setpar('xs', h.sx[0], file)
    setpar('zs', h.sz[0], file)
    setpar('ts', h.ts, file)

    # adjust wavelet
    setpar('f0', PAR['F0'], file)
Ejemplo n.º 21
0
def write_sources(PAR, h, path='.'):
    """ Writes source information to text file
    """
    file = findpath('sesiflows.seistools') + '/' + 'specfem3d/FORCESOLUTION'
    with open(file, 'r') as f:
        lines = f.readlines()

    file = 'DATA/FORCESOURCE'
    _writelines(file, lines)

    # adjust coordinates
    setpar('xs', h.sx[0], file)
    setpar('zs', h.sz[0], file)
    setpar('ts', h.ts, file)

    # adjust wavelet
    setpar('f0', PAR['F0'], file)
Ejemplo n.º 22
0
def write_sources(par, hdr, path='.', suffix=''):
    """ Writes source information to text file
    """
    file = findpath('sesiflows.seistools') + '/' + 'specfem2d/SOURCE'
    with open(file, 'r') as f:
        lines = f.readlines()

    file = path + '/' + 'DATA/SOURCE' + suffix
    _writelines(file, lines)

    # adjust source coordinates
    setpar('xs', hdr.sx[0], file)
    setpar('zs', hdr.sy[0], file)
    setpar('ts', hdr.ts, file)

    # adjust source amplitude
    try:
        fs = float(getpar('factor', file))
        setpar('factor', str(fs*hdr.fs), file)
    except:
        pass

    # adjust source wavelet
    if 1:
        # Ricker wavelet
        setpar('time_function_type', 1, file)
    elif 0:
        # first derivative of Gaussian
        setpar('time_function_type', 2, file)
    elif 0:
        # Gaussian
        setpar('time_function_type', 3, file)
    elif 0:
        # Dirac
        setpar('time_function_type', 4, file)
    elif 0:
        # Heaviside
        setpar('time_function_type', 5, file)

    setpar('f0', par['F0'], file)
Ejemplo n.º 23
0
def write_sources(par, hdr, path='.', suffix=''):
    """ Writes source information to text file
    """
    file = findpath('seistools') + '/' + 'specfem2d/SOURCE'
    with open(file, 'r') as f:
        lines = f.readlines()

    file = path + '/' + 'DATA/SOURCE' + suffix
    _writelines(file, lines)

    # adjust source coordinates
    setpar('xs', hdr.sx[0], file)
    setpar('zs', hdr.sy[0], file)
    setpar('ts', hdr.ts, file)

    # adjust source amplitude
    try:
        fs = float(getpar('factor', file))
        setpar('factor', str(fs * hdr.fs), file)
    except:
        pass

    # adjust source wavelet
    if 1:
        # Ricker wavelet
        setpar('time_function_type', 1, file)
    elif 0:
        # first derivative of Gaussian
        setpar('time_function_type', 2, file)
    elif 0:
        # Gaussian
        setpar('time_function_type', 3, file)
    elif 0:
        # Dirac
        setpar('time_function_type', 4, file)
    elif 0:
        # Heaviside
        setpar('time_function_type', 5, file)

    setpar('f0', par['F0'], file)
Ejemplo n.º 24
0
def write_parameters(par, version='git-devel'):
    """ Writes parameters to text file
    """
    # read template
    file = findpath('seistools') + '/' + 'specfem2d/par-' + version
    with open(file, 'r') as f:
        lines = f.readlines()
    lines[-1] = ' '.join(['1', str(par.NX), '1', str(par.NZ), '1'])

    # write parameter file
    file = 'DATA/Par_file'
    _writelines(file, lines)
    setpar('xmin', str(par.XMIN))
    setpar('xmax', str(par.XMAX))
    setpar('nx', str(par.NX))
    setpar('nt', str(par.NT))
    setpar('deltat', str(par.DT))
    setpar('nsources', str(1))

    # write interfaces file
    file = 'DATA/interfaces.dat'
    lines = []
    lines.extend('2\n')
    lines.extend('2\n')
    lines.extend('%f %f\n' % (par.XMIN, par.ZMIN))
    lines.extend('%f %f\n' % (par.XMAX, par.ZMIN))
    lines.extend('2\n')
    lines.extend('%f %f\n' % (par.XMIN, par.ZMAX))
    lines.extend('%f %f\n' % (par.XMAX, par.ZMAX))
    lines.extend(str(par.NZ))
    _writelines(file, lines)
Ejemplo n.º 25
0
def write_sources(coords, path='.', ws=1., suffix=''):
    """ Writes source information to text file
    """
    sx, sy, sz = coords

    filename = findpath('seisflows.seistools') + '/' + 'specfem2d/SOURCE'
    with open(filename, 'r') as f:
        lines = f.readlines()

    filename = 'DATA/SOURCE' + suffix
    with open(filename, 'w') as f:
        f.writelines(lines)

    # adjust source coordinates
    setpar('xs', sx, filename)
    setpar('zs', sy, filename)
    #setpar('ts', ts[0], filename)

    # adjust source amplitude
    try:
        fs = float(getpar('factor', filename))
        fs *= ws
        setpar('factor', str(fs), filename)
    except:
        pass

    # adjust source wavelet
    if 1:
        # Ricker wavelet
        setpar('time_function_type', 1, filename)
    elif 0:
        # first derivative of Gaussian
        setpar('time_function_type', 2, filename)
    elif 0:
        # Gaussian
        setpar('time_function_type', 3, filename)
    elif 0:
        # Dirac
        setpar('time_function_type', 4, filename)
    elif 0:
        # Heaviside
        setpar('time_function_type', 5, filename)
Ejemplo n.º 26
0
def write_parameters(par, version="git-devel"):
    """ Writes parameters to text file
    """
    # read template
    file = findpath("seistools") + "/" + "specfem2d/par-" + version
    with open(file, "r") as f:
        lines = f.readlines()
    lines[-1] = " ".join(["1", str(par.NX), "1", str(par.NZ), "1"])

    # write parameter file
    file = "DATA/Par_file"
    _writelines(file, lines)
    setpar("xmin", str(par.XMIN))
    setpar("xmax", str(par.XMAX))
    setpar("nx", str(par.NX))
    setpar("nt", str(par.NT))
    setpar("deltat", str(par.DT))
    setpar("nsources", str(1))

    # write interfaces file
    file = "DATA/interfaces.dat"
    lines = []
    lines.extend("2\n")
    lines.extend("2\n")
    lines.extend("%f %f\n" % (par.XMIN, par.ZMIN))
    lines.extend("%f %f\n" % (par.XMAX, par.ZMIN))
    lines.extend("2\n")
    lines.extend("%f %f\n" % (par.XMIN, par.ZMAX))
    lines.extend("%f %f\n" % (par.XMAX, par.ZMAX))
    lines.extend(str(par.NZ))
    _writelines(file, lines)
Ejemplo n.º 27
0
def write_sources(par, hdr, path=".", suffix=""):
    """ Writes source information to text file
    """
    file = findpath("seistools") + "/" + "specfem2d/SOURCE"
    with open(file, "r") as f:
        lines = f.readlines()

    file = path + "/" + "DATA/SOURCE" + suffix
    _writelines(file, lines)

    # adjust source coordinates
    setpar("xs", hdr.sx[0], file)
    setpar("zs", hdr.sy[0], file)
    setpar("ts", hdr.ts, file)

    # adjust source amplitude
    try:
        fs = float(getpar("factor", file))
        setpar("factor", str(fs * hdr.fs), file)
    except:
        pass

    # adjust source wavelet
    if 1:
        # Ricker wavelet
        setpar("time_function_type", 1, file)
    elif 0:
        # first derivative of Gaussian
        setpar("time_function_type", 2, file)
    elif 0:
        # Gaussian
        setpar("time_function_type", 3, file)
    elif 0:
        # Dirac
        setpar("time_function_type", 4, file)
    elif 0:
        # Heaviside
        setpar("time_function_type", 5, file)

    setpar("f0", par["F0"], file)
Ejemplo n.º 28
0
def write_parameters(par, version='git-devel'):
    """ Writes parameters to text file
    """
    # read template
    file = findpath('sesiflows.seistools') + '/' + 'specfem2d/par-' + version
    with open(file, 'r') as f:
        lines = f.readlines()
    lines[-1] = ' '.join(['1', str(par.NX), '1', str(par.NZ), '1'])

    # write parameter file
    file = 'DATA/Par_file'
    _writelines(file, lines)
    setpar('xmin', str(par.XMIN))
    setpar('xmax', str(par.XMAX))
    setpar('nx', str(par.NX))
    setpar('nt', str(par.NT))
    setpar('deltat', str(par.DT))
    setpar('nsources', str(1))

    # write interfaces file
    file = 'DATA/interfaces.dat'
    lines = []
    lines.extend('2\n')
    lines.extend('2\n')
    lines.extend('%f %f\n'%(par.XMIN, par.ZMIN))
    lines.extend('%f %f\n'%(par.XMAX, par.ZMIN))
    lines.extend('2\n')
    lines.extend('%f %f\n'%(par.XMIN, par.ZMAX))
    lines.extend('%f %f\n'%(par.XMAX, par.ZMAX))
    lines.extend(str(par.NZ))
    _writelines(file, lines)