From b09a19e0266b43edb0c16b1d1b3963a0c6e57a32 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Tue, 5 Apr 2011 20:54:18 +0100 Subject: [PATCH] ENH: sampledPatch: patchSet instead of single patch --- .../postProcessing/sampling/sample/sampleDict | 12 +- .../sampledPatch/sampledPatch.C | 124 +++++++++++++----- .../sampledPatch/sampledPatch.H | 60 +++++---- .../sampledPatch/sampledPatchTemplates.C | 59 ++++----- .../sampledPatchInternalField.C | 34 +++-- .../sampledPatchInternalField.H | 10 +- .../sampledPatchInternalFieldTemplates.C | 73 +++++++---- .../pisoFoam/les/pitzDaily/system/controlDict | 2 +- .../pitzDailyDirectMapped/system/controlDict | 2 +- .../ras/sloshingTank2D/system/controlDict | 2 +- .../ras/sloshingTank2D3DoF/system/controlDict | 2 +- 11 files changed, 248 insertions(+), 132 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index c34ce71daf9..b983a35a11f 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -150,29 +150,29 @@ surfaces interpolate true; } - movingWall_constant + walls_constant { type patch; - patchName movingWall; + patches ( ".*Wall.*" ); // Optional: whether to leave as faces (=default) or triangulate // triangulate false; } - movingWall_interpolated + walls_interpolated { type patch; - patchName movingWall; + patches ( ".*Wall.*" ); interpolate true; // Optional: whether to leave as faces (=default) or triangulate // triangulate false; } - movingNearWall_interpolated + nearWalls_interpolated { // Sample cell values off patch. Does not need to be the near-wall // cell, can be arbitrarily far away. type patchInternalField; - patchName movingWall; + patches ( ".*Wall.*" ); distance 0.0001; interpolate true; // Optional: whether to leave as faces (=default) or triangulate diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C index 97ca76f68cd..6f180dcd863 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -46,15 +46,14 @@ Foam::sampledPatch::sampledPatch ( const word& name, const polyMesh& mesh, - const word& patchName, + const wordReList& patchNames, const bool triangulate ) : sampledSurface(name, mesh), - patchName_(patchName), + patchNames_(patchNames), triangulate_(triangulate), - needsUpdate_(true), - patchFaceLabels_(0) + needsUpdate_(true) {} @@ -66,10 +65,9 @@ Foam::sampledPatch::sampledPatch ) : sampledSurface(name, mesh, dict), - patchName_(dict.lookup("patchName")), + patchNames_(dict.lookup("patches")), triangulate_(dict.lookupOrDefault("triangulate", false)), - needsUpdate_(true), - patchFaceLabels_(0) + needsUpdate_(true) {} @@ -81,6 +79,20 @@ Foam::sampledPatch::~sampledPatch() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::labelList& Foam::sampledPatch::patchIDs() const +{ + if (patchIDs_.empty()) + { + patchIDs_ = mesh().boundaryMesh().patchSet + ( + patchNames_, + false + ).sortedToc(); + } + return patchIDs_; +} + + bool Foam::sampledPatch::needsUpdate() const { return needsUpdate_; @@ -97,7 +109,10 @@ bool Foam::sampledPatch::expire() sampledSurface::clearGeom(); MeshStorage::clear(); + patchIDs_.clear(); + patchIndex_.clear(); patchFaceLabels_.clear(); + patchStart_.clear(); needsUpdate_ = true; return true; @@ -111,31 +126,67 @@ bool Foam::sampledPatch::update() return false; } - const label patchI = mesh().boundaryMesh().findPatchID(patchName_); - - if (patchI != -1) + label sz = 0; + forAll(patchIDs(), i) { - const polyPatch& p = mesh().boundaryMesh()[patchI]; - this->storedPoints() = p.localPoints(); - this->storedFaces() = p.localFaces(); + label patchI = patchIDs()[i]; + const polyPatch& pp = mesh().boundaryMesh()[patchI]; - // an identity map - patchFaceLabels_.setSize(faces().size()); - forAll(patchFaceLabels_, i) + if (isA<emptyPolyPatch>(pp)) { - patchFaceLabels_[i] = i; + FatalErrorIn("sampledPatch::update()") + << "Cannot sample an empty patch. Patch " << pp.name() + << exit(FatalError); } - // triangulate uses remapFaces() - // - this is somewhat less efficient since it recopies the faces - // that we just created, but we probably don't want to do this - // too often anyhow. - if (triangulate_) + sz += pp.size(); + } + + // For every face (or triangle) the originating patch and local face in the + // patch. + patchIndex_.setSize(sz); + patchFaceLabels_.setSize(sz); + patchStart_.setSize(patchIDs().size()); + labelList meshFaceLabels(sz); + + sz = 0; + + forAll(patchIDs(), i) + { + label patchI = patchIDs()[i]; + + patchStart_[i] = sz; + + const polyPatch& pp = mesh().boundaryMesh()[patchI]; + + forAll(pp, j) { - MeshStorage::triangulate(); + patchIndex_[sz] = i; + patchFaceLabels_[sz] = j; + meshFaceLabels[sz] = pp.start()+j; + sz++; } } + indirectPrimitivePatch allPatches + ( + IndirectList<face>(mesh().faces(), meshFaceLabels), + mesh().points() + ); + + this->storedPoints() = allPatches.localPoints(); + this->storedFaces() = allPatches.localFaces(); + + + // triangulate uses remapFaces() + // - this is somewhat less efficient since it recopies the faces + // that we just created, but we probably don't want to do this + // too often anyhow. + if (triangulate_) + { + MeshStorage::triangulate(); + } + if (debug) { print(Pout); @@ -148,10 +199,7 @@ bool Foam::sampledPatch::update() // remap action on triangulation -void Foam::sampledPatch::remapFaces -( - const labelUList& faceMap -) +void Foam::sampledPatch::remapFaces(const labelUList& faceMap) { // recalculate the cells cut if (&faceMap && faceMap.size()) @@ -161,11 +209,27 @@ void Foam::sampledPatch::remapFaces ( UIndirectList<label>(patchFaceLabels_, faceMap) ); + patchIndex_ = labelList + ( + UIndirectList<label>(patchIndex_, faceMap) + ); + + // Redo patchStart. + if (patchIndex_.size() > 0) + { + patchStart_[patchIndex_[0]] = 0; + for (label i = 1; i < patchIndex_.size(); i++) + { + if (patchIndex_[i] != patchIndex_[i-1]) + { + patchStart_[patchIndex_[i]] = i; + } + } + } } } - Foam::tmp<Foam::scalarField> Foam::sampledPatch::sample ( const volScalarField& vField @@ -257,7 +321,7 @@ Foam::tmp<Foam::tensorField> Foam::sampledPatch::interpolate void Foam::sampledPatch::print(Ostream& os) const { os << "sampledPatch: " << name() << " :" - << " patch:" << patchName() + << " patches:" << patchNames() << " faces:" << faces().size() << " points:" << points().size(); } diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H index ed292055692..672b09c2068 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ Class Foam::sampledPatch Description - A sampledSurface on a patch. Non-triangulated by default. + A sampledSurface on patches. Non-triangulated by default. SourceFiles sampledPatch.C @@ -57,8 +57,11 @@ class sampledPatch // Private data - //- Name of patch - const word patchName_; + //- Name of patches + const wordReList patchNames_; + + //- Corresponding patchIDs + mutable labelList patchIDs_; //- Triangulated faces or keep faces as is bool triangulate_; @@ -66,11 +69,16 @@ class sampledPatch //- Track if the surface needs an update mutable bool needsUpdate_; - //- Local patch face labels + //- For every face (or triangle) the originating patch + labelList patchIndex_; + + //- For every face (or triangle) the index in the originating patch labelList patchFaceLabels_; - // Private Member Functions + //- Start indices (in patchFaceLabels_) of patches + labelList patchStart_; + // Private Member Functions //- sample field on faces template <class Type> @@ -79,15 +87,34 @@ class sampledPatch const GeometricField<Type, fvPatchField, volMesh>& vField ) const; - template <class Type> tmp<Field<Type> > interpolateField(const interpolation<Type>&) const; - //- remap action on triangulation or cleanup virtual void remapFaces(const labelUList& faceMap); + +protected: + + const wordReList& patchNames() const + { + return patchNames_; + } + + const labelList& patchIDs() const; + + const labelList& patchStart() const + { + return patchStart_; + } + + const labelList& patchFaceLabels() const + { + return patchFaceLabels_; + } + + public: //- Runtime type information @@ -101,7 +128,7 @@ public: ( const word& name, const polyMesh& mesh, - const word& patchName, + const wordReList& patchNames, const bool triangulate = false ); @@ -133,21 +160,6 @@ public: virtual bool update(); - const word patchName() const - { - return patchName_; - } - - label patchIndex() const - { - return mesh().boundaryMesh().findPatchID(patchName_); - } - - const labelList& patchFaceLabels() const - { - return patchFaceLabels_; - } - //- Points of surface virtual const pointField& points() const { diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C index 35d92ec9ddb..a46309cce73 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,15 +37,11 @@ Foam::sampledPatch::sampleField // One value per face tmp<Field<Type> > tvalues(new Field<Type>(patchFaceLabels_.size())); Field<Type>& values = tvalues(); - - if (patchIndex() != -1) + forAll(patchFaceLabels_, i) { - const Field<Type>& bField = vField.boundaryField()[patchIndex()]; - - forAll(patchFaceLabels_, elemI) - { - values[elemI] = bField[patchFaceLabels_[elemI]]; - } + label patchI = patchIDs_[patchIndex_[i]]; + const Field<Type>& bField = vField.boundaryField()[patchI]; + values[i] = bField[patchFaceLabels_[i]]; } return tvalues; @@ -63,34 +59,33 @@ Foam::sampledPatch::interpolateField tmp<Field<Type> > tvalues(new Field<Type>(points().size())); Field<Type>& values = tvalues(); - if (patchIndex() != -1) - { - const polyPatch& patch = mesh().boundaryMesh()[patchIndex()]; - const labelList& own = mesh().faceOwner(); + const labelList& own = mesh().faceOwner(); + + boolList pointDone(points().size(), false); - boolList pointDone(points().size(), false); + forAll(faces(), cutFaceI) + { + label patchI = patchIDs_[patchIndex_[cutFaceI]]; + const polyPatch& pp = mesh().boundaryMesh()[patchI]; + label patchFaceI = patchFaceLabels()[cutFaceI]; + const face& f = faces()[cutFaceI]; - forAll(faces(), cutFaceI) + forAll(f, faceVertI) { - const face& f = faces()[cutFaceI]; + label pointI = f[faceVertI]; - forAll(f, faceVertI) + if (!pointDone[pointI]) { - label pointI = f[faceVertI]; - - if (!pointDone[pointI]) - { - label faceI = patchFaceLabels()[cutFaceI] + patch.start(); - label cellI = own[faceI]; - - values[pointI] = interpolator.interpolate - ( - points()[pointI], - cellI, - faceI - ); - pointDone[pointI] = true; - } + label faceI = patchFaceI + pp.start(); + label cellI = own[faceI]; + + values[pointI] = interpolator.interpolate + ( + points()[pointI], + cellI, + faceI + ); + pointDone[pointI] = true; } } } diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C index f97a78891c0..24a102bf22a 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -56,15 +56,27 @@ Foam::sampledPatchInternalField::sampledPatchInternalField ) : sampledPatch(name, mesh, dict), - directMappedPatchBase - ( - mesh.boundaryMesh()[sampledPatch::patchIndex()], - mesh.name(), // sampleRegion - directMappedPatchBase::NEARESTCELL, // sampleMode - word::null, // samplePatch - -readScalar(dict.lookup("distance")) - ) -{} + mappers_(patchIDs().size()) +{ + const scalar distance = readScalar(dict.lookup("distance")); + + forAll(patchIDs(), i) + { + label patchI = patchIDs()[i]; + mappers_.set + ( + i, + new directMappedPatchBase + ( + mesh.boundaryMesh()[patchI], + mesh.name(), // sampleRegion + directMappedPatchBase::NEARESTCELL, // sampleMode + word::null, // samplePatch + -distance // sample inside my domain + ) + ); + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -167,7 +179,7 @@ Foam::tmp<Foam::tensorField> Foam::sampledPatchInternalField::interpolate void Foam::sampledPatchInternalField::print(Ostream& os) const { os << "sampledPatchInternalField: " << name() << " :" - << " patch:" << patchName() + << " patches:" << patchNames() << " faces:" << faces().size() << " points:" << points().size(); } diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H index 53178239c82..90488d62388 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,9 +54,13 @@ namespace Foam class sampledPatchInternalField : - public sampledPatch, - public directMappedPatchBase + public sampledPatch { + // Private data + + //- Mapping engines + PtrList<directMappedPatchBase> mappers_; + // Private Member Functions diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C index 1c27cae1293..b9faafec3ce 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,20 +36,27 @@ Foam::sampledPatchInternalField::sampleField const GeometricField<Type, fvPatchField, volMesh>& vField ) const { - const mapDistribute& distMap = map(); - // One value per face tmp<Field<Type> > tvalues(new Field<Type>(patchFaceLabels().size())); Field<Type>& values = tvalues(); - if (patchIndex() != -1) + forAll(patchStart(), i) { + // Get patchface wise data by sampling internal field Field<Type> interpVals = vField.internalField(); - distMap.distribute(interpVals); + mappers_[i].map().distribute(interpVals); + + // Store at correct position in values + label end = + ( + i < patchStart().size()-1 + ? patchStart()[i+1] + : patchFaceLabels().size() + ); - forAll(patchFaceLabels(), elemI) + for (label triI = patchStart()[i]; triI < end; triI++) { - values[elemI] = interpVals[patchFaceLabels()[elemI]]; + values[triI] = interpVals[patchFaceLabels()[triI]]; } } @@ -64,19 +71,24 @@ Foam::sampledPatchInternalField::interpolateField const interpolation<Type>& interpolator ) const { - // One value per vertex + label sz = 0; + forAll(patchIDs(), i) + { + sz += mesh().boundaryMesh()[patchIDs()[i]].size(); + } + + Field<Type> allPatchVals(sz); + sz = 0; - if (patchIndex() != -1) + forAll(patchIDs(), i) { // See directMappedFixedValueFvPatchField - const mapDistribute& distMap = map(); - - const polyPatch& pp = mesh().boundaryMesh()[patchIndex()]; + const mapDistribute& distMap = mappers_[i].map(); // Send back sample points to processor that holds the cell. // Mark cells with point::max so we know which ones we need // to interpolate (since expensive). - vectorField samples(samplePoints()); + vectorField samples(mappers_[i].samplePoints()); distMap.reverseDistribute(mesh().nCells(), point::max, samples); Field<Type> patchVals(mesh().nCells()); @@ -96,18 +108,35 @@ Foam::sampledPatchInternalField::interpolateField distMap.distribute(patchVals); // Now patchVals holds the interpolated data in patch face order. - // Interpolate to points. Note: points are patch.localPoints() so - // can use standard interpolation - - return PrimitivePatchInterpolation<primitivePatch> - ( - pp - ).faceToPointInterpolate(patchVals); + // Collect. + SubList<Type>(allPatchVals, patchVals.size(), sz).assign(patchVals); + sz += patchVals.size(); } - else + + // Interpolate to points. Reconstruct the patch of all faces to aid + // interpolation. + + labelList meshFaceLabels(allPatchVals.size()); + sz = 0; + forAll(patchIDs(), i) { - return tmp<Field<Type> >(new Field<Type>(points().size())); + const polyPatch& pp = mesh().boundaryMesh()[patchIDs()[i]]; + forAll(pp, i) + { + meshFaceLabels[sz++] = pp.start()+i; + } } + + indirectPrimitivePatch allPatches + ( + IndirectList<face>(mesh().faces(), meshFaceLabels), + mesh().points() + ); + + return PrimitivePatchInterpolation<indirectPrimitivePatch> + ( + allPatches + ).faceToPointInterpolate(allPatchVals); } diff --git a/tutorials/incompressible/pisoFoam/les/pitzDaily/system/controlDict b/tutorials/incompressible/pisoFoam/les/pitzDaily/system/controlDict index c09d6b3c9b6..fa1f1897409 100644 --- a/tutorials/incompressible/pisoFoam/les/pitzDaily/system/controlDict +++ b/tutorials/incompressible/pisoFoam/les/pitzDaily/system/controlDict @@ -124,7 +124,7 @@ functions nearWall { type patchInternalField; - patchName lowerWall; + patches ( lowerWall ); distance 1E-6; interpolate true; triangulate false; diff --git a/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/system/controlDict b/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/system/controlDict index c09d6b3c9b6..fa1f1897409 100644 --- a/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/system/controlDict +++ b/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/system/controlDict @@ -124,7 +124,7 @@ functions nearWall { type patchInternalField; - patchName lowerWall; + patches ( lowerWall ); distance 1E-6; interpolate true; triangulate false; diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/system/controlDict b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/system/controlDict index 02ec76f28a8..f705cefe807 100644 --- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/system/controlDict +++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/system/controlDict @@ -89,7 +89,7 @@ functions walls { type patch; - patchName walls; + patches (walls); triangulate false; } ); diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/system/controlDict b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/system/controlDict index c703fff253a..09fc5039bc2 100644 --- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/system/controlDict +++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/system/controlDict @@ -88,7 +88,7 @@ functions walls { type patch; - patchName walls; + patches (walls); triangulate false; } ); -- GitLab