Commit 0d904f91 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: handle restart files with new ADIOS

- ADIOS-2.4.0 and earlier had timeName.bp files
  and timeName.bp.dir/ directories. Restart checked for
  times based on the timeName.bp files

- ADIOS-2.5.0 and later simply use timeName/ directories,
  for which we can use slight modifications of standard
  OpenFOAM fileOperation routines.

Does not handle mixed naming. If the .bp files exist, we assume that
they provide full coverage for restart.
parent f635fe33
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "adiosFoam.H"
#include "fileOperation.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -35,68 +36,90 @@ const Foam::string Foam::adiosFoam::foamAttribute("/openfoam");
const Foam::string Foam::adiosFoam::timeAttribute("/time");
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
Foam::instantList Foam::adiosFoam::findTimes
(
const fileName& directory,
const word& constantName
)
// adios-2.4.0 and earlier:
// - <time>.bp files and <time>.bp.dir directories
//
// later:
// - <time> directories
namespace Foam
{
static Foam::instantList findTimes_bp(const fileName& directory)
{
// Read directory entries into a list
fileNameList dirEntries(readDir(directory, fileName::FILE, false));
const fileNameList dirEntries(Foam::readDir(directory, fileName::FILE, false));
// Initialise instant list
instantList Times(dirEntries.size() + 1);
label nTimes = 0;
// Check for "constant" - not yet useful
bool haveConstant = false;
// Check for .bp files
for (const fileName& dirEntry : dirEntries)
{
if (dirEntry.hasExt("bp") && dirEntry.lessExt() == constantName)
if (dirEntry.hasExt("bp"))
{
Times[nTimes].value() = 0;
Times[nTimes].name() = word(dirEntry);
++nTimes;
haveConstant = true;
break;
}
}
// Read and parse all the entries in the directory
if (!nTimes)
{
return instantList();
}
instantList times(nTimes);
nTimes = 0;
// Parse directory entry into time value/name
for (const fileName& dirEntry : dirEntries)
{
if (dirEntry.hasExt("bp"))
{
scalar val;
const word dirValue(dirEntry.lessExt());
if (readScalar(dirValue, val))
if (readScalar(dirValue, times[nTimes].value()))
{
Times[nTimes].value() = val;
Times[nTimes].name() = word(dirEntry);
times[nTimes].name() = word(dirEntry);
++nTimes;
}
}
}
// Reset the length of the times list
Times.setSize(nTimes);
times.resize(nTimes);
if (haveConstant)
if (nTimes > 1)
{
if (nTimes > 2)
{
std::sort(&Times[1], Times.end(), instant::less());
}
std::sort(times.begin(), times.end(), instant::less());
}
else if (nTimes > 1)
return times;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
Foam::instantList Foam::adiosFoam::findTimes
(
const fileName& directory,
const word& constantName
)
{
instantList times(findTimes_bp(directory));
if (times.size())
{
std::sort(&Times[0], Times.end(), instant::less());
// Older format with .bp files
return times;
}
return Times;
// Newer format, uses directory names only
fileNameList dirEntries(Foam::readDir(directory, fileName::DIRECTORY));
return fileOperation::sortTimes(dirEntries, constantName);
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -61,7 +61,8 @@ extern const string foamAttribute;
extern const string timeAttribute;
//- Search a given directory for ADIOS time files
//- Search a given directory for ADIOS time directories,
//- but first checks for .bp files (ADIOS-2.4.0 and earlier)
instantList findTimes
(
const fileName& directory,
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -73,7 +73,14 @@ bool Foam::functionObjects::adiosWrite::restart()
// Restart from a specified time, or from latest
const instantList adiosTimes = adiosFoam::findTimes(dataDir_);
instantList adiosTimes;
if (Pstream::master())
{
adiosTimes = adiosFoam::findTimes(dataDir_);
}
Pstream::scatter(adiosTimes);
restartIndex_ = -1;
if (restartType_ == restartTime)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment