functionObjectFile: Use wordList rather than wordHashSet to maintain order

Change based on patch provided by Hassan Kassem
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1796
This commit is contained in:
Henry Weller
2015-08-05 17:38:31 +01:00
parent b9e2578cf6
commit 8234c04bc2
2 changed files with 18 additions and 26 deletions

View File

@ -33,12 +33,12 @@ License
const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing"; const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing";
Foam::label Foam::functionObjectFile::addChars = 7; Foam::label Foam::functionObjectFile::addChars = 7;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjectFile::initStream(Ostream& os) const void Foam::functionObjectFile::initStream(Ostream& os) const
{ {
os.setf(ios_base::scientific, ios_base::floatfield); os.setf(ios_base::scientific, ios_base::floatfield);
// os.precision(IOstream::defaultPrecision());
os.width(charWidth()); os.width(charWidth());
} }
@ -58,7 +58,7 @@ Foam::fileName Foam::functionObjectFile::baseFileDir() const
baseDir = baseDir/outputPrefix; baseDir = baseDir/outputPrefix;
} }
// append mesh name if not default region // Append mesh name if not default region
if (isA<polyMesh>(obr_)) if (isA<polyMesh>(obr_))
{ {
const polyMesh& mesh = refCast<const polyMesh>(obr_); const polyMesh& mesh = refCast<const polyMesh>(obr_);
@ -85,18 +85,16 @@ void Foam::functionObjectFile::createFiles()
const word startTimeName = const word startTimeName =
obr_.time().timeName(obr_.time().startTime().value()); obr_.time().timeName(obr_.time().startTime().value());
label i = 0; forAll(names_, i)
forAllConstIter(wordHashSet, names_, iter)
{ {
if (!filePtrs_.set(i)) if (!filePtrs_.set(i))
{ {
fileName outputDir(baseFileDir()/prefix_/startTimeName); fileName outputDir(baseFileDir()/prefix_/startTimeName);
mkDir(outputDir); mkDir(outputDir);
word fName(iter.key()); word fName(names_[i]);
// check if file already exists // Check if file already exists
IFstream is(outputDir/(fName + ".dat")); IFstream is(outputDir/(fName + ".dat"));
if (is.good()) if (is.good())
{ {
@ -109,7 +107,6 @@ void Foam::functionObjectFile::createFiles()
writeFileHeader(i); writeFileHeader(i);
i++;
} }
} }
} }
@ -117,9 +114,7 @@ void Foam::functionObjectFile::createFiles()
void Foam::functionObjectFile::writeFileHeader(const label i) void Foam::functionObjectFile::writeFileHeader(const label i)
{ {}
// do nothing
}
void Foam::functionObjectFile::write() void Foam::functionObjectFile::write()
@ -131,12 +126,12 @@ void Foam::functionObjectFile::write()
void Foam::functionObjectFile::resetNames(const wordList& names) void Foam::functionObjectFile::resetNames(const wordList& names)
{ {
names_.clear(); names_.clear();
names_.insert(names); names_.append(names);
if (Pstream::master()) if (Pstream::master())
{ {
filePtrs_.clear(); filePtrs_.clear();
filePtrs_.setSize(names_.toc().size()); filePtrs_.setSize(names_.size());
createFiles(); createFiles();
} }
@ -146,7 +141,7 @@ void Foam::functionObjectFile::resetNames(const wordList& names)
void Foam::functionObjectFile::resetName(const word& name) void Foam::functionObjectFile::resetName(const word& name)
{ {
names_.clear(); names_.clear();
names_.insert(name); names_.append(name);
if (Pstream::master()) if (Pstream::master())
{ {
@ -192,14 +187,13 @@ Foam::functionObjectFile::functionObjectFile
filePtrs_() filePtrs_()
{ {
names_.clear(); names_.clear();
names_.insert(name); names_.append(name);
if (Pstream::master()) if (Pstream::master())
{ {
filePtrs_.clear(); filePtrs_.clear();
filePtrs_.setSize(1); filePtrs_.setSize(1);
// cannot create files - need to access virtual function // Cannot create files - need to access virtual function
} }
} }
@ -217,14 +211,13 @@ Foam::functionObjectFile::functionObjectFile
filePtrs_() filePtrs_()
{ {
names_.clear(); names_.clear();
names_.insert(names); names_.append(names);
if (Pstream::master()) if (Pstream::master())
{ {
filePtrs_.clear(); filePtrs_.clear();
filePtrs_.setSize(names_.size()); filePtrs_.setSize(names_.size());
// cannot create files - need to access virtual function // Cannot create files - need to access virtual function
} }
} }
@ -237,7 +230,7 @@ Foam::functionObjectFile::~functionObjectFile()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordHashSet& Foam::functionObjectFile::names() const const Foam::wordList& Foam::functionObjectFile::names() const
{ {
return names_; return names_;
} }

View File

@ -2,7 +2,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) 2012-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -57,8 +57,6 @@ namespace Foam
class functionObjectFile class functionObjectFile
{ {
private:
// Private data // Private data
//- Reference to the database //- Reference to the database
@ -68,7 +66,7 @@ private:
const word prefix_; const word prefix_;
//- File names //- File names
wordHashSet names_; wordList names_;
//- File pointer //- File pointer
PtrList<OFstream> filePtrs_; PtrList<OFstream> filePtrs_;
@ -120,6 +118,7 @@ public:
//- Additional characters for writing //- Additional characters for writing
static label addChars; static label addChars;
// Constructors // Constructors
//- Construct null //- Construct null
@ -149,7 +148,7 @@ public:
// Member Functions // Member Functions
//- Return const access to the names //- Return const access to the names
const wordHashSet& names() const; const wordList& names() const;
//- Return access to the file (if only 1) //- Return access to the file (if only 1)
OFstream& file(); OFstream& file();