PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
IPMeanSquareFunctional.hh
Go to the documentation of this file.
1 // Copyright (C) 2012, 2013, 2014, 2015, 2020, 2022 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 "pism/inverse/functional/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 array::Scalar.
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<array::Scalar> {
36 public:
37  /*!
38  * @param[in] grid the computational grid
39  * @param[in] weights Vector of weights (NULL implies all weights are 1)
40  */
41  IPMeanSquareFunctional2S(std::shared_ptr<const Grid> grid,
42  array::Scalar *weights=NULL)
43  : IPInnerProductFunctional<array::Scalar>(grid),
44  m_weights(weights),
45  m_normalization(1.) {};
47 
48  virtual void normalize(double scale);
49 
50  virtual void valueAt(array::Scalar &x, double *OUTPUT);
51  virtual void dot(array::Scalar &a, array::Scalar &b, double *OUTPUT);
52  virtual void gradientAt(array::Scalar &x, array::Scalar &gradient);
53 
54 protected:
57 
58 private:
61 };
62 
63 
64 //! Implements a functional corresponding to a (possibly weighted) sum of squares of components of an array::Scalar.
65 /*! If the vector has component vectors \f$x_i\f$ the functional is
66  \f[
67  J(x) = c_N \sum_{i} w_i |x_i|^2
68  \f]
69  where \f$[w_i]\f$ is a vector of weights and \f$c_N\f$ is a normalization constant. The value
70  of the normalization constant is set implicitly by a call to normalize().
71 */
72 class IPMeanSquareFunctional2V : public IPInnerProductFunctional<array::Vector> {
73 public:
74  IPMeanSquareFunctional2V(std::shared_ptr<const Grid> grid, array::Scalar *weights=NULL) :
75  IPInnerProductFunctional<array::Vector>(grid), m_weights(weights), m_normalization(1.) {};
77 
78  virtual void normalize(double scale);
79 
80  virtual void valueAt(array::Vector &x, double *OUTPUT);
81  virtual void dot(array::Vector &a, array::Vector &b, double *OUTPUT);
82  virtual void gradientAt(array::Vector &x, array::Vector &gradient);
83 
84 protected:
87 
88 private:
91 };
92 
93 
94 } // end of namespace inverse
95 } // end of namespace pism
96 
97 #endif /* end of include guard: IPMEANSQUAREFUNCTIONAL_HH_DZ18EO5C */
Abstract base class for IPFunctionals arising from an inner product.
Definition: IPFunctional.hh:94
virtual void normalize(double scale)
Implicitly set the normalization constant for the functional.
virtual void dot(array::Scalar &a, array::Scalar &b, double *OUTPUT)
Computes the inner product .
IPMeanSquareFunctional2S(std::shared_ptr< const Grid > grid, array::Scalar *weights=NULL)
virtual void valueAt(array::Scalar &x, double *OUTPUT)
Computes the value of the functional at the vector x.
virtual void gradientAt(array::Scalar &x, array::Scalar &gradient)
Computes the gradient of the functional at the vector x.
IPMeanSquareFunctional2S & operator=(IPMeanSquareFunctional2S const &)
IPMeanSquareFunctional2S(IPMeanSquareFunctional2S const &)
Implements a functional corresponding to a (possibly weighted) sum of squares of components of an arr...
virtual void gradientAt(array::Vector &x, array::Vector &gradient)
Computes the gradient of the functional at the vector x.
virtual void dot(array::Vector &a, array::Vector &b, double *OUTPUT)
Computes the inner product .
IPMeanSquareFunctional2V & operator=(IPMeanSquareFunctional2V const &)
virtual void valueAt(array::Vector &x, double *OUTPUT)
Computes the value of the functional at the vector x.
IPMeanSquareFunctional2V(IPMeanSquareFunctional2V const &)
virtual void normalize(double scale)
Implicitly set the normalization constant for the functional.
IPMeanSquareFunctional2V(std::shared_ptr< const Grid > grid, array::Scalar *weights=NULL)
Implements a functional corresponding to a (possibly weighted) sum of squares of components of an arr...