Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions core/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ Model::Model()

Model::~Model() { }

void Model::configureTime()
{
ModelMetadata& metadata = ModelMetadata::getInstance();

// Start/stop times. Run length will override stop time, if present.
std::string startTimeStr
= Configured::getConfiguration(keyMap.at(STARTTIME_KEY), std::string());
std::string stopTimeStr = Configured::getConfiguration(keyMap.at(STOPTIME_KEY), std::string());
std::string runLengthStr
= Configured::getConfiguration(keyMap.at(RUNLENGTH_KEY), std::string());
std::string stepStr = Configured::getConfiguration(keyMap.at(TIMESTEP_KEY), std::string());

if (runLengthStr.empty()) {
if (stopTimeStr.empty()) {
throw std::invalid_argument(std::string("At least one of ") + keyMap.at(STOPTIME_KEY)
+ " or " + keyMap.at(RUNLENGTH_KEY) + " must be set");
} else {
metadata.setTimes(startTimeStr, TimePoint(stopTimeStr), stepStr);
}
} else {
metadata.setTimes(startTimeStr, Duration(runLengthStr), stepStr);
}
iterator.setStartStopStep(metadata.startTime(), metadata.stopTime(), metadata.stepLength());
}

void Model::configure()
{
// Configure logging
Expand All @@ -76,25 +101,7 @@ void Model::configure()
auto& metadata = ModelMetadata::getInstance();
#endif

// Start/stop times. Run length will override stop time, if present.
std::string startTimeStr
= Configured::getConfiguration(keyMap.at(STARTTIME_KEY), std::string());
std::string stopTimeStr = Configured::getConfiguration(keyMap.at(STOPTIME_KEY), std::string());
std::string runLengthStr
= Configured::getConfiguration(keyMap.at(RUNLENGTH_KEY), std::string());
std::string stepStr = Configured::getConfiguration(keyMap.at(TIMESTEP_KEY), std::string());

if (runLengthStr.empty()) {
if (stopTimeStr.empty()) {
throw std::invalid_argument(std::string("At least one of ") + keyMap.at(STOPTIME_KEY)
+ " or " + keyMap.at(RUNLENGTH_KEY) + " must be set");
} else {
metadata.setTimes(startTimeStr, TimePoint(stopTimeStr), stepStr);
}
} else {
metadata.setTimes(startTimeStr, Duration(runLengthStr), stepStr);
}
iterator.setStartStopStep(metadata.startTime(), metadata.stopTime(), metadata.stepLength());
configureTime();

ModelState initialState(StructureFactory::stateFromFile(initialFileName));

Expand Down
57 changes: 6 additions & 51 deletions core/src/Xios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ bool Xios::doOnce()
return true;
}

//! Get the configuration for the XIOS handler
ConfigMap Xios::getConfig() const { return ConfigMap(); }

Xios::HelpMap& Xios::getHelpText(HelpMap& map, bool getAll)
{
map["Xios"] = {
Expand Down Expand Up @@ -217,40 +214,6 @@ void Xios::configure()
istringstream(Configured::getConfiguration(keyMap.at(ENABLED_KEY), std::string()))
>> std::boolalpha >> isEnabled;

// Extract the start time from the model configuration
// TODO: Deduce from Model.iterator rather than duplicating here?
std::string startTimeStr;
istringstream(Configured::getConfiguration(keyMap.at(STARTTIME_KEY), std::string()))
>> startTimeStr;
if (startTimeStr.length() == 0) {
Logged::warning("Xios: Setting default start: 1970-01-01T00:00:00Z");
startTimeStr = "1970-01-01T00:00:00Z";
}
startTime = TimePoint(startTimeStr);

// Extract the timestep from the model configuration
// TODO: Deduce from Model.iterator rather than duplicating here?
std::string timeStepStr;
istringstream(Configured::getConfiguration(keyMap.at(TIME_STEP_KEY), std::string()))
>> timeStepStr;
if (timeStepStr.length() == 0) {
Logged::warning("Xios: Setting default time_step: P0-0T01:00:00");
timeStepStr = "P0-0T01:00:00";
}
timestep = Duration(timeStepStr);

// Extract the stop time from the model configuration
// TODO: Deduce from Model.iterator rather than duplicating here?
std::string stopTimeStr;
istringstream(Configured::getConfiguration(keyMap.at(STOPTIME_KEY), std::string()))
>> stopTimeStr;
if (stopTimeStr.length() == 0) {
Logged::warning("Xios: Setting default stop: start time plus P0-0T01:00:00");
stopTime = startTime + timestep;
} else {
stopTime = TimePoint(stopTimeStr);
}

if (isEnabled) {
configureServer();
}
Expand All @@ -275,15 +238,17 @@ void Xios::configureServer()
// Initialize calendar wrapper for 'nextSIM-DG' context
cxios_get_current_calendar_wrapper(&clientCalendar);
cxios_set_calendar_wrapper_type(clientCalendar, calendarType.c_str(), calendarType.length());
cxios_set_calendar_wrapper_timestep(clientCalendar, convertDurationToXios(timestep));
ModelMetadata& metadata = ModelMetadata::getInstance();
cxios_set_calendar_wrapper_timestep(
clientCalendar, convertDurationToXios(metadata.stepLength()));
cxios_create_calendar(clientCalendar);
cxios_update_calendar_timestep(clientCalendar);

// Set default calendar origin
setCalendarOrigin(TimePoint("1970-01-01T00:00:00Z")); // Unix epoch

// Set start time from configuration file
setCalendarStart(TimePoint(startTime));
setCalendarStart(metadata.startTime());
}

/*!
Expand Down Expand Up @@ -413,17 +378,6 @@ void Xios::setCalendarStart(const TimePoint start)
cxios_set_calendar_wrapper_date_start_date(clientCalendar, datetime);
}

/*!
* Set calendar timestep
*
* @param timestep
*/
void Xios::setCalendarTimestep(const Duration timestep)
{
cxios_set_calendar_wrapper_timestep(clientCalendar, convertDurationToXios(timestep));
cxios_update_calendar_timestep(clientCalendar);
}

/*!
* Update XIOS calendar iteration/step number to some value
*
Expand Down Expand Up @@ -1412,7 +1366,8 @@ void Xios::createFile(const std::string fileId)
// TODO: Account for diagnostics (#917)
}
if (periodStr.length() == 0 || periodStr == "0") {
setFileOutputFreq(fileId, stopTime - startTime);
ModelMetadata& metadata = ModelMetadata::getInstance();
setFileOutputFreq(fileId, metadata.runLength());
} else {
setFileOutputFreq(fileId, Duration(periodStr));
}
Expand Down
1 change: 1 addition & 0 deletions core/src/include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Model : public Configured<Model> {
// environment and configuration to the model
~Model(); // Finalize the model. Collect data and so on.

void configureTime();
void configure() override;

enum {
Expand Down
5 changes: 0 additions & 5 deletions core/src/include/Xios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Xios : public Configured<Xios> {
};

/* Help config */
ConfigMap getConfig() const;
static HelpMap& getHelpText(HelpMap& map, bool getAll);
static HelpMap& getHelpRecursive(HelpMap& map, bool getAll);

Expand All @@ -78,7 +77,6 @@ class Xios : public Configured<Xios> {
void setCalendarType(const std::string type);
void setCalendarOrigin(const TimePoint origin);
void setCalendarStart(const TimePoint start);
void setCalendarTimestep(const Duration timestep);
void setCalendarStep(const int stepNumber);
void incrementCalendar();
std::string getCalendarType();
Expand Down Expand Up @@ -168,9 +166,6 @@ class Xios : public Configured<Xios> {

/* Calendar, date and duration */
std::string calendarType;
Duration timestep;
TimePoint startTime;
TimePoint stopTime;
xios::CCalendarWrapper* clientCalendar;
std::string convertXiosDatetimeToString(const cxios_date datetime, const bool isoFormat = true);
cxios_date convertStringToXiosDatetime(const std::string datetime, const bool isoFormat = true);
Expand Down
2 changes: 1 addition & 1 deletion core/src/include/indexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Indexer {
/*!
* @brief Produces a one-dimensional index of an array given a multi-dimensional location.
*
* @detail Given the dimensions of a mulit-dimensional array and a vector of positions across those
* @details Given the dimensions of a mulit-dimensional array and a vector of positions across those
* dimensions, this function returns the corresponding index of that location within the flattened,
* one-dimensional representation of the array, as it would typically be stored in memory, or when
* a multi-dimensional spatial array is flattened into a single logical dimension.
Expand Down
61 changes: 53 additions & 8 deletions core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,54 +136,91 @@ if(ENABLE_MPI)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/xios_test_mask.cdl
)
add_custom_target(generate_xios_masks ALL DEPENDS xios_test_mask.nc)
add_custom_command(
OUTPUT xios_test_partition_metadata_1.nc
COMMAND
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 1 decomp -m mask -o xy
-g xios_test_mask.nc --output-prefix xios_test
DEPENDS xios_test_mask.nc
)
add_custom_command(
OUTPUT xios_test_partition_metadata_2.nc
COMMAND
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 decomp -m mask -o xy
-g xios_test_mask.nc --output-prefix xios_test
DEPENDS xios_test_mask.nc
)
add_custom_command(
OUTPUT xios_test_partition_metadata_3.nc
COMMAND
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 3 decomp -m mask -o xy
-g xios_test_mask.nc --output-prefix xios_test
DEPENDS xios_test_mask.nc
)
add_custom_target(generate_xios_partition_metadata ALL
DEPENDS xios_test_partition_metadata_2.nc
DEPENDS
xios_test_partition_metadata_1.nc
xios_test_partition_metadata_2.nc
xios_test_partition_metadata_3.nc
)

add_executable(testXiosCalendar_MPI1 "XiosCalendar_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosCalendar_MPI1 PRIVATE USE_XIOS)
target_include_directories(
testXiosCalendar_MPI1
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosCalendar_MPI1 PRIVATE nextsimlib doctest::doctest)

add_executable(testXiosAxis_MPI3 "XiosAxis_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosAxis_MPI3 PRIVATE USE_XIOS)
target_include_directories(
testXiosAxis_MPI3
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosAxis_MPI3 PRIVATE nextsimlib doctest::doctest)

add_executable(testXiosGrid_MPI2 "XiosGrid_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosGrid_MPI2 PRIVATE USE_XIOS)
target_include_directories(
testXiosGrid_MPI2
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosGrid_MPI2 PRIVATE nextsimlib doctest::doctest)

add_executable(testXiosField_MPI3 "XiosField_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosField_MPI3 PRIVATE USE_XIOS)
target_include_directories(
testXiosField_MPI3
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosField_MPI3 PRIVATE nextsimlib doctest::doctest)

add_executable(testXiosFile_MPI2 "XiosFile_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosFile_MPI2 PRIVATE USE_XIOS)
target_include_directories(
testXiosFile_MPI2
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosFile_MPI2 PRIVATE nextsimlib doctest::doctest)

Expand All @@ -195,15 +232,23 @@ if(ENABLE_MPI)
)
target_include_directories(
testXiosRead_MPI2
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosRead_MPI2 PRIVATE nextsimlib doctest::doctest)

add_executable(testXiosWrite_MPI2 "XiosWrite_test.cpp" "MainMPI.cpp")
target_compile_definitions(testXiosWrite_MPI2 PRIVATE USE_XIOS)
target_include_directories(
testXiosWrite_MPI2
PRIVATE "${MODEL_INCLUDE_DIR}" "${XIOS_INCLUDE_LIST}" "${ModulesRoot}/StructureModule"
PRIVATE
${PHYSICS_INCLUDE_DIRS}
"${MODEL_INCLUDE_DIR}"
"${XIOS_INCLUDE_LIST}"
"${ModulesRoot}/StructureModule"
)
target_link_libraries(testXiosWrite_MPI2 PRIVATE nextsimlib doctest::doctest)

Expand Down
18 changes: 18 additions & 0 deletions core/test/XiosAxis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "StructureModule/include/ParametricGrid.hpp"
#include "include/Finalizer.hpp"
#include "include/Model.hpp"
#include "include/ModelMPI.hpp"
#include "include/Xios.hpp"

namespace Nextsim {
Expand All @@ -26,7 +28,23 @@ namespace Nextsim {
*/
MPI_TEST_CASE("TestXiosAxis", 3)
{
// Enable XIOS in the 'config' and provide parameters to configure it
enableXios();
std::stringstream config;
config << "[model]" << std::endl;
config << "start = 2023-03-17T17:11:00Z" << std::endl;
config << "stop = 2023-03-17T18:11:00Z" << std::endl;
config << "time_step = P0-0T01:00:00" << std::endl;
std::unique_ptr<std::istream> pcstream(new std::stringstream(config.str()));
Configurator::addStream(std::move(pcstream));

// Create ModelMetadata instance based off a partition metadata file
auto& modelMPI = ModelMPI::getInstance(test_comm);
auto& metadata = ModelMetadata::getInstance("xios_test_partition_metadata_3.nc");

// 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
Xios& xiosHandler = Xios::getInstance();
Expand Down
Loading
Loading