From ba805ea40b0b0b74556cd7cbbde3ae8f8c69305a Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Fri, 31 Mar 2023 08:47:27 +0200 Subject: [PATCH 1/5] Add the missing Configured header. --- physics/src/modules/include/FluxConfiguredAtmosphere.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/physics/src/modules/include/FluxConfiguredAtmosphere.hpp b/physics/src/modules/include/FluxConfiguredAtmosphere.hpp index 0e4eddd8f..1a1169214 100644 --- a/physics/src/modules/include/FluxConfiguredAtmosphere.hpp +++ b/physics/src/modules/include/FluxConfiguredAtmosphere.hpp @@ -10,6 +10,8 @@ #include "IAtmosphereBoundary.hpp" +#include "include/Configured.hpp" + namespace Nextsim { //! A class to provide constant atmospheric forcings that can be configured at run time. From a59ac8b77c37ed04e53d0a3afa2463a323bfe074 Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Fri, 31 Mar 2023 08:48:23 +0200 Subject: [PATCH 2/5] Move configuration from MissingData to Model. --- core/src/DevGridIO.cpp | 4 ++-- core/src/MissingData.cpp | 28 ++-------------------------- core/src/Model.cpp | 10 +++++----- core/src/ModelComponent.cpp | 6 ++++-- core/src/ParaGridIO.cpp | 4 ++-- core/src/RectGridIO.cpp | 4 ++-- core/src/include/MissingData.hpp | 14 ++------------ core/src/include/Model.hpp | 1 + core/src/include/ModelComponent.hpp | 1 - 9 files changed, 20 insertions(+), 52 deletions(-) diff --git a/core/src/DevGridIO.cpp b/core/src/DevGridIO.cpp index 0d82ea2cb..9c39f15f9 100644 --- a/core/src/DevGridIO.cpp +++ b/core/src/DevGridIO.cpp @@ -141,11 +141,11 @@ void dumpModelData(const ModelState& state, netCDF::NcGroup& dataGroup) const std::string& name = entry.first; if (entry.second.getType() == ModelArray::Type::H) { netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims2)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(entry.second.getData()); } else if (entry.second.getType() == ModelArray::Type::Z) { netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims3)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(entry.second.getData()); } } diff --git a/core/src/MissingData.cpp b/core/src/MissingData.cpp index a0578eec6..b6e70bcde 100644 --- a/core/src/MissingData.cpp +++ b/core/src/MissingData.cpp @@ -9,31 +9,7 @@ namespace Nextsim { -template <> -const std::map Configured::keyMap = { - { MissingData::MISSINGVALUE_KEY, "model.missing_value" }, -}; -static const double missingDefault = -0x1p300; -double MissingData::m_value = missingDefault; -void MissingData::configure() -{ - m_value - = Configured::getConfiguration(keyMap.at(MissingData::MISSINGVALUE_KEY), missingDefault); -} +const double MissingData::defaultValue = -0x1p300; +double MissingData::value = MissingData::defaultValue; -ConfigMap MissingData::getConfig() -{ - return { - { keyMap.at(MISSINGVALUE_KEY), m_value }, - }; -} - -MissingData::HelpMap& MissingData::getHelpText(HelpMap& map, bool getAll) -{ - map["MissingData"] = { - { keyMap.at(MISSINGVALUE_KEY), ConfigType::NUMERIC, { "-∞", "∞" }, "-2³⁰⁰", "", - "Missing data indicator used for input and output." }, - }; - return map; -} } /* namespace Nextsim */ diff --git a/core/src/Model.cpp b/core/src/Model.cpp index 5ad1cbafb..447c5ab4b 100644 --- a/core/src/Model.cpp +++ b/core/src/Model.cpp @@ -31,6 +31,7 @@ const std::map Configured::keyMap = { { Model::STOPTIME_KEY, "model.stop" }, { Model::RUNLENGTH_KEY, "model.run_length" }, { Model::TIMESTEP_KEY, "model.time_step" }, + { Model::MISSINGVALUE_KEY, "model.missing_value" }, }; Model::Model() @@ -68,8 +69,7 @@ void Model::configure() TimePoint timeNow = iterator.parseAndSet(startTimeStr, stopTimeStr, durationStr, stepStr); m_etadata.setTime(timeNow); - MissingData mdi; - mdi.configure(); + MissingData::value = Configured::getConfiguration(keyMap.at(MISSINGVALUE_KEY), MissingData::defaultValue); initialFileName = Configured::getConfiguration(keyMap.at(RESTARTFILE_KEY), std::string()); @@ -91,9 +91,8 @@ ConfigMap Model::getConfig() const { keyMap.at(STOPTIME_KEY), stopTimeStr }, { keyMap.at(RUNLENGTH_KEY), durationStr }, { keyMap.at(TIMESTEP_KEY), stepStr }, + { keyMap.at(MISSINGVALUE_KEY), MissingData::value }, }; - // MissingData has a static getState - cMap.merge(MissingData::getConfig()); return cMap; } @@ -114,6 +113,8 @@ Model::HelpMap& Model::getHelpText(HelpMap& map, bool getAll) "Model physics timestep, formatted a ISO8601 duration (P prefix). " }, { keyMap.at(RESTARTFILE_KEY), ConfigType::STRING, {}, "", "", "The file path to the restart file to use for the run." }, + { keyMap.at(MISSINGVALUE_KEY), ConfigType::NUMERIC, { "-∞", "∞" }, "-2³⁰⁰", "", + "Missing data indicator used for input and output." }, }; return map; @@ -122,7 +123,6 @@ Model::HelpMap& Model::getHelpText(HelpMap& map, bool getAll) Model::HelpMap& Model::getHelpRecursive(HelpMap& map, bool getAll) { getHelpText(map, getAll); - MissingData::getHelpRecursive(map, getAll); PrognosticData::getHelpRecursive(map, getAll); Module::getHelpRecursive(map, getAll); return map; diff --git a/core/src/ModelComponent.cpp b/core/src/ModelComponent.cpp index 0b2a37651..a7132afb7 100644 --- a/core/src/ModelComponent.cpp +++ b/core/src/ModelComponent.cpp @@ -7,6 +7,8 @@ #include "include/ModelComponent.hpp" +#include "include/MissingData.hpp" + namespace Nextsim { std::unordered_map ModelComponent::registeredModules; @@ -114,12 +116,12 @@ ModelArray ModelComponent::mask(const ModelArray& data) case (ModelArray::Type::H): case (ModelArray::Type::U): case (ModelArray::Type::V): { - return data * oceanMask() + MissingData::value() * (1 - oceanMask()); + return data * oceanMask() + MissingData::value * (1 - oceanMask()); break; } case (ModelArray::Type::Z): { ModelArray copy = ModelArray::ZField(); - copy = MissingData::value(); + copy = MissingData::value; size_t nZ = data.dimensions()[data.nDimensions() - 1]; for (size_t iOcean = 0; iOcean < nOcean; ++iOcean) { size_t i = oceanIndex[iOcean]; diff --git a/core/src/ParaGridIO.cpp b/core/src/ParaGridIO.cpp index 9181fa51a..def8db747 100644 --- a/core/src/ParaGridIO.cpp +++ b/core/src/ParaGridIO.cpp @@ -168,7 +168,7 @@ void ParaGridIO::dumpModelState(const ModelState& state, const ModelMetadata& me ModelArray::Type type = entry.second.getType(); std::vector& ncDims = dimMap.at(type); netCDF::NcVar var(dataGroup.addVar(entry.first, netCDF::ncDouble, ncDims)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(entry.second.getData()); } } @@ -315,7 +315,7 @@ void ParaGridIO::dumpModelState(const ModelState& state, const ModelMetadata& me ModelArray::Type type = entry.second.getType(); std::vector& ncDims = dimMap.at(type); netCDF::NcVar var(dataGroup.addVar(entry.first, netCDF::ncDouble, ncDims)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(indexArrays.at(type), extentArrays.at(type), entry.second.getData()); } else { // Write the mask data diff --git a/core/src/RectGridIO.cpp b/core/src/RectGridIO.cpp index 702529750..3ac451a0e 100644 --- a/core/src/RectGridIO.cpp +++ b/core/src/RectGridIO.cpp @@ -108,11 +108,11 @@ void RectGridIO::dumpModelState(const ModelState& state, const ModelMetadata& me const std::string& name = entry.first; if (entry.second.getType() == ModelArray::Type::H) { netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims2)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(entry.second.getData()); } else if (entry.second.getType() == ModelArray::Type::Z) { netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims3)); - var.putAtt(mdiName, netCDF::ncDouble, MissingData::value()); + var.putAtt(mdiName, netCDF::ncDouble, MissingData::value); var.putVar(entry.second.getData()); } } diff --git a/core/src/include/MissingData.hpp b/core/src/include/MissingData.hpp index ec51cf151..3d2745c86 100644 --- a/core/src/include/MissingData.hpp +++ b/core/src/include/MissingData.hpp @@ -14,18 +14,8 @@ namespace Nextsim { class MissingData : public Configured { public: - inline static double value() { return m_value; } - void configure() override; - enum { - MISSINGVALUE_KEY, - }; - - static ConfigMap getConfig(); - static HelpMap& getHelpRecursive(HelpMap& map, bool getAll) { return getHelpText(map, getAll); } - static HelpMap& getHelpText(HelpMap& map, bool getAll); - -private: - static double m_value; + static const double defaultValue; + static double value; }; } /* namespace Nextsim */ diff --git a/core/src/include/Model.hpp b/core/src/include/Model.hpp index d759c64db..75fcfbd1f 100644 --- a/core/src/include/Model.hpp +++ b/core/src/include/Model.hpp @@ -34,6 +34,7 @@ class Model : public Configured { STOPTIME_KEY, RUNLENGTH_KEY, TIMESTEP_KEY, + MISSINGVALUE_KEY, }; ConfigMap getConfig() const; diff --git a/core/src/include/ModelComponent.hpp b/core/src/include/ModelComponent.hpp index c65180b12..b424cfe2c 100644 --- a/core/src/include/ModelComponent.hpp +++ b/core/src/include/ModelComponent.hpp @@ -9,7 +9,6 @@ #define MODELCOMPONENT_HPP #include "include/Logged.hpp" -#include "include/MissingData.hpp" #include "include/ModelArrayRef.hpp" #include "include/ModelState.hpp" #include "include/OutputSpec.hpp" From 457ff463b075ca26bae0a6dbf4d44f1f08d109c9 Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Fri, 31 Mar 2023 09:23:39 +0200 Subject: [PATCH 3/5] Remove Configured.cpp from as many tests as possible (1). --- core/test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/test/CMakeLists.txt b/core/test/CMakeLists.txt index 482d4fd1f..3461d835f 100644 --- a/core/test/CMakeLists.txt +++ b/core/test/CMakeLists.txt @@ -145,7 +145,6 @@ add_executable(testModelComponent "ModelComponent_test.cpp" "${CoreSrc}/ModelComponent.cpp" "${CoreSrc}/MissingData.cpp" - "${CoreSrc}/Configurator.cpp" "${CoreSrc}/ModelArray.cpp" "${CoreSrc}/${ModelArrayStructure}/ModelArrayDetails.cpp" ) From db3f0eeb8bdd94a6269b2bae52403d16b3bd4fc7 Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Fri, 31 Mar 2023 10:35:34 +0200 Subject: [PATCH 4/5] clang formatting --- core/src/Model.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/Model.cpp b/core/src/Model.cpp index 447c5ab4b..1be3f9981 100644 --- a/core/src/Model.cpp +++ b/core/src/Model.cpp @@ -69,7 +69,8 @@ void Model::configure() TimePoint timeNow = iterator.parseAndSet(startTimeStr, stopTimeStr, durationStr, stepStr); m_etadata.setTime(timeNow); - MissingData::value = Configured::getConfiguration(keyMap.at(MISSINGVALUE_KEY), MissingData::defaultValue); + MissingData::value + = Configured::getConfiguration(keyMap.at(MISSINGVALUE_KEY), MissingData::defaultValue); initialFileName = Configured::getConfiguration(keyMap.at(RESTARTFILE_KEY), std::string()); From db7f7ccec8fa7b0d314673dbff0bb5220602a157 Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Thu, 11 May 2023 08:11:07 +0200 Subject: [PATCH 5/5] Eliminate the compiler warning from PrognosticData_test. --- core/test/PrognosticData_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/test/PrognosticData_test.cpp b/core/test/PrognosticData_test.cpp index aca8e9bbe..effd72da3 100644 --- a/core/test/PrognosticData_test.cpp +++ b/core/test/PrognosticData_test.cpp @@ -13,7 +13,6 @@ #include "include/PrognosticData.hpp" #include "include/ConfiguredModule.hpp" -#include "include/IOceanBoundary.hpp" #include "include/ModelComponent.hpp" #include "include/Module.hpp" #include "include/UnescoFreezing.hpp" @@ -21,6 +20,8 @@ #include +extern template class Module::Module; + namespace Nextsim { TEST_SUITE_BEGIN("PrognosticData");