-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathXiosCalendar_test.cpp
More file actions
81 lines (69 loc) · 2.8 KB
/
XiosCalendar_test.cpp
File metadata and controls
81 lines (69 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*!
* @author Joe Wallwork <jw2423@cam.ac.uk>
* @author Adeleke Bankole <ab3191@cam.ac.uk>
* @brief Tests for XIOS calendars
* @details
* This test is designed to test calendar functionality of the C++ interface
* for XIOS.
*/
#include <doctest/extensions/doctest_mpi.h>
#undef INFO
#include "StructureModule/include/ParametricGrid.hpp"
#include "include/Configurator.hpp"
#include "include/Finalizer.hpp"
#include "include/Model.hpp"
#include "include/ModelMPI.hpp"
#include "include/Xios.hpp"
namespace Nextsim {
/*!
* TestXiosCalendar
*
* This function tests the calendar functionality of the C++ interface for XIOS. It
* needs to be run with 1 rank i.e.,
*
* `mpirun -n 1 ./testXiosCalendar_MPI1`
*
*/
MPI_TEST_CASE("TestXiosCalendar", 1)
{
std::stringstream config;
config << "[model]" << std::endl;
config << "start = 2023-03-17T00:00:00Z" << std::endl;
config << "stop = 2023-03-17T00:00:00Z" << std::endl;
config << "time_step = P0-0T01:00:00" << std::endl;
config << "partition_file = xios_test_partition_metadata_1.nc" << std::endl;
std::unique_ptr<std::istream> pcstream(new std::stringstream(config.str()));
Configurator::addStream(std::move(pcstream));
// Create ModelMPI instance based off the test communicator
auto& modelMPI = ModelMPI::getInstance(test_comm);
// Create a Model and configure it so that time options are parsed
Model model;
model.configureTime();
// Get the Xios singleton instance and check it's initialized
// NOTE: The singleton is created when Xios::getInstance() is first called. In this test, this
// happens when the time sets set by ModelMetadata::setTime(). This occurs in the call to
// Model::configureTime() above.
Xios& xiosHandler = Xios::getInstance();
// --- Tests for calendar API
// Calendar start
REQUIRE(xiosHandler.getCalendarStart().format() == "2023-03-17T00:00:00Z"); // Set in config
TimePoint start("2023-03-18T00:00:00Z");
xiosHandler.setCalendarStart(start);
REQUIRE(start == xiosHandler.getCalendarStart());
REQUIRE(start.format() == "2023-03-18T00:00:00Z");
// Timestep
ModelMetadata& metadata = ModelMetadata::getInstance();
REQUIRE(metadata.stepLength().seconds() == 3600.0); // Read from config
// NOTE: Needs calling before Xios::getCurrentDate()
xiosHandler.close_context_definition();
// --- Tests for getCurrentDate method
REQUIRE(xiosHandler.getCalendarStep() == 0);
REQUIRE(xiosHandler.getCurrentDate().format() == "2023-03-18T00:00:00Z");
// -- Tests that the timestep is set up correctly
xiosHandler.setCalendarStep(1);
REQUIRE(xiosHandler.getCalendarStep() == 1);
REQUIRE(xiosHandler.getCurrentDate().format() == "2023-03-18T01:00:00Z");
xiosHandler.context_finalize();
Finalizer::finalize();
}
}