Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into aug23_mar3
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/ParaGridIO.cpp
	core/src/include/ModelComponent.hpp
  • Loading branch information
timspainNERSC committed Aug 10, 2023
2 parents 50fcd88 + 7c75977 commit 4ea9d31
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 52 deletions.
4 changes: 2 additions & 2 deletions core/src/DevGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
28 changes: 2 additions & 26 deletions core/src/MissingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,7 @@

namespace Nextsim {

template <>
const std::map<int, std::string> Configured<MissingData>::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 */
11 changes: 6 additions & 5 deletions core/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const std::map<int, std::string> Configured<Model>::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()
Expand Down Expand Up @@ -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());

Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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<IDiagnosticOutput>(map, getAll);
return map;
Expand Down
6 changes: 4 additions & 2 deletions core/src/ModelComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "include/ModelComponent.hpp"

#include "include/MissingData.hpp"

namespace Nextsim {

std::unordered_map<std::string, ModelComponent*> ModelComponent::registeredModules;
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions core/src/ParaGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void ParaGridIO::dumpModelState(
ModelArray::Type type = entry.second.getType();
std::vector<netCDF::NcDim>& 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());
}
}
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/RectGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
14 changes: 2 additions & 12 deletions core/src/include/MissingData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ namespace Nextsim {

class MissingData : public Configured<MissingData> {
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 */
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 @@ -34,6 +34,7 @@ class Model : public Configured<Model> {
STOPTIME_KEY,
RUNLENGTH_KEY,
TIMESTEP_KEY,
MISSINGVALUE_KEY,
};

ConfigMap getConfig() const;
Expand Down
1 change: 0 additions & 1 deletion core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 2 additions & 0 deletions physics/src/modules/include/FluxConfiguredAtmosphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4ea9d31

Please sign in to comment.