Commit c4aebc3c authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: avoid double write triggering in writeObjects functionObject

- in the previous version, a specification such as (U "U.*")
  would have selected the field name twice for writing
parent 87523aca
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -26,6 +26,7 @@ License ...@@ -26,6 +26,7 @@ License
#include "writeObjects.H" #include "writeObjects.H"
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "ListOps.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
...@@ -127,25 +128,33 @@ bool Foam::functionObjects::writeObjects::write() ...@@ -127,25 +128,33 @@ bool Foam::functionObjects::writeObjects::write()
obr_.time().writeTimeDict(); obr_.time().writeTimeDict();
} }
DynamicList<word> allNames(obr_.toc().size()); // Get selection
for (const wordRe& objName : objectNames_) const wordList selectedNames(obr_.sortedNames<regIOobject>(objectNames_));
{
wordList names(obr_.names<regIOobject>(objName)); // Warning if anything was missed
bitSet missed(objectNames_.size());
if (names.size()) label index = 0;
for (const wordRe& select : objectNames_)
{
if (!ListOps::found(selectedNames, select))
{ {
allNames.append(std::move(names)); missed.set(index);
} }
else ++index;
}
if (missed.any())
{ {
WarningInFunction WarningInFunction
<< "Object " << objName << " not found in " << "No corresponding selection for "
<< "database. Available objects:" << nl << obr_.sortedToc() << flatOutput(subset(missed, objectNames_)) << nl
<< "Available objects in database:"
<< nl << obr_.sortedToc()
<< endl; << endl;
} }
}
for (const word& objName : allNames) for (const word& objName : selectedNames)
{ {
regIOobject& obj = obr_.lookupObjectRef<regIOobject>(objName); regIOobject& obj = obr_.lookupObjectRef<regIOobject>(objName);
...@@ -181,6 +190,9 @@ bool Foam::functionObjects::writeObjects::write() ...@@ -181,6 +190,9 @@ bool Foam::functionObjects::writeObjects::write()
<< ". Valid writeOption types are " << ". Valid writeOption types are "
<< writeOptionNames_ << writeOptionNames_
<< exit(FatalError); << exit(FatalError);
continue;
break;
} }
} }
......
Supports Markdown
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