12 #ifndef TEST_INTERFACE_INCREMENT_H_
13 #define TEST_INTERFACE_INCREMENT_H_
21 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
23 #include <boost/noncopyable.hpp>
25 #include "atlas/field.h"
26 #include "eckit/config/LocalConfiguration.h"
27 #include "eckit/testing/Test.h"
34 #include "oops/util/DateTime.h"
35 #include "oops/util/dot_product.h"
36 #include "oops/util/Logger.h"
64 return theIncrementFixture;
74 const double tol_default = 1e-8;
76 time_.reset(
new util::DateTime(
test_->getString(
"date")));
79 oops::Log::warning() <<
80 "Warning: Increment norm tolerance greater than 1e-8 "
81 "may not be suitable for certain solvers." <<
86 ~IncrementFixture<MODEL>() {}
90 std::unique_ptr<const eckit::LocalConfiguration>
test_;
93 std::unique_ptr<util::DateTime>
time_;
104 Increment_ dx(Test_::resol(), Test_::ctlvars(), Test_::time());
105 oops::Log::test() <<
"Printing zero increment: " << dx << std::endl;
107 EXPECT(dx.norm() == 0.0);
116 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
118 oops::Log::test() <<
"Printing random increment: " << dx1 << std::endl;
120 EXPECT(dx1.norm() > 0.0);
123 EXPECT(dx2.norm() > 0.0);
127 EXPECT(dx2.norm() == 0.0);
136 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
138 EXPECT(dx1.norm() > 0.0);
141 Increment_ dx2(dx1,
true);
142 EXPECT(dx2.norm() == dx1.norm());
145 Increment_ dx3(dx1,
false);
146 EXPECT(dx3.norm() == 0.0);
156 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
157 Increment_ dx2(Test_::resol(), dx1);
160 EXPECT(dx2.norm() == dx1.norm());
169 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
171 Increment_ dx2(Test_::resol(), Test_::ctlvars(), Test_::time());
175 double dot1 = dx1.norm();
178 double dot2 = dx2.norm();
182 double dot3 = dx2.norm();
185 EXPECT(dot3 <= dot1 + dot2);
194 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
203 EXPECT(dx2.norm() < Test_::tolerance());
212 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
214 Increment_ dx2(Test_::resol(), Test_::ctlvars(), Test_::time());
218 double zz1 = dot_product(dx1, dx2);
219 double zz2 = dot_product(dx2, dx1);
230 Increment_ dx(Test_::resol(), Test_::ctlvars(), Test_::time());
232 EXPECT(dx.norm() > 0.0);
236 EXPECT(dx.norm() == 0.0);
237 EXPECT(dx.validTime() == Test_::time());
240 util::Duration onehour(3600);
241 util::DateTime newTime(Test_::time().toString());
247 EXPECT(dx.norm() == 0.0);
248 EXPECT(dx.validTime() == newTime);
257 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
268 EXPECT(dx2.norm() < Test_::tolerance());
279 bool skipTest = Test_::test().getBool(
"skip accum test",
false);
281 oops::Log::warning() <<
"Skipping Increment.accum test";
286 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
289 Increment_ dx2(Test_::resol(), Test_::ctlvars(), Test_::time());
292 Increment_ diff(dx1);
294 EXPECT(diff.norm() != 0.0);
297 State_ x(Test_::resol(), Test_::ctlvars(), Test_::time());
313 EXPECT(diff.norm() != 0.0);
318 EXPECT(diff.norm() == 0.0);
328 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
331 util::DateTime tt(Test_::time() + util::Duration(
"PT15H"));
332 Increment_ dx2(Test_::resol(), Test_::ctlvars(), tt);
335 std::vector<double> vect;
337 EXPECT(vect.size() == dx1.serialSize());
340 dx2.deserialize(vect, index);
341 EXPECT(index == dx1.serialSize());
342 EXPECT(index == dx2.serialSize());
345 EXPECT(vect.size() == dx1.serialSize() * 2);
347 if (dx1.serialSize() > 0) {
348 EXPECT(dx1.norm() > 0.0);
349 EXPECT(dx2.norm() > 0.0);
350 EXPECT(dx2.validTime() == Test_::time());
353 EXPECT(dx2.norm() == 0.0);
363 if (Test_::skipAtlas() == 0) {
365 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
370 std::unique_ptr<atlas::FieldSet> atlasFieldSet(
new atlas::FieldSet());
373 dx1.setAtlas(atlasFieldSet.get());
374 dx1.toAtlas(atlasFieldSet.get());
376 dx1.fromAtlas(atlasFieldSet.get());
378 EXPECT(dx2.norm() == 0.0);
390 bool skipTest = Test_::test().getBool(
"skip diff test",
false);
392 oops::Log::warning() <<
"Skipping Increment.diff test";
397 State_ x1(Test_::resol(), Test_::ctlvars(), Test_::time());
398 State_ x2(Test_::resol(), Test_::ctlvars(), Test_::time());
401 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
404 Increment_ dx2(Test_::resol(), Test_::ctlvars(), Test_::time());
408 Increment_ diff1(dx1);
409 Increment_ diff2(Test_::resol(), Test_::ctlvars(), Test_::time());
411 EXPECT(diff1.norm() != 0.0);
423 EXPECT(diff1.norm() == diff2.norm());
433 Increment_ dx(Test_::resol(), Test_::ctlvars(), Test_::time());
436 util::Duration onehour(3600);
437 dx.updateTime(onehour);
440 util::DateTime newTime(Test_::time().toString());
442 EXPECT(dx.validTime() == newTime);
452 Increment_ dx1(Test_::resol(), Test_::ctlvars(), Test_::time());
455 EXPECT(dx1.norm() == dx2.norm());
458 dx1.schur_product_with(dx2);
461 EXPECT(dx1.norm() != dx2.norm());
466 dx1.schur_product_with(dx2);
467 EXPECT(dx1.norm() == 0.0);
471 Increment_ dx1in(dx1);
473 dx1.schur_product_with(dx2);
474 EXPECT(dx1.norm() == dx1in.norm());
479 template <
typename MODEL>
486 std::string
testid()
const override {
return "test::Increment<" + MODEL::name() +
">";}
489 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
491 ts.emplace_back(
CASE(
"interface/Increment/testIncrementConstructor")
492 { testIncrementConstructor<MODEL>(); });
493 ts.emplace_back(
CASE(
"interface/Increment/testIncrementCopyConstructor")
494 { testIncrementCopyConstructor<MODEL>(); });
495 ts.emplace_back(
CASE(
"interface/Increment/testIncrementCopyBoolConstructor")
496 { testIncrementCopyBoolConstructor<MODEL>(); });
497 ts.emplace_back(
CASE(
"interface/Increment/testIncrementChangeResConstructor")
498 { testIncrementChangeResConstructor<MODEL>(); });
499 ts.emplace_back(
CASE(
"interface/Increment/testIncrementTriangle")
500 { testIncrementTriangle<MODEL>(); });
501 ts.emplace_back(
CASE(
"interface/Increment/testIncrementOpPlusEq")
502 { testIncrementOpPlusEq<MODEL>(); });
503 ts.emplace_back(
CASE(
"interface/Increment/testIncrementDotProduct")
504 { testIncrementDotProduct<MODEL>(); });
505 ts.emplace_back(
CASE(
"interface/Increment/testIncrementAxpy")
506 { testIncrementAxpy<MODEL>(); });
507 ts.emplace_back(
CASE(
"interface/Increment/testIncrementAccum")
508 { testIncrementAccum<MODEL>(); });
509 ts.emplace_back(
CASE(
"interface/Increment/testIncrementDiff")
510 { testIncrementDiff<MODEL>(); });
511 ts.emplace_back(
CASE(
"interface/Increment/testIncrementZero")
512 { testIncrementZero<MODEL>(); });
513 ts.emplace_back(
CASE(
"interface/Increment/testIncrementTime")
514 { testIncrementTime<MODEL>(); });
515 ts.emplace_back(
CASE(
"interface/Increment/testIncrementSchur")
516 { testIncrementSchur<MODEL>(); });
517 ts.emplace_back(
CASE(
"interface/Increment/testIncrementSerialize")
518 { testIncrementSerialize<MODEL>(); });
519 ts.emplace_back(
CASE(
"interface/Increment/testIncrementAtlas")
520 { testIncrementAtlas<MODEL>(); });
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
State class used in oops; subclass of interface class interface::State.
std::unique_ptr< bool > skipAccumTest_
static const eckit::Configuration & test()
static const double & tolerance()
static const int & skipAtlas()
static IncrementFixture< MODEL > & getInstance()
std::unique_ptr< const eckit::LocalConfiguration > test_
static const Geometry_ & resol()
std::unique_ptr< Geometry_ > resol_
std::unique_ptr< bool > skipDiffTest_
static const oops::Variables & ctlvars()
static const util::DateTime & time()
std::unique_ptr< oops::Variables > ctlvars_
std::unique_ptr< util::DateTime > time_
oops::Geometry< MODEL > Geometry_
std::string testid() const override
void clear() const override
void register_tests() const override
static const eckit::Configuration & config()
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
void testIncrementCopyBoolConstructor()
void testIncrementChangeResConstructor()
void testIncrementSchur()
void testIncrementSerialize()
void testIncrementCopyConstructor()
void testIncrementTriangle()
void testIncrementAccum()
void testIncrementOpPlusEq()
void testIncrementDotProduct()
void testIncrementConstructor()
tests Increment constructor and print method
void testIncrementAtlas()
CASE("test_linearmodelparameterswrapper_valid_name")