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.taskid == 0: print("WARNING: nt != PAR.NT") setpar('nt', PAR.NT) if dt != PAR.DT: if self.taskid == 0: print("WARNING: dt != PAR.DT") setpar('deltat', PAR.DT) if f0 != PAR.F0: if self.taskid == 0: print("WARNING: f0 != PAR.F0") setpar('f0', PAR.F0, filename='DATA/SOURCE') if self.mesh_properties.nproc != PAR.NPROC: if self.taskid == 0: print('Warning: mesh_properties.nproc != PAR.NPROC') if 'MULTIPLES' in PAR: if PAR.MULTIPLES: setpar('absorbtop', '.false.') else: setpar('absorbtop', '.true.')
def generate_data(self, **model_kwargs): """ Generates data (perform meshing and database generation first) """ self.generate_mesh(**model_kwargs) unix.cd(self.cwd) setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.false.') call_solver(system.mpiexec(), 'bin/xmeshfem2D', output='mesher.log') call_solver(system.mpiexec(), 'bin/xspecfem2D', output='solver.log') if PAR.FORMAT in ['SU', 'su']: src = glob('OUTPUT_FILES/*.su') # work around SPECFEM2D's different file names (depending on the # version used : # ?? junliu # _d? unix.rename('single_d.su', 'single.su', src) src = glob('OUTPUT_FILES/*.su') dst = 'traces/obs' unix.mv(src, dst) if PAR.SAVETRACES: self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
def generate_mesh(self, model_path=None, model_name=None, model_type='gll'): """ Performs meshing and database generation """ # Assert that the model name and path are not empty assert (model_name) assert (model_type) self.initialize_solver_directories() unix.cd(self.cwd) assert (exists(model_path)) # Check that the path exist # Fill _mesh_properties which contain the number of integration points, # the number of procs used and the coordinates of the points self.check_mesh_properties(model_path) # Copy the model files (ex: proc000023_vp.bin ...) into DATA # modify by junliu # it seems that should change the model_type setpar('MODEL', model_type) print model_type src = glob(join(model_path, '*')) dst = join(self.cwd, 'DATA') unix.cp(src, dst) # Export the model into output folder if self.taskid == 0: self.export_model(PATH.OUTPUT + '/' + model_name)
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.taskid == 0: print "WARNING: nt != PAR.NT" setpar('nt', PAR.NT) if dt != PAR.DT: if self.taskid == 0: print "WARNING: dt != PAR.DT" setpar('deltat', PAR.DT) if f0 != PAR.F0: if self.taskid == 0: print "WARNING: f0 != PAR.F0" setpar('f0', PAR.F0, filename='DATA/SOURCE') if self.mesh_properties.nproc != PAR.NPROC: if self.taskid == 0: print 'Warning: mesh_properties.nproc != PAR.NPROC' if 'MULTIPLES' in PAR: if PAR.MULTIPLES: setpar('absorbtop', '.false.') else: setpar('absorbtop', '.true.')
def write_receivers(self): unix.cd(self.cwd) key = 'use_existing_STATIONS' val = '.true.' setpar(key, val) _, h = preprocess.load('traces/obs') solvertools.write_receivers(h.nr, h.rx, h.rz)
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')
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)
def forward(self, path='traces/syn'): """ Calls SPECFEM2D forward solver """ setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') call_solver(system.mpiexec(), 'bin/xmeshfem2D') call_solver(system.mpiexec(), 'bin/xspecfem2D') if PAR.FORMAT in ['SU', 'su']: filenames = glob('OUTPUT_FILES/*.su') unix.mv(filenames, path)
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 different SPECFEM2D 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) call_solver(system.mpiexec(), 'bin/xspecfem2D')
def check_solver_parameter_files(self): """ Checks solver parameters """ found = False for ntStr in ['NSTEP', 'nt']: # Different specfem conventions try: nt = getpar(ntStr, cast=int, noOutput=True) found = True except Exception: pass if not found: raise Exception('Not found in Specfem Par_file: NSTEP or nt') found = False for dtStr in ['DT', 'deltat']: # Different specfem conventions try: dt = getpar(dtStr, cast=float, noOutput=True) found = True except Exception: pass if not found: raise Exception('Not found in Specfem Par_file: DT or deltat') f0 = getpar('f0', file='DATA/SOURCE', cast=float) if nt != PAR.NT: if self.taskid == 0: print "WARNING: nt != PAR.NT", nt, PAR.NT setpar('nt', PAR.NT) if dt != PAR.DT: if self.taskid == 0: print "WARNING: dt != PAR.DT", dt, PAR.DT setpar('deltat', PAR.DT) if f0 != PAR.F0: if self.taskid == 0: print "WARNING: f0 != PAR.F0" setpar('f0', PAR.F0, filename='DATA/SOURCE') if self.mesh_properties.nproc != PAR.NPROC: if self.taskid == 0: print 'Warning: mesh_properties.nproc != PAR.NPROC' if 'MULTIPLES' in PAR: if PAR.MULTIPLES: setpar('absorbtop', '.false.') else: setpar('absorbtop', '.true.')
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 different SPECFEM2D 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) call_solver(system.mpiexec(), 'bin/xmeshfem2D') call_solver(system.mpiexec(), 'bin/xspecfem2D')
def forward(self, path='traces/syn'): """ Calls SPECFEM2D forward solver """ setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') call_solver(system.mpiexec(), 'bin/xmeshfem2D') call_solver(system.mpiexec(), 'bin/xspecfem2D') if PAR.FORMAT in ['SU', 'su']: filenames = glob('OUTPUT_FILES/*.su') # work around SPECFEM2D's different file names (depending on the # version used : unix.rename('single_p.su', 'single.su', filenames) filenames = glob('OUTPUT_FILES/*.su') unix.mv(filenames, path)
def generate_data(self, **model_kwargs): """ Generates data """ self.generate_mesh(**model_kwargs) unix.cd(self.cwd) setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') call_solver(system.mpiexec(), 'bin/xspecfem3D') if PAR.FORMAT in ['ASCII', 'ascii']: src = glob('OUTPUT_FILES/*.sem.ascii') dst = 'traces/obs' unix.mv(src, dst) if PAR.SAVETRACES: self.export_traces(PATH.OUTPUT+'/'+'traces/obs')
def generate_data(self, **model_kwargs): """ Generates data """ self.generate_mesh(**model_kwargs) unix.cd(self.cwd) setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') call_solver(system.mpiexec(), 'bin/xspecfem3D') if PAR.FORMAT in ['ASCII', 'ascii']: src = glob('OUTPUT_FILES/*.sem.ascii') dst = 'traces/obs' unix.mv(src, dst) if PAR.SAVETRACES: self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
def generate_data(self, **model_kwargs): """ Generates data """ self.generate_mesh(**model_kwargs) unix.cd(self.cwd) setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.false.') call_solver(system.mpiexec(), 'bin/xmeshfem2D', output='mesher.log') call_solver(system.mpiexec(), 'bin/xspecfem2D') if PAR.FORMAT in ['SU', 'su']: src = glob('OUTPUT_FILES/*.su') dst = 'traces/obs' unix.mv(src, dst) if PAR.SAVETRACES: self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
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.taskid == 0: print "WARNING: nt != PAR.NT" setpar('NSTEP', PAR.NT) if dt != PAR.DT: if self.taskid == 0: print "WARNING: dt != PAR.DT" setpar('DT', PAR.DT) if self.mesh_properties.nproc != PAR.NPROC: if self.taskid == 0: print 'Warning: mesh_properties.nproc != PAR.NPROC' if 'MULTIPLES' in PAR: raise NotImplementedError
def generate_data(self, **model_kwargs): """ Generates data in the synthetic-synthetic comparison case. Not for use in the real-data problem. Differs from specfem3d.nz in that it automatically calls generate mesh for the true model, rather than passing them in as kwargs. """ # Prepare for the forward simulation self.generate_mesh(**model_kwargs) print 'specfem3d_nz.generate data' unix.cd(self.cwd) setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') setpar('ATTENUATION ', '.true.') call_solver(system.mpiexec(), 'bin/xspecfem3D') # seismic unix format if PAR.FORMAT in ['SU', 'su']: src = glob('OUTPUT_FILES/*_d?_SU') dst = 'traces/obs' unix.mv(src, dst) # ascii sem output format elif PAR.FORMAT == "ascii": src = glob('OUTPUT_FILES/*sem?') dst = 'traces/obs' unix.mv(src, dst) if PAR.SAVETRACES: self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
def write_sources(PAR, h, path='.'): """ Writes source information to text file """ file = findpath('sesiflows.plugins') + '/' + 'specfem3d/FORCESOLUTION' with open(file, 'r') as f: lines = f.readlines() file = 'DATA/FORCESOURCE' with open(file, 'w') as f: f.writelines(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)
def forward(self, path='traces/syn'): """ Calls SPECFEM3D forward solver and then moves files into path """ setpar('SIMULATION_TYPE', '1') setpar('SAVE_FORWARD', '.true.') setpar('ATTENUATION ', '.true.') call_solver(system.mpiexec(), 'bin/xgenerate_databases') call_solver(system.mpiexec(), 'bin/xspecfem3D') # seismic unix output format if PAR.FORMAT in ['SU', 'su']: src = glob('OUTPUT_FILES/*_d?_SU') dst = path unix.mv(src, dst) # ascii sem output format elif PAR.FORMAT == "ascii": src = glob('OUTPUT_FILES/*sem?') dst = path unix.mv(src, dst)
def write_sources(coords, path='.', ws=1., suffix=''): """ Writes source information to text file """ sx, sy, sz = coords filename = findpath('seisflows.plugins') + '/' + 'solver/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)
def write_sources(coords, path='.', ws=1., suffix=''): """ Writes source information to text file TODO this has to be adapted for new versions of specfem because the source file format has changed """ sx, sy, sz = coords filename = findpath('seisflows.plugins') + '/' + 'solver/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)