probes - handle fields as wordReList

- adjust code to more closely resemble sampledSets / sampledSurfaces
This commit is contained in:
Mark Olesen
2009-12-01 17:53:18 +01:00
parent b752ce5272
commit 2667382644
8 changed files with 293 additions and 268 deletions

View File

@ -1,5 +1,6 @@
probes/probes.C probes/probes.C
probes/probesFunctionObject.C probes/probesGrouping.C
probes/probesFunctionObject/probesFunctionObject.C
sampledSet/cloud/cloudSet.C sampledSet/cloud/cloudSet.C
sampledSet/coordSet/coordSet.C sampledSet/coordSet/coordSet.C

View File

@ -32,26 +32,25 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam defineTypeNameAndDebug(Foam::probes, 0);
{
defineTypeNameAndDebug(probes, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::probes::findCells(const fvMesh& mesh) void Foam::probes::findCells(const fvMesh& mesh)
{ {
if (cellList_.empty()) cellList_.clear();
{ cellList_.setSize(size());
cellList_.setSize(probeLocations_.size());
forAll(probeLocations_, probeI) forAll(*this, probeI)
{ {
cellList_[probeI] = mesh.findCell(probeLocations_[probeI]); const vector& location = operator[](probeI);
cellList_[probeI] = mesh.findCell(location);
if (debug && cellList_[probeI] != -1) if (debug && cellList_[probeI] != -1)
{ {
Pout<< "probes : found point " << probeLocations_[probeI] Pout<< "probes : found point " << location
<< " in cell " << cellList_[probeI] << endl; << " in cell " << cellList_[probeI] << endl;
} }
} }
@ -60,6 +59,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
// Check if all probes have been found. // Check if all probes have been found.
forAll(cellList_, probeI) forAll(cellList_, probeI)
{ {
const vector& location = operator[](probeI);
label cellI = cellList_[probeI]; label cellI = cellList_[probeI];
// Check at least one processor with cell. // Check at least one processor with cell.
@ -70,7 +70,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
if (Pstream::master()) if (Pstream::master())
{ {
WarningIn("probes::read()") WarningIn("probes::read()")
<< "Did not find location " << probeLocations_[probeI] << "Did not find location " << location
<< " in any cell. Skipping location." << endl; << " in any cell. Skipping location." << endl;
} }
} }
@ -80,7 +80,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
if (cellList_[probeI] != -1 && cellList_[probeI] != cellI) if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
{ {
WarningIn("probes::read()") WarningIn("probes::read()")
<< "Location " << probeLocations_[probeI] << "Location " << location
<< " seems to be on multiple domains:" << " seems to be on multiple domains:"
<< " cell " << cellList_[probeI] << " cell " << cellList_[probeI]
<< " on my domain " << Pstream::myProcNo() << " on my domain " << Pstream::myProcNo()
@ -92,153 +92,97 @@ void Foam::probes::findCells(const fvMesh& mesh)
} }
} }
} }
}
} }
bool Foam::probes::checkFieldTypes() Foam::label Foam::probes::prepare()
{ {
wordList fieldTypes(fieldNames_.size()); const label nFields = classifyFields();
// check files for a particular time
if (loadFromFiles_)
{
forAll(fieldNames_, fieldI)
{
IOobject io
(
fieldNames_[fieldI],
obr_.time().timeName(),
refCast<const polyMesh>(obr_),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (io.headerOk())
{
fieldTypes[fieldI] = io.headerClassName();
}
else
{
fieldTypes[fieldI] = "(notFound)";
}
}
}
else
{
// check objectRegistry
forAll(fieldNames_, fieldI)
{
objectRegistry::const_iterator iter =
obr_.find(fieldNames_[fieldI]);
if (iter != obr_.end())
{
fieldTypes[fieldI] = iter()->type();
}
else
{
fieldTypes[fieldI] = "(notFound)";
}
}
}
label nFields = 0;
// classify fieldTypes
nFields += countFields(scalarFields_, fieldTypes);
nFields += countFields(vectorFields_, fieldTypes);
nFields += countFields(sphericalTensorFields_, fieldTypes);
nFields += countFields(symmTensorFields_, fieldTypes);
nFields += countFields(tensorFields_, fieldTypes);
// concatenate all the lists into foundFields
wordList foundFields(nFields);
label fieldI = 0;
forAll(scalarFields_, i)
{
foundFields[fieldI++] = scalarFields_[i];
}
forAll(vectorFields_, i)
{
foundFields[fieldI++] = vectorFields_[i];
}
forAll(sphericalTensorFields_, i)
{
foundFields[fieldI++] = sphericalTensorFields_[i];
}
forAll(symmTensorFields_, i)
{
foundFields[fieldI++] = symmTensorFields_[i];
}
forAll(tensorFields_, i)
{
foundFields[fieldI++] = tensorFields_[i];
}
// adjust file streams
if (Pstream::master()) if (Pstream::master())
{ {
fileName probeDir; wordHashSet currentFields;
forAll(scalarFields_, fieldI)
{
currentFields.set(scalarFields_[fieldI]);
}
forAll(vectorFields_, fieldI)
{
currentFields.set(vectorFields_[fieldI]);
}
forAll(sphericalTensorFields_, fieldI)
{
currentFields.set(sphericalTensorFields_[fieldI]);
}
forAll(symmTensorFields_, fieldI)
{
currentFields.set(symmTensorFields_[fieldI]);
}
forAll(tensorFields_, fieldI)
{
currentFields.set(tensorFields_[fieldI]);
}
if (debug)
{
Info<< "Probing fields:" << currentFields << nl
<< "Probing locations:" << *this << nl
<< endl;
}
fileName probeDir;
fileName probeSubDir = name_; fileName probeSubDir = name_;
if (obr_.name() != polyMesh::defaultRegion) if (mesh_.name() != polyMesh::defaultRegion)
{ {
probeSubDir = probeSubDir/obr_.name(); probeSubDir = probeSubDir/mesh_.name();
} }
probeSubDir = probeSubDir/obr_.time().timeName(); probeSubDir = probeSubDir/mesh_.time().timeName();
if (Pstream::parRun()) if (Pstream::parRun())
{ {
// Put in undecomposed case // Put in undecomposed case
// (Note: gives problems for distributed data running) // (Note: gives problems for distributed data running)
probeDir = obr_.time().path()/".."/probeSubDir; probeDir = mesh_.time().path()/".."/probeSubDir;
} }
else else
{ {
probeDir = obr_.time().path()/probeSubDir; probeDir = mesh_.time().path()/probeSubDir;
} }
// Close the file if any fields have been removed. // ignore known fields, close streams for fields that no longer exist
forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter) forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
{ {
if (findIndex(foundFields, iter.key()) == -1) if (!currentFields.erase(iter.key()))
{ {
if (debug) if (debug)
{ {
Pout<< "close stream: " << iter()->name() << endl; Info<< "close probe stream: " << iter()->name() << endl;
} }
delete probeFilePtrs_.remove(iter); delete probeFilePtrs_.remove(iter);
} }
} }
// Open new files for new fields. Keep existing files. // currentFields now just has the new fields - open streams for them
forAllConstIter(wordHashSet, currentFields, iter)
probeFilePtrs_.resize(2*foundFields.size());
forAll(foundFields, fieldI)
{ {
const word& fldName = foundFields[fieldI]; const word& fieldName = iter.key();
// Check if added field. If so open a stream for it.
if (!probeFilePtrs_.found(fldName))
{
// Create directory if does not exist. // Create directory if does not exist.
mkDir(probeDir); mkDir(probeDir);
OFstream* sPtr = new OFstream(probeDir/fldName); OFstream* sPtr = new OFstream(probeDir/fieldName);
if (debug) if (debug)
{ {
Pout<< "open stream: " << sPtr->name() << endl; Info<< "open probe stream: " << sPtr->name() << endl;
} }
probeFilePtrs_.insert(fldName, sPtr); probeFilePtrs_.insert(fieldName, sPtr);
unsigned int w = IOstream::defaultPrecision() + 7; unsigned int w = IOstream::defaultPrecision() + 7;
@ -247,9 +191,9 @@ bool Foam::probes::checkFieldTypes()
*sPtr<< '#' << setw(IOstream::defaultPrecision() + 6) *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
<< vector::componentNames[cmpt]; << vector::componentNames[cmpt];
forAll(probeLocations_, probeI) forAll(*this, probeI)
{ {
*sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt]; *sPtr<< ' ' << setw(w) << operator[](probeI)[cmpt];
} }
*sPtr << endl; *sPtr << endl;
} }
@ -259,16 +203,7 @@ bool Foam::probes::checkFieldTypes()
} }
} }
if (debug) return nFields;
{
Pout<< "Probing fields:" << foundFields << nl
<< "Probing locations:" << probeLocations_ << nl
<< endl;
}
}
return nFields > 0;
} }
@ -282,18 +217,10 @@ Foam::probes::probes
const bool loadFromFiles const bool loadFromFiles
) )
: :
pointField(0),
name_(name), name_(name),
obr_(obr), mesh_(refCast<const fvMesh>(obr)),
loadFromFiles_(loadFromFiles), loadFromFiles_(loadFromFiles)
fieldNames_(0),
probeLocations_(0),
scalarFields_(),
vectorFields_(),
sphericalTensorFields_(),
symmTensorFields_(),
tensorFields_(),
cellList_(0),
probeFilePtrs_(0)
{ {
read(dict); read(dict);
} }
@ -321,7 +248,7 @@ void Foam::probes::end()
void Foam::probes::write() void Foam::probes::write()
{ {
if (probeLocations_.size() && checkFieldTypes()) if (size() && prepare())
{ {
sampleAndWrite(scalarFields_); sampleAndWrite(scalarFields_);
sampleAndWrite(vectorFields_); sampleAndWrite(vectorFields_);
@ -334,13 +261,12 @@ void Foam::probes::write()
void Foam::probes::read(const dictionary& dict) void Foam::probes::read(const dictionary& dict)
{ {
dict.lookup("fields") >> fieldNames_; dict.lookup("probeLocations") >> *this;
dict.lookup("probeLocations") >> probeLocations_; dict.lookup("fields") >> fieldSelection_;
// Force all cell locations to be redetermined // redetermined all cell locations
cellList_.clear(); findCells(mesh_);
findCells(refCast<const fvMesh>(obr_)); prepare();
checkFieldTypes();
} }

View File

@ -44,6 +44,8 @@ SourceFiles
#include "pointField.H" #include "pointField.H"
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
#include "wordReList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -60,6 +62,8 @@ class mapPolyMesh;
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class probes class probes
:
public pointField
{ {
// Private classes // Private classes
@ -67,20 +71,15 @@ class probes
template<class Type> template<class Type>
class fieldGroup class fieldGroup
: :
public wordList public DynamicList<word>
{ {
public: public:
//- Construct null //- Construct null
fieldGroup() fieldGroup()
: :
wordList() DynamicList<word>(0)
{} {}
//- Construct for a list of field names
fieldGroup(const wordList& fieldNames)
:
wordList(fieldNames)
{}
}; };
@ -90,8 +89,8 @@ class probes
// Also used as the name of the probes directory. // Also used as the name of the probes directory.
word name_; word name_;
//- Const reference to objectRegistry //- Const reference to fvMesh
const objectRegistry& obr_; const fvMesh& mesh_;
//- Load fields from files (not from objectRegistry) //- Load fields from files (not from objectRegistry)
bool loadFromFiles_; bool loadFromFiles_;
@ -100,11 +99,7 @@ class probes
// Read from dictonary // Read from dictonary
//- Names of fields to probe //- Names of fields to probe
wordList fieldNames_; wordReList fieldSelection_;
//- Locations to probe
vectorField probeLocations_;
// Calculated // Calculated
@ -124,19 +119,21 @@ class probes
// Private Member Functions // Private Member Functions
//- 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 containing probes //- Find cells containing probes
void findCells(const fvMesh&); void findCells(const fvMesh&);
//- classify field types, return true if nFields > 0 //- Classify field type and Open/close file streams,
bool checkFieldTypes(); // returns number of fields
label prepare();
//- Find the fields in the list of the given type, return count
template<class Type>
label countFields
(
fieldGroup<Type>& fieldList,
const wordList& fieldTypes
) const;
//- Sample and write a particular volume field //- Sample and write a particular volume field
template<class Type> template<class Type>
@ -146,7 +143,7 @@ class probes
); );
//- Sample and write all the fields of the given type //- Sample and write all the fields of the given type
template <class Type> template<class Type>
void sampleAndWrite(const fieldGroup<Type>&); void sampleAndWrite(const fieldGroup<Type>&);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
@ -188,15 +185,21 @@ public:
} }
//- Return names of fields to probe //- Return names of fields to probe
virtual const wordList& fieldNames() const virtual const wordReList& fieldNames() const
{ {
return fieldNames_; return fieldSelection_;
} }
//- Return locations to probe //- Return locations to probe
virtual const vectorField& probeLocations() const virtual const pointField& probeLocations() const
{ {
return probeLocations_; return *this;
}
//- Return location for probe i
virtual const point& probe(const label i) const
{
return operator[](i);
} }
//- Cells to be probed (obtained from the locations) //- Cells to be probed (obtained from the locations)

View File

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "probes.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::probes::clearFieldGroups()
{
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
}
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;
}
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
(
fieldName,
objects.find(fieldName)()->headerClassName()
);
}
}
else
{
// check currently available fields
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(indices, fieldI)
{
const word& fieldName = allFields[indices[fieldI]];
nFields += appendFieldGroup
(
fieldName,
mesh_.find(fieldName)()->type()
);
}
}
return nFields;
}
// ************************************************************************* //

View File

@ -63,35 +63,6 @@ public:
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
Foam::label Foam::probes::countFields
(
fieldGroup<Type>& fieldList,
const wordList& fieldTypes
) const
{
fieldList.setSize(fieldNames_.size());
label nFields = 0;
forAll(fieldNames_, fieldI)
{
if
(
fieldTypes[fieldI]
== GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
fieldList[nFields] = fieldNames_[fieldI];
nFields++;
}
}
fieldList.setSize(nFields);
return nFields;
}
template<class Type> template<class Type>
void Foam::probes::sampleAndWrite void Foam::probes::sampleAndWrite
( (
@ -103,15 +74,15 @@ void Foam::probes::sampleAndWrite
if (Pstream::master()) if (Pstream::master())
{ {
unsigned int w = IOstream::defaultPrecision() + 7; unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& probeStream = *probeFilePtrs_[vField.name()]; OFstream& os = *probeFilePtrs_[vField.name()];
probeStream << setw(w) << vField.time().value(); os << setw(w) << vField.time().value();
forAll(values, probeI) forAll(values, probeI)
{ {
probeStream << ' ' << setw(w) << values[probeI]; os << ' ' << setw(w) << values[probeI];
} }
probeStream << endl; os << endl;
} }
} }
@ -133,30 +104,30 @@ void Foam::probes::sampleAndWrite
IOobject IOobject
( (
fields[fieldI], fields[fieldI],
obr_.time().timeName(), mesh_.time().timeName(),
refCast<const polyMesh>(obr_), mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
), ),
refCast<const fvMesh>(obr_) mesh_
) )
); );
} }
else else
{ {
objectRegistry::const_iterator iter = obr_.find(fields[fieldI]); objectRegistry::const_iterator iter = mesh_.find(fields[fieldI]);
if if
( (
iter != obr_.end() iter != objectRegistry::end()
&& iter()->type() && iter()->type()
== GeometricField<Type, fvPatchField, volMesh>::typeName == GeometricField<Type, fvPatchField, volMesh>::typeName
) )
{ {
sampleAndWrite sampleAndWrite
( (
obr_.lookupObject mesh_.lookupObject
<GeometricField<Type, fvPatchField, volMesh> > <GeometricField<Type, fvPatchField, volMesh> >
( (
fields[fieldI] fields[fieldI]
@ -181,12 +152,12 @@ Foam::probes::sample
tmp<Field<Type> > tValues tmp<Field<Type> > tValues
( (
new Field<Type>(probeLocations_.size(), unsetVal) new Field<Type>(this->size(), unsetVal)
); );
Field<Type>& values = tValues(); Field<Type>& values = tValues();
forAll(probeLocations_, probeI) forAll(*this, probeI)
{ {
if (cellList_[probeI] >= 0) if (cellList_[probeI] >= 0)
{ {
@ -207,7 +178,7 @@ Foam::probes::sample(const word& fieldName) const
{ {
return sample return sample
( (
obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> > mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
( (
fieldName fieldName
) )

View File

@ -145,7 +145,6 @@ Foam::sampledSets::sampledSets
loadFromFiles_(loadFromFiles), loadFromFiles_(loadFromFiles),
outputPath_(fileName::null), outputPath_(fileName::null),
searchEngine_(mesh_, true), searchEngine_(mesh_, true),
fieldSelection_(),
interpolationScheme_(word::null), interpolationScheme_(word::null),
writeFormat_(word::null) writeFormat_(word::null)
{ {