11 #ifndef TEST_INTERFACE_STATE_H_ 
   12 #define TEST_INTERFACE_STATE_H_ 
   20 #define ECKIT_TESTING_SELF_REGISTER_CASES 0 
   22 #include <boost/noncopyable.hpp> 
   24 #include "eckit/config/LocalConfiguration.h" 
   25 #include "eckit/testing/Test.h" 
   31 #include "oops/util/DateTime.h" 
   32 #include "oops/util/dot_product.h" 
   33 #include "oops/util/Logger.h" 
   40 template <
typename MODEL> 
class StateFixture : 
private boost::noncopyable {
 
   55     return theStateFixture;
 
   65   ~StateFixture<MODEL>() {}
 
   67   std::unique_ptr<const eckit::LocalConfiguration>  
test_;
 
   77   const double norm = Test_::test().getDouble(
"norm file");
 
   78   const double tol = Test_::test().getDouble(
"tolerance");
 
   79   const util::DateTime vt(Test_::test().getString(
"date"));
 
   82   const eckit::LocalConfiguration conf(Test_::test(), 
"statefile");
 
   83   std::unique_ptr<State_> xx1(
new State_(Test_::resol(), conf));
 
   86   oops::Log::test() << 
"Printing State from yaml: " << *xx1 << std::endl;
 
   87   const double norm1 = xx1->norm();
 
   89   EXPECT(oops::is_close(norm1, norm, tol));
 
   90   EXPECT(xx1->validTime() == vt);
 
   93   std::unique_ptr<State_> xx2(
new State_(*xx1));
 
   95   EXPECT(oops::is_close(xx2->norm(), norm, tol));
 
   96   EXPECT(xx2->validTime() == vt);
 
  103   const double norm2 = xx1->norm();
 
  104   EXPECT(norm1 == norm2);
 
  108   State_ xx3(Test_::resol(), vars, vt);
 
  109   oops::Log::test() << 
"Printing empty State: " << xx3 << std::endl;
 
  110   EXPECT(xx3.norm() == 0);
 
  111   EXPECT(xx3.validTime() == vt);
 
  112   EXPECT(xx3.variables() == vars);
 
  115   State_ xx4(Test_::resol(), *xx1);
 
  116   EXPECT(oops::is_close(xx4.norm(), norm, tol));
 
  117   EXPECT(xx4.validTime() == vt);
 
  118   EXPECT(xx4.variables() == xx1->variables());
 
  130   const double norm = Test_::test().getDouble(
"norm file");
 
  131   const double tol = Test_::test().getDouble(
"tolerance");
 
  132   const util::DateTime vt(Test_::test().getString(
"date"));
 
  134   const eckit::LocalConfiguration conf(Test_::test(), 
"statefile");
 
  135   State_ xx1(Test_::resol(), conf);
 
  138   const Geometry_ & geometry = xx1.geometry();
 
  139   State_ xx2(geometry, conf);
 
  141   const double norm2 = xx2.norm();
 
  142   EXPECT(oops::is_close(norm2, norm, tol));
 
  175   if (!Test_::test().
has(
"state generate")) {
 
  176     oops::Log::warning() << 
"Bypassing Analytical Initial Condition Test";
 
  180   const eckit::LocalConfiguration confgen(Test_::test(), 
"state generate");
 
  181   const State_ xx(Test_::resol(), confgen);
 
  183   const double norm = Test_::test().getDouble(
"norm generated state");
 
  184   const double tol = Test_::test().getDouble(
"tolerance");
 
  186   oops::Log::debug() << 
"xx.norm(): " << std::fixed << std::setprecision(8) << xx.norm()
 
  188   oops::Log::debug() << 
"norm: " << std::fixed << std::setprecision(8) << norm << std::endl;
 
  190   EXPECT(oops::is_close(xx.norm(), norm, tol));
 
  209   const eckit::LocalConfiguration conf(Test_::test(), 
"statefile");
 
  210   State_ xx(Test_::resol(), conf);
 
  211   const double tol = Test_::test().getDouble(
"tolerance");
 
  215   EXPECT(xx.norm() == 0.0);
 
  218   const State_ yy(Test_::resol(), conf);
 
  219   const std::vector<double> mults {3.0, 0.0, -3.0};
 
  220   for (
const auto & mult : mults) {
 
  222     xx.accumul(mult, yy);
 
  223     EXPECT(oops::is_close(xx.norm(), std::abs(mult) * yy.norm(), tol));
 
  227   State_ zz(Test_::resol(), conf);
 
  229   EXPECT_NOT(oops::is_close(zz.norm(), yy.norm(), tol, 0, oops::TestVerbosity::SILENT));
 
  248   const eckit::LocalConfiguration conf(Test_::test(), 
"statefile");
 
  249   State_ xx(Test_::resol(), conf);
 
  252   const util::Duration onehour(3600);
 
  253   xx.updateTime(onehour);
 
  254   xx.updateTime(onehour);
 
  257   State_ yy(Test_::resol(), conf);
 
  260   const util::Duration twohours(7200);
 
  261   yy.updateTime(twohours);
 
  263   EXPECT(xx.validTime() == yy.validTime());
 
  266   xx.updateTime(onehour);
 
  267   EXPECT_NOT(xx.validTime() == yy.validTime());
 
  286   const eckit::LocalConfiguration conf(Test_::test(), 
"statefile");
 
  287   State_ xx(Test_::resol(), conf);
 
  288   const double tol = Test_::test().getDouble(
"tolerance");
 
  291   const double norm = xx.norm();
 
  300   EXPECT(xx.norm() == norm);
 
  302   if (Test_::test().
has(
"statefileout")) {
 
  304     const double mult = 2.0;
 
  305     xx.accumul(mult, xx);
 
  308     const double normout = xx.norm();
 
  311     const eckit::LocalConfiguration confout(Test_::test(), 
"statefileout");
 
  317     State_ yy(Test_::resol(), confout);
 
  320     EXPECT(oops::is_close(yy.norm(), normout, tol));
 
  323     EXPECT_NOT(oops::is_close(norm, normout, tol, 0, oops::TestVerbosity::SILENT));
 
  329 template <
typename MODEL>
 
  336   std::string 
testid()
 const override {
return "test::State<" + MODEL::name() + 
">";}
 
  339     std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
 
  341     ts.emplace_back(
CASE(
"interface/State/testStateConstructors")
 
  342       { testStateConstructors<MODEL>(); });
 
  343     ts.emplace_back(
CASE(
"interface/State/testStateGeometry")
 
  344       { testStateGeometry<MODEL>(); });
 
  345     ts.emplace_back(
CASE(
"interface/State/testStateAnalyticInitialCondition")
 
  346       { testStateAnalyticInitialCondition<MODEL>(); });
 
  347     ts.emplace_back(
CASE(
"interface/State/testStateZeroAndAccumul")
 
  348       { testStateZeroAndAccumul<MODEL>(); });
 
  349     ts.emplace_back(
CASE(
"interface/State/testStateDateTime")
 
  350                     { testStateDateTime<MODEL>(); });
 
  351     ts.emplace_back(
CASE(
"interface/State/testStateReadWrite")
 
  352       { testStateReadWrite<MODEL>(); });
 
Geometry class used in oops; subclass of interface class interface::Geometry.
 
State class used in oops; subclass of interface class interface::State.
 
static StateFixture< MODEL > & getInstance()
 
oops::State< MODEL > State_
 
static const eckit::Configuration & test()
 
static const Geometry_ & resol()
 
oops::Geometry< MODEL > Geometry_
 
std::unique_ptr< Geometry_ > resol_
 
std::unique_ptr< const eckit::LocalConfiguration > test_
 
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)
 
logical function has(this, var)
 
void testStateReadWrite()
Read and write tests.
 
void testStateDateTime()
validTime and updateTime tests
 
void testStateZeroAndAccumul()
Tests of zero and accumul.
 
void testStateGeometry()
Tests State::geometry() and Geometry copy constructors.
 
void testStateConstructors()
tests constructors and print method
 
CASE("test_linearmodelparameterswrapper_valid_name")
 
void testStateAnalyticInitialCondition()
Interpolation test.