OOPS
test/base/Departures.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020-2020 UCAR
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  */
7 
8 #ifndef TEST_BASE_DEPARTURES_H_
9 #define TEST_BASE_DEPARTURES_H_
10 
11 #include <Eigen/Dense>
12 #include <string>
13 #include <vector>
14 
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
16 
17 #include "eckit/config/LocalConfiguration.h"
18 #include "eckit/testing/Test.h"
19 #include "oops/base/Departures.h"
20 #include "oops/runs/Test.h"
21 #include "oops/util/Logger.h"
23 #include "test/TestEnvironment.h"
24 
25 namespace test {
26 
27 // -----------------------------------------------------------------------------
28 
29 template <typename OBS> void testDepartures() {
30  typedef ObsTestsFixture<OBS> Test_;
31  typedef oops::Departures<OBS> Departures_;
32 
33  Departures_ y(Test_::obspace());
34  Departures_ y2(Test_::obspace());
35  Departures_ ydiff(Test_::obspace());
36 
37  // check assign and "-=" operator
38  y.random();
39  double ref_rms = y.rms();
40  oops::Log::test() << "yrandom.rms=" << ref_rms << std::endl;
41 
42  y2.zero();
43  oops::Log::test() << "yzero.rms=" << y2.rms() << std::endl;
44 
45  ydiff = y;
46  ydiff -= y2;
47  oops::Log::test() << "rms(yrandom-yzero)=" << ydiff.rms() << std::endl;
48 
49  EXPECT(ydiff.rms() != 0.0);
50 
51  // check pack operator
52  Eigen::VectorXd ypack = y.packEigen();
53  oops::Log::info() << "ypack: " << ypack << std::endl;
54  double rms = ypack.norm() / sqrt(ypack.size());
55  oops::Log::test() << "rms(ypack)=" << rms << std::endl;
56  oops::Log::test() << "y.rms()=" << ref_rms << std::endl;
57  oops::Log::test() << "y.rms()-rms(ypack)" << ref_rms - rms << std::endl;
58 
59  EXPECT(oops::is_close(ref_rms, rms, 1.e-14));
60 }
61 
62 template <typename OBS> class Departures : public oops::Test {
64  public:
66  virtual ~Departures() {}
67  private:
68  std::string testid() const override {return "test::Departures<" + OBS::name() + ">";}
69 
70  void register_tests() const override {
71  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
72  ts.emplace_back(CASE("base/Departures/testDepartures")
73  { testDepartures<OBS>(); });
74  }
75 
76  void clear() const override {
77  Test_::reset();
78  }
79 };
80 
81 // =============================================================================
82 
83 } // namespace test
84 
85 #endif // TEST_BASE_DEPARTURES_H_
test::ObsTestsFixture
Definition: ObsTestsFixture.h:29
test::Departures::clear
void clear() const override
Definition: test/base/Departures.h:76
test::Departures::testid
std::string testid() const override
Definition: test/base/Departures.h:68
test::ObsTestsFixture::reset
static void reset()
Definition: ObsTestsFixture.h:37
test::testDepartures
void testDepartures()
Definition: test/base/Departures.h:29
test::CASE
CASE("test_linearmodelparameterswrapper_valid_name")
Definition: LinearModelFactory.cc:22
test::Departures
Definition: test/base/Departures.h:62
test
Definition: LinearModelFactory.cc:20
Departures.h
Test.h
oops::Departures
Difference between two observation vectors.
Definition: oops/base/Departures.h:44
ObsTestsFixture.h
test::Departures::Test_
ObsTestsFixture< OBS > Test_
Definition: test/base/Departures.h:63
test::Departures::Departures
Departures()
Definition: test/base/Departures.h:65
TestEnvironment.h
test::Departures::register_tests
void register_tests() const override
Definition: test/base/Departures.h:70
test::Departures::~Departures
virtual ~Departures()
Definition: test/base/Departures.h:66
oops::Test
Definition: Test.h:39