ENH: handle watching included files

This commit is contained in:
mattijs
2022-11-24 09:00:00 +00:00
committed by Andrew Heather
parent bcd873ccfe
commit aec4ba30a3
3 changed files with 95 additions and 38 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,12 +27,13 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "includeEntry.H" #include "includeEntry.H"
#include "addToMemberFunctionSelectionTable.H"
#include "stringOps.H" #include "stringOps.H"
#include "IFstream.H" #include "IFstream.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "Time.H" #include "UPstream.H"
#include "fileOperation.H" #include "fileOperation.H"
#include "regIOobject.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -133,6 +134,15 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is Istream& is
) )
{ {
const auto* rioPtr = isA<regIOobject>(parentDict.topDict());
const label oldComm
(
rioPtr && rioPtr->global()
? fileHandler().comm(UPstream::worldComm)
: fileHandler().comm()
);
const fileName rawName(is); const fileName rawName(is);
const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); const fileName fName(resolveFile(is.name().path(), rawName, parentDict));
@ -148,20 +158,19 @@ bool Foam::functionEntries::includeEntry::execute
} }
// Add watch on included file // Add watch on included file
const dictionary& top = parentDict.topDict(); if (rioPtr)
if (isA<regIOobject>(top))
{ {
regIOobject& rio = const_cast<regIOobject&> const_cast<regIOobject&>(*rioPtr).addWatch(fName);
(
dynamic_cast<const regIOobject&>(top)
);
rio.addWatch(fName);
} }
parentDict.read(ifs); parentDict.read(ifs);
fileHandler().comm(oldComm);
return true; return true;
} }
fileHandler().comm(oldComm);
if (!mandatory) if (!mandatory)
{ {
return true; // Never fails if optional return true; // Never fails if optional
@ -185,6 +194,15 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is Istream& is
) )
{ {
const auto* rioPtr = isA<regIOobject>(parentDict.topDict());
const label oldComm
(
rioPtr && rioPtr->global()
? fileHandler().comm(UPstream::worldComm)
: fileHandler().comm()
);
const fileName rawName(is); const fileName rawName(is);
const fileName fName(resolveFile(is.name().path(), rawName, parentDict)); const fileName fName(resolveFile(is.name().path(), rawName, parentDict));
@ -200,20 +218,19 @@ bool Foam::functionEntries::includeEntry::execute
} }
// Add watch on included file // Add watch on included file
const dictionary& top = parentDict.topDict(); if (rioPtr)
if (isA<regIOobject>(top))
{ {
regIOobject& rio = const_cast<regIOobject&> const_cast<regIOobject&>(*rioPtr).addWatch(fName);
(
dynamic_cast<const regIOobject&>(top)
);
rio.addWatch(fName);
} }
entry.read(parentDict, ifs); entry.read(parentDict, ifs);
fileHandler().comm(oldComm);
return true; return true;
} }
fileHandler().comm(oldComm);
if (!mandatory) if (!mandatory)
{ {
return true; // Never fails if optional return true; // Never fails if optional

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenFOAM Foundation Copyright (C) 2015-2017 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,12 +27,14 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "includeEtcEntry.H" #include "includeEtcEntry.H"
#include "addToMemberFunctionSelectionTable.H"
#include "etcFiles.H" #include "etcFiles.H"
#include "stringOps.H" #include "stringOps.H"
#include "IFstream.H" #include "IFstream.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "UPstream.H"
#include "fileOperation.H" #include "fileOperation.H"
#include "regIOobject.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -113,6 +115,15 @@ bool Foam::functionEntries::includeEtcEntry::execute
Istream& is Istream& is
) )
{ {
const regIOobject* rioPtr = isA<regIOobject>(parentDict.topDict());
const label oldComm
(
rioPtr && rioPtr->global()
? fileHandler().comm(UPstream::worldComm)
: fileHandler().comm()
);
const fileName rawName(is); const fileName rawName(is);
const fileName fName(resolveEtcFile(rawName, parentDict)); const fileName fName(resolveEtcFile(rawName, parentDict));
@ -127,9 +138,13 @@ bool Foam::functionEntries::includeEtcEntry::execute
Info<< fName << nl; Info<< fName << nl;
} }
parentDict.read(ifs); parentDict.read(ifs);
fileHandler().comm(oldComm);
return true; return true;
} }
fileHandler().comm(oldComm);
if (!mandatory) if (!mandatory)
{ {
return true; // Never fails if optional return true; // Never fails if optional
@ -153,6 +168,15 @@ bool Foam::functionEntries::includeEtcEntry::execute
Istream& is Istream& is
) )
{ {
const regIOobject* rioPtr = isA<regIOobject>(parentDict.topDict());
const label oldComm
(
rioPtr && rioPtr->global()
? fileHandler().comm(UPstream::worldComm)
: fileHandler().comm()
);
const fileName rawName(is); const fileName rawName(is);
const fileName fName(resolveEtcFile(rawName, parentDict)); const fileName fName(resolveEtcFile(rawName, parentDict));
@ -167,9 +191,13 @@ bool Foam::functionEntries::includeEtcEntry::execute
Info<< fName << nl; Info<< fName << nl;
} }
entry.read(parentDict, ifs); entry.read(parentDict, ifs);
fileHandler().comm(oldComm);
return true; return true;
} }
fileHandler().comm(oldComm);
if (!mandatory) if (!mandatory)
{ {
return true; // Never fails if optional return true; // Never fails if optional

View File

@ -2766,7 +2766,15 @@ void Foam::fileOperations::masterUncollatedFileOperation::addWatches
{ {
const labelList& watchIndices = rio.watchIndices(); const labelList& watchIndices = rio.watchIndices();
// Do on master and distribute effect to subprocs such that after
// all have consistent numbering & files
DynamicList<label> newWatchIndices; DynamicList<label> newWatchIndices;
if (UPstream::master())
{
// Switch off comms inside findWatch/addWatch etc.
const bool oldParRun = UPstream::parRun(false);
labelHashSet removedWatches(watchIndices); labelHashSet removedWatches(watchIndices);
for (const fileName& f : files) for (const fileName& f : files)
@ -2775,12 +2783,12 @@ void Foam::fileOperations::masterUncollatedFileOperation::addWatches
if (index == -1) if (index == -1)
{ {
newWatchIndices.append(addWatch(f)); newWatchIndices.push_back(addWatch(f));
} }
else else
{ {
// Existing watch // Existing watch
newWatchIndices.append(watchIndices[index]); newWatchIndices.push_back(watchIndices[index]);
removedWatches.erase(index); removedWatches.erase(index);
} }
} }
@ -2791,6 +2799,10 @@ void Foam::fileOperations::masterUncollatedFileOperation::addWatches
removeWatch(watchIndices[index]); removeWatch(watchIndices[index]);
} }
UPstream::parRun(oldParRun);
}
Pstream::broadcast(newWatchIndices);
rio.watchIndices() = newWatchIndices; rio.watchIndices() = newWatchIndices;
} }