diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 7a68f98b03..8ad9a47b89 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -707,6 +707,12 @@ private: DynamicList& existingEdgeLocations ) const; + //- Return a list of the nearest feature edge locations + List nearestFeatureEdgeLocations + ( + const Foam::point& pt + ) const; + //- Check if a point is near any feature edge points. bool pointIsNearFeatureEdgeLocation(const Foam::point& pt) const; @@ -983,6 +989,27 @@ private: labelList& neighbour ) const; + //- Rotates a face by an amount nPos + face rotateFace + ( + const face& f, + const label nPos + ) const; + + //- Rotate the faces on processor patches if necessary + void reorderProcessorPatches + ( + const word& meshName, + const fileName& instance, + const pointField& points, + faceList& faces, + const wordList& patchTypes, + const wordList& patchNames, + const labelList& patchSizes, + const labelList& patchStarts, + const labelList& procNeighbours + ) const; + //- Disallow default bitwise copy construct conformalVoronoiMesh(const conformalVoronoiMesh&); diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index fc860a3b59..49c4fe71fa 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -562,6 +562,178 @@ void Foam::conformalVoronoiMesh::writeMesh } +Foam::face Foam::conformalVoronoiMesh::rotateFace +( + const face& f, + const label nPos +) const +{ + face newF(f.size()); + + forAll(f, fp) + { + label fp1 = (fp + nPos) % f.size(); + + if (fp1 < 0) + { + fp1 += f.size(); + } + + newF[fp1] = f[fp]; + } + + return newF; +} + + +void Foam::conformalVoronoiMesh::reorderProcessorPatches +( + const word& meshName, + const fileName& instance, + const pointField& points, + faceList& faces, + const wordList& patchTypes, + const wordList& patchNames, + const labelList& patchSizes, + const labelList& patchStarts, + const labelList& procNeighbours +) const +{ + fvMesh tempMesh + ( + IOobject + ( + meshName, + instance, + runTime_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + xferCopy(pointField()), + xferCopy(faceList()), + xferCopy(cellList()) + ); + + List patches(patchStarts.size()); + + forAll(patches, p) + { + if (patchTypes[p] == processorPolyPatch::typeName) + { + patches[p] = new processorPolyPatch + ( + patchNames[p], + patchSizes[p], + patchStarts[p], + p, + tempMesh.boundaryMesh(), + Pstream::myProcNo(), + procNeighbours[p] + ); + } + else + { + patches[p] = polyPatch::New + ( + patchTypes[p], + patchNames[p], + patchSizes[p], + patchStarts[p], + p, + tempMesh.boundaryMesh() + ).ptr(); + } + } + + // Rotation on new faces. + labelList rotation(faces.size(), 0); + + PstreamBuffers pBufs(Pstream::nonBlocking); + + // Send ordering + forAll(patches, patchI) + { + if (isA(*patches[patchI])) + { + static_cast(patches[patchI])->initOrder + ( + pBufs, + primitivePatch + ( + SubList + ( + faces, + patchSizes[patchI], + patchStarts[patchI] + ), + points + ) + ); + } + } + + pBufs.finishedSends(); + + // Receive and calculate ordering + bool anyChanged = false; + + forAll(patches, patchI) + { + if (isA(*patches[patchI])) + { + labelList patchFaceMap(patchSizes[patchI], -1); + labelList patchFaceRotation(patchSizes[patchI], 0); + + bool changed = + static_cast(patches[patchI])->order + ( + pBufs, + primitivePatch + ( + SubList + ( + faces, + patchSizes[patchI], + patchStarts[patchI] + ), + points + ), + patchFaceMap, + patchFaceRotation + ); + + if (changed) + { + // Merge patch face reordering into mesh face reordering table + label start = patchStarts[patchI]; + + forAll(patchFaceRotation, patchFaceI) + { + rotation[patchFaceI + start] = + patchFaceRotation[patchFaceI]; + } + + anyChanged = true; + } + } + } + + reduce(anyChanged, orOp()); + + if (anyChanged) + { + // Rotate faces (rotation is already in new face indices). + forAll(rotation, faceI) + { + if (rotation[faceI] != 0) + { + faces[faceI] = rotateFace(faces[faceI], rotation[faceI]); + } + } + } +} + + void Foam::conformalVoronoiMesh::writeMesh ( const word& meshName, @@ -583,6 +755,22 @@ void Foam::conformalVoronoiMesh::writeMesh writeObjMesh(points, faces, word(meshName + ".obj")); } + if (Pstream::parRun()) + { + reorderProcessorPatches + ( + meshName, + instance, + points, + faces, + patchTypes, + patchNames, + patchSizes, + patchStarts, + procNeighbours + ); + } + fvMesh mesh ( IOobject diff --git a/applications/utilities/mesh/generation/cvMesh/cvMesh.C b/applications/utilities/mesh/generation/cvMesh/cvMesh.C index daf03aa376..ecd7f102ba 100644 --- a/applications/utilities/mesh/generation/cvMesh/cvMesh.C +++ b/applications/utilities/mesh/generation/cvMesh/cvMesh.C @@ -43,10 +43,21 @@ using namespace Foam; int main(int argc, char *argv[]) { + argList::addBoolOption + ( + "noFilter", + "Do not filter the mesh" + ); + #include "setRootCase.H" #include "createTime.H" + runTime.functionObjects().off(); + const bool noFilter = !args.optionFound("noFilter"); + + Info<< "Mesh filtering is " << (noFilter ? "on" : "off") << endl; + IOdictionary cvMeshDict ( IOobject @@ -74,7 +85,7 @@ int main(int argc, char *argv[]) << nl << endl; } - mesh.writeMesh(runTime.constant(), true); + mesh.writeMesh(runTime.constant(), noFilter); Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s"