-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*! | ||
* @file MainMPI.cpp | ||
* | ||
* @date 13 Sep 2024 | ||
* @author Einar Ólason <einar.olason@nersc.no> | ||
* | ||
* This file is required so that the MPI enabled doc-test OASISCoupledOcean_test.cpp (and any | ||
* others) can run. | ||
*/ | ||
|
||
#define DOCTEST_CONFIG_IMPLEMENT | ||
|
||
#include <doctest/extensions/doctest_mpi.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* @file OASISCoupledOcean_test.cpp | ||
* | ||
* @date 13 Sep 2024 | ||
* @author Einar Ólason <einar.olason@nersc.no> | ||
*/ | ||
|
||
#include <doctest/extensions/doctest_mpi.h> | ||
|
||
#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(); | ||
} |