Commit dbc0bbc9 authored by mattijs's avatar mattijs
Browse files

ENH: extrudeMesh: preserve hexRef8Data. Fixes #471.

parent 2f2e0cf1
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -57,6 +57,7 @@ Description
#include "planeExtrusion.H"
#include "emptyPolyPatch.H"
#include "processorMeshes.H"
#include "hexRef8Data.H"
using namespace Foam;
......@@ -338,6 +339,9 @@ int main(int argc, char *argv[])
// Optional added cells (get written to cellSet)
labelHashSet addedCellsSet;
// Optional refinement data
autoPtr<hexRef8Data> refDataPtr;
if (mode == PATCH || mode == MESH)
{
if (flipNormals && mode == MESH)
......@@ -640,6 +644,32 @@ int main(int argc, char *argv[])
// Expansion ratio not used.
scalarField ratio(extrudePatch.nPoints(), 1.0);
// Load any refinement data
if (mode == MESH)
{
// Tricky: register hexRef8 onto the database
// since the mesh does not yet exist. It should not be registered
// onto the input mesh.
refDataPtr.reset
(
new hexRef8Data
(
IOobject
(
"dummy",
mesh.facesInstance(),
polyMesh::meshSubDir,
runTimeExtruded, //mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
)
);
}
// Topo change container. Either copy an existing mesh or start
// with empty storage (number of patches only needed for checking)
autoPtr<polyTopoChange> meshMod
......@@ -746,6 +776,12 @@ int main(int argc, char *argv[])
backPatchFaces
);
// Update
if (refDataPtr.valid())
{
refDataPtr().updateMesh(map());
}
// Store added cells
if (mode == MESH)
{
......@@ -909,6 +945,11 @@ int main(int argc, char *argv[])
updateFaceLabels(map(), backPatchFaces);
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
{
refDataPtr().updateMesh(map());
}
// Move mesh (if inflation used)
if (map().hasMotionPoints())
{
......@@ -1039,6 +1080,11 @@ int main(int argc, char *argv[])
// Update local data
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
{
refDataPtr().updateMesh(map());
}
// Move mesh (if inflation used)
if (map().hasMotionPoints())
{
......@@ -1072,6 +1118,12 @@ int main(int argc, char *argv[])
}
}
if (refDataPtr.valid())
{
refDataPtr().write();
}
Info<< "End\n" << endl;
return 0;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -309,6 +309,76 @@ void Foam::hexRef8Data::sync(const IOobject& io)
}
void Foam::hexRef8Data::updateMesh(const mapPolyMesh& map)
{
// Sanity check
if
(
(cellLevelPtr_.valid() && cellLevelPtr_().size() != map.nOldCells())
|| (pointLevelPtr_.valid() && pointLevelPtr_().size() != map.nOldPoints())
)
{
cellLevelPtr_.clear();
pointLevelPtr_.clear();
level0EdgePtr_.clear();
refHistoryPtr_.clear();
return;
}
if (cellLevelPtr_.valid())
{
const labelList& cellMap = map.cellMap();
labelList& cellLevel = cellLevelPtr_();
labelList newCellLevel(cellMap.size());
forAll(cellMap, newCelli)
{
label oldCelli = cellMap[newCelli];
if (oldCelli == -1)
{
newCellLevel[newCelli] = 0;
}
else
{
newCellLevel[newCelli] = cellLevel[oldCelli];
}
}
cellLevel.transfer(newCellLevel);
}
if (pointLevelPtr_.valid())
{
const labelList& pointMap = map.pointMap();
labelList& pointLevel = pointLevelPtr_();
labelList newPointLevel(pointMap.size());
forAll(pointMap, newPointi)
{
label oldPointi = pointMap[newPointi];
if (oldPointi == -1)
{
newPointLevel[newPointi] = 0;
}
else
{
newPointLevel[newPointi] = pointLevel[oldPointi];
}
}
pointLevel.transfer(newPointLevel);
}
// No need to map the level0Edge
if (refHistoryPtr_.valid() && refHistoryPtr_().active())
{
refHistoryPtr_().updateMesh(map);
}
}
void Foam::hexRef8Data::distribute(const mapDistributePolyMesh& map)
{
if (cellLevelPtr_.valid())
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -117,6 +117,9 @@ public:
// (even if they don't have a mesh). Used by redistributePar.
void sync(const IOobject& io);
//- Update local numbering for changed mesh.
void updateMesh(const mapPolyMesh&);
//- In-place distribute
void distribute(const mapDistributePolyMesh&);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment