8#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
9#include <doctest/doctest.h>
22const std::string stateFilename =
"modelState.test.nc";
24TEST_SUITE_BEGIN(
"DevGrid");
25TEST_CASE(
"Write and read a ModelState-based DevGrid restart file")
28 grid.setIO(
new DevGridIO(grid));
31 size_t nx = DevGrid::nx;
32 size_t ny = DevGrid::nx;
33 double yFactor = 0.01;
34 double xFactor = 0.0001;
40 HField fractional(ModelArray::Type::H);
41 HField mask(ModelArray::Type::H);
42 for (
int j = 0; j < ny; ++j) {
43 for (
int i = 0; i < nx; ++i) {
44 fractional(i, j) = j * yFactor + i * xFactor;
45 mask(i, j) = (i + j) % 2;
49 HField hice = fractional + 1;
50 HField cice = fractional + 2;
51 HField sst = fractional + 3;
52 HField sss = fractional + 4;
53 HField hsnow = fractional + 5;
55 HField ticeValue = -(fractional + 1);
56 ZField tice = ModelArray::ZField();
57 tice.setData(ticeValue);
69 ModelMetadata metadata;
70 metadata.setTime(TimePoint(
"2000-01-01T00:00:00Z"));
72 grid.dumpModelState(state, metadata, stateFilename);
80 gridIn.setIO(
new DevGridIO(grid));
81 ModelState ms = gridIn.getModelState(stateFilename);
85 REQUIRE(ms.data.at(
"hice")(targetX, targetY) != 0);
86 REQUIRE(ms.data.at(
"hice")(targetX, targetY) > 1);
87 REQUIRE(ms.data.at(
"hice")(targetX, targetY) < 2);
88 REQUIRE(ms.data.at(
"hice")(targetX, targetY) == 1.0703);
90 ZField ticeIn = ms.data.at(
"tice");
92 REQUIRE(ticeIn.dimensions()[2] == 1);
93 REQUIRE(ticeIn(targetX, targetY, 0U) == -1.0703);
95 std::remove(stateFilename.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.