Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions core/src/ModelArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,24 @@ void ModelArray::setData(const DataType& from) { m_data = from; } // setData(fro

void ModelArray::setData(const ModelArray& from) { setData(from.m_data.data()); }

void ModelArray::setDimensions(Type type, const MultiDim& newDims)
#ifdef USE_MPI
void ModelArray::setDimensions(Type type, const MultiDim& globalDims, const MultiDim& localDims)
{
std::vector<Dimension>& dimSpecs = typeDimensions.at(type);
for (size_t i = 0; i < dimSpecs.size(); ++i) {
definedDimensions.at(dimSpecs[i]).localLength = newDims[i];
definedDimensions.at(dimSpecs[i]).globalLength = globalDims[i];
definedDimensions.at(dimSpecs[i]).localLength = localDims[i];
}
#else
void ModelArray::setDimensions(Type type, const MultiDim& globalDims)
{
std::vector<Dimension>& dimSpecs = typeDimensions.at(type);
for (size_t i = 0; i < dimSpecs.size(); ++i) {
// for serial code (non-MPI) global and local dims are the same.
definedDimensions.at(dimSpecs[i]).globalLength = globalDims[i];
definedDimensions.at(dimSpecs[i]).localLength = globalDims[i];
}
#endif
validateMaps();
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/ParaGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void ParaGridIO::dumpModelState(const ModelState& state, const std::string& file
for (auto entry : ModelArray::definedDimensions) {
ModelArray::Dimension dim = entry.first;
size_t dimSz = (dimCompMap.count(dim)) ? ModelArray::nComponents(dimCompMap.at(dim))
: dimSz = entry.second.localLength;
: dimSz = entry.second.globalLength;
ncFromMAMap[dim] = ncFile.addDim(entry.second.name, dimSz);
// TODO Do I need to add data, even if it is just integers 0...n-1?
}
Expand Down
24 changes: 9 additions & 15 deletions core/src/RectGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ void dimensionSetter(
const netCDF::NcFile& ncFile, const std::string& fieldName, ModelArray::Type type)
{
size_t nDims = ncFile.getVar(fieldName).getDimCount();
ModelArray::MultiDim dims;
dims.resize(nDims);
for (size_t d = 0; d < nDims; ++d) {
dims[d] = ncFile.getVar(fieldName).getDim(d).getSize();
}
// The dimensions in the netCDF are in the reverse order compared to ModelArray
std::reverse(dims.begin(), dims.end());
// Replace X, Y dimensions with local extends
ModelArray::MultiDim globalDims;
ModelArray::MultiDim localDims;
globalDims.resize(nDims);
localDims.resize(nDims);
auto& metadata = ModelMetadata::getInstance();
dims[0] = metadata.getLocalExtentX();
dims[1] = metadata.getLocalExtentY();
ModelArray::setDimensions(type, dims);
globalDims[0] = metadata.getGlobalExtentX();
globalDims[1] = metadata.getGlobalExtentY();
localDims[0] = metadata.getLocalExtentX();
localDims[1] = metadata.getLocalExtentY();
ModelArray::setDimensions(type, globalDims, localDims);
}
#else
void dimensionSetter(
Expand Down Expand Up @@ -77,10 +75,6 @@ ModelState RectGridIO::getModelState(const std::string& filePath)
// Get the sizes of the three types of field
// HField from hice
dimensionSetter(ncFile, hiceName, ModelArray::Type::H);
// UField from hice
dimensionSetter(ncFile, hiceName, ModelArray::Type::U);
// VField from hice
dimensionSetter(ncFile, hiceName, ModelArray::Type::V);

#ifdef USE_MPI
// Set the origins and extensions for reading 2D data based
Expand Down
17 changes: 15 additions & 2 deletions core/src/include/ModelArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ class ModelArray {
* @param type The type of array the dimensions are to be specified for.
* @param dim The per-dimension size to be set.
*/
#ifdef USE_MPI
static void setDimensions(Type, const MultiDim&, const MultiDim&);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I don't like the idea of having a different function signature serial and MPI versions of the code. I wonder if a better solution might be changing the result of ModelArray::dimensions from a plain MultiDim to a vector of not scalars but local-global pairs in the MPI case.

#else
static void setDimensions(Type, const MultiDim&);
#endif

/*!
* @brief Sets the number and size of the dimensions of this type of ModelArray.
*
Expand All @@ -340,9 +345,17 @@ class ModelArray {
*
* @param dim The per-dimension size to be set.
*/
void setDimensions(const MultiDim& dims)
#ifdef USE_MPI
void setDimensions(const MultiDim& globalDims, const MultiDim& localDims)
#else
void setDimensions(const MultiDim& globalDims)
#endif
{
setDimensions(type, dims);
#ifdef USE_MPI
setDimensions(type, globalDims, localDims);
#else
setDimensions(type, globalDims);
#endif
resize();
}

Expand Down
33 changes: 23 additions & 10 deletions core/src/modules/DynamicsModule/BBMDynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

#include "include/BBMDynamics.hpp"
#include "include/ModelArray.hpp"
#include "include/ModelMetadata.hpp"
#include "include/constants.hpp"
#include "include/gridNames.hpp"

Expand Down Expand Up @@ -112,17 +114,27 @@ void BBMDynamics::setData(const ModelState::DataMap& ms)
if (uice.getType() == ModelArray::Type::CG && uice.dimensions()[0] != cgDims[0]) {
// CG degree of the read data
const unsigned int fileCGdegree = (ModelArray::dimensions(ModelArray::Type::CG)[0] - 1)
/ ModelArray::dimensions(ModelArray::Type::H)[0];
const unsigned int modelCGdegree = (cgDims[0] - 1)
/ ModelArray::dimensions(ModelArray::Type::H)[0];
/ ModelArray::dimensions(ModelArray::Type::H)[0];
const unsigned int modelCGdegree
= (cgDims[0] - 1) / ModelArray::dimensions(ModelArray::Type::H)[0];

throw std::runtime_error(
"Differing CG degrees between input data and model are not supported. File CG degree = "
+ std::to_string(fileCGdegree) + ", model CG degree = "
+ std::to_string(modelCGdegree) + ".");
"Differing CG degrees between input data and model are not supported. File CG degree = "
+ std::to_string(fileCGdegree) + ", model CG degree = " + std::to_string(modelCGdegree)
+ ".");
}
// Set the dimensions of CG arrays
#ifdef USE_MPI
auto& metadata = ModelMetadata::getInstance();
ModelArray::MultiDim globalDims, localDims;
globalDims[0] = metadata.getGlobalExtentX();
globalDims[1] = metadata.getGlobalExtentY();
localDims[0] = metadata.getLocalExtentX();
localDims[1] = metadata.getLocalExtentY();
ModelArray::setDimensions(ModelArray::Type::CG, globalDims, localDims);
#else
ModelArray::setDimensions(ModelArray::Type::CG, cgDims);
#endif

// Set the data in the kernel arrays.
// Required data
Expand Down Expand Up @@ -194,10 +206,11 @@ void BBMDynamics::advectField(
ModelState BBMDynamics::getStatePrognostic() const
{
return { {
{ uName, kernel.getCGData(uName) },
{ vName, kernel.getCGData(vName) },
{ damageName, damage },
}, { getConfiguration() } };
{ uName, kernel.getCGData(uName) },
{ vName, kernel.getCGData(vName) },
{ damageName, damage },
},
{ getConfiguration() } };
}

BBMDynamics::HelpMap& BBMDynamics::getHelpText(HelpMap& map, bool getAll)
Expand Down
31 changes: 22 additions & 9 deletions core/src/modules/DynamicsModule/MEVPDynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

#include "include/MEVPDynamics.hpp"
#include "include/ModelArray.hpp"
#include "include/ModelMetadata.hpp"
#include "include/constants.hpp"
#include "include/gridNames.hpp"

Expand Down Expand Up @@ -98,17 +100,27 @@ void MEVPDynamics::setData(const ModelState::DataMap& ms)
if (uice.getType() == ModelArray::Type::CG && uice.dimensions()[0] != cgDims[0]) {
// CG degree of the read data
const unsigned int fileCGdegree = (ModelArray::dimensions(ModelArray::Type::CG)[0] - 1)
/ ModelArray::dimensions(ModelArray::Type::H)[0];
const unsigned int modelCGdegree = (cgDims[0] - 1)
/ ModelArray::dimensions(ModelArray::Type::H)[0];
/ ModelArray::dimensions(ModelArray::Type::H)[0];
const unsigned int modelCGdegree
= (cgDims[0] - 1) / ModelArray::dimensions(ModelArray::Type::H)[0];

throw std::runtime_error(
"Differing CG degrees between input data and model are not supported. File CG degree = "
+ std::to_string(fileCGdegree) + ", model CG degree = "
+ std::to_string(modelCGdegree) + ".");
"Differing CG degrees between input data and model are not supported. File CG degree = "
+ std::to_string(fileCGdegree) + ", model CG degree = " + std::to_string(modelCGdegree)
+ ".");
}
// Set the dimensions of CG arrays
#ifdef USE_MPI
auto& metadata = ModelMetadata::getInstance();
ModelArray::MultiDim globalDims, localDims;
globalDims[0] = metadata.getGlobalExtentX();
globalDims[1] = metadata.getGlobalExtentY();
localDims[0] = metadata.getLocalExtentX();
localDims[1] = metadata.getLocalExtentY();
ModelArray::setDimensions(ModelArray::Type::CG, globalDims, localDims);
Comment on lines +116 to +120
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the metadata class could have a function to generate the correct form of the combined local/global dims.

#else
ModelArray::setDimensions(ModelArray::Type::CG, cgDims);
#endif

// Set the data in the kernel arrays.
for (const auto& fieldName : namedFields) {
Expand Down Expand Up @@ -155,9 +167,10 @@ void MEVPDynamics::advectField(
ModelState MEVPDynamics::getStatePrognostic() const
{
return { {
{ uName, kernel.getCGData(uName) },
{ vName, kernel.getCGData(vName) },
}, { getConfiguration() } };
{ uName, kernel.getCGData(uName) },
{ vName, kernel.getCGData(vName) },
},
{ getConfiguration() } };
}

MEVPDynamics::HelpMap& MEVPDynamics::getHelpText(HelpMap& map, bool getAll)
Expand Down
4 changes: 4 additions & 0 deletions core/test/RectGrid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ TEST_CASE("Write and read a ModelState-based RectGrid restart file")

// Reset dimensions so it is possible to check if they
// are read correctly from refeence file
#ifdef USE_MPI
ModelArray::setDimensions(ModelArray::Type::H, { 1, 1 }, { 1, 1 });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would become ```
ModelArray::setDimensions(ModelArray::Type::H, { { 1, 1 }, { 1, 1 } });

#else
ModelArray::setDimensions(ModelArray::Type::H, { 1, 1 });
#endif
REQUIRE(ModelArray::dimensions(ModelArray::Type::H)[0] == 1);
RectangularGrid gridIn;
size_t targetX = 1;
Expand Down
Loading