FV3 Bundle
HybridCovariance.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_HYBRIDCOVARIANCE_H_
12 #define OOPS_BASE_HYBRIDCOVARIANCE_H_
13 
14 #include <boost/scoped_ptr.hpp>
15 
16 #include "eckit/config/LocalConfiguration.h"
21 #include "oops/base/Variables.h"
24 #include "oops/interface/State.h"
25 #include "oops/util/abor1_cpp.h"
26 #include "oops/util/DateTime.h"
27 #include "oops/util/Logger.h"
28 
29 namespace oops {
30 
31 /// Generic hybrid static-ensemble model space error covariance.
32 
33 // -----------------------------------------------------------------------------
34 template <typename MODEL>
39 
40  public:
41  HybridCovariance(const Geometry_ &, const Variables &,
42  const eckit::Configuration &, const State_ &, const State_ &);
44 
45  void randomize(Increment_ &) const override;
46 
47  private:
48  void doMultiply(const Increment_ &, Increment_ &) const override;
49  void doInverseMultiply(const Increment_ &, Increment_ &) const override;
50 
51  boost::scoped_ptr< ModelSpaceCovarianceBase<MODEL> > static_;
52  boost::scoped_ptr< EnsembleCovariance<MODEL> > ensemble_;
53  double ensWeight_;
54 };
55 
56 // =============================================================================
57 
58 /// Constructor, destructor
59 // -----------------------------------------------------------------------------
60 template<typename MODEL>
62  const eckit::Configuration & config,
63  const State_ & xb, const State_ & fg)
64  : ModelSpaceCovarianceBase<MODEL>(xb, fg, resol, config),
65  static_(CovarianceFactory<MODEL>::create(
66  eckit::LocalConfiguration(config, "static"), resol, vars, xb, fg))
67 {
68  const eckit::LocalConfiguration ensConf(config, "ensemble");
69  ensemble_.reset(new EnsembleCovariance<MODEL>(resol, vars, ensConf, xb, fg));
70 
71  ensWeight_ = config.getDouble("ensemble_weight");
72  ASSERT(ensWeight_ > 0.0 && ensWeight_ <= 1.0);
73  Log::trace() << "HybridCovariance created." << std::endl;
74 }
75 // -----------------------------------------------------------------------------
76 template<typename MODEL>
78  Log::trace() << "HybridCovariance destructed" << std::endl;
79 }
80 // -----------------------------------------------------------------------------
81 template<typename MODEL>
83  static_->multiply(dxi, dxo);
84  dxo *= (1.0-ensWeight_);
85  Increment_ tmp(dxo);
86  ensemble_->multiply(dxi, tmp);
87  dxo.axpy(ensWeight_, tmp);
88 }
89 // -----------------------------------------------------------------------------
90 template<typename MODEL>
93  dxo.zero();
94  GMRESR(dxo, dxi, *this, Id, 10, 1.0e-3);
95 }
96 // -----------------------------------------------------------------------------
97 template<typename MODEL>
99  ABORT("HybridCovariance::randomize: Would it make sense?");
100 }
101 // -----------------------------------------------------------------------------
102 } // namespace oops
103 
104 #endif // OOPS_BASE_HYBRIDCOVARIANCE_H_
Geometry< MODEL > Geometry_
double GMRESR(VECTOR &xx, const VECTOR &bb, const AMATRIX &A, const PMATRIX &precond, const int maxiter, const double tolerance)
Definition: GMRESR.h:63
Generic ensemble based model space error covariance.
boost::scoped_ptr< EnsembleCovariance< MODEL > > ensemble_
Increment< MODEL > Increment_
void doInverseMultiply(const Increment_ &, Increment_ &) const override
void doMultiply(const Increment_ &, Increment_ &) const override
void zero()
Linear algebra operators.
subroutine, public create(self, c_conf)
Encapsulates the model state.
The namespace for the main oops code.
boost::scoped_ptr< ModelSpaceCovarianceBase< MODEL > > static_
real(fp), parameter, public e
real(fp), parameter xb
Definition: ufo_aod_mod.F90:41
void randomize(Increment_ &) const override
Abstract base class for model space error covariances.
void axpy(const double &, const Increment &, const bool check=true)
GMRESR solver for Ax=b.
Increment Class: Difference between two states.
Identity matrix.
HybridCovariance(const Geometry_ &, const Variables &, const eckit::Configuration &, const State_ &, const State_ &)
Constructor, destructor.
Generic hybrid static-ensemble model space error covariance.