From 06f22a9bf3eda6decf4d85a5b1cce50ddfe74138 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 6 Jun 2016 11:51:05 +0100 Subject: [PATCH 01/96] ENH: cleanup Ostream to ease usage (issue #254) - Include newline in beginBlock/endBlock, since this corresponds to the standard usage. The beginBlock now takes keyType instead of word. - Provide Ostream::writeEntry method to reduce clutter and simplify writing of entries. Before ====== os << indent << "name" << nl << indent << token::BEGIN_BLOCK << incrIndent << nl; os.writeKeyword("key1") << val1 << token::END_STATEMENT << nl; os.writeKeyword("key2") << val2 << token::END_STATEMENT << nl; os << decrIndent << indent << token::END_BLOCK << nl; After ===== os.beginBlock("name"); os.writeEntry("key1", val1); os.writeEntry("key2", val2); os.endBlock(); - For completeness, support inline use of various Ostream methods. For example, os << beginBlock; os.writeEntry("key1", val1); os.writeEntry("key2", val2); os << endBlock; - For those who wish to write in long form, can also use endEntry inline: os.beginBlock("name"); os.writeKeyword("key1") << val2 << endEntry; os.writeKeyword("key2") << val2 << endEntry; os.endBlock(); The endEntry encapsulates a semi-colon, newline combination. --- src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C | 20 ++++--- src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H | 58 ++++++++++++++++--- src/OpenFOAM/db/dictionary/dictionaryIO.C | 4 +- .../GeometricField/GeometricBoundaryField.C | 8 +-- src/OpenFOAM/global/profiling/profiling.C | 51 ++++++---------- .../global/profiling/profilingSysInfo.C | 21 ++----- .../global/profiling/profilingSysInfo.H | 14 ----- .../polyBoundaryMesh/polyBoundaryMesh.C | 4 +- .../meshes/primitiveShapes/plane/plane.C | 11 ++-- .../primitives/functions/Function1/CSV/CSV.C | 37 ++++-------- .../functions/Function1/Sine/Sine.C | 8 +-- .../functions/Function1/Square/Square.C | 10 ++-- .../functions/Function1/TableFile/TableFile.C | 9 +-- 13 files changed, 124 insertions(+), 131 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index 4131da7af4..754c5fb185 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -79,11 +79,9 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) } -Foam::Ostream& Foam::Ostream::beginBlock(const word& keyword) +Foam::Ostream& Foam::Ostream::beginBlock(const keyType& keyword) { - indent(); - write(keyword); - endl(); + indent(); write(keyword); write('\n'); beginBlock(); return *this; @@ -92,8 +90,7 @@ Foam::Ostream& Foam::Ostream::beginBlock(const word& keyword) Foam::Ostream& Foam::Ostream::beginBlock() { - indent(); - write(char(token::BEGIN_BLOCK)); + indent(); write(char(token::BEGIN_BLOCK)); write('\n'); incrIndent(); return *this; @@ -103,8 +100,15 @@ Foam::Ostream& Foam::Ostream::beginBlock() Foam::Ostream& Foam::Ostream::endBlock() { decrIndent(); - indent(); - write(char(token::END_BLOCK)); + indent(); write(char(token::END_BLOCK)); write('\n'); + + return *this; +} + + +Foam::Ostream& Foam::Ostream::endEntry() +{ + write(char(token::END_STATEMENT)); write('\n'); return *this; } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index 0bd02a5b55..1634689c64 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -154,33 +154,47 @@ public: return indentLevel_; } - //- Incrememt the indent level + //- Increment the indent level void incrIndent() { ++indentLevel_; } - //- Decrememt the indent level + //- Decrement the indent level void decrIndent(); //- Write the keyword followed by an appropriate indentation virtual Ostream& writeKeyword(const keyType&); //- Write begin block group with the given name - // Uses the appropriate indentation, - // does not include a trailing newline. - virtual Ostream& beginBlock(const word&); + // Increments indentation, adds newline. + virtual Ostream& beginBlock(const keyType&); //- Write begin block group without a name - // Uses the appropriate indentation, - // does not include a trailing newline. + // Increments indentation, adds newline. virtual Ostream& beginBlock(); //- Write end block group - // Uses the appropriate indentation, - // does not include a trailing newline. + // Decrements indentation, adds newline. virtual Ostream& endBlock(); + //- Write end entry (';') followed by newline. + virtual Ostream& endEntry(); + + //- Write a keyword/value entry. + // The following two are functionally equivalent: + // \code + // os.writeEntry(key, value); + // + // os.writeKeyword(key) << value << endEntry; + // \endcode + template + Ostream& writeEntry(const keyType& key, const T& value) + { + writeKeyword(key) << value; + return endEntry(); + } + // Stream state functions @@ -273,6 +287,32 @@ inline Ostream& endl(Ostream& os) } +//- Write begin block group without a name +// Increments indentation, adds newline. +inline Ostream& beginBlock(Ostream& os) +{ + os.beginBlock(); + return os; +} + + +//- Write end block group +// Decrements indentation, adds newline. +inline Ostream& endBlock(Ostream& os) +{ + os.endBlock(); + return os; +} + + +//- Write end entry (';') followed by newline. +inline Ostream& endEntry(Ostream& os) +{ + os.endEntry(); + return os; +} + + // Useful aliases for tab and newline characters static const char tab = '\t'; static const char nl = '\n'; diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index d2880798fc..b9db794b80 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -175,7 +175,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const if (subDict) { os << nl; - os.beginBlock() << nl; + os.beginBlock(); } forAllConstIter(IDLList, *this, iter) @@ -203,7 +203,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const if (subDict) { - os.endBlock() << endl; + os.endBlock() << flush; } } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index fe43d9225d..7e273aa9fd 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -569,16 +569,16 @@ template class PatchField, class GeoMesh> void Foam::GeometricField::Boundary:: writeEntry(const word& keyword, Ostream& os) const { - os.beginBlock(keyword) << nl; + os.beginBlock(keyword); forAll(*this, patchi) { - os.beginBlock(this->operator[](patchi).patch().name()) << nl; + os.beginBlock(this->operator[](patchi).patch().name()); os << this->operator[](patchi); - os.endBlock() << endl; + os.endBlock(); } - os.endBlock() << endl; + os.endBlock() << flush; // Check state of IOstream os.check diff --git a/src/OpenFOAM/global/profiling/profiling.C b/src/OpenFOAM/global/profiling/profiling.C index 6471022850..10c61852ad 100644 --- a/src/OpenFOAM/global/profiling/profiling.C +++ b/src/OpenFOAM/global/profiling/profiling.C @@ -41,17 +41,6 @@ Foam::label Foam::profiling::Information::nextId_(0); // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -// file-scope function -template -inline static void writeEntry -( - Foam::Ostream& os, const Foam::word& key, const T& value -) -{ - os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n'; -} - - Foam::label Foam::profiling::Information::getNextId() { return nextId_++; @@ -369,7 +358,7 @@ void Foam::profiling::Information::update(const scalar& elapsed) bool Foam::profiling::writeData(Ostream& os) const { - os.beginBlock("profiling") << nl; // FUTURE: without nl + os.beginBlock("profiling"); // Add extra new line between entries label nTrigger = 0; @@ -420,22 +409,22 @@ bool Foam::profiling::writeData(Ostream& os) const } } - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); if (sysInfo_) { os << nl; - os.beginBlock("sysInfo") << nl; // FUTURE: without nl + os.beginBlock("sysInfo"); sysInfo_->write(os); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); } if (cpuInfo_) { os << nl; - os.beginBlock("cpuInfo") << nl; // FUTURE: without nl + os.beginBlock("cpuInfo"); cpuInfo_->write(os); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); } if (memInfo_) @@ -443,10 +432,10 @@ bool Foam::profiling::writeData(Ostream& os) const memInfo_->update(); os << nl; - os.beginBlock("memInfo") << nl; // FUTURE: without nl + os.beginBlock("memInfo"); memInfo_->write(os); - writeEntry(os, "units", "kB"); - os.endBlock() << nl; // FUTURE: without nl + os.writeEntry("units", "kB"); + os.endBlock(); } return os; @@ -536,26 +525,24 @@ Foam::Ostream& Foam::profiling::Information::write { // write in dictionary format - os.beginBlock("trigger" + Foam::name(id_)) << nl; // FUTURE: without nl + os.beginBlock(word("trigger" + Foam::name(id_))); - // FUTURE: os.writeEntry(key, value); - - writeEntry(os, "id", id_); + os.writeEntry("id", id_); if (id_ != parent().id()) { - writeEntry(os, "parentId", parent().id()); + os.writeEntry("parentId", parent().id()); } - writeEntry(os, "description", description()); - writeEntry(os, "calls", calls() + (offset ? 1 : 0)); - writeEntry(os, "totalTime", totalTime() + elapsedTime); - writeEntry(os, "childTime", childTime() + childTimes); + os.writeEntry("description", description()); + os.writeEntry("calls", calls() + (offset ? 1 : 0)); + os.writeEntry("totalTime", totalTime() + elapsedTime); + os.writeEntry("childTime", childTime() + childTimes); if (maxMem_) { - writeEntry(os, "maxMem", maxMem_); + os.writeEntry("maxMem", maxMem_); } - writeEntry(os, "onStack", Switch(onStack())); + os.writeEntry("onStack", Switch(onStack())); - os.endBlock() << nl; // FUTURE: without nl + os.endBlock(); return os; } diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.C b/src/OpenFOAM/global/profiling/profilingSysInfo.C index 9b6ff2f34b..51b0601736 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.C +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.C @@ -29,17 +29,6 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -// file-scope function -template -inline static void writeEntry -( - Foam::Ostream& os, const Foam::word& key, const T& value -) -{ - os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n'; -} - - // file-scope function inline static void printEnv ( @@ -49,7 +38,7 @@ inline static void printEnv const std::string value = getEnv(envName); if (!value.empty()) { - writeEntry(os, key, value); + os.writeEntry(key, value); } } @@ -74,12 +63,12 @@ Foam::Ostream& Foam::profiling::sysInfo::write Ostream& os ) const { - writeEntry(os, "host", hostName(false)); // short name - writeEntry(os, "date", clock::dateTime()); + os.writeEntry("host", hostName(false)); // short name + os.writeEntry("date", clock::dateTime()); // compile-time information - writeEntry(os, "version", std::string(FOAMversion)); - writeEntry(os, "build", std::string(FOAMbuild)); + os.writeEntry("version", std::string(FOAMversion)); + os.writeEntry("build", std::string(FOAMbuild)); printEnv(os, "arch", "WM_ARCH"); printEnv(os, "compilerType", "WM_COMPILER_TYPE"); diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.H b/src/OpenFOAM/global/profiling/profilingSysInfo.H index 26201fac36..b2e84f888f 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.H +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.H @@ -51,12 +51,6 @@ class Ostream; class profiling::sysInfo { - // Private Static Data Members - - - // Private Data Members - - // Private Member Functions //- Disallow default bitwise copy construct @@ -72,9 +66,6 @@ protected: friend class profiling; - - // Member Functions - public: @@ -90,11 +81,6 @@ public: // Member Functions - // Access - - - // Edit - //- Update it with a new timing information void update(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index aa619792c3..edb37c727b 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1120,9 +1120,9 @@ bool Foam::polyBoundaryMesh::writeData(Ostream& os) const forAll(patches, patchi) { - os.beginBlock(patches[patchi].name()) << nl; + os.beginBlock(patches[patchi].name()); os << patches[patchi]; - os.endBlock() << endl; + os.endBlock(); } os << decrIndent << token::END_LIST; diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 06a08a3598..99539ee2c6 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -449,15 +449,14 @@ Foam::point Foam::plane::mirror(const point& p) const void Foam::plane::writeDict(Ostream& os) const { - os.writeKeyword("planeType") << "pointAndNormal" - << token::END_STATEMENT << nl; + os.writeEntry("planeType", "pointAndNormal"); - os.beginBlock("pointAndNormalDict") << nl; + os.beginBlock("pointAndNormalDict"); - os.writeKeyword("point") << point_ << token::END_STATEMENT << nl; - os.writeKeyword("normal") << normal_ << token::END_STATEMENT << nl; + os.writeEntry("point", point_); + os.writeEntry("normal", normal_); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index a929f868ee..9d2d858174 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -263,41 +263,28 @@ template void Foam::Function1Types::CSV::writeData(Ostream& os) const { Function1::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase::writeEntries(os); - os.writeKeyword("nHeaderLine") << nHeaderLine_ - << token::END_STATEMENT << nl; - os.writeKeyword("refColumn") << refColumn_ - << token::END_STATEMENT << nl; + os.writeEntry("nHeaderLine", nHeaderLine_); + os.writeEntry("refColumn", refColumn_); // Force writing labelList in ascii - os.writeKeyword("componentColumns"); - if (os.format() == IOstream::BINARY) - { - os.format(IOstream::ASCII); - os << componentColumns_; - os.format(IOstream::BINARY); - } - else - { - os << componentColumns_; - } - os << token::END_STATEMENT << nl; + const enum IOstream::streamFormat fmt = os.format(); + os.format(IOstream::ASCII); + os.writeEntry("componentColumns", componentColumns_); + os.format(fmt); - os.writeKeyword("separator") << string(separator_) - << token::END_STATEMENT << nl; - os.writeKeyword("mergeSeparators") << mergeSeparators_ - << token::END_STATEMENT << nl; - os.writeKeyword("fileName") << fName_ - << token::END_STATEMENT << nl; + os.writeEntry("separator", string(separator_)); + os.writeEntry("mergeSeparators", mergeSeparators_); + os.writeEntry("fileName", fName_); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index 85a7aefe04..a11acd4df8 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C @@ -89,17 +89,17 @@ template void Foam::Function1Types::Sine::writeData(Ostream& os) const { Function1::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); - os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; + os.writeEntry("t0", t0_); amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index 9c55e8800e..0e258bc30e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C @@ -102,18 +102,18 @@ template void Foam::Function1Types::Square::writeData(Ostream& os) const { Function1::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); - os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl; - os.writeKeyword("markSpace") << markSpace_ << token::END_STATEMENT << nl; + os.writeEntry("t0", t0_); + os.writeEntry("markSpace", markSpace_); amplitude_->writeData(os); frequency_->writeData(os); scale_->writeData(os); level_->writeData(os); - os.endBlock() << endl; + os.endBlock() << flush; } diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C index 414e616077..3682836999 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C @@ -78,16 +78,17 @@ template void Foam::Function1Types::TableFile::writeData(Ostream& os) const { Function1::writeData(os); - os << token::END_STATEMENT << nl; + os.endEntry(); - os.beginBlock(word(this->name() + "Coeffs")) << nl; + os.beginBlock(word(this->name() + "Coeffs")); // Note: for TableBase write the dictionary entries it needs but not // the values themselves TableBase::writeEntries(os); - os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl; - os.endBlock() << endl; + os.writeEntry("fileName", fName_); + + os.endBlock() << flush; } From 6d5db96ad9c7b513b401dadcaf4f06d6d51cb012 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 9 Jun 2016 18:33:56 +0100 Subject: [PATCH 02/96] ENH: subdict output with leading name (issue #255) - Introduce dictionary::writeEntries for better code-reuse. Before ====== os << nl << indent << "name"; dict.write(os); After ===== dict.write(os, "name"); --- .../test/dictionary/Test-dictionary.C | 11 ++++--- src/OpenFOAM/db/dictionary/dictionary.H | 10 +++++- .../dictionaryEntry/dictionaryEntryIO.C | 7 ++--- src/OpenFOAM/db/dictionary/dictionaryIO.C | 31 ++++++++++++++----- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/applications/test/dictionary/Test-dictionary.C b/applications/test/dictionary/Test-dictionary.C index 287c63db21..dc55b9902f 100644 --- a/applications/test/dictionary/Test-dictionary.C +++ b/applications/test/dictionary/Test-dictionary.C @@ -48,14 +48,13 @@ int main(int argc, char *argv[]) { dictionary dict; - dict.add("aaOPENMPIcc", 1); + dict.add(word("aa" + getEnv("WM_MPLIB") + "cc"), 16); string s("DDD${aa${WM_MPLIB}cc}EEE"); stringOps::inplaceExpand(s, dict, true, false); Info<< "variable expansion:" << s << endl; } - Info<< nl << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl @@ -65,7 +64,9 @@ int main(int argc, char *argv[]) { { dictionary dict1(IFstream("testDict")()); - Info<< "dict1: " << dict1 << nl + dict1.writeEntry("dict1", Info); + + Info<< nl << "toc: " << dict1.toc() << nl << "keys: " << dict1.keys() << nl << "patterns: " << dict1.keys(true) << endl; @@ -89,14 +90,14 @@ int main(int argc, char *argv[]) << "no = " << dict4.name() << " " << dict4.toc() << endl; } - IOobject::writeDivider(Info); { dictionary dict(IFstream("testDictRegex")()); dict.add(keyType("fooba[rz]", true), "anything"); - Info<< "dict:" << dict << nl + dict.writeEntry("testDictRegex", Info); + Info<< nl << "toc: " << dict.toc() << nl << "keys: " << dict.keys() << nl << "patterns: " << dict.keys(true) << endl; diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 8c4d544f4d..4a7c728437 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -503,6 +503,14 @@ public: // Write + //- Write sub-dictionary with the keyword as its header + void writeEntry(const keyType& keyword, Ostream&) const; + + //- Write dictionary entries. + // Optionally with extra new line between entries for + // "top-level" dictionaries + void writeEntries(Ostream&, const bool extraNewLine=false) const; + //- Write dictionary, normally with sub-dictionary formatting void write(Ostream&, const bool subDict=true) const; diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index 677d5beaac..0b2c5315ec 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,10 +68,7 @@ Foam::dictionaryEntry::dictionaryEntry void Foam::dictionaryEntry::write(Ostream& os) const { - // write keyword with indent but without trailing spaces - os.indent(); - os.write(keyword()); - dictionary::write(os); + dictionary::writeEntry(keyword(), os); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index b9db794b80..081068488f 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -170,14 +170,16 @@ Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict) // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * // -void Foam::dictionary::write(Ostream& os, bool subDict) const +void Foam::dictionary::writeEntry(const keyType& kw, Ostream& os) const { - if (subDict) - { - os << nl; - os.beginBlock(); - } + os.beginBlock(kw); + writeEntries(os); + os.endBlock() << flush; +} + +void Foam::dictionary::writeEntries(Ostream& os, const bool extraNewLine) const +{ forAllConstIter(IDLList, *this, iter) { const entry& e = *iter; @@ -185,8 +187,9 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const // Write entry os << e; - // Add extra new line between entries for "top-level" dictionaries - if (!subDict && parent() == dictionary::null && e != *last()) + // Add extra new line between entries for "top-level" dictionaries, + // but not after the last entry (looks ugly). + if (extraNewLine && parent() == dictionary::null && e != *last()) { os << nl; } @@ -200,6 +203,18 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const << endl; } } +} + + +void Foam::dictionary::write(Ostream& os, const bool subDict) const +{ + if (subDict) + { + os << nl; + os.beginBlock(); + } + + writeEntries(os, !subDict); if (subDict) { From cae7ce37f522b4a5aa9b8f5b217f0f6038ea697c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 1 Jul 2016 08:23:13 +0200 Subject: [PATCH 03/96] ENH: provide formatting version of Foam::name() (issue #253) - there are some cases in which the C-style sprintf is much more convenient, albeit problematic for buffer overwrites. Provide a formatting version of Foam::name() for language primitives that is buffer-safe. Returns a Foam::word, so that further output will be unquoted, but without any checking that the characters are indeed entirely valid word characters. Example use, i = 1234; s = Foam::name("%08d", i); produces '00001234' Alternative using string streams: std::ostringstream buf; buf.fill('0'); buf << setw(8) << i; s = buf.str(); Note that the format specification can also be slightly more complex: Foam::name("output%08d.vtk", i); Foam::name("timing=%.2fs", time); It remains the caller's responsibility to ensure that the format mask is valid. --- applications/test/string/Test-string.C | 42 ++++++++++- src/OpenFOAM/primitives/Scalar/Scalar.C | 16 ++++- src/OpenFOAM/primitives/Scalar/Scalar.H | 12 +++- src/OpenFOAM/primitives/ints/int32/int32.H | 19 ++++- src/OpenFOAM/primitives/ints/int32/int32IO.C | 15 ++-- src/OpenFOAM/primitives/ints/int64/int64.H | 19 ++++- src/OpenFOAM/primitives/ints/int64/int64IO.C | 13 ++-- src/OpenFOAM/primitives/ints/uint32/uint32.H | 21 +++++- .../primitives/ints/uint32/uint32IO.C | 13 ++-- src/OpenFOAM/primitives/ints/uint64/uint64.H | 21 +++++- .../primitives/ints/uint64/uint64IO.C | 13 ++-- .../primitives/strings/stringOps/stringOps.H | 25 ++++++- .../strings/stringOps/stringOpsTemplates.C | 69 +++++++++++++++++++ 13 files changed, 266 insertions(+), 32 deletions(-) create mode 100644 src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index f39be8c206..a8276c2926 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,6 +31,10 @@ Description #include "dictionary.H" #include "IOstreams.H" +#include "int.H" +#include "uint.H" +#include "scalar.H" + using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -118,6 +122,8 @@ int main(int argc, char *argv[]) Info<< "after replace: " << test2 << endl; } + cout<< "\nEnter some string to test:\n"; + string s; Sin.getLine(s); @@ -126,7 +132,39 @@ int main(int argc, char *argv[]) cout<< "output string with " << s2.length() << " characters\n"; cout<< "ostream<< >" << s2 << "<\n"; Info<< "Ostream<< >" << s2 << "<\n"; - Info<< "hash:" << hex << string::hash()(s2) << endl; + Info<< "hash:" << hex << string::hash()(s2) << dec << endl; + + cout<< "\ntest Foam::name()\n"; + + Info<< "hash: = " << Foam::name("0x%012X", string::hash()(s2)) << endl; + + // test formatting on int + { + label val = 25; + Info<<"val: " << val << "\n"; + + Info<< "int " << val << " as word >" + << Foam::name(val) << "< or " + << Foam::name("formatted >%08d<", val) << "\n"; + } + + // test formatting on scalar + { + scalar val = 3.1415926535897931; + Info<< "scalar " << val << " as word >" + << Foam::name(val) << "< or " + << Foam::name("formatted >%.9f<", val) << "\n"; + } + + // test formatting on uint + { + uint64_t val = 25000000ul; + Info<<"val: " << val << "\n"; + + Info<< "uint64 " << val << " as word >" + << Foam::name(val) << "< or " + << Foam::name("formatted >%08d<", val) << "\n"; + } Info<< "\nEnd\n" << endl; return 0; diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C index 0a3e09b0b1..a801378b21 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.C +++ b/src/OpenFOAM/primitives/Scalar/Scalar.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,6 +23,8 @@ License \*---------------------------------------------------------------------------*/ +#include "stringOps.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -62,6 +64,18 @@ word name(const Scalar val) } +word name(const char* fmt, const Scalar val) +{ + return stringOps::name(fmt, val); +} + + +word name(const std::string& fmt, const Scalar val) +{ + return stringOps::name(fmt, val); +} + + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Scalar readScalar(Istream& is) diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H index 4d8f29ff54..6b2213fa6a 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.H +++ b/src/OpenFOAM/primitives/Scalar/Scalar.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,6 +109,16 @@ public: word name(const Scalar); +//- Return a word representation of a Scalar, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const char* fmt, const Scalar); + + +//- Return a word representation of a Scalar, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const std::string& fmt, const Scalar); + + // Standard C++ transcendental functions transFunc(sqrt) diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H index de8baa2109..96c748b052 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.H +++ b/src/OpenFOAM/primitives/ints/int32/int32.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,7 +56,22 @@ class Ostream; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- Return a word representation of an int32 -word name(const int32_t); +inline word name(const int32_t val) +{ + // no stripping required + return word(std::to_string(val), false); +} + + +//- Return a word representation of an int32, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const char* fmt, const int32_t); + + +//- Return a word representation of an int32, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const std::string&, const int32_t); + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/ints/int32/int32IO.C b/src/OpenFOAM/primitives/ints/int32/int32IO.C index a8c972377d..c5023315f0 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32IO.C +++ b/src/OpenFOAM/primitives/ints/int32/int32IO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "int32.H" +#include "stringOps.H" #include "IOstreams.H" #include @@ -32,11 +33,15 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::word Foam::name(const int32_t val) +Foam::word Foam::name(const char* fmt, const int32_t val) { - std::ostringstream buf; - buf << val; - return buf.str(); + return stringOps::name(fmt, val); +} + + +Foam::word Foam::name(const std::string& fmt, const int32_t val) +{ + return stringOps::name(fmt, val); } diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H index 2bb5a05804..bcbcea38f7 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.H +++ b/src/OpenFOAM/primitives/ints/int64/int64.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,22 @@ class Ostream; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- Return a word representation of an int64 -word name(const int64_t); +inline word name(const int64_t val) +{ + // no stripping required + return word(std::to_string(val), false); +} + + +//- Return a word representation of an int64, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const char* fmt, const int64_t); + + +//- Return a word representation of an int64, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const std::string& fmt, const int64_t); + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index 89f14163a0..0523bb94cb 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "int64.H" +#include "stringOps.H" #include "IOstreams.H" #include @@ -32,11 +33,15 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::word Foam::name(const int64_t val) +Foam::word Foam::name(const char* fmt, const int64_t val) { - std::ostringstream buf; - buf << val; - return buf.str(); + return stringOps::name(fmt, val); +} + + +Foam::word Foam::name(const std::string& fmt, const int64_t val) +{ + return stringOps::name(fmt, val); } diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H index 34803c218f..469189e976 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.H +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,8 +55,23 @@ class Ostream; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Return a word representation of an uint32 -word name(const uint32_t); +//- Return a word representation of a uint32 +inline word name(const uint32_t val) +{ + // no stripping required + return word(std::to_string(val), false); +} + + +//- Return a word representation of a uint32, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const char* fmt, const uint32_t); + + +//- Return a word representation of a uint32, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const std::string& fmt, const uint32_t); + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C index 2746938d63..f88f5b1ad8 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C @@ -24,17 +24,22 @@ License \*---------------------------------------------------------------------------*/ #include "uint32.H" +#include "stringOps.H" #include "IOstreams.H" #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::word Foam::name(const uint32_t val) +Foam::word Foam::name(const char* fmt, const uint32_t val) { - std::ostringstream buf; - buf << val; - return buf.str(); + return stringOps::name(fmt, val); +} + + +Foam::word Foam::name(const std::string& fmt, const uint32_t val) +{ + return stringOps::name(fmt, val); } diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H index e1a742b6c2..2cf102e057 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.H +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,8 +59,23 @@ class Ostream; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Return a word representation of an uint64 -word name(const uint64_t); +//- Return a word representation of a uint64 +inline word name(const uint64_t val) +{ + // no stripping required + return word(std::to_string(val), false); +} + + +//- Return a word representation of a uint64_t, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const char* fmt, const uint64_t); + + +//- Return a word representation of a uint64_t, using printf-style formatter. +// The representation is not checked for valid word characters. +word name(const std::string& fmt, const uint64_t); + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C index be10f83b01..3e110d933a 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C @@ -24,17 +24,22 @@ License \*---------------------------------------------------------------------------*/ #include "uint64.H" +#include "stringOps.H" #include "IOstreams.H" #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::word Foam::name(const uint64_t val) +Foam::word Foam::name(const char* fmt, const uint64_t val) { - std::ostringstream buf; - buf << val; - return buf.str(); + return stringOps::name(fmt, val); +} + + +Foam::word Foam::name(const std::string& fmt, const uint64_t val) +{ + return stringOps::name(fmt, val); } diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index 3a72467bc9..fb408455f6 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +36,7 @@ SourceFiles #define stringOps_H #include "string.H" +#include "word.H" #include "dictionary.H" #include "HashTable.H" @@ -292,6 +293,21 @@ namespace stringOps string& inplaceTrim(string&); + //- Return a word representation of the primitive, + // using printf-style formatter. + // The representation is not checked for valid word characters - + // it is assumed that the caller knows what they are doing + template + Foam::word name(const char* fmt, const PrimitiveType& val); + + //- Return a word representation of the primitive, + // using printf-style formatter. + // The representation is not checked for valid word characters - + // it is assumed that the caller knows what they are doing + template + Foam::word name(const std::string& fmt, const PrimitiveType& val); + + } // End namespace stringOps @@ -299,6 +315,13 @@ namespace stringOps } // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "stringOpsTemplates.C" +#endif + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C b/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C new file mode 100644 index 0000000000..a3874aa88e --- /dev/null +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C @@ -0,0 +1,69 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// NOTE: with C++11 could consider variadic templates for a more general +// sprintf implementation + +template +Foam::word Foam::stringOps::name +( + const char* fmt, + const PrimitiveType& val +) +{ + // same concept as GNU/BSD asprintf() + // use snprintf with zero to determine the number of characters required + + int n = ::snprintf(0, 0, fmt, val); + if (n > 0) + { + char buf[n+1]; + ::snprintf(buf, n+1, fmt, val); + buf[n] = 0; + + // no stripping desired + return word(buf, false); + } + + return word::null; +} + + +template +Foam::word Foam::stringOps::name +( + const std::string& fmt, + const PrimitiveType& val +) +{ + return stringOps::name(fmt.c_str(), val); +} + + +// ************************************************************************* // From ce121c92dcd8dfdd08ac42e83d713d8e270c958b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 1 Jul 2016 09:09:50 +0200 Subject: [PATCH 04/96] STYLE: minor simplification of check for uniform contents --- .../Lists/CompactListList/CompactListListIO.C | 6 ++--- .../containers/Lists/FixedList/FixedListIO.C | 17 ++++++++------ src/OpenFOAM/containers/Lists/List/ListIO.C | 4 ++++ .../containers/Lists/PackedList/PackedList.C | 11 +++++----- .../Lists/UIndirectList/UIndirectListIO.C | 15 ++++++------- src/OpenFOAM/containers/Lists/UList/UListIO.C | 21 +++++++++++------- src/OpenFOAM/fields/Fields/Field/Field.C | 8 +++---- src/OpenFOAM/matrices/Matrix/MatrixIO.C | 22 +++++++++---------- 8 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C index 727e8803ac..5a001a1932 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C @@ -42,13 +42,13 @@ Foam::Istream& Foam::operator>>(Istream& is, CompactListList& lst) { is >> lst.offsets_ >> lst.m_; // Note: empty list gets output as two empty lists - if (lst.offsets_.size() == 0) + if (lst.offsets_.size()) { - lst.size_ = 0; + lst.size_ = lst.offsets_.size()-1; } else { - lst.size_ = lst.offsets_.size()-1; + lst.size_ = 0; } return is; } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 9119234ef6..31cf08ada6 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -118,6 +118,8 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& L) } else { + // contents are binary and contiguous + is.read(reinterpret_cast(L.data()), Size*sizeof(T)); is.fatalCheck @@ -167,12 +169,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (Size > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (Size > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -194,7 +194,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write end delimiter os << token::END_BLOCK; } - else if (Size <= 1 ||(Size < 11 && contiguous())) + else if (Size <= 1 || (Size < 11 && contiguous())) { // Write start delimiter os << token::BEGIN_LIST; @@ -202,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write contents forAll(L, i) { - if (i > 0) os << token::SPACE; + if (i) os << token::SPACE; os << L[i]; } @@ -226,6 +226,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) } else { + // Contents are binary and contiguous + + // write(...) includes surrounding start/end delimiters os.write(reinterpret_cast(L.cdata()), Size*sizeof(T)); } diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index d43fda22d7..bbc55ec10d 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -92,6 +92,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else { + // uniform content (delimiter == token::BEGIN_BLOCK) + T element; is >> element; @@ -113,6 +115,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else { + // contents are binary and contiguous + if (s) { is.read(reinterpret_cast(L.data()), s*sizeof(T)); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index 5e0487ebcd..6addd5d23e 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -407,12 +407,10 @@ Foam::Ostream& Foam::PackedList::write // Write list contents depending on data format if (os.format() == IOstream::ASCII) { - bool uniform = false; - - if (sz > 1 && !indexedOutput) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (sz > 1 && !indexedOutput); + if (uniform) { - uniform = true; - forAll(lst, i) { if (lst[i] != lst[0]) @@ -475,9 +473,12 @@ Foam::Ostream& Foam::PackedList::write } else { + // Contents are binary and contiguous + os << nl << sz << nl; if (sz) { + // write(...) includes surrounding start/end delimiters os.write ( reinterpret_cast(lst.storage().cdata()), diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C index 18f1f5fe94..3b52f8484c 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,12 +40,10 @@ Foam::Ostream& Foam::operator<< // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (L.size() > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (L.size() > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -99,14 +97,15 @@ Foam::Ostream& Foam::operator<< } else { - // this is annoying, and wasteful, but there's currently no alternative - + // Contents are binary and contiguous os << nl << L.size() << nl; if (L.size()) { + // This is annoying, and wasteful, but currently no alternative List lst = L(); + // write(...) includes surrounding start/end delimiters os.write ( reinterpret_cast(lst.cdata()), diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index e31b5dd2bc..cba400379f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,12 +65,10 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (L.size() > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (L.size() > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -100,7 +98,7 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) // Write contents forAll(L, i) { - if (i > 0) os << token::SPACE; + if (i) os << token::SPACE; os << L[i]; } @@ -124,10 +122,13 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) } else { + // Contents are binary and contiguous os << nl << L.size() << nl; + if (L.size()) { - os.write(reinterpret_cast(L.v_), L.byteSize()); + // write(...) includes surrounding start/end delimiters + os.write(reinterpret_cast(L.cdata()), L.byteSize()); } } @@ -208,6 +209,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) } else { + // uniform content (delimiter == token::BEGIN_BLOCK) + T element; is >> element; @@ -229,6 +232,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) } else { + // contents are binary and contiguous + if (s) { is.read(reinterpret_cast(L.data()), s*sizeof(T)); diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index 1c021bcca2..997135bc34 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -727,12 +727,10 @@ void Foam::Field::writeEntry(const word& keyword, Ostream& os) const { os.writeKeyword(keyword); - bool uniform = false; - - if (this->size() && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (this->size() && contiguous()); + if (uniform) { - uniform = true; - forAll(*this, i) { if (this->operator[](i) != this->operator[](0)) diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index 154a066914..b965bb37d7 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -160,15 +160,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) { if (mn) { - bool uniform = false; - const Type* v = M.v_; - if (mn > 1 && contiguous()) + // can the contents be considered 'uniform' (ie, identical) + bool uniform = (mn > 1 && contiguous()); + if (uniform) { - uniform = true; - - for (label i=0; i& M) if (uniform) { - // Write size of list and start contents delimiter + // Write start delimiter os << token::BEGIN_BLOCK; - // Write list contents + // Write contents os << v[0]; - // Write end of contents delimiter + // Write end delimiter os << token::END_BLOCK; } else if (mn < 10 && contiguous()) { - // Write size of list and start contents delimiter + // Write start contents delimiter os << token::BEGIN_LIST; label k = 0; @@ -204,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) // Write row for (label j=0; j< M.n(); j++) { - if (j > 0) os << token::SPACE; + if (j) os << token::SPACE; os << v[k++]; } @@ -216,7 +214,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) } else { - // Write size of list and start contents delimiter + // Write start contents delimiter os << nl << token::BEGIN_LIST; label k = 0; From 9965c5006c794f262a531de0c8d9dc2a6222adbe Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 1 Jul 2016 09:55:51 +0200 Subject: [PATCH 05/96] STYLE: minor improvement when writing list entry --- .../containers/Lists/FixedList/FixedListIO.C | 8 +++----- src/OpenFOAM/containers/Lists/UList/UList.H | 2 +- src/OpenFOAM/containers/Lists/UList/UListIO.C | 15 ++++++--------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 31cf08ada6..e6ba7a4678 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -138,12 +138,10 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& L) template void Foam::FixedList::writeEntry(Ostream& os) const { - if - ( - token::compound::isCompound("List<" + word(pTraits::typeName) + '>') - ) + const word tag = "List<" + word(pTraits::typeName) + '>'; + if (token::compound::isCompound(tag)) { - os << word("List<" + word(pTraits::typeName) + '>') << " "; + os << tag << " "; } os << *this; diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index ee574c33ec..719df10a0f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -219,7 +219,7 @@ public: //- Copy elements of the given UList void deepCopy(const UList&); - //- Write the UList as a dictionary entry + //- Write the UList with its compound type void writeEntry(Ostream&) const; //- Write the UList as a dictionary entry with keyword diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index cba400379f..3d78024079 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -34,16 +34,13 @@ License template void Foam::UList::writeEntry(Ostream& os) const { - if - ( - size() - && token::compound::isCompound - ( - "List<" + word(pTraits::typeName) + '>' - ) - ) + if (size()) { - os << word("List<" + word(pTraits::typeName) + '>') << " "; + const word tag = "List<" + word(pTraits::typeName) + '>'; + if (token::compound::isCompound(tag)) + { + os << tag << ' '; + } } os << *this; From 9a82743d32efe77f00c51aba45bfb41c4dd9c503 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 29 Sep 2016 12:00:00 +0200 Subject: [PATCH 06/96] STYLE: bump to v1609+ for foundation merge version --- wmake/rules/General/general | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wmake/rules/General/general b/wmake/rules/General/general index 4fb68a01d7..f7e42cbef3 100644 --- a/wmake/rules/General/general +++ b/wmake/rules/General/general @@ -1,5 +1,5 @@ #-------------------------------*- makefile -*--------------------------------- -WM_VERSION = OPENFOAM_PLUS=1606 +WM_VERSION = OPENFOAM_PLUS=1609 AR = ar ARFLAGS = cr From fae40c5def3fb839238d38a800564dd6384a427b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 29 Sep 2016 14:10:49 +0200 Subject: [PATCH 07/96] STYLE: use POSIX 'unset -f' for functions (affects dash) --- etc/config.sh/aliases | 6 +++--- etc/config.sh/unset | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/config.sh/aliases b/etc/config.sh/aliases index 2e0f67146b..3fc8eb96db 100644 --- a/etc/config.sh/aliases +++ b/etc/config.sh/aliases @@ -70,7 +70,7 @@ alias run='cd $FOAM_RUN' # Refresh the environment # ~~~~~~~~~~~~~~~~~~~~~~~ # For backward-compatibility unalias wmRefresh if it is defined as an alias -[ "$(type -t wmRefresh)" = "alias" ] && unalias wmRefresh || unset wmRefresh +[ "$(type -t wmRefresh)" = "alias" ] && unalias wmRefresh || unset -f wmRefresh wmRefresh() { wmProjectDir=$WM_PROJECT_DIR @@ -82,7 +82,7 @@ wmRefresh() # Change OpenFOAM version # ~~~~~~~~~~~~~~~~~~~~~~~ -unset foamVersion +unset -f foamVersion foamVersion() { if [ "$1" ]; then @@ -99,7 +99,7 @@ foamVersion() # Change ParaView version # ~~~~~~~~~~~~~~~~~~~~~~~ -unset foamPV +unset -f foamPV foamPV() { . $WM_PROJECT_DIR/etc/config.sh/paraview ParaView_VERSION=${1:-none} diff --git a/etc/config.sh/unset b/etc/config.sh/unset index 7bce3ddf0d..a0e6be5bc5 100644 --- a/etc/config.sh/unset +++ b/etc/config.sh/unset @@ -183,9 +183,9 @@ unalias util unalias tut unalias run -unset wmRefresh -unset foamVersion -unset foamPV +unset -f wmRefresh +unset -f foamVersion +unset -f foamPV #------------------------------------------------------------------------------ From 787b19c4e4a37a1191d7d26308b62940f413f860 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 12 Jul 2016 17:19:06 +0200 Subject: [PATCH 08/96] STYLE: cleanup compiler settings (issue #176) - export/setenv WM_COMPILER_TYPE as suggested by Mattijs. - for overall consistency, don't carp about an unset WM_COMPILER_TYPE, since this would only be on the first instance (prior to the export/setenv) and would be confusing about why/when this message may occur. - reduce clutter: only use (system|ThirdParty) for WM_COMPILER_TYPE. Drop the old 'OpenFOAM' setting for WM_COMPILER_TYPE, which was transitional in early 2011. - make the error messages more meaningful --- etc/bashrc | 2 +- etc/config.csh/compiler | 1 - etc/config.csh/settings | 46 ++++++++++++++++++++------------------ etc/config.sh/compiler | 2 +- etc/config.sh/settings | 49 +++++++++++++++++++---------------------- etc/cshrc | 2 +- 6 files changed, 50 insertions(+), 52 deletions(-) diff --git a/etc/bashrc b/etc/bashrc index 81bf28feaf..84e38d9e7e 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -57,7 +57,7 @@ export FOAM_INST_DIR=$HOME/$WM_PROJECT # $FOAM_INST_DIR/site/$WM_PROJECT_VERSION or $FOAM_INST_DIR/site #- Compiler location: -# WM_COMPILER_TYPE= system | ThirdParty (OpenFOAM) +# WM_COMPILER_TYPE= system | ThirdParty export WM_COMPILER_TYPE=system #- Compiler: diff --git a/etc/config.csh/compiler b/etc/config.csh/compiler index 3e28c20b71..7d8f757b23 100644 --- a/etc/config.csh/compiler +++ b/etc/config.csh/compiler @@ -31,7 +31,6 @@ #------------------------------------------------------------------------------ switch ("$WM_COMPILER_TYPE") -case OpenFOAM: case ThirdParty: # Default versions of GMP, MPFR and MPC, override as necessary set gmp_version=gmp-system diff --git a/etc/config.csh/settings b/etc/config.csh/settings index 1cee3fcd91..659b4c5ae2 100644 --- a/etc/config.csh/settings +++ b/etc/config.csh/settings @@ -204,14 +204,9 @@ _foamAddLib ${FOAM_USER_LIBBIN}:${FOAM_SITE_LIBBIN}:${FOAM_LIBBIN}:${FOAM_EXT_L unset gcc_version gmp_version mpfr_version mpc_version unsetenv GMP_ARCH_PATH MPFR_ARCH_PATH - -# Location of compiler installation -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if ( ! $?WM_COMPILER_TYPE ) then - setenv WM_COMPILER_TYPE system - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" - echo " WM_COMPILER_TYPE not set, using '$WM_COMPILER_TYPE'" -endif +# Compiler installation - default to system +# ~~~~~~~~~~~~~~~~~~~~~ +if ( ! $?WM_COMPILER_TYPE ) setenv WM_COMPILER_TYPE system # Load configured compiler versions, regardless of the compiler type # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -235,13 +230,16 @@ case ThirdParty: # Check that the compiler directory can be found if ( ! -d "$gccDir" ) then - echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" - echo " Cannot find $gccDir installation." - echo " Please install this compiler version or if you wish to" \ - " use the system compiler," - echo " change the 'WM_COMPILER_TYPE' setting to 'system'" - echo + cat << GCC_NOT_FOUND +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.csh/settings: +Cannot find '$WM_COMPILER' compiler installation + $gccDir + + Either install this compiler version, or use the system compiler by setting + WM_COMPILER_TYPE to 'system' in \$WM_PROJECT_DIR/etc/cshrc. +=============================================================================== +GCC_NOT_FOUND endif _foamAddMan $gccDir/man @@ -268,18 +266,22 @@ case ThirdParty: echo " ${gccDir:t} (${gmpDir:t} ${mpfrDir:t} ${mpcDir:t})" endif endif + if ( $?clang_version ) then set clangDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$clang_version # Check that the compiler directory can be found if ( ! -d "$clangDir" ) then - echo - echo "Warning in $WM_PROJECT_DIR/etc/config.csh/settings:" - echo " Cannot find $clangDir installation." - echo " Please install this compiler version or if you wish to" \ - " use the system compiler," - echo " change the 'WM_COMPILER_TYPE' setting to 'system'" - echo + cat << CLANG_NOT_FOUND +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.csh/settings: +Cannot find '$WM_COMPILER' compiler installation + $clangDir + + Either install this compiler version, or use the system compiler by setting + WM_COMPILER_TYPE to 'system' in \$WM_PROJECT_DIR/etc/cshrc. +=============================================================================== +CLANG_NOT_FOUND endif _foamAddMan $clangDir/man diff --git a/etc/config.sh/compiler b/etc/config.sh/compiler index 5cfc75e56c..0f27fab8a6 100644 --- a/etc/config.sh/compiler +++ b/etc/config.sh/compiler @@ -31,7 +31,7 @@ #------------------------------------------------------------------------------ case "$WM_COMPILER_TYPE" in -OpenFOAM | ThirdParty) +ThirdParty) # Default versions of GMP, MPFR and MPC, override as necessary gmp_version=gmp-system mpfr_version=mpfr-system diff --git a/etc/config.sh/settings b/etc/config.sh/settings index e67bf5126f..4e457c15c0 100644 --- a/etc/config.sh/settings +++ b/etc/config.sh/settings @@ -206,14 +206,9 @@ _foamAddLib $FOAM_USER_LIBBIN:$FOAM_SITE_LIBBIN:$FOAM_LIBBIN:$FOAM_EXT_LIBBIN:$ unset gcc_version gmp_version mpfr_version mpc_version unset GMP_ARCH_PATH MPFR_ARCH_PATH -# Location of compiler installation -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if [ -z "$WM_COMPILER_TYPE" ] -then - WM_COMPILER_TYPE=system - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 - echo " WM_COMPILER_TYPE not set, using '$WM_COMPILER_TYPE'" 1>&2 -fi +# Compiler installation - default to system +# ~~~~~~~~~~~~~~~~~~~~~ +: ${WM_COMPILER_TYPE:=system}; export WM_COMPILER_TYPE # Load configured compiler versions, regardless of the compiler type # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -232,15 +227,16 @@ OpenFOAM | ThirdParty) mpcDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/${mpc_version:-mpc-system} # Check that the compiler directory can be found - [ -d "$gccDir" ] || { - echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 - echo " Cannot find $gccDir installation." 1>&2 - echo " Please install this compiler version or if you wish to" \ - " use the system compiler," 1>&2 - echo " change the 'WM_COMPILER_TYPE' setting to 'system'" 1>&2 - echo - } + [ -d "$gccDir" ] || cat << GCC_NOT_FOUND 1>&2 +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.sh/settings: +Cannot find '$WM_COMPILER' compiler installation + $gccDir + + Either install this compiler version, or use the system compiler by setting + WM_COMPILER_TYPE to 'system' in \$WM_PROJECT_DIR/etc/bashrc. +=============================================================================== +GCC_NOT_FOUND _foamAddMan $gccDir/man _foamAddPath $gccDir/bin @@ -276,15 +272,16 @@ OpenFOAM | ThirdParty) clangDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$clang_version # Check that the compiler directory can be found - [ -d "$clangDir" ] || { - echo 1>&2 - echo "Warning in $WM_PROJECT_DIR/etc/config.sh/settings:" 1>&2 - echo " Cannot find $clangDir installation." 1>&2 - echo " Please install this compiler version or if you wish to" \ - " use the system compiler," 1>&2 - echo " change the 'WM_COMPILER_TYPE' setting to 'system'" 1>&2 - echo 1>&2 - } + [ -d "$clangDir" ] || cat << CLANG_NOT_FOUND 1>&2 +=============================================================================== +Warning in $WM_PROJECT_DIR/etc/config.sh/settings: +Cannot find '$WM_COMPILER' compiler installation + $clangDir + + Either install this compiler version, or use the system compiler by setting + WM_COMPILER_TYPE to 'system' in \$WM_PROJECT_DIR/etc/bashrc. +=============================================================================== +CLANG_NOT_FOUND _foamAddMan $clangDir/share/man _foamAddPath $clangDir/bin diff --git a/etc/cshrc b/etc/cshrc index 984db6bfef..8f509b2839 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -57,7 +57,7 @@ echo $FOAM_INST_DIR # $FOAM_INST_DIR/site/$WM_PROJECT_VERSION or $FOAM_INST_DIR/site #- Compiler location: -# WM_COMPILER_TYPE = system | ThirdParty (OpenFOAM) +# WM_COMPILER_TYPE = system | ThirdParty setenv WM_COMPILER_TYPE system #- Compiler: From 9e2259c19cf394d4626d113e21894cd50c50cbeb Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 13 Jul 2016 09:57:58 +0200 Subject: [PATCH 09/96] STYLE: clean out clutter in paraview config files (issue #176) Now reduced to 3 environment variables: ParaView_DIR - paraview installation directory ParaView_INCLUDE_DIR - paraview include directory PV_PLUGIN_PATH - paraview plugin directory for OpenFOAM modules Previously also had (ParaView_MAJOR, ParaView_VERSION). ThirdParty makeParaView adjusted accordingly. ENH: improved configuration possibility for non-ThirdParty paraview installation. BUG: csh foamPV alias was completely incorrect. --- etc/config.csh/aliases | 2 +- etc/config.csh/paraview | 154 +++++++++++++++++++---------------- etc/config.sh/aliases | 5 +- etc/config.sh/paraview | 174 +++++++++++++++++++++------------------- 4 files changed, 179 insertions(+), 156 deletions(-) diff --git a/etc/config.csh/aliases b/etc/config.csh/aliases index 33bb0e4a98..f04b6e8114 100644 --- a/etc/config.csh/aliases +++ b/etc/config.csh/aliases @@ -82,7 +82,7 @@ alias foamVersion \ # Change ParaView version # ~~~~~~~~~~~~~~~~~~~~~~~ alias foamPV \ - 'source $WM_PROJECT_DIR/etc/config.csh/paraview ParaView_VERSION=\!*; echo paraview-$ParaView_VERSION' + 'source $WM_PROJECT_DIR/etc/config.csh/paraview ParaView_VERSION=\!*; echo ${ParaView_DIR:t}' #------------------------------------------------------------------------------ diff --git a/etc/config.csh/paraview b/etc/config.csh/paraview index 16fa58d48a..ba718b0c0c 100644 --- a/etc/config.csh/paraview +++ b/etc/config.csh/paraview @@ -3,7 +3,7 @@ # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | +# \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -25,40 +25,50 @@ # config.csh/paraview # # Description -# Setup file for paraview-[3-5].x +# Setup file for paraview (and cmake) # Sourced from OpenFOAM-/etc/cshrc or from foamPV alias # -# Note -# The env. variables 'ParaView_DIR' and 'ParaView_MAJOR' -# are required for building plugins +# If using system-wide installation for cmake, use the following settings: # +# cmake_version=cmake-system +# +# Note +# The following env. variables are required for building plugins: +# ParaView_DIR +# ParaView_INCLUDE_DIR +# PV_PLUGIN_PATH +# +# If using a central installation not located under ThirdParty, you will +# need to set some environment values directly. For example, +# +# setenv ParaView_DIR /opt/paraview/paraview-5.0.1 +# setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/paraview-5.0 +# setenv PV_PLUGIN_PATH $FOAM_LIBBIN/paraview-5.0 +# +# setenv PATH ${ParaView_DIR}/bin:${PATH} +# setenv LD_LIBRARY_PATH ${ParaView_DIR}/lib/paraview-5.0:${LD_LIBRARY_PATH} +# unsetenv ParaView_VERSION # avoid using ThirdParty settings +# +#------------------------------------------------------------------------------ + +setenv ParaView_VERSION 5.0.1 +setenv ParaView_MAJOR detect # Automatically determine major version + +set cmake_version=cmake-system + #------------------------------------------------------------------------------ # Clean the PATH set cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$ParaView_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"` if ( $status == 0 ) setenv PATH $cleaned -# Determine the cmake to be used +# Environment for ThirdParty cmake unsetenv CMAKE_HOME -foreach cmake ( cmake-3.2.1 cmake-2.8.12.1 cmake-2.8.8 cmake-2.8.4 cmake-2.8.3 cmake-2.8.1 ) - set cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake - if ( -r $cmake ) then - setenv CMAKE_HOME $cmake - setenv PATH ${CMAKE_HOME}/bin:${PATH} - break - endif -end - -#- ParaView version, automatically determine major version: -#setenv ParaView_VERSION 3.12.0 -#setenv ParaView_VERSION 4.0.1 -#setenv ParaView_VERSION 4.1.0 -#setenv ParaView_VERSION 4.3.1 -#setenv ParaView_VERSION 4.4.0 -#setenv ParaView_VERSION 5.0.0 -setenv ParaView_VERSION 5.0.1 -setenv ParaView_MAJOR detect - +set cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake_version +if ( -r $cmake ) then + setenv CMAKE_HOME $cmake + setenv PATH ${CMAKE_HOME}/bin:${PATH} +endif # Evaluate command-line parameters for ParaView while ( $#argv > 0 ) @@ -72,62 +82,64 @@ while ( $#argv > 0 ) end -# Set MAJOR version to correspond to VERSION -# ParaView_MAJOR is "." from ParaView_VERSION -switch ("$ParaView_VERSION") -case "$ParaView_MAJOR".*: - # Version and major appear to correspond - breaksw +# Require that ParaView_VERSION has not been unset. +# Avoids conflict with an alternative (non-ThirdParty) installation. +if ( $?ParaView_VERSION ) then -case [0-9]*: - # Extract major from the version - setenv ParaView_MAJOR `echo ${ParaView_VERSION} | \ - sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'` - breaksw -endsw + # Set MAJOR version to correspond to VERSION + # ParaView_MAJOR is "." from ParaView_VERSION + switch ("$ParaView_VERSION") + case "$ParaView_MAJOR".*: + # Version and major appear to correspond + breaksw + case [0-9]*: + # Extract major from the version + setenv ParaView_MAJOR `echo ${ParaView_VERSION} | \ + sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'` + breaksw + endsw -set paraviewInstDir=$WM_THIRD_PARTY_DIR/ParaView-${ParaView_VERSION} -set paraviewArchName=ParaView-$ParaView_VERSION + set pvName=ParaView-$ParaView_VERSION + set pvMajor=paraview-$ParaView_MAJOR + set pvSrcDir=$WM_THIRD_PARTY_DIR/$pvName -setenv ParaView_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$paraviewArchName + setenv ParaView_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$pvName -# Set paths if binaries or source are present -if ( -r $ParaView_DIR || -r $paraviewInstDir ) then - setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/paraview-${ParaView_MAJOR} - if (! -r $ParaView_INCLUDE_DIR && -r $ParaView_DIR/include/paraview-3.0) then - setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/paraview-3.0 - endif + # Set paths if binaries or source are present + if ( -r $ParaView_DIR || -r $pvSrcDir ) then + set pvLibDir=${ParaView_DIR}/lib/$pvMajor + set pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping - set ParaView_LIB_DIR=${ParaView_DIR}/lib/paraview-${ParaView_MAJOR} + setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/$pvMajor + setenv PV_PLUGIN_PATH $FOAM_LIBBIN/$pvMajor + setenv PATH ${ParaView_DIR}/bin:${PATH} + setenv LD_LIBRARY_PATH "${pvLibDir}:${LD_LIBRARY_PATH}" - setenv PATH ${ParaView_DIR}/bin:${PATH} - setenv LD_LIBRARY_PATH "${ParaView_LIB_DIR}:${LD_LIBRARY_PATH}" - setenv PV_PLUGIN_PATH $FOAM_LIBBIN/paraview-${ParaView_MAJOR} - - if ($?FOAM_VERBOSE && $?prompt) then - echo "Using paraview" - echo " ParaView_DIR : $ParaView_DIR" - echo " ParaView_LIB_DIR : $ParaView_LIB_DIR" - echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" - echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" - endif - - - # Add in python libraries if required - set paraviewPython=$ParaView_DIR/Utilities/VTKPythonWrapping - if ( -r $paraviewPython ) then - if ($?PYTHONPATH) then - setenv PYTHONPATH ${PYTHONPATH}:${paraviewPython}:$ParaView_LIB_DIR - else - setenv PYTHONPATH ${paraviewPython}:$ParaView_LIB_DIR + # Add in python libraries if required + if ( -r $pvPython ) then + if ($?PYTHONPATH) then + setenv PYTHONPATH ${PYTHONPATH}:${pvPython}:$pvLibDir + else + setenv PYTHONPATH ${pvPython}:$pvLibDir + endif endif + + if ($?FOAM_VERBOSE && $?prompt) then + echo "Using paraview" + echo " ParaView_DIR : $ParaView_DIR" + echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" + echo " library dir : $pvLibDir" + echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" + endif + else + unsetenv ParaView_INCLUDE_DIR PV_PLUGIN_PATH + setenv ParaView_DIR # Defined but empty (used by foamPV alias) endif -else - unsetenv PV_PLUGIN_PATH + endif - -unset cleaned cmake paraviewInstDir paraviewPython +unset cleaned cmake cmake_version pvName pvMajor pvSrcDir pvLibDir pvPython +unsetenv ParaView_VERSION ParaView_MAJOR #------------------------------------------------------------------------------ diff --git a/etc/config.sh/aliases b/etc/config.sh/aliases index 3fc8eb96db..4fa36c11c9 100644 --- a/etc/config.sh/aliases +++ b/etc/config.sh/aliases @@ -102,8 +102,9 @@ foamVersion() unset -f foamPV foamPV() { - . $WM_PROJECT_DIR/etc/config.sh/paraview ParaView_VERSION=${1:-none} - echo "paraview-$ParaView_VERSION (major: $ParaView_MAJOR)" 1>&2 + . $WM_PROJECT_DIR/etc/config.sh/paraview "${@+ParaView_VERSION=$1}" + local pvdir="${ParaView_DIR##*/}" + echo "${pvdir:-ParaView_DIR not set}" 1>&2 } diff --git a/etc/config.sh/paraview b/etc/config.sh/paraview index 4d5c89911c..0438aa1323 100644 --- a/etc/config.sh/paraview +++ b/etc/config.sh/paraview @@ -3,7 +3,7 @@ # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | +# \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -25,12 +25,37 @@ # etc/config.sh/paraview # # Description -# Setup file for paraview-[3-5].x +# Setup file for paraview (& cmake) # Sourced from OpenFOAM-/etc/bashrc or from foamPV alias # +# If using system-wide installation for cmake, use the following settings: +# +# cmake_version=cmake-system +# # Note -# The env. variables 'ParaView_DIR' and 'ParaView_MAJOR' -# are required for building plugins +# The following env. variables are required for building plugins: +# ParaView_DIR +# ParaView_INCLUDE_DIR +# PV_PLUGIN_PATH +# +# If using a central installation not located under ThirdParty, you will +# need to set some environment values directly. For example, +# +# export ParaView_DIR=/opt/paraview/paraview-5.0.1 +# export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-5.0 +# export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-5.0 +# +# export PATH=$ParaView_DIR/bin:$PATH +# export LD_LIBRARY_PATH=$ParaView_DIR/lib/paraview-5.0:$LD_LIBRARY_PATH +# unset ParaView_VERSION # avoid using ThirdParty settings +# +#------------------------------------------------------------------------------ + +ParaView_VERSION=5.0.1 +ParaView_MAJOR=detect # Automatically determine major version + +cmake_version=cmake-system + #------------------------------------------------------------------------------ # Clean the PATH @@ -41,32 +66,15 @@ cleaned=$($WM_PROJECT_DIR/bin/foamCleanPath "$PATH" \ ) \ && PATH="$cleaned" -# Determine the cmake to be used +# Environment for ThirdParty cmake unset CMAKE_HOME -for cmake in cmake-3.2.1 cmake-2.8.12.1 cmake-2.8.8 cmake-2.8.4 cmake-2.8.3 \ - cmake-2.8.1 -do - cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake - if [ -r $cmake ] - then - export CMAKE_HOME=$cmake - export CMAKE_ROOT=$cmake - export PATH=$CMAKE_HOME/bin:$PATH - break - fi -done - - -#- ParaView version, automatically determine major version -#export ParaView_VERSION=3.12.0 -#export ParaView_VERSION=4.0.1 -#export ParaView_VERSION=4.1.0 -#export ParaView_VERSION=4.3.1 -#export ParaView_VERSION=4.4.0 -#export ParaView_VERSION=5.0.0 -export ParaView_VERSION=5.0.1 -export ParaView_MAJOR=detect - +cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake_version +if [ -r $cmake ] +then + export CMAKE_HOME=$cmake + export CMAKE_ROOT=$cmake + export PATH=$CMAKE_HOME/bin:$PATH +fi # Evaluate command-line parameters for ParaView _foamParaviewEval() @@ -86,67 +94,69 @@ _foamParaviewEval() # Evaluate command-line parameters _foamParaviewEval $@ - -# Set MAJOR version to correspond to VERSION -# ParaView_MAJOR is "." from ParaView_VERSION -case "$ParaView_VERSION" in -"$ParaView_MAJOR".* ) - # Version and major appear to correspond - ;; - -[0-9]*) - # Extract major from the version - ParaView_MAJOR=$(echo $ParaView_VERSION | \ - sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/') - ;; -esac -export ParaView_VERSION ParaView_MAJOR - -paraviewInstDir=$WM_THIRD_PARTY_DIR/ParaView-$ParaView_VERSION -paraviewArchName=ParaView-$ParaView_VERSION - -export ParaView_DIR=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$paraviewArchName - -# Set paths if binaries or source are present -if [ -r $ParaView_DIR -o -r $paraviewInstDir ] +# Require that ParaView_VERSION has not been unset. +# Avoids conflict with an alternative (non-ThirdParty) installation. +if [ -n "$ParaView_VERSION" ] then - export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-$ParaView_MAJOR - if [ ! -d $ParaView_INCLUDE_DIR -a -d $ParaView_DIR/include/paraview-3.0 ] + + # Set MAJOR version to correspond to VERSION + # ParaView_MAJOR is "." from ParaView_VERSION + case "$ParaView_VERSION" in + "$ParaView_MAJOR".* ) + # Version and major appear to correspond + ;; + + [0-9]*) + # Extract major from the version + ParaView_MAJOR=$(echo $ParaView_VERSION | \ + sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/') + ;; + esac + + pvName=ParaView-$ParaView_VERSION + pvMajor=paraview-$ParaView_MAJOR + pvSrcDir=$WM_THIRD_PARTY_DIR/$pvName + + export ParaView_DIR=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$pvName + + # Set paths if binaries or source are present + if [ -r $ParaView_DIR -o -r $pvSrcDir ] then - export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-3.0 - fi + pvLibDir=$ParaView_DIR/lib/$pvMajor + pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping - ParaView_LIB_DIR=$ParaView_DIR/lib/paraview-$ParaView_MAJOR + export ParaView_INCLUDE_DIR=$ParaView_DIR/include/$pvMajor + export PV_PLUGIN_PATH=$FOAM_LIBBIN/$pvMajor + export PATH=$ParaView_DIR/bin:$PATH + export LD_LIBRARY_PATH=$pvLibDir:$LD_LIBRARY_PATH - export PATH=$ParaView_DIR/bin:$PATH - export LD_LIBRARY_PATH=$ParaView_LIB_DIR:$LD_LIBRARY_PATH - export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-$ParaView_MAJOR - - if [ "$FOAM_VERBOSE" -a "$PS1" ] - then - echo "Using paraview" - echo " ParaView_DIR : $ParaView_DIR" - echo " ParaView_LIB_DIR : $ParaView_LIB_DIR" - echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" - echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" - fi - - # Add in python libraries if required - paraviewPython=$ParaView_DIR/Utilities/VTKPythonWrapping - if [ -r $paraviewPython ] - then - if [ "$PYTHONPATH" ] + # Add in python libraries if required + if [ -r $pvPython ] then - export PYTHONPATH=$PYTHONPATH:$paraviewPython:$ParaView_LIB_DIR - else - export PYTHONPATH=$paraviewPython:$ParaView_LIB_DIR + if [ "$PYTHONPATH" ] + then + export PYTHONPATH=$PYTHONPATH:$pvPython:$pvLibDir + else + export PYTHONPATH=$pvPython:$pvLibDir + fi fi + + if [ "$FOAM_VERBOSE" -a "$PS1" ] + then + echo "Using paraview" + echo " ParaView_DIR : $ParaView_DIR" + echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" + echo " library dir : $pvLibDir" + echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" + fi + else + unset ParaView_DIR ParaView_INCLUDE_DIR PV_PLUGIN_PATH fi -else - unset PV_PLUGIN_PATH + fi -unset _foamParaviewEval -unset cleaned cmake paraviewInstDir paraviewPython +unset -f _foamParaviewEval +unset cleaned cmake cmake_version pvName pvMajor pvSrcDir pvLibDir pvPython +unset ParaView_VERSION ParaView_MAJOR #------------------------------------------------------------------------------ From 8e0981d9ed28706ec723b28d6d76530ab899e751 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 9 Sep 2016 11:01:37 +0100 Subject: [PATCH 10/96] functionObjectList::readFunctionObject: Added support for region specification Now the postProcess utility '-region' option works correctly, e.g. for the chtMultiRegionSimpleFoam/heatExchanger case postProcess -region air -func "mag(U)" calculates 'mag(U)' for all the time steps in region 'air'. --- .../functionObjectList/functionObjectList.C | 33 +++++++++++++++++-- .../functionObjectList/functionObjectList.H | 3 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 7bd1882942..04cfc5acfb 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -151,7 +151,8 @@ bool Foam::functionObjectList::readFunctionObject ( const string& funcNameArgs, dictionary& functionsDict, - HashSet& requiredFields + HashSet& requiredFields, + const word& region ) { // Parse the optional functionObject arguments: @@ -291,6 +292,12 @@ bool Foam::functionObjectList::readFunctionObject funcDict.set(entry::New(entryStream).ptr()); } + // Insert the region name if specified + if (region != word::null) + { + funcDict.set("region", region); + } + // Merge this functionObject dictionary into functionsDict dictionary funcArgsDict; funcArgsDict.add(string::validate(funcNameArgs), funcDict); @@ -352,6 +359,14 @@ Foam::autoPtr Foam::functionObjectList::New dictionary& functionsDict = controlDict.subDict("functions"); + word region = word::null; + + // Set the region name if specified + if (args.optionFound("region")) + { + region = args["region"]; + } + if ( args.optionFound("dict") @@ -377,7 +392,13 @@ Foam::autoPtr Foam::functionObjectList::New if (args.optionFound("func")) { - readFunctionObject(args["func"], functionsDict, requiredFields); + readFunctionObject + ( + args["func"], + functionsDict, + requiredFields, + region + ); } if (args.optionFound("funcs")) @@ -386,7 +407,13 @@ Foam::autoPtr Foam::functionObjectList::New forAll(funcs, i) { - readFunctionObject(funcs[i], functionsDict, requiredFields); + readFunctionObject + ( + funcs[i], + functionsDict, + requiredFields, + region + ); } } diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index da27e7d7f3..405e613369 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -218,7 +218,8 @@ public: ( const string& funcNameArgs0, dictionary& functionsDict, - HashSet& requiredFields + HashSet& requiredFields, + const word& region = word::null ); //- Read and set the function objects if their data have changed From cb1a012b66b3e0d72cef50197b6cd3d0887c7693 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 9 Sep 2016 12:20:25 +0100 Subject: [PATCH 11/96] structuredRenumber: Corrected to run in parallel Patch contributed by Mattijs Janssens --- .../structuredRenumber/OppositeFaceCellWave.C | 331 ++++++++++++++++++ .../structuredRenumber/OppositeFaceCellWave.H | 143 ++++++++ .../OppositeFaceCellWaveName.C | 36 ++ .../structuredRenumber/structuredRenumber.C | 154 +++++--- .../structuredRenumber/structuredRenumber.H | 35 +- 5 files changed, 651 insertions(+), 48 deletions(-) create mode 100644 src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C create mode 100644 src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.H create mode 100644 src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWaveName.C diff --git a/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C b/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C new file mode 100644 index 0000000000..4e865bd0b1 --- /dev/null +++ b/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C @@ -0,0 +1,331 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "OppositeFaceCellWave.H" +#include "polyMesh.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::OppositeFaceCellWave::opposingFaceLabels +( + const label celli, + const label masterFaceLabel, + DynamicList