8 #ifndef TEST_IODA_OBSSPACEINDEXRECNUM_H_
9 #define TEST_IODA_OBSSPACEINDEXRECNUM_H_
16 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
18 #include <boost/noncopyable.hpp>
19 #include <boost/shared_ptr.hpp>
21 #include "eckit/config/LocalConfiguration.h"
22 #include "eckit/testing/Test.h"
24 #include "oops/mpi/mpi.h"
25 #include "oops/runs/Test.h"
26 #include "oops/test/TestEnvironment.h"
28 #include "ioda/distribution/Accumulator.h"
29 #include "ioda/IodaTrait.h"
37 class ObsSpaceTestFixture :
private boost::noncopyable {
45 for (
auto &space : spaces) {
54 return theObsSpaceTestFixture;
58 util::DateTime bgn(::test::TestEnvironment::config().getString(
"window begin"));
59 util::DateTime end(::test::TestEnvironment::config().getString(
"window end"));
61 std::vector<eckit::LocalConfiguration> conf;
62 ::test::TestEnvironment::config().get(
"observations", conf);
64 for (std::size_t jj = 0; jj < conf.size(); ++jj) {
65 eckit::LocalConfiguration obsconf(conf[jj],
"obs space");
67 obsparams.validateAndDeserialize(obsconf);
68 boost::shared_ptr<ioda::ObsSpace> tmp(
new ioda::ObsSpace(obsparams, oops::mpi::world(),
69 bgn, end, oops::mpi::myself()));
76 std::vector<boost::shared_ptr<ioda::ObsSpace> >
ospaces_;
82 typedef ObsSpaceTestFixture Test_;
84 std::vector<eckit::LocalConfiguration> conf;
85 ::test::TestEnvironment::config().get(
"observations", conf);
87 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
89 eckit::LocalConfiguration testConfig;
90 conf[jj].get(
"test data", testConfig);
91 oops::Log::debug() <<
"Test data configuration: " << testConfig << std::endl;
93 const ObsSpace &odb = Test_::obspace(jj);
96 std::size_t GlobalNlocs = odb.globalNumLocs();
98 std::size_t Nvars = odb.
nvars();
99 bool ObsAreSorted = odb.obsAreSorted();
102 std::size_t ExpectedGlobalNlocs = testConfig.getUnsigned(
"nlocs");
103 std::size_t ExpectedNvars = testConfig.getUnsigned(
"nvars");
104 bool ExpectedObsAreSorted = testConfig.getBool(
"obs are sorted");
106 oops::Log::debug() <<
"GlobalNlocs, ExpectedGlobalNlocs: " << GlobalNlocs <<
", "
107 << ExpectedGlobalNlocs << std::endl;
108 oops::Log::debug() <<
"Nvars, ExpectedNvars: " << Nvars <<
", "
109 << ExpectedNvars << std::endl;
110 oops::Log::debug() <<
"ObsAreSorted, ExpectedObsAreSorted: " << ObsAreSorted <<
", "
111 << ExpectedObsAreSorted << std::endl;
113 EXPECT(GlobalNlocs == ExpectedGlobalNlocs);
115 EXPECT(Nvars == ExpectedNvars);
116 EXPECT(ObsAreSorted == ExpectedObsAreSorted);
119 if (odb.distribution()->
name() !=
"Halo") {
120 std::size_t Nrecs = 0;
121 std::set<std::size_t> recIndices;
122 auto accumulator = odb.distribution()->createAccumulator<std::size_t>();
123 for (std::size_t loc = 0; loc <
Nlocs; ++loc) {
124 if (
bool isNewRecord = recIndices.insert(odb.recnum()[loc]).second) {
125 accumulator->addTerm(loc, 1);
129 const size_t ExpectedNrecs = odb.nrecs();
130 EXPECT_EQUAL(Nrecs, ExpectedNrecs);
133 std::size_t GlobalNrecs = accumulator->computeResult();
134 std::size_t ExpectedGlobalNrecs = testConfig.getUnsigned(
"nrecs");
135 EXPECT_EQUAL(GlobalNrecs, ExpectedGlobalNrecs);
145 std::vector<eckit::LocalConfiguration> conf;
146 ::test::TestEnvironment::config().get(
"observations", conf);
148 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
150 eckit::LocalConfiguration testConfig;
151 conf[jj].get(
"test data", testConfig);
152 oops::Log::debug() <<
"Test data configuration: " << testConfig << std::endl;
155 std::vector<std::size_t> Index = Test_::obspace(jj).index();
156 std::vector<std::size_t> Recnum = Test_::obspace(jj).recnum();
160 int MyMpiSize = Test_::obspace(jj).comm().
size();
161 int MyMpiRank = Test_::obspace(jj).comm().rank();
163 std::string MyPath =
"mpi size" + std::to_string(MyMpiSize) +
164 ".rank" + std::to_string(MyMpiRank);
165 std::vector<std::size_t> ExpectedIndex = testConfig.getUnsignedVector(MyPath +
".index");
166 std::vector<std::size_t> ExpectedRecnum = testConfig.getUnsignedVector(MyPath +
".recnum");
167 eckit::LocalConfiguration recidxTestConfig;
168 testConfig.get(MyPath +
".recidx", recidxTestConfig);
170 oops::Log::debug() <<
"Index, ExpectedIndex: " << Index <<
", "
171 << ExpectedIndex << std::endl;
172 oops::Log::debug() <<
"Recnum, ExpectedRecnum: " << Recnum <<
", "
173 << ExpectedRecnum << std::endl;
175 EXPECT(Index == ExpectedIndex);
176 EXPECT(Recnum == ExpectedRecnum);
179 oops::Log::debug() <<
"recidxTestConfig: " << recidxTestConfig << std::endl;
180 std::vector<std::size_t> RecIdxRecNums = Test_::obspace(jj).recidx_all_recnums();
181 for (std::size_t i = 0; i < RecIdxRecNums.size(); ++i) {
182 std::size_t RecNum = RecIdxRecNums[i];
183 std::string TestConfigKey =
"rec" + std::to_string(RecNum);
184 std::vector<std::size_t> ExpectedRecIdxVector =
185 recidxTestConfig.getUnsignedVector(TestConfigKey);
186 std::vector<std::size_t> RecIdxVector = Test_::obspace(jj).recidx_vector(RecNum);
188 oops::Log::debug() <<
"RecIdxVector, ExpectedRecIdxVector: "
189 << RecIdxVector <<
", " << ExpectedRecIdxVector << std::endl;
190 EXPECT(RecIdxVector == ExpectedRecIdxVector);
200 typedef ObsSpaceTestFixture Test_;
212 std::string
testid()
const override {
return "test::ObsSpaceIndexRecnum<ioda::IodaTrait>";}
215 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
217 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testConstructor")
219 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testIndexRecnum")
221 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testCleanup")
std::string testid() const override
void clear() const override
virtual ~ObsSpaceIndexRecnum()
void register_tests() const override
std::vector< boost::shared_ptr< ioda::ObsSpace > > ospaces_
static ioda::ObsSpace & obspace(const std::size_t ii)
static ObsSpaceTestFixture & getInstance()
static std::size_t size()
CASE("Derived variable, unit conversion, and exception checking methods")