8 #ifndef TEST_INTERFACE_LINEAROBSOPERATOR_H_ 9 #define TEST_INTERFACE_LINEAROBSOPERATOR_H_ 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> 19 #include <boost/scoped_ptr.hpp> 26 #include "oops/util/dot_product.h" 27 #include "oops/util/Logger.h" 36 typedef ObsTestsFixture<MODEL> Test_;
39 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
40 boost::scoped_ptr<LinearObsOperator_> ov(
new LinearObsOperator_(Test_::obspace()[jj]));
41 BOOST_CHECK(ov.get());
44 BOOST_CHECK(!ov.get());
60 const double zero = 0.0;
61 const double coef = 3.14;
64 std::vector<eckit::LocalConfiguration>
conf;
65 obsconf.get(
"ObsTypes",
conf);
67 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
68 ObsOperator_ hop(Test_::obspace()[jj]);
69 LinearObsOperator_ hoptl(Test_::obspace()[jj]);
71 const eckit::LocalConfiguration gconf(
conf[jj],
"GeoVaLs");
72 Locations_ locs(Test_::obspace()[jj].locations(Test_::tbgn(), Test_::tend()));
73 const GeoVaLs_ gval(gconf, hop.variables());
75 eckit::LocalConfiguration biasConf;
76 conf[jj].get(
"ObsBias", biasConf);
77 const ObsAuxCtrl_ ybias(biasConf);
78 hoptl.setTrajectory(gval, ybias);
80 const ObsAuxIncr_ ybinc(biasConf);
81 ObsVector_ dy1(Test_::obspace()[jj]);
82 GeoVaLs_ gv(gconf, hoptl.variables());
85 hoptl.simulateObsTL(gv, dy1, ybinc);
87 BOOST_CHECK_EQUAL(dy1.rms(),
zero);
90 hoptl.simulateObsTL(gv, dy1, ybinc);
92 BOOST_CHECK(dy1.rms() >
zero);
95 ObsVector_ dy2(Test_::obspace()[jj]);
96 hoptl.simulateObsTL(gv, dy2, ybinc);
100 BOOST_CHECK_SMALL(dy1.rms(),
tol);
116 const double zero = 0.0;
119 std::vector<eckit::LocalConfiguration>
conf;
120 obsconf.get(
"ObsTypes",
conf);
122 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
123 ObsOperator_ hop(Test_::obspace()[jj]);
124 LinearObsOperator_ hoptl(Test_::obspace()[jj]);
125 eckit::LocalConfiguration gconf(
conf[jj],
"GeoVaLs");
126 Locations_ locs(Test_::obspace()[jj].locations(Test_::tbgn(), Test_::tend()));
127 const GeoVaLs_ gval(gconf, hop.variables());
129 eckit::LocalConfiguration biasConf;
130 conf[jj].get(
"ObsBias", biasConf);
131 const ObsAuxCtrl_ ybias(biasConf);
133 hoptl.setTrajectory(gval, ybias);
135 ObsAuxIncr_ ybinc(biasConf);
137 ObsVector_ dy1(Test_::obspace()[jj]);
138 ObsVector_ dy2(Test_::obspace()[jj]);
139 GeoVaLs_ gv1(gconf, hoptl.variables());
140 GeoVaLs_ gv2(gconf, hoptl.variables());
143 BOOST_REQUIRE(dot_product(gv1, gv1) >
zero);
144 hoptl.simulateObsTL(gv1, dy1, ybinc);
145 BOOST_CHECK(dot_product(dy1, dy1) >
zero);
148 BOOST_REQUIRE(dot_product(dy2, dy2) >
zero);
150 hoptl.simulateObsAD(gv2, dy2, ybinc);
151 BOOST_CHECK(dot_product(gv2, gv2) >
zero);
153 const double zz1 = dot_product(gv1, gv2);
154 const double zz2 = dot_product(dy1, dy2);
157 << (zz1-zz2)/zz2 << std::endl;
159 BOOST_CHECK(zz1 !=
zero);
160 BOOST_CHECK(zz2 !=
zero);
161 BOOST_CHECK_CLOSE(zz1, zz2,
tol);
179 std::vector<eckit::LocalConfiguration>
conf;
180 obsconf.get(
"ObsTypes",
conf);
185 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
186 LinearObsOperator_ hoptl(Test_::obspace()[jj]);
187 ObsOperator_ hop(Test_::obspace()[jj]);
189 const eckit::LocalConfiguration gconf(
conf[jj],
"GeoVaLs");
190 Locations_ locs(Test_::obspace()[jj].locations(Test_::tbgn(), Test_::tend()));
192 eckit::LocalConfiguration biasConf;
193 conf[jj].get(
"ObsBias", biasConf);
194 const ObsAuxCtrl_ ybias(biasConf);
196 const ObsAuxIncr_ ybinc(biasConf);
198 ObsVector_ y1(Test_::obspace()[jj]);
199 ObsVector_ y2(Test_::obspace()[jj]);
200 ObsVector_ y3(Test_::obspace()[jj]);
202 GeoVaLs_ gv(gconf, hop.variables());
204 hoptl.setTrajectory(gv, ybias);
206 hop.simulateObs(gv, y1, ybias);
208 GeoVaLs_ dgv(gconf, hoptl.variables());
211 GeoVaLs_ gv0(gconf, hop.variables());
213 ObsVector_ y3_init(Test_::obspace()[jj]);
216 for (
int jter = 0; jter < iter; ++jter) {
221 hop.simulateObs(gv, y2, ybias);
223 hoptl.simulateObsTL(dgv, y3, ybinc);
225 double test_norm = y2.rms();
227 oops::Log::debug() <<
"Iter:" << jter <<
" ||(h(x+alpha*dx)-h(x))/h'(alpha*dx)||=" 228 << test_norm << std::endl;
230 BOOST_CHECK(y2.rms() <
tol);
244 boost::unit_test::test_suite * ts = BOOST_TEST_SUITE(
"interface/LinearObsOperator");
246 ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
247 ts->add(BOOST_TEST_CASE(&testLinearity<MODEL>));
248 ts->add(BOOST_TEST_CASE(&testTangentLinear<MODEL>));
249 ts->add(BOOST_TEST_CASE(&testAdjoint<MODEL>));
250 boost::unit_test::framework::master_test_suite().add(ts);
258 #endif // TEST_INTERFACE_LINEAROBSOPERATOR_H_ virtual ~LinearObsOperator()
void register_tests() const
static const eckit::Configuration & config()
real(double), parameter zero
std::string testid() const