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:
@ -1,5 +1,7 @@
|
|||||||
EXE_INC = \
|
EXE_INC = \
|
||||||
|
-I$(LIB_SRC)/dynamicMesh/lnInclude \
|
||||||
-I$(LIB_SRC)/finiteVolume/lnInclude
|
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||||
|
|
||||||
EXE_LIBS = \
|
EXE_LIBS = \
|
||||||
|
-ldynamicMesh \
|
||||||
-lfiniteVolume
|
-lfiniteVolume
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -42,8 +42,7 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
IOobject::MUST_READ_IF_MODIFIED,
|
IOobject::MUST_READ_IF_MODIFIED,
|
||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
mirrorMeshPtr_(nullptr)
|
|
||||||
{
|
{
|
||||||
plane mirrorPlane(mirrorMeshDict_);
|
plane mirrorPlane(mirrorMeshDict_);
|
||||||
|
|
||||||
@ -108,6 +107,21 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
Info<< " New points: " << nNewPoints << endl;
|
Info<< " New points: " << nNewPoints << endl;
|
||||||
newPoints.setSize(nNewPoints);
|
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();
|
Info<< "Mirroring faces. Old faces: " << oldFaces.size();
|
||||||
|
|
||||||
// Algorithm:
|
// Algorithm:
|
||||||
@ -329,6 +343,10 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
cellList newCells(2*oldCells.size());
|
cellList newCells(2*oldCells.size());
|
||||||
label nNewCells = 0;
|
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.
|
// Grab the original cells. Take care of face renumbering.
|
||||||
forAll(oldCells, celli)
|
forAll(oldCells, celli)
|
||||||
{
|
{
|
||||||
@ -342,6 +360,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
nc[i] = masterFaceLookup[oc[i]];
|
nc[i] = masterFaceLookup[oc[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cellMap[nNewCells] = celli;
|
||||||
|
|
||||||
nNewCells++;
|
nNewCells++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,6 +378,8 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
nc[i] = mirrorFaceLookup[oc[i]];
|
nc[i] = mirrorFaceLookup[oc[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cellMap[nNewCells] = celli;
|
||||||
|
|
||||||
nNewCells++;
|
nNewCells++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,15 +387,18 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
|
|||||||
Info<< "Mirroring cell shapes." << endl;
|
Info<< "Mirroring cell shapes." << endl;
|
||||||
|
|
||||||
Info<< nl << "Creating new mesh" << endl;
|
Info<< nl << "Creating new mesh" << endl;
|
||||||
mirrorMeshPtr_ = new fvMesh
|
mirrorMeshPtr_.reset
|
||||||
(
|
(
|
||||||
io,
|
new fvMesh
|
||||||
xferMove(newPoints),
|
(
|
||||||
xferMove(newFaces),
|
io,
|
||||||
xferMove(newCells)
|
xferMove(newPoints),
|
||||||
|
xferMove(newFaces),
|
||||||
|
xferMove(newCells)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
fvMesh& pMesh = *mirrorMeshPtr_;
|
fvMesh& pMesh = mirrorMeshPtr_();
|
||||||
|
|
||||||
// Add the boundary patches
|
// Add the boundary patches
|
||||||
List<polyPatch*> p(newPatchSizes.size());
|
List<polyPatch*> p(newPatchSizes.size());
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -55,7 +55,13 @@ class mirrorFvMesh
|
|||||||
IOdictionary mirrorMeshDict_;
|
IOdictionary mirrorMeshDict_;
|
||||||
|
|
||||||
//- Mirrored mesh
|
//- Mirrored mesh
|
||||||
fvMesh* mirrorMeshPtr_;
|
autoPtr<fvMesh> mirrorMeshPtr_;
|
||||||
|
|
||||||
|
//- Cell map
|
||||||
|
autoPtr<labelList> cellMapPtr_;
|
||||||
|
|
||||||
|
//- Point map
|
||||||
|
autoPtr<labelList> pointMapPtr_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
@ -85,7 +91,19 @@ public:
|
|||||||
//- Return reference to mirror mesh
|
//- Return reference to mirror mesh
|
||||||
const fvMesh& mirrorMesh() const
|
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_();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -32,6 +32,8 @@ Description
|
|||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "mirrorFvMesh.H"
|
#include "mirrorFvMesh.H"
|
||||||
|
#include "mapPolyMesh.H"
|
||||||
|
#include "hexRef8Data.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -39,18 +41,12 @@ using namespace Foam;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
#include "addOverwriteOption.H"
|
#include "addOverwriteOption.H"
|
||||||
#include "setRootCase.H"
|
#include "setRootCase.H"
|
||||||
#include "createTime.H"
|
#include "createTime.H"
|
||||||
|
|
||||||
const bool overwrite = args.optionFound("overwrite");
|
const bool overwrite = args.optionFound("overwrite");
|
||||||
|
|
||||||
if (!overwrite)
|
|
||||||
{
|
|
||||||
runTime++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mirrorFvMesh mesh
|
mirrorFvMesh mesh
|
||||||
(
|
(
|
||||||
IOobject
|
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
|
// Set the precision of the points data to 10
|
||||||
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
|
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;
|
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;
|
Info<< "End" << endl;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -90,24 +90,27 @@ Foam::mapPolyMesh::mapPolyMesh
|
|||||||
oldPatchNMeshPoints_(oldPatchNMeshPoints),
|
oldPatchNMeshPoints_(oldPatchNMeshPoints),
|
||||||
oldCellVolumesPtr_(oldCellVolumesPtr)
|
oldCellVolumesPtr_(oldCellVolumesPtr)
|
||||||
{
|
{
|
||||||
// Calculate old patch sizes
|
if (oldPatchStarts_.size())
|
||||||
for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++)
|
|
||||||
{
|
{
|
||||||
oldPatchSizes_[patchi] =
|
// Calculate old patch sizes
|
||||||
oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi];
|
for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; 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
|
oldPatchSizes_[patchi] =
|
||||||
<< abort(FatalError);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
void Foam::hexRef8Data::distribute(const mapDistributePolyMesh& map)
|
||||||
{
|
{
|
||||||
if (cellLevelPtr_.valid())
|
if (cellLevelPtr_.valid())
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -117,6 +117,9 @@ public:
|
|||||||
// (even if they don't have a mesh). Used by redistributePar.
|
// (even if they don't have a mesh). Used by redistributePar.
|
||||||
void sync(const IOobject& io);
|
void sync(const IOobject& io);
|
||||||
|
|
||||||
|
//- In-place update for topology changes
|
||||||
|
void updateMesh(const mapPolyMesh&);
|
||||||
|
|
||||||
//- In-place distribute
|
//- In-place distribute
|
||||||
void distribute(const mapDistributePolyMesh&);
|
void distribute(const mapDistributePolyMesh&);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user