sampledSets - handle fields as wordReList

- adjust code to more closely resemble sampledSurfaces
This commit is contained in:
Mark Olesen
2009-12-01 16:11:18 +01:00
parent abc8d96198
commit b752ce5272
9 changed files with 373 additions and 308 deletions

View File

@ -9,6 +9,7 @@ sampledSet/midPoint/midPointSet.C
sampledSet/midPointAndFace/midPointAndFaceSet.C sampledSet/midPointAndFace/midPointAndFaceSet.C
sampledSet/sampledSet/sampledSet.C sampledSet/sampledSet/sampledSet.C
sampledSet/sampledSets/sampledSets.C sampledSet/sampledSets/sampledSets.C
sampledSet/sampledSets/sampledSetsGrouping.C
sampledSet/sampledSetsFunctionObject/sampledSetsFunctionObject.C sampledSet/sampledSetsFunctionObject/sampledSetsFunctionObject.C
sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C
sampledSet/uniform/uniformSet.C sampledSet/uniform/uniformSet.C
@ -34,6 +35,7 @@ sampledSurface/distanceSurface/distanceSurface.C
sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C
sampledSurface/sampledSurface/sampledSurface.C sampledSurface/sampledSurface/sampledSurface.C
sampledSurface/sampledSurfaces/sampledSurfaces.C sampledSurface/sampledSurfaces/sampledSurfaces.C
sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C
sampledSurface/sampledSurfacesFunctionObject/sampledSurfacesFunctionObject.C sampledSurface/sampledSurfacesFunctionObject/sampledSurfacesFunctionObject.C
sampledSurface/thresholdCellFaces/thresholdCellFaces.C sampledSurface/thresholdCellFaces/thresholdCellFaces.C
sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C

View File

@ -34,103 +34,12 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam defineTypeNameAndDebug(Foam::sampledSets, 0);
{
defineTypeNameAndDebug(sampledSets, 0);
}
bool Foam::sampledSets::verbose_ = false; bool Foam::sampledSets::verbose_ = false;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::sampledSets::checkFieldTypes()
{
wordList fieldTypes(fieldNames_.size());
// check files for a particular time
if (loadFromFiles_)
{
forAll(fieldNames_, fieldi)
{
IOobject io
(
fieldNames_[fieldi],
mesh_.time().timeName(),
mesh_,
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 =
mesh_.find(fieldNames_[fieldi]);
if (iter != mesh_.objectRegistry::end())
{
fieldTypes[fieldi] = iter()->type();
}
else
{
fieldTypes[fieldi] = "(notFound)";
}
}
}
label nFields = 0;
// classify fieldTypes
nFields += grep(scalarFields_, fieldTypes);
nFields += grep(vectorFields_, fieldTypes);
nFields += grep(sphericalTensorFields_, fieldTypes);
nFields += grep(symmTensorFields_, fieldTypes);
nFields += grep(tensorFields_, fieldTypes);
if (Pstream::master())
{
if (debug)
{
Pout<< "timeName = " << mesh_.time().timeName() << nl
<< "scalarFields " << scalarFields_ << nl
<< "vectorFields " << vectorFields_ << nl
<< "sphTensorFields " << sphericalTensorFields_ << nl
<< "symTensorFields " << symmTensorFields_ <<nl
<< "tensorFields " << tensorFields_ <<nl;
}
if (nFields > 0)
{
if (debug)
{
Pout<< "Creating directory "
<< outputPath_/mesh_.time().timeName()
<< nl << endl;
}
mkDir(outputPath_/mesh_.time().timeName());
}
}
return nFields > 0;
}
void Foam::sampledSets::combineSampledSets void Foam::sampledSets::combineSampledSets
( (
PtrList<coordSet>& masterSampledSets, PtrList<coordSet>& masterSampledSets,
@ -147,9 +56,9 @@ void Foam::sampledSets::combineSampledSets
const PtrList<sampledSet>& sampledSets = *this; const PtrList<sampledSet>& sampledSets = *this;
forAll(sampledSets, seti) forAll(sampledSets, setI)
{ {
const sampledSet& samplePts = sampledSets[seti]; const sampledSet& samplePts = sampledSets[setI];
// Collect data from all processors // Collect data from all processors
List<List<point> > gatheredPts(Pstream::nProcs()); List<List<point> > gatheredPts(Pstream::nProcs());
@ -190,7 +99,7 @@ void Foam::sampledSets::combineSampledSets
// Sort curveDist and use to fill masterSamplePts // Sort curveDist and use to fill masterSamplePts
SortableList<scalar> sortedDist(allCurveDist); SortableList<scalar> sortedDist(allCurveDist);
indexSets[seti] = sortedDist.indices(); indexSets[setI] = sortedDist.indices();
// Get reference point (note: only master has all points) // Get reference point (note: only master has all points)
point refPt; point refPt;
@ -207,12 +116,12 @@ void Foam::sampledSets::combineSampledSets
masterSampledSets.set masterSampledSets.set
( (
seti, setI,
new coordSet new coordSet
( (
samplePts.name(), samplePts.name(),
samplePts.axis(), samplePts.axis(),
List<point>(UIndirectList<point>(allPts, indexSets[seti])), List<point>(UIndirectList<point>(allPts, indexSets[setI])),
refPt refPt
) )
); );
@ -236,7 +145,7 @@ Foam::sampledSets::sampledSets
loadFromFiles_(loadFromFiles), loadFromFiles_(loadFromFiles),
outputPath_(fileName::null), outputPath_(fileName::null),
searchEngine_(mesh_, true), searchEngine_(mesh_, true),
fieldNames_(), fieldSelection_(),
interpolationScheme_(word::null), interpolationScheme_(word::null),
writeFormat_(word::null) writeFormat_(word::null)
{ {
@ -285,7 +194,36 @@ void Foam::sampledSets::end()
void Foam::sampledSets::write() void Foam::sampledSets::write()
{ {
if (size() && checkFieldTypes()) if (size())
{
const label nFields = classifyFields();
if (Pstream::master())
{
if (debug)
{
Pout<< "timeName = " << mesh_.time().timeName() << nl
<< "scalarFields " << scalarFields_ << nl
<< "vectorFields " << vectorFields_ << nl
<< "sphTensorFields " << sphericalTensorFields_ << nl
<< "symTensorFields " << symmTensorFields_ <<nl
<< "tensorFields " << tensorFields_ <<nl;
}
if (nFields)
{
if (debug)
{
Pout<< "Creating directory "
<< outputPath_/mesh_.time().timeName()
<< nl << endl;
}
mkDir(outputPath_/mesh_.time().timeName());
}
}
if (nFields)
{ {
sampleAndWrite(scalarFields_); sampleAndWrite(scalarFields_);
sampleAndWrite(vectorFields_); sampleAndWrite(vectorFields_);
@ -293,26 +231,27 @@ void Foam::sampledSets::write()
sampleAndWrite(symmTensorFields_); sampleAndWrite(symmTensorFields_);
sampleAndWrite(tensorFields_); sampleAndWrite(tensorFields_);
} }
}
} }
void Foam::sampledSets::read(const dictionary& dict) void Foam::sampledSets::read(const dictionary& dict)
{ {
dict_ = dict; dict_ = dict;
dict_.lookup("fields") >> fieldSelection_;
clearFieldGroups();
fieldNames_ = wordList(dict_.lookup("fields")); interpolationScheme_ = dict.lookupOrDefault<word>
(
"interpolationScheme",
"cell"
);
writeFormat_ = dict.lookupOrDefault<word>
(
"setFormat",
"null"
);
interpolationScheme_ = "cell";
dict_.readIfPresent("interpolationScheme", interpolationScheme_);
writeFormat_ = "null";
dict_.readIfPresent("setFormat", writeFormat_);
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
PtrList<sampledSet> newList PtrList<sampledSet> newList
( (
@ -324,7 +263,7 @@ void Foam::sampledSets::read(const dictionary& dict)
if (Pstream::master() && debug) if (Pstream::master() && debug)
{ {
Pout<< "sample fields:" << fieldNames_ << nl Pout<< "sample fields:" << fieldSelection_ << nl
<< "sample sets:" << nl << "(" << nl; << "sample sets:" << nl << "(" << nl;
forAll(*this, si) forAll(*this, si)

View File

@ -43,6 +43,7 @@ SourceFiles
#include "interpolation.H" #include "interpolation.H"
#include "coordSet.H" #include "coordSet.H"
#include "writer.H" #include "writer.H"
#include "wordReList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -67,25 +68,40 @@ class sampledSets
template<class Type> template<class Type>
class fieldGroup class fieldGroup
: :
public wordList public DynamicList<word>
{ {
public: public:
//- Set formatter //- The set formatter
autoPtr<writer<Type> > formatter; autoPtr< writer<Type> > formatter;
//- Construct null //- Construct null
fieldGroup() fieldGroup()
: :
wordList(0), DynamicList<word>(0),
formatter(NULL) formatter(NULL)
{} {}
//- Construct for a particular format
fieldGroup(const word& writeFormat)
:
DynamicList<word>(0),
formatter(writer<Type>::New(writeFormat))
{}
//- Reset format and field list
void clear() void clear()
{ {
wordList::clear(); DynamicList<word>::clear();
formatter.clear(); formatter.clear();
} }
//- Assign a new formatter
void operator=(const word& writeFormat)
{
formatter = writer<Type>::New(writeFormat);
}
}; };
@ -161,7 +177,7 @@ class sampledSets
// Read from dictonary // Read from dictonary
//- Names of fields to sample //- Names of fields to sample
wordList fieldNames_; wordReList fieldSelection_;
//- Interpolation scheme to use //- Interpolation scheme to use
word interpolationScheme_; word interpolationScheme_;
@ -187,16 +203,14 @@ class sampledSets
// Private Member Functions // Private Member Functions
//- Classify field types, return true if nFields > 0 //- Clear old field groups
bool checkFieldTypes(); void clearFieldGroups();
//- Find the fields in the list of the given type, return count //- Append fieldName to the appropriate group
template<class Type> label appendFieldGroup(const word& fieldName, const word& fieldType);
label grep
( //- Classify field types, returns the number of fields
fieldGroup<Type>& fieldList, label classifyFields();
const wordList& fieldTypes
) const;
//- Combine points from all processors. Sort by curveDist and produce //- Combine points from all processors. Sort by curveDist and produce
// index list. Valid result only on master processor. // index list. Valid result only on master processor.

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 "sampledSets.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::sampledSets::clearFieldGroups()
{
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
}
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();
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

@ -46,10 +46,10 @@ Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
interpolation<Type>::New(interpolationScheme, field) interpolation<Type>::New(interpolationScheme, field)
); );
forAll(samplers, seti) forAll(samplers, setI)
{ {
Field<Type>& values = this->operator[](seti); Field<Type>& values = this->operator[](setI);
const sampledSet& samples = samplers[seti]; const sampledSet& samples = samplers[setI];
values.setSize(samples.size()); values.setSize(samples.size());
forAll(samples, samplei) forAll(samples, samplei)
@ -79,10 +79,10 @@ Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
List<Field<Type> >(samplers.size()), List<Field<Type> >(samplers.size()),
name_(field.name()) name_(field.name())
{ {
forAll(samplers, seti) forAll(samplers, setI)
{ {
Field<Type>& values = this->operator[](seti); Field<Type>& values = this->operator[](setI);
const sampledSet& samples = samplers[seti]; const sampledSet& samples = samplers[setI];
values.setSize(samples.size()); values.setSize(samples.size());
forAll(samples, samplei) forAll(samples, samplei)
@ -105,41 +105,12 @@ Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
{} {}
template<class Type>
Foam::label Foam::sampledSets::grep
(
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::sampledSets::writeSampleFile void Foam::sampledSets::writeSampleFile
( (
const coordSet& masterSampleSet, const coordSet& masterSampleSet,
const PtrList<volFieldSampler<Type> >& masterFields, const PtrList<volFieldSampler<Type> >& masterFields,
const label seti, const label setI,
const fileName& timeDir, const fileName& timeDir,
const writer<Type>& formatter const writer<Type>& formatter
) )
@ -150,7 +121,7 @@ void Foam::sampledSets::writeSampleFile
forAll(masterFields, fieldi) forAll(masterFields, fieldi)
{ {
valueSetNames[fieldi] = masterFields[fieldi].name(); valueSetNames[fieldi] = masterFields[fieldi].name();
valueSets[fieldi] = &masterFields[fieldi][seti]; valueSets[fieldi] = &masterFields[fieldi][setI];
} }
fileName fName fileName fName
@ -180,11 +151,11 @@ void Foam::sampledSets::combineSampledValues
{ {
List<Field<T> > masterValues(indexSets.size()); List<Field<T> > masterValues(indexSets.size());
forAll(indexSets, seti) forAll(indexSets, setI)
{ {
// Collect data from all processors // Collect data from all processors
List<Field<T> > gatheredData(Pstream::nProcs()); List<Field<T> > gatheredData(Pstream::nProcs());
gatheredData[Pstream::myProcNo()] = sampledFields[fieldi][seti]; gatheredData[Pstream::myProcNo()] = sampledFields[fieldi][setI];
Pstream::gatherList(gatheredData); Pstream::gatherList(gatheredData);
if (Pstream::master()) if (Pstream::master())
@ -198,10 +169,10 @@ void Foam::sampledSets::combineSampledValues
) )
); );
masterValues[seti] = UIndirectList<T> masterValues[setI] = UIndirectList<T>
( (
allData, allData,
indexSets[seti] indexSets[setI]
)(); )();
} }
} }
@ -232,7 +203,7 @@ void Foam::sampledSets::sampleAndWrite
// Create or use existing writer // Create or use existing writer
if (fields.formatter.empty()) if (fields.formatter.empty())
{ {
fields.formatter = writer<Type>::New(writeFormat_); fields = writeFormat_;
} }
// Storage for interpolated values // Storage for interpolated values
@ -326,13 +297,13 @@ void Foam::sampledSets::sampleAndWrite
if (Pstream::master()) if (Pstream::master())
{ {
forAll(masterSampledSets_, seti) forAll(masterSampledSets_, setI)
{ {
writeSampleFile writeSampleFile
( (
masterSampledSets_[seti], masterSampledSets_[setI],
masterFields, masterFields,
seti, setI,
outputPath_/mesh_.time().timeName(), outputPath_/mesh_.time().timeName(),
fields.formatter() fields.formatter()
); );

View File

@ -33,11 +33,12 @@ License
#include "mergePoints.H" #include "mergePoints.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
#include "IOobjectList.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::sampledSurfaces, 0);
bool Foam::sampledSurfaces::verbose_ = false;
Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
namespace Foam namespace Foam
{ {
//- Used to offset faces in Pstream::combineOffset //- Used to offset faces in Pstream::combineOffset
@ -63,102 +64,11 @@ namespace Foam
} }
}; };
defineTypeNameAndDebug(sampledSurfaces, 0);
} }
bool Foam::sampledSurfaces::verbose_(false);
Foam::scalar Foam::sampledSurfaces::mergeTol_(1e-10);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label Foam::sampledSurfaces::appendFieldType
(
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::sampledSurfaces::classifyFieldTypes()
{
label nFields = 0;
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
// check files for a particular time
if (loadFromFiles_)
{
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 += appendFieldType
(
fieldName,
objects.find(fieldName)()->headerClassName()
);
}
}
else
{
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(indices, fieldI)
{
const word& fieldName = allFields[indices[fieldI]];
nFields += appendFieldType
(
fieldName,
mesh_.find(fieldName)()->type()
);
}
}
return nFields;
}
void Foam::sampledSurfaces::writeGeometry() const void Foam::sampledSurfaces::writeGeometry() const
{ {
// Write to time directory under outputPath_ // Write to time directory under outputPath_
@ -269,7 +179,7 @@ void Foam::sampledSurfaces::write()
// finalize surfaces, merge points etc. // finalize surfaces, merge points etc.
update(); update();
const label nFields = classifyFieldTypes(); const label nFields = classifyFields();
if (Pstream::master()) if (Pstream::master())
{ {
@ -290,8 +200,8 @@ void Foam::sampledSurfaces::write()
mkDir(outputPath_/mesh_.time().timeName()); mkDir(outputPath_/mesh_.time().timeName());
} }
// write geometry first if required, or when no fields would otherwise // write geometry first if required,
// be written // or when no fields would otherwise be written
if (nFields == 0 || genericFormatter_->separateFiles()) if (nFields == 0 || genericFormatter_->separateFiles())
{ {
writeGeometry(); writeGeometry();
@ -309,15 +219,7 @@ void Foam::sampledSurfaces::write()
void Foam::sampledSurfaces::read(const dictionary& dict) void Foam::sampledSurfaces::read(const dictionary& dict)
{ {
dict.lookup("fields") >> fieldSelection_; dict.lookup("fields") >> fieldSelection_;
clearFieldGroups();
// might be okay for a size estimate, but we don't really know
const label nFields = fieldSelection_.size();
scalarFields_.reset(nFields);
vectorFields_.reset(nFields);
sphericalTensorFields_.reset(nFields);
symmTensorFields_.reset(nFields);
tensorFields_.reset(nFields);
interpolationScheme_ = dict.lookupOrDefault<word> interpolationScheme_ = dict.lookupOrDefault<word>
( (
@ -340,7 +242,6 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
dict.lookup("surfaces"), dict.lookup("surfaces"),
sampledSurface::iNew(mesh_) sampledSurface::iNew(mesh_)
); );
transfer(newList); transfer(newList);
if (Pstream::parRun()) if (Pstream::parRun())

View File

@ -69,7 +69,7 @@ class sampledSurfaces
{ {
public: public:
//- Surface formatter //- The surface formatter
autoPtr< surfaceWriter<Type> > formatter; autoPtr< surfaceWriter<Type> > formatter;
//- Construct null //- Construct null
@ -86,34 +86,19 @@ class sampledSurfaces
formatter(surfaceWriter<Type>::New(writeFormat)) formatter(surfaceWriter<Type>::New(writeFormat))
{} {}
//- Construct for a particular surface format and a list of field //- Reset format and field list
// names void clear()
fieldGroup
(
const word& writeFormat,
const wordList& fieldNames
)
:
DynamicList<word>(fieldNames),
formatter(surfaceWriter<Type>::New(writeFormat))
{}
void reset(const label nElem)
{ {
formatter.clear();
DynamicList<word>::reserve(nElem);
DynamicList<word>::clear(); DynamicList<word>::clear();
formatter.clear();
} }
//- Assign a new formatter
void operator=(const word& writeFormat) void operator=(const word& writeFormat)
{ {
formatter = surfaceWriter<Type>::New(writeFormat); formatter = surfaceWriter<Type>::New(writeFormat);
} }
void operator=(const wordList& fieldNames)
{
DynamicList<word>::operator=(fieldNames);
}
}; };
@ -192,11 +177,14 @@ class sampledSurfaces
// Private Member Functions // Private Member Functions
//- Clear old field groups
void clearFieldGroups();
//- Append fieldName to the appropriate group //- Append fieldName to the appropriate group
label appendFieldType(const word& fieldName, const word& fieldType); 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 classifyFieldTypes(); label classifyFields();
//- Write geometry only //- Write geometry only
void writeGeometry() const; void writeGeometry() const;

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 "sampledSurfaces.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::sampledSurfaces::clearFieldGroups()
{
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
}
Foam::label Foam::sampledSurfaces::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::sampledSurfaces::classifyFields()
{
label nFields = 0;
clearFieldGroups();
// check files for a particular time
if (loadFromFiles_)
{
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
{
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

@ -178,7 +178,7 @@ void Foam::sampledSurfaces::sampleAndWrite
if if
( (
iter != mesh_.objectRegistry::end() iter != objectRegistry::end()
&& iter()->type() && iter()->type()
== GeometricField<Type, fvPatchField, volMesh>::typeName == GeometricField<Type, fvPatchField, volMesh>::typeName
) )