Commit d765375a 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 3a8b4999
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / 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
This file is part of OpenFOAM.
......@@ -26,6 +26,7 @@ License
#include "writeObjects.H"
#include "Time.H"
#include "polyMesh.H"
#include "ListOps.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -127,25 +128,33 @@ bool Foam::functionObjects::writeObjects::write()
obr_.time().writeTimeDict();
}
DynamicList<word> allNames(obr_.toc().size());
for (const wordRe& objName : objectNames_)
{
wordList names(obr_.names<regIOobject>(objName));
// Get selection
const wordList selectedNames(obr_.sortedNames<regIOobject>(objectNames_));
if (names.size())
{
allNames.append(std::move(names));
}
else
// Warning if anything was missed
bitSet missed(objectNames_.size());
label index = 0;
for (const wordRe& select : objectNames_)
{
if (!ListOps::found(selectedNames, select))
{
WarningInFunction
<< "Object " << objName << " not found in "
<< "database. Available objects:" << nl << obr_.sortedToc()
<< endl;
missed.set(index);
}
++index;
}
for (const word& objName : allNames)
if (missed.any())
{
WarningInFunction
<< "No corresponding selection for "
<< flatOutput(subset(missed, objectNames_)) << nl
<< "Available objects in database:"
<< nl << obr_.sortedToc()
<< endl;
}
for (const word& objName : selectedNames)
{
regIOobject& obj = obr_.lookupObjectRef<regIOobject>(objName);
......@@ -181,6 +190,9 @@ bool Foam::functionObjects::writeObjects::write()
<< ". Valid writeOption types are "
<< writeOptionNames_
<< exit(FatalError);
continue;
break;
}
}
......
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