From bf7cd78d6b53fd7e42dfe97cd6451f5eac2eba1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20=C3=96rn=20=C3=93lason?= Date: Fri, 13 Sep 2024 09:08:36 +0200 Subject: [PATCH] First steps in implementing a unit test for OASISCoupledOcean A skeleton of a unit test in OASISCoupledOcean_test.cpp and some changes in the accompanying CMakeLists.txt to make it compile. Added MainMPI.cpp so that the test starts. We still need a namcouple file and the actual ins-and-outs of the test. --- physics/test/CMakeLists.txt | 6 ++++ physics/test/MainMPI.cpp | 30 +++++++++++++++++++ physics/test/OASISCoupledOcean_test.cpp | 40 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 physics/test/MainMPI.cpp create mode 100644 physics/test/OASISCoupledOcean_test.cpp diff --git a/physics/test/CMakeLists.txt b/physics/test/CMakeLists.txt index 2b01dcc4d..0a204ad34 100644 --- a/physics/test/CMakeLists.txt +++ b/physics/test/CMakeLists.txt @@ -37,6 +37,12 @@ if(ENABLE_MPI) PRIVATE USE_MPI TEST_FILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\" ) target_link_libraries(testTOPAZOcn_MPI1 PRIVATE nextsimlib doctest::doctest) + if (ENABLE_OASIS) + add_executable(testOASISCoupledOcean_MPI2 "OASISCoupledOcean_test.cpp" "MainMPI.cpp") + target_include_directories(testOASISCoupledOcean_MPI2 PRIVATE "${ModulesRoot}/OceanBoundaryModule") + target_compile_definitions(testOASISCoupledOcean_MPI2 PRIVATE TEST_FILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\") + target_link_libraries(testOASISCoupledOcean_MPI2 PRIVATE nextsimlib doctest::doctest) + endif () else() add_executable(testERA5Atm "ERA5Atm_test.cpp") target_compile_definitions(testERA5Atm PRIVATE TEST_FILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\") diff --git a/physics/test/MainMPI.cpp b/physics/test/MainMPI.cpp new file mode 100644 index 000000000..5fde9684e --- /dev/null +++ b/physics/test/MainMPI.cpp @@ -0,0 +1,30 @@ +/*! + * @file MainMPI.cpp + * + * @date 13 Sep 2024 + * @author Einar Ólason + * + * This file is required so that the MPI enabled doc-test OASISCoupledOcean_test.cpp (and any + * others) can run. + */ + +#define DOCTEST_CONFIG_IMPLEMENT + +#include + +int main(int argc, char** argv) +{ + doctest::mpi_init_thread(argc, argv, MPI_THREAD_MULTIPLE); + + doctest::Context ctx; + ctx.setOption("reporters", "MpiConsoleReporter"); + ctx.setOption("reporters", "MpiFileReporter"); + ctx.setOption("force-colors", true); + ctx.applyCommandLine(argc, argv); + + int test_result = ctx.run(); + + doctest::mpi_finalize(); + + return test_result; +} diff --git a/physics/test/OASISCoupledOcean_test.cpp b/physics/test/OASISCoupledOcean_test.cpp new file mode 100644 index 000000000..1c4109728 --- /dev/null +++ b/physics/test/OASISCoupledOcean_test.cpp @@ -0,0 +1,40 @@ +/*! + * @file OASISCoupledOcean_test.cpp + * + * @date 13 Sep 2024 + * @author Einar Ólason + */ + +#include + +#include "include/OASISCoupledOcean.hpp" + +namespace Nextsim { + +TEST_SUITE_BEGIN("OASISCoupledOcean"); +MPI_TEST_CASE("OASIS init put and get", 2) +{ + MPI_Comm modelCommunicator; + int compID; // Not actually used. Only useful for debugging + const std::string compName = "nextsim"; // Not useful for any setups we have in mind + OASIS_CHECK_ERR(oasis_c_init_comp(&compID, compName.c_str(), OASIS_COUPLED)); + OASIS_CHECK_ERR(oasis_c_get_localcomm(&modelCommunicator)); + + ModelArray::setDimensions(ModelArray::Type::H, { 1, 1 }); + ModelArray::setDimensions(ModelArray::Type::Z, { 1, 1, 1 }); + + HField cice(ModelArray::Type::H); + cice = 1.0; + ModelComponent::getStore().registerArray(Protected::C_ICE, &cice, RO); + OASISCoupledOcean ocpl; + ModelMetadata metadata; + + ocpl.setData(ModelState::DataMap()); + ocpl.setMetadata(metadata); + ocpl.updateBefore(TimestepTime()); + ocpl.updateAfter(TimestepTime()); + + OASIS_CHECK_ERR(oasis_c_terminate()); +} +TEST_SUITE_END(); +} \ No newline at end of file