FV3 Bundle
EnsembleCovariance.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_BASE_ENSEMBLECOVARIANCE_H_
12 #define OOPS_BASE_ENSEMBLECOVARIANCE_H_
13 
14 #include <boost/scoped_ptr.hpp>
15 
16 #include "eckit/config/LocalConfiguration.h"
22 #include "oops/base/Variables.h"
26 #include "oops/interface/State.h"
27 #include "oops/util/abor1_cpp.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/Logger.h"
30 
31 namespace oops {
32 
33 /// Generic ensemble based model space error covariance.
34 
35 // -----------------------------------------------------------------------------
36 template <typename MODEL>
39  typedef boost::shared_ptr<StateEnsemble<MODEL> > EnsemblePtr_;
45 
46  public:
47  EnsembleCovariance(const Geometry_ &, const Variables &,
48  const eckit::Configuration &, const State_ &, const State_ &);
50 
51  void randomize(Increment_ &) const override;
52 
53  private:
54  void doMultiply(const Increment_ &, Increment_ &) const override;
55  void doInverseMultiply(const Increment_ &, Increment_ &) const override;
56 
57  const util::DateTime time_;
58  boost::scoped_ptr<Localization_> loc_;
59 };
60 
61 // =============================================================================
62 
63 /// Constructor, destructor
64 // -----------------------------------------------------------------------------
65 template<typename MODEL>
67  const eckit::Configuration & conf,
68  const State_ & xb, const State_ & fg)
69  : ModelSpaceCovarianceBase<MODEL>(xb, fg, resol, conf),
70  time_(conf.getString("date")), loc_()
71 {
72  Log::trace() << "EnsembleCovariance::EnsembleCovariance start" << std::endl;
73 // Compute the ensemble of perturbations at time of xb.
74  ASSERT(xb.validTime() == time_);
75  EnsemblePtr_ ens_k(new Ensemble_(xb.validTime(), conf));
76  ens_k->linearize(xb, fg, resol);
77  EnsemblesCollection_::getInstance().put(xb.validTime(), ens_k);
78 
79  const eckit::LocalConfiguration confloc(conf, "localization");
80  loc_.reset(new Localization_(resol, confloc));
81  Log::trace() << "EnsembleCovariance::EnsembleCovariance done" << std::endl;
82 }
83 // -----------------------------------------------------------------------------
84 template<typename MODEL>
86  Log::trace() << "EnsembleCovariance destructed." << std::endl;
87 }
88 // -----------------------------------------------------------------------------
89 template<typename MODEL>
91  Increment_ & dxo) const {
92  EnsemblePtr_ e_k2 = EnsemblesCollection_::getInstance()[dxi.validTime()];
93  EnsemblePtr_ e_k1 = EnsemblesCollection_::getInstance()[dxo.validTime()];
94 
95  // Apply to dxi the block B_k1k2 of the B matrix which contains the
96  // covariance of perturbations at time k1 with covariance at time k2
97  dxo.zero();
98  for (unsigned int m = 0; m < e_k1->size(); ++m) {
99  Increment_ dx(dxi);
100  dx.schur_product_with((*e_k2)[m]);
101  loc_->multiply(dx);
102  dx.schur_product_with((*e_k1)[m]);
103 
104  // We can't use '+=' , dxo and dx aren't at the same time (QG)
105  dxo.axpy(1.0, dx, false);
106  }
107 }
108 // -----------------------------------------------------------------------------
109 template<typename MODEL>
111  Increment_ & dxo) const {
113  dxo.zero();
114  GMRESR(dxo, dxi, *this, Id, 10, 1.0e-3);
115 }
116 // -----------------------------------------------------------------------------
117 template<typename MODEL>
119  ABORT("EnsembleCovariance::randomize: Would it make sense?");
120 }
121 // -----------------------------------------------------------------------------
122 } // namespace oops
123 
124 #endif // OOPS_BASE_ENSEMBLECOVARIANCE_H_
double GMRESR(VECTOR &xx, const VECTOR &bb, const AMATRIX &A, const PMATRIX &precond, const int maxiter, const double tolerance)
Definition: GMRESR.h:63
boost::scoped_ptr< Localization_ > loc_
const util::DateTime time_
Generic ensemble based model space error covariance.
void doInverseMultiply(const Increment_ &, Increment_ &) const override
Definition: conf.py:1
const util::DateTime validTime() const
Time.
void zero()
Linear algebra operators.
EnsemblesCollection< MODEL > EnsemblesCollection_
static EnsemblesCollection< MODEL > & getInstance()
Localization< MODEL > Localization_
Encapsulates the model state.
Geometry< MODEL > Geometry_
integer, parameter m
The namespace for the main oops code.
real(fp), parameter, public e
real(fp), parameter xb
Definition: ufo_aod_mod.F90:41
Abstract base class for model space error covariances.
void axpy(const double &, const Increment &, const bool check=true)
GMRESR solver for Ax=b.
EnsembleCovariance(const Geometry_ &, const Variables &, const eckit::Configuration &, const State_ &, const State_ &)
Constructor, destructor.
Increment Class: Difference between two states.
void randomize(Increment_ &) const override
Identity matrix.
Increment< MODEL > Increment_
void doMultiply(const Increment_ &, Increment_ &) const override
boost::shared_ptr< StateEnsemble< MODEL > > EnsemblePtr_
StateEnsemble< MODEL > Ensemble_
void schur_product_with(const Increment &)