From fd6f81bbf3b914aedeb211bb2d3f03120f8315d0 Mon Sep 17 00:00:00 2001 From: sergio Date: Tue, 7 Aug 2012 14:23:55 +0100 Subject: [PATCH] ENH: Adding surfaceFields sampling to sampledPatch --- .../sampledPatch/sampledPatch.C | 44 ++++ .../sampledPatch/sampledPatch.H | 36 +++ .../sampledPatch/sampledPatchTemplates.C | 21 ++ .../sampledSurface/sampledSurface.C | 49 ++++ .../sampledSurface/sampledSurface.H | 31 +++ .../sampledSurfaces/sampledSurfaces.C | 32 ++- .../sampledSurfaces/sampledSurfaces.H | 48 ++-- .../sampledSurfaces/sampledSurfacesGrouping.C | 78 +----- .../sampledSurfacesTemplates.C | 227 ++++++++++-------- 9 files changed, 343 insertions(+), 223 deletions(-) diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C index 1f8eaf9e1b..da2d90c9fa 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C @@ -28,6 +28,7 @@ License #include "polyMesh.H" #include "polyPatch.H" #include "volFields.H" +#include "surfaceFields.H" #include "addToRunTimeSelectionTable.H" @@ -274,6 +275,49 @@ Foam::tmp Foam::sampledPatch::sample } +Foam::tmp Foam::sampledPatch::sample +( + const surfaceScalarField& sField +) const +{ + return sampleField(sField); +} + + +Foam::tmp Foam::sampledPatch::sample +( + const surfaceVectorField& sField +) const +{ + return sampleField(sField); +} + +Foam::tmp Foam::sampledPatch::sample +( + const surfaceSphericalTensorField& sField +) const +{ + return sampleField(sField); +} + + +Foam::tmp Foam::sampledPatch::sample +( + const surfaceSymmTensorField& sField +) const +{ + return sampleField(sField); +} + + +Foam::tmp Foam::sampledPatch::sample +( + const surfaceTensorField& sField +) const +{ + return sampleField(sField); +} + Foam::tmp Foam::sampledPatch::interpolate ( const interpolation& interpolator diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H index 36590a747a..0ec8dbd89f 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H @@ -87,6 +87,13 @@ class sampledPatch const GeometricField& vField ) const; + //- sample surface field on faces + template + tmp > sampleField + ( + const GeometricField& sField + ) const; + template tmp > interpolateField(const interpolation&) const; @@ -203,6 +210,35 @@ public: const volTensorField& ) const; + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceScalarField& + ) const; + + //- Surface Sample field on surface + virtual tmp sample + ( + const surfaceVectorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceSphericalTensorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceSymmTensorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceTensorField& + ) const; //- interpolate field on surface virtual tmp interpolate diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C index 47b31e97c2..8725f412be 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C @@ -48,6 +48,27 @@ Foam::sampledPatch::sampleField } +template +Foam::tmp > +Foam::sampledPatch::sampleField +( + const GeometricField& sField +) const +{ + // One value per face + tmp > tvalues(new Field(patchFaceLabels_.size())); + Field& values = tvalues(); + + forAll(patchFaceLabels_, i) + { + label patchI = patchIDs_[patchIndex_[i]]; + values[i] = sField.boundaryField()[patchI][patchFaceLabels_[i]]; + } + + return tvalues; +} + + template Foam::tmp > Foam::sampledPatch::interpolateField diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index 5c7c5abb90..aaca4f087c 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C @@ -240,6 +240,55 @@ Foam::scalar Foam::sampledSurface::area() const } +Foam::tmp Foam::sampledSurface::sample +( + const surfaceScalarField& sField +) const +{ + notImplemented("tmp sampledSurface::sample"); + return tmp(NULL); +} + + +Foam::tmp Foam::sampledSurface::sample +( + const surfaceVectorField& sField +) const +{ + notImplemented("tmp sampledSurface::sample"); + return tmp(NULL); +} + +Foam::tmp Foam::sampledSurface::sample +( + const surfaceSphericalTensorField& sField +) const +{ + notImplemented("tmp sampledSurface::sample"); + return tmp(NULL); +} + + +Foam::tmp Foam::sampledSurface::sample +( + const surfaceSymmTensorField& sField +) const +{ + notImplemented("tmp sampledSurface::sample"); + return tmp(NULL); +} + + +Foam::tmp Foam::sampledSurface::sample +( + const surfaceTensorField& sField +) const +{ + notImplemented("tmp sampledSurface::sample"); + return tmp(NULL); +} + + Foam::tmp > Foam::sampledSurface::project(const Field& field) const { diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index 9843143107..7ef9654ebd 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -57,6 +57,8 @@ SourceFiles #include "runTimeSelectionTables.H" #include "autoPtr.H" #include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" +#include "surfaceMesh.H" #include "polyMesh.H" #include "coordinateSystems.H" #include "interpolation.H" @@ -352,6 +354,35 @@ public: const volTensorField& ) const = 0; + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceScalarField& + ) const; + + //- Surface Sample field on surface + virtual tmp sample + ( + const surfaceVectorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceSphericalTensorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceSymmTensorField& + ) const; + + //- Surface sample field on surface + virtual tmp sample + ( + const surfaceTensorField& + ) const; //- Interpolate field on surface virtual tmp interpolate diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index a8dfaebdfc..5fedecbd56 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -95,12 +95,7 @@ Foam::sampledSurfaces::sampledSurfaces fieldSelection_(), interpolationScheme_(word::null), mergeList_(), - formatter_(NULL), - scalarFields_(), - vectorFields_(), - sphericalTensorFields_(), - symmTensorFields_(), - tensorFields_() + formatter_(NULL) { if (Pstream::parRun()) { @@ -154,13 +149,6 @@ void Foam::sampledSurfaces::write() { if (debug) { - Pout<< "timeName = " << mesh_.time().timeName() << nl - << "scalarFields " << scalarFields_ << nl - << "vectorFields " << vectorFields_ << nl - << "sphTensorFields " << sphericalTensorFields_ << nl - << "symTensorFields " << symmTensorFields_ <(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); } } diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 0904c92ef0..ff676d1f99 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -40,7 +40,9 @@ SourceFiles #include "sampledSurface.H" #include "surfaceWriter.H" #include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" #include "wordReList.H" +#include "IOobjectList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -60,21 +62,6 @@ class sampledSurfaces { // Private classes - //- Class used for grouping field types - template - class fieldGroup - : - public DynamicList - { - public: - - //- Construct null - fieldGroup() - : - DynamicList(0) - {} - }; - //- Class used for surface merging information class mergeInfo @@ -137,13 +124,6 @@ class sampledSurfaces //- Surface formatter autoPtr formatter_; - //- Categorized scalar/vector/tensor fields - fieldGroup scalarFields_; - fieldGroup vectorFields_; - fieldGroup sphericalTensorFields_; - fieldGroup symmTensorFields_; - fieldGroup tensorFields_; - // Private Member Functions @@ -159,13 +139,33 @@ class sampledSurfaces //- Write geometry only void writeGeometry() const; + //- Write sampled fieldName on surface and on outputDir path + template + void writeSurface + ( + const Field& values, + const label surfI, + const word& fieldName, + const fileName& outputDir + ); + //- Sample and write a particular volume field template - void sampleAndWrite(const GeometricField&); + void sampleAndWrite + ( + const GeometricField& + ); + + //- Sample and write a particular surface field + template + void sampleAndWrite + ( + const GeometricField& + ); //- Sample and write all the fields of the given type template - void sampleAndWrite(fieldGroup&); + void sampleAndWrite(const IOobjectList& allObjects); //- Disallow default bitwise copy construct and assignment sampledSurfaces(const sampledSurfaces&); diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C index 0dda16b180..6e67008de3 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C @@ -30,94 +30,22 @@ License // * * * * * * * * * * * * * 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 + // 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() - ); - } + return indices.size(); } 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 indices.size(); } - - return nFields; } diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 78d7808d7a..a56fcadf79 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -25,10 +25,86 @@ License #include "sampledSurfaces.H" #include "volFields.H" +#include "surfaceFields.H" #include "ListListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +template +void Foam::sampledSurfaces::writeSurface +( + const Field& values, + const label surfI, + const word& fieldName, + const fileName& outputDir +) +{ + const sampledSurface& s = operator[](surfI); + + if (Pstream::parRun()) + { + // Collect values from all processors + List > gatheredValues(Pstream::nProcs()); + gatheredValues[Pstream::myProcNo()] = values; + Pstream::gatherList(gatheredValues); + + if (Pstream::master()) + { + // Combine values into single field + Field allValues + ( + ListListOps::combine > + ( + gatheredValues, + accessOp >() + ) + ); + + // Renumber (point data) to correspond to merged points + if (mergeList_[surfI].pointsMap.size() == allValues.size()) + { + inplaceReorder(mergeList_[surfI].pointsMap, allValues); + allValues.setSize(mergeList_[surfI].points.size()); + } + + // Write to time directory under outputPath_ + // skip surface without faces (eg, a failed cut-plane) + if (mergeList_[surfI].faces.size()) + { + formatter_->write + ( + outputDir, + s.name(), + mergeList_[surfI].points, + mergeList_[surfI].faces, + fieldName, + allValues, + s.interpolate() + ); + } + } + } + else + { + // Write to time directory under outputPath_ + // skip surface without faces (eg, a failed cut-plane) + if (s.faces().size()) + { + formatter_->write + ( + outputDir, + s.name(), + s.points(), + s.faces(), + fieldName, + values, + s.interpolate() + ); + } + } +} + + template void Foam::sampledSurfaces::sampleAndWrite ( @@ -65,125 +141,64 @@ void Foam::sampledSurfaces::sampleAndWrite values = s.sample(vField); } - if (Pstream::parRun()) - { - // Collect values from all processors - List > gatheredValues(Pstream::nProcs()); - gatheredValues[Pstream::myProcNo()] = values; - Pstream::gatherList(gatheredValues); - - if (Pstream::master()) - { - // Combine values into single field - Field allValues - ( - ListListOps::combine > - ( - gatheredValues, - accessOp >() - ) - ); - - // Renumber (point data) to correspond to merged points - if (mergeList_[surfI].pointsMap.size() == allValues.size()) - { - inplaceReorder(mergeList_[surfI].pointsMap, allValues); - allValues.setSize(mergeList_[surfI].points.size()); - } - - // Write to time directory under outputPath_ - // skip surface without faces (eg, a failed cut-plane) - if (mergeList_[surfI].faces.size()) - { - formatter_->write - ( - outputDir, - s.name(), - mergeList_[surfI].points, - mergeList_[surfI].faces, - fieldName, - allValues, - s.interpolate() - ); - } - } - } - else - { - // Write to time directory under outputPath_ - // skip surface without faces (eg, a failed cut-plane) - if (s.faces().size()) - { - formatter_->write - ( - outputDir, - s.name(), - s.points(), - s.faces(), - fieldName, - values, - s.interpolate() - ); - } - } + writeSurface(values, surfI, fieldName, outputDir); } } + template void Foam::sampledSurfaces::sampleAndWrite ( - fieldGroup& fields + const GeometricField& sField ) { - if (fields.size()) + const word& fieldName = sField.name(); + const fileName outputDir = outputPath_/sField.time().timeName(); + + forAll(*this, surfI) { - forAll(fields, fieldI) + const sampledSurface& s = operator[](surfI); + Field values = s.sample(sField); + writeSurface(values, surfI, fieldName, outputDir); + } +} + + +template +void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& allObjects) +{ + IOobjectList fields = allObjects.lookupClass(GeoField::typeName); + forAllConstIter(IOobjectList, fields, fieldIter) + { + forAll (fieldSelection_, fieldI) { - if (Pstream::master() && verbose_) + const wordRe field = fieldSelection_[fieldI]; + if (field.match(fieldIter()->name())) { - Pout<< "sampleAndWrite: " << fields[fieldI] << endl; - } - - if (loadFromFiles_) - { - sampleAndWrite - ( - GeometricField - ( - IOobject - ( - fields[fieldI], - mesh_.time().timeName(), - mesh_, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ), - mesh_ - ) - ); - } - else - { - objectRegistry::const_iterator iter = - mesh_.find(fields[fieldI]); - - if - ( - iter != objectRegistry::end() - && iter()->type() - == GeometricField::typeName - ) + if (Pstream::master() && verbose_) { - sampleAndWrite - ( - mesh_.lookupObject - > - ( - fields[fieldI] - ) - ); + Pout<< "sampleAndWrite: " << field << endl; + } + + if (loadFromFiles_) + { + fieldIter()->readOpt() = IOobject::MUST_READ; + sampleAndWrite + ( + GeoField + ( + *fieldIter(), + mesh_ + ) + ); + } + else + { + sampleAndWrite + ( + mesh_.lookupObject(fieldIter()->name()) + ); } } }