From cf8ad3d9364b76e413d4e534fa908b83efd43bc9 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 15 Nov 2011 10:29:59 +0000 Subject: [PATCH] ENH: cyclicAMI: handle FaceCellWave (e.g. wall distance) --- src/OpenFOAM/Make/files | 3 - .../polyPatches/polyPatch/polyPatch.H | 2 +- .../AMIInterpolation/AMIInterpolation.C | 258 +++++++------ .../AMIInterpolation/AMIInterpolation.H | 29 +- .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.H | 9 + .../cyclicAMIPolyPatchTemplates.C | 19 + src/meshTools/Make/files | 11 +- .../algorithms/MeshWave/FaceCellWave.C | 342 +++++++++++++----- .../algorithms/MeshWave/FaceCellWave.H | 11 +- .../algorithms/MeshWave/FaceCellWaveName.C | 0 .../algorithms/MeshWave/MeshWave.C | 0 .../algorithms/MeshWave/MeshWave.H | 0 .../algorithms/MeshWave/MeshWaveName.C | 0 .../PatchEdgeFaceWave/PatchEdgeFaceWave.C | 0 .../PatchEdgeFaceWave/PatchEdgeFaceWave.H | 0 .../PatchEdgeFaceWave/PatchEdgeFaceWaveName.C | 0 .../PatchEdgeFaceWave/patchEdgeFaceInfo.C | 0 .../PatchEdgeFaceWave/patchEdgeFaceInfo.H | 0 .../PatchEdgeFaceWave/patchEdgeFaceInfoI.H | 0 .../PointEdgeWave/PointEdgeWave.C | 0 .../PointEdgeWave/PointEdgeWave.H | 0 .../PointEdgeWave/PointEdgeWaveName.C | 0 .../PointEdgeWave/pointEdgePoint.C | 0 .../PointEdgeWave/pointEdgePoint.H | 0 .../PointEdgeWave/pointEdgePointI.H | 0 25 files changed, 479 insertions(+), 205 deletions(-) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/FaceCellWave.C (77%) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/FaceCellWave.H (97%) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/FaceCellWaveName.C (100%) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/MeshWave.C (100%) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/MeshWave.H (100%) rename src/{OpenFOAM => meshTools}/algorithms/MeshWave/MeshWaveName.C (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/PatchEdgeFaceWave.C (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/PatchEdgeFaceWave.H (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/PatchEdgeFaceWaveName.C (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/patchEdgeFaceInfo.C (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/patchEdgeFaceInfo.H (100%) rename src/meshTools/{ => algorithms}/PatchEdgeFaceWave/patchEdgeFaceInfoI.H (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/PointEdgeWave.C (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/PointEdgeWave.H (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/PointEdgeWaveName.C (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/pointEdgePoint.C (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/pointEdgePoint.H (100%) rename src/meshTools/{ => algorithms}/PointEdgeWave/pointEdgePointI.H (100%) diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 6e169d64bc..da569b2e21 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -577,9 +577,6 @@ $(interpolations)/interpolationTable/tableReaders/tableReaders.C $(interpolations)/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C $(interpolations)/interpolationTable/tableReaders/csv/csvTableReaders.C -algorithms/MeshWave/MeshWaveName.C -algorithms/MeshWave/FaceCellWaveName.C - algorithms/indexedOctree/indexedOctreeName.C algorithms/indexedOctree/treeDataCell.C diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H index 5601c1e993..0fa859bddb 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H @@ -300,7 +300,7 @@ public: //- Slice list to patch template - const typename List::subList patchSlice(const List& l) const + const typename List::subList patchSlice(const UList& l) const { return typename List::subList(l, this->size(), start_); } diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index a0965ff941..cae738707d 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -30,6 +30,37 @@ License #include "mergePoints.H" #include "mapDistribute.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + //- Combine operator for interpolateToSource/Target + template + class combineBinaryOp + { + const BinaryOp& bop_; + + public: + + combineBinaryOp(const BinaryOp& bop) + : + bop_(bop) + {} + + void operator() + ( + Type& x, + const label faceI, + const Type& y, + const scalar weight + ) const + { + x = bop_(x, weight*y); + } + }; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template @@ -1773,94 +1804,12 @@ void Foam::AMIInterpolation::update template -template -Foam::tmp > -Foam::AMIInterpolation::interpolateToSource +template +void Foam::AMIInterpolation::interpolateToTarget ( - const Field& fld, - const BinaryOp& bop -) const -{ - if (fld.size() != tgtAddress_.size()) - { - FatalErrorIn - ( - "AMIInterpolation::interpolateToSource(const Field) const" - ) << "Supplied field size is not equal to target patch size" << nl - << " source patch = " << srcAddress_.size() << nl - << " target patch = " << tgtAddress_.size() << nl - << " supplied field = " << fld.size() - << abort(FatalError); - } - - tmp > tresult - ( - new Field - ( - srcAddress_.size(), - pTraits::zero - ) - ); - - Field& result = tresult(); - - if (singlePatchProc_ == -1) - { - const mapDistribute& map = tgtMapPtr_(); - - Field work(fld); - map.distribute(work); - - forAll(result, faceI) - { - const labelList& faces = srcAddress_[faceI]; - const scalarList& weights = srcWeights_[faceI]; - - forAll(faces, i) - { - result[faceI] = bop(result[faceI], work[faces[i]]*weights[i]); - } - } - } - else - { - forAll(result, faceI) - { - const labelList& faces = srcAddress_[faceI]; - const scalarList& weights = srcWeights_[faceI]; - - forAll(faces, i) - { - result[faceI] = bop(result[faceI], fld[faces[i]]*weights[i]); - } - } - } - - return tresult; -} - - -template -template -Foam::tmp > -Foam::AMIInterpolation::interpolateToSource -( - const tmp >& tFld, - const BinaryOp& bop -) const -{ - return interpolateToSource(tFld(), bop); -} - - - -template -template -Foam::tmp > -Foam::AMIInterpolation::interpolateToTarget -( - const Field& fld, - const BinaryOp& bop + const UList& fld, + const CombineOp& bop, + List& result ) const { if (fld.size() != srcAddress_.size()) @@ -1875,22 +1824,13 @@ Foam::AMIInterpolation::interpolateToTarget << abort(FatalError); } - tmp > tresult - ( - new Field - ( - tgtAddress_.size(), - pTraits::zero - ) - ); - - Field& result = tresult(); + result.setSize(tgtAddress_.size()); if (singlePatchProc_ == -1) { const mapDistribute& map = srcMapPtr_(); - Field work(fld); + List work(fld); map.distribute(work); forAll(result, faceI) @@ -1900,7 +1840,7 @@ Foam::AMIInterpolation::interpolateToTarget forAll(faces, i) { - result[faceI] = bop(result[faceI], work[faces[i]]*weights[i]); + bop(result[faceI], faceI, work[faces[i]], weights[i]); } } } @@ -1913,10 +1853,126 @@ Foam::AMIInterpolation::interpolateToTarget forAll(faces, i) { - result[faceI] = bop(result[faceI], fld[faces[i]]*weights[i]); + bop(result[faceI], faceI, fld[faces[i]], weights[i]); } } } +} + + +template +template +void Foam::AMIInterpolation::interpolateToSource +( + const UList& fld, + const CombineOp& bop, + List& result +) const +{ + if (fld.size() != tgtAddress_.size()) + { + FatalErrorIn + ( + "AMIInterpolation::interpolateToSource(const Field) const" + ) << "Supplied field size is not equal to target patch size" << nl + << " source patch = " << srcAddress_.size() << nl + << " target patch = " << tgtAddress_.size() << nl + << " supplied field = " << fld.size() + << abort(FatalError); + } + + result.setSize(srcAddress_.size()); + + if (singlePatchProc_ == -1) + { + const mapDistribute& map = tgtMapPtr_(); + + List work(fld); + map.distribute(work); + + forAll(result, faceI) + { + const labelList& faces = srcAddress_[faceI]; + const scalarList& weights = srcWeights_[faceI]; + + forAll(faces, i) + { + bop(result[faceI], faceI, work[faces[i]], weights[i]); + } + } + } + else + { + forAll(result, faceI) + { + const labelList& faces = srcAddress_[faceI]; + const scalarList& weights = srcWeights_[faceI]; + + forAll(faces, i) + { + bop(result[faceI], faceI, fld[faces[i]], weights[i]); + } + } + } +} + + +template +template +Foam::tmp > +Foam::AMIInterpolation::interpolateToSource +( + const Field& fld, + const BinaryOp& bop +) const +{ + tmp > tresult + ( + new Field + ( + srcAddress_.size(), + pTraits::zero + ) + ); + + interpolateToSource(fld, combineBinaryOp(bop), tresult()); + + return tresult; +} + + +template +template +Foam::tmp > +Foam::AMIInterpolation::interpolateToSource +( + const tmp >& tFld, + const BinaryOp& bop +) const +{ + return interpolateToSource(tFld, bop); +} + + +template +template +Foam::tmp > +Foam::AMIInterpolation::interpolateToTarget +( + const Field& fld, + const BinaryOp& bop +) const +{ + tmp > tresult + ( + new Field + ( + tgtAddress_.size(), + pTraits::zero + ) + ); + + interpolateToTarget(fld, combineBinaryOp(bop), tresult()); return tresult; } @@ -1931,7 +1987,7 @@ Foam::AMIInterpolation::interpolateToTarget const BinaryOp& bop ) const { - return interpolateToTarget(tFld(), bop); + return interpolateToTarget(tFld, bop); } diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index e43180db6f..c9aa12da90 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -404,7 +404,30 @@ public: // Evaluation - //- Interpolate from target to source with supplied op + // Low-level + + //- Interpolate from target to source with supplied op + // to combine existing value with remote value and weight + template + void interpolateToSource + ( + const UList& fld, + const CombineOp& bop, + List& result + ) const; + + //- Interpolate from source to target with supplied op + // to combine existing value with remote value and weight + template + void interpolateToTarget + ( + const UList& fld, + const CombineOp& bop, + List& result + ) const; + + + //- Interpolate from target to source with supplied binary op template tmp > interpolateToSource ( @@ -412,7 +435,8 @@ public: const BinaryOp& bop ) const; - //- Interpolate from target tmp field to source with supplied op + //- Interpolate from target tmp field to source with supplied + // binary op template tmp > interpolateToSource ( @@ -464,7 +488,6 @@ public: const tmp >& tFld ) const; - // Checks //- Write face connectivity as OBJ file diff --git a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H index 9ced39571a..dcd26799c0 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H +++ b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H @@ -318,6 +318,15 @@ public: const tmp >& tFld ) const; + //- Low-level interpolate List + template + void interpolate + ( + const UList& fld, + const BinaryOp& bop, + List& result + ) const; + //- Calculate the patch geometry virtual void calcGeometry diff --git a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatchTemplates.C b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatchTemplates.C index ccafd75fd4..4bf59fba41 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatchTemplates.C +++ b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatchTemplates.C @@ -59,4 +59,23 @@ Foam::tmp > Foam::cyclicAMIPolyPatch::interpolate } +template +void Foam::cyclicAMIPolyPatch::interpolate +( + const UList& fld, + const BinaryOp& bop, + List& result +) const +{ + if (owner()) + { + AMIPtr_->interpolateToSource(fld, bop, result); + } + else + { + neighbPatch().AMIPtr_->interpolateToTarget(fld, bop, result); + } +} + + // ************************************************************************* // diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 4ba28fce08..e1c9854902 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -30,14 +30,21 @@ meshSearch/meshSearch.C meshTools/meshTools.C -pWave = PointEdgeWave +algorithms = algorithms + +pWave = $(algorithms)/PointEdgeWave $(pWave)/PointEdgeWaveName.C $(pWave)/pointEdgePoint.C -patchWave = PatchEdgeFaceWave +patchWave = $(algorithms)/PatchEdgeFaceWave $(patchWave)/PatchEdgeFaceWaveName.C $(patchWave)/patchEdgeFaceInfo.C +meshWave = $(algorithms)/MeshWave +$(meshWave)/MeshWaveName.C +$(meshWave)/FaceCellWaveName.C + + regionSplit/regionSplit.C indexedOctree/treeDataEdge.C diff --git a/src/OpenFOAM/algorithms/MeshWave/FaceCellWave.C b/src/meshTools/algorithms/MeshWave/FaceCellWave.C similarity index 77% rename from src/OpenFOAM/algorithms/MeshWave/FaceCellWave.C rename to src/meshTools/algorithms/MeshWave/FaceCellWave.C index 5b11137329..c0e1e72ee8 100644 --- a/src/OpenFOAM/algorithms/MeshWave/FaceCellWave.C +++ b/src/meshTools/algorithms/MeshWave/FaceCellWave.C @@ -27,11 +27,14 @@ License #include "polyMesh.H" #include "processorPolyPatch.H" #include "cyclicPolyPatch.H" +#include "cyclicAMIPolyPatch.H" #include "OPstream.H" #include "IPstream.H" #include "PstreamReduceOps.H" #include "debug.H" #include "typeInfo.H" +#include "SubField.H" +#include "globalMeshData.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -44,6 +47,53 @@ Foam::scalar Foam::FaceCellWave::propagationTol_ = 0.01; template Foam::label Foam::FaceCellWave::dummyTrackData_ = 12345; +namespace Foam +{ + //- Combine operator for AMIInterpolation + template + class combine + { + FaceCellWave& solver_; + + const polyPatch& patch_; + + public: + + combine + ( + FaceCellWave& solver, + const polyPatch& patch + ) + : + solver_(solver), + patch_(patch) + {} + + + void operator() + ( + Type& x, + const label faceI, + const Type& y, + const scalar weight + ) const + { + if (y.valid(solver_.data())) + { + x.updateFace + ( + solver_.mesh(), + patch_.start() + faceI, + y, + solver_.propagationTol(), + solver_.data() + ); + } + } + }; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -244,11 +294,12 @@ void Foam::FaceCellWave::checkCyclic // Check if has cyclic patches template -bool Foam::FaceCellWave::hasCyclicPatch() const +template +bool Foam::FaceCellWave::hasPatch() const { forAll(mesh_.boundaryMesh(), patchI) { - if (isA(mesh_.boundaryMesh()[patchI])) + if (isA(mesh_.boundaryMesh()[patchI])) { return true; } @@ -446,119 +497,117 @@ void Foam::FaceCellWave::offset template void Foam::FaceCellWave::handleProcPatches() { + const globalMeshData& pData = mesh_.globalData(); + + // Which patches are processor patches + const labelList& procPatches = pData.processorPatches(); + // Send all PstreamBuffers pBufs(Pstream::nonBlocking); - forAll(mesh_.boundaryMesh(), patchI) + forAll(procPatches, i) { - const polyPatch& patch = mesh_.boundaryMesh()[patchI]; + label patchI = procPatches[i]; - if (isA(patch)) + const processorPolyPatch& procPatch = + refCast(mesh_.boundaryMesh()[patchI]); + + // Allocate buffers + label nSendFaces; + labelList sendFaces(procPatch.size()); + List sendFacesInfo(procPatch.size()); + + // Determine which faces changed on current patch + nSendFaces = getChangedPatchFaces + ( + procPatch, + 0, + procPatch.size(), + sendFaces, + sendFacesInfo + ); + + // Adapt wallInfo for leaving domain + leaveDomain + ( + procPatch, + nSendFaces, + sendFaces, + sendFacesInfo + ); + + if (debug) { - // Allocate buffers - label nSendFaces; - labelList sendFaces(patch.size()); - List sendFacesInfo(patch.size()); - - // Determine which faces changed on current patch - nSendFaces = getChangedPatchFaces - ( - patch, - 0, - patch.size(), - sendFaces, - sendFacesInfo - ); - - // Adapt wallInfo for leaving domain - leaveDomain - ( - patch, - nSendFaces, - sendFaces, - sendFacesInfo - ); - - const processorPolyPatch& procPatch = - refCast(patch); - - if (debug) - { - Pout<< " Processor patch " << patchI << ' ' << patch.name() - << " communicating with " << procPatch.neighbProcNo() - << " Sending:" << nSendFaces - << endl; - } - - UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs); - //writeFaces(nSendFaces, sendFaces, sendFacesInfo, toNeighbour); - toNeighbour - << SubList