// Calculate geometrically collocated points, Requires PackedList to be // sized and initalised! Foam::label Foam::autoSnapDriver::getCollocatedPoints ( const scalar tol, const pointField& points, PackedBoolList& isCollocatedPoint ) { labelList pointMap; label nUnique = mergePoints ( points, // points tol, // mergeTol false, // verbose pointMap ); bool hasMerged = (nUnique < points.size()); if (!returnReduce(hasMerged, orOp<bool>())) { return 0; } // Determine which merged points are referenced more than once label nCollocated = 0; // Per old point the newPoint. Or -1 (not set yet) or -2 (already seen // twice) labelList firstOldPoint(nUnique, -1); forAll(pointMap, oldPointI) { label newPointI = pointMap[oldPointI]; if (firstOldPoint[newPointI] == -1) { // First use of oldPointI. Store. firstOldPoint[newPointI] = oldPointI; } else if (firstOldPoint[newPointI] == -2) { // Third or more reference of oldPointI -> non-manifold isCollocatedPoint.set(oldPointI, 1u); nCollocated++; } else { // Second reference of oldPointI -> non-manifold isCollocatedPoint.set(firstOldPoint[newPointI], 1u); nCollocated++; isCollocatedPoint.set(oldPointI, 1u); nCollocated++; // Mark with special value to save checking next time round firstOldPoint[newPointI] = -2; } }
// Pass1: relabel edges // ~~~~~~~~~~~~~~~~~~~~ forAll(dynEdges, i) { edge& e = dynEdges[i]; e[0] = mapPointId[e[0]]; e[1] = mapPointId[e[1]]; usedPoints.set(e[0]); usedPoints.set(e[1]); }
// Calculate inverse sum of edge weights (currently always 1.0) void Foam::autoLayerDriver::sumWeights ( const PackedBoolList& isMasterEdge, const labelList& meshEdges, const labelList& meshPoints, const edgeList& edges, scalarField& invSumWeight ) const { const pointField& pts = meshRefiner_.mesh().points(); invSumWeight = 0; forAll(edges, edgeI) { if (isMasterEdge.get(meshEdges[edgeI]) == 1) { const edge& e = edges[edgeI]; //scalar eWeight = edgeWeights[edgeI]; //scalar eWeight = 1.0; scalar eMag = max ( VSMALL, mag ( pts[meshPoints[e[1]]] - pts[meshPoints[e[0]]] ) ); scalar eWeight = 1.0/eMag; invSumWeight[e[0]] += eWeight; invSumWeight[e[1]] += eWeight; } } syncTools::syncPointList ( meshRefiner_.mesh(), meshPoints, invSumWeight, plusEqOp<scalar>(), scalar(0.0) // null value ); forAll(invSumWeight, pointI) { scalar w = invSumWeight[pointI]; if (w > 0.0) { invSumWeight[pointI] = 1.0/w; } }
void Foam::snappyLayerDriver::averageNeighbours ( const polyMesh& mesh, const PackedBoolList& isMasterEdge, const labelList& meshEdges, const labelList& meshPoints, const edgeList& edges, const scalarField& invSumWeight, const Field<Type>& data, Field<Type>& average ) { const pointField& pts = mesh.points(); average = Zero; forAll(edges, edgeI) { if (isMasterEdge.get(meshEdges[edgeI]) == 1) { const edge& e = edges[edgeI]; //scalar eWeight = edgeWeights[edgeI]; //scalar eWeight = 1.0; scalar eMag = max ( VSMALL, mag ( pts[meshPoints[e[1]]] - pts[meshPoints[e[0]]] ) ); scalar eWeight = 1.0/eMag; label v0 = e[0]; label v1 = e[1]; average[v0] += eWeight*data[v1]; average[v1] += eWeight*data[v0]; } } syncTools::syncPointList ( mesh, meshPoints, average, plusEqOp<Type>(), Zero // null value ); average *= invSumWeight; }
// Calculate inverse sum of edge weights (currently always 1.0) void Foam::autoLayerDriver::sumWeights ( const PackedBoolList& isMasterEdge, const labelList& meshEdges, const labelList& meshPoints, const edgeList& edges, scalarField& invSumWeight ) const { invSumWeight = 0; forAll(edges, edgeI) { if (isMasterEdge.get(meshEdges[edgeI]) == 1) { const edge& e = edges[edgeI]; //scalar eWeight = edgeWeights[edgeI]; scalar eWeight = 1.0; invSumWeight[e[0]] += eWeight; invSumWeight[e[1]] += eWeight; } } syncTools::syncPointList ( meshRefiner_.mesh(), meshPoints, invSumWeight, plusEqOp<scalar>(), scalar(0.0), // null value false // no separation ); forAll(invSumWeight, pointI) { scalar w = invSumWeight[pointI]; if (w > 0.0) { invSumWeight[pointI] = 1.0/w; } }
// the PackedBoolList::count method would probably be faster // since we are only checking for 'true' anyhow Foam::label Foam::dynamicRefineFvMesh::count ( const PackedBoolList& l, const unsigned int val ) { label n = 0; forAll(l, i) { if (l.get(i) == val) { n++; } // debug also serves to get-around Clang compiler trying to optimsie // out this forAll loop under O3 optimisation if (debug) { Info<< "n=" << n << endl; } } return n; }
void dynamicRefineFvMesh::calculateProtectedCells ( PackedBoolList& unrefineableCell ) const { if (protectedCell_.empty()) { unrefineableCell.clear(); return; } const labelList& cellLevel = meshCutter_.cellLevel(); unrefineableCell = protectedCell_; // Get neighbouring cell level labelList neiLevel(nFaces()-nInternalFaces()); for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++) { neiLevel[faceI-nInternalFaces()] = cellLevel[faceOwner()[faceI]]; } syncTools::swapBoundaryFaceList(*this, neiLevel, false); while (true) { // Pick up faces on border of protected cells boolList seedFace(nFaces(), false); forAll(faceNeighbour(), faceI) { label own = faceOwner()[faceI]; bool ownProtected = (unrefineableCell.get(own) == 1); label nei = faceNeighbour()[faceI]; bool neiProtected = (unrefineableCell.get(nei) == 1); if (ownProtected && (cellLevel[nei] > cellLevel[own])) { seedFace[faceI] = true; } else if (neiProtected && (cellLevel[own] > cellLevel[nei])) { seedFace[faceI] = true; } } for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++) { label own = faceOwner()[faceI]; bool ownProtected = (unrefineableCell.get(own) == 1); if ( ownProtected && (neiLevel[faceI-nInternalFaces()] > cellLevel[own]) ) { seedFace[faceI] = true; } } syncTools::syncFaceList(*this, seedFace, orEqOp<bool>(), false); // Extend unrefineableCell bool hasExtended = false; for (label faceI = 0; faceI < nInternalFaces(); faceI++) { if (seedFace[faceI]) { label own = faceOwner()[faceI]; if (unrefineableCell.get(own) == 0) { unrefineableCell.set(own, 1); hasExtended = true; } label nei = faceNeighbour()[faceI]; if (unrefineableCell.get(nei) == 0) { unrefineableCell.set(nei, 1); hasExtended = true; } } } for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++) { if (seedFace[faceI]) { label own = faceOwner()[faceI]; if (unrefineableCell.get(own) == 0) { unrefineableCell.set(own, 1); hasExtended = true; } } } if (!returnReduce(hasExtended, orOp<bool>())) { break; } }
void Foam::displacementLayeredMotionFvMotionSolver::calcZoneMask ( const label cellZoneI, PackedBoolList& isZonePoint, PackedBoolList& isZoneEdge ) const { if (cellZoneI == -1) { isZonePoint.setSize(mesh().nPoints()); isZonePoint = 1; isZoneEdge.setSize(mesh().nEdges()); isZoneEdge = 1; } else { const cellZone& cz = mesh().cellZones()[cellZoneI]; label nPoints = 0; forAll(cz, i) { const labelList& cPoints = mesh().cellPoints(cz[i]); forAll(cPoints, cPointI) { if (!isZonePoint[cPoints[cPointI]]) { isZonePoint[cPoints[cPointI]] = 1; nPoints++; } } } syncTools::syncPointList ( mesh(), isZonePoint, orEqOp<unsigned int>(), 0 ); // Mark edge inside cellZone label nEdges = 0; forAll(cz, i) { const labelList& cEdges = mesh().cellEdges(cz[i]); forAll(cEdges, cEdgeI) { if (!isZoneEdge[cEdges[cEdgeI]]) { isZoneEdge[cEdges[cEdgeI]] = 1; nEdges++; } } } syncTools::syncEdgeList ( mesh(), isZoneEdge, orEqOp<unsigned int>(), 0 ); Info<< "On cellZone " << cz.name() << " marked " << returnReduce(nPoints, sumOp<label>()) << " points and " << returnReduce(nEdges, sumOp<label>()) << " edges." << endl; } }