/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ 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 3 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, see . \*---------------------------------------------------------------------------*/ #include "syncTools.H" #include "polyMesh.H" #include "processorPolyPatch.H" #include "cyclicPolyPatch.H" #include "globalMeshData.H" #include "contiguous.H" #include "transform.H" #include "SubField.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template void Foam::syncTools::combine ( Map& pointValues, const CombineOp& cop, const label index, const T& val ) { typename Map::iterator iter = pointValues.find(index); if (iter != pointValues.end()) { cop(iter(), val); } else { pointValues.insert(index, val); } } template void Foam::syncTools::combine ( EdgeMap& edgeValues, const CombineOp& cop, const edge& index, const T& val ) { typename EdgeMap::iterator iter = edgeValues.find(index); if (iter != edgeValues.end()) { cop(iter(), val); } else { edgeValues.insert(index, val); } } template void Foam::syncTools::syncPointMap ( const polyMesh& mesh, Map& pointValues, // from mesh point label to value const CombineOp& cop, const TransformOp& top ) { const polyBoundaryMesh& patches = mesh.boundary(); // Synchronise multiple shared points. const globalMeshData& pd = mesh.globalData(); // Values on shared points. Keyed on global shared index. Map sharedPointValues(0); if (pd.nGlobalPoints() > 0) { // meshPoint per local index const labelList& sharedPtLabels = pd.sharedPointLabels(); // global shared index per local index const labelList& sharedPtAddr = pd.sharedPointAddr(); sharedPointValues.resize(sharedPtAddr.size()); // Fill my entries in the shared points forAll(sharedPtLabels, i) { label meshPointi = sharedPtLabels[i]; typename Map::const_iterator fnd = pointValues.find(meshPointi); if (fnd != pointValues.end()) { combine ( sharedPointValues, cop, sharedPtAddr[i], // index fnd() // value ); } } } if (Pstream::parRun()) { PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Send forAll(patches, patchi) { if ( isA(patches[patchi]) && patches[patchi].nPoints() > 0 ) { const processorPolyPatch& procPatch = refCast(patches[patchi]); // Get data per patchPoint in neighbouring point numbers. const labelList& meshPts = procPatch.meshPoints(); const labelList& nbrPts = procPatch.nbrPoints(); // Extract local values. Create map from nbrPoint to value. // Note: how small initial size? Map patchInfo(meshPts.size() / 20); forAll(meshPts, i) { typename Map::const_iterator iter = pointValues.find(meshPts[i]); if (iter != pointValues.end()) { patchInfo.insert(nbrPts[i], iter()); } } UOPstream toNeighb(procPatch.neighbProcNo(), pBufs); toNeighb << patchInfo; } } pBufs.finishedSends(); // Receive and combine. forAll(patches, patchi) { if ( isA(patches[patchi]) && patches[patchi].nPoints() > 0 ) { const processorPolyPatch& procPatch = refCast(patches[patchi]); UIPstream fromNb(procPatch.neighbProcNo(), pBufs); Map nbrPatchInfo(fromNb); // Transform top(procPatch, nbrPatchInfo); const labelList& meshPts = procPatch.meshPoints(); // Only update those values which come from neighbour forAllConstIter(typename Map, nbrPatchInfo, nbrIter) { combine ( pointValues, cop, meshPts[nbrIter.key()], nbrIter() ); } } } } // Do the cyclics. forAll(patches, patchi) { if (isA(patches[patchi])) { const cyclicPolyPatch& cycPatch = refCast(patches[patchi]); if (cycPatch.owner()) { // Owner does all. const cyclicPolyPatch& nbrPatch = cycPatch.nbrPatch(); const edgeList& coupledPoints = cycPatch.coupledPoints(); const labelList& meshPtsA = cycPatch.meshPoints(); const labelList& meshPtsB = nbrPatch.meshPoints(); // Extract local values. Create map from coupled-edge to value. Map half0Values(meshPtsA.size() / 20); Map half1Values(half0Values.size()); forAll(coupledPoints, i) { const edge& e = coupledPoints[i]; typename Map::const_iterator point0Fnd = pointValues.find(meshPtsA[e[0]]); if (point0Fnd != pointValues.end()) { half0Values.insert(i, point0Fnd()); } typename Map::const_iterator point1Fnd = pointValues.find(meshPtsB[e[1]]); if (point1Fnd != pointValues.end()) { half1Values.insert(i, point1Fnd()); } } // Transform to receiving side top(cycPatch, half1Values); top(nbrPatch, half0Values); forAll(coupledPoints, i) { const edge& e = coupledPoints[i]; typename Map::const_iterator half0Fnd = half0Values.find(i); if (half0Fnd != half0Values.end()) { combine ( pointValues, cop, meshPtsB[e[1]], half0Fnd() ); } typename Map::const_iterator half1Fnd = half1Values.find(i); if (half1Fnd != half1Values.end()) { combine ( pointValues, cop, meshPtsA[e[0]], half1Fnd() ); } } } } } // Synchronise multiple shared points. if (pd.nGlobalPoints() > 0) { // meshPoint per local index const labelList& sharedPtLabels = pd.sharedPointLabels(); // global shared index per local index const labelList& sharedPtAddr = pd.sharedPointAddr(); // Reduce on master. if (Pstream::parRun()) { if (Pstream::master()) { // Receive the edges using shared points from the slave. for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { IPstream fromSlave(Pstream::commsTypes::scheduled, slave); Map nbrValues(fromSlave); // Merge neighbouring values with my values forAllConstIter(typename Map, nbrValues, iter) { combine ( sharedPointValues, cop, iter.key(), // edge iter() // value ); } } // Send back for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { OPstream toSlave(Pstream::commsTypes::scheduled, slave); toSlave << sharedPointValues; } } else { // Slave: send to master { OPstream toMaster ( Pstream::commsTypes::scheduled, Pstream::masterNo() ); toMaster << sharedPointValues; } // Receive merged values { IPstream fromMaster ( Pstream::commsTypes::scheduled, Pstream::masterNo() ); fromMaster >> sharedPointValues; } } } // Merge sharedPointValues (keyed on sharedPointAddr) into // pointValues (keyed on mesh points). // Map from global shared index to meshpoint Map