mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: handle watching included files
This commit is contained in:
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -2766,30 +2766,42 @@ 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;
|
||||||
labelHashSet removedWatches(watchIndices);
|
if (UPstream::master())
|
||||||
|
|
||||||
for (const fileName& f : files)
|
|
||||||
{
|
{
|
||||||
const label index = findWatch(watchIndices, f);
|
// Switch off comms inside findWatch/addWatch etc.
|
||||||
|
const bool oldParRun = UPstream::parRun(false);
|
||||||
|
|
||||||
if (index == -1)
|
labelHashSet removedWatches(watchIndices);
|
||||||
{
|
|
||||||
newWatchIndices.append(addWatch(f));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Existing watch
|
|
||||||
newWatchIndices.append(watchIndices[index]);
|
|
||||||
removedWatches.erase(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove any unused watches
|
for (const fileName& f : files)
|
||||||
for (const label index : removedWatches)
|
{
|
||||||
{
|
const label index = findWatch(watchIndices, f);
|
||||||
removeWatch(watchIndices[index]);
|
|
||||||
|
if (index == -1)
|
||||||
|
{
|
||||||
|
newWatchIndices.push_back(addWatch(f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Existing watch
|
||||||
|
newWatchIndices.push_back(watchIndices[index]);
|
||||||
|
removedWatches.erase(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any unused watches
|
||||||
|
for (const label index : removedWatches)
|
||||||
|
{
|
||||||
|
removeWatch(watchIndices[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
UPstream::parRun(oldParRun);
|
||||||
}
|
}
|
||||||
|
Pstream::broadcast(newWatchIndices);
|
||||||
|
|
||||||
rio.watchIndices() = newWatchIndices;
|
rio.watchIndices() = newWatchIndices;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user