diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/Make/options b/applications/utilities/mesh/manipulation/mirrorMesh/Make/options index fa15f12452..ac6ecd8333 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 e294fc70d8..3a3059c0f6 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 | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- 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: @@ -317,6 +331,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) { @@ -330,6 +348,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) nc[i] = masterFaceLookup[oc[i]]; } + cellMap[nNewCells] = celli; + nNewCells++; } @@ -346,6 +366,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) nc[i] = mirrorFaceLookup[oc[i]]; } + cellMap[nNewCells] = celli; + nNewCells++; } @@ -361,7 +383,7 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io) std::move(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 99794622ad..918152fa90 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 @@ -57,6 +57,12 @@ class mirrorFvMesh //- Mirrored mesh autoPtr mirrorMeshPtr_; + //- Cell map + autoPtr cellMapPtr_; + + //- Point map + autoPtr pointMapPtr_; + // Private Member Functions @@ -84,7 +90,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 f35f3ad5d8..532113e6a0 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 @@ -35,6 +35,8 @@ Description #include "argList.H" #include "Time.H" #include "mirrorFvMesh.H" +#include "mapPolyMesh.H" +#include "hexRef8Data.H" using namespace Foam; @@ -42,18 +44,12 @@ using namespace Foam; int main(int argc, char *argv[]) { - #include "addOverwriteOption.H" #include "setRootCase.H" #include "createTime.H" const bool overwrite = args.found("overwrite"); - if (!overwrite) - { - runTime++; - } - mirrorFvMesh mesh ( IOobject @@ -64,11 +60,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" << nl << endl; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C index a8dcb1886f..81efe34235 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 6a47453cf1..b05d58a6c7 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8Data.C @@ -326,7 +326,6 @@ void Foam::hexRef8Data::updateMesh(const mapPolyMesh& map) } - if (cellLevelPtr_.valid()) { const labelList& cellMap = map.cellMap(); @@ -347,6 +346,7 @@ void Foam::hexRef8Data::updateMesh(const mapPolyMesh& map) } } cellLevel.transfer(newCellLevel); + cellLevelPtr_().instance() = map.mesh().facesInstance(); } if (pointLevelPtr_.valid()) { @@ -368,13 +368,14 @@ void Foam::hexRef8Data::updateMesh(const mapPolyMesh& map) } } pointLevel.transfer(newPointLevel); + pointLevelPtr_().instance() = map.mesh().facesInstance(); } - // No need to map the level0Edge if (refHistoryPtr_.valid() && refHistoryPtr_().active()) { refHistoryPtr_().updateMesh(map); + refHistoryPtr_().instance() = map.mesh().facesInstance(); } }