tIPMeanSquareFunctional.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
 (HTM) git clone git://src.adamsgaard.dk/pism
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tIPMeanSquareFunctional.hh (3487B)
       ---
            1 // Copyright (C) 2012, 2013, 2014, 2015  David Maxwell
            2 //
            3 // This file is part of PISM.
            4 //
            5 // PISM is free software; you can redistribute it and/or modify it under the
            6 // terms of the GNU General Public License as published by the Free Software
            7 // Foundation; either version 3 of the License, or (at your option) any later
            8 // version.
            9 //
           10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
           11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
           12 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
           13 // details.
           14 //
           15 // You should have received a copy of the GNU General Public License
           16 // along with PISM; if not, write to the Free Software
           17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
           18 
           19 #ifndef IPMEANSQUAREFUNCTIONAL_HH_DZ18EO5C
           20 #define IPMEANSQUAREFUNCTIONAL_HH_DZ18EO5C
           21 
           22 #include "IPFunctional.hh"
           23 
           24 namespace pism {
           25 namespace inverse {
           26 
           27 //! Implements a functional corresponding to a (possibly weighted) sum of squares of components of an IceModelVec2S.
           28 /*! If the vector has components \f$x_i\f$ the functional is
           29   \f[
           30   J(x) = c_N \sum_{i} w_i x_i^2
           31   \f]
           32   where \f$[w_i]\f$ is a vector of weights and \f$c_N\f$ is a normalization constant. The value
           33   of the normalization constant is set implicitly by a call to normalize().
           34 */
           35 class IPMeanSquareFunctional2S : public IPInnerProductFunctional<IceModelVec2S> {
           36 public:
           37   IPMeanSquareFunctional2S(IceGrid::ConstPtr grid, 
           38                            IceModelVec2S *weights=NULL) :  ///< Vector of weights (NULL implies all weights are 1)
           39     IPInnerProductFunctional<IceModelVec2S>(grid), m_weights(weights), m_normalization(1.) {};
           40   virtual ~IPMeanSquareFunctional2S() {};
           41 
           42   virtual void normalize(double scale);
           43 
           44   virtual void valueAt(IceModelVec2S &x, double *OUTPUT);
           45   virtual void dot(IceModelVec2S &a, IceModelVec2S &b, double *OUTPUT);
           46   virtual void gradientAt(IceModelVec2S &x, IceModelVec2S &gradient);
           47 
           48 protected:
           49   IceModelVec2S *m_weights;
           50   double m_normalization;
           51 
           52 private:
           53   IPMeanSquareFunctional2S(IPMeanSquareFunctional2S const &);
           54   IPMeanSquareFunctional2S & operator=(IPMeanSquareFunctional2S const &);
           55 };
           56 
           57 
           58 //! Implements a functional corresponding to a (possibly weighted) sum of squares of components of an IceModelVec2S.
           59 /*! If the vector has component vectors \f$x_i\f$ the functional is
           60   \f[
           61   J(x) = c_N \sum_{i} w_i |x_i|^2
           62   \f]
           63   where \f$[w_i]\f$ is a vector of weights and \f$c_N\f$ is a normalization constant. The value
           64   of the normalization constant is set implicitly by a call to normalize().
           65 */
           66 class IPMeanSquareFunctional2V : public IPInnerProductFunctional<IceModelVec2V> {
           67 public:
           68   IPMeanSquareFunctional2V(IceGrid::ConstPtr grid, IceModelVec2S *weights=NULL) :
           69     IPInnerProductFunctional<IceModelVec2V>(grid), m_weights(weights), m_normalization(1.) {};
           70   virtual ~IPMeanSquareFunctional2V() {};
           71 
           72   virtual void normalize(double scale);
           73 
           74   virtual void valueAt(IceModelVec2V &x, double *OUTPUT);
           75   virtual void dot(IceModelVec2V &a, IceModelVec2V &b, double *OUTPUT);
           76   virtual void gradientAt(IceModelVec2V &x, IceModelVec2V &gradient);
           77 
           78 protected:
           79   IceModelVec2S *m_weights;
           80   double m_normalization;
           81 
           82 private:
           83   IPMeanSquareFunctional2V(IPMeanSquareFunctional2V const &);
           84   IPMeanSquareFunctional2V & operator=(IPMeanSquareFunctional2V const &);
           85 };
           86 
           87 
           88 } // end of namespace inverse
           89 } // end of namespace pism
           90 
           91 #endif /* end of include guard: IPMEANSQUAREFUNCTIONAL_HH_DZ18EO5C */