diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/Make/options b/applications/utilities/mesh/manipulation/mirrorMesh/Make/options index fa15f1245..ac6ecd833 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/Make/options +++ b/applications/utilities/mesh/manipulation/mirrorMesh/Make/options @@ -1,5 +1,7 @@ EXE_INC = \ + -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude EXE_LIBS = \ + -ldynamicMesh \ -lfiniteVolume diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C index afbf8f557..e2fc75511 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,8 +42,7 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) - ), - mirrorMeshPtr_(nullptr) + ) { plane mirrorPlane(mirrorMeshDict_); @@ -108,6 +107,21 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) Info<< " New points: " << nNewPoints << endl; newPoints.setSize(nNewPoints); + // Construct new to old map + pointMapPtr_.reset(new labelList(newPoints.size())); + labelList& pointMap = pointMapPtr_(); + // Insert old points + forAll(oldPoints, oldPointi) + { + pointMap[oldPointi] = oldPointi; + } + forAll(mirrorPointLookup, oldPointi) + { + pointMap[mirrorPointLookup[oldPointi]] = oldPointi; + } + + + Info<< "Mirroring faces. Old faces: " << oldFaces.size(); // Algorithm: @@ -329,6 +343,10 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) cellList newCells(2*oldCells.size()); label nNewCells = 0; + // Construct new to old cell map + cellMapPtr_.reset(new labelList(newCells.size())); + labelList& cellMap = cellMapPtr_(); + // Grab the original cells. Take care of face renumbering. forAll(oldCells, celli) { @@ -342,6 +360,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) nc[i] = masterFaceLookup[oc[i]]; } + cellMap[nNewCells] = celli; + nNewCells++; } @@ -358,6 +378,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) nc[i] = mirrorFaceLookup[oc[i]]; } + cellMap[nNewCells] = celli; + nNewCells++; } @@ -365,15 +387,18 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) Info<< "Mirroring cell shapes." << endl; Info<< nl << "Creating new mesh" << endl; - mirrorMeshPtr_ = new fvMesh + mirrorMeshPtr_.reset ( - io, - xferMove(newPoints), - xferMove(newFaces), - xferMove(newCells) + new fvMesh + ( + io, + xferMove(newPoints), + xferMove(newFaces), + xferMove(newCells) + ) ); - fvMesh& pMesh = *mirrorMeshPtr_; + fvMesh& pMesh = mirrorMeshPtr_(); // Add the boundary patches List p(newPatchSizes.size()); diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.H b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.H index bb1168665..660a4cde3 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.H +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,7 +55,13 @@ class mirrorFvMesh IOdictionary mirrorMeshDict_; //- Mirrored mesh - fvMesh* mirrorMeshPtr_; + autoPtr mirrorMeshPtr_; + + //- Cell map + autoPtr cellMapPtr_; + + //- Point map + autoPtr pointMapPtr_; // Private Member Functions @@ -85,7 +91,19 @@ public: //- Return reference to mirror mesh const fvMesh& mirrorMesh() const { - return *mirrorMeshPtr_; + return mirrorMeshPtr_(); + } + + //- Mirrorred to original cell + const labelList& cellMap() const + { + return cellMapPtr_(); + } + + //- Mirrorred to original point + const labelList& pointMap() const + { + return pointMapPtr_(); } }; diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C index f90ed99ee..d70e94103 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,6 +32,8 @@ Description #include "argList.H" #include "Time.H" #include "mirrorFvMesh.H" +#include "mapPolyMesh.H" +#include "hexRef8Data.H" using namespace Foam; @@ -39,18 +41,12 @@ using namespace Foam; int main(int argc, char *argv[]) { - #include "addOverwriteOption.H" #include "setRootCase.H" #include "createTime.H" const bool overwrite = args.optionFound("overwrite"); - if (!overwrite) - { - runTime++; - } - mirrorFvMesh mesh ( IOobject @@ -61,11 +57,71 @@ int main(int argc, char *argv[]) ) ); + hexRef8Data refData + ( + IOobject + ( + "dummy", + mesh.facesInstance(), + polyMesh::meshSubDir, + mesh, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ) + ); + + if (!overwrite) + { + runTime++; + mesh.setInstance(runTime.timeName()); + } + + // Set the precision of the points data to 10 IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // Generate the mirrorred mesh + const fvMesh& mMesh = mesh.mirrorMesh(); + + const_cast(mMesh).setInstance(mesh.facesInstance()); Info<< "Writing mirrored mesh" << endl; - mesh.mirrorMesh().write(); + mMesh.write(); + + // Map the hexRef8 data + mapPolyMesh map + ( + mesh, + mesh.nPoints(), //nOldPoints, + mesh.nFaces(), //nOldFaces, + mesh.nCells(), //nOldCells, + mesh.pointMap(), //pointMap, + List(0), // pointsFromPoints, + labelList(0), //faceMap, + List(0), //facesFromPoints, + List(0), //facesFromEdges, + List(0), //facesFromFaces, + mesh.cellMap(), //cellMap, + List(0), //cellsFromPoints, + List(0), //cellsFromEdges, + List(0), //cellsFromFaces, + List(0), //cellsFromCells, + labelList(0), //reversePointMap, + labelList(0), //reverseFaceMap, + labelList(0), //reverseCellMap, + labelHashSet(0), //flipFaceFlux, + labelListList(0), //patchPointMap, + labelListList(0), //pointZoneMap, + labelListList(0), //faceZonePointMap, + labelListList(0), //faceZoneFaceMap, + labelListList(0), //cellZoneMap, + pointField(0), //preMotionPoints, + labelList(0), //oldPatchStarts, + labelList(0), //oldPatchNMeshPoints, + autoPtr() //oldCellVolumesPtr + ); + refData.updateMesh(map); + refData.write(); Info<< "End" << endl; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C index 45a156334..ffb93ff05 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,24 +90,27 @@ Foam::mapPolyMesh::mapPolyMesh oldPatchNMeshPoints_(oldPatchNMeshPoints), oldCellVolumesPtr_(oldCellVolumesPtr) { - // Calculate old patch sizes - for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++) + if (oldPatchStarts_.size()) { - oldPatchSizes_[patchi] = - oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi]; - } - - // Set the last one by hand - const label lastPatchID = oldPatchStarts_.size() - 1; - - oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID]; - - if (polyMesh::debug) - { - if (min(oldPatchSizes_) < 0) + // Calculate old patch sizes + for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++) { - FatalErrorInFunction - << abort(FatalError); + oldPatchSizes_[patchi] = + oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi]; + } + + // Set the last one by hand + const label lastPatchID = oldPatchStarts_.size() - 1; + + oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID]; + + if (polyMesh::debug) + { + if (min(oldPatchSizes_) < 0) + { + FatalErrorInFunction + << abort(FatalError); + } } } } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C index f8821a1e5..5e02b1006 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C @@ -309,6 +309,29 @@ void Foam::hexRef8Data::sync(const IOobject& io) } +void Foam::hexRef8Data::updateMesh(const mapPolyMesh& map) +{ + if (cellLevelPtr_.valid()) + { + cellLevelPtr_() = labelList(cellLevelPtr_(), map.cellMap()); + cellLevelPtr_().instance() = map.mesh().facesInstance(); + } + if (pointLevelPtr_.valid()) + { + pointLevelPtr_() = labelList(pointLevelPtr_(), map.pointMap()); + pointLevelPtr_().instance() = map.mesh().facesInstance(); + } + + // No need to distribute the level0Edge + + if (refHistoryPtr_.valid() && refHistoryPtr_().active()) + { + refHistoryPtr_().updateMesh(map); + refHistoryPtr_().instance() = map.mesh().facesInstance(); + } +} + + void Foam::hexRef8Data::distribute(const mapDistributePolyMesh& map) { if (cellLevelPtr_.valid()) diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.H index c2a709d6d..4af3f4acf 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -117,6 +117,9 @@ public: // (even if they don't have a mesh). Used by redistributePar. void sync(const IOobject& io); + //- In-place update for topology changes + void updateMesh(const mapPolyMesh&); + //- In-place distribute void distribute(const mapDistributePolyMesh&);