8#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
9#include <doctest/doctest.h>
20const std::string filename =
"RectGrid_test.nc";
23TEST_SUITE_BEGIN(
"RectGrid");
24TEST_CASE(
"Write and read a ModelState-based RectGrid restart file")
27 grid.setIO(
new RectGridIO(grid));
32 double yFactor = 0.01;
33 double xFactor = 0.0001;
39 HField fractional(ModelArray::Type::H);
40 HField mask(ModelArray::Type::H);
41 for (
int j = 0; j < ny; ++j) {
42 for (
int i = 0; i < nx; ++i) {
43 fractional(i, j) = j * yFactor + i * xFactor;
44 mask(i, j) = (i - nx / 2)*(i - nx/2) + (j - ny / 2) * (j - ny / 2) > (nx * ny) ? 0 : 1;
48 HField hice = fractional + 1;
49 HField cice = fractional + 2;
50 HField sst = fractional + 3;
51 HField sss = fractional + 4;
52 HField hsnow = fractional + 5;
54 HField ticeValue = -(fractional + 1);
55 ZField tice = ModelArray::ZField();
56 tice.setData(ticeValue);
68 ModelMetadata metadata;
69 metadata.setTime(TimePoint(
"2000-01-01T00:00:00Z"));
71 grid.dumpModelState(state, metadata, filename);
75 RectangularGrid gridIn;
79 gridIn.setIO(
new RectGridIO(grid));
80 ModelState ms = gridIn.getModelState(filename);
84 REQUIRE(ms.data.at(
"hice")(targetX, targetY) != 0);
85 REQUIRE(ms.data.at(
"hice")(targetX, targetY) > 1);
86 REQUIRE(ms.data.at(
"hice")(targetX, targetY) < 2);
87 REQUIRE(ms.data.at(
"hice")(targetX, targetY) == 1.0703);
89 ZField ticeIn = ms.data.at(
"tice");
91 REQUIRE(ticeIn.dimensions()[2] == 1);
92 REQUIRE(ticeIn(targetX, targetY, 0U) == -1.0703);
94 std::remove(filename.c_str());
const MultiDim & dimensions() const
Returns a vector<size_t> of the size of each dimension of this type of ModelArray.
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.