Merge branch 'HashTable-method-enhancements' into 'develop'

Hash table method enhancements

See merge request !112
This commit is contained in:
Mark Olesen
2017-05-18 12:54:36 +01:00
71 changed files with 2627 additions and 1385 deletions

View File

@ -234,6 +234,97 @@ int main()
Info<<"\ntable1: " << table1 << endl;
// Start again
HashTable<scalar> table1start
{
{"aaa", 1.0},
{"aba", 2.0},
{"a_ca", 3.0},
{"ada", 4.0},
{"aeq_", 5.0},
{"aaw", 6.0},
{"abs", 7.0},
{"a_cr", 8.0},
{"adx", 9.0},
{"ae_c", 10.0}
};
table1 = table1start;
Info<< "\ntable has keys: "
<< flatOutput(table1.sortedToc()) << nl;
wordRe matcher(".*_.*", wordRe::REGEX);
table1.filterKeys
(
[&matcher](const word& k){ return matcher.match(k); }
);
Info<< "retain things matching " << matcher << " => "
<< flatOutput(table1.sortedToc()) << nl;
table1 = table1start;
table1.filterKeys
(
[&matcher](const word& k){ return matcher.match(k); },
true
);
Info<< "prune things matching " << matcher << " => "
<< flatOutput(table1.sortedToc()) << nl;
// Same, without a lambda
table1 = table1start;
table1.filterKeys(matcher, true);
Info<< "prune things matching " << matcher << " => "
<< flatOutput(table1.sortedToc()) << nl;
// Same idea, but inverted logic inside the lambda
table1 = table1start;
table1.filterKeys
(
[&matcher](const word& k){ return !matcher.match(k); },
true
);
Info<< "prune things matching " << matcher << " => "
<< flatOutput(table1.sortedToc()) << nl;
table1 = table1start;
Info<< "\ntable:" << table1 << nl;
table1.filterValues
(
[](const scalar& v){ return (v >= 5); }
);
Info<< "\ntable with values >= 5:" << table1 << nl;
table1 = table1start;
Info<< "\ntable:" << table1 << nl;
table1.filterEntries
(
[&matcher](const word& k, const scalar& v)
{
return matcher(k) && (v >= 5);
}
);
Info<< "\ntable with values >= 5 and matching " << matcher
<< table1 << nl;
table1 = table1start;
Info<< "\ntable:" << table1 << nl;
Info<< "has "
<< table1.countValues([](const scalar& v) { return v >= 7; })
<< " values >= 7 with these keys: "
<< table1.tocValues([](const scalar& v) { return v >= 7; })
<< nl;
Info<< "\nDone\n";
return 0;

View File

@ -0,0 +1,3 @@
Test-IOobjectList.C
EXE = $(FOAM_USER_APPBIN)/Test-IOobjectList

View File

@ -0,0 +1,3 @@
EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = -lfiniteVolume

View File

@ -0,0 +1,104 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
Description
Basic tests of IOobjectList
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "volFields.H"
#include "timeSelector.H"
#include "IOobjectList.H"
#include "hashedWordList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addOption("re", "wordReList");
// timeSelector::addOptions();
timeSelector::addOptions(true, true);
#include "setRootCase.H"
#include "createTime.H"
wordReList matcher;
if (args.optionFound("re"))
{
matcher = args.optionReadList<wordRe>("re");
Info<<"limit names: " << matcher << nl;
}
const hashedWordList subsetTypes
{
volScalarField::typeName,
volScalarField::Internal::typeName,
volVectorField::typeName,
};
instantList timeDirs = timeSelector::select0(runTime, args);
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
// Objects at this time
IOobjectList objects(runTime, runTime.timeName());
HashTable<wordHashSet> classes =
(
matcher.size()
? objects.classes(matcher)
: objects.classes()
);
Info<< "Time: " << runTime.timeName() << nl;
Info<<"Name: " << flatOutput(objects.sortedNames()) << nl
<<"Objects: " << objects << nl
<<"Classes: " << classes << nl;
classes.filterKeys(subsetTypes);
Info<<"only retain: " << flatOutput(subsetTypes) << nl;
Info<<"Pruned: " << classes << nl;
classes = objects.classes();
classes.erase(subsetTypes);
Info<<"remove: " << flatOutput(subsetTypes) << nl;
Info<<"Pruned: " << classes << nl;
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -180,9 +180,9 @@ int main(int argc, char *argv[])
// A regex with a zero length matcher doesn't work at all:
// eg "(png|jpg|txt|)" regex matcher itself
wordRe matcher0("()", wordRe::REGEXP);
wordRe matcher1("(png|jpg|txt)", wordRe::REGEXP);
wordRe matcher2("(png|txt)", wordRe::REGEXP);
wordRe matcher0("()", wordRe::REGEX);
wordRe matcher1("(png|jpg|txt)", wordRe::REGEX);
wordRe matcher2("(png|txt)", wordRe::REGEX);
Info<<"Has extension(s):" << nl
<< "input: " << endWithDot << nl;

View File

@ -0,0 +1,3 @@
Test-predicates.C
EXE = $(FOAM_USER_APPBIN)/Test-predicates

View File

@ -0,0 +1 @@
/**/

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
Application
Test-predicates
Description
Simple tests using predicates
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
#include "labelList.H"
#include "wordList.H"
#include "predicates.H"
#include "FlatOutput.H"
#include "regExp.H"
using namespace Foam;
template<class ListType, class UnaryPredicate>
label printMatching(const ListType& list, const UnaryPredicate& pred)
{
label count = 0;
Info<< "(";
for (const auto& val : list)
{
if (pred(val))
{
if (count) Info<< ' ';
Info<< val;
++count;
}
}
Info<< ") => " << count << nl;
return count;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
wordList words
{
"abc",
"def",
"hij",
"abc_",
"def_",
"hij_",
};
labelRange range(-10, 40);
labelList values(range.begin(), range.end());
Info<<"words: " << flatOutput(words) << endl;
Info<<"values: " << flatOutput(values) << endl;
regExp matcher(".*_.*");
Info<<"With '_': ";
printMatching(words, matcher);
Info<<"All: ";
printMatching(words, predicates::always());
Info<<"None: ";
printMatching(words, predicates::never());
Info<<"Neg values: ";
printMatching(values, [](const label v) { return v < 0; });
Info<<"Even values: ";
printMatching(values, [](const label v) { return !(v % 2); });
Info<<"All: ";
printMatching(values, predicates::always());
Info<<"None: ";
printMatching(values, predicates::never());
return 0;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,7 +30,10 @@ Description
#include "IFstream.H"
#include "List.H"
#include "Tuple2.H"
#include "keyType.H"
#include "wordRe.H"
#include "wordRes.H"
#include "predicates.H"
using namespace Foam;
@ -44,12 +47,37 @@ int main(int argc, char *argv[])
Foam::string s2("this .* file");
const char * s3 = "this .* file";
keyType keyre("x.*", true);
wordReList wordrelist
{
{"this", wordRe::LITERAL},
{"x.*", wordRe::REGEX},
{"file[a-b]", wordRe::REGEX},
};
wordRes wrelist(wordrelist);
Info<< "re-list:" << wrelist() << endl;
Info<< "match this: " << wrelist("this") << endl;
Info<< "match xyz: " << wrelist("xyz") << endl;
Info<< "match zyx: " << wrelist("zyx") << endl;
Info<< "match xyz: " << wrelist.match("xyz") << endl;
Info<< "match any: " << predicates::always()("any junk") << endl;
Info<< "keyre match: " << keyre("xyz") << endl;
Info<< "string match: " << string("this").match("xyz") << endl;
Info<< "string match: " << string("x.*")("xyz") << endl;
Info<< "string match: " << string("x.*")(keyre) << endl;
wordRe(s1, wordRe::DETECT).info(Info) << endl;
wordRe(s2).info(Info) << endl;
wordRe(s2, wordRe::DETECT).info(Info) << endl;
wordRe(s3, wordRe::REGEXP).info(Info) << endl;
wordRe(s3, wordRe::REGEX).info(Info) << endl;
wre = "this .* file";
Info<<"substring: " << wre(4) << endl;
wre.info(Info) << endl;
wre = s1;
wre.info(Info) << endl;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -112,7 +112,7 @@ labelList nearestPatch(const polyMesh& mesh, const labelList& patchIDs)
{
WarningInFunction
<< "Did not visit some faces, e.g. face " << faceI
<< " at " << mesh.faceCentres()[faceI] << endl
<< " at " << mesh.faceCentres()[faceI] << nl
<< "Using patch " << patchIDs[0] << " as nearest"
<< endl;
haveWarned = true;
@ -129,57 +129,38 @@ labelList nearestPatch(const polyMesh& mesh, const labelList& patchIDs)
}
template<class Type>
void subsetVolFields
//
// Subset field-type, availability information cached
// in the availableFields hashtable.
//
template<class Type, template<class> class PatchField, class GeoMesh>
void subsetFields
(
const fvMeshSubset& subsetter,
const wordList& fieldNames,
PtrList<GeometricField<Type, fvPatchField, volMesh>>& subFields
HashTable<wordHashSet>& availableFields,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& subFields
)
{
typedef GeometricField<Type, PatchField, GeoMesh> FieldType;
const word fieldType = FieldType::typeName;
const wordList fieldNames = availableFields(fieldType).sortedToc();
subFields.setSize(fieldNames.size());
const fvMesh& baseMesh = subsetter.baseMesh();
if (fieldNames.empty())
{
return;
}
Info<< "Subsetting " << fieldType << " (";
forAll(fieldNames, i)
{
const word& fieldName = fieldNames[i];
if (i) Info<< ' ';
Info<< fieldName;
Info<< "Subsetting field " << fieldName << endl;
GeometricField<Type, fvPatchField, volMesh> fld
(
IOobject
(
fieldName,
baseMesh.time().timeName(),
baseMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
baseMesh
);
subFields.set(i, subsetter.interpolate(fld));
}
}
template<class Type>
void subsetSurfaceFields
(
const fvMeshSubset& subsetter,
const wordList& fieldNames,
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& subFields
)
{
const fvMesh& baseMesh = subsetter.baseMesh();
forAll(fieldNames, i)
{
const word& fieldName = fieldNames[i];
Info<< "Subsetting field " << fieldName << endl;
GeometricField<Type, fvsPatchField, surfaceMesh> fld
FieldType fld
(
IOobject
(
@ -193,7 +174,11 @@ void subsetSurfaceFields
);
subFields.set(i, subsetter.interpolate(fld));
// Subsetting adds 'subset' prefix - rename to match original.
subFields[i].rename(fieldName);
}
Info<< ")" << nl;
}
@ -202,19 +187,30 @@ void subsetPointFields
(
const fvMeshSubset& subsetter,
const pointMesh& pMesh,
const wordList& fieldNames,
HashTable<wordHashSet>& availableFields,
PtrList<GeometricField<Type, pointPatchField, pointMesh>>& subFields
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> FieldType;
const word fieldType = FieldType::typeName;
const wordList fieldNames = availableFields(fieldType).sortedToc();
subFields.setSize(fieldNames.size());
const fvMesh& baseMesh = subsetter.baseMesh();
if (fieldNames.empty())
{
return;
}
Info<< "Subsetting " << fieldType << " (";
forAll(fieldNames, i)
{
const word& fieldName = fieldNames[i];
if (i) Info<< ' ';
Info<< fieldName;
Info<< "Subsetting field " << fieldName << endl;
GeometricField<Type, pointPatchField, pointMesh> fld
FieldType fld
(
IOobject
(
@ -228,7 +224,11 @@ void subsetPointFields
);
subFields.set(i, subsetter.interpolate(fld));
// Subsetting adds 'subset' prefix - rename to match original.
subFields[i].rename(fieldName);
}
Info<< ")" << nl;
}
@ -236,19 +236,30 @@ template<class Type>
void subsetDimensionedFields
(
const fvMeshSubset& subsetter,
const wordList& fieldNames,
HashTable<wordHashSet>& availableFields,
PtrList<DimensionedField<Type, volMesh>>& subFields
)
{
typedef DimensionedField<Type, volMesh> FieldType;
const word fieldType = FieldType::typeName;
const wordList fieldNames = availableFields(fieldType).sortedToc();
subFields.setSize(fieldNames.size());
const fvMesh& baseMesh = subsetter.baseMesh();
if (fieldNames.empty())
{
return;
}
Info<< "Subsetting " << fieldType << " (";
forAll(fieldNames, i)
{
const word& fieldName = fieldNames[i];
if (i) Info<< ' ';
Info<< fieldName;
Info<< "Subsetting field " << fieldName << endl;
DimensionedField<Type, volMesh> fld
FieldType fld
(
IOobject
(
@ -262,7 +273,11 @@ void subsetDimensionedFields
);
subFields.set(i, subsetter.interpolate(fld));
// Subsetting adds 'subset' prefix - rename to match original.
subFields[i].rename(fieldName);
}
Info<< ")" << nl;
}
@ -289,7 +304,7 @@ void subsetTopoSets
// Map the data
PackedBoolList isSet(set.maxSize(mesh));
forAllConstIter(labelHashSet, set, iter)
forAllConstIters(set, iter)
{
isSet[iter.key()] = true;
}
@ -359,7 +374,6 @@ int main(int argc, char *argv[])
#include "createNamedMesh.H"
const word setName = args[1];
word meshInstance = mesh.pointsInstance();
@ -378,7 +392,7 @@ int main(int argc, char *argv[])
}
Info<< "Reading cell set from " << setName << endl << endl;
Info<< "Reading cell set from " << setName << nl << endl;
// Create mesh subsetting engine
fvMeshSubset subsetter(mesh);
@ -389,11 +403,7 @@ int main(int argc, char *argv[])
{
const word patchName = args["patch"];
exposedPatchIDs = labelList
(
1,
mesh.boundaryMesh().findPatchID(patchName)
);
exposedPatchIDs = { mesh.boundaryMesh().findPatchID(patchName) };
if (exposedPatchIDs[0] == -1)
{
@ -402,8 +412,8 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
Info<< "Adding exposed internal faces to patch " << patchName << endl
<< endl;
Info<< "Adding exposed internal faces to patch " << patchName
<< nl << endl;
}
else if (args.optionFound("patches"))
{
@ -412,14 +422,14 @@ int main(int argc, char *argv[])
exposedPatchIDs = mesh.boundaryMesh().patchSet(patchNames).sortedToc();
Info<< "Adding exposed internal faces to nearest of patches "
<< patchNames << endl << endl;
<< patchNames << nl << endl;
}
else
{
Info<< "Adding exposed internal faces to a patch called"
<< " \"oldInternalFaces\" (created if necessary)" << endl
<< endl;
exposedPatchIDs = labelList(1, label(-1));
exposedPatchIDs = { -1 };
}
@ -431,7 +441,6 @@ int main(int argc, char *argv[])
}
else
{
// Find per face the nearest patch
labelList nearestExposedPatch(nearestPatch(mesh, exposedPatchIDs));
@ -454,77 +463,45 @@ int main(int argc, char *argv[])
IOobjectList objects(mesh, runTime.timeName());
HashTable<wordHashSet> availableFields = objects.classes();
// Read vol fields and subset
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
wordList scalarNames(objects.names(volScalarField::typeName));
PtrList<volScalarField> scalarFlds(scalarNames.size());
subsetVolFields(subsetter, scalarNames, scalarFlds);
PtrList<volScalarField> scalarFlds;
subsetFields(subsetter, availableFields, scalarFlds);
wordList vectorNames(objects.names(volVectorField::typeName));
PtrList<volVectorField> vectorFlds(vectorNames.size());
subsetVolFields(subsetter, vectorNames, vectorFlds);
PtrList<volVectorField> vectorFlds;
subsetFields(subsetter, availableFields, vectorFlds);
wordList sphericalTensorNames
(
objects.names(volSphericalTensorField::typeName)
);
PtrList<volSphericalTensorField> sphericalTensorFlds
(
sphericalTensorNames.size()
);
subsetVolFields(subsetter, sphericalTensorNames, sphericalTensorFlds);
PtrList<volSphericalTensorField> sphTensorFlds;
subsetFields(subsetter, availableFields, sphTensorFlds);
wordList symmTensorNames(objects.names(volSymmTensorField::typeName));
PtrList<volSymmTensorField> symmTensorFlds(symmTensorNames.size());
subsetVolFields(subsetter, symmTensorNames, symmTensorFlds);
PtrList<volSymmTensorField> symmTensorFlds;
subsetFields(subsetter, availableFields, symmTensorFlds);
wordList tensorNames(objects.names(volTensorField::typeName));
PtrList<volTensorField> tensorFlds(tensorNames.size());
subsetVolFields(subsetter, tensorNames, tensorFlds);
PtrList<volTensorField> tensorFlds;
subsetFields(subsetter, availableFields, tensorFlds);
// Read surface fields and subset
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wordList surfScalarNames(objects.names(surfaceScalarField::typeName));
PtrList<surfaceScalarField> surfScalarFlds(surfScalarNames.size());
subsetSurfaceFields(subsetter, surfScalarNames, surfScalarFlds);
PtrList<surfaceScalarField> surfScalarFlds;
subsetFields(subsetter, availableFields, surfScalarFlds);
wordList surfVectorNames(objects.names(surfaceVectorField::typeName));
PtrList<surfaceVectorField> surfVectorFlds(surfVectorNames.size());
subsetSurfaceFields(subsetter, surfVectorNames, surfVectorFlds);
PtrList<surfaceVectorField> surfVectorFlds;
subsetFields(subsetter, availableFields, surfVectorFlds);
wordList surfSphericalTensorNames
(
objects.names(surfaceSphericalTensorField::typeName)
);
PtrList<surfaceSphericalTensorField> surfSphericalTensorFlds
(
surfSphericalTensorNames.size()
);
subsetSurfaceFields
(
subsetter,
surfSphericalTensorNames,
surfSphericalTensorFlds
);
PtrList<surfaceSphericalTensorField> surfSphTensorFlds;
subsetFields(subsetter, availableFields, surfSphTensorFlds);
wordList surfSymmTensorNames
(
objects.names(surfaceSymmTensorField::typeName)
);
PtrList<surfaceSymmTensorField> surfSymmTensorFlds
(
surfSymmTensorNames.size()
);
subsetSurfaceFields(subsetter, surfSymmTensorNames, surfSymmTensorFlds);
PtrList<surfaceSymmTensorField> surfSymmTensorFlds;
subsetFields(subsetter, availableFields, surfSymmTensorFlds);
wordList surfTensorNames(objects.names(surfaceTensorField::typeName));
PtrList<surfaceTensorField> surfTensorFlds(surfTensorNames.size());
subsetSurfaceFields(subsetter, surfTensorNames, surfTensorFlds);
PtrList<surfaceTensorField> surfTensorFlds;
subsetFields(subsetter, availableFields, surfTensorFlds);
// Read point fields and subset
@ -532,86 +509,39 @@ int main(int argc, char *argv[])
const pointMesh& pMesh = pointMesh::New(mesh);
wordList pointScalarNames(objects.names(pointScalarField::typeName));
PtrList<pointScalarField> pointScalarFlds(pointScalarNames.size());
subsetPointFields(subsetter, pMesh, pointScalarNames, pointScalarFlds);
PtrList<pointScalarField> pointScalarFlds;
subsetPointFields(subsetter, pMesh, availableFields, pointScalarFlds);
wordList pointVectorNames(objects.names(pointVectorField::typeName));
PtrList<pointVectorField> pointVectorFlds(pointVectorNames.size());
subsetPointFields(subsetter, pMesh, pointVectorNames, pointVectorFlds);
PtrList<pointVectorField> pointVectorFlds;
subsetPointFields(subsetter, pMesh, availableFields, pointVectorFlds);
wordList pointSphericalTensorNames
(
objects.names(pointSphericalTensorField::typeName)
);
PtrList<pointSphericalTensorField> pointSphericalTensorFlds
(
pointSphericalTensorNames.size()
);
subsetPointFields
(
subsetter,
pMesh,
pointSphericalTensorNames,
pointSphericalTensorFlds
);
PtrList<pointSphericalTensorField> pointSphTensorFlds;
subsetPointFields(subsetter, pMesh, availableFields, pointSphTensorFlds);
wordList pointSymmTensorNames
(
objects.names(pointSymmTensorField::typeName)
);
PtrList<pointSymmTensorField> pointSymmTensorFlds
(
pointSymmTensorNames.size()
);
subsetPointFields
(
subsetter,
pMesh,
pointSymmTensorNames,
pointSymmTensorFlds
);
PtrList<pointSymmTensorField> pointSymmTensorFlds;
subsetPointFields(subsetter, pMesh, availableFields, pointSymmTensorFlds);
wordList pointTensorNames(objects.names(pointTensorField::typeName));
PtrList<pointTensorField> pointTensorFlds(pointTensorNames.size());
subsetPointFields(subsetter, pMesh, pointTensorNames, pointTensorFlds);
PtrList<pointTensorField> pointTensorFlds;
subsetPointFields(subsetter, pMesh, availableFields, pointTensorFlds);
// Read dimensioned fields and subset
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typedef volScalarField::Internal dimScalType;
wordList scalarDimNames(objects.names(dimScalType::typeName));
PtrList<dimScalType> scalarDimFlds(scalarDimNames.size());
subsetDimensionedFields(subsetter, scalarDimNames, scalarDimFlds);
PtrList<volScalarField::Internal> scalarDimFlds;
subsetDimensionedFields(subsetter, availableFields, scalarDimFlds);
typedef volVectorField::Internal dimVecType;
wordList vectorDimNames(objects.names(dimVecType::typeName));
PtrList<dimVecType> vectorDimFlds(vectorDimNames.size());
subsetDimensionedFields(subsetter, vectorDimNames, vectorDimFlds);
PtrList<volVectorField::Internal> vectorDimFlds;
subsetDimensionedFields(subsetter, availableFields, vectorDimFlds);
typedef volSphericalTensorField::Internal dimSphereType;
wordList sphericalTensorDimNames(objects.names(dimSphereType::typeName));
PtrList<dimSphereType> sphericalTensorDimFlds
(
sphericalTensorDimNames.size()
);
subsetDimensionedFields
(
subsetter,
sphericalTensorDimNames,
sphericalTensorDimFlds
);
PtrList<volSphericalTensorField::Internal> sphTensorDimFlds;
subsetDimensionedFields(subsetter, availableFields, sphTensorDimFlds);
typedef volSymmTensorField::Internal dimSymmTensorType;
wordList symmTensorDimNames(objects.names(dimSymmTensorType::typeName));
PtrList<dimSymmTensorType> symmTensorDimFlds(symmTensorDimNames.size());
subsetDimensionedFields(subsetter, symmTensorDimNames, symmTensorDimFlds);
PtrList<volSymmTensorField::Internal> symmTensorDimFlds;
subsetDimensionedFields(subsetter, availableFields, symmTensorDimFlds);
typedef volTensorField::Internal dimTensorType;
wordList tensorDimNames(objects.names(dimTensorType::typeName));
PtrList<dimTensorType> tensorDimFlds(tensorDimNames.size());
subsetDimensionedFields(subsetter, tensorDimNames, tensorDimFlds);
PtrList<volTensorField::Internal> tensorDimFlds;
subsetDimensionedFields(subsetter, availableFields, tensorDimFlds);
// topoSets and subset
@ -620,6 +550,7 @@ int main(int argc, char *argv[])
PtrList<cellSet> cellSets;
PtrList<faceSet> faceSets;
PtrList<pointSet> pointSets;
{
IOobjectList objects(mesh, mesh.facesInstance(), "polyMesh/sets");
objects.remove(currentSet);
@ -650,7 +581,6 @@ int main(int argc, char *argv[])
}
// Write mesh and fields to new time
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -668,123 +598,100 @@ int main(int argc, char *argv[])
subsetter.subMesh().setInstance(runTime.timeName());
}
Info<< "Writing subsetted mesh and fields to time " << runTime.timeName()
<< endl;
subsetter.subMesh().write();
processorMeshes::removeFiles(subsetter.subMesh());
// Subsetting adds 'subset' prefix. Rename field to be like original.
// Volume fields
forAll(scalarFlds, i)
{
scalarFlds[i].rename(scalarNames[i]);
scalarFlds[i].write();
}
forAll(vectorFlds, i)
{
vectorFlds[i].rename(vectorNames[i]);
vectorFlds[i].write();
}
forAll(sphericalTensorFlds, i)
forAll(sphTensorFlds, i)
{
sphericalTensorFlds[i].rename(sphericalTensorNames[i]);
sphericalTensorFlds[i].write();
sphTensorFlds[i].write();
}
forAll(symmTensorFlds, i)
{
symmTensorFlds[i].rename(symmTensorNames[i]);
symmTensorFlds[i].write();
}
forAll(tensorFlds, i)
{
tensorFlds[i].rename(tensorNames[i]);
tensorFlds[i].write();
}
// Surface ones.
// Surface fields.
forAll(surfScalarFlds, i)
{
surfScalarFlds[i].rename(surfScalarNames[i]);
surfScalarFlds[i].write();
}
forAll(surfVectorFlds, i)
{
surfVectorFlds[i].rename(surfVectorNames[i]);
surfVectorFlds[i].write();
}
forAll(surfSphericalTensorFlds, i)
forAll(surfSphTensorFlds, i)
{
surfSphericalTensorFlds[i].rename(surfSphericalTensorNames[i]);
surfSphericalTensorFlds[i].write();
surfSphTensorFlds[i].write();
}
forAll(surfSymmTensorFlds, i)
{
surfSymmTensorFlds[i].rename(surfSymmTensorNames[i]);
surfSymmTensorFlds[i].write();
}
forAll(surfTensorNames, i)
forAll(surfTensorFlds, i)
{
surfTensorFlds[i].rename(surfTensorNames[i]);
surfTensorFlds[i].write();
}
// Point ones
// Point fields
forAll(pointScalarFlds, i)
{
pointScalarFlds[i].rename(pointScalarNames[i]);
pointScalarFlds[i].write();
}
forAll(pointVectorFlds, i)
{
pointVectorFlds[i].rename(pointVectorNames[i]);
pointVectorFlds[i].write();
}
forAll(pointSphericalTensorFlds, i)
forAll(pointSphTensorFlds, i)
{
pointSphericalTensorFlds[i].rename(pointSphericalTensorNames[i]);
pointSphericalTensorFlds[i].write();
pointSphTensorFlds[i].write();
}
forAll(pointSymmTensorFlds, i)
{
pointSymmTensorFlds[i].rename(pointSymmTensorNames[i]);
pointSymmTensorFlds[i].write();
}
forAll(pointTensorNames, i)
forAll(pointTensorFlds, i)
{
pointTensorFlds[i].rename(pointTensorNames[i]);
pointTensorFlds[i].write();
}
// DimensionedFields
// Dimensioned fields
forAll(scalarDimFlds, i)
{
scalarDimFlds[i].rename(scalarDimNames[i]);
scalarDimFlds[i].write();
}
forAll(vectorDimFlds, i)
{
vectorDimFlds[i].rename(vectorDimNames[i]);
vectorDimFlds[i].write();
}
forAll(sphericalTensorDimFlds, i)
forAll(sphTensorDimFlds, i)
{
sphericalTensorDimFlds[i].rename(sphericalTensorDimNames[i]);
sphericalTensorDimFlds[i].write();
sphTensorDimFlds[i].write();
}
forAll(symmTensorDimFlds, i)
{
symmTensorDimFlds[i].rename(symmTensorDimNames[i]);
symmTensorDimFlds[i].write();
}
forAll(tensorDimFlds, i)
{
tensorDimFlds[i].rename(tensorDimNames[i]);
tensorDimFlds[i].write();
}
Info<< "End\n" << endl;
return 0;

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "doxygenXmlParser.H"
#include "wordRe.H"
#include "regExp.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -40,8 +40,8 @@ Foam::doxygenXmlParser::doxygenXmlParser
dictionary(dictionary::null)
{
// Pre-construct and compile regular expressions
const wordRe nameRe(".*.H", wordRe::DETECT);
const wordRe searchStrRe(searchStr, wordRe::DETECT);
const regExp nameRe(".*.H");
const regExp searchStrRe(searchStr);
// Pre-construct constant strings and names to speed-up comparisons
const string slashStartTag('/' + startTag);
@ -163,7 +163,7 @@ Foam::doxygenXmlParser::doxygenXmlParser
(
!exactMatch
&& !found(tName) // not already added
&& wordRe(".*" + tName + ".*", wordRe::DETECT).match(name)
&& regExp(".*" + tName + ".*").match(name)
)
{
dictionary dict(dictionary::null);

View File

@ -23,7 +23,7 @@ if (!fieldsToUse.found(fieldName))
).typeHeaderOk<volScalarField>(false, false)
);
if (variableGood)
if (!variableGood)
{
break;
}

View File

@ -35,36 +35,25 @@ if (timeDirs.size() && !noLagrangian)
cloudPrefix/cloudName
);
// clouds always require "positions"
// Clouds always have "positions"
if (cloudObjs.found("positions"))
{
HashTable<HashTable<word>>::iterator cloudIter =
cloudFields.find(cloudName);
// Save the cloud fields on a per cloud basis
auto fieldsPerCloud = cloudFields(cloudName);
if (cloudIter == cloudFields.end())
forAllConstIters(cloudObjs, fieldIter)
{
// A newly discovered cloud
cloudFields.insert(cloudName, HashTable<word>());
cloudIter = cloudFields.find(cloudName);
}
const IOobject* obj = fieldIter();
forAllConstIter(IOobjectList, cloudObjs, fieldIter)
{
const IOobject& obj = *fieldIter();
// Add field and field type
cloudIter().insert
(
obj.name(),
obj.headerClassName()
);
// Field name/type
fieldsPerCloud.insert(obj->name(), obj->headerClassName());
}
}
}
}
// prune out "positions" again since it gets treated specially
forAllIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
// Prune out "positions" again since it gets treated specially
forAllIters(cloudFields, cloudIter)
{
cloudIter().erase("positions");
}
@ -76,18 +65,13 @@ if (timeDirs.size() && !noLagrangian)
}
// sorted list of cloud names
// Sorted list of cloud names
const wordList cloudNames(cloudFields.sortedToc());
if (cloudNames.size())
{
// complete the echo information
Info<< "(";
forAll(cloudNames, cloudNo)
{
Info<< ' ' << cloudNames[cloudNo];
}
Info<< " ) " << endl;
// Complete the echo information - as flatOutput
cloudNames.writeList(Info) << endl;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -78,6 +78,7 @@ Note
#include "fvc.H"
#include "volFields.H"
#include "hashedWordList.H"
#include "labelIOField.H"
#include "scalarIOField.H"
@ -190,7 +191,7 @@ int main(int argc, char *argv[])
);
// The volume field types that we handle
const wordList volFieldTypes
const hashedWordList volFieldTypes
{
volScalarField::typeName,
volVectorField::typeName,
@ -207,7 +208,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
// default to binary output, unless otherwise specified
// Default to binary output, unless otherwise specified
const IOstream::streamFormat format =
(
args.optionFound("ascii")
@ -234,7 +235,7 @@ int main(int argc, char *argv[])
}
//
// general (case) output options
// General (case) output options
//
ensightCase::options caseOpts(format);
@ -257,7 +258,7 @@ int main(int argc, char *argv[])
//
// output configuration (geometry related)
// Output configuration (geometry related)
//
ensightMesh::options writeOpts(format);
writeOpts.noPatches(args.optionFound("noPatches"));
@ -313,12 +314,6 @@ int main(int argc, char *argv[])
ensCase.printInfo(Info) << endl;
}
// Set Time to the last time before looking for lagrangian objects
runTime.setTime(timeDirs.last(), timeDirs.size()-1);
IOobjectList objects(mesh, runTime.timeName());
#include "checkMeshMoving.H"
#include "findCloudFields.H"
@ -331,6 +326,40 @@ int main(int argc, char *argv[])
<< timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << nl << endl;
// Get the list of supported classes/fields
HashTable<wordHashSet> usableObjects;
{
// Initially all possible objects that are available at the final time
IOobjectList objects(mesh, timeDirs.last().name());
// Categorize by classes, pre-filter on name (if requested)
usableObjects =
(
fieldPatterns.empty()
? objects.classes()
: objects.classes(fieldPatterns)
);
// Limit to types that we explicitly handle
usableObjects.filterKeys(volFieldTypes);
// Force each field-type into existence (simplifies code logic
// and doesn't cost much) and simultaneously remove all
// "*_0" restart fields
for (auto fieldType : volFieldTypes)
{
usableObjects
(
fieldType
).filterKeys
(
[](const word& k){ return k.endsWith("_0"); },
true // prune
);
}
}
// ignore special fields (_0 fields),
// ignore fields we don't handle,
// ignore fields that are not available for all time-steps
@ -362,25 +391,22 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~~~~~~~~~~~~~
Info<< "Write volume field (";
forAll(volFieldTypes, typei)
for (auto fieldType : volFieldTypes)
{
const word& fieldType = volFieldTypes[typei];
wordList fieldNames = objects.names(fieldType);
// For convenience, just force each field-type into existence.
// This simplifies code logic and doesn't cost much at all.
wordHashSet& fieldNames = usableObjects(fieldType);
// Filter on name as required
if (!fieldPatterns.empty())
forAllIters(fieldNames, fieldIter)
{
inplaceSubsetStrings(fieldPatterns, fieldNames);
}
forAll(fieldNames, fieldi)
{
const word& fieldName = fieldNames[fieldi];
const word& fieldName = fieldIter.key();
#include "checkData.H"
// Partially complete field?
if (!fieldsToUse[fieldName])
{
fieldNames.erase(fieldIter);
continue;
}
@ -597,7 +623,8 @@ int main(int argc, char *argv[])
}
else
{
// Do not currently handle this type - blacklist for the future.
// Do not currently handle this type
// - blacklist for the future.
fieldsToUse.set(fieldName, false);
}

View File

@ -199,7 +199,7 @@ void print(Ostream& os, const wordList& flds)
labelList getSelectedPatches
(
const polyBoundaryMesh& patches,
const List<wordRe>& excludePatches
const wordRes& excludePatches
)
{
DynamicList<label> patchIDs(patches.size());
@ -219,7 +219,7 @@ labelList getSelectedPatches
Info<< " discarding empty/processor patch " << patchi
<< " " << pp.name() << endl;
}
else if (findStrings(excludePatches, pp.name()))
else if (excludePatches.match(pp.name()))
{
Info<< " excluding patch " << patchi
<< " " << pp.name() << endl;
@ -379,7 +379,7 @@ int main(int argc, char *argv[])
const bool allPatches = args.optionFound("allPatches");
List<wordRe> excludePatches;
wordReList excludePatches;
if (args.optionFound("excludePatches"))
{
args.optionLookup("excludePatches")() >> excludePatches;

View File

@ -64,7 +64,7 @@ class vtkPVFoamReader
{
public:
vtkTypeMacro(vtkPVFoamReader, vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream&, vtkIndent);
void PrintSelf(ostream&, vtkIndent) VTK_OVERRIDE;
static vtkPVFoamReader* New();
@ -199,7 +199,7 @@ protected:
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
) VTK_OVERRIDE;
//- Get the mesh/fields for a particular time
virtual int RequestData
@ -207,10 +207,10 @@ protected:
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
) VTK_OVERRIDE;
//- Fill in additional port information
virtual int FillOutputPortInformation(int, vtkInformation*);
virtual int FillOutputPortInformation(int, vtkInformation*) VTK_OVERRIDE;
//- The observer to modify this object when array selections are modified
vtkCallbackCommand* SelectionObserver;

View File

@ -62,7 +62,7 @@ class vtkPVblockMeshReader
{
public:
vtkTypeMacro(vtkPVblockMeshReader, vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream&, vtkIndent);
void PrintSelf(ostream&, vtkIndent) VTK_OVERRIDE;
static vtkPVblockMeshReader* New();
@ -127,7 +127,7 @@ protected:
vtkInformation* unusedRequest,
vtkInformationVector** unusedInputVector,
vtkInformationVector* outputVector
);
) VTK_OVERRIDE;
//- Get the mesh for a particular time
virtual int RequestData
@ -135,10 +135,10 @@ protected:
vtkInformation* unusedRequest,
vtkInformationVector** unusedInputVector,
vtkInformationVector* outputVector
);
) VTK_OVERRIDE;
//- Fill in additional port information
virtual int FillOutputPortInformation(int, vtkInformation*);
virtual int FillOutputPortInformation(int, vtkInformation*) VTK_OVERRIDE;
// The observer to modify this object when array selections are modified
vtkCallbackCommand* SelectionObserver;

View File

@ -169,7 +169,7 @@ void Foam::boundaryInfo::setType(const label patchI, const word& condition)
return;
}
if (wordRe(".*[Mm]apped.*", wordRe::REGEXP).match(types_[patchI]))
if (regExp(".*[Mm]apped.*").match(types_[patchI]))
{
// ugly hack to avoid overriding mapped types
return;

View File

@ -1,9 +1,9 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# fix permissions (NB: '+X' and not '+x'!)
# Fix permissions (NB: '+X' and not '+x'!)
chmod a+rX $WM_PROJECT_DIR $WM_PROJECT_DIR/doc Doxygen
Doxygen/Allwmake
exec Doxygen/Allwmake "$@"
#------------------------------------------------------------------------------

View File

@ -14,13 +14,17 @@ usage() {
usage: ${0##*/} [OPTION]
options:
-online use links to the Github repositories instead of the local source code
-config name use alternative doxygen config
-dir name process given directory name directly
-online use links to the Github repositories instead of the
local source code
-help
USAGE
exit 1
}
# -----------------------------------------------------------------------------
defineURL() {
WEB_PATH="https://develop.openfoam.com"
@ -39,13 +43,43 @@ defineURL() {
export FOAM_ONLINE_REPO="$FOAM_BASE_REPO/blob/${FOAM_REPO_TAG}"
}
# parse options
unset configName dirName
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
;;
-config)
configName="$2"
[ -f "$configName" ] || {
# No such file. Try some common alternatives
for ending in $configName ".$configName" "-$configName"
do
if [ -f "Doxyfile$ending" ]
then
configName="Doxyfile$ending"
break
fi
done
}
[ -f "$configName" ] || {
echo "Could not resolve Doxyfile config: $configName" 1>&2
exit 1
}
shift
;;
-dir)
dirName="$2"
[ -d "$dirName" ] || {
echo "Could not resolve input directory: $dirName" 1>&2
exit 1
}
shift
;;
-online)
defineURL
;;
@ -56,19 +90,31 @@ do
shift
done
#------------------------------------------------------------------------------
rm -rf latex man
# remove html directory in background
# Remove html directory in background
mv html html-stagedRemove$$ 2> /dev/null
rm -rf html-stagedRemove$$ >/dev/null 2>&1 &
# ensure that created files are readable by everyone
# Ensure that created files are readable by everyone
umask 22
doxygen
# fix permissions (NB: '+X' and not '+x'!)
if [ -n "$dirName" ]
then
# Create a temporary with only the specified directory
tmpConfig="${TMPDIR:-/tmp}/Doxyfile.$$"
trap 'rm -f $tmpConfig 2>/dev/null; exit 0' EXIT TERM INT
cat $PWD/Doxyfile > $tmpConfig
echo "INPUT = $dirName" >> $tmpConfig
doxygen $tmpConfig
else
doxygen $configName
fi
# Fix permissions (NB: '+X' and not '+x'!)
chmod -R a+rX html latex man 2>/dev/null
echo

View File

@ -111,7 +111,7 @@ Foam::regExp::~regExp()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::regExp::set(const char* pattern, bool ignoreCase)
bool Foam::regExp::set(const char* pattern, bool ignoreCase)
{
clear();
@ -137,7 +137,7 @@ void Foam::regExp::set(const char* pattern, bool ignoreCase)
// avoid zero-length patterns
if (!*pat)
{
return;
return false;
}
}
@ -154,11 +154,15 @@ void Foam::regExp::set(const char* pattern, bool ignoreCase)
<< nl << errbuf
<< exit(FatalError);
}
return true;
}
return false; // Was cleared and nothing was set
}
void Foam::regExp::set(const std::string& pattern, bool ignoreCase)
bool Foam::regExp::set(const std::string& pattern, bool ignoreCase)
{
return set(pattern.c_str(), ignoreCase);
}
@ -208,7 +212,7 @@ bool Foam::regExp::match(const std::string& text) const
if
(
regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(text.size()))
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == regoff_t(text.size()))
)
{
return true;

View File

@ -128,20 +128,23 @@ public:
// Editing
//- Compile pattern into a regular expression, optionally ignore case
void set(const char* pattern, bool ignoreCase=false);
//- Compile pattern into a regular expression, optionally ignore case.
// \return True if the pattern was compiled
bool set(const char* pattern, bool ignoreCase=false);
//- Compile pattern into a regular expression, optionally ignore case
void set(const std::string& pattern, bool ignoreCase=false);
// \return True if the pattern was compiled
bool set(const std::string& pattern, bool ignoreCase=false);
//- Clear expression, return true if expression had existed.
//- Clear expression.
// \return True if expression had existed prior to the clear.
bool clear();
// Matching/Searching
//- Find position within string.
// Returns the index where it begins or string::npos if not found
// \Return The index where it begins or string::npos if not found
std::string::size_type find(const std::string& text) const;
//- Return true if it matches the entire string
@ -158,6 +161,9 @@ public:
// Member Operators
//- Perform match on text
inline bool operator()(const std::string& text) const;
//- Assign and compile pattern from a character array
// Always case sensitive
inline void operator=(const char* pattern);

View File

@ -66,6 +66,12 @@ inline bool Foam::regExp::search(const std::string& text) const
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
inline bool Foam::regExp::operator()(const std::string& text) const
{
return match(text);
}
inline void Foam::regExp::operator=(const char* pattern)
{
set(pattern);

View File

@ -97,8 +97,8 @@ $(strings)/fileName/fileName.C
$(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyType.C
$(strings)/wordRe/wordRe.C
$(strings)/wordRes/wordRes.C
$(strings)/lists/hashedWordList.C
$(strings)/lists/wordReListMatcher.C
$(strings)/stringOps/stringOps.C
ops = primitives/ops

View File

@ -158,6 +158,20 @@ Foam::label Foam::HashSet<Key, Hash>::insert(std::initializer_list<Key> lst)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator()(const Key& key) const
{
return this->found(key);
}
template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
{
return this->found(key);
}
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& lst)
{
@ -180,12 +194,6 @@ void Foam::HashSet<Key, Hash>::operator=(std::initializer_list<Key> lst)
}
template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
{
return this->found(key);
}
template<class Key, class Hash>
bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const

View File

@ -156,22 +156,24 @@ public:
// Edit
//- Insert a new entry
// \return True if the entry inserted, which means that it did
// not previously exist in the set.
bool insert(const Key& key)
{
return this->parent_type::insert(key, nil());
}
//- Insert keys from the list of Key
// Return the number of new elements inserted
// \return The number of new elements inserted
label insert(const UList<Key>& lst);
//- Insert keys from the list of Key
// Return the number of new elements inserted
// \return The number of new elements inserted
template<unsigned Size>
label insert(const FixedList<Key, Size>& lst);
//- Insert keys from a initializer list of Key
// Return the number of new elements inserted
// \return The number of new elements inserted
label insert(std::initializer_list<Key> lst);
//- Same as insert (cannot overwrite nil content)
@ -200,18 +202,21 @@ public:
}
//- Unset the specified key - same as erase
// \return True if the entry existed and was removed
bool unset(const Key& key)
{
return this->parent_type::erase(key);
}
//- Unset the listed keys - same as erase
// \return The number of items removed
label unset(const UList<Key>& lst)
{
return this->parent_type::erase(lst);
}
//- Unset the listed keys - same as erase
// \return The number of items removed
template<unsigned Size>
label unset(const FixedList<Key, Size>& lst)
{
@ -219,11 +224,36 @@ public:
}
//- Unset the listed keys - same as erase
// \return The number of items removed
label unset(std::initializer_list<Key> lst)
{
return this->parent_type::erase(lst);
}
//- Not applicable for HashSet
template<class UnaryPredicate>
List<Key> tocValues(const UnaryPredicate&, const bool) = delete;
//- Not applicable for HashSet
template<class BinaryPredicate>
List<Key> tocEntries(const BinaryPredicate&, const bool) = delete;
//- Not applicable for HashSet
template<class UnaryPredicate>
label countValues(const UnaryPredicate&, const bool) = delete;
//- Not applicable for HashSet
template<class BinaryPredicate>
label countEntries(const BinaryPredicate&, const bool) = delete;
//- Not applicable for HashSet
template<class UnaryPredicate>
label filterValues(const UnaryPredicate&, const bool) = delete;
//- Not applicable for HashSet
template<class BinaryPredicate>
label filterEntries(const BinaryPredicate&, const bool) = delete;
// STL iterators
@ -248,12 +278,15 @@ public:
// Member Operators
//- This operation doesn't make much sense for a hash-set
void operator()(const Key& key) = delete;
//- Return true if the entry exists, same as found()
inline bool operator()(const Key& key) const;
//- Return true if the entry exists, same as found().
inline bool operator[](const Key& key) const;
// Comparison
//- Equality. Two hashset are equal when they have the same keys.
// Independent of table size or order.
bool operator==(const this_type& rhs) const;
@ -262,6 +295,8 @@ public:
bool operator!=(const this_type& rhs) const;
// Assignment
//- Assignment from a UList of keys
void operator=(const UList<Key>& lst);
@ -273,6 +308,8 @@ public:
void operator=(std::initializer_list<Key> lst);
// Logical operations
//- Combine entries from HashSets
void operator|=(const HashSet<Key, Hash>& rhs);

View File

@ -231,25 +231,169 @@ Foam::HashTable<T, Key, Hash>::find
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::toc() const
{
List<Key> keys(nElmts_);
label keyI = 0;
List<Key> keyLst(nElmts_);
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
keys[keyI++] = iter.key();
keyLst[count++] = iter.key();
}
return keys;
return keyLst;
}
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc() const
{
List<Key> sortedLst = this->toc();
sort(sortedLst);
List<Key> keyLst = this->toc();
Foam::sort(keyLst);
return sortedLst;
return keyLst;
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocKeys
(
const UnaryPredicate& pred,
const bool invert
) const
{
List<Key> keyLst(nElmts_);
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.key()) ? !invert : invert))
{
keyLst[count++] = iter.key();
}
}
keyLst.setSize(count);
Foam::sort(keyLst);
return keyLst;
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocValues
(
const UnaryPredicate& pred,
const bool invert
) const
{
List<Key> keyLst(nElmts_);
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.object()) ? !invert : invert))
{
keyLst[count++] = iter.key();
}
}
keyLst.setSize(count);
Foam::sort(keyLst);
return keyLst;
}
template<class T, class Key, class Hash>
template<class BinaryPredicate>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocEntries
(
const BinaryPredicate& pred,
const bool invert
) const
{
List<Key> keyLst(nElmts_);
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.key(), iter.object()) ? !invert : invert))
{
keyLst[count++] = iter.key();
}
}
keyLst.setSize(count);
Foam::sort(keyLst);
return keyLst;
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::countKeys
(
const UnaryPredicate& pred,
const bool invert
) const
{
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.key()) ? !invert : invert))
{
++count;
}
}
return count;
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::countValues
(
const UnaryPredicate& pred,
const bool invert
) const
{
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.object()) ? !invert : invert))
{
++count;
}
}
return count;
}
template<class T, class Key, class Hash>
template<class BinaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::countEntries
(
const BinaryPredicate& pred,
const bool invert
) const
{
label count = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if ((pred(iter.key(), iter.object()) ? !invert : invert))
{
++count;
}
}
return count;
}
@ -617,6 +761,87 @@ void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::filterKeys
(
const UnaryPredicate& pred,
const bool pruning
)
{
label changed = 0;
for (iterator iter = begin(); iter != end(); ++iter)
{
// Matches? either prune (pruning) or keep (!pruning)
if
(
(pred(iter.key()) ? pruning : !pruning)
&& erase(iter)
)
{
++changed;
}
}
return changed;
}
template<class T, class Key, class Hash>
template<class UnaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::filterValues
(
const UnaryPredicate& pred,
const bool pruning
)
{
label changed = 0;
for (iterator iter = begin(); iter != end(); ++iter)
{
// Matches? either prune (pruning) or keep (!pruning)
if
(
(pred(iter.object()) ? pruning : !pruning)
&& erase(iter)
)
{
++changed;
}
}
return changed;
}
template<class T, class Key, class Hash>
template<class BinaryPredicate>
Foam::label Foam::HashTable<T, Key, Hash>::filterEntries
(
const BinaryPredicate& pred,
const bool pruning
)
{
label changed = 0;
for (iterator iter = begin(); iter != end(); ++iter)
{
// Matches? either prune (pruning) or keep (!pruning)
if
(
(pred(iter.key(), iter.object()) ? pruning : !pruning)
&& erase(iter)
)
{
++changed;
}
}
return changed;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>

View File

@ -255,7 +255,7 @@ private:
inline label hashKeyIndex(const Key& key) const;
//- Assign a new hash-entry to a possibly already existing key.
// Return true if the new entry was set.
// \return True if the new entry was set.
bool set(const Key& key, const T& obj, const bool protect);
@ -330,22 +330,83 @@ public:
//- Return hashed entry if it exists, or return the given default
inline const T& lookup(const Key& key, const T& deflt) const;
// Table of contents
//- Return the table of contents
List<Key> toc() const;
//- Return the table of contents as a sorted list
List<Key> sortedToc() const;
//- Return the sorted table of contents with keys that satisfy
// the unary predicate, optionally with inverted logic.
template<class UnaryPredicate>
List<Key> tocKeys
(
const UnaryPredicate& pred,
const bool invert = false
) const;
//- Return the sorted table of contents with values that satisfy
// the unary predicate, optionally with inverted logic.
template<class UnaryPredicate>
List<Key> tocValues
(
const UnaryPredicate& pred,
const bool invert = false
) const;
//- Return the sorted table of contents with keys/values that satisfy
// the binary predicate, optionally with inverted logic.
template<class BinaryPredicate>
List<Key> tocEntries
(
const BinaryPredicate& pred,
const bool invert = false
) const;
// Counting
//- Count the number of keys that satisfy the unary predicate,
// optionally with inverted logic.
template<class UnaryPredicate>
label countKeys
(
const UnaryPredicate& pred,
const bool invert = false
) const;
//- Count the number of values that satisfy the unary predicate,
// optionally with inverted logic.
template<class UnaryPredicate>
label countValues
(
const UnaryPredicate& pred,
const bool invert = false
) const;
//- Count the number of entries that satisfy the binary predicate,
// optionally with inverted logic.
template<class BinaryPredicate>
label countEntries
(
const BinaryPredicate& pred,
const bool invert = false
) const;
// Edit
//- Insert a new entry
// Return true if the entry inserted, which means that it did
// \return True if the entry inserted, which means that it did
// not previously exist in the table.
inline bool insert(const Key& key, const T& obj);
//- Assign a new entry, overwriting existing entries.
// Returns true.
//
// \return True, since it always overwrites any entries.
inline bool set(const Key& key, const T& obj);
//- Erase an entry specified by given iterator
@ -357,30 +418,34 @@ public:
// auto iter = table.find(unknownKey);
// table.erase(iter);
// \endcode
// which is what \code table.erase(unknownKey) \endcode does anyhow
// which is what \code table.erase(unknownKey) \endcode does anyhow.
//
// \return True if the corresponding entry existed and was removed
bool erase(const iterator& iter);
//- Erase an entry specified by the given key
// \return True if the entry existed and was removed
bool erase(const Key& key);
//- Remove table entries given by the listed keys
// Return the number of elements removed
// \return The number of items removed
label erase(const UList<Key>& keys);
//- Remove table entries given by the listed keys
// Return the number of elements removed
// \return The number of items removed
template<unsigned Size>
label erase(const FixedList<Key, Size>& keys);
//- Remove table entries given by the listed keys
// Return the number of elements removed
// \return The number of items removed
label erase(std::initializer_list<Key> keys);
//- Remove table entries given by keys of the other hash-table.
// Return the number of elements removed.
//
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary.
//
// \return The number of items removed
template<class AnyType, class AnyHash>
label erase(const HashTable<AnyType, Key, AnyHash>& other);
@ -388,9 +453,66 @@ public:
//
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary.
//
// \return The number of items changed (removed)
template<class AnyType, class AnyHash>
label retain(const HashTable<AnyType, Key, AnyHash>& other);
//- Generalized means to filter table entries based on their keys.
// Keep (or optionally prune) entries with keys that satisfy
// the unary predicate, which has the following signature:
// \code
// bool operator()(const Key& k);
// \endcode
//
// For example,
// \code
// wordRes goodFields = ...;
// allFieldNames.filterKeys
// (
// [&goodFields](const word& k){ return goodFields.match(k); }
// );
// \endcode
//
// \return The number of items changed (removed)
template<class UnaryPredicate>
label filterKeys
(
const UnaryPredicate& pred,
const bool pruning = false
);
//- Generalized means to filter table entries based on their values.
// Keep (or optionally prune) entries with values that satisfy
// the unary predicate, which has the following signature:
// \code
// bool operator()(const T& v);
// \endcode
//
// \return The number of items changed (removed)
template<class UnaryPredicate>
label filterValues
(
const UnaryPredicate& pred,
const bool pruning = false
);
//- Generalized means to filter table entries based on their key/value.
// Keep (or optionally prune) entries with keys/values that satisfy
// the binary predicate, which has the following signature:
// \code
// bool operator()(const Key& k, const T& v);
// \endcode
//
// \return The number of items changed (removed)
template<class BinaryPredicate>
label filterEntries
(
const BinaryPredicate& pred,
const bool pruning = false
);
//- Resize the hash table for efficiency
void resize(const label sz);

View File

@ -46,26 +46,26 @@ Foam::label Foam::HashTableCore::canonicalSize(const label requested_size)
{
return 0;
}
else if (requested_size >= maxTableSize)
{
return maxTableSize;
}
// Enforce power of two - makes for a vey fast modulus etc.
// Enforce power of two - makes for a very fast modulus.
// Use unsigned for these calculations.
//
// - The lower limit (8) is somewhat arbitrary, but if the hash table
// is too small, there will be many direct table collisions.
// - The uper limit (approx. labelMax/4) must be a power of two,
// - The upper limit (approx. labelMax/4) must be a power of two,
// need not be extremely large for hashing.
uLabel powerOfTwo = 8; // lower-limit
const uLabel size = requested_size;
if (size < powerOfTwo)
if (size <= powerOfTwo)
{
return powerOfTwo;
}
else if (requested_size >= maxTableSize)
{
return maxTableSize;
}
else if (size & (size-1)) // <- Modulus of i^2
{
// Determine power-of-two. Brute-force is fast enough.

View File

@ -46,26 +46,26 @@ Foam::label Foam::StaticHashTableCore::canonicalSize(const label requested_size)
{
return 0;
}
else if (requested_size >= maxTableSize)
{
return maxTableSize;
}
// Enforce power of two - makes for a vey fast modulus etc.
// Enforce power of two - makes for a very fast modulus.
// Use unsigned for these calculations.
//
// - The lower limit (8) is somewhat arbitrary, but if the hash table
// is too small, there will be many direct table collisions.
// - The uper limit (approx. labelMax/4) must be a power of two,
// - The upper limit (approx. labelMax/4) must be a power of two,
// need not be extremely large for hashing.
uLabel powerOfTwo = 8; // lower-limit
const uLabel size = requested_size;
if (size < powerOfTwo)
if (size <= powerOfTwo)
{
return powerOfTwo;
}
else if (requested_size >= maxTableSize)
{
return maxTableSize;
}
else if (size & (size-1)) // <- Modulus of i^2
{
// Determine power-of-two. Brute-force is fast enough.

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,99 @@ License
#include "Time.H"
#include "OSspecific.H"
#include "IOList.H"
#include "stringListOps.H"
#include "predicates.H"
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
namespace Foam
{
// Templated implementation for lookup() - file-scope
template<class UnaryMatchPredicate>
static IOobjectList lookupImpl
(
const IOobjectList& list,
const UnaryMatchPredicate& matcher
)
{
IOobjectList results(list.size());
forAllConstIters(list, iter)
{
if (matcher(iter.key()))
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
}
results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
}
}
return results;
}
// Templated implementation for classes() - file-scope
template<class UnaryMatchPredicate>
static HashTable<wordHashSet> classesImpl
(
const IOobjectList& list,
const UnaryMatchPredicate& matcher
)
{
HashTable<wordHashSet> summary(2*list.size());
// Summary (key,val) = (class-name, object-names)
forAllConstIters(list, iter)
{
if (matcher(iter.key()))
{
// Create entry (if needed) and insert
summary(iter.object()->headerClassName()).insert(iter.key());
}
}
return summary;
}
// Templated implementation for names(), sortedNames() - file-scope
template<class UnaryMatchPredicate>
static wordList namesImpl
(
const IOobjectList& list,
const word& clsName,
const UnaryMatchPredicate& matcher,
const bool doSort
)
{
wordList objNames(list.size());
label count = 0;
forAllConstIters(list, iter)
{
if (iter()->headerClassName() == clsName && matcher(iter.key()))
{
objNames[count++] = iter.key();
}
}
objNames.setSize(count);
if (doSort)
{
Foam::sort(objNames);
}
return objNames;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -62,14 +154,14 @@ Foam::IOobjectList::IOobjectList
}
// Create a list of file names in this directory
fileNameList ObjectNames =
fileNameList objNames =
readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
forAll(ObjectNames, i)
forAll(objNames, i)
{
IOobject* objectPtr = new IOobject
(
ObjectNames[i],
objNames[i],
newInstance,
local,
db,
@ -81,7 +173,7 @@ Foam::IOobjectList::IOobjectList
// Use object with local scope
if (objectPtr->typeHeaderOk<IOList<label>>(false))
{
insert(ObjectNames[i], objectPtr);
insert(objectPtr->name(), objectPtr);
}
else
{
@ -119,7 +211,7 @@ bool Foam::IOobjectList::remove(IOobject& io)
Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
{
HashPtrTable<IOobject>::const_iterator iter = find(name);
const_iterator iter = find(name);
if (iter.found())
{
@ -144,53 +236,13 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& matcher) const
{
IOobjectList results(size());
forAllConstIters(*this, iter)
{
if (matcher.match(iter.key()))
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
}
results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
}
}
return results;
return lookupImpl(*this, matcher);
}
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
Foam::IOobjectList Foam::IOobjectList::lookup(const wordRes& matcher) const
{
wordReListMatcher mat(matcher);
IOobjectList results(size());
forAllConstIters(*this, iter)
{
if (mat.match(iter.key()))
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
}
results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
}
}
return results;
return lookupImpl(*this, matcher);
}
@ -219,6 +271,26 @@ Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
}
Foam::HashTable<Foam::wordHashSet> Foam::IOobjectList::classes() const
{
return classesImpl(*this, predicates::always());
}
Foam::HashTable<Foam::wordHashSet>
Foam::IOobjectList::classes(const wordRe& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::HashTable<Foam::wordHashSet>
Foam::IOobjectList::classes(const wordRes& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::wordList Foam::IOobjectList::names() const
{
return HashPtrTable<IOobject>::toc();
@ -236,20 +308,7 @@ Foam::wordList Foam::IOobjectList::names
const word& clsName
) const
{
wordList objNames(size());
label count = 0;
forAllConstIters(*this, iter)
{
if (iter()->headerClassName() == clsName)
{
objNames[count++] = iter.key();
}
}
objNames.setSize(count);
return objNames;
return namesImpl(*this, clsName, predicates::always(), false);
}
@ -259,21 +318,17 @@ Foam::wordList Foam::IOobjectList::names
const wordRe& matcher
) const
{
wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames));
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordReList& matcher
const wordRes& matcher
) const
{
wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames));
return namesImpl(*this, clsName, matcher, false);
}
@ -282,10 +337,7 @@ Foam::wordList Foam::IOobjectList::sortedNames
const word& clsName
) const
{
wordList sortedLst = names(clsName);
sort(sortedLst);
return sortedLst;
return namesImpl(*this, clsName, predicates::always(), true);
}
@ -295,23 +347,35 @@ Foam::wordList Foam::IOobjectList::sortedNames
const wordRe& matcher
) const
{
wordList sortedLst = names(clsName, matcher);
sort(sortedLst);
return sortedLst;
return namesImpl(*this, clsName, matcher, true);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
const wordReList& matcher
const wordRes& matcher
) const
{
wordList sortedLst = names(clsName, matcher);
sort(sortedLst);
return namesImpl(*this, clsName, matcher, true);
}
return sortedLst;
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const IOobjectList& list)
{
os << nl << list.size() << nl << token::BEGIN_LIST << nl;
forAllConstIters(list, it)
{
os << it.key() << token::SPACE << it.object()->headerClassName() << nl;
}
os << token::END_LIST;
os.check(FUNCTION_NAME);
return os;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,14 +36,20 @@ SourceFiles
#define IOobjectList_H
#include "HashPtrTable.H"
#include "HashSet.H"
#include "IOobject.H"
#include "wordReList.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
class IOobjectList;
Ostream& operator<<(Ostream& os, const IOobjectList& list);
/*---------------------------------------------------------------------------*\
Class IOobjectList Declaration
\*---------------------------------------------------------------------------*/
@ -86,12 +92,17 @@ public:
// Member functions
// Basic methods
//- Add an IOobject to the list
bool add(IOobject& io);
//- Remove an IOobject from the list
bool remove(IOobject& io);
// Lookup
//- Lookup a given name and return IOobject ptr if found else nullptr
IOobject* lookup(const word& name) const;
@ -99,12 +110,94 @@ public:
IOobjectList lookup(const wordRe& matcher) const;
//- The list of all IOobjects with matching names
IOobjectList lookup(const wordReList& matcher) const;
IOobjectList lookup(const wordRes& matcher) const;
//- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& clsName) const;
// Summary of classes
//- A summary hash of classes used and their associated object names.
// The HashTable representation allows us to leverage various
// HashTable methods.
// This hashed summary view can be useful when querying particular
// aspects. For example,
//
// \code
// IOobjectList objects(runTime, runTime.timeName());
// HashTable<wordHashSet> classes = objects.classes();
//
// // How many volScalarField?
// word checkType = volScalarField::typeName;
//
// Info<< checkType << "="
// << (classes.found(checkType) ? classes[checkType].size() : 0)
// << nl;
// \endcode
// Using the two-parameter HashTable::lookup method lets us avoid
// the \c '?' ternary, but still looks fairly ugly:
// \code
// Info<< checkType << "="
// << classes.lookup(checkType, wordHashSet()).size() << nl;
// \endcode
//
// If we have non-const access to the hash table, and don't mind
// incidentally creating empty entries,
// we can use the HashTable::operator() directly:
// \code
// Info<< checkType << "=" << classes(checkType).size() << nl;
// \endcode
//
// Of course, for a single query it would have been easier
// and simpler to have used a direct query of the names:
// \code
// Info<< checkType << "=" << objects.names(checkType).size() << nl;
// \endcode
//
// The summary hash, however, becomes most useful when reducing
// the objects in consideration to a particular subset. For example,
// \code
// const wordHashSet interestingTypes
// {
// volScalarField::typeName,
// volVectorField::typeName
// };
//
// classes.retain(interestingTypes);
// \endcode
// Or do just the opposite:
// \code
// classes.erase(unsupportedTypes);
// \endcode
// This also works with a hashedWordList, since it provides the
// expected '()' operator. But in this case the more general
// HashTable::filterKeys is required:
// \code
// const hashedWordList interestingTypes
// {
// volScalarField::typeName,
// volVectorField::typeName
// };
//
// classes.filterKeys(interestingTypes);
// \endcode
//
// Of course, there are many other ways to use and manipulate the
// summary information.
HashTable<wordHashSet> classes() const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRe& matcher) const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRes& matcher) const;
// Summary of names
//- A list of names of the IOobjects
wordList names() const;
@ -117,9 +210,11 @@ public:
//- The names of IOobjects with the given class name that also
// have a name satisfying the input matcher
wordList names(const word& clsName, const wordReList& matcher) const;
wordList names(const word& clsName, const wordRes& matcher) const;
// Summary of names (sorted)
//- A sorted list of names of the IOobjects
wordList sortedNames() const;
@ -132,11 +227,12 @@ public:
//- The sorted names of IOobjects with the given class name that also
// have a name satisfying the input matcher
wordList sortedNames
(
const word& clsName,
const wordReList& matcher
) const;
wordList sortedNames(const word& clsName, const wordRes& matcher) const;
// Ostream Operator
friend Ostream& operator<<(Ostream& os, const IOobjectList& list);
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,6 +25,7 @@ License
#include "objectRegistry.H"
#include "Time.H"
#include "predicates.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -103,7 +104,7 @@ Foam::objectRegistry::~objectRegistry()
}
}
for (label i=0; i < nMyObjects; i++)
for (label i=0; i < nMyObjects; ++i)
{
checkOut(*myObjects[i]);
}
@ -112,6 +113,26 @@ Foam::objectRegistry::~objectRegistry()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::HashTable<Foam::wordHashSet> Foam::objectRegistry::classes() const
{
return classesImpl(*this, predicates::always());
}
Foam::HashTable<Foam::wordHashSet>
Foam::objectRegistry::classes(const wordRe& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::HashTable<Foam::wordHashSet>
Foam::objectRegistry::classes(const wordRes& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::wordList Foam::objectRegistry::names() const
{
return HashTable<regIOobject*>::toc();
@ -124,31 +145,31 @@ Foam::wordList Foam::objectRegistry::sortedNames() const
}
Foam::wordList Foam::objectRegistry::names(const word& ClassName) const
Foam::wordList Foam::objectRegistry::names(const word& clsName) const
{
wordList objectNames(size());
wordList objNames(size());
label count=0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
if (iter()->type() == ClassName)
if (iter()->type() == clsName)
{
objectNames[count++] = iter.key();
objNames[count++] = iter.key();
}
}
objectNames.setSize(count);
objNames.setSize(count);
return objectNames;
return objNames;
}
Foam::wordList Foam::objectRegistry::sortedNames(const word& ClassName) const
Foam::wordList Foam::objectRegistry::sortedNames(const word& clsName) const
{
wordList sortedLst = names(ClassName);
sort(sortedLst);
wordList objNames = names(clsName);
Foam::sort(objNames);
return sortedLst;
return objNames;
}
@ -224,7 +245,7 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const
{
iterator iter = const_cast<objectRegistry&>(*this).find(io.name());
if (iter != end())
if (iter.found())
{
if (objectRegistry::debug)
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,8 +37,9 @@ SourceFiles
#define objectRegistry_H
#include "HashTable.H"
#include "HashSet.H"
#include "regIOobject.H"
#include "wordReList.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -75,6 +76,24 @@ class objectRegistry
// Used to terminate searching within the ancestors
bool parentNotTime() const;
//- Templated implementation for classes()
template<class UnaryMatchPredicate>
static HashTable<wordHashSet> classesImpl
(
const objectRegistry& list,
const UnaryMatchPredicate& matcher
);
//- Templated implementation for names()
template<class Type, class UnaryMatchPredicate>
static wordList namesImpl
(
const objectRegistry& list,
const UnaryMatchPredicate& matcher,
const bool doSort
);
//- Disallow Copy constructor
objectRegistry(const objectRegistry&) = delete;
@ -133,47 +152,70 @@ public:
return dbDir_;
}
// Summary of classes
//- A summary hash of classes used and their associated object names.
// Behaviour and usage as per IOobjectList::classes
HashTable<wordHashSet> classes() const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRe& matcher) const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRes& matcher) const;
// Summary of names
//- A list of names of the objects
wordList names() const;
//- The names of objects with the given class name
wordList names(const word& clsName) const;
//- The names of objects with the given type
template<class Type>
wordList names() const;
//- The names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList names(const wordRe& matcher) const;
//- The names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList names(const wordRes& matcher) const;
// Summary of names (sorted)
//- A sorted list of names of the objects
wordList sortedNames() const;
//- A list of names of objects that have the given class name
wordList names(const word& className) const;
//- The sorted names of objects with the given class name
wordList sortedNames(const word& clsName) const;
//- A sorted list of names of objects that have the given class name
wordList sortedNames(const word& className) const;
//- A list of names of objects that have the given type
template<class Type>
wordList names() const;
//- A list of names of objects that have the given type,
// and that also satisfy the input matcher
template<class Type>
wordList names(const wordRe&) const;
//- A list of names for objects that have the given type,
// and that also satisfy the input matchers
template<class Type>
wordList names(const wordReList&) const;
//- A sorted list of names of objects that have the given type
//- The sorted names of objects with the given type
template<class Type>
wordList sortedNames() const;
//- A sorted list of names of objects that have the given type,
// and that also satisfy the input matcher
//- The sorted names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRe&) const;
wordList sortedNames(const wordRe& matcher) const;
//- A sorted list of names of objects that have the given type,
// and that also satisfy the input matchers
//- The sorted names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordReList&) const;
wordList sortedNames(const wordRes& matcher) const;
// Lookup
//- Lookup and return a const sub-objectRegistry.
// Optionally create it if it does not exist.
// If recursive, search parent registries.
@ -245,6 +287,8 @@ public:
) const;
// Events
//- Return new event number.
label getEvent() const;
@ -255,10 +299,10 @@ public:
virtual void rename(const word& newName);
//- Add an regIOobject to registry
bool checkIn(regIOobject&) const;
bool checkIn(regIOobject& io) const;
//- Remove an regIOobject from registry
bool checkOut(regIOobject&) const;
bool checkOut(regIOobject& io) const;
// Reading

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,95 +25,115 @@ License
#include "objectRegistry.H"
#include "stringListOps.H"
#include "predicates.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Templated implementation for classes()
template<class UnaryMatchPredicate>
Foam::HashTable<Foam::wordHashSet> Foam::objectRegistry::classesImpl
(
const objectRegistry& list,
const UnaryMatchPredicate& matcher
)
{
HashTable<wordHashSet> summary(2*list.size());
// Summary (key,val) = (class-name, object-names)
forAllConstIters(list, iter)
{
if (matcher(iter.key()))
{
// Create entry (if needed) and insert
summary(iter.object()->type()).insert(iter.key());
}
}
return summary;
}
// Templated implementation for names()
template<class Type, class UnaryMatchPredicate>
Foam::wordList Foam::objectRegistry::namesImpl
(
const objectRegistry& list,
const UnaryMatchPredicate& matcher,
const bool doSort
)
{
wordList objNames(list.size());
label count = 0;
forAllConstIters(list, iter)
{
if (isA<Type>(*iter()) && matcher(iter()->name()))
{
objNames[count++] = iter()->name();
}
}
objNames.setSize(count);
if (doSort)
{
Foam::sort(objNames);
}
return objNames;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::wordList Foam::objectRegistry::names() const
{
wordList objectNames(size());
label count=0;
forAllConstIter(HashTable<regIOobject*>, *this, iter)
{
if (isA<Type>(*iter()))
{
objectNames[count++] = iter()->name();
}
}
objectNames.setSize(count);
return objectNames;
return namesImpl<Type>(*this, predicates::always(), false);
}
template<class Type>
Foam::wordList Foam::objectRegistry::names(const wordRe& matcher) const
{
wordList objectNames(size());
label count = 0;
forAllConstIter(HashTable<regIOobject*>, *this, iter)
{
if (isA<Type>(*iter()))
{
const word& objectName = iter()->name();
if (matcher.match(objectName))
{
objectNames[count++] = objectName;
}
}
}
objectNames.setSize(count);
return objectNames;
return namesImpl<Type>(*this, matcher, false);
}
template<class Type>
Foam::wordList Foam::objectRegistry::names(const wordReList& matcher) const
Foam::wordList Foam::objectRegistry::names
(
const wordRes& matcher
) const
{
wordList names(this->names<Type>());
return wordList(names, findStrings(matcher, names));
return namesImpl<Type>(*this, matcher, false);
}
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames() const
{
wordList sorted(this->names<Type>());
sort(sorted);
return sorted;
}
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames
(
const wordRe& match
) const
{
wordList sorted(this->names<Type>(match));
sort(sorted);
return sorted;
return namesImpl<Type>(*this, predicates::always(), true);
}
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames
(
const wordReList& matcher
const wordRe& matcher
) const
{
wordList sorted(this->names<Type>(matcher));
sort(sorted);
return namesImpl<Type>(*this, matcher, true);
}
return sorted;
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames
(
const wordRes& matcher
) const
{
return namesImpl<Type>(*this, matcher, true);
}
@ -125,7 +145,7 @@ Foam::HashTable<const Type*> Foam::objectRegistry::lookupClass
{
HashTable<const Type*> objectsOfClass(size());
forAllConstIter(HashTable<regIOobject*>, *this, iter)
forAllConstIters(*this, iter)
{
if (strict ? isType<Type>(*iter()) : isA<Type>(*iter()))
{
@ -149,7 +169,7 @@ Foam::HashTable<Type*> Foam::objectRegistry::lookupClass
{
HashTable<Type*> objectsOfClass(size());
forAllIter(HashTable<regIOobject*>, *this, iter)
forAllIters(*this, iter)
{
if (strict ? isType<Type>(*iter()) : isA<Type>(*iter()))
{
@ -194,7 +214,7 @@ const Type& Foam::objectRegistry::lookupObject
{
const_iterator iter = find(name);
if (iter != end())
if (iter.found())
{
const Type* ptr = dynamic_cast<const Type*>(iter());
@ -252,7 +272,7 @@ const Type* Foam::objectRegistry::lookupObjectPtr
{
const_iterator iter = find(name);
if (iter != end())
if (iter.found())
{
const Type* ptr = dynamic_cast<const Type*>(iter());

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,23 +47,23 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
// Count number of objects in all zones
label nObjects = 0;
forAll(*this, zoneI)
forAll(*this, zonei)
{
nObjects += this->operator[](zoneI).size();
nObjects += this->operator[](zonei).size();
}
zoneMapPtr_ = new Map<label>(2*nObjects);
Map<label>& zm = *zoneMapPtr_;
// Fill in objects of all zones into the map. The key is the global
// object index and the result is the zone index
forAll(*this, zoneI)
// Fill in objects of all zones into the map.
// The key is the global object index, value is the zone index
forAll(*this, zonei)
{
const labelList& zoneObjects = this->operator[](zoneI);
const labelList& zoneObjects = this->operator[](zonei);
forAll(zoneObjects, objI)
{
zm.insert(zoneObjects[objI], zoneI);
zm.insert(zoneObjects[objI], zonei);
}
}
}
@ -91,27 +91,23 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::read()
PtrList<entry> patchEntries(is);
zones.setSize(patchEntries.size());
forAll(zones, zoneI)
forAll(zones, zonei)
{
zones.set
(
zoneI,
zonei,
ZoneType::New
(
patchEntries[zoneI].keyword(),
patchEntries[zoneI].dict(),
zoneI,
patchEntries[zonei].keyword(),
patchEntries[zonei].dict(),
zonei,
*this
)
);
}
// Check state of IOstream
is.check
(
"ZoneMesh::ZoneMesh"
"(const IOobject&, const MeshType&)"
);
is.check(FUNCTION_NAME);
close();
@ -125,6 +121,40 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::read()
}
// Templated implementation for names()
template<class ZoneType, class MeshType>
template<class UnaryMatchPredicate>
Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::namesImpl
(
const PtrList<ZoneType>& zones,
const UnaryMatchPredicate& matcher,
const bool doSort
)
{
wordList lst(zones.size());
label count = 0;
forAll(zones, zonei)
{
const word& zname = zones[zonei].name();
if (matcher(zname))
{
lst[count++] = zname;
}
}
lst.setSize(count);
if (doSort)
{
Foam::sort(lst);
}
return lst;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ZoneType, class MeshType>
@ -179,9 +209,9 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
// Nothing read. Use supplied zones
PtrList<ZoneType>& zones = *this;
zones.setSize(pzm.size());
forAll(zones, zoneI)
forAll(zones, zonei)
{
zones.set(zoneI, pzm[zoneI].clone(*this).ptr());
zones.set(zonei, pzm[zonei].clone(*this).ptr());
}
}
}
@ -238,9 +268,9 @@ Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::types() const
wordList lst(zones.size());
forAll(zones, zoneI)
forAll(zones, zonei)
{
lst[zoneI] = zones[zoneI].type();
lst[zonei] = zones[zonei].type();
}
return lst;
@ -254,9 +284,9 @@ Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::names() const
wordList lst(zones.size());
forAll(zones, zoneI)
forAll(zones, zonei)
{
lst[zoneI] = zones[zoneI].name();
lst[zonei] = zones[zonei].name();
}
return lst;
@ -269,22 +299,18 @@ Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::names
const wordRe& matcher
) const
{
wordList lst = this->names();
return wordList(lst, findStrings(matcher, lst));
return namesImpl(*this, matcher, false);
}
template<class ZoneType, class MeshType>
Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::names
(
const wordReList& matcher
const wordRes& matcher
)
const
{
wordList lst = this->names();
return wordList(lst, findStrings(matcher, lst));
return namesImpl(*this, matcher, false);
}
@ -304,24 +330,18 @@ Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::sortedNames
const wordRe& matcher
) const
{
wordList sortedLst = this->names(matcher);
sort(sortedLst);
return sortedLst;
return namesImpl(*this, matcher, true);
}
template<class ZoneType, class MeshType>
Foam::wordList Foam::ZoneMesh<ZoneType, MeshType>::sortedNames
(
const wordReList& matcher
const wordRes& matcher
)
const
{
wordList sortedLst = this->names(matcher);
sort(sortedLst);
return sortedLst;
return namesImpl(*this, matcher, true);
}
@ -342,15 +362,15 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
else
{
indices.setSize(this->size());
label nFound = 0;
label count = 0;
forAll(*this, i)
{
if (key == operator[](i).name())
{
indices[nFound++] = i;
indices[count++] = i;
}
}
indices.setSize(nFound);
indices.setSize(count);
}
}
@ -388,7 +408,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
}
}
// not found
// Not found
return -1;
}
@ -401,11 +421,11 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
{
const PtrList<ZoneType>& zones = *this;
forAll(zones, zoneI)
forAll(zones, zonei)
{
if (zones[zoneI].name() == zoneName)
if (zones[zonei].name() == zoneName)
{
return zoneI;
return zonei;
}
}
@ -417,7 +437,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
<< "List of available zone names: " << names() << endl;
}
// not found
// Not found
return -1;
}
@ -447,9 +467,9 @@ void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
PtrList<ZoneType>& zones = *this;
forAll(zones, zoneI)
forAll(zones, zonei)
{
zones[zoneI].clearAddressing();
zones[zonei].clearAddressing();
}
}
@ -472,9 +492,9 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::checkDefinition
const PtrList<ZoneType>& zones = *this;
forAll(zones, zoneI)
forAll(zones, zonei)
{
inError |= zones[zoneI].checkDefinition(report);
inError |= zones[zonei].checkDefinition(report);
}
return inError;
}
@ -535,16 +555,16 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::checkParallelSync
// Check contents
if (!hasError)
{
forAll(zones, zoneI)
forAll(zones, zonei)
{
if (zones[zoneI].checkParallelSync(false))
if (zones[zonei].checkParallelSync(false))
{
hasError = true;
if (debug || (report && Pstream::master()))
{
Info<< " ***Zone " << zones[zoneI].name()
<< " of type " << zones[zoneI].type()
Info<< " ***Zone " << zones[zonei].name()
<< " of type " << zones[zonei].type()
<< " is not correctly synchronised"
<< " across coupled boundaries."
<< " (coupled faces are either not both"
@ -563,9 +583,9 @@ void Foam::ZoneMesh<ZoneType, MeshType>::movePoints(const pointField& p)
{
PtrList<ZoneType>& zones = *this;
forAll(zones, zoneI)
forAll(zones, zonei)
{
zones[zoneI].movePoints(p);
zones[zonei].movePoints(p);
}
}
@ -586,9 +606,9 @@ const ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator[]
const word& zoneName
) const
{
const label zoneI = findZoneID(zoneName);
const label zonei = findZoneID(zoneName);
if (zoneI < 0)
if (zonei < 0)
{
FatalErrorInFunction
<< "Zone named " << zoneName << " not found." << nl
@ -596,7 +616,7 @@ const ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator[]
<< abort(FatalError);
}
return operator[](zoneI);
return operator[](zonei);
}
@ -606,9 +626,9 @@ ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator[]
const word& zoneName
)
{
const label zoneI = findZoneID(zoneName);
const label zonei = findZoneID(zoneName);
if (zoneI < 0)
if (zonei < 0)
{
FatalErrorInFunction
<< "Zone named " << zoneName << " not found." << nl
@ -616,7 +636,7 @@ ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator[]
<< abort(FatalError);
}
return operator[](zoneI);
return operator[](zonei);
}
@ -631,9 +651,9 @@ Foam::Ostream& Foam::operator<<
{
os << zones.size() << nl << token::BEGIN_LIST;
forAll(zones, zoneI)
forAll(zones, zonei)
{
zones[zoneI].writeDict(os);
zones[zonei].writeDict(os);
}
os << token::END_LIST;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,7 +40,7 @@ SourceFiles
#include "pointField.H"
#include "Map.H"
#include "PackedBoolList.H"
#include "wordReList.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,7 +54,7 @@ namespace Foam
template<class ZoneType, class MeshType> class ZoneMesh;
template<class ZoneType, class MeshType>
Ostream& operator<<(Ostream&, const ZoneMesh<ZoneType, MeshType>&);
Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones);
/*---------------------------------------------------------------------------*\
Class ZoneMesh Declaration
@ -80,6 +80,19 @@ class ZoneMesh
//- Read if IOobject flags set. Return true if read.
bool read();
//- Create zone map
void calcZoneMap() const;
//- Templated implementation for names()
template<class UnaryMatchPredicate>
static wordList namesImpl
(
const PtrList<ZoneType>& zones,
const UnaryMatchPredicate& matcher,
const bool doSort
);
//- Disallow construct as copy
ZoneMesh(const ZoneMesh&) = delete;
@ -87,10 +100,6 @@ class ZoneMesh
void operator=(const ZoneMesh<ZoneType, MeshType>&) = delete;
//- Create zone map
void calcZoneMap() const;
public:
// Constructors
@ -98,24 +107,24 @@ public:
//- Read constructor given IOobject and a MeshType reference
ZoneMesh
(
const IOobject&,
const MeshType&
const IOobject& io,
const MeshType& mesh
);
//- Construct given size
ZoneMesh
(
const IOobject&,
const MeshType&,
const IOobject& io,
const MeshType& mesh,
const label size
);
//- Construct given a PtrList
ZoneMesh
(
const IOobject&,
const MeshType&,
const PtrList<ZoneType>&
const IOobject& io,
const MeshType& mesh,
const PtrList<ZoneType>& pzm
);
@ -146,32 +155,32 @@ public:
wordList names() const;
//- A list of the zone names satisfying the input matcher
wordList names(const wordRe&) const;
wordList names(const wordRe& matcher) const;
//- A list of the zone names satisfying the input matchers
wordList names(const wordReList&) const;
wordList names(const wordRes& matcher) const;
//- Sorted list of the zone names
wordList sortedNames() const;
//- Sorted list of the zone names satisfying the input matcher
wordList sortedNames(const wordRe&) const;
wordList sortedNames(const wordRe& matcher) const;
//- Sorted list of the zone names satisfying the input matchers
wordList sortedNames(const wordReList&) const;
wordList sortedNames(const wordRes& matcher) const;
//- Return zone indices for all matches
labelList findIndices(const keyType&) const;
labelList findIndices(const keyType& key) const;
//- Return zone index for the first match, return -1 if not found
label findIndex(const keyType&) const;
label findIndex(const keyType& key) const;
//- Find zone index given a name
label findZoneID(const word& zoneName) const;
//- Mark cells that match the zone specification
PackedBoolList findMatching(const keyType&) const;
PackedBoolList findMatching(const keyType& key) const;
//- Clear addressing
void clearAddressing();
@ -187,10 +196,10 @@ public:
bool checkParallelSync(const bool report = false) const;
//- Correct zone mesh after moving points
void movePoints(const pointField&);
void movePoints(const pointField& p);
//- writeData member function required by regIOobject
bool writeData(Ostream&) const;
bool writeData(Ostream& os) const;
// Member Operators
@ -198,18 +207,18 @@ public:
using PtrList<ZoneType>::operator[];
//- Return const reference to ZoneType by name.
const ZoneType& operator[](const word&) const;
const ZoneType& operator[](const word& zoneName) const;
//- Return reference to ZoneType by name.
ZoneType& operator[](const word&);
ZoneType& operator[](const word& zoneName);
// Ostream operator
friend Ostream& operator<< <ZoneType, MeshType>
(
Ostream&,
const ZoneMesh<ZoneType, MeshType>&
Ostream& os,
const ZoneMesh<ZoneType, MeshType>& zones
);
};

View File

@ -50,8 +50,8 @@ namespace Foam
class Switch;
class dictionary;
Istream& operator>>(Istream&, Switch&);
Ostream& operator<<(Ostream&, const Switch&);
Istream& operator>>(Istream& is, Switch& s);
Ostream& operator<<(Ostream& is, const Switch& s);
/*---------------------------------------------------------------------------*\
@ -108,8 +108,12 @@ private:
// Static Member Functions
//- Return a switchType representation of a word
static switchType asEnum(const std::string&, const bool allowInvalid);
//- Return a switchType representation of an input string
static switchType asEnum
(
const std::string& str,
const bool allowInvalid
);
public:
@ -161,8 +165,8 @@ public:
// value is not found, it is added into the dictionary.
static Switch lookupOrAddToDict
(
const word&,
dictionary&,
const word& name,
dictionary& dict,
const Switch& defaultValue = false
);
@ -176,7 +180,7 @@ public:
const char* asText() const;
//- Update the value of the Switch if it is found in the dictionary
bool readIfPresent(const word&, const dictionary&);
bool readIfPresent(const word& name, const dictionary& dict);
// Member Operators
@ -202,8 +206,8 @@ public:
// IOstream Operators
friend Istream& operator>>(Istream&, Switch&);
friend Ostream& operator<<(Ostream&, const Switch&);
friend Istream& operator>>(Istream& is, Switch& s);
friend Ostream& operator<<(Ostream& os, const Switch& s);
};

View File

@ -79,10 +79,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
return is;
}
// Check state of Istream
is.check("Istream& operator>>(Istream&, Switch&)");
is.check(FUNCTION_NAME);
return is;
}
@ -90,7 +87,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
Foam::Ostream& Foam::operator<<(Ostream& os, const Switch& s)
{
os << Switch::names[s.switch_];
os.check("Ostream& operator<<(Ostream&, const Switch&)");
os.check(FUNCTION_NAME);
return os;
}

View File

@ -45,10 +45,10 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Istream& operator>>(Istream&, bool&);
Ostream& operator<<(Ostream&, const bool);
Istream& operator>>(Istream& is, bool& b);
Ostream& operator<<(Ostream& os, const bool b);
bool readBool(Istream&);
bool readBool(Istream& is);
} // End namespace Foam
@ -61,7 +61,7 @@ bool readBool(Istream&);
namespace Foam
{
// template specialisation for pTraits<bool>
// Template specialisation for pTraits<bool>
template<>
class pTraits<bool>
{
@ -95,10 +95,10 @@ public:
// Constructors
//- Construct from primitive
explicit pTraits(const bool&);
explicit pTraits(const bool& p);
//- Construct from Istream
pTraits(Istream&);
pTraits(Istream& is);
// Member Functions

View File

@ -21,17 +21,11 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Reads an bool from an input stream, for a given version number and file
format. If an ASCII file is being read, then the line numbers are counted
and an erroneous read is reported.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "bool.H"
#include "Switch.H"
#include "error.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,8 +45,8 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const bool b)
{
// we could also write as text string without any difficulty
// os << (b ? "true" : "false");
os.write(label(b));
os.check("Ostream& operator<<(Ostream&, const bool)");
os.write(int(b));
os.check(FUNCTION_NAME);
return os;
}

View File

@ -48,10 +48,10 @@ class Ostream;
typedef uint8_t direction;
direction readDirection(Istream&);
Istream& operator>>(Istream&, direction&);
Ostream& operator<<(Ostream&, const direction);
std::ostream& operator<<(std::ostream&, const direction);
direction readDirection(Istream& is);
Istream& operator>>(Istream& is, direction& d);
Ostream& operator<<(Ostream& os, const direction d);
std::ostream& operator<<(std::ostream& os, const direction d);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -61,17 +61,15 @@ Foam::Istream& Foam::operator>>(Istream& is, direction& d)
return is;
}
// Check state of Istream
is.check("Istream& operator>>(Istream&, direction&)");
is.check(FUNCTION_NAME);
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const direction d)
{
os.write(label(d));
os.check("Ostream& operator<<(Ostream&, const direction)");
os.write(int(d));
os.check(FUNCTION_NAME);
return os;
}

View File

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
Namespace
Foam::predicates
Description
Various constant predicate types.
SourceFiles
predicates.H
\*---------------------------------------------------------------------------*/
#ifndef predicates_H
#define predicates_H
#include <string>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace predicates
{
/*---------------------------------------------------------------------------*\
Class always Declaration
\*---------------------------------------------------------------------------*/
//- Unary and binary predicates returning true, useful for templating.
class always
{
public:
typedef always value_type;
//- Construct null
inline always()
{}
//- Evalulated as a bool - return true
inline operator bool() const
{
return true;
}
//- Unary predicate returning true
template<class T>
inline bool operator()(const T&) const
{
return true;
}
//- Binary predicate returning false
template<class T1, class T2>
inline bool operator()(const T1&, const T2&) const
{
return true;
}
//- String matching returning true
inline bool match(const std::string& unused, bool literal=false) const
{
return true;
}
};
/*---------------------------------------------------------------------------*\
Class never Declaration
\*---------------------------------------------------------------------------*/
//- Unary and binary predicates returning false, useful for templating.
class never
{
public:
typedef never value_type;
//- Construct null
inline never()
{}
//- Evalulated as a bool - return false
inline operator bool() const
{
return false;
}
//- Unary predicate returning false
template<class T>
inline bool operator()(const T&) const
{
return false;
}
//- Binary predicate returning false
template<class T1, class T2>
inline bool operator()(const T1&, const T2&) const
{
return false;
}
//- String matching returning false
inline bool match(const std::string& unused, bool literal=false) const
{
return false;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace predicates
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -52,13 +52,11 @@ bool Foam::keyType::match(const std::string& text, bool literal) const
{
if (literal || !isPattern_)
{
// check as string
return (text == *this);
return !compare(text); // Compare as literal string
}
else
{
// check as regex
return regExp(*this).match(text);
return regExp(*this).match(text); // Match as regex
}
}

View File

@ -121,6 +121,13 @@ public:
// Member operators
//- Avoid masking the normal operator()
using word::operator();
//- Perform smart match on text
inline bool operator()(const std::string& text) const;
// Assignment
//- Assignment operator, retaining type (literal or regex)

View File

@ -81,6 +81,12 @@ inline bool Foam::keyType::isPattern() const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::keyType::operator()(const std::string& text) const
{
return match(text); // Use smart match
}
inline void Foam::keyType::operator=(const keyType& s)
{
string::operator=(s); // Bypass checking

View File

@ -47,8 +47,8 @@ namespace Foam
class hashedWordList;
// Forward declaration of friend functions and operators
Istream& operator>>(Istream&, hashedWordList&);
Ostream& operator<<(Ostream&, const hashedWordList&);
Istream& operator>>(Istream& is, hashedWordList& lst);
Ostream& operator<<(Ostream& os, const hashedWordList& lst);
/*---------------------------------------------------------------------------*\
@ -97,7 +97,7 @@ public:
);
//- Construct from an initializer list
inline hashedWordList(std::initializer_list<word>);
inline hashedWordList(std::initializer_list<word> lst);
//- Construct from the word keys of any HashTable, sorting immediately.
// This also handles a wordHashSet, which is derived from a HashTable.
@ -105,7 +105,7 @@ public:
template<class AnyType, class AnyHash>
explicit inline hashedWordList
(
const HashTable<AnyType, word, AnyHash>& h
const HashTable<AnyType, word, AnyHash>& tbl
);
//- Construct from number and list of words,
@ -122,7 +122,7 @@ public:
hashedWordList(const char** lst, const bool removeDuplicates=false);
//- Construct from Istream
hashedWordList(Istream&);
hashedWordList(Istream& is);
// Member Functions
@ -161,26 +161,33 @@ public:
// Member Operators
//- Assignment operator from list of words
inline void operator=(const UList<word>& lst);
//- Assignment operator from initializer list
inline void operator=(std::initializer_list<word> lst);
//- Assignment operator.
inline void operator=(const hashedWordList& lst);
//- Return name corresponding to specified index
inline const word& operator[](const label index) const;
//- Return index corresponding to specified name
//- Return index corresponding to specified name, or -1 on failure
inline label operator[](const word& name) const;
//- Does the list contain the specified name - same as found.
// Makes hashedWordList suitable as a unary predicate.
inline bool operator()(const word& name) const;
// Assignment
//- Assignment operator from list of words. Rehashes the indices.
inline void operator=(const UList<word>& lst);
//- Assignment operator from initializer list. Rehashes the indices.
inline void operator=(std::initializer_list<word> lst);
//- Assignment operator. Rehashes the indices.
inline void operator=(const hashedWordList& lst);
// Istream operators
friend Istream& operator>>(Istream&, hashedWordList&);
friend Ostream& operator<<(Ostream&, const hashedWordList&);
friend Istream& operator>>(Istream& is, hashedWordList& lst);
friend Ostream& operator<<(Ostream& os, const hashedWordList& lst);
};

View File

@ -90,21 +90,15 @@ inline Foam::hashedWordList::hashedWordList(std::initializer_list<word> lst)
template<class AnyType, class AnyHash>
inline Foam::hashedWordList::hashedWordList
(
const HashTable<AnyType, word, AnyHash>& h
const HashTable<AnyType, word, AnyHash>& tbl
)
:
List<word>(h.size())
List<word>(tbl.size())
{
label nElem = 0;
for
(
typename HashTable<AnyType, word, AnyHash>::const_iterator
iter = h.cbegin();
iter != h.cend();
++iter
)
label count = 0;
for (auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
{
List<word>::operator[](nElem++) = iter.key();
List<word>::operator[](count++) = iter.key();
}
this->sort();
@ -162,6 +156,34 @@ inline void Foam::hashedWordList::sort()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline const Foam::word& Foam::hashedWordList::operator[]
(
const label index
) const
{
return List<word>::operator[](index);
}
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
{
auto iter = indices_.find(name);
if (iter.found())
{
return iter.object();
}
return -1; // Not found (or not hashed?)
}
inline bool Foam::hashedWordList::operator()(const word& name) const
{
return indices_.found(name);
}
inline void Foam::hashedWordList::operator=(const UList<word>& lst)
{
List<word>::operator=(lst);
@ -182,20 +204,4 @@ inline void Foam::hashedWordList::operator=(const hashedWordList& lst)
}
inline const Foam::word& Foam::hashedWordList::operator[]
(
const label index
) const
{
return List<word>::operator[](index);
}
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
{
// Could return -1 instead of bombing out
return indices_[name];
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,11 +35,10 @@ SourceFiles
#ifndef stringListOps_H
#define stringListOps_H
#include "regExp.H"
#include "labelList.H"
#include "stringList.H"
#include "wordReList.H"
#include "wordReListMatcher.H"
#include "regExp.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,79 +46,88 @@ namespace Foam
{
// Single-string matches:
//- Return true if string matches one of the regular expressions
inline bool findStrings
(
const wordReListMatcher& matcher,
const std::string& str
)
//- Return true if text matches one of the regular expressions
// The primary purpose of this function is to automatically convert
// a wordReList to a wordRes for matching.
inline bool findStrings(const wordRes& matcher, const std::string& text)
{
return matcher.match(str);
return matcher(text);
}
// Multi-string matches:
//- Return list indices for matching strings
template<class Matcher, class StringType>
//- Extract list indices
// The unary match predicate has the following signature:
// \code
// bool operator()(const std::string& text);
// \endcode
//
// \return List indices for matching strings
template<class UnaryMatchPredicate, class StringType>
labelList findMatchingStrings
(
const Matcher& matcher,
const UnaryMatchPredicate& matcher,
const UList<StringType>& lst,
const bool invert=false
);
//- Return list indices for strings matching the regular expression
// Template partial specialization of findMatchingStrings
template<class StringType>
labelList findStrings
(
const regExp& re,
const UList<StringType>& lst,
const bool invert=false
)
{
return findMatchingStrings(re, lst, invert);
}
//- Return list indices for strings matching the regular expression
// Template partial specialization of findMatchingStrings
template<class StringType>
labelList findStrings
(
const char* rePattern,
const regExp& matcher,
const UList<StringType>& lst,
const bool invert=false
)
{
const regExp re(rePattern);
return findMatchingStrings(re, lst, invert);
return findMatchingStrings(matcher, lst, invert);
}
//- Return list indices for strings matching the regular expression
// Template partial specialization of findMatchingStrings
template<class StringType>
labelList findStrings
(
const std::string& rePattern,
const char* re,
const UList<StringType>& lst,
const bool invert=false
)
{
const regExp re(rePattern);
return findMatchingStrings(re, lst, invert);
const regExp matcher(re);
return findMatchingStrings(matcher, lst, invert);
}
//- Return list indices for strings matching the regular expression
// Template partial specialization of findMatchingStrings
template<class StringType>
labelList findStrings
(
const wordRe& wre,
const std::string& re,
const UList<StringType>& lst,
const bool invert=false
)
{
return findMatchingStrings(wre, lst, invert);
const regExp matcher(re);
return findMatchingStrings(matcher, lst, invert);
}
//- Return list indices for strings matching the regular expression
// Template partial specialization of findMatchingStrings
template<class StringType>
labelList findStrings
(
const wordRe& matcher,
const UList<StringType>& lst,
const bool invert=false
)
{
return findMatchingStrings(matcher, lst, invert);
}
@ -128,7 +136,7 @@ namespace Foam
template<class StringType>
labelList findStrings
(
const wordReListMatcher& matcher,
const wordRes& matcher,
const UList<StringType>& lst,
const bool invert=false
)
@ -136,31 +144,50 @@ namespace Foam
return findMatchingStrings(matcher, lst, invert);
}
// subsetting multi-string matches (similar to ListOp):
// Subsetting multi-string matches (similar to ListOp):
//- Extract elements of StringList when regular expression matches
// optionally invert the match
// eg, to extract all selected elements:
// \code
// subsetMatchingStrings<regExp, stringList>(myRegExp, lst);
template<class Matcher, class StringListType>
// \endcode
template<class UnaryMatchPredicate, class StringListType>
StringListType subsetMatchingStrings
(
const Matcher&,
const StringListType&,
const UnaryMatchPredicate& matcher,
const StringListType& lst,
const bool invert=false
);
//- Extract elements of StringList when regular expression matches
// Template partial specialization of subsetMatchingStrings
template<class StringListType>
StringListType subsetStrings
(
const regExp& re,
const regExp& matcher,
const StringListType& lst,
const bool invert=false
)
{
return subsetMatchingStrings(re, lst, invert);
return subsetMatchingStrings(matcher, lst, invert);
}
//- Extract elements of StringList when regular expression matches
// Template partial specialization of subsetMatchingStrings
template<class StringListType>
StringListType subsetStrings
(
const char* re,
const StringListType& lst,
const bool invert=false
)
{
const regExp matcher(re);
return subsetMatchingStrings(matcher, lst, invert);
}
//- Extract elements of StringList when regular expression matches
@ -168,13 +195,13 @@ namespace Foam
template<class StringListType>
StringListType subsetStrings
(
const char* rePattern,
const std::string& re,
const StringListType& lst,
const bool invert=false
)
{
const regExp re(rePattern);
return subsetMatchingStrings(re, lst, invert);
const regExp matcher(re);
return subsetMatchingStrings(matcher, lst, invert);
}
//- Extract elements of StringList when regular expression matches
@ -182,13 +209,12 @@ namespace Foam
template<class StringListType>
StringListType subsetStrings
(
const std::string& rePattern,
const wordRe& matcher,
const StringListType& lst,
const bool invert=false
)
{
const regExp re(rePattern);
return subsetMatchingStrings(re, lst, invert);
return subsetMatchingStrings(matcher, lst, invert);
}
//- Extract elements of StringList when regular expression matches
@ -196,20 +222,7 @@ namespace Foam
template<class StringListType>
StringListType subsetStrings
(
const wordRe& wre,
const StringListType& lst,
const bool invert=false
)
{
return subsetMatchingStrings(wre, lst, invert);
}
//- Extract elements of StringList when regular expression matches
// Template partial specialization of subsetMatchingStrings
template<class StringListType>
StringListType subsetStrings
(
const wordReListMatcher& matcher,
const wordRes& matcher,
const StringListType& lst,
const bool invert=false
)
@ -222,11 +235,11 @@ namespace Foam
// optionally invert the match
// eg, to extract all selected elements:
// inplaceSubsetMatchingStrings<regExp, stringList>(myRegExp, lst);
template<class Matcher, class StringListType>
template<class UnaryMatchPredicate, class StringListType>
void inplaceSubsetMatchingStrings
(
const Matcher&,
StringListType&,
const UnaryMatchPredicate& matcher,
StringListType& lst,
const bool invert=false
);
@ -235,12 +248,12 @@ namespace Foam
template<class StringListType>
void inplaceSubsetStrings
(
const regExp& re,
const regExp& matcher,
StringListType& lst,
const bool invert=false
)
{
inplaceSubsetMatchingStrings(re, lst, invert);
inplaceSubsetMatchingStrings(matcher, lst, invert);
}
//- Inplace extract elements of StringList when regular expression matches
@ -248,13 +261,13 @@ namespace Foam
template<class StringListType>
void inplaceSubsetStrings
(
const char* rePattern,
const char* re,
StringListType& lst,
const bool invert=false
)
{
const regExp re(rePattern);
inplaceSubsetMatchingStrings(re, lst, invert);
const regExp matcher(re);
inplaceSubsetMatchingStrings(matcher, lst, invert);
}
//- Inplace extract elements of StringList when regular expression matches
@ -262,13 +275,13 @@ namespace Foam
template<class StringListType>
void inplaceSubsetStrings
(
const std::string& rePattern,
const std::string& re,
StringListType& lst,
const bool invert=false
)
{
const regExp re(rePattern);
inplaceSubsetMatchingStrings(re, lst, invert);
const regExp matcher(re);
inplaceSubsetMatchingStrings(matcher, lst, invert);
}
//- Inplace extract elements of StringList when regular expression matches
@ -276,12 +289,12 @@ namespace Foam
template<class StringListType>
void inplaceSubsetStrings
(
const wordRe& wre,
const wordRe& matcher,
StringListType& lst,
const bool invert=false
)
{
inplaceSubsetMatchingStrings(wre, lst, invert);
inplaceSubsetMatchingStrings(matcher, lst, invert);
}
//- Inplace extract elements of StringList when regular expression matches
@ -289,7 +302,7 @@ namespace Foam
template<class StringListType>
void inplaceSubsetStrings
(
const wordReListMatcher& matcher,
const wordRes& matcher,
StringListType& lst,
const bool invert=false
)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,75 +25,79 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Matcher, class StringType>
template<class UnaryMatchPredicate, class StringType>
Foam::labelList Foam::findMatchingStrings
(
const Matcher& matcher,
const UnaryMatchPredicate& matcher,
const UList<StringType>& lst,
const bool invert
)
{
labelList indices(lst.size());
label nElem = 0;
forAll(lst, elemI)
label count = 0;
forAll(lst, elemi)
{
if (matcher.match(lst[elemI]) ? !invert : invert)
if (matcher(lst[elemi]) ? !invert : invert)
{
indices[nElem++] = elemI;
indices[count++] = elemi;
}
}
indices.setSize(nElem);
indices.setSize(count);
return indices;
}
template<class Matcher, class StringListType>
template<class UnaryMatchPredicate, class StringListType>
StringListType Foam::subsetMatchingStrings
(
const Matcher& matcher,
const UnaryMatchPredicate& matcher,
const StringListType& lst,
const bool invert
)
{
// Create copy
// Create as a copy
StringListType newLst(lst.size());
// ensure consistent addressable size (eg, DynamicList)
// Ensure consistent addressable size (eg, DynamicList)
newLst.setSize(lst.size());
label nElem = 0;
forAll(lst, elemI)
label count = 0;
forAll(lst, elemi)
{
if (matcher.match(lst[elemI]) ? !invert : invert)
if (matcher(lst[elemi]) ? !invert : invert)
{
newLst[nElem++] = lst[elemI];
newLst[count++] = lst[elemi];
}
}
newLst.setSize(nElem);
newLst.setSize(count);
return newLst;
}
template<class Matcher, class StringListType>
template<class UnaryMatchPredicate, class StringListType>
void Foam::inplaceSubsetMatchingStrings
(
const Matcher& matcher,
const UnaryMatchPredicate& matcher,
StringListType& lst,
const bool invert
)
{
label nElem = 0;
forAll(lst, elemI)
label count = 0;
forAll(lst, elemi)
{
if (matcher.match(lst[elemI]) ? !invert : invert)
if (matcher(lst[elemi]) ? !invert : invert)
{
lst[nElem++] = lst[elemI];
if (count != elemi)
{
lst[count] = lst[elemi];
}
++count;
}
}
lst.setSize(nElem);
lst.setSize(count);
}

View File

@ -94,7 +94,9 @@ public:
hash()
{}
inline unsigned operator()(const string&, unsigned seed = 0) const;
//- Hash for string.
// Uses Foam::string instead of std::string for automatic conversions.
inline unsigned operator()(const string& str, unsigned seed = 0) const;
};
@ -109,7 +111,7 @@ public:
//- Construct as copy of character array
inline string(const char* str);
//- Construct as copy of specified number of characters
//- Construct as copy with a maximum number of characters
inline string(const char* str, const size_type len);
//- Construct from a single character
@ -222,14 +224,18 @@ public:
// Member Operators
//- Return the sub-string from the i-th character for \a n characters
//- Match text
// \return True when strings match literally.
inline bool operator()(const std::string& text) const;
//- Return sub-string from the i-th character for \a n characters
inline string operator()
(
const size_type i,
const size_type n
) const;
//- Return the sub-string from the first character for \a n characters
//- Return sub-string from the first character for \a n characters
inline string operator()
(
const size_type n

View File

@ -178,15 +178,21 @@ inline String Foam::string::validate(const std::string& str)
return ss;
}
inline bool Foam::string::match(const std::string& text) const
{
// check as string
return (text == *this);
return !compare(text); // Always compare as literal string
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::string::operator()(const std::string& text) const
{
return !compare(text); // Always compare as literal string
}
inline Foam::string Foam::string::operator()
(
const size_type i,
@ -205,11 +211,11 @@ inline Foam::string Foam::string::operator()(const size_type n) const
inline unsigned Foam::string::hash::operator()
(
const string& key,
const string& str,
unsigned seed
) const
{
return Hasher(key.data(), key.size(), seed);
return Hasher(str.data(), str.size(), seed);
}
// ************************************************************************* //

View File

@ -25,7 +25,7 @@ Class
Foam::word
Description
A class for handling words, derived from string.
A class for handling words, derived from Foam::string.
A word is a string of characters without whitespace, quotes, slashes,
semicolons or brace brackets. Words are delimited by whitespace.
@ -93,7 +93,7 @@ public:
inline word
(
const char* s,
const size_type,
const size_type len,
const bool doStripInvalid
);

View File

@ -99,11 +99,11 @@ inline Foam::word::word(const char* s, const bool doStripInvalid)
inline Foam::word::word
(
const char* s,
const size_type n,
const size_type len,
const bool doStripInvalid
)
:
string(s, n)
string(s, len)
{
if (doStripInvalid)
{

View File

@ -92,15 +92,15 @@ public:
// Public data types
//- Enumeration with compile options
// Note that 'REGEXP' is implicit if 'NOCASE' is specified alone.
// Note that 'REGEX' is implicit if 'NOCASE' is specified alone.
enum compOption
{
LITERAL = 0, //!< Treat as a string literal
DETECT = 1, //!< Detect if the string contains meta-characters
REGEXP = 2, //!< Treat as regular expression
REGEX = 2, //!< Treat as regular expression
NOCASE = 4, //!< Ignore case in regular expression
DETECT_NOCASE = DETECT | NOCASE, //!< Combined DETECT and NOCASE
REGEXP_NOCASE = REGEXP | NOCASE //!< Combined REGEXP and NOCASE
DETECT_NOCASE = DETECT|NOCASE, //!< Combined DETECT and NOCASE
REGEX_NOCASE = REGEX|NOCASE //!< Combined REGEX and NOCASE
};
@ -119,30 +119,35 @@ public:
//- Construct as copy
inline wordRe(const wordRe& str);
//- Construct from keyType
//- Construct from keyType, using its compile information
inline explicit wordRe(const keyType& str);
//- Construct as copy of character array, treat as a literal
inline explicit wordRe(const char* str);
//- Construct as copy of std::string, treat as a literal
inline explicit wordRe(const std::string& str);
//- Construct as copy of string, treat as a literal
inline explicit wordRe(const string& str);
//- Construct as copy of word, treat as a literal
inline explicit wordRe(const word& str);
//- Construct from keyType, use specified compile option
inline wordRe(const keyType& str, const compOption);
//- Construct as copy of word
inline explicit wordRe(const word& str);
//- Construct as copy of character array, use specified compile option
inline wordRe(const char* str, const compOption);
//- Construct as copy of character array
// Optionally specify how it should be treated.
inline explicit wordRe(const char* str, const compOption = LITERAL);
//- Construct as copy of std::string, use specified compile option
inline wordRe(const std::string& str, const compOption);
//- Construct as copy of string.
// Optionally specify how it should be treated.
inline explicit wordRe(const string& str, const compOption = LITERAL);
//- Construct as copy of string, use specified compile option
inline wordRe(const string& str, const compOption);
//- Construct as copy of std::string
// Optionally specify how it should be treated.
inline explicit wordRe
(
const std::string& str,
const compOption = LITERAL
);
//- Construct as copy of word, use specified compile option
inline wordRe(const word& str, const compOption);
//- Construct from Istream
// Words are treated as literals, strings with an auto-test
@ -200,6 +205,13 @@ public:
// Member operators
//- Avoid masking the normal operator()
using word::operator();
//- Perform smart match on text, as per match()
inline bool operator()(const std::string& text) const;
// Assignment
//- Copy wordRe and its type (literal or regex)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,7 +48,7 @@ inline Foam::wordRe::wordRe()
inline Foam::wordRe::wordRe(const wordRe& str)
:
word(str),
word(str, false),
re_()
{
if (str.isPattern())
@ -58,13 +58,6 @@ inline Foam::wordRe::wordRe(const wordRe& str)
}
inline Foam::wordRe::wordRe(const word& str)
:
word(str),
re_()
{}
inline Foam::wordRe::wordRe(const keyType& str)
:
word(str, false),
@ -77,6 +70,34 @@ inline Foam::wordRe::wordRe(const keyType& str)
}
inline Foam::wordRe::wordRe(const char* str)
:
word(str, false),
re_()
{}
inline Foam::wordRe::wordRe(const std::string& str)
:
word(str, false),
re_()
{}
inline Foam::wordRe::wordRe(const string& str)
:
word(str, false),
re_()
{}
inline Foam::wordRe::wordRe(const word& str)
:
word(str, false),
re_()
{}
inline Foam::wordRe::wordRe(const keyType& str, const compOption opt)
:
word(str, false),
@ -91,17 +112,7 @@ inline Foam::wordRe::wordRe(const keyType& str, const compOption opt)
inline Foam::wordRe::wordRe(const char* str, const compOption opt)
:
word(str, false),
re_()
{
compile(opt);
}
inline Foam::wordRe::wordRe(const string& str, const compOption opt)
:
word(str, false),
re_()
wordRe(str)
{
compile(opt);
}
@ -109,8 +120,23 @@ inline Foam::wordRe::wordRe(const string& str, const compOption opt)
inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
:
word(str, false),
re_()
wordRe(str)
{
compile(opt);
}
inline Foam::wordRe::wordRe(const string& str, const compOption opt)
:
wordRe(str)
{
compile(opt);
}
inline Foam::wordRe::wordRe(const word& str, const compOption opt)
:
wordRe(str)
{
compile(opt);
}
@ -126,42 +152,38 @@ inline bool Foam::wordRe::isPattern() const
inline bool Foam::wordRe::compile(const compOption opt) const
{
bool doCompile = false;
if (opt & wordRe::REGEXP)
if (opt)
{
doCompile = true;
bool comp = false;
if (opt & wordRe::REGEX)
{
comp = true;
}
else if (opt & wordRe::DETECT)
{
if (string::meta<regExp>(*this) || !string::valid<word>(*this))
{
doCompile = true;
}
comp = string::meta<regExp>(*this) || !string::valid<word>(*this);
}
else if (opt & wordRe::NOCASE)
{
doCompile = true;
comp = true;
}
if (doCompile)
if (comp)
{
re_.set(*this, (opt & wordRe::NOCASE));
return re_.set(*this, (opt & wordRe::NOCASE));
}
else
{
}
// Fall-through behaviour - not a regex
re_.clear();
}
return re_.exists();
return false;
}
inline bool Foam::wordRe::compile() const
{
re_ = *this;
return re_.exists();
return re_.set(*this);
}
@ -169,7 +191,7 @@ inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
{
if (re_.clear() && doStripInvalid)
{
// skip stripping unless debug is active to avoid costly operations
// Skip stripping unless debug is active to avoid costly operations
if (word::debug)
{
string::stripInvalid<word>
@ -192,13 +214,11 @@ inline bool Foam::wordRe::match(const std::string& text, bool literal) const
{
if (literal || !re_.exists())
{
// check as string
return (text == *this);
return !compare(text); // Compare as literal string
}
else
{
// check as regex
return re_.match(text);
return re_.match(text); // Match as regex
}
}
@ -225,6 +245,12 @@ inline void Foam::wordRe::set(const char* str, const compOption opt)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::wordRe::operator()(const std::string& text) const
{
return match(text);
}
inline void Foam::wordRe::operator=(const wordRe& str)
{
string::operator=(str);
@ -263,21 +289,21 @@ inline void Foam::wordRe::operator=(const keyType& str)
inline void Foam::wordRe::operator=(const string& str)
{
string::operator=(str);
compile(wordRe::DETECT); // auto-detect regex
compile(wordRe::DETECT); // Auto-detect regex
}
inline void Foam::wordRe::operator=(const std::string& str)
{
string::operator=(str);
compile(wordRe::DETECT); // auto-detect regex
compile(wordRe::DETECT); // Auto-detect regex
}
inline void Foam::wordRe::operator=(const char* str)
{
string::operator=(str);
compile(wordRe::DETECT); // auto-detect regex
compile(wordRe::DETECT); // Auto-detect regex
}

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::wordReListMatcher
Description
The older name for Foam::wordRes, which is a wrapper for matching
a std::string against wordRe list.
\*---------------------------------------------------------------------------*/
#ifndef wordReListMatcher_H
#define wordReListMatcher_H
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef wordRes wordReListMatcher;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
#endif
// ************************************************************************* //

View File

@ -23,17 +23,17 @@ License
\*---------------------------------------------------------------------------*/
#include "wordReListMatcher.H"
#include "wordRes.H"
#include "HashSet.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::wordReList Foam::wordReListMatcher::uniq(const UList<wordRe>& input)
Foam::wordReList Foam::wordRes::uniq(const UList<wordRe>& input)
{
wordReList retain(input.size());
wordHashSet uniqWord;
label nUniq = 0;
label count = 0;
forAll(input, i)
{
const wordRe& select = input[i];
@ -44,11 +44,11 @@ Foam::wordReList Foam::wordReListMatcher::uniq(const UList<wordRe>& input)
|| uniqWord.insert(static_cast<const word&>(select))
)
{
retain[nUniq++] = select;
retain[count++] = select;
}
}
retain.setSize(nUniq);
retain.setSize(count);
return retain;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -22,23 +22,23 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::wordReListMatcher
Foam::wordRes
Description
A wrapper for matching a List of wordRe.
A wrapper for matching a std::string against a wordRe list.
Note
The constructor should remain non-explicit. This allows automatic
conversion from UList\<wordRe\> to wordReListMatcher in search
functions.
conversion from UList\<wordRe\> to wordRes in search functions.
SourceFiles
wordReListMatcherI.H
wordResI.H
wordRes.C
\*---------------------------------------------------------------------------*/
#ifndef wordReListMatcher_H
#define wordReListMatcher_H
#ifndef wordRes_H
#define wordRes_H
#include "wordReList.H"
@ -48,33 +48,46 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class wordReListMatcher Declaration
Class wordRes Declaration
\*---------------------------------------------------------------------------*/
class wordReListMatcher
class wordRes
{
// Private data
//- Reference to underlying list
const UList<wordRe>& reList_;
const UList<wordRe>& list_;
public:
// STL type definitions
//- Type of values the list contains
typedef wordRe value_type;
// Constructors
//- Construct from a List of wordRe
inline wordReListMatcher(const UList<wordRe>&);
//- Construct from a list of wordRe
inline wordRes(const UList<wordRe>& list);
// Static Constructors, Helpers
//- Return a wordReList with duplicate words filtered out.
// No filtering is done on regular expressions.
static wordReList uniq(const UList<wordRe>& input);
// Member Functions
// Access
//- The number of elements in the list
inline label size() const;
inline bool empty() const;
//- Return underlying list of wordRe
inline const UList<wordRe>& operator()() const;
//- True if the list is empty
inline bool empty() const;
// Searching
@ -82,14 +95,23 @@ public:
//- Return true if string matches any of the regular expressions
// Smart match as regular expression or as a string.
// Optionally specify a literal match only.
inline bool match(const std::string&, bool literalMatch=false) const;
inline bool match
(
const std::string& text,
const bool literal = false
) const;
// Helpers
// Member operators
//- Return a wordReList with duplicate words filtered out.
// No filtering is done on regular expressions.
static wordReList uniq(const UList<wordRe>& input);
//- Return underlying list of wordRe
inline const UList<wordRe>& operator()() const;
//- Perform smart match on text, as per match()
inline bool operator()(const std::string& text) const;
//- Return element of constant list
inline const wordRe& operator[](const label i) const;
};
@ -100,7 +122,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "wordReListMatcherI.H"
#include "wordResI.H"
#endif

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,46 +26,40 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::wordReListMatcher::wordReListMatcher
inline Foam::wordRes::wordRes
(
const UList<wordRe>& lst
const UList<wordRe>& list
)
:
reList_(lst)
list_(list)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::wordReListMatcher::size() const
inline Foam::label Foam::wordRes::size() const
{
return reList_.size();
return list_.size();
}
inline bool Foam::wordReListMatcher::empty() const
inline bool Foam::wordRes::empty() const
{
return reList_.empty();
return list_.empty();
}
inline const Foam::UList<Foam::wordRe>&
Foam::wordReListMatcher::operator()() const
{
return reList_;
}
inline bool Foam::wordReListMatcher::match
inline bool Foam::wordRes::match
(
const std::string& text,
bool literalMatch
const bool literal
) const
{
const label n = reList_.size();
const label n = list_.size();
for (label i = 0; i < n; ++i)
{
if (reList_[i].match(text, literalMatch))
if (list_[i].match(text, literal))
{
return true;
}
@ -75,4 +69,24 @@ inline bool Foam::wordReListMatcher::match
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline const Foam::UList<Foam::wordRe>& Foam::wordRes::operator()() const
{
return list_;
}
inline bool Foam::wordRes::operator()(const std::string& text) const
{
return match(text);
}
inline const Foam::wordRe& Foam::wordRes::operator[](const label i) const
{
return list_[i];
}
// ************************************************************************* //

View File

@ -151,7 +151,7 @@ void Foam::ensightMesh::correct()
useAll = false;
matched = findMatchingStrings
(
wordReListMatcher(matcher),
wordRes(matcher),
patchNames
);
}
@ -250,7 +250,7 @@ void Foam::ensightMesh::correct()
wordList selectZones = mesh_.faceZones().names();
inplaceSubsetMatchingStrings
(
wordReListMatcher(matcher),
wordRes(matcher),
selectZones
);

View File

@ -27,7 +27,7 @@ License
#include "volFields.H"
#include "dictionary.H"
#include "wordReListMatcher.H"
#include "wordRes.H"
#include "steadyStateDdtScheme.H"
#include "addToRunTimeSelectionTable.H"
@ -142,7 +142,7 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
return false;
}
selectFields_ = wordReListMatcher::uniq
selectFields_ = wordRes::uniq
(
wordReList(dict.lookup("fields"))
);

View File

@ -27,7 +27,7 @@ License
#include "volFields.H"
#include "dictionary.H"
#include "wordReListMatcher.H"
#include "wordRes.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -120,7 +120,7 @@ bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
selectFields_ = wordReListMatcher::uniq
selectFields_ = wordRes::uniq
(
wordReList(dict.lookup("fields"))
);

View File

@ -480,8 +480,7 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
else
{
WarningInFunction
<< "Glyphs can only be added to " << pTraits<scalar>::typeName
<< " and " << pTraits<vector>::typeName << " fields. "
<< "Glyphs can only be added to scalar and vector fields."
<< " Field " << scaleFieldName << " has " << nComponents
<< " components" << endl;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -133,6 +133,7 @@ protected:
//- Load fields from files (not from objectRegistry)
bool loadFromFiles_;
// Read from dictonary
//- Names of fields to probe
@ -179,16 +180,13 @@ protected:
//- Clear old field groups
void clearFieldGroups();
//- Append fieldName to the appropriate group
label appendFieldGroup(const word& fieldName, const word& fieldType);
//- Classify field types, returns the number of fields
label classifyFields();
//- Find cells and faces containing probes
virtual void findElements(const fvMesh&);
virtual void findElements(const fvMesh& mesh);
//- Classify field type and Open/close file streams,
//- Classify field type and open/close file streams,
// returns number of fields to sample
label prepare();
@ -219,10 +217,10 @@ private:
void sampleAndWriteSurfaceFields(const fieldGroup<Type>&);
//- Disallow default bitwise copy construct
probes(const probes&);
probes(const probes&) = delete;
//- Disallow default bitwise assignment
void operator=(const probes&);
void operator=(const probes&) = delete;
public:

View File

@ -47,106 +47,74 @@ void Foam::probes::clearFieldGroups()
}
Foam::label Foam::probes::appendFieldGroup
(
const word& fieldName,
const word& fieldType
)
{
if (fieldType == volScalarField::typeName)
{
scalarFields_.append(fieldName);
return 1;
}
else if (fieldType == volVectorField::typeName)
{
vectorFields_.append(fieldName);
return 1;
}
else if (fieldType == volSphericalTensorField::typeName)
{
sphericalTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == volSymmTensorField::typeName)
{
symmTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == volTensorField::typeName)
{
tensorFields_.append(fieldName);
return 1;
}
else if (fieldType == surfaceScalarField::typeName)
{
surfaceScalarFields_.append(fieldName);
return 1;
}
else if (fieldType == surfaceVectorField::typeName)
{
surfaceVectorFields_.append(fieldName);
return 1;
}
else if (fieldType == surfaceSphericalTensorField::typeName)
{
surfaceSphericalTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == surfaceSymmTensorField::typeName)
{
surfaceSymmTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == surfaceTensorField::typeName)
{
surfaceTensorFields_.append(fieldName);
return 1;
}
return 0;
}
Foam::label Foam::probes::classifyFields()
{
label nFields = 0;
clearFieldGroups();
if (loadFromFiles_)
{
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName());
wordList allFields = objects.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(indices, fieldi)
{
const word& fieldName = allFields[indices[fieldi]];
nFields += appendFieldGroup
HashTable<wordHashSet> available =
(
fieldName,
objects.find(fieldName)()->headerClassName()
loadFromFiles_
? IOobjectList(mesh_, mesh_.time().timeName()).classes(fieldSelection_)
: mesh_.classes(fieldSelection_)
);
}
}
else
{
// Check currently available fields
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(indices, fieldi)
forAllConstIters(available, iter)
{
const word& fieldName = allFields[indices[fieldi]];
const word& fieldType = iter.key();
const wordList fieldNames = iter.object().sortedToc();
nFields += appendFieldGroup
(
fieldName,
mesh_.find(fieldName)()->type()
);
const label count = fieldNames.size(); // pre-filtered, so non-empty
if (fieldType == volScalarField::typeName)
{
scalarFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volVectorField::typeName)
{
vectorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volSphericalTensorField::typeName)
{
sphericalTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volSymmTensorField::typeName)
{
symmTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volTensorField::typeName)
{
tensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == surfaceScalarField::typeName)
{
surfaceScalarFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == surfaceVectorField::typeName)
{
surfaceVectorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == surfaceSphericalTensorField::typeName)
{
surfaceSphericalTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == surfaceSymmTensorField::typeName)
{
surfaceSymmTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == surfaceTensorField::typeName)
{
surfaceTensorFields_.append(fieldNames);
nFields += count;
}
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -104,7 +104,6 @@ class sampledSets
{
formatter = writer<Type>::New(writeFormat);
}
};
@ -205,9 +204,6 @@ class sampledSets
//- Clear old field groups
void clearFieldGroups();
//- Append fieldName to the appropriate group
label appendFieldGroup(const word& fieldName, const word& fieldType);
//- Classify field types, returns the number of fields
label classifyFields();
@ -245,8 +241,8 @@ class sampledSets
//- Disallow default bitwise copy construct and assignment
sampledSets(const sampledSets&);
void operator=(const sampledSets&);
sampledSets(const sampledSets&) = delete;
void operator=(const sampledSets&) = delete;
public:

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
#include "volFields.H"
#include "IOobjectList.H"
#include "stringListOps.H"
#include "UIndirectList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -40,107 +41,81 @@ void Foam::sampledSets::clearFieldGroups()
}
Foam::label Foam::sampledSets::appendFieldGroup
(
const word& fieldName,
const word& fieldType
)
{
if (fieldType == volScalarField::typeName)
{
scalarFields_.append(fieldName);
return 1;
}
else if (fieldType == volVectorField::typeName)
{
vectorFields_.append(fieldName);
return 1;
}
else if (fieldType == volSphericalTensorField::typeName)
{
sphericalTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == volSymmTensorField::typeName)
{
symmTensorFields_.append(fieldName);
return 1;
}
else if (fieldType == volTensorField::typeName)
{
tensorFields_.append(fieldName);
return 1;
}
return 0;
}
Foam::label Foam::sampledSets::classifyFields()
{
label nFields = 0;
clearFieldGroups();
wordList allFields; // Just needed for warnings
HashTable<wordHashSet> available;
if (loadFromFiles_)
{
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName());
wordList allFields = objects.sortedNames();
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
forAll(indices, fieldi)
{
const word& fieldName = allFields[indices[fieldi]];
nFields += appendFieldGroup
(
fieldName,
objects.find(fieldName)()->headerClassName()
);
}
}
else
{
WarningInFunction
<< "Cannot find field file matching "
<< fieldSelection_[i] << endl;
}
}
allFields = objects.names();
available = objects.classes(fieldSelection_);
}
else
{
// Check currently available fields
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
allFields = mesh_.names();
available = mesh_.classes(fieldSelection_);
}
DynamicList<label> missed(fieldSelection_.size());
// Detect missing fields
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
if (findStrings(fieldSelection_[i], allFields).empty())
{
forAll(indices, fieldi)
{
const word& fieldName = allFields[indices[fieldi]];
nFields += appendFieldGroup
(
fieldName,
mesh_.find(fieldName)()->type()
);
missed.append(i);
}
}
else
if (missed.size())
{
WarningInFunction
<< "Cannot find registered field matching "
<< fieldSelection_[i] << endl;
<< nl
<< "Cannot find "
<< (loadFromFiles_ ? "field file" : "registered field")
<< " matching "
<< UIndirectList<wordRe>(fieldSelection_, missed) << endl;
}
forAllConstIters(available, iter)
{
const word& fieldType = iter.key();
const wordList fieldNames = iter.object().sortedToc();
const label count = fieldNames.size(); // pre-filtered, so non-empty
if (fieldType == volScalarField::typeName)
{
scalarFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volVectorField::typeName)
{
vectorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volSphericalTensorField::typeName)
{
sphericalTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volSymmTensorField::typeName)
{
symmTensorFields_.append(fieldNames);
nFields += count;
}
else if (fieldType == volTensorField::typeName)
{
tensorFields_.append(fieldNames);
nFields += count;
}
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,9 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "sampledSurfaces.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "stringListOps.H"
#include "UIndirectList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -34,48 +34,50 @@ Foam::label Foam::sampledSurfaces::classifyFields()
{
label nFields = 0;
wordList allFields; // Just needed for warnings
HashTable<wordHashSet> available;
if (loadFromFiles_)
{
// Check files for a particular time
IOobjectList objects(obr_, obr_.time().timeName());
wordList allFields = objects.sortedNames();
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
nFields += indices.size();
}
else
{
WarningInFunction
<< "Cannot find field file matching "
<< fieldSelection_[i] << endl;
}
}
allFields = objects.names();
available = objects.classes(fieldSelection_);
}
else
{
// Check currently available fields
wordList allFields = obr_.sortedNames();
allFields = obr_.names();
available = obr_.classes(fieldSelection_);
}
DynamicList<label> missed(fieldSelection_.size());
// Detect missing fields
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
if (findStrings(fieldSelection_[i], allFields).empty())
{
nFields += indices.size();
missed.append(i);
}
else
}
if (missed.size())
{
WarningInFunction
<< "Cannot find registered field matching "
<< fieldSelection_[i] << endl;
}
<< nl
<< "Cannot find "
<< (loadFromFiles_ ? "field file" : "registered field")
<< " matching "
<< UIndirectList<wordRe>(fieldSelection_, missed) << endl;
}
// Total number selected
forAllConstIters(available, iter)
{
nFields += iter.object().size();
}
return nFields;

View File

@ -31,7 +31,7 @@ License
#include "volPointInterpolation.H"
#include "PatchTools.H"
#include "mapPolyMesh.H"
#include "wordReListMatcher.H"
#include "wordRes.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -268,7 +268,7 @@ bool Foam::surfMeshSamplers::write()
}
// avoid duplicate entries
select = wordReListMatcher::uniq(select);
select = wordRes::uniq(select);
forAll(*this, surfI)
{
@ -290,7 +290,7 @@ bool Foam::surfMeshSamplers::read(const dictionary& dict)
if (dict.found("surfaces"))
{
fieldSelection_ = wordReListMatcher::uniq
fieldSelection_ = wordRes::uniq
(
wordReList(dict.lookup("fields"))
);