FV3 Bundle
src/lorenz95/ModelBiasCovariance.cc
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 
12 
13 #include <cmath>
14 #include <iostream>
15 #include <random>
16 #include <string>
17 
18 #include "eckit/config/Configuration.h"
20 #include "oops/util/Logger.h"
21 
22 // -----------------------------------------------------------------------------
23 namespace lorenz95 {
24 // -----------------------------------------------------------------------------
25 ModelBiasCovariance::ModelBiasCovariance(const eckit::Configuration & conf, const Resolution &)
26  : conf_(conf), variance_(0.0), active_(false)
27 {
28  if (conf_.has("standard_deviation")) {
29  active_ = true;
30  const double zz = conf_.getDouble("standard_deviation");
31  variance_ = zz * zz;
32  ASSERT(variance_ > 0.0);
33  oops::Log::info() << "ModelBiasCovariance variance = " << variance_ << std::endl;
34  }
35 }
36 // -----------------------------------------------------------------------------
38  ModelBiasCorrection & dxout) const {
39  if (active_) {
40  dxout = dxin;
41  dxout *= variance_;
42  } else {
43  dxout.zero();
44  }
45 }
46 // -----------------------------------------------------------------------------
48  ModelBiasCorrection & dxout) const {
49  if (active_) {
50  dxout = dxin;
51  dxout *= 1.0 / variance_;
52  } else {
53  dxout.zero();
54  }
55 }
56 // -----------------------------------------------------------------------------
58  const double stdev = std::sqrt(variance_);
59  static std::mt19937 generator(3);
60  static std::normal_distribution<double> distribution(0.0, stdev);
61  dx.bias() = distribution(generator);
62 }
63 // -----------------------------------------------------------------------------
64 void ModelBiasCovariance::print(std::ostream & os) const {
65  if (active_) {
66  os << "ModelBiasCovariance: variance = " << variance_ << std::endl;
67  } else {
68  os << "ModelBiasCovariance not active" << std::endl;
69  }
70 }
71 // -----------------------------------------------------------------------------
72 } // namespace lorenz95
ModelBiasCovariance(const eckit::Configuration &, const Resolution &)
Constructor, destructor.
void randomize(ModelBiasCorrection &) const
Definition: conf.py:1
void inverseMultiply(const ModelBiasCorrection &, ModelBiasCorrection &) const
integer(long), parameter false
Handles resolution.
Definition: Resolution.h:25
subroutine, public info(self)
The namespace for the L95 model.
void multiply(const ModelBiasCorrection &, ModelBiasCorrection &) const