From 4dd02834c2860a60082312120c287c0dba4211fa Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 16 Feb 2011 12:57:13 +0000 Subject: [PATCH 01/76] STYLE: minor code formatting --- src/lagrangian/basic/Particle/Particle.H | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lagrangian/basic/Particle/Particle.H b/src/lagrangian/basic/Particle/Particle.H index 484ca7ded0..743925525a 100644 --- a/src/lagrangian/basic/Particle/Particle.H +++ b/src/lagrangian/basic/Particle/Particle.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -120,7 +120,7 @@ public: protected: - // Private data + // Protected data //- Reference to the particle cloud const Cloud& cloud_; @@ -179,18 +179,18 @@ protected: const label tetPtI ) const; - //- Find the lambda value for a moving tri face - inline scalar movingTetLambda - ( - const vector& from, - const vector& to, - const label triI, - const vector& tetArea, - const label tetPlaneBasePtI, - const label cellI, - const label tetFaceI, - const label tetPtI - ) const; + //- Find the lambda value for a moving tri face + inline scalar movingTetLambda + ( + const vector& from, + const vector& to, + const label triI, + const vector& tetArea, + const label tetPlaneBasePtI, + const label cellI, + const label tetFaceI, + const label tetPtI + ) const; //- Modify the tet owner data by crossing triI inline void tetNeighbour(label triI); From 23dd3e072b3d2088a1153cb7f0d736b3de057190 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 13:02:36 +0100 Subject: [PATCH 02/76] ENH: provide for writing contents only from dictionary entries --- src/OpenFOAM/db/dictionary/dictionary.H | 3 ++- .../dictionaryEntry/dictionaryEntry.H | 4 +-- .../dictionaryEntry/dictionaryEntryIO.C | 2 +- .../primitiveEntry/primitiveEntry.H | 5 +++- .../primitiveEntry/primitiveEntryIO.C | 26 ++++++++++++++----- .../primitives/strings/stringOps/stringOps.H | 4 --- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index f1196852bf..cb3b03b00f 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -477,7 +477,8 @@ public: // Write - void write(Ostream&, bool subDict=true) const; + //- Write dictionary, normally with sub-dictionary formatting + void write(Ostream&, const bool subDict=true) const; // Member Operators diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index 050840c5e4..7713e503af 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -146,7 +146,7 @@ public: //- Return non-const access to dictionary dictionary& dict(); - // Write + //- Write void write(Ostream&) const; //- Return info proxy. diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index b090188a0d..2477f0450b 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index 6edf2c621c..01f08cea5b 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -168,6 +168,9 @@ public: //- Write void write(Ostream&) const; + //- Write, optionally with contents only (no keyword, etc) + void write(Ostream&, const bool contentsOnly) const; + //- Return info proxy. // Used to print token information to a stream InfoProxy info() const diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index fa9a50efdb..33c3dc8ff7 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -210,31 +210,43 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::primitiveEntry::write(Ostream& os) const +void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const { - os.writeKeyword(keyword()); + if (!contentsOnly) + { + os.writeKeyword(keyword()); + } for (label i=0; iwrite(os, false); } diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index d9756a2705..6d416dd6e8 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -128,19 +128,15 @@ namespace stringOps string& inplaceTrimLeft(string&); //- Return string trimmed of trailing whitespace - // NOT IMPLEMENTED string trimRight(const string&); //- Trim trailing whitespace inplace - // NOT IMPLEMENTED string& inplaceTrimRight(string&); //- Return string trimmed of leading and trailing whitespace - // NOT IMPLEMENTED string trim(const string&); //- Trim leading and trailing whitespace inplace - // NOT IMPLEMENTED string& inplaceTrim(string&); From 31f6d9ba5e8b18c6fbec2631a264030c89d4745a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 13:38:57 +0100 Subject: [PATCH 03/76] ENH: add stringOps::expandDict --- applications/test/string/Test-string.C | 19 ++- .../primitives/strings/stringOps/stringOps.C | 145 +++++++++++++++++- .../primitives/strings/stringOps/stringOps.H | 41 ++++- 3 files changed, 198 insertions(+), 7 deletions(-) diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index d117f50c41..e9639c4736 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -22,11 +22,13 @@ License along with OpenFOAM. If not, see . Description + Test some string functionality \*---------------------------------------------------------------------------*/ #include "string.H" #include "stringOps.H" +#include "dictionary.H" #include "IOstreams.H" using namespace Foam; @@ -38,9 +40,19 @@ int main(int argc, char *argv[]) { string test ( - " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ " + " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ with " + " $(DONOTSUBST) some other ${USER} entries " ); + dictionary dict; + dict.add("HOME", "myHome"); + + dictionary subDict; + subDict.add("value1", "test1"); + subDict.add("value2", "test2"); + dict.add("FOAM_RUN", subDict); + + Info<< "string:" << test << nl << "hash:" << unsigned(string::hash()(test)) << endl; @@ -73,7 +85,10 @@ int main(int argc, char *argv[]) Info<< string(test).replaceAll("kj", "zzz") << endl; Info<< string(test).replaceAll("kj", "z") << endl; - Info<< string(test).expand() << endl; + Info<< "expanded: " << string(test).expand() << endl; + + Info<<"dictionary-based substitution: " << dict << endl; + Info<< "expandDict: " << stringOps::expandDict(test, dict) << endl; string test2("~OpenFOAM/controlDict"); Info<< test2 << " => " << test2.expand() << endl; diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index 49142b10ec..f0a55ee1bd 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -24,7 +24,9 @@ License \*---------------------------------------------------------------------------*/ #include "stringOps.H" +#include "typeInfo.H" #include "OSspecific.H" +#include "OStringStream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -73,10 +75,17 @@ Foam::string& Foam::stringOps::inplaceExpand { string::iterator iter = s.begin() + begVar + 1; + // more generous in accepting keywords than for env variables while ( iter != s.end() - && (isalnum(*iter) || *iter == '_') + && + ( + isalnum(*iter) + || *iter == '.' + || *iter == ':' + || *iter == '_' + ) ) { ++iter; @@ -86,10 +95,14 @@ Foam::string& Foam::stringOps::inplaceExpand if (endVar != string::npos && endVar != begVar) { - string varName = s.substr + const word varName ( - begVar + 1 + delim, - endVar - begVar - 2*delim + s.substr + ( + begVar + 1 + delim, + endVar - begVar - 2*delim + ), + false ); HashTable::const_iterator fnd = @@ -130,6 +143,130 @@ Foam::string& Foam::stringOps::inplaceExpand } +Foam::string Foam::stringOps::expandDict +( + const string& original, + const dictionary& dict, + const char sigil +) +{ + string s(original); + return inplaceExpandDict(s, dict, sigil); +} + + +Foam::string& Foam::stringOps::inplaceExpandDict +( + string& s, + const dictionary& dict, + const char sigil +) +{ + string::size_type begVar = 0; + + // Expand $VAR or ${VAR} + // Repeat until nothing more is found + while + ( + (begVar = s.find(sigil, begVar)) != string::npos + && begVar < s.size()-1 + ) + { + if (begVar == 0 || s[begVar-1] != '\\') + { + // Find end of first occurrence + string::size_type endVar = begVar; + string::size_type delim = 0; + + if (s[begVar+1] == '{') + { + endVar = s.find('}', begVar); + delim = 1; + } + else + { + string::iterator iter = s.begin() + begVar + 1; + + // more generous in accepting keywords than for env variables + while + ( + iter != s.end() + && + ( + isalnum(*iter) + || *iter == '.' + || *iter == ':' + || *iter == '_' + ) + ) + { + ++iter; + ++endVar; + } + } + + if (endVar != string::npos && endVar != begVar) + { + const word varName + ( + s.substr + ( + begVar + 1 + delim, + endVar - begVar - 2*delim + ), + false + ); + + + // lookup the variable name in the given dictionary + const entry* ePtr = dict.lookupEntryPtr(varName, true, true); + + // if defined - copy its entries + if (ePtr != NULL) + { + OStringStream buf; + if (ePtr->isDict()) + { + ePtr->dict().write(buf, false); + } + else + { + // fail for other types + dynamicCast + ( + *ePtr + ).write(buf, true); + } + + s.std::string::replace + ( + begVar, + endVar - begVar + 1, + buf.str() + ); + begVar += buf.str().size(); + } + else + { + // not defined - leave untouched. + begVar = endVar; + } + } + else + { + break; + } + } + else + { + ++begVar; + } + } + + return s; +} + + Foam::string Foam::stringOps::expandEnv ( const string& original, diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index 6d416dd6e8..6d0ded9012 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -36,6 +36,7 @@ SourceFiles #define stringOps_H #include "string.H" +#include "dictionary.H" #include "HashTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,6 +55,8 @@ namespace stringOps // -# variables // - "$VAR", "${VAR}" // + // Any unknown entries are removed + // // \note the leading sigil can be changed to avoid conflicts with other // string expansions string expand @@ -69,6 +72,8 @@ namespace stringOps // -# variables // - "$VAR", "${VAR}" // + // Any unknown entries are removed + // // \note the leading sigil can be changed to avoid conflicts with other // string expansions string& inplaceExpand @@ -78,6 +83,39 @@ namespace stringOps const char sigil = '$' ); + //- Expand occurences of variables according to the dictionary + // Expansion includes: + // -# variables + // - "$VAR", "${VAR}" + // + // Any unknown entries are left as-is + // + // \note the leading sigil can be changed to avoid conflicts with other + // string expansions + string expandDict + ( + const string&, + const dictionary& dict, + const char sigil = '$' + ); + + + //- Inplace expand occurences of variables according to the dictionary + // Expansion includes: + // -# variables + // - "$VAR", "${VAR}" + // + // Any unknown entries are left as-is + // + // \note the leading sigil can be changed to avoid conflicts with other + // string expansions + string& inplaceExpandDict + ( + string&, + const dictionary& dict, + const char sigil = '$' + ); + //- Expand initial tildes and all occurences of environment variables // Expansion includes: @@ -90,6 +128,7 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // + // Any unknown entries are removed silently if allowEmptyVar is true // \sa // Foam::findEtcFile string expandEnv @@ -111,6 +150,7 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // + // Any unknown entries are removed silently if allowEmptyVar is true // \sa // Foam::findEtcFile string& inplaceExpandEnv @@ -140,7 +180,6 @@ namespace stringOps string& inplaceTrim(string&); - } // End namespace stringOps From 67fc6a171ad0c14b6f7f9420f259b442c0dc6a33 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 14:22:14 +0100 Subject: [PATCH 04/76] ENH: use stringOps::expandDict when processing codeStream input --- applications/test/codeStream/codeStreamDict1 | 20 ++++++++++++------- .../functionEntries/codeStream/codeStream.C | 9 ++++++++- .../codeStream/codeStreamTools.C | 7 +++---- .../codedFixedValueFvPatchScalarField.C | 4 ++++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/applications/test/codeStream/codeStreamDict1 b/applications/test/codeStream/codeStreamDict1 index 54fb3d0efe..ec94ddb173 100644 --- a/applications/test/codeStream/codeStreamDict1 +++ b/applications/test/codeStream/codeStreamDict1 @@ -14,10 +14,15 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// #include "codeStreamDefaults" +// values from outer-scope +begIter 0; +endIter 200; writeInterval #codeStream { + // values from inner-scope + nDumps 5; + codeInclude #{ #include "fvCFD.H" @@ -30,14 +35,15 @@ writeInterval #codeStream code #{ - scalar start = 0; - scalar end = 100; - label nDumps = 5; - label interval = end - start; - Info<<"on-the-fly: " << ((interval)/nDumps) << endl; - os << ((interval)/nDumps); + label interval = ($endIter - $begIter); + label nDumps = $nDumps; + os << (interval / nDumps); #}; }; +// play with cleanup +#remove begIter + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 1accc97517..21ffba1f91 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -83,17 +83,21 @@ bool Foam::functionEntries::codeStream::execute << exit(FatalIOError); } + // get code dictionary + // must reference parent for stringOps::expandDict to work nicely + dictionary codeDict("#codeStream", parentDict, is); + // Read three sections of code. // Remove any leading whitespace - necessary for compilation options, // convenience for includes and body. - dictionary codeDict(is); // "codeInclude" is optional string codeInclude; if (codeDict.found("codeInclude")) { codeInclude = stringOps::trim(codeDict["codeInclude"]); + stringOps::inplaceExpandDict(codeInclude, codeDict); } // "codeOptions" is optional @@ -101,10 +105,13 @@ bool Foam::functionEntries::codeStream::execute if (codeDict.found("codeOptions")) { codeOptions = stringOps::trim(codeDict["codeOptions"]); + stringOps::inplaceExpandDict(codeOptions, codeDict); } // "code" is mandatory string code = stringOps::trim(codeDict["code"]); + stringOps::inplaceExpandDict(code, codeDict); + // Create SHA1 digest from the contents SHA1Digest sha; diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C index fc1c6f0ffb..aee9c859d8 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C @@ -159,12 +159,11 @@ void Foam::codeStreamTools::copyAndExpand { is.getLine(line); - // normal expansion according to mapping + // expand according to mapping + // expanding according to env variables might cause too many + // surprises stringOps::inplaceExpand(line, mapping); - // expand according to env variables - stringOps::inplaceExpandEnv(line, true, true); - os << line.c_str() << nl; } while (is.good()); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index b87a560ac0..05c778ad5b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -96,6 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary if (dict.found("codeInclude")) { codeInclude = stringOps::trim(dict["codeInclude"]); + stringOps::inplaceExpandDict(codeInclude, dict); } // "codeOptions" is optional @@ -103,10 +104,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary if (dict.found("codeOptions")) { codeOptions = stringOps::trim(dict["codeOptions"]); + stringOps::inplaceExpandDict(codeOptions, dict); } // "code" is mandatory string code = stringOps::trim(dict["code"]); + stringOps::inplaceExpandDict(code, dict); + // Create SHA1 digest from the contents SHA1Digest sha; From 97a15a8b06c69d4ae4a995053385eb337aa24301 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 14:42:51 +0100 Subject: [PATCH 05/76] STYLE: simplify stringOps::expand names --- .../functionEntries/codeStream/codeStream.C | 8 +-- .../codeStream/codeStreamTools.C | 11 ++-- .../primitives/strings/stringOps/stringOps.C | 54 +++++++++---------- .../primitives/strings/stringOps/stringOps.H | 18 +++---- .../codedFixedValueFvPatchScalarField.C | 6 +-- 5 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 21ffba1f91..f2bc4c3f10 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -84,7 +84,7 @@ bool Foam::functionEntries::codeStream::execute } // get code dictionary - // must reference parent for stringOps::expandDict to work nicely + // must reference parent for stringOps::expand to work nicely dictionary codeDict("#codeStream", parentDict, is); @@ -97,7 +97,7 @@ bool Foam::functionEntries::codeStream::execute if (codeDict.found("codeInclude")) { codeInclude = stringOps::trim(codeDict["codeInclude"]); - stringOps::inplaceExpandDict(codeInclude, codeDict); + stringOps::inplaceExpand(codeInclude, codeDict); } // "codeOptions" is optional @@ -105,12 +105,12 @@ bool Foam::functionEntries::codeStream::execute if (codeDict.found("codeOptions")) { codeOptions = stringOps::trim(codeDict["codeOptions"]); - stringOps::inplaceExpandDict(codeOptions, codeDict); + stringOps::inplaceExpand(codeOptions, codeDict); } // "code" is mandatory string code = stringOps::trim(codeDict["code"]); - stringOps::inplaceExpandDict(code, codeDict); + stringOps::inplaceExpand(code, codeDict); // Create SHA1 digest from the contents diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C index aee9c859d8..d0cd0b6830 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C @@ -51,28 +51,25 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName Foam::fileName Foam::codeStreamTools::baseDir() { - return stringOps::expandEnv("$FOAM_CASE/codeStream"); + return stringOps::expand("$FOAM_CASE/codeStream"); } Foam::fileName Foam::codeStreamTools::libSubDir() { - return stringOps::expandEnv("platforms/$WM_OPTIONS/lib"); + return stringOps::expand("platforms/$WM_OPTIONS/lib"); } Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName) { - return stringOps::expandEnv - ( - "$FOAM_CASE/codeStream/" + subDirName - ); + return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName); } Foam::fileName Foam::codeStreamTools::libPath(const word& codeName) { - return stringOps::expandEnv + return stringOps::expand ( "$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib" + codeName + ".so" diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index f0a55ee1bd..99e7fb8ab3 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -143,7 +143,7 @@ Foam::string& Foam::stringOps::inplaceExpand } -Foam::string Foam::stringOps::expandDict +Foam::string Foam::stringOps::expand ( const string& original, const dictionary& dict, @@ -151,11 +151,11 @@ Foam::string Foam::stringOps::expandDict ) { string s(original); - return inplaceExpandDict(s, dict, sigil); + return inplaceExpand(s, dict, sigil); } -Foam::string& Foam::stringOps::inplaceExpandDict +Foam::string& Foam::stringOps::inplaceExpand ( string& s, const dictionary& dict, @@ -218,11 +218,11 @@ Foam::string& Foam::stringOps::inplaceExpandDict ); - // lookup the variable name in the given dictionary + // lookup in the dictionary const entry* ePtr = dict.lookupEntryPtr(varName, true, true); // if defined - copy its entries - if (ePtr != NULL) + if (ePtr) { OStringStream buf; if (ePtr->isDict()) @@ -248,7 +248,7 @@ Foam::string& Foam::stringOps::inplaceExpandDict } else { - // not defined - leave untouched. + // not defined - leave original string untouched begVar = endVar; } } @@ -267,24 +267,21 @@ Foam::string& Foam::stringOps::inplaceExpandDict } -Foam::string Foam::stringOps::expandEnv +Foam::string Foam::stringOps::expand ( const string& original, - const bool recurse, - const bool allowEmptyVar + const bool allowEmpty ) { string s(original); - return inplaceExpandEnv(s, recurse, allowEmptyVar); + return inplaceExpand(s, allowEmpty); } -// Expand all occurences of environment variables and initial tilde sequences -Foam::string& Foam::stringOps::inplaceExpandEnv +Foam::string& Foam::stringOps::inplaceExpand ( string& s, - const bool recurse, - const bool allowEmptyVar + const bool allowEmpty ) { string::size_type begVar = 0; @@ -325,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv if (endVar != string::npos && endVar != begVar) { - string varName = s.substr + const word varName ( - begVar + 1 + delim, - endVar - begVar - 2*delim + s.substr + ( + begVar + 1 + delim, + endVar - begVar - 2*delim + ), + false ); - string varValue = getEnv(varName); - + const string varValue = getEnv(varName); if (varValue.size()) { - if (recurse) - { - varValue.expand(recurse, allowEmptyVar); - } s.std::string::replace ( begVar, @@ -347,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv ); begVar += varValue.size(); } - else if (allowEmptyVar) + else if (allowEmpty) { s.std::string::replace ( @@ -358,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv } else { - FatalErrorIn("string::expand(const bool, const bool)") + FatalErrorIn + ( + "stringOps::inplaceExpand(string&, const bool)" + ) << "Unknown variable name " << varName << '.' << exit(FatalError); } @@ -431,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s) if (!s.empty()) { string::size_type beg = 0; - while (isspace(s[beg])) + while (beg < s.size() && isspace(s[beg])) { ++beg; } @@ -451,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s) if (!s.empty()) { string::size_type beg = 0; - while (isspace(s[beg])) + while (beg < s.size() && isspace(s[beg])) { ++beg; } @@ -517,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s) return s; } + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index 6d0ded9012..cfd7993739 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -92,7 +92,7 @@ namespace stringOps // // \note the leading sigil can be changed to avoid conflicts with other // string expansions - string expandDict + string expand ( const string&, const dictionary& dict, @@ -109,7 +109,7 @@ namespace stringOps // // \note the leading sigil can be changed to avoid conflicts with other // string expansions - string& inplaceExpandDict + string& inplaceExpand ( string&, const dictionary& dict, @@ -128,14 +128,13 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - // Any unknown entries are removed silently if allowEmptyVar is true + // Any unknown entries are removed silently if allowEmpty is true // \sa // Foam::findEtcFile - string expandEnv + string expand ( const string&, - const bool recurse=false, - const bool allowEmptyVar = false + const bool allowEmpty = false ); @@ -150,14 +149,13 @@ namespace stringOps // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - // Any unknown entries are removed silently if allowEmptyVar is true + // Any unknown entries are removed silently if allowEmpty is true // \sa // Foam::findEtcFile - string& inplaceExpandEnv + string& inplaceExpand ( string&, - const bool recurse=false, - const bool allowEmptyVar = false + const bool allowEmpty = false ); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 05c778ad5b..51f88bf131 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -96,7 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary if (dict.found("codeInclude")) { codeInclude = stringOps::trim(dict["codeInclude"]); - stringOps::inplaceExpandDict(codeInclude, dict); + stringOps::inplaceExpand(codeInclude, dict); } // "codeOptions" is optional @@ -104,12 +104,12 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary if (dict.found("codeOptions")) { codeOptions = stringOps::trim(dict["codeOptions"]); - stringOps::inplaceExpandDict(codeOptions, dict); + stringOps::inplaceExpand(codeOptions, dict); } // "code" is mandatory string code = stringOps::trim(dict["code"]); - stringOps::inplaceExpandDict(code, dict); + stringOps::inplaceExpand(code, dict); // Create SHA1 digest from the contents From 5ab254d5b07a3eb5be1af743b6f83282f0c0f2b6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 15:18:01 +0100 Subject: [PATCH 06/76] STYLE: drop dubious string::expand recursion - was used for on-the-fly, but not needed anymore --- src/OpenFOAM/primitives/strings/string/string.C | 14 ++++---------- src/OpenFOAM/primitives/strings/string/string.H | 7 ++----- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C index 05ad3a5682..4c9218d77e 100644 --- a/src/OpenFOAM/primitives/strings/string/string.C +++ b/src/OpenFOAM/primitives/strings/string/string.C @@ -93,8 +93,7 @@ Foam::string& Foam::string::replaceAll } -// Expand all occurences of environment variables and initial tilde sequences -Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) +Foam::string& Foam::string::expand(const bool allowEmpty) { size_type begVar = 0; @@ -134,20 +133,15 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) if (endVar != npos && endVar != begVar) { - string varName = substr + const string varName = substr ( begVar + 1 + delim, endVar - begVar - 2*delim ); - string varValue = getEnv(varName); - + const string varValue = getEnv(varName); if (varValue.size()) { - if (recurse) - { - varValue.expand(recurse, allowEmptyVar); - } std::string::replace ( begVar, @@ -156,7 +150,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) ); begVar += varValue.size(); } - else if (allowEmptyVar) + else if (allowEmpty) { std::string::replace ( diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 8dec948567..618ce6bb59 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -180,13 +180,10 @@ public: // - leading "~user" : home directory for specified user // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // + // Any unknown entries are removed silently if allowEmpty is true // \sa // Foam::findEtcFile - string& expand - ( - const bool recurse=false, - const bool allowEmptyVar = false - ); + string& expand(const bool allowEmpty = false); //- Remove repeated characters returning true if string changed bool removeRepeated(const char); From 6e6d3bb4f88480c5b98c30a98131c82fbfcea3b1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 16:16:28 +0100 Subject: [PATCH 07/76] STYLE: move InfoSwitches, OptimisationSwitches up front in etc/controlDict - add doc-dir doc/doxygen so it doesn't get forgotten --- etc/controlDict | 55 +++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/etc/controlDict b/etc/controlDict index 403aa02285..4aa8a3ec0a 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: 1.7 | +| \\ / O peration | Version: 2.0 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -24,6 +24,7 @@ Documentation "$WM_PROJECT_USER_DIR/html" "~OpenFOAM/html" "$WM_PROJECT_DIR/doc/Doxygen/html" + "$WM_PROJECT_DIR/doc/doxygen/html" ); doxySourceFileExts ( @@ -32,6 +33,34 @@ Documentation ); } + +InfoSwitches +{ + writePrecision 6; + writeJobInfo 0; + + // Allow case-supplied c++ code (#codeStream, codedFixedValue) + allowSystemOperations 0; +} + + +OptimisationSwitches +{ + fileModificationSkew 10; + + //- Modification checking: + // - timeStamp : use modification time on file + // - inotify : use inotify framework + // - timeStampMaster : do time stamp (and file reading) only on master. + // - inotifyMaster : do inotify (and file reading) only on master. + fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster; + + commsType nonBlocking; //scheduled; //blocking; + floatTransfer 0; + nProcsSimpleSum 0; +} + + DebugSwitches { Analytical 0; @@ -864,30 +893,6 @@ DebugSwitches zoneToPoint 0; } -InfoSwitches -{ - writePrecision 6; - writeJobInfo 0; - - // Allow case-supplied c++ code (#codeStream, codedFixedValue) - allowSystemOperations 0; -} - -OptimisationSwitches -{ - fileModificationSkew 10; - - //- Modification checking: - // - timeStamp : use modification time on file - // - inotify : use inotify framework - // - timeStampMaster : do time stamp (and file reading) only on master. - // - inotifyMaster : do inotify (and file reading) only on master. - fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster; - - commsType nonBlocking; //scheduled; //blocking; - floatTransfer 0; - nProcsSimpleSum 0; -} DimensionedConstants { From b0e39f71c3de921097b377bce4b34de19de8a886 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 16:17:25 +0100 Subject: [PATCH 08/76] STYLE: minor cleanup on doc/code for codeStream --- doc/changes/codeStream.org | 9 +++++---- .../db/dynamicLibrary/codeStream/codeStreamTools.C | 12 ------------ .../db/dynamicLibrary/codeStream/codeStreamTools.H | 8 -------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org index bcef4c166b..6e26ba9810 100644 --- a/doc/changes/codeStream.org +++ b/doc/changes/codeStream.org @@ -49,13 +49,14 @@ - it copies a template file =($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C)=, substituting all occurences of =code=, =codeInclude=, =codeOptions=. - - it writes library source files to =constant/codeStream/= and compiles + - it writes library source files to =codeStream/= and compiles it using =wmake libso=. - - the resulting library gets loaded (=dlopen=, =dlsym=) and the function - executed + - the resulting library is generated under + =codeStream/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=) + and the function executed - the function will have written its output into the Ostream which then gets used to construct the entry to replace the whole =#codeStream= section. - - using the sha1 means that same code will only be compiled and loaded once. + - using the SHA1 means that same code will only be compiled and loaded once. * Boundary condition: =codedFixedValue= This uses the code from codeStream to have an in-line specialised diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C index d0cd0b6830..1eaa2a4e9d 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C @@ -49,18 +49,6 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -Foam::fileName Foam::codeStreamTools::baseDir() -{ - return stringOps::expand("$FOAM_CASE/codeStream"); -} - - -Foam::fileName Foam::codeStreamTools::libSubDir() -{ - return stringOps::expand("platforms/$WM_OPTIONS/lib"); -} - - Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName) { return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName); diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H index 4f158b6aea..460eb7e0fc 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H @@ -145,14 +145,6 @@ public: // Member functions - //- Directory for compile/link (case-specific) - // Expanded from \$FOAM_CASE/codeStream - static fileName baseDir(); - - //- Subdirectory name for library - // Expanded from platforms/\$WM_OPTIONS/lib - static fileName libSubDir(); - //- Local path for specified code name // Expanded from \$FOAM_CASE/codeStream static fileName codePath(const word& subDirName); From 6eb982573cd8f220434b4877f5dcb89a52ecda85 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 24 Feb 2011 08:54:12 +0100 Subject: [PATCH 09/76] ENH: add stub function to codedFixedValueFvPatchScalarField for version checking - eg, fixedValue10_, its existence indicates that the correct library has been loaded --- .../fixedValueFvPatchScalarFieldTemplate.C | 14 ++++++++ .../functionEntries/codeStream/codeStream.C | 26 +++++++-------- .../codeStream/codeStreamTools.C | 29 ++++++++++++++++ .../codeStream/codeStreamTools.H | 7 ++++ .../codedFixedValueFvPatchScalarField.C | 33 +++++++++++-------- 5 files changed, 81 insertions(+), 28 deletions(-) diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C index 417b77ee68..76a31e9fb0 100644 --- a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C +++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C @@ -35,6 +35,20 @@ ${codeInclude} namespace Foam { +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +extern "C" +{ + // unique function name that can be checked if the correct library version + // has been loaded + bool ${typeName}_${SHA1sum}() + { + return true; + } +} + + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // ${typeName}FixedValueFvPatchScalarField:: diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index f2bc4c3f10..6144653367 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -35,7 +35,8 @@ License #include "dlLibraryTable.H" #include "OSspecific.H" #include "Time.H" -#include "Pstream.H" +#include "PstreamReduceOps.H" + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -70,18 +71,11 @@ bool Foam::functionEntries::codeStream::execute Istream& is ) { - if (isAdministrator()) - { - FatalIOErrorIn - ( - "functionEntries::codeStream::execute(..)", - parentDict - ) << "This code should not be executed by someone with administrator" - << " rights due to security reasons." << endl - << "(it writes a shared library which then gets loaded " - << "using dlopen)" - << exit(FatalIOError); - } + codeStreamTools::checkSecurity + ( + "functionEntries::codeStream::execute(..)", + parentDict + ); // get code dictionary // must reference parent for stringOps::expand to work nicely @@ -175,6 +169,7 @@ bool Foam::functionEntries::codeStream::execute copyFiles[0].file() = fileCsrc; copyFiles[0].set("codeInclude", codeInclude); copyFiles[0].set("code", code); + copyFiles[0].set("SHA1sum", sha.str()); List filesContents(2); @@ -218,8 +213,9 @@ bool Foam::functionEntries::codeStream::execute } } -// bool dummy = true; -// reduce(dummy, orOp()); + // all processes must wait for compile + bool dummy = true; + reduce(dummy, orOp()); if (!dlLibraryTable::open(libPath, false)) { diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C index 1eaa2a4e9d..cf252d1f8b 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C @@ -49,6 +49,28 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +void Foam::codeStreamTools::checkSecurity +( + const char* title, + const dictionary& context +) +{ + if (isAdministrator()) + { + FatalIOErrorIn + ( + title, + context + ) << "This code should not be executed by someone with administrator" + << " rights due to security reasons." << nl + << "(it writes a shared library which then gets loaded " + << "using dlopen)" + << exit(FatalIOError); + } +} + + + Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName) { return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName); @@ -253,6 +275,13 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const // variables mapping HashTable mapping(copyFiles_[i]); mapping.set("typeName", name_); + + // provide a zero digest if not otherwise specified + if (!mapping.found("SHA1sum")) + { + mapping.insert("SHA1sum", SHA1Digest().str()); + } + copyAndExpand(is, os, mapping); } diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H index 460eb7e0fc..8df397cc15 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H @@ -145,6 +145,13 @@ public: // Member functions + //- Check security for creating dynamic code + static void checkSecurity + ( + const char* title, + const dictionary& context + ); + //- Local path for specified code name // Expanded from \$FOAM_CASE/codeStream static fileName codePath(const word& subDirName); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 51f88bf131..8b19852db8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -124,7 +124,9 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary // <<"new SHA1: " << sha << endl; - // (void) codeStreamTools::upToDate(codePath, sha) + // only use side-effect of writing SHA1Digest for now + (void) codeStreamTools::upToDate(codePath, sha); + // TODO: compile on-demand if (true) { @@ -152,6 +154,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary copyFiles[0].file() = fileCsrc; copyFiles[0].set("codeInclude", codeInclude); copyFiles[0].set("code", code); + copyFiles[0].set("SHA1sum", sha.str()); copyFiles[1].file() = fileHsrc; @@ -190,18 +193,11 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { - if (isAdministrator()) - { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::updateLibrary()", - dict_ - ) << "This code should not be executed by someone with administrator" - << " rights due to security reasons." << endl - << "(it writes a shared library which then gets loaded " - << "using dlopen)" - << exit(FatalIOError); - } + codeStreamTools::checkSecurity + ( + "codedFixedValueFvPatchScalarField::updateLibrary()", + dict_ + ); // write code into redirectType_ subdir const fileName codePath = codeStreamTools::codePath(redirectType_); @@ -220,6 +216,16 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() void* lib = dlLibraryTable::findLibrary(libPath); + + // TODO: + // calculate old/new SHA1 for code + // check if the correct library version was already loaded. + // Find the library handle. + // + // string signatureName(redirectType_ + "_" + sha().str()); + // void (*signatureFunction)(); + // signatureFunction = reinterpret_cast(dlSym(lib, signatureName)); + if (dict_.found("code")) { if (!lib) @@ -274,6 +280,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() } } + // all processes must wait for compile bool dummy = true; reduce(dummy, orOp()); From 5fb0a7124116399c36d55726aa9de3ab95bc9f8b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 24 Feb 2011 08:56:59 +0100 Subject: [PATCH 10/76] STYLE: use string directly in call to Foam::system --- src/postProcessing/functionObjects/systemCall/systemCall.C | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/postProcessing/functionObjects/systemCall/systemCall.C b/src/postProcessing/functionObjects/systemCall/systemCall.C index 664589750c..0a9d825644 100644 --- a/src/postProcessing/functionObjects/systemCall/systemCall.C +++ b/src/postProcessing/functionObjects/systemCall/systemCall.C @@ -102,7 +102,7 @@ void Foam::systemCall::execute() { forAll(executeCalls_, callI) { - Foam::system(executeCalls_[callI].c_str()); + Foam::system(executeCalls_[callI]); } } @@ -111,7 +111,7 @@ void Foam::systemCall::end() { forAll(endCalls_, callI) { - Foam::system(endCalls_[callI].c_str()); + Foam::system(endCalls_[callI]); } } @@ -120,7 +120,7 @@ void Foam::systemCall::write() { forAll(writeCalls_, callI) { - Foam::system(writeCalls_[callI].c_str()); + Foam::system(writeCalls_[callI]); } } From 0bc22ece49cd4268a1b08507d314aae5d66e28de Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 24 Feb 2011 09:04:06 +0100 Subject: [PATCH 11/76] COMP: fully qualify POSIX function calls --- src/OSspecific/POSIX/POSIX.C | 80 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 03eefb623b..4909d08244 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -63,28 +63,28 @@ defineTypeNameAndDebug(Foam::POSIX, 0); pid_t Foam::pid() { - return getpid(); + return ::getpid(); } pid_t Foam::ppid() { - return getppid(); + return ::getppid(); } pid_t Foam::pgid() { - return getpgrp(); + return ::getpgrp(); } bool Foam::env(const word& envName) { - return getenv(envName.c_str()) != NULL; + return ::getenv(envName.c_str()) != NULL; } Foam::string Foam::getEnv(const word& envName) { - char* env = getenv(envName.c_str()); + char* env = ::getenv(envName.c_str()); if (env) { @@ -113,12 +113,12 @@ bool Foam::setEnv Foam::word Foam::hostName(bool full) { char buf[128]; - gethostname(buf, sizeof(buf)); + ::gethostname(buf, sizeof(buf)); // implementation as per hostname from net-tools if (full) { - struct hostent *hp = gethostbyname(buf); + struct hostent *hp = ::gethostbyname(buf); if (hp) { return hp->h_name; @@ -132,13 +132,13 @@ Foam::word Foam::hostName(bool full) Foam::word Foam::domainName() { char buf[128]; - gethostname(buf, sizeof(buf)); + ::gethostname(buf, sizeof(buf)); // implementation as per hostname from net-tools - struct hostent *hp = gethostbyname(buf); + struct hostent *hp = ::gethostbyname(buf); if (hp) { - char *p = strchr(hp->h_name, '.'); + char *p = ::strchr(hp->h_name, '.'); if (p) { ++p; @@ -152,7 +152,7 @@ Foam::word Foam::domainName() Foam::word Foam::userName() { - struct passwd* pw = getpwuid(getuid()); + struct passwd* pw = ::getpwuid(::getuid()); if (pw != NULL) { @@ -167,14 +167,14 @@ Foam::word Foam::userName() bool Foam::isAdministrator() { - return (geteuid() == 0); + return (::geteuid() == 0); } // use $HOME environment variable or passwd info Foam::fileName Foam::home() { - char* env = getenv("HOME"); + char* env = ::getenv("HOME"); if (env != NULL) { @@ -182,7 +182,7 @@ Foam::fileName Foam::home() } else { - struct passwd* pw = getpwuid(getuid()); + struct passwd* pw = ::getpwuid(getuid()); if (pw != NULL) { @@ -202,18 +202,18 @@ Foam::fileName Foam::home(const word& userName) if (userName.size()) { - pw = getpwnam(userName.c_str()); + pw = ::getpwnam(userName.c_str()); } else { - char* env = getenv("HOME"); + char* env = ::getenv("HOME"); if (env != NULL) { return fileName(env); } - pw = getpwuid(getuid()); + pw = ::getpwuid(::getuid()); } if (pw != NULL) @@ -230,7 +230,7 @@ Foam::fileName Foam::home(const word& userName) Foam::fileName Foam::cwd() { char buf[256]; - if (getcwd(buf, sizeof(buf))) + if (::getcwd(buf, sizeof(buf))) { return buf; } @@ -247,7 +247,7 @@ Foam::fileName Foam::cwd() bool Foam::chDir(const fileName& dir) { - return chdir(dir.c_str()) == 0; + return ::chdir(dir.c_str()) == 0; } @@ -311,7 +311,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) // abort if the file is mandatory, otherwise return null if (mandatory) { - cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :" + std::cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :" " could not find mandatory file\n '" << name.c_str() << "'\n\n" << std::endl; ::exit(1); @@ -591,7 +591,7 @@ Foam::fileNameList Foam::readDir label nEntries = 0; // Attempt to open directory and set the structure pointer - if ((source = opendir(directory.c_str())) == NULL) + if ((source = ::opendir(directory.c_str())) == NULL) { dirEntries.setSize(0); @@ -605,7 +605,7 @@ Foam::fileNameList Foam::readDir else { // Read and parse all the entries in the directory - while ((list = readdir(source)) != NULL) + while ((list = ::readdir(source)) != NULL) { fileName fName(list->d_name); @@ -651,7 +651,7 @@ Foam::fileNameList Foam::readDir // Reset the length of the entries list dirEntries.setSize(nEntries); - closedir(source); + ::closedir(source); } return dirEntries; @@ -781,7 +781,7 @@ bool Foam::ln(const fileName& src, const fileName& dst) return false; } - if (symlink(src.c_str(), dst.c_str()) == 0) + if (::symlink(src.c_str(), dst.c_str()) == 0) { return true; } @@ -810,11 +810,11 @@ bool Foam::mv(const fileName& src, const fileName& dst) { const fileName dstName(dst/src.name()); - return rename(src.c_str(), dstName.c_str()) == 0; + return ::rename(src.c_str(), dstName.c_str()) == 0; } else { - return rename(src.c_str(), dst.c_str()) == 0; + return ::rename(src.c_str(), dst.c_str()) == 0; } } @@ -846,7 +846,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext) // possible index where we have no choice if (!exists(dstName, false) || n == maxIndex) { - return rename(src.c_str(), dstName.c_str()) == 0; + return ::rename(src.c_str(), dstName.c_str()) == 0; } } @@ -873,7 +873,7 @@ bool Foam::rm(const fileName& file) } else { - return remove(string(file + ".gz").c_str()) == 0; + return ::remove(string(file + ".gz").c_str()) == 0; } } @@ -892,7 +892,7 @@ bool Foam::rmDir(const fileName& directory) struct dirent *list; // Attempt to open directory and set the structure pointer - if ((source = opendir(directory.c_str())) == NULL) + if ((source = ::opendir(directory.c_str())) == NULL) { WarningIn("rmDir(const fileName&)") << "cannot open directory " << directory << endl; @@ -902,7 +902,7 @@ bool Foam::rmDir(const fileName& directory) else { // Read and parse all the entries in the directory - while ((list = readdir(source)) != NULL) + while ((list = ::readdir(source)) != NULL) { fileName fName(list->d_name); @@ -919,7 +919,7 @@ bool Foam::rmDir(const fileName& directory) << " while removing directory " << directory << endl; - closedir(source); + ::closedir(source); return false; } @@ -933,7 +933,7 @@ bool Foam::rmDir(const fileName& directory) << " while removing directory " << directory << endl; - closedir(source); + ::closedir(source); return false; } @@ -947,12 +947,12 @@ bool Foam::rmDir(const fileName& directory) WarningIn("rmDir(const fileName&)") << "failed to remove directory " << directory << endl; - closedir(source); + ::closedir(source); return false; } - closedir(source); + ::closedir(source); return true; } @@ -990,7 +990,7 @@ bool Foam::ping struct sockaddr_in destAddr; // will hold the destination addr u_int addr; - if ((hostPtr = gethostbyname(destName.c_str())) == NULL) + if ((hostPtr = ::gethostbyname(destName.c_str())) == NULL) { FatalErrorIn ( @@ -1003,7 +1003,7 @@ bool Foam::ping addr = (reinterpret_cast(*(hostPtr->h_addr_list)))->s_addr; // Allocate socket - sockfd = socket(AF_INET, SOCK_STREAM, 0); + sockfd = ::socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { FatalErrorIn @@ -1031,7 +1031,7 @@ bool Foam::ping if ( - connect + ::connect ( sockfd, reinterpret_cast(&destAddr), @@ -1074,19 +1074,19 @@ int Foam::system(const std::string& command) void* Foam::dlOpen(const fileName& lib) { - return dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL); + return ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL); } bool Foam::dlClose(void* handle) { - return dlclose(handle) == 0; + return ::dlclose(handle) == 0; } void* Foam::dlSym(void* handle, const std::string& symbol) { - void* fun = dlsym(handle, symbol.c_str()); + void* fun = ::dlsym(handle, symbol.c_str()); char *error; if ((error = dlerror()) != NULL) From 4aafea74a93ce8238933857a4fdfb70f07654cd5 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 24 Feb 2011 11:35:24 +0100 Subject: [PATCH 12/76] COMP: removed calcEntry bits missed in b4dae1a5ab621b811f3dcfec577cb3e94a46b23f --- applications/test/dictionary/testDictCalc | 31 ------------- .../test/dictionary/testDictCalcError | 46 ------------------- .../icoFoam/cavity/constant/polyMesh/boundary | 2 +- wmake/rules/General/standard | 2 +- 4 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 applications/test/dictionary/testDictCalc delete mode 100644 applications/test/dictionary/testDictCalcError diff --git a/applications/test/dictionary/testDictCalc b/applications/test/dictionary/testDictCalc deleted file mode 100644 index d57031f8d6..0000000000 --- a/applications/test/dictionary/testDictCalc +++ /dev/null @@ -1,31 +0,0 @@ -/*--------------------------------*- C++ -*----------------------------------*\ -| ========= | | -| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: Any | -| \\ / A nd | Web: www.OpenFOAM.com | -| \\/ M anipulation | | -\*---------------------------------------------------------------------------*/ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - object testDictCalc; -} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -flowRatePerHour 720; - -x 10; -y 20; -z t s v; -p #calc{ 1 + 2 + 10 * 15 + $x - $y }; - -// this calculation is in-place, but does not work inside a string: -flowRate "The flow rate " #calc{ $flowRatePerHour / 3600 } "kg/s"; - -// this is also okay -x #calc{ $x * 1E-3 }; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/test/dictionary/testDictCalcError b/applications/test/dictionary/testDictCalcError deleted file mode 100644 index 911df9feb8..0000000000 --- a/applications/test/dictionary/testDictCalcError +++ /dev/null @@ -1,46 +0,0 @@ -/*--------------------------------*- C++ -*----------------------------------*\ -| ========= | | -| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: Any | -| \\ / A nd | Web: www.OpenFOAM.com | -| \\/ M anipulation | | -\*---------------------------------------------------------------------------*/ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - object testDictCalcError; -} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -flowRatePerHour 720; - -x 10; -y 20; -z t s v; -// z #test{ // this -// 123 - 456 -// // comments // are -// /* stripped -// * 10 -// * {} -// */ -// + 1 /*100 */ 10 -// }; - -p this calculation #calc{ - 1xxx1 + 2 + 10 * 15 + - $x - $y - // $x + $y -} -is done inplace; - - -flowRate #calc{ $flowRatePerHour / 3600}; - -xxx yyy; -foo 30; -bar 15; - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary b/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary index 22050b51a1..ae94ef4763 100644 --- a/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary +++ b/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: dev.olesenm | +| \\ / O peration | Version: dev | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ diff --git a/wmake/rules/General/standard b/wmake/rules/General/standard index 76a60a31ce..d3e977df09 100644 --- a/wmake/rules/General/standard +++ b/wmake/rules/General/standard @@ -4,7 +4,7 @@ include $(GENERAL_RULES)/sourceToDep include $(GENERAL_RULES)/flex include $(GENERAL_RULES)/flex++ -include $(GENERAL_RULES)/coco-cpp +## include $(GENERAL_RULES)/coco-cpp ## include $(GENERAL_RULES)/byacc ## include $(GENERAL_RULES)/btyacc++ include $(GENERAL_RULES)/bison From 51399bbbd16d3a1a869d3e034cb363612ffb50d9 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 24 Feb 2011 13:21:39 +0100 Subject: [PATCH 13/76] STYLE: use dynamicCode/ instead of codeStream/ for dynamically generated code --- ReleaseNotes-dev | 8 ++++---- bin/tools/CleanFunctions | 10 +++++----- doc/changes/{codeStream.org => dynamicCode.org} | 9 +++++---- .../{codeStream => dynamicCode}/codeStreamTemplate.C | 0 .../fixedValueFvPatchScalarFieldTemplate.C | 0 .../fixedValueFvPatchScalarFieldTemplate.H | 0 etc/controlDict | 2 +- etc/settings.csh | 5 +++-- etc/settings.sh | 5 +++-- .../db/dynamicLibrary/codeStream/codeStreamTools.C | 10 +++++----- 10 files changed, 26 insertions(+), 23 deletions(-) rename doc/changes/{codeStream.org => dynamicCode.org} (93%) rename etc/codeTemplates/{codeStream => dynamicCode}/codeStreamTemplate.C (100%) rename etc/codeTemplates/{codeStream => dynamicCode}/fixedValueFvPatchScalarFieldTemplate.C (100%) rename etc/codeTemplates/{codeStream => dynamicCode}/fixedValueFvPatchScalarFieldTemplate.H (100%) diff --git a/ReleaseNotes-dev b/ReleaseNotes-dev index cb57f5cf9f..7583a3d999 100644 --- a/ReleaseNotes-dev +++ b/ReleaseNotes-dev @@ -140,7 +140,7 @@ + only files that can be re-read are being checked. Drastic reduction of number of files to check. *** *New* #codeStream dictionary entry - Uses on-the-fly compilation of OpenFOAM C++ code to construct dictionary. + Uses dynamic compilation of OpenFOAM C++ code to construct dictionary. E.g. in blockMeshDict: #+BEGIN_SRC c++ convertToMeters 0.001; @@ -160,7 +160,7 @@ #}; } #+END_SRC - See also ./[[doc/changes/codeStream.org]] + See also ./[[doc/changes/dynamicCode.org]] * Solvers A number of new solvers have been developed for a range of engineering @@ -191,7 +191,7 @@ + takes optional fieldName to sample + directMapped patch added 'normal' method to calculate sample points to e.g. sample fields just above wall (e.g. for streaklines) - + *New* codedFixedValue: Uses the on-the-fly code compilation from #codeStream + + *New* codedFixedValue: Uses the dynamic code compilation from #codeStream to provide an in-line fixedValueFvPatchScalarField. E.g. #+BEGIN_SRC c++ outlet @@ -206,7 +206,7 @@ #}; } #+END_SRC - See also [[./doc/changes/codeStream.org]] + See also [[./doc/changes/dynamicCode.org]] * Utilities There have been some utilities added and updated in this release. diff --git a/bin/tools/CleanFunctions b/bin/tools/CleanFunctions index 458fdc026e..3c1c9412d9 100644 --- a/bin/tools/CleanFunctions +++ b/bin/tools/CleanFunctions @@ -57,13 +57,13 @@ cleanTimeDirectories() # -# Remove codeStream subdirectory if it looks appropriate +# Remove dynamicCode subdirectory if it looks appropriate # -cleanCodeStream() +cleanDynamicCode() { - if [ -d system -a -d codeStream ] + if [ -d system -a -d dynamicCode ] then - rm -rf codeStream > /dev/null 2>&1 + rm -rf dynamicCode > /dev/null 2>&1 fi } @@ -71,7 +71,7 @@ cleanCodeStream() cleanCase() { cleanTimeDirectories - cleanCodeStream + cleanDynamicCode rm -rf processor* > /dev/null 2>&1 rm -rf probes* > /dev/null 2>&1 diff --git a/doc/changes/codeStream.org b/doc/changes/dynamicCode.org similarity index 93% rename from doc/changes/codeStream.org rename to doc/changes/dynamicCode.org index 6e26ba9810..1cd3d3338a 100644 --- a/doc/changes/codeStream.org +++ b/doc/changes/dynamicCode.org @@ -1,6 +1,6 @@ # -*- mode: org; -*- # -#+TITLE: =codeStream=: On-the-fly code compilation +#+TITLE: =dynamicCode=: Dynamic code compilation #+AUTHOR: OpenCFD Ltd. #+DATE: TBA #+LINK: http://www.openfoam.com @@ -47,12 +47,13 @@ =code=, =codeInclude=, =codeOptions= sections (these are just strings) and calculates the SHA1 checksum of the contents. - it copies a template file - =($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C)=, substituting all + =(~OpenFOAM/codeTemplates/dynamicCode/codeStreamTemplate.C)= or + =($FOAM_CODE_TEMPLATES/codeStreamTemplate.C)=, substituting all occurences of =code=, =codeInclude=, =codeOptions=. - - it writes library source files to =codeStream/= and compiles + - it writes library source files to =dynamicCode/= and compiles it using =wmake libso=. - the resulting library is generated under - =codeStream/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=) + =dynamicCode/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=) and the function executed - the function will have written its output into the Ostream which then gets used to construct the entry to replace the whole =#codeStream= section. diff --git a/etc/codeTemplates/codeStream/codeStreamTemplate.C b/etc/codeTemplates/dynamicCode/codeStreamTemplate.C similarity index 100% rename from etc/codeTemplates/codeStream/codeStreamTemplate.C rename to etc/codeTemplates/dynamicCode/codeStreamTemplate.C diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/dynamicCode/fixedValueFvPatchScalarFieldTemplate.C similarity index 100% rename from etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C rename to etc/codeTemplates/dynamicCode/fixedValueFvPatchScalarFieldTemplate.C diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H b/etc/codeTemplates/dynamicCode/fixedValueFvPatchScalarFieldTemplate.H similarity index 100% rename from etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H rename to etc/codeTemplates/dynamicCode/fixedValueFvPatchScalarFieldTemplate.H diff --git a/etc/controlDict b/etc/controlDict index 4aa8a3ec0a..cc45466672 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -39,7 +39,7 @@ InfoSwitches writePrecision 6; writeJobInfo 0; - // Allow case-supplied c++ code (#codeStream, codedFixedValue) + // Allow case-supplied C++ code (#codeStream, codedFixedValue) allowSystemOperations 0; } diff --git a/etc/settings.csh b/etc/settings.csh index a48a188382..48b234a337 100644 --- a/etc/settings.csh +++ b/etc/settings.csh @@ -63,8 +63,9 @@ setenv FOAM_SITE_LIBBIN $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/ setenv FOAM_USER_APPBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin setenv FOAM_USER_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib -# codeStream templates -setenv FOAM_CODESTREAM_TEMPLATE_DIR $WM_PROJECT_DIR/etc/codeTemplates/codeStream +# dynamicCode templates +# - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion +# setenv FOAM_CODE_TEMPLATES $WM_PROJECT_DIR/etc/codeTemplates/dynamicCode # convenience setenv FOAM_APP $WM_PROJECT_DIR/applications diff --git a/etc/settings.sh b/etc/settings.sh index 9281ffba95..beebfacf74 100644 --- a/etc/settings.sh +++ b/etc/settings.sh @@ -86,8 +86,9 @@ export FOAM_SITE_LIBBIN=$WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/ export FOAM_USER_APPBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin export FOAM_USER_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib -# codeStream templates -export FOAM_CODESTREAM_TEMPLATE_DIR=$WM_PROJECT_DIR/etc/codeTemplates/codeStream +# dynamicCode templates +# - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion +# export FOAM_CODE_TEMPLATES=$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode # convenience export FOAM_APP=$WM_PROJECT_DIR/applications diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C index cf252d1f8b..e29732ce8d 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C @@ -41,10 +41,10 @@ int Foam::codeStreamTools::allowSystemOperations const Foam::word Foam::codeStreamTools::codeTemplateEnvName - = "FOAM_CODESTREAM_TEMPLATES"; + = "FOAM_CODE_TEMPLATES"; const Foam::fileName Foam::codeStreamTools::codeTemplateDirName - = "codeTemplates/codeStream"; + = "codeTemplates/dynamicCode"; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -73,7 +73,7 @@ void Foam::codeStreamTools::checkSecurity Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName) { - return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName); + return stringOps::expand("$FOAM_CASE/dynamicCode/" + subDirName); } @@ -81,7 +81,7 @@ Foam::fileName Foam::codeStreamTools::libPath(const word& codeName) { return stringOps::expand ( - "$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib" + "$FOAM_CASE/dynamicCode/platforms/$WM_OPTIONS/lib/lib" + codeName + ".so" ); } @@ -95,7 +95,7 @@ Foam::string Foam::codeStreamTools::libTarget(const word& codeName) Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile) { - // try to get template from FOAM_CODESTREAM_TEMPLATES + // try to get template from FOAM_CODE_TEMPLATES fileName templateDir(Foam::getEnv(codeTemplateEnvName)); fileName file; From f2b04ab9a7b765f6f7ba4dbebdb8b4d3345aee17 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 15:37:38 +0000 Subject: [PATCH 14/76] COMP: promoted finiteVolume in build order --- src/Allwmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Allwmake b/src/Allwmake index 128d4a9845..9f90c0f641 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -38,9 +38,9 @@ parallel/decompose/AllwmakeLnInclude # dummyThirdParty (dummy metisDecomp, scotchDecomp etc) needed by e.g. meshTools dummyThirdParty/Allwmake $* +wmake $makeOption finiteVolume wmake $makeOption lagrangian/basic wmake $makeOption lagrangian/distributionModels -wmake $makeOption finiteVolume wmake $makeOption genericPatchFields # Build the proper scotchDecomp, metisDecomp etc. From 0bbd3e55e61793cfa972aa7a12243b99f748c1ca Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 15:41:47 +0000 Subject: [PATCH 15/76] ENH: moved pointInTet() to inside() method in tetrahedron --- .../primitiveShapes/tetrahedron/tetrahedron.H | 10 +++--- .../tetrahedron/tetrahedronI.H | 34 ++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H index 7e55cd872c..53e92c7f66 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H +++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -174,10 +174,10 @@ public: ) const; //- Return nearest point to p on tetrahedron - inline pointHit nearestPoint - ( - const point& p - ) const; + inline pointHit nearestPoint(const point& p) const; + + //- Return true if point is inside tetrahedron + inline bool inside(const point& pt) const; //- Return (min)containment sphere, i.e. the smallest sphere with // all points inside. Returns pointHit with: diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H index 38c9eae41c..309f16ddea 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -380,6 +380,38 @@ inline Foam::pointHit Foam::tetrahedron::nearestPoint } +template +bool Foam::tetrahedron::inside(const point& pt) const +{ + // For robustness, assuming that the point is in the tet unless + // "definitively" shown otherwise by obtaining a positive dot + // product greater than a tolerance of SMALL. + + // The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal + // vectors and base points for the half-space planes are: + // area[0] = Sa(); + // area[1] = Sb(); + // area[2] = Sc(); + // area[3] = Sd(); + // planeBase[0] = tetBasePt = tet.b() + // planeBase[1] = ptA = tet.c() + // planeBase[2] = tetBasePt = tet.b() + // planeBase[3] = tetBasePt = tet.b() + + vector n = Sa(); + n /= (Foam::mag(n) + VSMALL); + + if (((pt - b_) & n) > SMALL) + { + return false; + } + else + { + return true; + } +} + + // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template From d79c91e689a83fb8c1ed3de61996a5f7843c242e Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 15:44:22 +0000 Subject: [PATCH 16/76] ENH: added cloud autoMap bas method (was pure abstract) --- src/OpenFOAM/fields/cloud/cloud.C | 12 ++++++++++-- src/OpenFOAM/fields/cloud/cloud.H | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/fields/cloud/cloud.C b/src/OpenFOAM/fields/cloud/cloud.C index c4260f02ee..40eb070bcd 100644 --- a/src/OpenFOAM/fields/cloud/cloud.C +++ b/src/OpenFOAM/fields/cloud/cloud.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -41,7 +41,7 @@ Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName) ( IOobject ( - ( cloudName.size() ? cloudName : defaultName ), + (cloudName.size() ? cloudName : defaultName), obr.time().timeName(), prefix, obr, @@ -58,4 +58,12 @@ Foam::cloud::~cloud() {} +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::cloud::autoMap(const mapPolyMesh&) +{ + notImplemented("cloud::autoMap(const mapPolyMesh&)"); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/cloud/cloud.H b/src/OpenFOAM/fields/cloud/cloud.H index a4c4eae51e..0755c6dd61 100644 --- a/src/OpenFOAM/fields/cloud/cloud.H +++ b/src/OpenFOAM/fields/cloud/cloud.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -91,7 +91,7 @@ public: //- Remap the cells of particles corresponding to the // mesh topology change - virtual void autoMap(const mapPolyMesh&) = 0; + virtual void autoMap(const mapPolyMesh&); }; From 06024cf98882324584ad4b067b352dc89e5dd6cc Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 16:02:28 +0000 Subject: [PATCH 17/76] ENH: Updated lagrangian basic particle - removed templating - updated track data --- src/lagrangian/basic/particle/particle.C | 147 +++++ .../Particle.H => particle/particle.H} | 313 ++++------ .../ParticleI.H => particle/particleI.H} | 488 ++++----------- .../ParticleIO.C => particle/particleIO.C} | 96 +-- .../particleTemplates.C} | 562 ++++++++++-------- 5 files changed, 713 insertions(+), 893 deletions(-) create mode 100644 src/lagrangian/basic/particle/particle.C rename src/lagrangian/basic/{Particle/Particle.H => particle/particle.H} (75%) rename src/lagrangian/basic/{Particle/ParticleI.H => particle/particleI.H} (55%) rename src/lagrangian/basic/{Particle/ParticleIO.C => particle/particleIO.C} (66%) rename src/lagrangian/basic/{Particle/Particle.C => particle/particleTemplates.C} (62%) diff --git a/src/lagrangian/basic/particle/particle.C b/src/lagrangian/basic/particle/particle.C new file mode 100644 index 0000000000..c2ae9af0d2 --- /dev/null +++ b/src/lagrangian/basic/particle/particle.C @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2011 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 "particle.H" +#include "transform.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +Foam::label Foam::particle::particleCount_ = 0; + +const Foam::scalar Foam::particle::trackingCorrectionTol = 1e-5; + +namespace Foam +{ + defineTypeNameAndDebug(particle, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::particle::particle +( + const polyMesh& mesh, + const vector& position, + const label cellI, + const label tetFaceI, + const label tetPtI +) +: + mesh_(mesh), + position_(position), + cellI_(cellI), + faceI_(-1), + stepFraction_(0.0), + tetFaceI_(tetFaceI), + tetPtI_(tetPtI), + origProc_(Pstream::myProcNo()), + origId_(getNewParticleID()) +{} + + +Foam::particle::particle +( + const polyMesh& mesh, + const vector& position, + const label cellI, + bool doCellFacePt +) +: + mesh_(mesh), + position_(position), + cellI_(cellI), + faceI_(-1), + stepFraction_(0.0), + tetFaceI_(-1), + tetPtI_(-1), + origProc_(Pstream::myProcNo()), + origId_(getNewParticleID()) +{ + if (doCellFacePt) + { + initCellFacePt(); + } +} + + +Foam::particle::particle(const particle& p) +: + mesh_(p.mesh_), + position_(p.position_), + cellI_(p.cellI_), + faceI_(p.faceI_), + stepFraction_(p.stepFraction_), + tetFaceI_(p.tetFaceI_), + tetPtI_(p.tetPtI_), + origProc_(p.origProc_), + origId_(p.origId_) +{} + + +Foam::particle::particle(const particle& p, const polyMesh& mesh) +: + mesh_(mesh), + position_(p.position_), + cellI_(p.cellI_), + faceI_(p.faceI_), + stepFraction_(p.stepFraction_), + tetFaceI_(p.tetFaceI_), + tetPtI_(p.tetPtI_), + origProc_(p.origProc_), + origId_(p.origId_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::particle::transformPosition(const tensor& T) +{ + position_ = transform(T, position_); +} + + +void Foam::particle::transformProperties(const tensor&) +{} + + +void Foam::particle::transformProperties(const vector&) +{} + + +// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // + +bool Foam::operator==(const particle& pA, const particle& pB) +{ + return (pA.origProc() == pB.origProc() && pA.origId() == pB.origId()); +} + + +bool Foam::operator!=(const particle& pA, const particle& pB) +{ + return !(pA == pB); +} + + +// ************************************************************************* // diff --git a/src/lagrangian/basic/Particle/Particle.H b/src/lagrangian/basic/particle/particle.H similarity index 75% rename from src/lagrangian/basic/Particle/Particle.H rename to src/lagrangian/basic/particle/particle.H index 743925525a..f9b832348f 100644 --- a/src/lagrangian/basic/Particle/Particle.H +++ b/src/lagrangian/basic/particle/particle.H @@ -22,99 +22,102 @@ License along with OpenFOAM. If not, see . Class - Foam::Particle + Foam::particle Description + Base particle class \*---------------------------------------------------------------------------*/ -#ifndef Particle_H -#define Particle_H +#ifndef particle_H +#define particle_H #include "vector.H" +#include "Cloud.H" #include "IDLList.H" #include "labelList.H" #include "pointField.H" #include "faceList.H" -#include "typeInfo.H" +//#include "typeInfo.H" #include "OFstream.H" #include "tetPointRef.H" #include "FixedList.H" #include "polyMeshTetDecomposition.H" -#include "wallPolyPatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -template -class Cloud; +// Forward declaration of classes +class particle; + +class polyPatch; -class wedgePolyPatch; -class symmetryPolyPatch; class cyclicPolyPatch; class processorPolyPatch; +class symmetryPolyPatch; class wallPolyPatch; -class polyPatch; +class wedgePolyPatch; // Forward declaration of friend functions and operators -template -class Particle; - -// Friend Operators - -template Ostream& operator<< ( Ostream&, - const Particle& + const particle& ); -template -bool operator==(const Particle&, const Particle&); +bool operator==(const particle&, const particle&); -template -bool operator!=(const Particle&, const Particle&); +bool operator!=(const particle&, const particle&); /*---------------------------------------------------------------------------*\ - Class Particle Declaration + Class Particle Declaration \*---------------------------------------------------------------------------*/ -template -class Particle +class particle : - public IDLList::link + public IDLList::link { - public: - //- Class used to pass tracking data to the trackToFace function - class trackData + template + class TrackingData { - // Private data - //- Reference to the cloud containing this particle - Cloud& cloud_; + //- Reference to the cloud containing (this) particle + CloudType& cloud_; public: - bool switchProcessor; - bool keepParticle; + // Public data + + typedef CloudType cloudType; + + //- Flag to switch processor + bool switchProcessor; + + //- Flag to indicate whether to keep particle (false = delete) + bool keepParticle; - // Constructors - - inline trackData(Cloud& cloud); + // Constructor + TrackingData(CloudType& cloud) + : + cloud_(cloud) + {} // Member functions //- Return a reference to the cloud - inline Cloud& cloud(); + CloudType& cloud() + { + return cloud_; + } }; @@ -122,8 +125,8 @@ protected: // Protected data - //- Reference to the particle cloud - const Cloud& cloud_; + //- Reference to the polyMesh database + const polyMesh& mesh_; //- Position of particle vector position_; @@ -156,7 +159,7 @@ protected: // Private Member Functions //- Find the tet tri faces between position and tet centre - inline void findTris + void findTris ( const vector& position, DynamicList