IODA Bundle
oops/src/test/interface/ObsSpace.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2017-2020 UCAR.
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  * In applying this licence, ECMWF does not waive the privileges and immunities
8  * granted to it by virtue of its status as an intergovernmental organisation nor
9  * does it submit to any jurisdiction.
10  */
11 
12 #ifndef TEST_INTERFACE_OBSSPACE_H_
13 #define TEST_INTERFACE_OBSSPACE_H_
14 
15 #include <string>
16 #include <vector>
17 
18 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
19 
20 #include <boost/noncopyable.hpp>
21 
22 #include "eckit/config/LocalConfiguration.h"
23 #include "eckit/testing/Test.h"
26 #include "oops/runs/Test.h"
27 #include "oops/util/DateTime.h"
28 #include "oops/util/Duration.h"
30 #include "test/TestEnvironment.h"
31 
32 namespace test {
33 
34 // -----------------------------------------------------------------------------
35 /// \brief tests constructor, window accessor methods and prints
36 template <typename OBS> void testConstructor() {
37  typedef ObsTestsFixture<OBS> Test_;
38 
39  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
40  oops::Log::test() << "Testing ObsSpace: " << Test_::obspace()[jj] << std::endl;
41  EXPECT(Test_::obspace()[jj].windowStart() == Test_::tbgn());
42  EXPECT(Test_::obspace()[jj].windowEnd() == Test_::tend());
43  }
44 }
45 
46 // -----------------------------------------------------------------------------
47 /// \brief tests that ObsSpaces created on subwindows have the same number obs as
48 /// ObsSpaces created on the whole window
49 template <typename OBS> void testSubwindows() {
50  typedef ObsTestsFixture<OBS> Test_;
51  typedef oops::ObsSpace<OBS> ObsSpace_;
52  typedef oops::ObsVector<OBS> ObsVector_;
53 
54  util::DateTime tmid = Test_::tbgn() + (Test_::tend()-Test_::tbgn())/2;
55  oops::Log::test() << "Testing subwindows: " << Test_::tbgn() << " to " << tmid << " and "
56  << tmid << " to " << Test_::tend() << std::endl;
57  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
58  eckit::LocalConfiguration obsconfig(Test_::config(jj), "obs space");
59  ObsSpace_ obspace1(obsconfig, oops::mpi::world(), Test_::tbgn(), tmid);
60  ObsSpace_ obspace2(obsconfig, oops::mpi::world(), tmid, Test_::tend());
61 
62  /// Create ObsVectors for each of the ObsSpaces, to compare nobs
63  ObsVector_ ovec(Test_::obspace()[jj]);
64  ObsVector_ ovec1(obspace1);
65  ObsVector_ ovec2(obspace2);
66  oops::Log::test() << Test_::obspace()[jj].obsname() << " nobs(all): " << ovec.nobs()
67  << " nobs(1st subwindow): " << ovec1.nobs()
68  << " nobs(2nd subwindow): " << ovec2.nobs() << std::endl;
69  EXPECT_EQUAL(ovec1.nobs() + ovec2.nobs(), ovec.nobs());
70  }
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 template <typename OBS> class ObsSpace : public oops::Test {
77  public:
78  ObsSpace() {}
79  virtual ~ObsSpace() {}
80  private:
81  std::string testid() const override {return "test::ObsSpace<" + OBS::name() + ">";}
82 
83  void register_tests() const override {
84  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
85 
86  ts.emplace_back(CASE("interface/ObsSpace/testConstructor")
87  { testConstructor<OBS>(); });
88  ts.emplace_back(CASE("interface/ObsSpace/testSubwindows")
89  { testSubwindows<OBS>(); });
90  }
91 
92  void clear() const override {
93  Test_::reset();
94  }
95 };
96 
97 // -----------------------------------------------------------------------------
98 
99 } // namespace test
100 
101 #endif // TEST_INTERFACE_OBSSPACE_H_
program test
void register_tests() const override
void clear() const override
ObsTestsFixture< OBS > Test_
std::string testid() const override
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
Definition: oops/mpi/mpi.cc:84
void testSubwindows()
tests that ObsSpaces created on subwindows have the same number obs as ObsSpaces created on the whole...
CASE("assimilation/FullGMRES/FullGMRES")
void testConstructor()
Tests creation and destruction of ObsErrorCovariances.