FV3 Bundle
test/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 
11 #include <iostream>
12 
13 #include <boost/scoped_ptr.hpp>
14 #include <boost/test/unit_test.hpp>
15 
16 #include "./TestConfig.h"
17 #include "eckit/config/LocalConfiguration.h"
20 #include "lorenz95/Resolution.h"
21 #include "test/TestFixture.h"
22 
23 namespace test {
24 
25 // -----------------------------------------------------------------------------
27  public:
29  eckit::LocalConfiguration res(TestConfig::config(), "resolution");
30  resol_.reset(new lorenz95::Resolution(res));
31  covconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "ModelBiasCovariance"));
32  nobias_.reset(new eckit::LocalConfiguration());
33  }
35  boost::scoped_ptr<lorenz95::Resolution> resol_;
36  boost::scoped_ptr<const eckit::LocalConfiguration> covconf_;
37  boost::scoped_ptr<const eckit::LocalConfiguration> nobias_;
38 };
39 // -----------------------------------------------------------------------------
40 
41 // -----------------------------------------------------------------------------
42 BOOST_FIXTURE_TEST_SUITE(test_modelBiasCovariance, ModBiasCovTestFixture)
43 // -----------------------------------------------------------------------------
44  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_constructor_conf) {
45  lorenz95::ModelBiasCovariance bcovar(*covconf_, *resol_);
46  BOOST_CHECK_EQUAL(bcovar.active(), true);
47  }
48 // -----------------------------------------------------------------------------
49  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_constructor_no_conf) {
50  lorenz95::ModelBiasCovariance bcovar(*nobias_, *resol_);
51  BOOST_CHECK_EQUAL(bcovar.active(), false);
52 }
53 // -----------------------------------------------------------------------------
54  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_linearize) {
55  // not yet implemented
56  }
57 // -----------------------------------------------------------------------------
58  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_multiply_active) {
59  // construct the ModelBiasCorrection object
60  lorenz95::ModelBiasCovariance bcovar(*covconf_, *resol_);
61  lorenz95::ModelBiasCorrection dbias1(*resol_, *covconf_);
62  dbias1.bias() = 2.0;
63  lorenz95::ModelBiasCorrection dbias2(dbias1, true);
64 
65  bcovar.multiply(dbias1, dbias2);
66 
67  double stdev = covconf_->getDouble("standard_deviation");
68  BOOST_CHECK_EQUAL(dbias2.bias(), dbias1.bias() * stdev * stdev);
69  }
70 // -----------------------------------------------------------------------------
71  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_multiply_inactive) {
72  // construct the ModelBiasCorrection object
73  lorenz95::ModelBiasCovariance bcovar(*nobias_, *resol_);
74  lorenz95::ModelBiasCorrection dbias1(*resol_, *covconf_);
75  dbias1.bias() = 2.0;
76  lorenz95::ModelBiasCorrection dbias2(dbias1, true);
77 
78  bcovar.multiply(dbias1, dbias2);
79 
80  // because the covconf_ is empty, the bias is set to 0
81  BOOST_CHECK_EQUAL(dbias2.bias(), 0.0);
82  }
83 // -----------------------------------------------------------------------------
84  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_invMult_active) {
85  // construct the ModelBiasCorrection object
86  lorenz95::ModelBiasCovariance bcovar(*covconf_, *resol_);
87  lorenz95::ModelBiasCorrection dbias1(*resol_, *covconf_);
88  dbias1.bias() = 2.0;
89  lorenz95::ModelBiasCorrection dbias2(dbias1, true);
90 
91  bcovar.inverseMultiply(dbias1, dbias2);
92 
93  double stdev = covconf_->getDouble("standard_deviation");
94  BOOST_CHECK_EQUAL(dbias2.bias(), dbias1.bias() *1.0 / (stdev * stdev));
95  }
96 // -----------------------------------------------------------------------------
97  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_invMult_inactive) {
98  // construct the ModelBiasCorrection object
99  lorenz95::ModelBiasCovariance bcovar(*nobias_, *resol_);
100  lorenz95::ModelBiasCorrection dbias1(*resol_, *covconf_);
101  dbias1.bias() = 2.0;
102  lorenz95::ModelBiasCorrection dbias2(dbias1, true);
103 
104  bcovar.inverseMultiply(dbias1, dbias2);
105 
106  // because the covconf_ is empty, the bias is set to 0
107  BOOST_CHECK_EQUAL(dbias2.bias(), 0.0);
108  }
109 // -----------------------------------------------------------------------------
110  BOOST_AUTO_TEST_CASE(test_modelBiasCovariance_active) {
111  lorenz95::ModelBiasCovariance bcovar(*covconf_, *resol_);
112  BOOST_CHECK_EQUAL(bcovar.active(), true);
113  }
114 // -----------------------------------------------------------------------------
115 
116 BOOST_AUTO_TEST_SUITE_END()
117 } // namespace test
void inverseMultiply(const ModelBiasCorrection &, ModelBiasCorrection &) const
boost::scoped_ptr< lorenz95::Resolution > resol_
Handles resolution.
Definition: Resolution.h:25
boost::scoped_ptr< const eckit::LocalConfiguration > covconf_
boost::scoped_ptr< const eckit::LocalConfiguration > nobias_
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
Definition: TestConfig.h:30
void multiply(const ModelBiasCorrection &, ModelBiasCorrection &) const