#include "iwop.hh" //#define VERBOSE namespace TSOpt { IWaveSpace::IWaveSpace(PARARRAY const & par, IWaveInfo const & ic, bool input, int lflag, ostream & outfile): _s(0), _keys(0) { try { if (!((lflag==ACTIVE_LINEAR) || (lflag==ACTIVE_NONLINEAR))) { RVLException e; e<<"ERROR: IWaveSpace constructor\n"; e<<" linear/nonlinear flag (lflag) has legit values of\n"; e<<" ACTIVE_NONLINEAR = 1, or ACTIVE_LINEAR = 2\n"; e<<" value of argument is "< * sp = NULL; if (parse(par,key,hdr)) { // extract suffix - this is the obvious "case" // implementation, but unsatisfactory in that adding a new // space type requires hacking the code. Something more // like a policy would be better, but not obvious how to // carry that off size_t pos = hdr.find_last_of("."); if (pos==std::string::npos || pos >= hdr.size()-1) { RVLException e; e<<"Error: IWaveSpace constructor - filename "<::export_clone(tmp); } catch (RVLException & e) { e<<"\ncalled from IWaveSpace constructor\n"; throw e; } #else try { GridSpace tmp(hdr,key,true,outfile); sp = RVL::Space::export_clone(tmp); } catch (RVLException & e) { e<<"\ncalled from IWaveSpace constructor\n"; throw e; } #endif } else if (suffix == "su") { #ifdef IWAVE_USE_MPI try { MPISEGYSpace tmp(hdr,key,retrieveGlobalComm(),outfile); sp = RVL::Space::export_clone(tmp); } catch (RVLException & e) { e<<"\ncalled from IWaveSpace constructor\n"; throw e; } #else try { SEGYSpace tmp(hdr,key,outfile); sp = RVL::Space::export_clone(tmp); } catch (RVLException & e) { e<<"\ncalled from IWaveSpace constructor\n"; throw e; } #endif } } if (sp) { _s.push_back(sp); _keys.push_back(key); } } } if (_s.size()==0) { RVLException e; e<<"Error: IWaveSpace constructor\n"; e<<" failed to locate any filenames linked to \n"; e<<" available keys, which are:\n"; for (size_t i=0;i((sp._s)[i]))) { _s[i]=RVL::Space::export_clone(*gsp); } else if ((tsp=dynamic_cast((sp._s)[i]))) { _s[i]=RVL::Space::export_clone(*tsp); } else { RVLException e; e<<"Error: IWaveSpace copy constructor\n"; e<<" element "<((sp._s)[i]))) { _s[i]=RVL::Space::export_clone(*gsp); } else if ((tsp=dynamic_cast((sp._s)[i]))) { _s[i]=RVL::Space::export_clone(*tsp); } else { RVLException e; e<<"Error: IWaveSpace copy constructor\n"; e<<" element "< f(*(_s[i])); d->push(f); } return d; } size_t IWaveSpace::getSize() const { return _s.size(); } Space const & IWaveSpace::operator[](size_t i) const { return *(_s[i]); } std::vector IWaveSpace::getKeys() const { return _keys; } void param_set(RVL::Vector const & x, PARARRAY & pars, IWaveSpace const & sp, std::string const & suf, FILE * stream) { try { // sanity test, required because no longer class member SpaceTest(sp,x,"param_set (IWave param transfer)"); Components cx(x); if (cx.getSize() != sp.getSize()) { RVLException e; e<<"Error: IWaveOp::param_set\n"; e<<" vector, key list have different numbers of components\n"; e<<" key list:\n"; for (size_t i=0;i0) e<<" suffix = "< & x, Vector & y) const { try { SpaceTest(this->getDomain(),x,"TSOpt::IWaveOp::apply (dom)"); SpaceTest(this->getRange(),y,"TSOpt::IWaveOp::apply (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x,*locpars,dom,nix,stream); param_set(y,*locpars,rng,nix,stream); // Change 11.05.10 - print par file used in sim if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLY\n"); ps_printall(*locpars,stream); fflush(stream); } /* zero output */ // y.zero(); if (dump_steps) { fprintf(stream,"IWOP::APPLY -> STEP\n"); fflush(stream); } int deriv=0; bool fwd=true; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWOP::APPLY -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveOp::apply\n"; throw e; } } void IWaveOp::applyDeriv(const Vector & x, const Vector & dx, Vector & dy) const { try { // sanity test arguments SpaceTest(this->getDomain(),x,"TSOpt::IWaveOp::applyDeriv (dom, ref)"); SpaceTest(this->getDomain(),dx,"TSOpt::IWaveOp::applyDeriv (dom, pert)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveOp::applyDeriv (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; std::string dsuf = "_d1"; param_set(x,*locpars,dom,nix,stream); param_set(dx,*locpars,dom,dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLYDERIV\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWOP::APPLYDER -> STEP\n"); fflush(stream); } int deriv=1; bool fwd=true; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWOP::APPLYDER -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveOp::applyDeriv\n"; throw e; } } void IWaveOp::applyAdjDeriv(const Vector & x, const Vector & dy, Vector & dx) const { try{ if (dump_steps) { fprintf(stream,"IWOP::APPLYADJ -> START\n"); fflush(stream); } SpaceTest(this->getDomain(),x,"TSOpt::IWaveOp::applyAdjDeriv (dom, ref)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveOp::applyAdjDeriv (rng)"); SpaceTest(this->getDomain(),dx,"TSOpt::IWaveOp::applyAdjDeriv (dom, pert)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; std::string dsuf = "_b1"; param_set(x,*locpars,dom,nix,stream); param_set(dx,*locpars,dom,dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLYADJDERIV\n"); ps_printall(*locpars,stream); fflush(stream); } int deriv=1; bool fwd=false; int printact=valparse(*locpars,"printact",0); if (dump_steps) { fprintf(stream,"IWOP::APPLYADJDER -> BUILD IWAVESIM\n"); fflush(stream); } IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); if (dump_steps) { fprintf(stream,"IWOP::APPLYADJDER -> RUN IWAVESIM\n"); fflush(stream); } sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWOP::APPLYADJ -> BARRIER\n"); fflush(stream); } #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif if (dump_steps) { fprintf(stream,"IWOP::APPLYADJ -> EXIT\n"); fflush(stream); } } catch (RVLException & e) { e<<"\n called from TSOpt::IWaveOp::applyAdjDeriv\n"; throw e; } } void IWaveOp::applyDeriv2(const Vector & x, const Vector & dx0, const Vector & dx1, Vector & dy) const { try { // sanity test arguments SpaceTest(this->getDomain(),x,"TSOpt::IWaveOp::applyDeriv2 (dom, ref)"); SpaceTest(this->getDomain(),dx0,"TSOpt::IWaveOp::applyDeriv2 (dom, pert1)"); SpaceTest(this->getDomain(),dx1,"TSOpt::IWaveOp::applyDeriv2 (dom, pert2)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveOp::applyDeriv2 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x,*locpars,dom,nix,stream); std::string dsuf = "_d1"; param_set(dx0,*locpars,dom,dsuf,stream); dsuf = "_d2"; param_set(dx1,*locpars,dom,dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLYDERIV\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWOP::APPLYDER -> STEP\n"); fflush(stream); } int deriv=2; bool fwd=true; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWOP::APPLYDER -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveOp::applyDeriv\n"; throw e; } } void IWaveOp::applyAdjDeriv2(const Vector & x, const Vector & dx0, const Vector & dy, Vector & dx1) const { try{ if (dump_steps) { fprintf(stream,"IWOP::APPLYADJ2 -> START\n"); fflush(stream); } SpaceTest(this->getDomain(),x,"TSOpt::IWaveOp::applyAdjDeriv2 (dom, ref)"); SpaceTest(this->getDomain(),dx0,"TSOpt::IWaveOp::applyAdjDeriv2 (dom, pert1)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveOp::applyAdjDeriv2 (rng)"); SpaceTest(this->getDomain(),dx1,"TSOpt::IWaveOp::applyAdjDeriv2 (dom, pert2)"); std::string nix = ""; PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); param_set(x,*locpars,dom,nix,stream); std::string dsuf = "_d1"; param_set(dx0,*locpars,dom,dsuf,stream); dsuf = "_b2"; param_set(dx1,*locpars,dom,dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLYADJDERIV2\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWOP::APPLYADJDER2 -> STEP\n"); fflush(stream); } int deriv=2; bool fwd=false; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif if (dump_steps) { fprintf(stream,"IWOP::APPLYADJDERIV2 -> EXIT\n"); fflush(stream); } } catch (RVLException & e) { e<<"\n called from TSOpt::IWaveOp::applyAdjDeriv\n"; throw e; } } Operator * IWaveOp::clone() const { return new IWaveOp(*this); } IWaveOp::IWaveOp(PARARRAY _pars, FILE * _stream, bool _dryrun, ostream & _drystr, ostream & _announce) : dom(_pars,ic,true), rng(_pars,ic,false), stream(_stream), pars(NULL), dump_steps(0), dump_pars(0), dump_term(0), dryrun(_dryrun), drystr(_drystr), announce(_announce) { int err=0; /* copy input par array to data member */ if ((err=ps_copy(&pars,_pars))) { RVLException e; e<<"Error: IWOP constructor from ps_copy, err="< & x0, const Vector & x1, Vector & y) const { try { SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::apply0 (nonlin dom)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::apply0 (lin dom)"); SpaceTest(this->getRange(),y,"TSOpt::IWaveLOVOp::apply0 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); param_set(y,*locpars,rng,nix,stream); // Change 11.05.10 - print par file used in sim if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWLOVOP::APPLY0\n"); ps_printall(*locpars,stream); fflush(stream); } /* zero output */ y.zero(); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLY0 -> STEP\n"); fflush(stream); } int deriv=0; bool fwd=true; int printact=valparse(*locpars,"printact",printact); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLY0 -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveLOVOp::apply0\n"; throw e; } } void IWaveLOVOp::applyAdj0(const Vector & x0, const Vector & y, Vector & x1) const { try { SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::applyAdj0 (nonlin dom)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::applyAdj0 (lin dom)"); SpaceTest(this->getRange(),y,"TSOpt::IWaveLOVOp::applyAdj0 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); param_set(y,*locpars,rng,nix,stream); // Change 11.05.10 - print par file used in sim if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWLOVOP::APPLYADJ0\n"); ps_printall(*locpars,stream); fflush(stream); } /* zero output */ x1.zero(); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJ0 -> STEP\n"); fflush(stream); } int deriv=0; bool fwd=false; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJ0 -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveLOVOp::applyAdj0\n"; throw e; } } void IWaveLOVOp::applyPartialDeriv0(const Vector & x0, const Vector & x1, const Vector & dx0, Vector & dy) const { try { // sanity test arguments SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::applyPartialDeriv0 (nonlin dom, ref)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::applyPartialDeriv0 (nonlin dom, ref)"); SpaceTest(this->getNonLinDomain(),dx0,"TSOpt::IWaveLOVOp::applyPartialDeriv0 (nonlin dom, pert)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveLOVOp::applyPartialDeriv0 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; std::string dsuf = "_d1"; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); param_set(dx0,*locpars,this->getNonLinDomain(),dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWLOVOP::APPLYPARTIALDERIV0\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYPARTIALDERIV0 -> STEP\n"); fflush(stream); } int deriv=1; bool fwd=true; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYPARTIALDERIV0 -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveLOVOp::applyPartialDeriv0\n"; throw e; } } void IWaveLOVOp::applyAdjPartialDeriv0(const Vector & x0, const Vector & x1, const Vector & dy, Vector & dx0) const { try{ if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV0 -> START\n"); fflush(stream); } SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::applyAdjPartialDeriv0 (nonlin dom, ref)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::applyAdjPartialDeriv0 (lin dom, ref)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveLOVOp::applyAdjPartialDeriv0 (rng)"); SpaceTest(this->getNonLinDomain(),dx0,"TSOpt::IWaveLOVOp::applyAdjPartialDeriv0 (nonlin dom, pert)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; std::string dsuf = "_b1"; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); param_set(dx0,*locpars,this->getNonLinDomain(),dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWLOVOP::APPLYADJPARTIALDERIV0\n"); ps_printall(*locpars,stream); fflush(stream); } int deriv=1; bool fwd=false; int printact=valparse(*locpars,"printact",0); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV0 -> BUILD IWAVESIM\n"); fflush(stream); } IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV0 -> RUN IWAVESIM\n"); fflush(stream); } sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWOP::APPLYADJPARTIALDERIV0 -> BARRIER\n"); fflush(stream); } #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV0 -> EXIT\n"); fflush(stream); } } catch (RVLException & e) { e<<"\n called from TSOpt::IWaveLOVOp::applyAdjDeriv\n"; throw e; } } void IWaveLOVOp::applyPartialDeriv20(const Vector & x0, const Vector & x1, const Vector & dx00, const Vector & dx01, Vector & dy) const { try { // sanity test arguments SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, ref)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, ref)"); SpaceTest(this->getNonLinDomain(),dx00,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, pert0)"); SpaceTest(this->getNonLinDomain(),dx01,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, pert1)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); std::string dsuf = "_d1"; param_set(dx00,*locpars,this->getNonLinDomain(),dsuf,stream); dsuf = "_d2"; param_set(dx01,*locpars,this->getNonLinDomain(),dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWLOVOP::APPLYPARTIALDERIV20\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYPARTIALDERIV20 -> STEP\n"); fflush(stream); } int deriv=2; bool fwd=true; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYPARTIALDERIV20 -> EXIT\n"); fflush(stream); } // placed to force all output to be written to disk // before any is copied #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif } catch (RVLException & e) { e<<"\ncalled from TSOpt::IWaveLOVOp::applyPartialDeriv20\n"; throw e; } } void IWaveLOVOp::applyAdjPartialDeriv20(const Vector & x0, const Vector & x1, const Vector & dy, const Vector & dx01, Vector & dx00) const { try{ if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV20 -> START\n"); fflush(stream); } // sanity test arguments SpaceTest(this->getNonLinDomain(),x0,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, ref)"); SpaceTest(this->getLinDomain(),x1,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, ref)"); SpaceTest(this->getNonLinDomain(),dx00,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, pert0)"); SpaceTest(this->getNonLinDomain(),dx01,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (nonlin dom, pert1)"); SpaceTest(this->getRange(),dy,"TSOpt::IWaveLOVOp::applyPartialDeriv20 (rng)"); PARARRAY * locpars = ps_new(); ps_copy(&locpars,*pars); std::string nix = ""; param_set(x0,*locpars,this->getNonLinDomain(),nix,stream); param_set(x1,*locpars,this->getLinDomain(),nix,stream); std::string dsuf = "_b2"; param_set(dx00,*locpars,this->getNonLinDomain(),dsuf,stream); dsuf = "_d1"; param_set(dx01,*locpars,this->getNonLinDomain(),dsuf,stream); param_set(dy,*locpars,rng,nix,stream); if (dump_pars) { fprintf(stream,"PARAM ARRAY CREATED IN IWOP::APPLYADJDERIV2\n"); ps_printall(*locpars,stream); fflush(stream); } if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV20 -> STEP\n"); fflush(stream); } int deriv=2; bool fwd=false; int printact=valparse(*locpars,"printact",0); IWaveSim sim(deriv,fwd,*locpars,stream,ic,printact,dryrun,drystr,announce); sim.run(); ps_delete(&locpars); #ifdef IWAVE_USE_MPI MPI_Barrier(retrieveGlobalComm()); #endif if (dump_steps) { fprintf(stream,"IWLOVOP::APPLYADJPARTIALDERIV20 -> EXIT\n"); fflush(stream); } } catch (RVLException & e) { e<<"\n called from TSOpt::IWaveLOVOp::applyAdjPartialDeriv20\n"; throw e; } } IWaveLOVOp::IWaveLOVOp(PARARRAY _pars, FILE * _stream, bool _dryrun, ostream & _drystr, ostream & _announce) : dom(2), rng(_pars,ic,false,ACTIVE_LINEAR), stream(_stream), pars(NULL), dump_steps(0), dump_pars(0), dump_term(0), dryrun(_dryrun), drystr(_drystr), announce(_announce) { try { int err=0; /* copy input par array to data member */ if ((err=ps_copy(&pars,_pars))) { RVLException e; e<<"Error: IWLOVOP constructor from ps_copy, err="< & v, std::vector keys) { try { Components cv(v); if (cv.getSize() != keys.size()) { RVLException e; e<<"ERROR: IWaveLoad\n"; e<<" number of vector components differs from number of keys\n"; e<<" aaaaaiiiiiieeeeeeeeeeeeeee!!!!!!!!!!!!!\n"; throw e; } for (int i=0; i(pars,keys[i]); #ifdef VERBOSE cerr<<"IWAVE load: "<(iwop.getDomain()); m0 = RVL::Vector::newPtr(iwop.getDomain()); IWaveLoad(pars, *m0,iwdom.getKeys()); Components cm0(*m0); /* select parameters to invert */ for (int i=0; i(pars, iwdom.getKeys()[i] + "_est", ""); if (tmp.size()>0) { est.push_back(tmp); estidx.push_back(i); estkeys.push_back(iwdom.getKeys()[i]+"_est"); } } /* detect null inversion */ if (est.size()==0) { RVLException e; e<<"ERROR: FWI constructor - no "; e<<" inversion targets specified (_est suffix)\n"; throw e; } /* create domain, range spaces for diagonal window op */ // might as well use clone since at this point nothing much // is allocated #ifdef VERBOSE cerr<<"create domain, intermed spaces\n"; #endif { #ifdef VERBOSE cerr<<"StdProductSpaces of size "< _dom(est.size()); RVL::StdProductSpace _med(est.size()); dom = RVL::Space::clonePtr(_dom); med = RVL::Space::clonePtr(_med); } RVL::StdProductSpace & domref = dynamic_cast &>(*dom); RVL::StdProductSpace & medref = dynamic_cast &>(*med); for (int i=0; i::newPtr(*med); lb = RVL::Vector::newPtr(*med); Components cub(*ub); Components clb(*lb); for (int i=0; i(pars, iwdom.getKeys()[estidx[i]] + "_ub", ""); if (ubn.size() > 0) { RVL::AssignFilename fn(ubn); cub[i].eval(fn); } else { try { float val = valparse(pars, iwdom.getKeys()[estidx[i]] + "_max"); RVL::RVLAssignConst ac(val); cub[i].eval(ac); #ifdef IWAVE_VERBOSE cerr<<"assigned upper bound for param "<(pars, iwdom.getKeys()[estidx[i]] + "_lb", ""); if (lbn.size() > 0) { RVL::AssignFilename fn(lbn); clb[i].eval(fn); } else { try { float val = valparse(pars, iwdom.getKeys()[estidx[i]] + "_min"); RVL::RVLAssignConst ac(val); clb[i].eval(ac); #ifdef VERBOSE cerr<<"assigned lower bound for param "<::newPtr(*med); Components clm0(*lm0); RVL::RVLVectorLogisticInverse vli; for (int i=0; i const *> vv(3); vv[0]=&(cm0[estidx[i]]); vv[1]=&(clb[i]); vv[2]=&(cub[i]); clm0[i].eval(vli,vv); #ifdef VERBOSE #ifdef IWAVE_USE_MPI RVL::RVLMin svmin; RVL::RVLMax svmax; RVL::MPISerialFunctionObjectRedn vmin(svmin); RVL::MPISerialFunctionObjectRedn vmax(svmax); clm0[i].eval(vmin); clm0[i].eval(vmax); cerr<<"*** background model comp "< vmin; RVL::RVLMax vmax; clm0[i].eval(vmin); clm0[i].eval(vmax); cerr<<"*** background model comp "<(pars,"taper1",0.0f); sw[1]=valparse(pars,"taper2",0.0f); sw[2]=valparse(pars,"taper3",0.0f); { RVL::DiagOp _dwop(est.size()); dwop = RVL::Operator::clonePtr(_dwop); } RVL::DiagOp & dwopref = dynamic_cast &>(*dwop); for (int i=0; i _dlop(*lb,*ub); dlop = RVL::Operator::clonePtr(_dlop); #ifdef VERBOSE cerr<<"injection op\n"; #endif /* inject range of window op into domain of IWaveOp - alter components in range, leave other at bg values */ { RVL::InjectOp _injop(m0,estidx); injop = RVL::Operator::clonePtr(_injop); } #ifdef VERBOSE cerr<<"opcomps\n"; #endif /* build the ops */ { // subgrid logistic params to grid logistic params // to grid model params, est model comps only RVL::OpComp _transop(*dwop,*dlop); // est model comps to all model comps to data RVL::OpComp _modelop(*injop,iwop); // subgrid est logistic params to data RVL::OpComp _op(_transop,_modelop); transop = RVL::Operator::clonePtr(_transop); modelop = RVL::Operator::clonePtr(_modelop); op = RVL::Operator::clonePtr(_op); } #ifdef VERBOSE cerr<<"end constructor\n"; #endif } catch (RVLException & e) { e<<"\ncalled from IWaveFWIOp constructor\n"; throw e; } } IWaveFWIOp::IWaveFWIOp(IWaveFWIOp const & x) : iwop(x.iwop), m0(x.m0), est(x.est), estidx(x.estidx), dom(x.dom), med(x.med), ub(x.ub), lb(x.lb), lm0(x.lm0), dwop(x.dwop), dlop(x.dlop), injop(x.injop), transop(x.transop), modelop(x.modelop), op(x.op) {} void IWaveFWIOp::apply(Vector const & x, Vector & y) const { try { y.zero(); RVL::Operator::export_apply(*op,x,y); #ifdef VERBOSE cerr<<"IWaveFWIOp::apply\n"; { #ifdef IWAVE_USE_MPI RVL::RVLMin svmin; RVL::RVLMax svmax; RVL::MPISerialFunctionObjectRedn vmin(svmin); RVL::MPISerialFunctionObjectRedn vmax(svmax); x.eval(vmin); x.eval(vmax); cerr<<"*** input min="< vmin; RVL::RVLMax vmax; x.eval(vmin); x.eval(vmax); cerr<<"*** input min="< svmin; RVL::RVLMax svmax; RVL::MPISerialFunctionObjectRedn vmin(svmin); RVL::MPISerialFunctionObjectRedn vmax(svmax); y.eval(vmin); y.eval(vmax); cerr<<"*** output min="< vmin; RVL::RVLMax vmax; y.eval(vmin); y.eval(vmax); cerr<<"*** output min="< const & x, Vector const & dx, Vector & dy) const { try { RVL::Operator::export_applyDeriv(*op,x,dx,dy); } catch (RVLException e) { e<<"\ncalled from IWaveFWIOp::applyDeriv\n"; throw e; } } void IWaveFWIOp::applyAdjDeriv(Vector const & x, Vector const & dy, Vector & dx) const { try { RVL::Operator::export_applyAdjDeriv(*op,x,dy,dx); } catch (RVLException e) { e<<"\ncalled from IWaveFWIOp::applyAdjDeriv\n"; throw e; } } void IWaveFWIOp::applyDeriv2(const Vector & x, const Vector & dx1, const Vector & dx2, Vector & dy) const { try { RVL::Operator::export_applyDeriv2(*op,x,dx1,dx2,dy); } catch (RVLException e) { e<<"\ncalled from IWaveFWIOp::applyDeriv2\n"; throw e; } } void IWaveFWIOp::applyAdjDeriv2(const Vector & x, const Vector & dy, const Vector & dx2, Vector & dx1) const { try { RVL::Operator::export_applyAdjDeriv2(*op,x,dy,dx2,dx1); } catch (RVLException e) { e<<"\ncalled from IWaveFWIOp::applyAdjDeriv2\n"; throw e; } } ostream & IWaveFWIOp::write(ostream & str) const { str<<"IWaveFWIOp::write\n"; return str; } }