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/probesFunctionObject.C
probes/probesGrouping.C
probes/probesFunctionObject/probesFunctionObject.C
sampledSet/cloud/cloudSet.C
sampledSet/coordSet/coordSet.C

View File

@ -32,26 +32,25 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(probes, 0);
}
defineTypeNameAndDebug(Foam::probes, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::probes::findCells(const fvMesh& mesh)
{
if (cellList_.empty())
{
cellList_.setSize(probeLocations_.size());
cellList_.clear();
cellList_.setSize(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)
{
Pout<< "probes : found point " << probeLocations_[probeI]
Pout<< "probes : found point " << location
<< " in cell " << cellList_[probeI] << endl;
}
}
@ -60,6 +59,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
// Check if all probes have been found.
forAll(cellList_, probeI)
{
const vector& location = operator[](probeI);
label cellI = cellList_[probeI];
// Check at least one processor with cell.
@ -70,7 +70,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
if (Pstream::master())
{
WarningIn("probes::read()")
<< "Did not find location " << probeLocations_[probeI]
<< "Did not find location " << location
<< " in any cell. Skipping location." << endl;
}
}
@ -80,7 +80,7 @@ void Foam::probes::findCells(const fvMesh& mesh)
if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
{
WarningIn("probes::read()")
<< "Location " << probeLocations_[probeI]
<< "Location " << location
<< " seems to be on multiple domains:"
<< " cell " << cellList_[probeI]
<< " on my domain " << Pstream::myProcNo()
@ -93,152 +93,96 @@ void Foam::probes::findCells(const fvMesh& mesh)
}
}
}
}
bool Foam::probes::checkFieldTypes()
Foam::label Foam::probes::prepare()
{
wordList fieldTypes(fieldNames_.size());
// 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];
}
const label nFields = classifyFields();
// adjust file streams
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_;
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())
{
// Put in undecomposed case
// (Note: gives problems for distributed data running)
probeDir = obr_.time().path()/".."/probeSubDir;
probeDir = mesh_.time().path()/".."/probeSubDir;
}
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)
{
if (findIndex(foundFields, iter.key()) == -1)
if (!currentFields.erase(iter.key()))
{
if (debug)
{
Pout<< "close stream: " << iter()->name() << endl;
Info<< "close probe stream: " << iter()->name() << endl;
}
delete probeFilePtrs_.remove(iter);
}
}
// Open new files for new fields. Keep existing files.
probeFilePtrs_.resize(2*foundFields.size());
forAll(foundFields, fieldI)
// currentFields now just has the new fields - open streams for them
forAllConstIter(wordHashSet, currentFields, iter)
{
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.
mkDir(probeDir);
OFstream* sPtr = new OFstream(probeDir/fldName);
OFstream* sPtr = new OFstream(probeDir/fieldName);
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;
@ -247,9 +191,9 @@ bool Foam::probes::checkFieldTypes()
*sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
<< vector::componentNames[cmpt];
forAll(probeLocations_, probeI)
forAll(*this, probeI)
{
*sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
*sPtr<< ' ' << setw(w) << operator[](probeI)[cmpt];
}
*sPtr << endl;
}
@ -259,16 +203,7 @@ bool Foam::probes::checkFieldTypes()
}
}
if (debug)
{
Pout<< "Probing fields:" << foundFields << nl
<< "Probing locations:" << probeLocations_ << nl
<< endl;
}
}
return nFields > 0;
return nFields;
}
@ -282,18 +217,10 @@ Foam::probes::probes
const bool loadFromFiles
)
:
pointField(0),
name_(name),
obr_(obr),
loadFromFiles_(loadFromFiles),
fieldNames_(0),
probeLocations_(0),
scalarFields_(),
vectorFields_(),
sphericalTensorFields_(),
symmTensorFields_(),
tensorFields_(),
cellList_(0),
probeFilePtrs_(0)
mesh_(refCast<const fvMesh>(obr)),
loadFromFiles_(loadFromFiles)
{
read(dict);
}
@ -321,7 +248,7 @@ void Foam::probes::end()
void Foam::probes::write()
{
if (probeLocations_.size() && checkFieldTypes())
if (size() && prepare())
{
sampleAndWrite(scalarFields_);
sampleAndWrite(vectorFields_);
@ -334,13 +261,12 @@ void Foam::probes::write()
void Foam::probes::read(const dictionary& dict)
{
dict.lookup("fields") >> fieldNames_;
dict.lookup("probeLocations") >> probeLocations_;
dict.lookup("probeLocations") >> *this;
dict.lookup("fields") >> fieldSelection_;
// Force all cell locations to be redetermined
cellList_.clear();
findCells(refCast<const fvMesh>(obr_));
checkFieldTypes();
// redetermined all cell locations
findCells(mesh_);
prepare();
}

View File

@ -44,6 +44,8 @@ SourceFiles
#include "pointField.H"
#include "volFieldsFwd.H"
#include "wordReList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -60,6 +62,8 @@ class mapPolyMesh;
\*---------------------------------------------------------------------------*/
class probes
:
public pointField
{
// Private classes
@ -67,20 +71,15 @@ class probes
template<class Type>
class fieldGroup
:
public wordList
public DynamicList<word>
{
public:
//- Construct null
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.
word name_;
//- Const reference to objectRegistry
const objectRegistry& obr_;
//- Const reference to fvMesh
const fvMesh& mesh_;
//- Load fields from files (not from objectRegistry)
bool loadFromFiles_;
@ -100,11 +99,7 @@ class probes
// Read from dictonary
//- Names of fields to probe
wordList fieldNames_;
//- Locations to probe
vectorField probeLocations_;
wordReList fieldSelection_;
// Calculated
@ -124,19 +119,21 @@ class probes
// 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
void findCells(const fvMesh&);
//- classify field types, return true if nFields > 0
bool checkFieldTypes();
//- Find the fields in the list of the given type, return count
template<class Type>
label countFields
(
fieldGroup<Type>& fieldList,
const wordList& fieldTypes
) const;
//- Classify field type and Open/close file streams,
// returns number of fields
label prepare();
//- Sample and write a particular volume field
template<class Type>
@ -188,15 +185,21 @@ public:
}
//- Return names of fields to probe
virtual const wordList& fieldNames() const
virtual const wordReList& fieldNames() const
{
return fieldNames_;
return fieldSelection_;
}
//- 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)

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 * * * * * * * * * * * //
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>
void Foam::probes::sampleAndWrite
(
@ -103,15 +74,15 @@ void Foam::probes::sampleAndWrite
if (Pstream::master())
{
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)
{
probeStream << ' ' << setw(w) << values[probeI];
os << ' ' << setw(w) << values[probeI];
}
probeStream << endl;
os << endl;
}
}
@ -133,30 +104,30 @@ void Foam::probes::sampleAndWrite
IOobject
(
fields[fieldI],
obr_.time().timeName(),
refCast<const polyMesh>(obr_),
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
refCast<const fvMesh>(obr_)
mesh_
)
);
}
else
{
objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
objectRegistry::const_iterator iter = mesh_.find(fields[fieldI]);
if
(
iter != obr_.end()
iter != objectRegistry::end()
&& iter()->type()
== GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
sampleAndWrite
(
obr_.lookupObject
mesh_.lookupObject
<GeometricField<Type, fvPatchField, volMesh> >
(
fields[fieldI]
@ -181,12 +152,12 @@ Foam::probes::sample
tmp<Field<Type> > tValues
(
new Field<Type>(probeLocations_.size(), unsetVal)
new Field<Type>(this->size(), unsetVal)
);
Field<Type>& values = tValues();
forAll(probeLocations_, probeI)
forAll(*this, probeI)
{
if (cellList_[probeI] >= 0)
{
@ -207,7 +178,7 @@ Foam::probes::sample(const word& fieldName) const
{
return sample
(
obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
(
fieldName
)

View File

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