FV3 Bundle
oops/src/test/interface/ObsOperator.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 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_INTERFACE_OBSOPERATOR_H_
9 #define TEST_INTERFACE_OBSOPERATOR_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #define BOOST_TEST_NO_MAIN
15 #define BOOST_TEST_ALTERNATIVE_INIT_API
16 #define BOOST_TEST_DYN_LINK
17 #include <boost/test/unit_test.hpp>
18 
19 #include <boost/noncopyable.hpp>
20 #include <boost/scoped_ptr.hpp>
21 
22 #include "eckit/config/LocalConfiguration.h"
23 #include "oops/interface/GeoVaLs.h"
28 #include "oops/runs/Test.h"
30 #include "test/TestEnvironment.h"
31 
32 namespace test {
33 
34 // -----------------------------------------------------------------------------
35 
36 template <typename MODEL> void testConstructor() {
37  typedef ObsTestsFixture<MODEL> Test_;
38  typedef oops::ObsOperator<MODEL> ObsOperator_;
39 
40  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
41  boost::scoped_ptr<ObsOperator_> hop(new ObsOperator_(Test_::obspace()[jj]));
42  BOOST_CHECK(hop.get());
43 
44  hop.reset();
45  BOOST_CHECK(!hop.get());
46  }
47 }
48 
49 // -----------------------------------------------------------------------------
50 
51 template <typename MODEL> void testEquiv() {
52  typedef ObsTestsFixture<MODEL> Test_;
53  typedef oops::GeoVaLs<MODEL> GeoVaLs_;
54  typedef oops::Locations<MODEL> Locations_;
55  typedef oops::ObsAuxControl<MODEL> ObsAuxCtrl_;
56  typedef oops::ObsOperator<MODEL> ObsOperator_;
57  typedef oops::ObsVector<MODEL> ObsVector_;
58 
59  const eckit::LocalConfiguration obsconf(TestEnvironment::config(), "Observations");
60  std::vector<eckit::LocalConfiguration> conf;
61  obsconf.get("ObsTypes", conf);
62 
63  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
64  ObsOperator_ hop(Test_::obspace()[jj]);
65  eckit::LocalConfiguration gconf(conf[jj], "GeoVaLs");
66  Locations_ locs(Test_::obspace()[jj].locations(Test_::tbgn(), Test_::tend()));
67  const GeoVaLs_ gval(gconf, hop.variables());
68 
69  eckit::LocalConfiguration biasConf;
70  conf[jj].get("ObsBias", biasConf);
71  const ObsAuxCtrl_ ybias(biasConf);
72 
73  ObsVector_ ovec(Test_::obspace()[jj]);
74 
75  hop.simulateObs(gval, ovec, ybias);
76 
77  const double zz = ovec.rms();
78  const double xx = conf[jj].getDouble("rmsequiv");
79  const double tol = conf[jj].getDouble("tolerance");
80  BOOST_CHECK_CLOSE(xx, zz, tol);
81  }
82 }
83 
84 // -----------------------------------------------------------------------------
85 
86 template <typename MODEL> class ObsOperator : public oops::Test {
87  public:
89  virtual ~ObsOperator() {}
90  private:
91  std::string testid() const {return "test::ObsOperator<" + MODEL::name() + ">";}
92 
93  void register_tests() const {
94  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/ObsOperator");
95 
96  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
97  ts->add(BOOST_TEST_CASE(&testEquiv<MODEL>));
98 
99  boost::unit_test::framework::master_test_suite().add(ts);
100  }
101 };
102 
103 // =============================================================================
104 
105 } // namespace test
106 
107 #endif // TEST_INTERFACE_OBSOPERATOR_H_
Definition: conf.py:1
static const eckit::Configuration & config()
character(len=32) name
void testConstructor()