// MPS_Space.cc // Author: Mario J. Bencomo // last modified: 12/07/16 #include "MPS_Space.hh" #define VERBOSE namespace TSOpt { //----------------------------------------------------------------------// void add_to_pars( PARARRAY const &pars, vector keys, vector vals){ //----------------------------------------------------------------------// try{ if( keys.size()!=vals.size() ){ RVLException e; e << "number of keys does not match number of values ...\n"; throw e; } for( int i=0; i ex_pos( string sufile, bool rcv ){ //----------------------------------------------------------------------// try{ vector pos; #ifdef IWAVE_USE_MPI if( retrieveGlobalRank()==0 ){ #endif //Reading in file FILE *fp = NULL; if(!(fp=iwave_const_fopen(sufile.c_str(),"r",NULL,stderr))){ RVLException e; e << "failed to open core file:"< s_pos, int N_basis, string ref_file, string MPS_file ){ //----------------------------------------------------------------------// try{ #ifdef IWAVE_USE_MPI if( retrieveGlobalRank()!=0 ){ RVLException e; e << "write_MPS_SEGY should only be called by rank 0!\n"; } #endif //opening MPS file FILE *fp_mps; fp_mps = iwave_const_fopen(MPS_file.c_str(),"w",NULL,stderr); if(fp_mps==NULL){ RVLException e; e << "failed to open MPS file!\n"; throw e; } //opening ref file FILE *fp_ref = iwave_const_fopen(ref_file.c_str(),"r",NULL,stderr); if(fp_ref==NULL){ RVLException e; e << "failed to open reference file!\n"; throw e; } segy tr; fgettra(fp_ref,&tr,0); //zeroing trace for( int it=0; it(pars,mks.MPS_file); ref_file = valparse(pars,mks.MPS_ref); hdr_file = valparse(pars,mks.hdr_files[0]); } catch(RVLException &e){ cerr << "Missing MPS, reference, or header filename.\n"; throw e; } //extract source positions from header file s_pos = ex_pos(hdr_file,false); #ifdef IWAVE_USE_MPI if( retrieveGlobalRank()==0 ){ #endif //generate MPS SEGY file write_MPS_SEGY( s_pos, get_MPS_basis().size(), ref_file, MPS_file ); #ifdef IWAVE_USE_MPI } MPI_Barrier(retrieveGlobalComm()); #endif //allocating core #ifdef IWAVE_USE_MPI MPISEGYSpace segy_sp(MPS_file,"MPS_file",retrieveGlobalComm(),cerr); core = RVL::Space::export_clone(segy_sp); #else SEGYSpace segy_sp(MPS_file,"MPS_file"); core = RVL::Space::export_clone(segy_sp); #endif if(core==NULL){ RVLException e; e << "failed to allocate core space\n"; throw e; } } catch(RVLException &e){ e << "ERROR from MPS_Space::gen_SEGY_core()\n"; throw e; } } //----------------------------------------------------------------------// void MPS_Space::sanity_checks() const{ //----------------------------------------------------------------------// try{ string corefn = this->get_coreFilename(); int ntr = get_ntr(corefn); int NTR = this->get_dim()*this->get_s_pos().size(); if( ntr!=NTR ){ RVLException e; e << "Number of traces in core file ("<(sp.core); core = RVL::Space::export_clone(*segy_sp); #else SEGYSpace const* segy_sp = NULL; segy_sp = dynamic_cast(sp.core); core = RVL::Space::export_clone(*segy_sp); #endif if( core==NULL ){ RVLException e; e << "failed to copy core\n"; throw e; } } catch(RVLException &e){ e << "ERROR from MPS_Space copy constructor\n"; throw e; } } //----------------------------------------------------------------------// MPS_Space::MPS_Space( MPS_KEYS _mks, PARARRAY const& pars, bool make ) : core(NULL), mks(_mks) { //----------------------------------------------------------------------// try{ //setting spatial dimension string grid_file = valparse(pars,mks.grid_file); grid g; init_default_grid(&g); read_grid(&g,grid_file.c_str(),stderr); s_dim = g.dim; //case where MPS file exists if(!make){ //allocating core string MPS_file = valparse(pars,mks.MPS_file); #ifdef IWAVE_USE_MPI MPISEGYSpace segy_sp(MPS_file,"MPS_file",retrieveGlobalComm(),cerr); core = RVL::Space::export_clone(segy_sp); #else SEGYSpace segy_sp(MPS_file,"MPS_file"); core = RVL::Space::export_clone(segy_sp); #endif if(core==NULL){ RVLException e; e << "failed to allocate core space\n"; throw e; } //setting source positions s_pos = ex_pos(MPS_file,false); if(s_pos.size()==0){ RVLException e; e << "no source positions extracted!\n"; throw e; } } //case where SEGY core is made from scratch else{ #ifdef IWAVE_USE_MPI if( retrieveGlobalRank()==0 ){ #endif cerr << "WARNING from MPS_Space constructor, \n" << "MPS file is assumed to not exist, \n" << "will make from scratch in subclass constructor!\n"; #ifdef IWAVE_USE_MPI } #endif } } catch(RVLException &e){ e << "ERROR from MPS_Space constructor\n"; throw e; } } //----------------------------------------------------------------------// MPS_Space::~MPS_Space(){ //----------------------------------------------------------------------// if(core) delete core; } /* //----------------------------------------------------------------------// DataContainer * MPS_Space::buildDataContainer() const { //----------------------------------------------------------------------// StdProductDataContainer * d = new StdProductDataContainer(); for (size_t i=0; i f(*(core)); d->push(f); } return d; } //----------------------------------------------------------------------// size_t MPS_Space::getSize() const{ //----------------------------------------------------------------------// size_t s = (core==NULL)? 0:1; return s; } //----------------------------------------------------------------------// Space const & MPS_Space::operator[](size_t i) const{ //----------------------------------------------------------------------// try{ if( i!=0 ){ RVLException e; e << "index i="<< i <<" must be equal to zero\n"; throw e; } return *(core); } catch(RVLException &e){ e << "ERROR from MPS_Space::operator[]\n"; throw e; } } */ //----------------------------------------------------------------------// DataContainerFactory const & MPS_Space::getDCF() const{ //----------------------------------------------------------------------// StdSpace const* stdsp = dynamic_cast const*>(core); return stdsp->getDCF(); } //----------------------------------------------------------------------// LinearAlgebraPackage const & MPS_Space::getLAP() const{ //----------------------------------------------------------------------// StdSpace const* stdsp = dynamic_cast const*>(core); return stdsp->getLAP(); } //----------------------------------------------------------------------// string MPS_Space::get_coreFilename() const{ //----------------------------------------------------------------------// try{ #ifdef IWAVE_USE_MPI MPISEGYSpace const* segy_sp = NULL; segy_sp = dynamic_cast(core); #else SEGYSpace const* segy_sp = NULL; segy_sp = dynamic_cast(core); #endif return segy_sp->getPrototypeFilename(); } catch(RVLException &e){ e << "ERROR from MPS_Space::get_coreFilename()\n"; throw e; } } //----------------------------------------------------------------------// Ituple MPS_Space::get_d_ord() const{ //----------------------------------------------------------------------// try{ vector MPS_b = get_MPS_basis(); Ituple d_ord; d_ord.coor[0] = 0; d_ord.coor[1] = 0; d_ord.coor[2] = 0; //looping over bases for( int i_b=0; i_bd_ord.coor[d] ) d_ord.coor[d] = MPS_b[i_b].derv[i_t].coor[d]; } } } return d_ord; } catch(RVLException &e){ e << "ERROR from MPS_Space::get_d_ord()\n"; throw e; } } //----------------------------------------------------------------------// int MPS_Space::get_MPS_ord() const{ //----------------------------------------------------------------------// try{ vector MPS_b = get_MPS_basis(); int d_ord=0; int tmp_ord; //looping over bases for( int i_b=0; i_bd_ord ) d_ord = tmp_ord; } } return d_ord; } catch(RVLException &e){ e << "ERROR from MPS_Space::get_d_ord()\n"; throw e; } } //----------------------------------------------------------------------// void MPS_Space::print_info(ostream &str) const{ //----------------------------------------------------------------------// try{ str << "\n" << "-----------------------------------------\n" << "Printing out MPS_Space info:\n" << "-----------------------------------------\n" << " type = "<< get_type() <<"\n" << " s_dim = "<< s_dim <<"\n" << " t_ord = "<< get_t_ord() <<"\n" << " MPS dim = "<< get_dim() <<"\n" << "core segy = "<< get_coreFilename() <<"\n" << " d_ord = "; for(int i=0; i>>>>>>>>> basis_"<< i <<", NT="<< get_MPS_basis()[i].NT <<"\n"; for(int j=0; j