Skip to content

Conversation

timspainNERSC
Copy link
Collaborator

Read old-style restart files

Fixes #931


Change Description

Adds the necessary code to allow the old-style restart files with netCDF groups to still be read. This involves making the ParaGridIO code generic so that dimensions and variables can be searched for both in the file root and in the data group. All newly written files are in the flat new style.


Test Description

The model successfully runs using my old style restart and forcing files.


Documentation Impact

Since no-one else should be generating the old-style files, this does not really need to be documented. Plus, I should eventually replace my old-style restart files over time.

Copy link
Contributor

@jwallwork23 jwallwork23 left a comment

Choose a reason for hiding this comment

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

Nice to have backward compatibility for reading files.

I have a couple of requests:

  1. Perhaps add a Logged warning when reading files through the legacy option to say that this is being done? Could even include a deprecation warning, if you think that'd be appropriate.
  2. In the ParaGridIO_Xios implementation of getModelState, perhaps we should raise an error if groups are found, with a message saying that the legacy format is not supported in the XIOS implementation? (I'm not sure how readable the XIOS errors would be.) I can then do the same for readForcingTimeStatic in #928.

Also note that some of the other code changes that align the MPI and non-MPI cases will conflict with similar changes in #744.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this will conflict with @TomMelt's changes in #744, although it'll be possible to rectify the two.

@github-project-automation github-project-automation bot moved this from Todo to Review required in neXtSIM_DG overview Oct 2, 2025
@timspainNERSC
Copy link
Collaborator Author

It might be easier to start from scratch.

This branch has conflicts that must be resolved

  • core/src/Model.cpp
  • core/src/ParaGridIO.cpp
  • core/src/RectGridIO.cpp
  • core/src/StructureFactory.cpp
  • core/src/include/ParaGridIO.hpp
  • core/src/include/RectGridIO.hpp
  • core/src/include/StructureFactory.hpp
  • core/src/modules/StructureModule/include/ParametricGrid.hpp
  • core/src/modules/StructureModule/include/RectangularGrid.hpp
  • core/src/modules/include/IStructure.hpp
  • core/test/ParaGrid_test.cpp
  • core/test/RectGrid_test.cpp

@timspainNERSC timspainNERSC force-pushed the issue931_oldsytlerestarts branch from e56494f to af75f07 Compare October 2, 2025 12:37
@timspainNERSC
Copy link
Collaborator Author

  1. In the ParaGridIO_Xios implementation of getModelState, perhaps we should raise an error if groups are found, with a message saying that the legacy format is not supported in the XIOS implementation? (I'm not sure how readable the XIOS errors would be.) I can then do the same for readForcingTimeStatic in XIOS implementation of readForcingTimeStatic #928.

What would be a sensible way of doing this? As far as I can tell, getModelState no longer does anything with the filename parameter, it (presumably) having been passed to the XIOS set up beforehand. It rather seems overkill to re-open the netCDF file from the passed filename, check for groups and then close it again.

@jwallwork23
Copy link
Contributor

What would be a sensible way of doing this? As far as I can tell, getModelState no longer does anything with the filename parameter, it (presumably) having been passed to the XIOS set up beforehand. It rather seems overkill to re-open the netCDF file from the passed filename, check for groups and then close it again.

Ah, good point. There's already an initial read of the NetCDF file in Xios::affixModelMetadata within the conditional that checks if an input file is provided so that would be the best place to add it.

nextsimdg/core/src/Xios.cpp

Lines 673 to 680 in af75f07

void Xios::affixModelMetadata()
{
auto& metadata = ModelMetadata::getInstance();
// Initial read of the NetCDF file to deduce the dimensions
if (inputFilename.length() > 0) {
try {
auto& modelMPI = ModelMPI::getInstance();
netCDF::NcFilePar ncFile(inputFilename, netCDF::NcFile::read, modelMPI.getComm());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Review required
Development

Successfully merging this pull request may close these issues.

ParaGridIO no longer reads old-style restart files.
2 participants