From 7f7cbddd01d04096fff6b8d1b196da2242071219 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 16 Feb 2011 14:42:35 +0100 Subject: [PATCH 01/28] COMP: adjustments to compile with clang --- .../mesh/generation/extrude/extrudeMesh/extrudeMesh.C | 2 +- .../PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt | 1 + .../ForceTypes/ParticleForceList/ParticleForceList.C | 6 +++++- .../PressureGradient/PressureGradientForceI.H | 2 +- .../ParticleForces/BrownianMotion/BrownianMotionForce.C | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C index 5804d962c8..3a690cba2d 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C @@ -499,7 +499,7 @@ int main(int argc, char *argv[]) // Layers per point labelList nPointLayers(extrudePatch.nPoints(), model().nLayers()); // Displacement for first layer - vectorField firstLayerDisp = displacement*model().sumThickness(1); + vectorField firstLayerDisp(displacement*model().sumThickness(1)); // Expansion ratio not used. scalarField ratio(extrudePatch.nPoints(), 1.0); diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt index 93dc9f702e..2c4be8d2d0 100644 --- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt @@ -18,6 +18,7 @@ LINK_DIRECTORIES( ) INCLUDE_DIRECTORIES( + $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPV3Foam diff --git a/src/lagrangian/intermediate/submodels/ForceTypes/ParticleForceList/ParticleForceList.C b/src/lagrangian/intermediate/submodels/ForceTypes/ParticleForceList/ParticleForceList.C index 452ef6690d..710ecdbb62 100644 --- a/src/lagrangian/intermediate/submodels/ForceTypes/ParticleForceList/ParticleForceList.C +++ b/src/lagrangian/intermediate/submodels/ForceTypes/ParticleForceList/ParticleForceList.C @@ -71,7 +71,11 @@ Foam::ParticleForceList::ParticleForceList forAllConstIter(wordHashSet, models, iter) { const word& model = iter.key(); - set(i, ParticleForce::New(owner, mesh, dict, model)); + this->set + ( + i, + ParticleForce::New(owner, mesh, dict, model) + ); i++; } } diff --git a/src/lagrangian/intermediate/submodels/Kinematic/ParticleForces/PressureGradient/PressureGradientForceI.H b/src/lagrangian/intermediate/submodels/Kinematic/ParticleForces/PressureGradient/PressureGradientForceI.H index ac81740903..07b3d244be 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/ParticleForces/PressureGradient/PressureGradientForceI.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/ParticleForces/PressureGradient/PressureGradientForceI.H @@ -41,7 +41,7 @@ const "const" ) << "gradU field not allocated" << abort(FatalError); - return reinterpret_cast(0); + return *reinterpret_cast(0); } } diff --git a/src/lagrangian/intermediate/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C b/src/lagrangian/intermediate/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C index 5d2c759b94..71c0378e7c 100644 --- a/src/lagrangian/intermediate/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C +++ b/src/lagrangian/intermediate/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C @@ -72,7 +72,7 @@ Foam::BrownianMotionForce::BrownianMotionForce if (turbulence_) { HashTable models = - this->mesh().objectRegistry::lookupClass + this->mesh().objectRegistry::template lookupClass < compressible::turbulenceModel >(); From 32292113f8b090bed7b415713d9c1cd4af0c127e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 17 Feb 2011 16:11:55 +0100 Subject: [PATCH 02/28] ENH: catch empty wildcards in foamCleanPath - also split on colons for consistency --- bin/foamCleanPath | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/foamCleanPath b/bin/foamCleanPath index 71b9c2dfe4..0485c76dd1 100755 --- a/bin/foamCleanPath +++ b/bin/foamCleanPath @@ -3,7 +3,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 @@ -34,9 +34,11 @@ # - elements whose start matches a wildcard # - inaccessible directories (with the -strip (at your option) # -# Note: -# - this routine will fail when directories have embedded spaces -# - false matches possible if a wildcard contains '.' (sed regex) +# Note +# - this routine will fail when directories have embedded spaces +# - false matches possible if a wildcard contains '.' (sed regex) +# - the wildcards can themselves can be written together and separated +# by colons or whitespace #------------------------------------------------------------------------------ usage() { cat <&2 @@ -81,11 +83,12 @@ shift ##DEBUG echo "input>$dirList<" 1>&2 -# preserve current IFS and split on whitespace +# preserve current IFS and split on colon or whitespace oldIFS="$IFS" -IFS=' ' +IFS=': ' # "wildcard1 ... wildcardN" may have been passed as a single parameter +# or may contain ':' separators set -- $* # strip out wildcards via sed @@ -94,7 +97,11 @@ do wildcard=$1 shift ##DEBUG echo "remove>$wildcard<" 1>&2 - dirList=$(echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g") + + if [ -n "$wildcard" ] + then + dirList=$(echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g") + fi done # split on ':' (and on space as well to avoid any surprises) From cae015b61589187ff3df94c791d5364e526aee3d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 18 Feb 2011 17:26:54 +0100 Subject: [PATCH 03/28] COMP: clang++ -Woverloaded-virtual -> spurious warnings? disable for now - this behaviour changed in clang 2.9 between trunk 122348 and trunk 125662 --- wmake/rules/linux64Clang/c++ | 3 ++- wmake/rules/linuxClang/c++ | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wmake/rules/linux64Clang/c++ b/wmake/rules/linux64Clang/c++ index 11efc0c69b..0acf5ff38f 100644 --- a/wmake/rules/linux64Clang/c++ +++ b/wmake/rules/linux64Clang/c++ @@ -1,6 +1,7 @@ .SUFFIXES: .C .cxx .cc .cpp -c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor +# -Woverloaded-virtual may produce spurious warnings, disable for now +c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -Wno-overloaded-virtual CC = clang++ -m64 diff --git a/wmake/rules/linuxClang/c++ b/wmake/rules/linuxClang/c++ index eec5f2c081..5623184ed5 100644 --- a/wmake/rules/linuxClang/c++ +++ b/wmake/rules/linuxClang/c++ @@ -1,6 +1,7 @@ .SUFFIXES: .C .cxx .cc .cpp -c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# -Woverloaded-virtual may produce spurious warnings, disable for now +c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -Wno-overloaded-virtual CC = clang++ -m32 From fe9fc5e51dcb88755f60f8fa7125481e77799083 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 18 Feb 2011 17:52:42 +0100 Subject: [PATCH 04/28] COMP: remove regExp dependency from polyBoundaryMesh --- .../mesh/manipulation/createPatch/createPatch.C | 11 +++++++++-- .../PV3FoamReader/PV3FoamReader/CMakeLists.txt | 1 - .../polyMesh/polyBoundaryMesh/polyBoundaryMesh.C | 2 +- .../polyMesh/polyBoundaryMesh/polyBoundaryMesh.H | 5 +++-- .../field/nearWallFields/nearWallFields.C | 11 ++++++----- .../functionObjects/forces/forces/forces.C | 6 +++++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C index db2649a6bd..5a3a649f05 100644 --- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C +++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.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 @@ -45,6 +45,7 @@ Description #include "IOPtrList.H" #include "polyTopoChange.H" #include "polyModifyFace.H" +#include "wordReList.H" using namespace Foam; @@ -669,7 +670,13 @@ int main(int argc, char *argv[]) if (sourceType == "patches") { - labelHashSet patchSources(patches.patchSet(dict.lookup("patches"))); + labelHashSet patchSources + ( + patches.patchSet + ( + wordReList(dict.lookup("patches")) + ) + ); // Repatch faces of the patches. forAllConstIter(labelHashSet, patchSources, iter) diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt index 2c4be8d2d0..93dc9f702e 100644 --- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt @@ -18,7 +18,6 @@ LINK_DIRECTORIES( ) INCLUDE_DIRECTORIES( - $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPV3Foam diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 897e290b43..9d37047635 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -550,7 +550,7 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const Foam::labelHashSet Foam::polyBoundaryMesh::patchSet ( - const wordReList& patchNames, + const UList& patchNames, const bool warnNotFound ) const { diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 39fb527368..f86295abb5 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -38,7 +38,6 @@ SourceFiles #include "polyPatchList.H" #include "regIOobject.H" #include "labelPair.H" -#include "wordReList.H" #include "HashSet.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -46,7 +45,9 @@ SourceFiles namespace Foam { +// Forward declaration of classes class polyMesh; +class wordRe; // Forward declaration of friend functions and operators @@ -171,7 +172,7 @@ public: // By default warns if given names are not found. labelHashSet patchSet ( - const wordReList& patchNames, + const UList& patchNames, const bool warnNotFound = true ) const; diff --git a/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C b/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C index 2774396e4f..485e27b5c8 100644 --- a/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C +++ b/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C @@ -24,16 +24,14 @@ License \*---------------------------------------------------------------------------*/ #include "nearWallFields.H" +#include "wordReList.H" //#include "volFields.H" //#include "selfContainedDirectMappedFixedValueFvPatchFields.H" //#include "interpolationCellPoint.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - defineTypeNameAndDebug(nearWallFields, 0); -} +defineTypeNameAndDebug(Foam::nearWallFields, 0); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -87,7 +85,10 @@ void Foam::nearWallFields::read(const dictionary& dict) const fvMesh& mesh = refCast(obr_); dict.lookup("fields") >> fieldSet_; - patchSet_ = mesh.boundaryMesh().patchSet(dict.lookup("patches")); + patchSet_ = mesh.boundaryMesh().patchSet + ( + wordReList(dict.lookup("patches")) + ); distance_ = readScalar(dict.lookup("distance")); diff --git a/src/postProcessing/functionObjects/forces/forces/forces.C b/src/postProcessing/functionObjects/forces/forces/forces.C index aacc6b1947..6900d0da6a 100644 --- a/src/postProcessing/functionObjects/forces/forces/forces.C +++ b/src/postProcessing/functionObjects/forces/forces/forces.C @@ -27,6 +27,7 @@ License #include "volFields.H" #include "dictionary.H" #include "Time.H" +#include "wordReList.H" #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H" #include "incompressible/RAS/RASModel/RASModel.H" @@ -229,7 +230,10 @@ void Foam::forces::read(const dictionary& dict) const fvMesh& mesh = refCast(obr_); - patchSet_ = mesh.boundaryMesh().patchSet(dict.lookup("patches")); + patchSet_ = mesh.boundaryMesh().patchSet + ( + wordReList(dict.lookup("patches")) + ); if (directForceDensity_) { From 6590b211e926f3f7a389a9476d142b4c118f6f47 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 18 Feb 2011 18:21:11 +0100 Subject: [PATCH 05/28] COMP: remove regExp dependency from polyBoundaryMesh --- .../PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt index 701b09d359..93dc9f702e 100644 --- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/CMakeLists.txt @@ -18,7 +18,6 @@ LINK_DIRECTORIES( ) INCLUDE_DIRECTORIES( - $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE} $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPV3Foam From 02f345940232e61caf3ff1acdcb08be5cfdd6081 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 21 Feb 2011 17:03:33 +0100 Subject: [PATCH 06/28] ENH: SHA1Digest::str() returns std::string of digest directly --- .../fixedValueFvPatchScalarFieldTemplate.C | 2 +- src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C | 16 ++++++++++++++++ src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C index 937fb5b550..417b77ee68 100644 --- a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C +++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 20101-2011 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C index 2d2e51bf73..16dbd838cd 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C @@ -101,6 +101,22 @@ bool Foam::SHA1Digest::empty() const } +std::string Foam::SHA1Digest::str() const +{ + std::string buf; + buf.resize(length*2); + + unsigned nChar = 0; + for (unsigned i = 0; i < length; ++i) + { + buf[nChar++] = hexChars[((v_[i] >> 4) & 0xF)]; + buf[nChar++] = hexChars[(v_[i] & 0xF)]; + } + + return buf; +} + + // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H index 19c9698d13..dca6adc367 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H @@ -80,6 +80,9 @@ public: //- Return true if the digest is empty (ie, all zero). bool empty() const; + //- Return string representation + std::string str() const; + //- Equality operator bool operator==(const SHA1Digest&) const; From ba873744f3adea23d00967b0ead5cef5b5f4c52c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 10:20:55 +0100 Subject: [PATCH 07/28] ENH: add stringOps namespace with a collection of string-related ops --- src/OpenFOAM/Make/files | 1 + .../functionEntries/codeStream/codeStream.C | 10 +- .../functionEntries/codeStream/codeStream.H | 4 +- .../codeStream/codeStreamTools.C | 14 - .../codeStream/codeStreamTools.H | 2 - .../primitives/strings/string/string.C | 66 ++-- .../primitives/strings/stringOps/stringOps.C | 359 ++++++++++++++++++ .../primitives/strings/stringOps/stringOps.H | 159 ++++++++ 8 files changed, 560 insertions(+), 55 deletions(-) create mode 100644 src/OpenFOAM/primitives/strings/stringOps/stringOps.C create mode 100644 src/OpenFOAM/primitives/strings/stringOps/stringOps.H diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 0f00726bff..a2c32b809b 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -78,6 +78,7 @@ $(strings)/fileName/fileNameIO.C $(strings)/keyType/keyType.C $(strings)/wordRe/wordRe.C $(strings)/lists/hashedWordList.C +$(strings)/stringOps/stringOps.C primitives/hashes/Hasher/Hasher.C diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 297430715a..d91fcce979 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -31,6 +31,7 @@ License #include "SHA1Digest.H" #include "OSHA1stream.H" #include "codeStreamTools.H" +#include "stringOps.H" #include "dlLibraryTable.H" #include "OSspecific.H" #include "Time.H" @@ -87,19 +88,18 @@ bool Foam::functionEntries::codeStream::execute string codeInclude = ""; if (codeDict.found("codeInclude")) { - codeInclude = codeStreamTools::stripLeading(codeDict["codeInclude"]); + codeInclude = stringOps::trimLeft(codeDict["codeInclude"]); } - string code = codeStreamTools::stripLeading(codeDict["code"]); + string code = stringOps::trimLeft(codeDict["code"]); string codeOptions = ""; if (codeDict.found("codeOptions")) { - codeOptions = codeStreamTools::stripLeading(codeDict["codeOptions"]); + codeOptions = stringOps::trimLeft(codeDict["codeOptions"]); } - // Create name out of contents - + // Create name from the contents SHA1Digest sha; { OSHA1stream os; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index 9357c11a89..6375d1329e 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -84,13 +84,11 @@ SourceFiles namespace Foam { -class ISstream; - namespace functionEntries { /*---------------------------------------------------------------------------*\ - Class codeStream Declaration + Class codeStream Declaration \*---------------------------------------------------------------------------*/ class codeStream diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C index 1667d2be4e..337fc177e1 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C @@ -211,20 +211,6 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const } -Foam::string Foam::codeStreamTools::stripLeading(const string& s) -{ - label sz = s.size(); - if (sz > 0 && s[0] == '\n') - { - return s(1, sz-1); - } - else - { - return s; - } -} - - bool Foam::codeStreamTools::writeDigest ( const fileName& dir, diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H index 9a4f1dff45..d04d2fad5d 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -120,8 +120,6 @@ public: static void* findLibrary(const fileName& libPath); - static string stripLeading(const string&); - static bool writeDigest(const fileName& dir, const SHA1Digest& sha1); static SHA1Digest readDigest(const fileName& dir); static bool upToDate(const fileName& dir, const SHA1Digest& sha1); diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C index f1c10bc008..05ad3a5682 100644 --- a/src/OpenFOAM/primitives/strings/string/string.C +++ b/src/OpenFOAM/primitives/strings/string/string.C @@ -96,75 +96,79 @@ 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) { - size_type startEnvar = 0; + size_type begVar = 0; // Expand $VARS // Repeat until nothing more is found while ( - (startEnvar = find('$', startEnvar)) != npos - && startEnvar < size()-1 + (begVar = find('$', begVar)) != npos + && begVar < size()-1 ) { - if (startEnvar == 0 || operator[](startEnvar-1) != '\\') + if (begVar == 0 || operator[](begVar-1) != '\\') { // Find end of first occurrence - size_type endEnvar = startEnvar; - size_type nd = 0; + size_type endVar = begVar; + size_type delim = 0; - if (operator[](startEnvar+1) == '{') + if (operator[](begVar+1) == '{') { - endEnvar = find('}', startEnvar); - nd = 1; + endVar = find('}', begVar); + delim = 1; } else { - iterator iter = begin() + startEnvar + 1; + iterator iter = begin() + begVar + 1; - while (iter != end() && (isalnum(*iter) || *iter == '_')) + while + ( + iter != end() + && (isalnum(*iter) || *iter == '_') + ) { ++iter; - ++endEnvar; + ++endVar; } } - if (endEnvar != npos && endEnvar != startEnvar) + if (endVar != npos && endVar != begVar) { - string enVar = substr + string varName = substr ( - startEnvar + 1 + nd, - endEnvar - startEnvar - 2*nd + begVar + 1 + delim, + endVar - begVar - 2*delim ); - string enVarString = getEnv(enVar); + string varValue = getEnv(varName); - if (enVarString.size()) + if (varValue.size()) { if (recurse) { - enVarString.expand(recurse, allowEmptyVar); + varValue.expand(recurse, allowEmptyVar); } std::string::replace ( - startEnvar, - endEnvar - startEnvar + 1, - enVarString + begVar, + endVar - begVar + 1, + varValue ); - startEnvar += enVarString.size(); + begVar += varValue.size(); } else if (allowEmptyVar) { std::string::replace ( - startEnvar, - endEnvar - startEnvar + 1, + begVar, + endVar - begVar + 1, "" ); } else { FatalErrorIn("string::expand(const bool, const bool)") - << "Unknown variable name " << enVar << '.' + << "Unknown variable name " << varName << '.' << exit(FatalError); } } @@ -175,7 +179,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) } else { - startEnvar++; + ++begVar; } } @@ -191,10 +195,10 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) word user; fileName file; - if ((startEnvar = find('/')) != npos) + if ((begVar = find('/')) != npos) { - user = substr(1, startEnvar - 1); - file = substr(startEnvar + 1); + user = substr(1, begVar - 1); + file = substr(begVar + 1); } else { @@ -215,7 +219,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) } else if (operator[](0) == '.') { - // Expand initial '.' and './' into cwd + // Expand a lone '.' and an initial './' into cwd if (size() == 1) { *this = cwd(); diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C new file mode 100644 index 0000000000..e3a4d4c8db --- /dev/null +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -0,0 +1,359 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-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 "stringOps.H" +#include "OSspecific.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::string Foam::stringOps::expand +( + const string& original, + const HashTable& mapping, + const char sigil +) +{ + string str(original); + return inplaceExpand(str, mapping); +} + + +Foam::string& Foam::stringOps::inplaceExpand +( + string& s, + const HashTable& mapping, + 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; + + while + ( + iter != s.end() + && (isalnum(*iter) || *iter == '_') + ) + { + ++iter; + ++endVar; + } + } + + if (endVar != string::npos && endVar != begVar) + { + string varName = s.substr + ( + begVar + 1 + delim, + endVar - begVar - 2*delim + ); + + HashTable::const_iterator fnd = + mapping.find(varName); + + if (fnd != HashTable::end()) + { + s.std::string::replace + ( + begVar, + endVar - begVar + 1, + *fnd + ); + begVar += (*fnd).size(); + } + else + { + s.std::string::replace + ( + begVar, + endVar - begVar + 1, + "" + ); + } + } + else + { + break; + } + } + else + { + ++begVar; + } + } + + return s; +} + + +Foam::string Foam::stringOps::expandEnv +( + const string& original, + const bool recurse, + const bool allowEmptyVar +) +{ + string str(original); + return inplaceExpandEnv(str, recurse, allowEmptyVar); +} + + +// Expand all occurences of environment variables and initial tilde sequences +Foam::string& Foam::stringOps::inplaceExpandEnv +( + string& s, + const bool recurse, + const bool allowEmptyVar +) +{ + string::size_type begVar = 0; + + // Expand $VARS + // Repeat until nothing more is found + while + ( + (begVar = s.find('$', 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; + + while + ( + iter != s.end() + && (isalnum(*iter) || *iter == '_') + ) + { + ++iter; + ++endVar; + } + } + + if (endVar != string::npos && endVar != begVar) + { + string varName = s.substr + ( + begVar + 1 + delim, + endVar - begVar - 2*delim + ); + + string varValue = getEnv(varName); + + if (varValue.size()) + { + if (recurse) + { + varValue.expand(recurse, allowEmptyVar); + } + s.std::string::replace + ( + begVar, + endVar - begVar + 1, + varValue + ); + begVar += varValue.size(); + } + else if (allowEmptyVar) + { + s.std::string::replace + ( + begVar, + endVar - begVar + 1, + "" + ); + } + else + { + FatalErrorIn("string::expand(const bool, const bool)") + << "Unknown variable name " << varName << '.' + << exit(FatalError); + } + } + else + { + break; + } + } + else + { + ++begVar; + } + } + + if (!s.empty()) + { + if (s[0] == '~') + { + // Expand initial ~ + // ~/ => home directory + // ~OpenFOAM => site/user OpenFOAM configuration directory + // ~user => home directory for specified user + + word user; + fileName file; + + if ((begVar = s.find('/')) != string::npos) + { + user = s.substr(1, begVar - 1); + file = s.substr(begVar + 1); + } + else + { + user = s.substr(1); + } + + // NB: be a bit lazy and expand ~unknownUser as an + // empty string rather than leaving it untouched. + // otherwise add extra test + if (user == "OpenFOAM") + { + s = findEtcFile(file); + } + else + { + s = home(user)/file; + } + } + else if (s[0] == '.') + { + // Expand a lone '.' and an initial './' into cwd + if (s.size() == 1) + { + s = cwd(); + } + else if (s[1] == '/') + { + s.std::string::replace(0, 1, cwd()); + } + } + } + + return s; +} + + +Foam::string Foam::stringOps::trimLeft(const string& s) +{ + if (!s.empty()) + { + string::size_type beg = 0; + while (isspace(s[beg])) + { + ++beg; + } + + if (beg) + { + return s.substr(beg); + } + } + + return s; +} + + +Foam::string& Foam::stringOps::inplaceTrimLeft(string& s) +{ + if (!s.empty()) + { + string::size_type beg = 0; + while (isspace(s[beg])) + { + ++beg; + } + + if (beg) + { + s.erase(0, beg); + } + } + + return s; +} + + +Foam::string Foam::stringOps::trimRight(const string& s) +{ + notImplemented("string stringOps::trimRight(const string&)"); + return s; +} + + +Foam::string& Foam::stringOps::inplaceTrimRight(string& s) +{ + notImplemented("string& stringOps::inplaceTrimRight(string&)"); + return s; +} + + +Foam::string Foam::stringOps::trim(const string& original) +{ + notImplemented("string stringOps::trim(const string&)"); + return original; +} + + +Foam::string& Foam::stringOps::inplaceTrim(string& s) +{ + notImplemented("string& stringOps::inplaceTrim(string&)"); + return s; +} + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H new file mode 100644 index 0000000000..d9756a2705 --- /dev/null +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -0,0 +1,159 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-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 . + +Namespace + Foam::stringOps + +Description + Collection of static functions to do various simple string-related + operations + +SourceFiles + stringOps.C + +\*---------------------------------------------------------------------------*/ +#ifndef stringOps_H +#define stringOps_H + +#include "string.H" +#include "HashTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Namespace stringOps Declaration +\*---------------------------------------------------------------------------*/ + +namespace stringOps +{ + //- Expand occurences of variables according to the mapping + // Expansion includes: + // -# variables + // - "$VAR", "${VAR}" + // + // \note the leading sigil can be changed to avoid conflicts with other + // string expansions + string expand + ( + const string&, + const HashTable& mapping, + const char sigil = '$' + ); + + + //- Inplace expand occurences of variables according to the mapping + // Expansion includes: + // -# variables + // - "$VAR", "${VAR}" + // + // \note the leading sigil can be changed to avoid conflicts with other + // string expansions + string& inplaceExpand + ( + string&, + const HashTable& mapping, + const char sigil = '$' + ); + + + //- Expand initial tildes and all occurences of environment variables + // Expansion includes: + // -# environment variables + // - "$VAR", "${VAR}" + // -# current directory + // - leading "./" : the current directory + // -# tilde expansion + // - leading "~/" : home directory + // - leading "~user" : home directory for specified user + // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory + // + // \sa + // Foam::findEtcFile + string expandEnv + ( + const string&, + const bool recurse=false, + const bool allowEmptyVar = false + ); + + + //- Expand initial tildes and all occurences of environment variables + // Expansion includes: + // -# environment variables + // - "$VAR", "${VAR}" + // -# current directory + // - leading "./" : the current directory + // -# tilde expansion + // - leading "~/" : home directory + // - leading "~user" : home directory for specified user + // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory + // + // \sa + // Foam::findEtcFile + string& inplaceExpandEnv + ( + string&, + const bool recurse=false, + const bool allowEmptyVar = false + ); + + + //- Return string trimmed of leading whitespace + string trimLeft(const string&); + + //- Trim leading whitespace inplace + 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&); + + + +} // End namespace stringOps + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From 4aa279d7bc90006ca75d61f3b3b8118eb5d70b08 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 12:34:20 +0100 Subject: [PATCH 08/28] ENH: use HashTable for mapping codeStream entries - write intermediate code to _SHA1 directories - add Test-codeStream --- applications/test/codeStream/Make/files | 3 + applications/test/codeStream/Make/options | 1 + .../test/codeStream/Test-codeStream.C | 75 +++++++++++ applications/test/codeStream/codeStreamDict1 | 43 +++++++ .../codeStream/codeStreamTemplate.C | 7 + .../functionEntries/codeStream/codeStream.C | 108 ++++++++++------ .../functionEntries/codeStream/codeStream.H | 32 ++++- .../codeStream/codeStreamTools.C | 121 +++++++++--------- .../codeStream/codeStreamTools.H | 64 ++++++--- 9 files changed, 336 insertions(+), 118 deletions(-) create mode 100644 applications/test/codeStream/Make/files create mode 100644 applications/test/codeStream/Make/options create mode 100644 applications/test/codeStream/Test-codeStream.C create mode 100644 applications/test/codeStream/codeStreamDict1 diff --git a/applications/test/codeStream/Make/files b/applications/test/codeStream/Make/files new file mode 100644 index 0000000000..a5e2ef2d2f --- /dev/null +++ b/applications/test/codeStream/Make/files @@ -0,0 +1,3 @@ +Test-codeStream.C + +EXE = $(FOAM_USER_APPBIN)/Test-codeStream diff --git a/applications/test/codeStream/Make/options b/applications/test/codeStream/Make/options new file mode 100644 index 0000000000..41306609f2 --- /dev/null +++ b/applications/test/codeStream/Make/options @@ -0,0 +1 @@ +EXE_INC = diff --git a/applications/test/codeStream/Test-codeStream.C b/applications/test/codeStream/Test-codeStream.C new file mode 100644 index 0000000000..f2fbf75637 --- /dev/null +++ b/applications/test/codeStream/Test-codeStream.C @@ -0,0 +1,75 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-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 . + +Application + Test-codeStream + +Description + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "IOstreams.H" +#include "IOobject.H" +#include "IFstream.H" +#include "dictionary.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::noParallel(); + argList::validArgs.insert("dict .. dictN"); + argList args(argc, argv, false, true); + + Info<< nl + << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl + << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl + << endl; + + if (args.size() <= 1) + { + Info<<"specify dictionaries to test\n"; + } + else + { + IOobject::writeDivider(Info); + for (label argI=1; argI < args.size(); ++argI) + { + const string& dictFile = args[argI]; + IFstream is(dictFile); + + dictionary dict(is); + + Info<< dict << endl; + } + } + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/test/codeStream/codeStreamDict1 b/applications/test/codeStream/codeStreamDict1 new file mode 100644 index 0000000000..54fb3d0efe --- /dev/null +++ b/applications/test/codeStream/codeStreamDict1 @@ -0,0 +1,43 @@ +/*--------------------------------*- 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 testDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// #include "codeStreamDefaults" + +writeInterval #codeStream +{ + codeInclude + #{ + #include "fvCFD.H" + #}; + + codeOptions + #{ + -I$(LIB_SRC)/finiteVolume/lnInclude + #}; + + code + #{ + scalar start = 0; + scalar end = 100; + label nDumps = 5; + label interval = end - start; + Info<<"on-the-fly: " << ((interval)/nDumps) << endl; + os << ((interval)/nDumps); + #}; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/etc/codeTemplates/codeStream/codeStreamTemplate.C b/etc/codeTemplates/codeStream/codeStreamTemplate.C index af4f82ffc8..f6aa7501cc 100644 --- a/etc/codeTemplates/codeStream/codeStreamTemplate.C +++ b/etc/codeTemplates/codeStream/codeStreamTemplate.C @@ -21,9 +21,14 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . +Description + Template for use with codeStream. + \*---------------------------------------------------------------------------*/ +//{{{ begin codeInclude ${codeInclude} +//}}} end codeInclude using namespace Foam; @@ -39,7 +44,9 @@ void ${typeName} Ostream& os ) { +//{{{ begin code ${code}; +//}}} end code } } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index d91fcce979..5a27355410 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -57,6 +57,16 @@ namespace functionEntries } +const Foam::word Foam::functionEntries::codeStream::codeTemplateName + = "codeStreamTemplate.C"; + +const Foam::word Foam::functionEntries::codeStream::codeTemplateEnvName + = "FOAM_CODESTREAM_TEMPLATES"; + +const Foam::fileName Foam::functionEntries::codeStream::codeTemplateDirName + = "codeTemplates/codeStream"; + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionEntries::codeStream::execute @@ -80,57 +90,52 @@ bool Foam::functionEntries::codeStream::execute } - // Read three sections of code. Remove any leading empty lines - // (necessary for compilation options, just visually pleasing for includes - // and body). + // Read three sections of code. + // Remove any leading whitespace - necessary for compilation options, + // convenience for includes and body. dictionary codeDict(is); - string codeInclude = ""; + // "codeInclude" is optional + string codeInclude; if (codeDict.found("codeInclude")) { codeInclude = stringOps::trimLeft(codeDict["codeInclude"]); } - string code = stringOps::trimLeft(codeDict["code"]); - string codeOptions = ""; + // "codeOptions" is optional + string codeOptions; if (codeDict.found("codeOptions")) { codeOptions = stringOps::trimLeft(codeDict["codeOptions"]); } + // "code" is mandatory + string code = stringOps::trimLeft(codeDict["code"]); // Create name from the contents SHA1Digest sha; { OSHA1stream os; - os << codeInclude << code << codeOptions; + os << codeInclude << codeOptions << code; sha = os.digest(); } - fileName name; - { - OStringStream str; - str << sha; - name = "codeStream" + str.str(); - } + // write code into _SHA1 subdirectory fileName dir; if (isA(parentDict)) { const IOdictionary& d = static_cast(parentDict); - dir = d.db().time().constantPath()/"codeStream"/name; + dir = d.db().time().constantPath()/"codeStream"/"_" + sha.str(); } else { - dir = "codeStream"/name; + dir = fileName("codeStream")/"_" + sha.str(); } - + fileName name = "codeStream_" + sha.str(); fileName libPath ( - Foam::getEnv("FOAM_USER_LIBBIN") - / "lib" - + name - + ".so" + Foam::getEnv("FOAM_USER_LIBBIN")/"lib" + name + ".so" ); void* lib = dlLibraryTable::findLibrary(libPath); @@ -143,39 +148,64 @@ bool Foam::functionEntries::codeStream::execute { Info<< "Creating new library in " << libPath << endl; - fileName templates + fileName srcFile; + + // try to get template from FOAM_CODESTREAM_TEMPLATES + fileName templateDir ( - Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR") + Foam::getEnv(codeTemplateEnvName) ); - if (!templates.size()) + + if (!templateDir.empty()) + { + srcFile = templateDir/codeTemplateName; + if (!isFile(srcFile, false)) + { + srcFile.clear(); + } + } + + // not found - fallback to ~OpenFOAM expansion + if (srcFile.empty()) + { + srcFile = findEtcFile + ( + codeTemplateDirName/codeTemplateName + ); + } + + if (srcFile.empty()) { FatalIOErrorIn ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Please set environment variable" - " FOAM_CODESTREAM_TEMPLATE_DIR" - << " to point to the location of codeStreamTemplate.C" + ) << "Could not find the code template: " + << codeTemplateName << nl + << "Under the $FOAM_CODESTREAM_TEMPLATES directory" + << " via via the ~OpenFOAM/" / codeTemplateDirName + << " expansion" << exit(FatalIOError); } - List copyFiles(1); - copyFiles[0].first() = templates/"codeStreamTemplate.C"; - stringPairList bodyVars(2); - bodyVars[0] = Pair("codeInclude", codeInclude); - bodyVars[1] = Pair("code", code); - copyFiles[0].second() = bodyVars; - List filesContents(2); + List copyFiles(1); + copyFiles[0].file() = srcFile; + copyFiles[0].set("codeInclude", codeInclude); + copyFiles[0].set("code", code); + + List filesContents(2); + // Write Make/files filesContents[0].first() = "Make/files"; filesContents[0].second() = - "codeStreamTemplate.C \n\ - LIB = $(FOAM_USER_LIBBIN)/lib" + name; + codeTemplateName + "\n" + "LIB = $(FOAM_USER_LIBBIN)/lib" + name; + // Write Make/options filesContents[1].first() = "Make/options"; filesContents[1].second() = - "EXE_INC = -g\\\n" + codeOptions + "\n\nLIB_LIBS = "; + "EXE_INC = -g \\\n" + codeOptions + "\n\nLIB_LIBS ="; codeStreamTools writer(name, copyFiles, filesContents); if (!writer.copyFilesContents(dir)) @@ -199,7 +229,8 @@ bool Foam::functionEntries::codeStream::execute ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Failed " << wmakeCmd << exit(FatalIOError); + ) << "Failed " << wmakeCmd + << exit(FatalIOError); } } @@ -209,7 +240,8 @@ bool Foam::functionEntries::codeStream::execute ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Failed loading library " << libPath << exit(FatalIOError); + ) << "Failed loading library " << libPath + << exit(FatalIOError); } lib = dlLibraryTable::findLibrary(libPath); diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index 6375d1329e..ea732167b5 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -29,11 +29,12 @@ Description generate the entry itself. So - codeStream reads three entries: 'code', 'codeInclude' (optional), 'codeOptions' (optional) - and uses those to generate library sources inside constant/codeStream/ + and uses those to generate library sources inside \f constant/codeStream/ - these get compiled using 'wmake libso' - the resulting library is loaded in executed with as arguments - const dictionary& dict, - Ostream& os + \code + (const dictionary& dict, Ostream& os) + \endcode where the dictionary is the current dictionary. - the code has to write into Ostream which is then used to construct the actual dictionary entry. @@ -41,6 +42,7 @@ Description E.g. to set the internal field of a field: + \verbatim internalField #codeStream { code @@ -56,19 +58,23 @@ Description #{ #include "fvCFD.H" #}; + + //- Optional: codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude #}; }; + \endverbatim - Note the #{ #} syntax which is just a way of inputting strings with embedded - newlines. + Note the \c \#{ ... \c \#} syntax is a 'verbatim' input mode that allows + inputting strings with embedded newlines. Limitations: - '~' symbol not allowed inside the code sections. - - probably some other limitations (uses string::expand which expands $, ~) + - probably some other limitations (uses string::expand which expands + \c \$ and \c ~ sequences) SourceFiles codeStream.C @@ -106,6 +112,20 @@ class codeStream public: + // Static data members + + //- Name of the code template to be used + const static word codeTemplateName; + + //- Name of the code template environment variable + // Used to located the codeTemplateName + const static word codeTemplateEnvName; + + //- Name of the code template sub-directory + // Used when locating the codeTemplateName via Foam::findEtcFile + const static fileName codeTemplateDirName; + + //- Runtime type information ClassName("codeStream"); diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C index 337fc177e1..783f986a0e 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C @@ -25,6 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "codeStreamTools.H" +#include "stringOps.H" #include "IFstream.H" #include "OFstream.H" #include "OSspecific.H" @@ -43,38 +44,46 @@ int Foam::codeStreamTools::allowSystemOperations void Foam::codeStreamTools::copyAndExpand ( - ISstream& sourceStr, - OSstream& destStr + ISstream& is, + OSstream& os, + const HashTable& mapping ) const { - if (!sourceStr.good()) + if (!is.good()) { FatalErrorIn ( "codeStreamTools::copyAndExpand()" " const" - ) << "Failed opening for reading " << sourceStr.name() + ) << "Failed opening for reading " << is.name() << exit(FatalError); } - if (!destStr.good()) + if (!os.good()) { FatalErrorIn ( "codeStreamTools::copyAndExpand()" " const" - ) << "Failed writing " << destStr.name() << exit(FatalError); + ) << "Failed writing " << os.name() + << exit(FatalError); } - // Copy file whilst rewriting environment vars + // Copy file while rewriting $VARS and ${VARS} string line; do { - sourceStr.getLine(line); - line.expand(true, true); // replace any envvars inside substitutions - destStr<< line.c_str() << nl; + is.getLine(line); + + // normal expansion according to mapping + stringOps::inplaceExpand(line, mapping); + + // expand according to env variables + stringOps::inplaceExpandEnv(line, true, true); + + os << line.c_str() << nl; } - while (sourceStr.good()); + while (is.good()); } @@ -109,11 +118,11 @@ Foam::codeStreamTools::codeStreamTools {} -Foam::codeStreamTools::codeStreamTools(const codeStreamTools& otf) +Foam::codeStreamTools::codeStreamTools(const codeStreamTools& tools) : - name_(otf.name_), - copyFiles_(otf.copyFiles_), - filesContents_(otf.filesContents_) + name_(tools.name_), + copyFiles_(tools.copyFiles_), + filesContents_(tools.filesContents_) {} @@ -127,21 +136,17 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const ( "codeStreamTools::copyFilesContents(const fileName&) const" ) << "Loading a shared library using case-supplied code is not" - << " enabled by default" << endl + << " enabled by default" << nl << "because of security issues. If you trust the code you can" - << " enable this" << endl + << " enable this" << nl << "facility be adding to the InfoSwitches setting in the system" - << " controlDict" << endl - << endl - << " allowSystemOperations 1" << endl - << endl - << "The system controlDict is either" << endl - << endl - << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << endl - << endl - << "or" << endl - << endl - << " $WM_PROJECT_DIR/etc/controlDict" << endl + << " controlDict" << nl + << nl + << " allowSystemOperations 1" << nl << nl + << "The system controlDict is either" << nl << nl + << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl + << "or" << nl << nl + << " $WM_PROJECT_DIR/etc/controlDict" << nl << endl << exit(FatalError); } @@ -149,64 +154,64 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const // Create dir mkDir(dir); - //Info<< "Setting envvar typeName=" << name_ << endl; - setEnv("typeName", name_, true); + // Info<< "set mapping typeName=" << name_ << endl; // Copy any template files forAll(copyFiles_, i) { - const List >& rules = copyFiles_[i].second(); - forAll(rules, j) - { - //Info<< "Setting envvar " << rules[j].first() << endl; - setEnv(rules[j].first(), rules[j].second(), true); - } + const fileName sourceFile(fileName(copyFiles_[i].file()).expand()); + const fileName destFile(dir/sourceFile.name()); - const fileName sourceFile = fileName(copyFiles_[i].first()).expand(); - const fileName destFile = dir/sourceFile.name(); - - IFstream sourceStr(sourceFile); - //Info<< "Reading from " << sourceStr.name() << endl; - if (!sourceStr.good()) + IFstream is(sourceFile); + //Info<< "Reading from " << is.name() << endl; + if (!is.good()) { FatalErrorIn ( - "codeStreamTools::copyFilesContents()" + "codeStreamTools::copyFilesContents(const fileName&)" " const" ) << "Failed opening " << sourceFile << exit(FatalError); } - OFstream destStr(destFile); + OFstream os(destFile); //Info<< "Writing to " << destFile.name() << endl; - if (!destStr.good()) + if (!os.good()) { FatalErrorIn ( - "codeStreamTools::copyFilesContents()" + "codeStreamTools::copyFilesContents(const fileName&)" " const" ) << "Failed writing " << destFile << exit(FatalError); } - copyAndExpand(sourceStr, destStr); + // variables mapping + HashTable mapping(copyFiles_[i]); + mapping.set("typeName", name_); + copyAndExpand(is, os, mapping); } + // Files that are always written: forAll(filesContents_, i) { - fileName f = fileName(dir/filesContents_[i].first()).expand(); + const fileName dstFile + ( + fileName(dir/filesContents_[i].first()).expand() + ); - mkDir(f.path()); - OFstream str(f); + mkDir(dstFile.path()); + OFstream os(dstFile); //Info<< "Writing to " << filesContents_[i].first() << endl; - if (!str.good()) + if (!os.good()) { FatalErrorIn ( "codeStreamTools::copyFilesContents()" " const" - ) << "Failed writing " << f << exit(FatalError); + ) << "Failed writing " << dstFile << exit(FatalError); } - str << filesContents_[i].second().c_str() << endl; + os << filesContents_[i].second().c_str() << endl; } + return true; } @@ -217,16 +222,16 @@ bool Foam::codeStreamTools::writeDigest const SHA1Digest& sha1 ) { - OFstream str(dir/"SHA1Digest"); - str << sha1; - return str.good(); + OFstream os(dir/"SHA1Digest"); + os << sha1; + return os.good(); } Foam::SHA1Digest Foam::codeStreamTools::readDigest(const fileName& dir) { - IFstream str(dir/"SHA1Digest"); - return SHA1Digest(str); + IFstream is(dir/"SHA1Digest"); + return SHA1Digest(is); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H index d04d2fad5d..0e989eafd6 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -39,20 +39,16 @@ SourceFiles #include "Tuple2.H" #include "Pair.H" #include "SHA1Digest.H" +#include "HashTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - -typedef List > stringPairList; -typedef Tuple2 > > fileAndVars; -typedef Tuple2 fileAndContent; - - -class OSstream; +// Forward declaration of classes class ISstream; +class OSstream; /*---------------------------------------------------------------------------*\ Class codeStreamTools Declaration @@ -60,20 +56,56 @@ class ISstream; class codeStreamTools { +public: + typedef Tuple2 fileAndContent; + + //- Helper class for managing file and variables + class fileAndVars + : + public HashTable + { + // Private data + fileName file_; + + public: + //- Construct null + fileAndVars() + {} + + //- Return the file name + const fileName& file() const + { + return file_; + } + + //- Return the file name + fileName& file() + { + return file_; + } + }; + + +private: // Private data //- Name for underlying set word name_; //- Files to copy - List copyFiles_; + List copyFiles_; //- Direct contents for files List filesContents_; protected: - void copyAndExpand(ISstream&, OSstream&) const; + void copyAndExpand + ( + ISstream&, + OSstream&, + const HashTable& mapping + ) const; public: @@ -96,12 +128,17 @@ public: ); //- Construct copy - codeStreamTools(const codeStreamTools& otf); + codeStreamTools(const codeStreamTools&); // Member functions - const List > > >& copyFiles() const + const word& name() const + { + return name_; + } + + const List& copyFiles() const { return copyFiles_; } @@ -111,11 +148,6 @@ public: return filesContents_; } - const word& name() const - { - return name_; - } - bool copyFilesContents(const fileName& dir) const; static void* findLibrary(const fileName& libPath); From 5f883935f39bf23de7d19068f6f053bee4a9c9ae Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 22 Feb 2011 12:15:10 +0000 Subject: [PATCH 09/28] ENH: codeStream.org: updated with system/codeDict --- doc/changes/codeStream.org | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org index 92f60198b3..57bd7f46cd 100644 --- a/doc/changes/codeStream.org +++ b/doc/changes/codeStream.org @@ -76,6 +76,21 @@ It by default always includes =fvCFD.H= and adds the =finiteVolume= library to the include search path. + A special form is where the code is not supplied in-line but instead comes + from the =codeDict= dictionary in the =system= directory. It should contain + a =fixedValue10= entry: + #+BEGIN_SRC c++ + fixedValue10 + { + code + #{ + operator==(min(10, 0.1*this->db().time().value())); + #}; + } + #+END_SRC + The advantage of using this indirect way is that it supports + runTimeModifiable so any change of the code will be picked up next iteration. + * Security Allowing the case to execute C++ code does introduce security risks. A third-party case might have a =#codeStream{#code system("rm -rf .");};= hidden From e5f8d855ecebf647fbba8278e781b53c2f7c02d1 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 22 Feb 2011 12:15:59 +0000 Subject: [PATCH 10/28] ENH: codeStreamTemplate.C: added some default includes --- etc/codeTemplates/codeStream/codeStreamTemplate.C | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/codeTemplates/codeStream/codeStreamTemplate.C b/etc/codeTemplates/codeStream/codeStreamTemplate.C index af4f82ffc8..1dbf7cca74 100644 --- a/etc/codeTemplates/codeStream/codeStreamTemplate.C +++ b/etc/codeTemplates/codeStream/codeStreamTemplate.C @@ -23,6 +23,10 @@ License \*---------------------------------------------------------------------------*/ +#include "dictionary.H" +#include "Ostream.H" +#include "Pstream.H" + ${codeInclude} using namespace Foam; From d9a1d9c5bdc1b64032ad0449cd3b357cce0bbd56 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 22 Feb 2011 12:16:29 +0000 Subject: [PATCH 11/28] ENH: codeStream: derive input binary/ascii format. (though use of #codeStream in binary field?) --- .../db/dictionary/functionEntries/codeStream/codeStream.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 297430715a..476c5148e9 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -237,7 +237,7 @@ bool Foam::functionEntries::codeStream::execute << " in library " << lib << exit(FatalIOError); } - OStringStream os; + OStringStream os(is.format()); (*function)(parentDict, os); IStringStream resultStream(os.str()); entry.read(parentDict, resultStream); From f0f2bfa6325bd03e017d6e2d315c1ee81a9e2d75 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 15:01:20 +0100 Subject: [PATCH 12/28] ENH: refactor codeStreamTools, use for codedFixedValueFvPatchScalarField --- doc/changes/onTheFly.txt | 2 +- src/OSspecific/POSIX/POSIX.C | 8 +- .../functionEntries/codeStream/codeStream.C | 51 ++---- .../functionEntries/codeStream/codeStream.H | 12 +- .../codeStream/codeStreamTools.C | 47 +++++ .../codeStream/codeStreamTools.H | 22 ++- src/OpenFOAM/include/OSspecific.H | 6 +- .../codedFixedValueFvPatchScalarField.C | 171 ++++++++++-------- .../codedFixedValueFvPatchScalarField.H | 24 ++- 9 files changed, 210 insertions(+), 133 deletions(-) diff --git a/doc/changes/onTheFly.txt b/doc/changes/onTheFly.txt index 9734c1f5a8..2dc3f5edfa 100644 --- a/doc/changes/onTheFly.txt +++ b/doc/changes/onTheFly.txt @@ -49,7 +49,7 @@ Example: Look up dictionary entries and do some calculation code, codeInclude, codeOptions sections (these are just strings) and calculates the SHA1 checksum of the contents. - it copies a template file -($FOAM_CODESTREAM_TEMPLATE_DIR/codeStreamTemplate.C), substituting all +($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C), substituting all occurences of code, codeInclude, codeOptions. - it writes library source files to constant/codeStream/ and compiles it using 'wmake libso'. diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 155fcea58d..03eefb623b 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -102,7 +102,7 @@ Foam::string Foam::getEnv(const word& envName) bool Foam::setEnv ( const word& envName, - const string& value, + const std::string& value, const bool overwrite ) { @@ -1066,7 +1066,7 @@ bool Foam::ping(const word& hostname, const label timeOut) } -int Foam::system(const string& command) +int Foam::system(const std::string& command) { return ::system(command.c_str()); } @@ -1084,14 +1084,14 @@ bool Foam::dlClose(void* handle) } -void* Foam::dlSym(void* handle, const string& symbol) +void* Foam::dlSym(void* handle, const std::string& symbol) { void* fun = dlsym(handle, symbol.c_str()); char *error; if ((error = dlerror()) != NULL) { - WarningIn("dlSym(void*, const string&)") + WarningIn("dlSym(void*, const std::string&)") << "Cannot lookup symbol " << symbol << " : " << error << endl; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 5a27355410..5eb948eee1 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -57,15 +57,9 @@ namespace functionEntries } -const Foam::word Foam::functionEntries::codeStream::codeTemplateName +const Foam::word Foam::functionEntries::codeStream::codeTemplateC = "codeStreamTemplate.C"; -const Foam::word Foam::functionEntries::codeStream::codeTemplateEnvName - = "FOAM_CODESTREAM_TEMPLATES"; - -const Foam::fileName Foam::functionEntries::codeStream::codeTemplateDirName - = "codeTemplates/codeStream"; - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -148,49 +142,30 @@ bool Foam::functionEntries::codeStream::execute { Info<< "Creating new library in " << libPath << endl; - fileName srcFile; - - // try to get template from FOAM_CODESTREAM_TEMPLATES - fileName templateDir + const fileName fileCsrc ( - Foam::getEnv(codeTemplateEnvName) + codeStreamTools::findTemplate + ( + codeTemplateC + ) ); - if (!templateDir.empty()) - { - srcFile = templateDir/codeTemplateName; - if (!isFile(srcFile, false)) - { - srcFile.clear(); - } - } - - // not found - fallback to ~OpenFOAM expansion - if (srcFile.empty()) - { - srcFile = findEtcFile - ( - codeTemplateDirName/codeTemplateName - ); - } - - if (srcFile.empty()) + // not found! + if (fileCsrc.empty()) { FatalIOErrorIn ( "functionEntries::codeStream::execute(..)", parentDict ) << "Could not find the code template: " - << codeTemplateName << nl - << "Under the $FOAM_CODESTREAM_TEMPLATES directory" - << " via via the ~OpenFOAM/" / codeTemplateDirName - << " expansion" + << codeTemplateC << nl + << codeStreamTools::searchedLocations() << exit(FatalIOError); } List copyFiles(1); - copyFiles[0].file() = srcFile; + copyFiles[0].file() = fileCsrc; copyFiles[0].set("codeInclude", codeInclude); copyFiles[0].set("code", code); @@ -199,7 +174,7 @@ bool Foam::functionEntries::codeStream::execute // Write Make/files filesContents[0].first() = "Make/files"; filesContents[0].second() = - codeTemplateName + "\n" + codeTemplateC + "\n\n" "LIB = $(FOAM_USER_LIBBIN)/lib" + name; // Write Make/options @@ -214,7 +189,7 @@ bool Foam::functionEntries::codeStream::execute ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Failed writing " << endl + ) << "Failed writing " < copyFiles(2); - copyFiles[0].first() = - templates/"fixedValueFvPatchScalarFieldTemplate.C"; - - copyFiles[0].second().setSize(2); - copyFiles[0].second()[0] = Pair("codeInclude", codeInclude); - copyFiles[0].second()[1] = Pair("code", code); - - copyFiles[1].first() = - templates/"fixedValueFvPatchScalarFieldTemplate.H"; + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Could not find one or both code templates: " + << codeTemplateC << ", " << codeTemplateH << nl + << codeStreamTools::searchedLocations() + << exit(FatalIOError); + } - List filesContents(2); - // Write Make/files - filesContents[0].first() = "Make/files"; - filesContents[0].second() = - "fixedValueFvPatchScalarFieldTemplate.C \n\n" - "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_; - // Write Make/options - filesContents[1].first() = "Make/options"; - filesContents[1].second() = - "EXE_INC = -g\\\n -I$(LIB_SRC)/finiteVolume/lnInclude\\\n" - + codeOptions - + "\n\nLIB_LIBS = "; + List copyFiles(2); + copyFiles[0].file() = fileCsrc; + copyFiles[0].set("codeInclude", codeInclude); + copyFiles[0].set("code", code); - codeStreamTools writer(redirectType_, copyFiles, filesContents); - if (!writer.copyFilesContents(dir)) - { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Failed writing " << endl - << copyFiles << endl - << filesContents - << exit(FatalIOError); - } + copyFiles[1].file() = fileHsrc; + + + List filesContents(2); + + // Write Make/files + filesContents[0].first() = "Make/files"; + filesContents[0].second() = + codeTemplateC + "\n\n" + "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_; + + // Write Make/options + filesContents[1].first() = "Make/options"; + filesContents[1].second() = + "EXE_INC = -g \\\n-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" + + codeOptions + + "\n\nLIB_LIBS = "; + + codeStreamTools writer(redirectType_, copyFiles, filesContents); + if (!writer.copyFilesContents(dir)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Failed writing " << nl + << copyFiles << nl + << filesContents + << exit(FatalIOError); } } @@ -221,7 +248,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (Pstream::master()) { - Foam::string wmakeCmd("wmake libso " + dir); + const Foam::string wmakeCmd("wmake libso " + dir); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { @@ -229,7 +256,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() ( "codedFixedValueFvPatchScalarField::updateLibrary()", dict_ - ) << "Failed " << wmakeCmd << exit(FatalIOError); + ) << "Failed " << wmakeCmd + << exit(FatalIOError); } } @@ -242,7 +270,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() ( "codedFixedValueFvPatchScalarField::updateLibrary()", dict_ - ) << "Failed loading library " << libPath << exit(FatalIOError); + ) << "Failed loading library " << libPath + << exit(FatalIOError); } } } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H index 9b3ed6debf..25b259b84c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H @@ -32,7 +32,7 @@ Description See also codeStream. Example: - + \verbatim movingWall { type codedFixedValue; @@ -53,13 +53,14 @@ Description //#{ // -I$(LIB_SRC)/finiteVolume/lnInclude //#}; - } + \endverbatim A special form is if the 'code' section is not supplied. In this case the code gets read from a (runTimeModifiable!) dictionary system/codeDict which would have an entry + \verbatim rampedFixedValue { code @@ -67,6 +68,10 @@ Description operator==(min(10, 0.1*this->db().time().value())); #}; } + \endverbatim + +SeeAlso + Foam::codeStreamTools for constant paths used SourceFiles codedFixedValueFvPatchScalarField.C @@ -86,7 +91,7 @@ namespace Foam class codeProperties; /*---------------------------------------------------------------------------*\ - Class codedFixedValueFvPatchScalarField Declaration + Class codedFixedValueFvPatchScalarField Declaration \*---------------------------------------------------------------------------*/ class codedFixedValueFvPatchScalarField @@ -108,8 +113,8 @@ class codedFixedValueFvPatchScalarField void writeLibrary ( - const fileName dir, - const fileName libPath, + const fileName& dir, + const fileName& libPath, const dictionary& dict ); @@ -117,6 +122,15 @@ class codedFixedValueFvPatchScalarField public: + // Static data members + + //- Name of the C code template to be used + const static word codeTemplateC; + + //- Name of the H code template to be used + const static word codeTemplateH; + + //- Runtime type information TypeName("codedFixedValue"); From ea2fcaa08bd8a9892cb1a32399aabff2af33e4d7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 15:41:55 +0100 Subject: [PATCH 13/28] ENH: add verbose option for dlLibraryTable::open/close - allows silent operation when we know what we are doing. --- .../db/dlLibraryTable/dlLibraryTable.C | 40 +++++++++++++------ .../db/dlLibraryTable/dlLibraryTable.H | 10 ++--- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C index c98ba120a4..09537c8e73 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C +++ b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C @@ -62,7 +62,11 @@ Foam::dlLibraryTable::~dlLibraryTable() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::dlLibraryTable::open(const fileName& functionLibName) +bool Foam::dlLibraryTable::open +( + const fileName& functionLibName, + const bool verbose +) { if (functionLibName.size()) { @@ -70,11 +74,14 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName) if (!functionLibPtr) { - WarningIn - ( - "dlLibraryTable::open(const fileName& functionLibName)" - ) << "could not load " << functionLibName - << endl; + if (verbose) + { + WarningIn + ( + "dlLibraryTable::open(const fileName&)" + ) << "could not load " << functionLibName + << endl; + } return false; } @@ -97,7 +104,11 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName) } -bool Foam::dlLibraryTable::close(const fileName& functionLibName) +bool Foam::dlLibraryTable::close +( + const fileName& functionLibName, + const bool verbose +) { void* libPtr = findLibrary(functionLibName); if (libPtr) @@ -106,11 +117,14 @@ bool Foam::dlLibraryTable::close(const fileName& functionLibName) if (!dlClose(libPtr)) { - WarningIn - ( - "dlLibraryTable::close(const fileName& functionLibName)" - ) << "could not close " << functionLibName - << endl; + if (verbose) + { + WarningIn + ( + "dlLibraryTable::close(const fileName&)" + ) << "could not close " << functionLibName + << endl; + } return false; } @@ -144,7 +158,7 @@ bool Foam::dlLibraryTable::open { fileNameList libNames(dict.lookup(libsEntry)); - bool allOpened = (libNames.size() > 0); + bool allOpened = !libNames.empty(); forAll(libNames, i) { diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H index 1b64897dd0..aaf472f67e 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H +++ b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H @@ -94,11 +94,11 @@ public: // Member Functions - //- Open the named library - static bool open(const fileName& name); + //- Open the named library, optionally with warnings if problems occur + static bool open(const fileName& name, const bool verbose = true); - //- Close the named library - static bool close(const fileName& name); + //- Close the named library, optionally with warnings if problems occur + static bool close(const fileName& name, const bool verbose = true); //- Find the handle of the named library static void* findLibrary(const fileName& name); @@ -109,7 +109,7 @@ public: //- Open all the libraries listed in the 'libsEntry' entry in the // given dictionary if present and check the additions - // to the give constructor table + // to the given constructor table template static bool open ( From 141fe37a8645391a3cf6f27ddeb1e42a9b832b34 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 16:07:06 +0100 Subject: [PATCH 14/28] ENH: compile codeStream into local directory only --- .../functionEntries/codeStream/codeStream.C | 63 ++++++++++++------- .../functionEntries/codeStream/codeStream.H | 8 +++ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 5eb948eee1..9fae385a49 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -114,31 +114,46 @@ bool Foam::functionEntries::codeStream::execute sha = os.digest(); } - // write code into _SHA1 subdirectory - fileName dir; - if (isA(parentDict)) - { - const IOdictionary& d = static_cast(parentDict); - dir = d.db().time().constantPath()/"codeStream"/"_" + sha.str(); - } - else - { - dir = fileName("codeStream")/"_" + sha.str(); - } - fileName name = "codeStream_" + sha.str(); - fileName libPath + // the code name = prefix + sha1 + const fileName codeName("codeStream_" + sha.str()); + + // local directory for compile/link + const fileName baseDir ( - Foam::getEnv("FOAM_USER_LIBBIN")/"lib" + name + ".so" + stringOps::expandEnv("$FOAM_CASE/codeStream") ); + // code is written into _SHA1 subdir + const fileName codeDir + ( + baseDir + / "_" + sha.str() + ); + + // library is written into platforms/$WM_OPTIONS/lib subdir + const fileName libPath + ( + baseDir + / stringOps::expandEnv("platforms/$WM_OPTIONS/lib") + / "lib" + codeName + ".so" + ); + + void* lib = dlLibraryTable::findLibrary(libPath); + // try to load if not already loaded + if (!lib && dlLibraryTable::open(libPath, false)) + { + lib = dlLibraryTable::findLibrary(libPath); + } + + // did not load - need to compile it if (!lib) { if (Pstream::master()) { - if (!codeStreamTools::upToDate(dir, sha)) + if (!codeStreamTools::upToDate(codeDir, sha)) { Info<< "Creating new library in " << libPath << endl; @@ -175,15 +190,16 @@ bool Foam::functionEntries::codeStream::execute filesContents[0].first() = "Make/files"; filesContents[0].second() = codeTemplateC + "\n\n" - "LIB = $(FOAM_USER_LIBBIN)/lib" + name; + "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + + codeName; // Write Make/options filesContents[1].first() = "Make/options"; filesContents[1].second() = "EXE_INC = -g \\\n" + codeOptions + "\n\nLIB_LIBS ="; - codeStreamTools writer(name, copyFiles, filesContents); - if (!writer.copyFilesContents(dir)) + codeStreamTools writer(codeName, copyFiles, filesContents); + if (!writer.copyFilesContents(codeDir)) { FatalIOErrorIn ( @@ -196,7 +212,7 @@ bool Foam::functionEntries::codeStream::execute } } - Foam::string wmakeCmd("wmake libso " + dir); + const Foam::string wmakeCmd("wmake libso " + codeDir); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { @@ -209,7 +225,10 @@ bool Foam::functionEntries::codeStream::execute } } - if (!dlLibraryTable::open(libPath)) + bool dummy = true; + reduce(dummy, orOp()); + + if (!dlLibraryTable::open(libPath, false)) { FatalIOErrorIn ( @@ -231,7 +250,7 @@ bool Foam::functionEntries::codeStream::execute void (*function)(const dictionary&, Ostream&); function = reinterpret_cast ( - dlSym(lib, name) + dlSym(lib, codeName) ); if (!function) @@ -240,7 +259,7 @@ bool Foam::functionEntries::codeStream::execute ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Failed looking up symbol " << name + ) << "Failed looking up symbol " << codeName << " in library " << lib << exit(FatalIOError); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index ecfbd1836a..4aaf375b6d 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -76,6 +76,14 @@ Description - probably some other limitations (uses string::expand which expands \c \$ and \c ~ sequences) +Note + The code to be compiled is stored under the local \f codeStream directory + with a subdirectory name corresponding to the SHA1 of the contents. + + The corresponding library code is located under the local + \f codeStream/platforms/$WM_OPTIONS/lib directory in a library + \f libcodeStream_SHA1.so + SourceFiles codeStream.C From dce20ade07d96d147d05ce2dc74ee690aa5b4e25 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 16:25:34 +0100 Subject: [PATCH 15/28] ENH: compile codedFixedValueFvPatchScalarField into local directory only --- .../functionEntries/codeStream/codeStream.C | 10 +- .../functionEntries/codeStream/codeStream.H | 4 +- .../codeStream/codeStreamTools.H | 6 +- .../derived/codedFixedValue/codeProperties.H | 4 +- .../codedFixedValueFvPatchScalarField.C | 164 ++++++++++-------- 5 files changed, 103 insertions(+), 85 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 9fae385a49..409a9e1fcc 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -106,7 +106,7 @@ bool Foam::functionEntries::codeStream::execute // "code" is mandatory string code = stringOps::trimLeft(codeDict["code"]); - // Create name from the contents + // Create SHA1 digest from the contents SHA1Digest sha; { OSHA1stream os; @@ -196,7 +196,9 @@ bool Foam::functionEntries::codeStream::execute // Write Make/options filesContents[1].first() = "Make/options"; filesContents[1].second() = - "EXE_INC = -g \\\n" + codeOptions + "\n\nLIB_LIBS ="; + "EXE_INC = -g \\\n" + + codeOptions + + "\n\nLIB_LIBS ="; codeStreamTools writer(codeName, copyFiles, filesContents); if (!writer.copyFilesContents(codeDir)) @@ -225,8 +227,8 @@ bool Foam::functionEntries::codeStream::execute } } - bool dummy = true; - reduce(dummy, orOp()); +// bool dummy = true; +// reduce(dummy, orOp()); if (!dlLibraryTable::open(libPath, false)) { diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index 4aaf375b6d..e04bdceaa4 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -29,7 +29,7 @@ Description generate the entry itself. So - codeStream reads three entries: 'code', 'codeInclude' (optional), 'codeOptions' (optional) - and uses those to generate library sources inside \f constant/codeStream/ + and uses those to generate library sources inside \f codeStream/ - these get compiled using 'wmake libso' - the resulting library is loaded in executed with as arguments \code @@ -123,7 +123,7 @@ public: // Static data members //- Name of the C code template to be used - const static word codeTemplateC; + static const word codeTemplateC; //- Runtime type information diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H index 58f48cf6d0..4bcb7dc7a5 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -113,15 +113,15 @@ public: //- Name of the code template environment variable // Used to located the codeTemplateName - const static word codeTemplateEnvName; + static const word codeTemplateEnvName; //- Name of the code template sub-directory // Used when locating the codeTemplateName via Foam::findEtcFile - const static fileName codeTemplateDirName; - + static const fileName codeTemplateDirName; static int allowSystemOperations; + // Constructors //- Construct null diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H index 70e770c15a..6916fa362f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H @@ -44,7 +44,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class codeProperties Declaration + Class codeProperties Declaration \*---------------------------------------------------------------------------*/ class codeProperties @@ -79,7 +79,7 @@ public: modified_ = false; } - //- Read the solution dictionary + //- Read the dictionary virtual bool read(); }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 4525e6a3ae..368a9ca8ca 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -32,6 +32,8 @@ License #include "dlLibraryTable.H" #include "IFstream.H" #include "OFstream.H" +#include "SHA1Digest.H" +#include "OSHA1stream.H" #include "codeStreamTools.H" #include "codeProperties.H" #include "stringOps.H" @@ -78,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const void Foam::codedFixedValueFvPatchScalarField::writeLibrary ( - const fileName& dir, + const fileName& codeDir, const fileName& libPath, const dictionary& dict ) @@ -106,73 +108,73 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary // "code" is mandatory string code = stringOps::trimLeft(dict["code"]); - - Info<< "Creating new library in " << libPath << endl; - - const fileName fileCsrc - ( - codeStreamTools::findTemplate - ( - codeTemplateC - ) - ); - - const fileName fileHsrc - ( - codeStreamTools::findTemplate - ( - codeTemplateH - ) - ); - - if (fileCsrc.empty() || fileHsrc.empty()) + // Create SHA1 digest from the contents + SHA1Digest sha; { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Could not find one or both code templates: " - << codeTemplateC << ", " << codeTemplateH << nl - << codeStreamTools::searchedLocations() - << exit(FatalIOError); + OSHA1stream os; + os << codeInclude << codeOptions << code; + sha = os.digest(); } - - - List copyFiles(2); - copyFiles[0].file() = fileCsrc; - copyFiles[0].set("codeInclude", codeInclude); - copyFiles[0].set("code", code); - - copyFiles[1].file() = fileHsrc; - - - List filesContents(2); - - // Write Make/files - filesContents[0].first() = "Make/files"; - filesContents[0].second() = - codeTemplateC + "\n\n" - "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_; - - // Write Make/options - filesContents[1].first() = "Make/options"; - filesContents[1].second() = - "EXE_INC = -g \\\n-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" - + codeOptions - + "\n\nLIB_LIBS = "; - - codeStreamTools writer(redirectType_, copyFiles, filesContents); - if (!writer.copyFilesContents(dir)) + if (!codeStreamTools::upToDate(codeDir, sha)) { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Failed writing " << nl - << copyFiles << nl - << filesContents - << exit(FatalIOError); + Info<< "Creating new library in " << libPath << endl; + + const fileName fileCsrc(codeStreamTools::findTemplate(codeTemplateC)); + const fileName fileHsrc(codeStreamTools::findTemplate(codeTemplateH)); + + // not found! + if (fileCsrc.empty() || fileHsrc.empty()) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Could not find one or both code templates: " + << codeTemplateC << ", " << codeTemplateH << nl + << codeStreamTools::searchedLocations() + << exit(FatalIOError); + } + + + + List copyFiles(2); + copyFiles[0].file() = fileCsrc; + copyFiles[0].set("codeInclude", codeInclude); + copyFiles[0].set("code", code); + + copyFiles[1].file() = fileHsrc; + + + List filesContents(2); + + // Write Make/files + filesContents[0].first() = "Make/files"; + filesContents[0].second() = + codeTemplateC + "\n\n" + "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + + redirectType_; + + // Write Make/options + filesContents[1].first() = "Make/options"; + filesContents[1].second() = + "EXE_INC = -g \\\n" + "-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" + + codeOptions + + "\n\nLIB_LIBS = "; + + codeStreamTools writer(redirectType_, copyFiles, filesContents); + if (!writer.copyFilesContents(codeDir)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Failed writing " << nl + << copyFiles << nl + << filesContents + << exit(FatalIOError); + } } } @@ -192,17 +194,31 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() << exit(FatalIOError); } - const fileName dir = - db().time().constantPath()/"codeStream"/redirectType_; - //Info<< "dir:" << dir << endl; + // local directory for compile/link + const fileName baseDir + ( + stringOps::expandEnv("$FOAM_CASE/codeStream") + ); + // code is written into redirectType_ subdir + const fileName codeDir + ( + baseDir + / redirectType_ + ); + + + //Info<< "codeDir:" << codeDir << endl; + + // library is written into platforms/$WM_OPTIONS/lib subdir const fileName libPath ( - Foam::getEnv("FOAM_USER_LIBBIN") - / "lib" - + redirectType_ - + ".so" + baseDir + / stringOps::expandEnv("platforms/$WM_OPTIONS/lib") + / "lib" + redirectType_ + ".so" ); + + //Info<< "libPath:" << libPath << endl; void* lib = dlLibraryTable::findLibrary(libPath); @@ -211,7 +227,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (!lib) { - writeLibrary(dir, libPath, dict_); + writeLibrary(codeDir, libPath, dict_); } } else @@ -240,7 +256,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() } const dictionary& codeDict = onTheFlyDict.subDict(redirectType_); - writeLibrary(dir, libPath, codeDict); + writeLibrary(codeDir, libPath, codeDict); } } @@ -248,7 +264,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (Pstream::master()) { - const Foam::string wmakeCmd("wmake libso " + dir); + const Foam::string wmakeCmd("wmake libso " + codeDir); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { From 869d6fa4609852bd7f8ceea5f0f0bd741a465b18 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 22 Feb 2011 15:27:24 +0000 Subject: [PATCH 16/28] ENH: ReleaseNotes-dev: mention of clang --- ReleaseNotes-dev | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReleaseNotes-dev b/ReleaseNotes-dev index d5ab98d8fb..cb57f5cf9f 100644 --- a/ReleaseNotes-dev +++ b/ReleaseNotes-dev @@ -278,3 +278,7 @@ + multipleBoxes, hotBoxes, panel, evaporationTest + =interDyMFoam= tutorials: + testTubeMixer: showcases =solidBodyMotionFunction= + +* Other + + compilable with =clang= + In your prefs.sh set the WM_COMPILER to Clang From 79939b9e186b9cb288ecab5cafa6fa5401f3449d Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 22 Feb 2011 15:29:57 +0000 Subject: [PATCH 17/28] ENH: #codeStream: preserve across preprocessing - new token: token::VERBATIMSTRING - writing of this type in primitiveEntry - disabling of all functionEntries in entry --- .../changeDictionary/changeDictionary.C | 24 +++++++++++++++++++ .../foamUpgradeCyclics/foamUpgradeCyclics.C | 20 +++++++++++++++- doc/changes/codeStream.org | 3 ++- .../db/IOstreams/Pstreams/UIPstream.C | 7 +++++- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C | 3 ++- src/OpenFOAM/db/IOstreams/token/token.H | 2 ++ src/OpenFOAM/db/IOstreams/token/tokenI.H | 18 ++++++++++---- src/OpenFOAM/db/IOstreams/token/tokenIO.C | 11 ++++++++- src/OpenFOAM/db/dictionary/entry/entry.C | 10 +++++++- src/OpenFOAM/db/dictionary/entry/entry.H | 5 +++- src/OpenFOAM/db/dictionary/entry/entryIO.C | 21 ++++++++++++---- .../primitiveEntry/primitiveEntryIO.C | 17 ++++++++++--- 12 files changed, 121 insertions(+), 20 deletions(-) diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index 083107efb9..c5df6ef79f 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -60,6 +60,8 @@ Usage \param -literalRE \n Do not interpret regular expressions; treat them as any other keyword. + \param -enableFunctionEntries \n + By default all dictionary preprocessing of fields is disabled \*---------------------------------------------------------------------------*/ @@ -255,6 +257,11 @@ int main(int argc, char *argv[]) "literalRE", "treat regular expressions literally (ie, as a keyword)" ); + argList::addBoolOption + ( + "enableFunctionEntries", + "enable expansion of dictionary directives - #include, #codeStream etc" + ); #include "addRegionOption.H" #include "setRootCase.H" @@ -271,6 +278,20 @@ int main(int argc, char *argv[]) << " not present." << endl; } + const bool enableEntries = args.optionFound("enableFunctionEntries"); + if (enableEntries) + { + Info<< "Allowing dictionary preprocessing ('#include', '#codeStream')." + << endl; + } + + int oldFlag = entry::disableFunctionEntries; + if (!enableEntries) + { + // By default disable dictionary expansion for fields + entry::disableFunctionEntries = 1; + } + fileName regionPrefix = ""; if (regionName != fvMesh::defaultRegion) @@ -410,6 +431,7 @@ int main(int argc, char *argv[]) false ) ); + const_cast(IOdictionary::typeName) = oldTypeName; // Fake type back to what was in field const_cast(fieldDict.type()) = fieldDict.headerClassName(); @@ -429,6 +451,8 @@ int main(int argc, char *argv[]) } } + entry::disableFunctionEntries = oldFlag; + Info<< endl; Info<< "End\n" << endl; diff --git a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C index dd44b49280..f1a7ab5301 100644 --- a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C +++ b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C @@ -34,6 +34,9 @@ Usage \param -test \n Suppress writing the updated files with split cyclics + \param -enableFunctionEntries \n + By default all dictionary preprocessing of fields is disabled + \*---------------------------------------------------------------------------*/ #include "argList.H" @@ -391,7 +394,12 @@ int main(int argc, char *argv[]) { timeSelector::addOptions(); - argList::addBoolOption("test"); + argList::addBoolOption("test", "test only; do not change any files"); + argList::addBoolOption + ( + "enableFunctionEntries", + "enable expansion of dictionary directives - #include, #codeStream etc" + ); # include "addRegionOption.H" # include "setRootCase.H" @@ -404,6 +412,7 @@ int main(int argc, char *argv[]) { Info<< "-test option: no changes made" << nl << endl; } + const bool enableEntries = args.optionFound("enableFunctionEntries"); Foam::word regionName = polyMesh::defaultRegion; @@ -482,6 +491,13 @@ int main(int argc, char *argv[]) IOobjectList objects(runTime, runTime.timeName()); + int oldFlag = entry::disableFunctionEntries; + if (!enableEntries) + { + // By default disable dictionary expansion for fields + entry::disableFunctionEntries = 1; + } + // volFields // ~~~~~~~~~ @@ -615,6 +631,8 @@ int main(int argc, char *argv[]) thisNames, nbrNames ); + + entry::disableFunctionEntries = oldFlag; } return 0; diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org index 57bd7f46cd..3297d26573 100644 --- a/doc/changes/codeStream.org +++ b/doc/changes/codeStream.org @@ -136,7 +136,8 @@ - =foamFormatConvert= - =changeDictionaryDict= - =foamUpgradeCyclics= - - =fieldToCell= + These applications will usually switch off all '#' processing. + Note: above field initialisation has the problem that the boundary conditions are not evaluated so e.g. processor boundaries will not hold the opposite cell diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C index f0026c2ff0..50728c425c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.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 @@ -162,11 +162,16 @@ Foam::Istream& Foam::UIPstream::read(token& t) // String case token::STRING : + case token::VERBATIMSTRING : { string* pval = new string; if (read(*pval)) { t = pval; + if (c == token::VERBATIMSTRING) + { + t.type() = token::VERBATIMSTRING; + } } else { diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index 135f61823a..90e2a46c82 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -203,7 +203,7 @@ Foam::Istream& Foam::ISstream::read(token& t) return *this; } - // Verbatim string + // Possible verbatim string or dictionary functionEntry case token::HASH : { char nextC; @@ -226,6 +226,7 @@ Foam::Istream& Foam::ISstream::read(token& t) else { t = sPtr; + t.type() = token::VERBATIMSTRING; } return *this; diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 7c91758c1a..c48c22b5c3 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -78,6 +78,7 @@ public: PUNCTUATION, WORD, STRING, + VERBATIMSTRING, LABEL, FLOAT_SCALAR, DOUBLE_SCALAR, @@ -318,6 +319,7 @@ public: // Access inline tokenType type() const; + inline tokenType& type(); inline bool good() const; inline bool undefined() const; diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index 6c3434dead..11124e9e2a 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.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 @@ -39,7 +39,7 @@ inline void token::clear() { delete wordTokenPtr_; } - else if (type_ == STRING) + else if (type_ == STRING || type_ == VERBATIMSTRING) { delete stringTokenPtr_; } @@ -88,6 +88,7 @@ inline token::token(const token& t) break; case STRING: + case VERBATIMSTRING: stringTokenPtr_ = new string(*t.stringTokenPtr_); break; @@ -178,6 +179,11 @@ inline token::tokenType token::type() const return type_; } +inline token::tokenType& token::type() +{ + return type_; +} + inline bool token::good() const { return (type_ != ERROR && type_ != UNDEFINED); @@ -231,12 +237,12 @@ inline const word& token::wordToken() const inline bool token::isString() const { - return (type_ == STRING); + return (type_ == STRING || type_ == VERBATIMSTRING); } inline const string& token::stringToken() const { - if (type_ == STRING) + if (type_ == STRING || type_ == VERBATIMSTRING) { return *stringTokenPtr_; } @@ -405,6 +411,7 @@ inline void token::operator=(const token& t) break; case STRING: + case VERBATIMSTRING: stringTokenPtr_ = new string(*t.stringTokenPtr_); break; @@ -511,6 +518,7 @@ inline bool token::operator==(const token& t) const return *wordTokenPtr_ == *t.wordTokenPtr_; case STRING: + case VERBATIMSTRING: return *stringTokenPtr_ == *t.stringTokenPtr_; case LABEL: @@ -544,7 +552,7 @@ inline bool token::operator==(const word& w) const inline bool token::operator==(const string& s) const { - return (type_ == STRING && stringToken() == s); + return ((type_ == STRING || type_ == VERBATIMSTRING) && stringToken() == s); } inline bool token::operator==(const label l) const diff --git a/src/OpenFOAM/db/IOstreams/token/tokenIO.C b/src/OpenFOAM/db/IOstreams/token/tokenIO.C index bf7cdd081d..23c17e75e5 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenIO.C +++ b/src/OpenFOAM/db/IOstreams/token/tokenIO.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 @@ -70,6 +70,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t) break; case token::STRING: + case token::VERBATIMSTRING: os << *t.stringTokenPtr_; break; @@ -156,6 +157,10 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy& ip) os << " the string " << t.stringToken(); break; + case token::VERBATIMSTRING: + os << " the verbatim string " << t.stringToken(); + break; + case token::LABEL: os << " the label " << t.labelToken(); break; @@ -226,6 +231,10 @@ Ostream& operator<<(Ostream& os, const InfoProxy& ip) os << " the string " << t.stringToken(); break; + case token::VERBATIMSTRING: + os << " the verbatim string " << t.stringToken(); + break; + case token::LABEL: os << " the label " << t.labelToken(); break; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index de62c861a4..3bba611dee 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.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 @@ -27,6 +27,14 @@ License #include "dictionary.H" #include "OStringStream.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +int Foam::entry::disableFunctionEntries +( + Foam::debug::infoSwitch("disableFunctionEntries", 0) +); + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::entry::entry(const keyType& keyword) diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index 21f5634728..93b5a143a2 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.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 @@ -81,6 +81,9 @@ class entry public: + static int disableFunctionEntries; + + // Constructors //- Construct from keyword diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index c61a97e7c5..1f3172f0e5 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.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 @@ -98,21 +98,32 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) } else // Keyword starts entry ... { - if (keyword[0] == '#') // ... Function entry + if + ( + !disableFunctionEntries + && keyword[0] == '#' + ) // ... Function entry { word functionName = keyword(1, keyword.size()-1); return functionEntry::execute(functionName, parentDict, is); } - else if (keyword[0] == '$') // ... Substitution entry + else if + ( + !disableFunctionEntries + && keyword[0] == '$') // ... Substitution entry { parentDict.substituteKeyword(keyword); return true; } - else if (keyword == "include") // ... For backward compatibility + else if + ( + !disableFunctionEntries + && keyword == "include" + ) // ... For backward compatibility { return functionEntries::includeEntry::execute(parentDict, is); } - else // ... Data entries + else // ... Data entries { token nextToken(is); is.putBack(nextToken); diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index a7fcb0c64d..fa9a50efdb 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.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 @@ -44,7 +44,8 @@ void Foam::primitiveEntry::append if ( - w.size() == 1 + disableFunctionEntries + || w.size() == 1 || ( !(w[0] == '$' && expandVariable(w, dict)) && !(w[0] == '#' && expandFunction(w, dict, is)) @@ -215,7 +216,17 @@ void Foam::primitiveEntry::write(Ostream& os) const for (label i=0; i Date: Tue, 22 Feb 2011 18:22:57 +0100 Subject: [PATCH 18/28] STYLE: refactor codeStream code into codeStreamTools --- .../functionEntries/codeStream/codeStream.C | 36 ++++-------- .../codeStream/codeStreamTools.C | 37 +++++++++++++ .../codeStream/codeStreamTools.H | 38 ++++++++++--- .../codedFixedValueFvPatchScalarField.C | 55 ++++++++----------- .../codedFixedValueFvPatchScalarField.H | 8 ++- 5 files changed, 108 insertions(+), 66 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 409a9e1fcc..02b5ec77f2 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -115,29 +115,14 @@ bool Foam::functionEntries::codeStream::execute } - // the code name = prefix + sha1 - const fileName codeName("codeStream_" + sha.str()); + // codeName = prefix + sha1 + const fileName codeName = "codeStream_" + sha.str(); - // local directory for compile/link - const fileName baseDir - ( - stringOps::expandEnv("$FOAM_CASE/codeStream") - ); + // write code into _SHA1 subdir + const fileName codePath = codeStreamTools::codePath("_" + sha.str()); - // code is written into _SHA1 subdir - const fileName codeDir - ( - baseDir - / "_" + sha.str() - ); - - // library is written into platforms/$WM_OPTIONS/lib subdir - const fileName libPath - ( - baseDir - / stringOps::expandEnv("platforms/$WM_OPTIONS/lib") - / "lib" + codeName + ".so" - ); + // write library into platforms/$WM_OPTIONS/lib subdir + const fileName libPath = codeStreamTools::libPath(codeName); void* lib = dlLibraryTable::findLibrary(libPath); @@ -153,7 +138,7 @@ bool Foam::functionEntries::codeStream::execute { if (Pstream::master()) { - if (!codeStreamTools::upToDate(codeDir, sha)) + if (!codeStreamTools::upToDate(codePath, sha)) { Info<< "Creating new library in " << libPath << endl; @@ -190,8 +175,7 @@ bool Foam::functionEntries::codeStream::execute filesContents[0].first() = "Make/files"; filesContents[0].second() = codeTemplateC + "\n\n" - "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" - + codeName; + + codeStreamTools::libTarget(codeName); // Write Make/options filesContents[1].first() = "Make/options"; @@ -201,7 +185,7 @@ bool Foam::functionEntries::codeStream::execute + "\n\nLIB_LIBS ="; codeStreamTools writer(codeName, copyFiles, filesContents); - if (!writer.copyFilesContents(codeDir)) + if (!writer.copyFilesContents(codePath)) { FatalIOErrorIn ( @@ -214,7 +198,7 @@ bool Foam::functionEntries::codeStream::execute } } - const Foam::string wmakeCmd("wmake libso " + codeDir); + const Foam::string wmakeCmd("wmake libso " + codePath); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C index 1b7928ee32..cf9f1a324a 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C @@ -49,6 +49,43 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +Foam::fileName Foam::codeStreamTools::baseDir() +{ + return stringOps::expandEnv("$FOAM_CASE/codeStream"); +} + + +Foam::fileName Foam::codeStreamTools::libSubDir() +{ + return stringOps::expandEnv("platforms/$WM_OPTIONS/lib"); +} + + +Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName) +{ + return stringOps::expandEnv + ( + "$FOAM_CASE/codeStream/" + subDirName + ); +} + + +Foam::fileName Foam::codeStreamTools::libPath(const word& codeName) +{ + return stringOps::expandEnv + ( + "$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib" + + codeName + ".so" + ); +} + + +Foam::string Foam::codeStreamTools::libTarget(const word& codeName) +{ + return "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeName; +} + + Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile) { // try to get template from FOAM_CODESTREAM_TEMPLATES diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H index 4bcb7dc7a5..4f158b6aea 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -119,6 +119,7 @@ public: // Used when locating the codeTemplateName via Foam::findEtcFile static const fileName codeTemplateDirName; + static int allowSystemOperations; @@ -144,6 +145,35 @@ 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); + + //- Local library path for specified code name + // Expanded from \$FOAM_CASE/platforms/\$WM_OPTIONS/lib + static fileName libPath(const word& codeName); + + //- The library target path for Make/files + static string libTarget(const word& codeName); + + + //- Find a code-template via the codeTemplateEnvName + // alternatively in the codeTemplateDirName via Foam::findEtcFile + static fileName findTemplate(const word& templateName); + + //- List searched locations in a format suitable for display an error + static string searchedLocations(); + + + const word& name() const { return name_; @@ -162,14 +192,6 @@ public: bool copyFilesContents(const fileName& dir) const; - //- Find a code-template via the codeTemplateEnvName - // alternatively in the codeTemplateDirName via Foam::findEtcFile - static fileName findTemplate(const word& templateName); - - //- List searched locations in a format suitable for display an error - static string searchedLocations(); - - static void* findLibrary(const fileName& libPath); static bool writeDigest(const fileName& dir, const SHA1Digest& sha1); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 368a9ca8ca..9ab2ba1368 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -80,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const void Foam::codedFixedValueFvPatchScalarField::writeLibrary ( - const fileName& codeDir, + const fileName& codePath, const fileName& libPath, const dictionary& dict ) @@ -116,7 +116,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary sha = os.digest(); } - if (!codeStreamTools::upToDate(codeDir, sha)) +// Info<<"old SHA1: " << sha1_ << nl +// <<"new SHA1: " << sha << endl; + + + // (void) codeStreamTools::upToDate(codePath, sha) + // TODO: compile on-demand + if (true) { Info<< "Creating new library in " << libPath << endl; @@ -152,8 +158,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary filesContents[0].first() = "Make/files"; filesContents[0].second() = codeTemplateC + "\n\n" - "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" - + redirectType_; + + codeStreamTools::libTarget(redirectType_); // Write Make/options filesContents[1].first() = "Make/options"; @@ -164,7 +169,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary + "\n\nLIB_LIBS = "; codeStreamTools writer(redirectType_, copyFiles, filesContents); - if (!writer.copyFilesContents(codeDir)) + if (!writer.copyFilesContents(codePath)) { FatalIOErrorIn ( @@ -194,32 +199,20 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() << exit(FatalIOError); } - // local directory for compile/link - const fileName baseDir - ( - stringOps::expandEnv("$FOAM_CASE/codeStream") - ); + // write code into redirectType_ subdir + const fileName codePath = codeStreamTools::codePath(redirectType_); - // code is written into redirectType_ subdir - const fileName codeDir - ( - baseDir - / redirectType_ - ); +// const fileName oldLibPath = codeStreamTools::libPath +// ( +// redirectType_ + "_" + sha1_ +// ); + + // write library into platforms/$WM_OPTIONS/lib subdir + const fileName libPath = codeStreamTools::libPath(redirectType_); - //Info<< "codeDir:" << codeDir << endl; - - // library is written into platforms/$WM_OPTIONS/lib subdir - const fileName libPath - ( - baseDir - / stringOps::expandEnv("platforms/$WM_OPTIONS/lib") - / "lib" + redirectType_ + ".so" - ); - - - //Info<< "libPath:" << libPath << endl; + //Info<< "codePath:" << codePath << nl + // << "libPath:" << libPath << endl; void* lib = dlLibraryTable::findLibrary(libPath); @@ -227,7 +220,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (!lib) { - writeLibrary(codeDir, libPath, dict_); + writeLibrary(codePath, libPath, dict_); } } else @@ -256,7 +249,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() } const dictionary& codeDict = onTheFlyDict.subDict(redirectType_); - writeLibrary(codeDir, libPath, codeDict); + writeLibrary(codePath, libPath, codeDict); } } @@ -264,7 +257,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (Pstream::master()) { - const Foam::string wmakeCmd("wmake libso " + codeDir); + const Foam::string wmakeCmd("wmake libso " + codePath); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H index 25b259b84c..d08059be3a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H @@ -58,7 +58,7 @@ Description A special form is if the 'code' section is not supplied. In this case the code gets read from a (runTimeModifiable!) dictionary system/codeDict - which would have an entry + which would have a corresponding entry \verbatim rampedFixedValue @@ -82,6 +82,7 @@ SourceFiles #define codedFixedValueFvPatchScalarField_H #include "fixedValueFvPatchFields.H" +#include "SHA1Digest.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -100,8 +101,13 @@ class codedFixedValueFvPatchScalarField { // Private data + //- Dictionary contents for the boundary condition mutable dictionary dict_; + //- SHA1Digest of the Dictionary contents + // Currently unused, but useful for reloading? + mutable SHA1Digest sha1_; + const word redirectType_; mutable autoPtr redirectPatchFieldPtr_; From f8cae3f43c939979732ff4e467ee97b8cdb7bf98 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 19:11:51 +0100 Subject: [PATCH 19/28] ENH: add cleanCodeStream to tools/CleanFunctions --- bin/tools/CleanFunctions | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/bin/tools/CleanFunctions b/bin/tools/CleanFunctions index 1118564704..458fdc026e 100644 --- a/bin/tools/CleanFunctions +++ b/bin/tools/CleanFunctions @@ -30,15 +30,14 @@ #cleanTimeDirectories() #{ -# echo "Cleaning $case case of $application application" -# TIME_DIRS=`foamInfoExec . $1 -times | sed '1,/constant/d'` -# for T in $TIME_DIRS +# echo "Cleaning $PWD case" +# for time in $(foamInfoExec -times) # do -# if [ $T != "0" ] -# then -# echo "Deleting directory $T" -# rm -rf ${T} > /dev/null 2>&1 -# fi +# # keep 0 and constant directories +# [ "$time" = "0" -o "$time" = constant ] || { +# echo "Deleting directory $time" +# rm -rf $time > /dev/null 2>&1 +# } # done # rm -rf {log,log.*,log-*,logSummary.*,.fxLock,*.xml,ParaView*,paraFoam*,*.OpenFOAM} > /dev/null 2>&1 #} @@ -56,15 +55,32 @@ cleanTimeDirectories() rm -rf ./[1-9]* ./-[1-9]* ./log ./log.* ./log-* ./logSummary.* ./.fxLock ./*.xml ./ParaView* ./paraFoam* ./*.OpenFOAM > /dev/null 2>&1 } + +# +# Remove codeStream subdirectory if it looks appropriate +# +cleanCodeStream() +{ + if [ -d system -a -d codeStream ] + then + rm -rf codeStream > /dev/null 2>&1 + fi +} + + cleanCase() { cleanTimeDirectories + cleanCodeStream + rm -rf processor* > /dev/null 2>&1 rm -rf probes* > /dev/null 2>&1 rm -rf forces* > /dev/null 2>&1 rm -rf sets > /dev/null 2>&1 rm -rf system/machines > /dev/null 2>&1 - if [ -d "constant/polyMesh" ]; then + + if [ -d constant/polyMesh ] + then (cd constant/polyMesh && \ rm -rf \ allOwner* cell* face* meshModifiers* \ @@ -94,7 +110,7 @@ cleanCase() removeCase() { - echo "Removing $case case" + echo "Removing ${1:-unknown} case" rm -rf $1 } From b7429ef5c42064a8eb5abf22527d773ce66ce63b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 19:40:37 +0100 Subject: [PATCH 20/28] STYLE: relocate codeStreamTools into dynamicLibrary subdir --- src/OpenFOAM/Make/files | 6 ++++-- .../codeStream/codeStreamTools.C | 0 .../codeStream/codeStreamTools.H | 0 .../db/{ => dynamicLibrary}/dlLibraryTable/dlLibraryTable.C | 0 .../db/{ => dynamicLibrary}/dlLibraryTable/dlLibraryTable.H | 0 .../dlLibraryTable/dlLibraryTableTemplates.C | 2 +- 6 files changed, 5 insertions(+), 3 deletions(-) rename src/OpenFOAM/db/{dictionary/functionEntries => dynamicLibrary}/codeStream/codeStreamTools.C (100%) rename src/OpenFOAM/db/{dictionary/functionEntries => dynamicLibrary}/codeStream/codeStreamTools.H (100%) rename src/OpenFOAM/db/{ => dynamicLibrary}/dlLibraryTable/dlLibraryTable.C (100%) rename src/OpenFOAM/db/{ => dynamicLibrary}/dlLibraryTable/dlLibraryTable.H (100%) rename src/OpenFOAM/db/{ => dynamicLibrary}/dlLibraryTable/dlLibraryTableTemplates.C (97%) diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index a2c32b809b..1d7f39dd1a 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -161,7 +161,6 @@ $(dictionaryEntry)/dictionaryEntryIO.C functionEntries = $(dictionary)/functionEntries $(functionEntries)/codeStream/codeStream.C -$(functionEntries)/codeStream/codeStreamTools.C $(functionEntries)/functionEntry/functionEntry.C $(functionEntries)/includeEntry/includeEntry.C $(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C @@ -199,7 +198,10 @@ $(regIOobject)/regIOobjectWrite.C db/IOobjectList/IOobjectList.C db/objectRegistry/objectRegistry.C db/CallbackRegistry/CallbackRegistryName.C -db/dlLibraryTable/dlLibraryTable.C + +dll = db/dynamicLibrary +$(dll)/codeStream/codeStreamTools.C +$(dll)/dlLibraryTable/dlLibraryTable.C db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObjectList/functionObjectList.C diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C similarity index 100% rename from src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C rename to src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H similarity index 100% rename from src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H rename to src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C similarity index 100% rename from src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C rename to src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H similarity index 100% rename from src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H rename to src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTableTemplates.C b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTableTemplates.C similarity index 97% rename from src/OpenFOAM/db/dlLibraryTable/dlLibraryTableTemplates.C rename to src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTableTemplates.C index e98cb1932c..13a9ae919f 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTableTemplates.C +++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTableTemplates.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 From 71d21f6de4f7a701dfb1361997899e922c9959a1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 10:13:10 +0100 Subject: [PATCH 21/28] ENH: implement stringOps - trim, trimRight, inplaceTrim, inplaceTrimRight --- applications/test/string/Test-string.C | 13 +++++- .../primitives/strings/stringOps/stringOps.C | 42 +++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index 5a182377df..d117f50c41 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.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 @@ -26,6 +26,7 @@ Description \*---------------------------------------------------------------------------*/ #include "string.H" +#include "stringOps.H" #include "IOstreams.H" using namespace Foam; @@ -35,11 +36,19 @@ using namespace Foam; int main(int argc, char *argv[]) { - string test("$HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$"); + string test + ( + " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ " + ); Info<< "string:" << test << nl << "hash:" << unsigned(string::hash()(test)) << endl; + Info<<"trimLeft: " << stringOps::trimLeft(test) << endl; + Info<<"trimRight: " << stringOps::trimRight(test) << endl; + Info<<"trim: " << stringOps::trim(test) << endl; + + // test sub-strings via iterators string::const_iterator iter = test.end(); string::const_iterator iter2 = test.end(); diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index e3a4d4c8db..49142b10ec 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -36,8 +36,8 @@ Foam::string Foam::stringOps::expand const char sigil ) { - string str(original); - return inplaceExpand(str, mapping); + string s(original); + return inplaceExpand(s, mapping); } @@ -137,8 +137,8 @@ Foam::string Foam::stringOps::expandEnv const bool allowEmptyVar ) { - string str(original); - return inplaceExpandEnv(str, recurse, allowEmptyVar); + string s(original); + return inplaceExpandEnv(s, recurse, allowEmptyVar); } @@ -331,28 +331,52 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s) Foam::string Foam::stringOps::trimRight(const string& s) { - notImplemented("string stringOps::trimRight(const string&)"); + if (!s.empty()) + { + string::size_type sz = s.size(); + while (sz && isspace(s[sz-1])) + { + --sz; + } + + if (sz < s.size()) + { + return s.substr(0, sz); + } + } + return s; } Foam::string& Foam::stringOps::inplaceTrimRight(string& s) { - notImplemented("string& stringOps::inplaceTrimRight(string&)"); + if (!s.empty()) + { + string::size_type sz = s.size(); + while (sz && isspace(s[sz-1])) + { + --sz; + } + + s.resize(sz); + } + return s; } Foam::string Foam::stringOps::trim(const string& original) { - notImplemented("string stringOps::trim(const string&)"); - return original; + return trimLeft(trimRight(original)); } Foam::string& Foam::stringOps::inplaceTrim(string& s) { - notImplemented("string& stringOps::inplaceTrim(string&)"); + inplaceTrimRight(s); + inplaceTrimLeft(s); + return s; } From f4a84af4650697d23d3cbe5b8b8f0341071aecb0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Feb 2011 10:23:50 +0100 Subject: [PATCH 22/28] STYLE: trim both ends of codeStream entries - improves consistency of SHA1 calculation --- .../db/dictionary/functionEntries/codeStream/codeStream.C | 6 +++--- .../codedFixedValue/codedFixedValueFvPatchScalarField.C | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index af3904759d..1accc97517 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -93,18 +93,18 @@ bool Foam::functionEntries::codeStream::execute string codeInclude; if (codeDict.found("codeInclude")) { - codeInclude = stringOps::trimLeft(codeDict["codeInclude"]); + codeInclude = stringOps::trim(codeDict["codeInclude"]); } // "codeOptions" is optional string codeOptions; if (codeDict.found("codeOptions")) { - codeOptions = stringOps::trimLeft(codeDict["codeOptions"]); + codeOptions = stringOps::trim(codeDict["codeOptions"]); } // "code" is mandatory - string code = stringOps::trimLeft(codeDict["code"]); + string code = stringOps::trim(codeDict["code"]); // Create SHA1 digest from the contents SHA1Digest sha; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 9ab2ba1368..b87a560ac0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -95,18 +95,18 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary string codeInclude; if (dict.found("codeInclude")) { - codeInclude = stringOps::trimLeft(dict["codeInclude"]); + codeInclude = stringOps::trim(dict["codeInclude"]); } // "codeOptions" is optional string codeOptions; if (dict.found("codeOptions")) { - codeOptions = stringOps::trimLeft(dict["codeOptions"]); + codeOptions = stringOps::trim(dict["codeOptions"]); } // "code" is mandatory - string code = stringOps::trimLeft(dict["code"]); + string code = stringOps::trim(dict["code"]); // Create SHA1 digest from the contents SHA1Digest sha; From c56423540290c16d20a2a70ed861f29df5444ecb Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 23 Feb 2011 10:14:43 +0000 Subject: [PATCH 23/28] STYLE: processorCyclic, lduPrimitiveMesh: extraneous code, comment --- .../meshes/lduMesh/lduPrimitiveMesh.H | 4 +- .../processorCyclicPointPatch.C | 345 +----------------- .../processorCyclicPointPatch.H | 39 +- .../processorCyclicPolyPatch.H | 45 +-- .../processorCyclicFvPatchField.H | 175 +-------- 5 files changed, 6 insertions(+), 602 deletions(-) diff --git a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.H b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.H index b5f16857ac..c84796da41 100644 --- a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.H +++ b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.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 @@ -25,7 +25,7 @@ Class Foam::lduPrimitiveMesh Description - Simplest contrete lduMesh which stores the addressing needed bu lduMatrix. + Simplest contrete lduMesh which stores the addressing needed by lduMatrix. \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processorCyclic/processorCyclicPointPatch.C b/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processorCyclic/processorCyclicPointPatch.C index f16ce4085e..edf4fb4da8 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processorCyclic/processorCyclicPointPatch.C +++ b/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processorCyclic/processorCyclicPointPatch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,11 +26,6 @@ License #include "processorCyclicPointPatch.H" #include "pointBoundaryMesh.H" #include "addToRunTimeSelectionTable.H" -//#include "pointMesh.H" -//#include "globalPointPatch.H" -//#include "faceList.H" -//#include "primitiveFacePatch.H" -//#include "emptyPolyPatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,344 +44,6 @@ addToRunTimeSelectionTable ); -// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // - -//void Foam::processorCyclicPointPatch::initGeometry(PstreamBuffers& pBufs) -//{ -// // Algorithm: -// // Depending on whether the patch is a master or a slave, get the -// // primitive patch points and filter away the points from the -// // global patch. -// -// if (isMaster()) -// { -// meshPoints_ = procPolyPatch_.meshPoints(); -// } -// else -// { -// // Slave side. Create the reversed patch and pick up its points -// // so that the order is correct -// const polyPatch& pp = patch(); -// -// faceList masterFaces(pp.size()); -// -// forAll(pp, faceI) -// { -// masterFaces[faceI] = pp[faceI].reverseFace(); -// } -// -// meshPoints_ = primitiveFacePatch -// ( -// masterFaces, -// pp.points() -// ).meshPoints(); -// } -// -// if (Pstream::parRun()) -// { -// initPatchPatchPoints(pBufs); -// } -//} -// -// -//void Foam::processorCyclicPointPatch::calcGeometry(PstreamBuffers& pBufs) -//{ -// if (Pstream::parRun()) -// { -// calcPatchPatchPoints(pBufs); -// } -// -// // If it is not runing parallel or there are no global points -// // create a 1->1 map -// if -// ( -// !Pstream::parRun() -// || !boundaryMesh().mesh().globalData().nGlobalPoints() -// ) -// { -// nonGlobalPatchPoints_.setSize(meshPoints_.size()); -// forAll(nonGlobalPatchPoints_, i) -// { -// nonGlobalPatchPoints_[i] = i; -// } -// } -// else -// { -// // Get reference to shared points -// const labelList& sharedPoints = -// boundaryMesh().globalPatch().meshPoints(); -// -// nonGlobalPatchPoints_.setSize(meshPoints_.size()); -// -// label noFiltPoints = 0; -// -// forAll(meshPoints_, pointI) -// { -// label curP = meshPoints_[pointI]; -// -// bool found = false; -// -// forAll(sharedPoints, sharedI) -// { -// if (sharedPoints[sharedI] == curP) -// { -// found = true; -// break; -// } -// } -// -// if (!found) -// { -// nonGlobalPatchPoints_[noFiltPoints] = pointI; -// meshPoints_[noFiltPoints] = curP; -// noFiltPoints++; -// } -// } -// -// nonGlobalPatchPoints_.setSize(noFiltPoints); -// meshPoints_.setSize(noFiltPoints); -// } -//} -// -// -//void processorCyclicPointPatch::initPatchPatchPoints(PstreamBuffers& pBufs) -//{ -// if (debug) -// { -// Info<< "processorCyclicPointPatch::" -// << "initPatchPatchPoints(PstreamBuffers&) : " -// << "constructing patch-patch points" -// << endl; -// } -// -// const polyBoundaryMesh& bm = boundaryMesh().mesh()().boundaryMesh(); -// -// // Get the mesh points for this patch corresponding to the faces -// const labelList& ppmp = meshPoints(); -// -// // Create a HashSet of the point labels for this patch -// Map