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 11fa2928a..e696fe4d6 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,8 @@ 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 +92,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 +114,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 +124,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 56272df5b..2bf0ade79 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; @@ -101,12 +103,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 62f548388..593832c4a 100644 --- a/core/src/ParaGridIO.cpp +++ b/core/src/ParaGridIO.cpp @@ -230,7 +230,7 @@ void ParaGridIO::dumpModelState( 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()); } } @@ -359,7 +359,7 @@ void ParaGridIO::writeDiagnosticTime( netCDF::NcVar var((isNew) ? dataGroup.addVar(entry.first, netCDF::ncDouble, ncDims) : dataGroup.getVar(entry.first)); if (isNew) - 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()); } diff --git a/core/src/RectGridIO.cpp b/core/src/RectGridIO.cpp index 8316ffe84..d62ccc53d 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 && entry.second.trueSize() > 0) { 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 && entry.second.trueSize() > 0) { 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/test/CMakeLists.txt b/core/test/CMakeLists.txt index 174880d87..8087e96a9 100644 --- a/core/test/CMakeLists.txt +++ b/core/test/CMakeLists.txt @@ -153,7 +153,6 @@ add_executable(testModelComponent "ModelComponent_test.cpp" "${CoreSrc}/ModelComponent.cpp" "${CoreSrc}/MissingData.cpp" - "${CoreSrc}/Configurator.cpp" "${CoreSrc}/ModelArray.cpp" "${CoreSrc}/${ModelArrayStructure}/ModelArrayDetails.cpp" ) 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.