11 #ifndef TEST_INTERFACE_LINEARMODEL_H_ 12 #define TEST_INTERFACE_LINEARMODEL_H_ 22 #define BOOST_TEST_NO_MAIN 23 #define BOOST_TEST_ALTERNATIVE_INIT_API 24 #define BOOST_TEST_DYN_LINK 26 #include <boost/noncopyable.hpp> 27 #include <boost/scoped_ptr.hpp> 28 #include <boost/test/unit_test.hpp> 30 #include "eckit/config/LocalConfiguration.h" 46 #include "oops/util/DateTime.h" 47 #include "oops/util/dot_product.h" 48 #include "oops/util/Duration.h" 80 return theLinearModelFixture;
85 const util::Duration
len(
test_->getString(
"fclength"));
102 time_.reset(
new util::DateTime(
xref_->validTime()));
105 oops::instantiateCovarFactory<MODEL>();
113 oops::instantiateTlmFactory<MODEL>();
114 boost::ptr_vector<LinearModel_> tlmvec;
121 tlm_.reset(tlmvec.release(tlmvec.begin()).
release());
126 boost::scoped_ptr<const eckit::LocalConfiguration>
test_;
127 boost::scoped_ptr<const eckit::LocalConfiguration>
tlConf_;
128 boost::scoped_ptr<const Geometry_>
resol_;
129 boost::scoped_ptr<const util::DateTime>
time_;
131 boost::scoped_ptr<const State_>
xref_;
133 boost::scoped_ptr<const ModelAux_>
bias_;
134 boost::scoped_ptr<const ModelAuxIncr_>
dbias_;
135 boost::scoped_ptr<const Covariance_>
B_;
136 boost::scoped_ptr<const LinearModel_>
tlm_;
144 const util::Duration
zero(0);
156 const util::Duration
zero(0);
158 Increment_ dxref(Test_::resol(), Test_::ctlvars(),
vt);
159 Test_::covariance().randomize(dxref);
160 ModelAuxIncr_ daux(Test_::dbias());
161 const double ininorm = dxref.norm();
162 BOOST_CHECK(ininorm > 0.0);
164 Increment_ dx(Test_::resol(), Test_::ctlvars(),
vt);
165 Increment_ dxm(Test_::resol(),
Test_::tlm().variables(),
vt);
169 BOOST_CHECK_EQUAL(dx.validTime(),
vt);
170 BOOST_CHECK_EQUAL(dx.norm(), ininorm);
176 BOOST_CHECK_EQUAL(dx.validTime(),
vt);
177 BOOST_CHECK_EQUAL(dx.norm(), ininorm);
189 const util::DateTime
t2(
t1 +
len);
190 BOOST_CHECK(
t2 >
t1);
192 Increment_ dx(Test_::resol(),
Test_::tlm().variables(),
t1);
193 ModelAuxIncr_ daux(Test_::dbias());
197 BOOST_CHECK_EQUAL(dx.norm(), 0.0);
199 BOOST_CHECK_EQUAL(dx.validTime(),
t2);
200 BOOST_CHECK_EQUAL(dx.norm(), 0.0);
204 BOOST_CHECK_EQUAL(dx.norm(), 0.0);
206 BOOST_CHECK_EQUAL(dx.validTime(),
t1);
207 BOOST_CHECK_EQUAL(dx.norm(), 0.0);
219 const util::DateTime
t2(
t1 +
len);
220 BOOST_CHECK(
t2 >
t1);
221 const double zz = 3.1415;
223 Increment_ dx1(Test_::resol(),
Test_::tlm().variables(),
t1);
224 Test_::covariance().randomize(dx1);
225 ModelAuxIncr_ daux1(Test_::dbias());
226 BOOST_CHECK(dx1.norm() > 0.0);
229 ModelAuxIncr_ daux2(daux1);
232 BOOST_CHECK_EQUAL(dx1.validTime(),
t2);
239 BOOST_CHECK_EQUAL(dx2.validTime(),
t2);
242 BOOST_CHECK_CLOSE(dx1.norm(), dx2.norm(),
tol);
254 const util::DateTime
t2(
t1 +
len);
255 BOOST_CHECK(
t2 >
t1);
257 Increment_ dx0(Test_::resol(),
Test_::tlm().variables(),
t1);
258 Test_::covariance().randomize(dx0);
259 BOOST_CHECK(dx0.norm() > 0.0);
263 const double dxnorm = dx.norm();
266 State_ xx0(Test_::xref());
275 std::vector<double> errors;
276 for (
unsigned int jtest = 0; jtest <
ntest; ++jtest) {
277 State_ xx(Test_::xref());
278 Increment_ pert(dx0);
283 Increment_ diff(Test_::resol(),
Test_::tlm().variables(),
t2);
285 const double difnorm = diff.norm();
286 const double err = zz * dxnorm / difnorm;
290 const double errnorm = derr.norm();
291 errors.push_back(errnorm / difnorm);
293 <<
", relative error = " << errnorm / difnorm << std::endl;
298 const double approx = *std::min_element(errors.begin(), errors.end());
301 BOOST_CHECK(approx <
tol);
313 const util::DateTime
t2(
t1 +
len);
314 BOOST_CHECK(
t2 >
t1);
316 Increment_ dx11(Test_::resol(),
Test_::tlm().variables(),
t1);
317 Test_::covariance().randomize(dx11);
318 ModelAuxIncr_ daux1(Test_::dbias());
319 BOOST_CHECK(dx11.norm() > 0.0);
320 Increment_ dx12(dx11);
322 BOOST_CHECK(dx12.norm() > 0.0);
324 Increment_ dx22(Test_::resol(),
Test_::tlm().variables(),
t2);
325 Test_::covariance().randomize(dx22);
326 ModelAuxIncr_ daux2(Test_::dbias());
327 BOOST_CHECK(dx22.norm() > 0.0);
328 Increment_ dx21(dx22);
330 BOOST_CHECK(dx21.norm() > 0.0);
332 BOOST_CHECK(dx11.norm() != dx22.norm());
333 BOOST_CHECK_EQUAL(dx11.validTime(),
t1);
334 BOOST_CHECK_EQUAL(dx21.validTime(),
t1);
335 BOOST_CHECK_EQUAL(dx12.validTime(),
t2);
336 BOOST_CHECK_EQUAL(dx22.validTime(),
t2);
338 const double dot1 = dot_product(dx11, dx21);
339 const double dot2 = dot_product(dx12, dx22);
341 BOOST_CHECK_CLOSE(dot1, dot2,
tol);
354 boost::unit_test::test_suite * ts = BOOST_TEST_SUITE(
"interface/LinearModel");
356 ts->add(BOOST_TEST_CASE(&testLinearModelConstructor<MODEL>));
357 ts->add(BOOST_TEST_CASE(&testLinearModelZeroLength<MODEL>));
358 ts->add(BOOST_TEST_CASE(&testLinearModelZeroPert<MODEL>));
359 ts->add(BOOST_TEST_CASE(&testLinearModelLinearity<MODEL>));
360 ts->add(BOOST_TEST_CASE(&testLinearApproximation<MODEL>));
361 ts->add(BOOST_TEST_CASE(&testLinearModelAdjoint<MODEL>));
362 boost::unit_test::framework::master_test_suite().add(ts);
370 #endif // TEST_INTERFACE_LINEARMODEL_H_ boost::scoped_ptr< const eckit::LocalConfiguration > test_
static const ModelAuxIncr_ & dbias()
void testLinearApproximation()
oops::ModelAuxIncrement< MODEL > ModelAuxIncr_
static const eckit::Configuration & test()
boost::scoped_ptr< const ModelAuxIncr_ > dbias_
oops::Increment< MODEL > Increment_
boost::scoped_ptr< const util::DateTime > time_
boost::scoped_ptr< const oops::Variables > ctlvars_
void testLinearModelLinearity()
static const State_ & xref()
Encapsulates the model state.
Save trajectory during forecast run.
static const eckit::Configuration & config()
boost::scoped_ptr< const Geometry_ > resol_
oops::ModelAuxControl< MODEL > ModelAux_
boost::scoped_ptr< const ModelAux_ > bias_
real(double), parameter zero
real, dimension(:,:,:), allocatable vt
oops::ModelSpaceCovarianceBase< MODEL > Covariance_
static const Geometry_ & resol()
void register_tests() const
static const Model_ & model()
std::string testid() const
static const LinearModel_ & tlm()
Control model post processing.
void testLinearModelZeroLength()
oops::Model< MODEL > Model_
Encapsulates the nonlinear forecast model.
Abstract base class for model space error covariances.
static const ModelAux_ & bias()
boost::scoped_ptr< const eckit::LocalConfiguration > tlConf_
void testLinearModelAdjoint()
oops::Geometry< MODEL > Geometry_
oops::State< MODEL > State_
boost::scoped_ptr< const State_ > xref_
Increment Class: Difference between two states.
boost::scoped_ptr< const Covariance_ > B_
static const oops::Variables & ctlvars()
boost::scoped_ptr< const LinearModel_ > tlm_
oops::LinearModel< MODEL > LinearModel_
Control model post processing.
void testLinearModelZeroPert()
void testLinearModelConstructor()
static const util::DateTime & time()
static const Covariance_ & covariance()
Encapsulates the linear forecast model.
boost::scoped_ptr< const Model_ > model_
void enrollProcessor(PostBase_ *pp)
static LinearModelFixture< MODEL > & getInstance()