FV3 Bundle
SaddlePointVector.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_ASSIMILATION_SADDLEPOINTVECTOR_H_
12 #define OOPS_ASSIMILATION_SADDLEPOINTVECTOR_H_
13 
14 #include <boost/scoped_ptr.hpp>
15 
18 #include "oops/util/dot_product.h"
19 
20 namespace oops {
21 
22 /*!
23  * Control vector for the saddle point formulation.
24  * The vector contains two ControlIncrements and one Departure,
25  * and knows how to do basic linear algebra.
26  */
27 /// Control vector for the saddle point formulation.
28 
29 // -----------------------------------------------------------------------------
30 template<typename MODEL> class SaddlePointVector {
33 
34  public:
37 
38 /// Accessor method to get the lambda_ component
39  const Multipliers_ & lambda() const {return *lambda_;}
40  Multipliers_ & lambda() {return *lambda_;}
41 
42 /// Accessor method to set the lambda_ component
44 
45 /// Accessor method to get the dx_ component
46  const CtrlInc_ & dx() const {return *dx_;}
47  CtrlInc_ & dx() {return *dx_;}
48 
49 /// Accessor method to set the dx_ component
50  void dx(CtrlInc_ * dx) {dx_.reset(dx);}
51 
55  SaddlePointVector & operator*=(const double);
56  void zero();
57  void axpy(const double, const SaddlePointVector &);
58  double dot_product_with(const SaddlePointVector &) const;
59 
60  private:
61  boost::scoped_ptr<Multipliers_> lambda_;
62  boost::scoped_ptr<CtrlInc_> dx_;
63 };
64 
65 // =============================================================================
66 
67 template<typename MODEL>
70  : lambda_(lambda), dx_(dx)
71 {}
72 
73 // -----------------------------------------------------------------------------
74 
75 template<typename MODEL>
77  : lambda_(new Multipliers_(*other.lambda_)), dx_(new CtrlInc_(*other.dx_))
78 {}
79 
80 // -----------------------------------------------------------------------------
81 
82 template<typename MODEL> SaddlePointVector<MODEL> &
84  *lambda_ = *rhs.lambda_;
85  *dx_ = *rhs.dx_;
86  return *this;
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 template<typename MODEL> SaddlePointVector<MODEL> &
93  *lambda_ += *rhs.lambda_;
94  *dx_ += *rhs.dx_;
95  return *this;
96 }
97 
98 // -----------------------------------------------------------------------------
99 
100 template<typename MODEL> SaddlePointVector<MODEL> &
102  *lambda_ -= *rhs.lambda_;
103  *dx_ -= *rhs.dx_;
104  return *this;
105 }
106 
107 // -----------------------------------------------------------------------------
108 
109 template<typename MODEL> SaddlePointVector<MODEL> &
111  *lambda_ *= rhs;
112  *dx_ *= rhs;
113  return *this;
114 }
115 
116 // -----------------------------------------------------------------------------
117 
118 template<typename MODEL> void SaddlePointVector<MODEL>::zero() {
119  lambda_->zero();
120  dx_->zero();
121 }
122 
123 // -----------------------------------------------------------------------------
124 
125 template<typename MODEL> void SaddlePointVector<MODEL>::axpy(const double zz,
126  const SaddlePointVector & rhs) {
127  lambda_->axpy(zz, *rhs.lambda_);
128  dx_->axpy(zz, *rhs.dx_);
129 }
130 
131 // -----------------------------------------------------------------------------
132 
133 template<typename MODEL> double SaddlePointVector<MODEL>::dot_product_with(
134  const SaddlePointVector & x2) const {
135 return dot_product(*lambda_, *x2.lambda_)
136  +dot_product(*dx_, *x2.dx_);
137 }
138 
139 // -----------------------------------------------------------------------------
140 
141 } // namespace oops
142 
143 #endif // OOPS_ASSIMILATION_SADDLEPOINTVECTOR_H_
DualVector< MODEL > Multipliers_
SaddlePointVector & operator-=(const SaddlePointVector &)
Container of dual space vectors for all terms of the cost function.
Definition: DualVector.h:34
ControlIncrement< MODEL > CtrlInc_
SaddlePointVector & operator=(const SaddlePointVector &)
void lambda(Multipliers_ *lambda)
Accessor method to set the lambda_ component.
The namespace for the main oops code.
boost::scoped_ptr< Multipliers_ > lambda_
double dot_product_with(const SaddlePointVector &) const
void dx(CtrlInc_ *dx)
Accessor method to set the dx_ component.
const Multipliers_ & lambda() const
Accessor method to get the lambda_ component.
SaddlePointVector & operator+=(const SaddlePointVector &)
void axpy(const double, const SaddlePointVector &)
SaddlePointVector & operator*=(const double)
Control vector for the saddle point formulation.
const CtrlInc_ & dx() const
Accessor method to get the dx_ component.
boost::scoped_ptr< CtrlInc_ > dx_
SaddlePointVector(CtrlInc_ *, Multipliers_ *)