ENH: simplify sampling grouping using new IOobjectList methods

This commit is contained in:
Mark Olesen
2017-05-17 16:25:20 +02:00
parent b2edd73881
commit aeae8e70de
5 changed files with 204 additions and 265 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -133,6 +133,7 @@ protected:
//- Load fields from files (not from objectRegistry) //- Load fields from files (not from objectRegistry)
bool loadFromFiles_; bool loadFromFiles_;
// Read from dictonary // Read from dictonary
//- Names of fields to probe //- Names of fields to probe
@ -179,16 +180,13 @@ protected:
//- Clear old field groups //- Clear old field groups
void clearFieldGroups(); void clearFieldGroups();
//- Append fieldName to the appropriate group
label appendFieldGroup(const word& fieldName, const word& fieldType);
//- Classify field types, returns the number of fields //- Classify field types, returns the number of fields
label classifyFields(); label classifyFields();
//- Find cells and faces containing probes //- 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 // returns number of fields to sample
label prepare(); label prepare();
@ -219,10 +217,10 @@ private:
void sampleAndWriteSurfaceFields(const fieldGroup<Type>&); void sampleAndWriteSurfaceFields(const fieldGroup<Type>&);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
probes(const probes&); probes(const probes&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const probes&); void operator=(const probes&) = delete;
public: 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() Foam::label Foam::probes::classifyFields()
{ {
label nFields = 0; label nFields = 0;
clearFieldGroups(); clearFieldGroups();
if (loadFromFiles_) HashTable<wordHashSet> available =
{
// 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
( (
fieldName, loadFromFiles_
objects.find(fieldName)()->headerClassName() ? 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 const label count = fieldNames.size(); // pre-filtered, so non-empty
(
fieldName, if (fieldType == volScalarField::typeName)
mesh_.find(fieldName)()->type() {
); 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / 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 License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -104,7 +104,6 @@ class sampledSets
{ {
formatter = writer<Type>::New(writeFormat); formatter = writer<Type>::New(writeFormat);
} }
}; };
@ -205,9 +204,6 @@ class sampledSets
//- Clear old field groups //- Clear old field groups
void clearFieldGroups(); void clearFieldGroups();
//- Append fieldName to the appropriate group
label appendFieldGroup(const word& fieldName, const word& fieldType);
//- Classify field types, returns the number of fields //- Classify field types, returns the number of fields
label classifyFields(); label classifyFields();
@ -245,8 +241,8 @@ class sampledSets
//- Disallow default bitwise copy construct and assignment //- Disallow default bitwise copy construct and assignment
sampledSets(const sampledSets&); sampledSets(const sampledSets&) = delete;
void operator=(const sampledSets&); void operator=(const sampledSets&) = delete;
public: public:

View File

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