mirrorMesh: Added support for cellLevel and pointLevel to support dynamic mesh refinement

Patch contributed by Mattijs Janssens
Resolves bug-report https://bugs.openfoam.org/view.php?id=2712
This commit is contained in:
Henry Weller
2017-10-27 15:25:29 +01:00
parent b34c323435
commit 28fdc3c4e8
7 changed files with 168 additions and 38 deletions

View File

@ -1,5 +1,7 @@
EXE_INC = \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-ldynamicMesh \
-lfiniteVolume

View File

@ -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<polyPatch*> p(newPatchSizes.size());

View File

@ -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<fvMesh> mirrorMeshPtr_;
//- Cell map
autoPtr<labelList> cellMapPtr_;
//- Point map
autoPtr<labelList> 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_();
}
};

View File

@ -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<fvMesh&>(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<objectMap>(0), // pointsFromPoints,
labelList(0), //faceMap,
List<objectMap>(0), //facesFromPoints,
List<objectMap>(0), //facesFromEdges,
List<objectMap>(0), //facesFromFaces,
mesh.cellMap(), //cellMap,
List<objectMap>(0), //cellsFromPoints,
List<objectMap>(0), //cellsFromEdges,
List<objectMap>(0), //cellsFromFaces,
List<objectMap>(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<scalarField>() //oldCellVolumesPtr
);
refData.updateMesh(map);
refData.write();
Info<< "End" << endl;

View File

@ -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);
}
}
}
}

View File

@ -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())

View File

@ -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&);