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 check_solver_parameter_files(self): """ Checks solver parameters """ nt = getpar('NSTEP', cast=int) dt = getpar('DT', cast=float) #f0 = getpar('f0', file='DATA/SOURCE', 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('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 get_source_positions(self): """ Read in source positions. Order coincides with self._source_names. """ positions = np.zeros((len(self._source_names), 2)) for isrc, source_name in enumerate(self._source_names): source_file = join(PATH.SPECFEM_DATA, self.source_prefix + '_' + source_name) xs = getpar('xs', source_file, cast=float) zs = getpar('zs', source_file, cast=float) positions[isrc, :] = [xs, zs] return positions
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 generate_mesh(self, model_path=None, model_name=None, model_type='gll'): """ Performs meshing and database generation """ print 'specfem3d_nz.generate mesh' assert (model_name) assert (model_type) unix.cd(self.cwd) if model_type in ['gll']: par = getpar('MODEL').strip() if par != 'gll': if self.taskid == 0: print 'WARNING: Unexpected Par_file setting:' print 'MODEL =', par assert (exists(model_path)) self.check_mesh_properties(model_path) src = glob(model_path + '/' + '*') dst = self.model_databases unix.cp(src, dst) call_solver(system.mpiexec(), 'bin/xgenerate_databases') if self.taskid == 0: self.export_model(PATH.OUTPUT + '/' + model_name) else: raise NotImplementedError
def generate_mesh(self, model_path=None, model_name=None, model_type='gll'): """ Performs meshing and database generation """ assert(model_name) assert(model_type) self.initialize_solver_directories() unix.cd(self.cwd) if model_type in ['gll']: par = getpar('MODEL').strip() if par != 'gll': if self.taskid == 0: print 'WARNING: Unexpected Par_file setting:' print 'MODEL =', par assert(exists(model_path)) self.check_mesh_properties(model_path) src = glob(model_path +'/'+ '*') dst = self.model_databases unix.cp(src, dst) call_solver(system.mpiexec(), 'bin/xmeshfem3D') call_solver(system.mpiexec(), 'bin/xgenerate_databases') if self.taskid == 0: self.export_model(PATH.OUTPUT +'/'+ model_name) else: raise NotImplementedError
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 check_stf_files(self): """ Get path of source time function files """ stf_files = [] for source_name in self.source_names_all: src = PATH.SPECFEM_DATA + '/' + self.source_prefix + '_' + source_name stf_file = getpar('name_of_source_file', src).lstrip().rstrip() if stf_file[0:2] == './': stf_file = dirname(PATH.SPECFEM_DATA) + '/' + stf_file[2:] if not exists(stf_file): stf_file = None stf_files.append(stf_file) self._stf_files = stf_files[:PAR.NTASK] self._stf_files_all = stf_files
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)
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)