diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index 248ac3e3d09e3285cbef54c01f21b25a266155fc..3d14464e71344c0566b79186c0e910544ab6dd24 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -206,8 +206,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -215,15 +215,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C index 3995031b536018caeb6e3a1e6c4e9e73eb281c32..0631f195e2ee0e147c701deacd53cc9508a4102f 100644 --- a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C +++ b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C @@ -195,8 +195,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -204,15 +204,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -220,7 +220,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C index 853becfc89dbd75c79ba7c2bf9cd0092dbbe1e89..3aee72a52d7bd38d6fb52a0a3507025555298df1 100644 --- a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C +++ b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C @@ -208,8 +208,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -217,15 +217,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -233,7 +233,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/bin/tools/pre-commit-hook b/bin/tools/pre-commit-hook index be4bb69b24294824b7f8a2314ec4462b5bc8766a..7d41b2e11c8284267345939f7ab9f5974fd87fb1 100755 --- a/bin/tools/pre-commit-hook +++ b/bin/tools/pre-commit-hook @@ -200,6 +200,34 @@ checkLineLengthNonComments() dieOnBadFiles "Limit code to 80 columns before pushing" } +# +# limit line length to 80-columns, except #directive lines +# +checkLineLengthNonDirective() +{ + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # parse line numbers from this (strip comment lines): + # path/fileName:<lineNr>: contents + lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" | + sed -n \ + -e '\@^[^:]*:[^:]*: *#.*@b' \ + -e 's@^[^:]*:\([0-9]*\):.*@\1@p' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + ;; + esac + done + ) + + dieOnBadFiles "Limit code to 80 columns before pushing" +} + # do all checks @@ -215,7 +243,7 @@ checkIllegalCode checkCopyright # ensure code conforms to 80 columns max -checkLineLength +checkLineLengthNonDirective exit 0 diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index babb31b6e85c8900ac78b1f95b6c534a7818afea..7df85dc6d55f4c798ed9f86d6ba9eb1a899687c1 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -26,6 +26,7 @@ License #include "ZoneMesh.H" #include "entry.H" #include "demandDrivenData.H" +#include "stringListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -241,6 +242,66 @@ Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::names() const } +template<class ZoneType, class MeshType> +Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices +( + const keyType& key +) const +{ + labelList indices; + if (key.isPattern()) + { + indices = findStrings(key, this->names()); + } + else + { + indices.setSize(this->size()); + label nFound = 0; + forAll(*this, i) + { + if (key == operator[](i).name()) + { + indices[nFound++] = i; + } + } + indices.setSize(nFound); + } + + return indices; +} + + +template<class ZoneType, class MeshType> +Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex +( + const keyType& key +) const +{ + if (key.isPattern()) + { + labelList indices = this->findIndices(key); + // return first element + if (!indices.empty()) + { + return indices[0]; + } + } + else + { + forAll(*this, i) + { + if (key == operator[](i).name()) + { + return i; + } + } + } + + // not found + return -1; +} + + template<class ZoneType, class MeshType> Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID ( @@ -265,7 +326,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID << "List of available zone names: " << names() << endl; } - // A dummy return to keep the compiler happy + // not found return -1; } diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 03b9c216becd4de67a54c8aabdb11a83be1f9db9..8854d9533b0e4aed4cb67357fc01d3010c98e191 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -121,8 +121,8 @@ public: // Return -1 if the object is not in the zone const Map<label>& zoneMap() const; - //- Given a global object index, return the zone it is in. If - //object does not belong to any zones, return -1 + //- Given a global object index, return the zone it is in. + // If object does not belong to any zones, return -1 label whichZone(const label objectIndex) const; //- Return a list of zone types @@ -134,6 +134,12 @@ public: //- Find zone index given a name label findZoneID(const word& zoneName) const; + //- Return zone indices for all matches + labelList findIndices(const keyType&) const; + + //- Return zone index for the first match, return -1 if not found + label findIndex(const keyType&) const; + //- Clear addressing void clearAddressing(); diff --git a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C index b7aef808507a2b3ca8794b4955551f6e5b06ab2a..4e1020a4f10d6c464662c5b1267d0db62d07e460 100644 --- a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C +++ b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C @@ -71,7 +71,7 @@ Foam::porousZone::porousZone key_(key), mesh_(mesh), dict_(dict), - cellZoneIds_(0), + cellZoneIds_(mesh_.cellZones().findIndices(key_)), coordSys_(dict, mesh), porosity_(1), intensity_(0), @@ -83,24 +83,6 @@ Foam::porousZone::porousZone { Info<< "Creating porous zone: " << key_ << endl; - if (key_.isPattern()) - { - cellZoneIds_ = findStrings - ( - key_, - mesh_.cellZones().names() - ); - } - else - { - const label zoneId = mesh_.cellZones().findZoneID(key_); - if (zoneId != -1) - { - cellZoneIds_.setSize(1); - cellZoneIds_[0] = zoneId; - } - } - bool foundZone = !cellZoneIds_.empty(); reduce(foundZone, orOp<bool>()); diff --git a/src/meshTools/coordinateSystems/coordinateSystem.C b/src/meshTools/coordinateSystems/coordinateSystem.C index 0a5fe400f7e7270d4d2a8cfb00174a142f06b4c2..1fbe52dfe9ff500b758cfdfb52464b8f64d2b0d1 100644 --- a/src/meshTools/coordinateSystems/coordinateSystem.C +++ b/src/meshTools/coordinateSystems/coordinateSystem.C @@ -142,17 +142,17 @@ Foam::coordinateSystem::coordinateSystem keyType key(entryPtr->stream()); const coordinateSystems& lst = coordinateSystems::New(obr); - const label id = lst.find(key); + const label index = lst.findIndex(key); if (debug) { Info<< "coordinateSystem::coordinateSystem" "(const dictionary&, const objectRegistry&):" << nl << "using global coordinate system: " - << key << "=" << id << endl; + << key << "=" << index << endl; } - if (id < 0) + if (index < 0) { FatalErrorIn ( @@ -165,7 +165,7 @@ Foam::coordinateSystem::coordinateSystem // copy coordinateSystem, but assign the name as the typeName // to avoid strange things in writeDict() - operator=(lst[id]); + operator=(lst[index]); name_ = typeName_(); } else diff --git a/src/meshTools/coordinateSystems/coordinateSystems.C b/src/meshTools/coordinateSystems/coordinateSystems.C index 4d829004081944a70489299514b6517118260a20..82b52fc72322f390c8f379556fb9700ae2e8459a 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.C +++ b/src/meshTools/coordinateSystems/coordinateSystems.C @@ -100,58 +100,64 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New Foam::label Foam::coordinateSystems::find(const keyType& key) const { + return findIndex(key); +} + + +Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const +{ + labelList indices; if (key.isPattern()) { - labelList allFound = findAll(key); - // return first element - if (!allFound.empty()) - { - return allFound[0]; - } + indices = findStrings(key, toc()); } else { + indices.setSize(size()); + label nFound = 0; forAll(*this, i) { if (key == operator[](i).name()) { - return i; + indices[nFound++] = i; } } + indices.setSize(nFound); } - return -1; + return indices; } -Foam::labelList Foam::coordinateSystems::findAll(const keyType& key) const +Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const { - labelList allFound; if (key.isPattern()) { - allFound = findStrings(key, toc()); + labelList indices = findIndices(key); + // return first element + if (!indices.empty()) + { + return indices[0]; + } } else { - allFound.setSize(size()); - label nFound = 0; forAll(*this, i) { if (key == operator[](i).name()) { - allFound[nFound++] = i; + return i; } } - allFound.setSize(nFound); } - return allFound; + return -1; } bool Foam::coordinateSystems::found(const keyType& key) const { - return find(key) >= 0; + return findIndex(key) != -1; } diff --git a/src/meshTools/coordinateSystems/coordinateSystems.H b/src/meshTools/coordinateSystems/coordinateSystems.H index 2976a6f94efa48a726a39946bf87cb88843b12f0..46ca3a4e73e410164a81cc47e91219ef8838a2aa 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.H +++ b/src/meshTools/coordinateSystems/coordinateSystems.H @@ -97,12 +97,16 @@ public: // Member Functions + //- Find and return indices for all matches + labelList findIndices(const keyType& key) const; + + //- Find and return index for the first match, return -1 if not found + label findIndex(const keyType& key) const; + //- Find and return index for the first match, returns -1 if not found + // @deprecated use findIndex() instead (deprecated Jul 2010) label find(const keyType& key) const; - //- Find and return indices for all matches - labelList findAll(const keyType& key) const; - //- Search for given key bool found(const keyType& key) const; diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C index 906bcf340ec8335056f66a784f52821a2815300e..80db186628f49475c4c729cd20f3fddb8da0189d 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -91,7 +91,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase forAll(zoneLst, zoneI) { - os << "ctable " << zoneI + 1 << " shell" << nl + os << "ctable " << zoneI + 1 << " shell" << " ,,,,,," << nl << "ctname " << zoneI + 1 << " " << zoneLst[zoneI].name() << nl; }