iwop.hh

Go to the documentation of this file.
00001 #ifndef __IWAVE_OP
00002 #define __IWAVE_OP
00003 
00004 #define DEFAULT_SNAPS 10
00005 
00006 //#include "alg.hh"
00007 #include "op.hh"
00008 #include "productspace.hh"
00009 #include "blockop.hh"
00010 #include "ocdc.hh"
00011 #include "gridpp.hh"
00012 #include "segypp.hh"
00013 #ifdef IWAVE_USE_MPI
00014 #include "mpigridpp.hh"
00015 #include "mpisegypp.hh"
00016 #endif
00017 #include "gridops.hh"
00018 #include "logistic.hh"
00019 #include "iwsim.hh"
00020 
00021 namespace TSOpt {
00022 
00023   //using namespace RVLAlg;
00024   using RVLAlg::ListAlg;
00025   using RVL::DataContainer;
00026   using RVL::ProductDataContainer;
00027   using RVL::StdProductDataContainer;
00028   using RVL::Space;
00029   using RVL::SpaceDCF;
00030   using RVL::ProductSpace;
00031   using RVL::StdProductSpace;
00032   using RVL::ConstContainer;
00033   using RVL::STRING_PAIR;
00034   using RVL::Vector;
00035   using RVL::Components;
00036   using RVL::FunctionObject;
00037   using RVL::Operator;
00038   using RVL::LinOpValOp;
00039   using RVL::Writeable;
00040   using RVL::AssignParams;
00041   
00042   class IWaveSpace: public ProductSpace<float> {
00043 
00044   private:
00045 
00047     std::vector< Space<float> const * > _s;
00048     std::vector< std::string > _keys;
00049 
00050   protected:
00051 
00052     Space<float> * clone() const {
00053       return new IWaveSpace(*this);
00054     }
00055     
00056   public:
00057 
00058     IWaveSpace(PARARRAY const & par, 
00059            IWaveInfo const & ic,
00060            bool input,
00061            int lflag = 1,
00062            ostream & outfile = cerr);
00063 
00064     IWaveSpace(IWaveSpace const & sp);
00065     
00066     ~IWaveSpace();
00067 
00070     DataContainer * buildDataContainer() const;
00071 
00072     size_t getSize() const;
00073     Space<float> const & operator[](size_t i) const;
00074     std::vector<std::string> getKeys() const;
00075   };
00076 
00077   // convenience filename transfer - weak sanity check, presume 
00078   // that membership is already established
00079   // change 25.03.16: hoisted out of IWaveOp class,
00080   // membership test added
00081   void param_set(RVL::Vector<float> const & x, 
00082          PARARRAY & pars, 
00083          IWaveSpace const & sp,
00084          std::string const & suf,
00085          FILE * stream=stderr);
00086 
00087   class IWaveOp: public Operator<float>  {
00088       
00089   private:
00090 
00091     IWaveInfo ic;
00092     IWaveSpace dom;
00093     IWaveSpace rng;
00094     mutable FILE * stream;              /* output stream            */
00095     PARARRAY * pars;            /* parameter array ref copy */
00096 
00097     // verbosity control
00098     int dump_steps;
00099     int dump_pars;
00100     int dump_term;
00101 
00102     // other verbosity control handled within iwave code
00103     
00104     // dry run option
00105     bool dryrun;
00106     ostream & drystr;
00107     
00108     // verbose announcements
00109     ostream & announce;
00110 
00111     IWaveOp();
00112       
00113   protected:
00114       
00115     void apply(const Vector<float> & x, 
00116            Vector<float> & y) const;
00117 
00118     void applyDeriv(const Vector<float> & x, 
00119             const Vector<float> & dx,
00120             Vector<float> & dy) const;
00121       
00122     void applyAdjDeriv(const Vector<float> & x, 
00123                const Vector<float> & dy,
00124                Vector<float> & dx) const;
00125       
00126     void applyDeriv2(const Vector<float> & x, 
00127              const Vector<float> & dx0,
00128              const Vector<float> & dx1,
00129              Vector<float> & dy) const;
00130 
00131     void applyAdjDeriv2(const Vector<float> & x, 
00132             const Vector<float> & dx0,
00133             const Vector<float> & dy,
00134             Vector<float> & dx1) const;
00135 
00136     Operator<float> * clone() const;
00137     
00138   public:
00139     
00140     IWaveOp(PARARRAY _pars, FILE * _stream,
00141         bool _dryrun=false,
00142         ostream & _drystr=cerr,
00143         ostream & _announce=cerr);
00144     
00145     IWaveOp(IWaveOp const & x);
00146 
00147     ~IWaveOp();
00148 
00149     const IWaveSpace & getIWaveDomain() const { return dom; } 
00150     const IWaveSpace & getIWaveRange() const { return rng; } 
00151     const Space<float> & getDomain() const { return getIWaveDomain(); }
00152     const Space<float> & getRange() const { return getIWaveRange(); }
00153 
00154     // added 23.06.10 to facilitate using source as variable
00155     // without admitting that it's part of domain
00156     PARARRAY & getPar();
00157     PARARRAY const & getPar() const;
00158 
00159     ostream & write(ostream & str) const;
00160   };
00161 
00162   class IWaveLOVOp: public LinOpValOp<float>  {
00163       
00164   private:
00165 
00166     IWaveInfo ic;
00167     StdProductSpace<float> dom;
00168     IWaveSpace rng;
00169     mutable FILE * stream;      /* output stream            */
00170     PARARRAY * pars;            /* parameter array ref copy */
00171 
00172     // verbosity control
00173     int dump_steps;
00174     int dump_pars;
00175     int dump_term;
00176 
00177     // other verbosity control handled within iwave code
00178     
00179     // dry run option
00180     bool dryrun;
00181     ostream & drystr;
00182     
00183     // verbose announcements
00184     ostream & announce;
00185 
00186     IWaveLOVOp();
00187       
00188   protected:
00189       
00190     virtual void apply0(const Vector<float> & x0,
00191             const Vector<float> & x1, 
00192             Vector<float> & y) const;
00193     
00194     void applyAdj0(const Vector<float> & x0,
00195            const Vector<float> & y, 
00196            Vector<float> & x1) const;
00197     
00198     void applyPartialDeriv0(const Vector<float> & x0,
00199                 const Vector<float> & x1,
00200                 const Vector<float> & dx0,
00201                 Vector<float> & dy) const;
00202     
00203     void applyAdjPartialDeriv0(const Vector<float> & x0,
00204                    const Vector<float> & x1,
00205                    const Vector<float> & dy,
00206                    Vector<float> & dx0) const;
00207     
00208     void applyPartialDeriv20(const Vector<float> & x0,
00209                  const Vector<float> & x1,
00210                  const Vector<float> & dx00,
00211                  const Vector<float> & dx01,
00212                  Vector<float> & dy) const;
00213     
00214     void applyAdjPartialDeriv20(const Vector<float> & x0,
00215                 const Vector<float> & x1,
00216                 const Vector<float> & dx00,
00217                 const Vector<float> & dy,
00218                 Vector<float> & dx01) const;
00219 
00220     RVL::OperatorProductDomain<float> * clonePD() const {
00221       return new IWaveLOVOp(*this);
00222     }
00223     
00224   public:
00225     
00226     IWaveLOVOp(PARARRAY _pars, FILE * _stream,
00227            bool _dryrun=false,
00228            ostream & _drystr=cerr,
00229            ostream & _announce=cerr);
00230     
00231     IWaveLOVOp(IWaveLOVOp const & x);
00232 
00233     ~IWaveLOVOp();
00234 
00235     // convenience functions
00236     const IWaveSpace & getNonLinDomain() const {
00237       try {
00238     IWaveSpace const & iwspace =
00239       dynamic_cast<IWaveSpace const &>(this->getProductDomain()[0]);
00240     return iwspace;
00241       }
00242       catch (RVLException & e) {
00243     e<<"\ncalled from IWaveLOVOp::getNonLinDomain\n";
00244     throw e;
00245       }
00246       catch (bad_cast) {
00247     RVLException e;
00248     e<<"ERROR: IWaveLOVOp::getNonLinDomain\n";
00249     e<<"  who knows how - first component of domain not iwspace\n";
00250     throw e;
00251       }
00252     }
00253     const IWaveSpace & getLinDomain() const {
00254       try {
00255     IWaveSpace const & iwspace =
00256       dynamic_cast<IWaveSpace const &>(this->getProductDomain()[1]);
00257     return iwspace;
00258       }
00259       catch (RVLException & e) {
00260     e<<"\ncalled from IWaveLOVOp::getLinDomain\n";
00261     throw e;
00262       }
00263       catch (bad_cast) {
00264     RVLException e;
00265     e<<"ERROR: IWaveLOVOp::getLinDomain\n";
00266     e<<"  who knows how - first component of domain not iwspace\n";
00267     throw e;
00268       }
00269     }
00270     const IWaveSpace & getIWaveRange() const { return rng; }
00271 
00272     // mandatory
00273     const ProductSpace<float> & getProductDomain() const { return dom; }
00274     const Space<float> & getRange() const { return rng; }
00275 
00276     // added 23.06.10 to facilitate using source as variable
00277     // without admitting that it's part of domain
00278     PARARRAY & getPar();
00279     PARARRAY const & getPar() const;
00280 
00281     ostream & write(ostream & str) const;
00282   };
00283 
00284   void IWaveLoad(PARARRAY,
00285          Vector<float> &,
00286          std::vector<std::string>);
00287 
00306   class IWaveFWIOp: public Operator<float> {
00307 
00308   private:
00309 
00310     IWaveOp iwop;
00311     std::shared_ptr<Vector<float> > m0;
00312     std::shared_ptr<Vector<float> > m;
00313     std::vector<std::string> est;
00314     std::vector<std::string> estkeys;
00315     std::vector<int> estidx;
00316     std::shared_ptr<Space<float> > dom;
00317     std::shared_ptr<Space<float> > med;
00318     std::shared_ptr<Vector<float> > ub;
00319     std::shared_ptr<Vector<float> > lb;
00320     std::shared_ptr<Vector<float> > lm0;
00321     std::shared_ptr<Operator<float> > dwop;
00322     std::shared_ptr<Operator<float> > dlop;
00323     std::shared_ptr<Operator<float> > injop;
00324     std::shared_ptr<Operator<float> > transop;
00325     std::shared_ptr<Operator<float> > modelop;
00326     std::shared_ptr<Operator<float> > op;
00327 
00328     IWaveFWIOp();
00329 
00330   protected:
00331 
00332     void apply(Vector<float> const & x,
00333            Vector<float> & y) const;
00334     
00335     void applyDeriv(Vector<float> const & x,
00336             Vector<float> const & dx,
00337             Vector<float> & dy) const;
00338     
00339     void applyAdjDeriv(Vector<float> const & x,
00340                Vector<float> const & dy,
00341                Vector<float> & dx) const;
00342     
00343     void applyDeriv2(const Vector<float> & x,
00344              const Vector<float> & dx1,
00345              const Vector<float> & dx2,
00346              Vector<float> & dy) const;
00347     
00348     void applyAdjDeriv2(const Vector<float> & x,
00349             const Vector<float> & dy,
00350             const Vector<float> & dx2,
00351             Vector<float> & dx1) const;
00352 
00353     Operator<float> * clone() const { return new IWaveFWIOp(*this); }
00354 
00355   public:
00356 
00357     IWaveFWIOp(PARARRAY par, FILE * stream);
00358 
00359     IWaveFWIOp(IWaveFWIOp const & x);
00360 
00361     ~IWaveFWIOp() {}
00362 
00363     Space<float> const & getDomain() const { return op->getDomain(); }
00364     Space<float> const & getRange() const { return op->getRange(); }
00365 
00366     Operator<float> const & getTransformOp() const { return *transop; }
00367     Operator<float> const & getModelingOp() const { return *modelop; }
00368 
00369     std::vector<std::string> getDomainKeys() const { return estkeys; }
00370     std::vector<std::string> getModelKeys() const {
00371       IWaveSpace const & iwdom =
00372     dynamic_cast<IWaveSpace const &>(iwop.getDomain());
00373       return iwdom.getKeys();
00374     }
00375     std::vector<std::string> getRangeKeys() const {
00376       IWaveSpace const & iwrng =
00377     dynamic_cast<IWaveSpace const &>(iwop.getRange());
00378       return iwrng.getKeys();
00379     }
00380     
00381     ostream & write(ostream & str) const;
00382 
00383   };
00384 }
00385 
00386 #endif

Generated on 5 Jan 2017 for IWAVECORE by  doxygen 1.4.7