Commit 2d9ea72b authored by mattijs's avatar mattijs
Browse files

allow -overwrite in snappyHexMesh

parent 92172c5d
......@@ -96,7 +96,7 @@ void writeMesh
const fvMesh& mesh = meshRefiner.mesh();
meshRefiner.printMeshInfo(debug, msg);
Info<< "Writing mesh to time " << mesh.time().timeName() << endl;
Info<< "Writing mesh to time " << meshRefiner.timeName() << endl;
meshRefiner.write(meshRefinement::MESH|meshRefinement::SCALARLEVELS, "");
if (debug & meshRefinement::OBJINTERSECTIONS)
......@@ -104,7 +104,7 @@ void writeMesh
meshRefiner.write
(
meshRefinement::OBJINTERSECTIONS,
mesh.time().path()/mesh.time().timeName()
mesh.time().path()/meshRefiner.timeName()
);
}
Info<< "Written mesh in = "
......@@ -115,6 +115,7 @@ void writeMesh
int main(int argc, char *argv[])
{
argList::validOptions.insert("overwrite", "");
# include "setRootCase.H"
# include "createTime.H"
runTime.functionObjects().off();
......@@ -123,6 +124,9 @@ int main(int argc, char *argv[])
Info<< "Read mesh in = "
<< runTime.cpuTimeIncrement() << " s" << endl;
const bool overwrite = args.optionFound("overwrite");
// Check patches and faceZones are synchronised
mesh.boundaryMesh().checkParallelSync(true);
meshRefinement::checkCoupledFaceZones(mesh);
......@@ -256,6 +260,7 @@ int main(int argc, char *argv[])
(
mesh,
mergeDist, // tolerance used in sorting coordinates
overwrite, // overwrite mesh files?
surfaces, // for surface intersection refinement
shells // for volume (inside/outside) refinement
);
......@@ -268,7 +273,7 @@ int main(int argc, char *argv[])
meshRefiner.write
(
debug&meshRefinement::OBJINTERSECTIONS,
mesh.time().path()/mesh.time().timeName()
mesh.time().path()/meshRefiner.timeName()
);
......@@ -369,6 +374,11 @@ int main(int argc, char *argv[])
// Refinement parameters
refinementParameters refineParams(refineDict);
if (!overwrite)
{
const_cast<Time&>(mesh.time())++;
}
refineDriver.doRefine(refineDict, refineParams, wantSnap, motionDict);
writeMesh
......@@ -390,6 +400,11 @@ int main(int argc, char *argv[])
// Snap parameters
snapParameters snapParams(snapDict);
if (!overwrite)
{
const_cast<Time&>(mesh.time())++;
}
snapDriver.doSnap(snapDict, motionDict, snapParams);
writeMesh
......@@ -407,6 +422,11 @@ int main(int argc, char *argv[])
// Layer addition parameters
layerParameters layerParams(layerDict, mesh.boundaryMesh());
if (!overwrite)
{
const_cast<Time&>(mesh.time())++;
}
layerDriver.doLayers
(
layerDict,
......
......@@ -148,6 +148,7 @@ Foam::scalar Foam::autoHexMeshDriver::getMergeDistance(const scalar mergeTol)
Foam::autoHexMeshDriver::autoHexMeshDriver
(
fvMesh& mesh,
const bool overwrite,
const dictionary& dict,
const dictionary& decomposeDict
)
......@@ -308,6 +309,7 @@ Foam::autoHexMeshDriver::autoHexMeshDriver
(
mesh,
mergeDist_, // tolerance used in sorting coordinates
overwrite,
surfaces(),
shells()
)
......@@ -321,7 +323,7 @@ Foam::autoHexMeshDriver::autoHexMeshDriver
meshRefinerPtr_().write
(
debug_&meshRefinement::OBJINTERSECTIONS,
mesh_.time().path()/mesh_.time().timeName()
mesh_.time().path()/meshRefinerPtr_().timeName()
);
}
......@@ -447,7 +449,7 @@ void Foam::autoHexMeshDriver::writeMesh(const string& msg) const
const meshRefinement& meshRefiner = meshRefinerPtr_();
meshRefiner.printMeshInfo(debug_, msg);
Info<< "Writing mesh to time " << mesh_.time().timeName() << endl;
Info<< "Writing mesh to time " << meshRefiner.timeName() << endl;
meshRefiner.write(meshRefinement::MESH|meshRefinement::SCALARLEVELS, "");
if (debug_ & meshRefinement::OBJINTERSECTIONS)
......@@ -455,7 +457,7 @@ void Foam::autoHexMeshDriver::writeMesh(const string& msg) const
meshRefiner.write
(
meshRefinement::OBJINTERSECTIONS,
mesh_.time().path()/mesh_.time().timeName()
mesh_.time().path()/meshRefiner.timeName()
);
}
Info<< "Written mesh in = "
......
......@@ -174,6 +174,7 @@ public:
autoHexMeshDriver
(
fvMesh& mesh,
const bool overwrite,
const dictionary& meshDict,
const dictionary& decomposeDict
);
......
......@@ -159,12 +159,16 @@ Foam::label Foam::autoLayerDriver::mergePatchFacesUndo
mesh.clearOut();
}
if (meshRefiner_.overwrite())
{
mesh.setInstance(meshRefiner_.oldInstance());
}
faceCombiner.updateMesh(map);
meshRefiner_.updateMesh(map, labelList(0));
for (label iteration = 0; iteration < 100; iteration++)
{
Info<< nl
......@@ -313,6 +317,11 @@ Foam::label Foam::autoLayerDriver::mergePatchFacesUndo
mesh.clearOut();
}
if (meshRefiner_.overwrite())
{
mesh.setInstance(meshRefiner_.oldInstance());
}
faceCombiner.updateMesh(map);
// Renumber restore maps
......@@ -336,7 +345,7 @@ Foam::label Foam::autoLayerDriver::mergePatchFacesUndo
if (debug)
{
Pout<< "Writing merged-faces mesh to time "
<< mesh.time().timeName() << nl << endl;
<< meshRefiner_.timeName() << nl << endl;
mesh.write();
}
}
......@@ -380,6 +389,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoLayerDriver::doRemovePoints
mesh.clearOut();
}
if (meshRefiner_.overwrite())
{
mesh.setInstance(meshRefiner_.oldInstance());
}
pointRemover.updateMesh(map);
meshRefiner_.updateMesh(map, labelList(0));
......@@ -433,6 +447,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoLayerDriver::doRestorePoints
mesh.clearOut();
}
if (meshRefiner_.overwrite())
{
mesh.setInstance(meshRefiner_.oldInstance());
}
pointRemover.updateMesh(map);
meshRefiner_.updateMesh(map, labelList(0));
......@@ -656,7 +675,7 @@ Foam::label Foam::autoLayerDriver::mergeEdgesUndo
if (debug)
{
Pout<< "Writing merged-edges mesh to time "
<< mesh.time().timeName() << nl << endl;
<< meshRefiner_.timeName() << nl << endl;
mesh.write();
}
}
......@@ -2724,7 +2743,7 @@ void Foam::autoLayerDriver::addLayers
IOobject
(
"pointMedialDist",
mesh.time().timeName(),
meshRefiner_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
......@@ -2739,7 +2758,7 @@ void Foam::autoLayerDriver::addLayers
IOobject
(
"dispVec",
mesh.time().timeName(),
meshRefiner_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
......@@ -2754,7 +2773,7 @@ void Foam::autoLayerDriver::addLayers
IOobject
(
"medialRatio",
mesh.time().timeName(),
meshRefiner_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
......@@ -2906,7 +2925,7 @@ void Foam::autoLayerDriver::addLayers
);
const_cast<Time&>(mesh.time())++;
Info<< "Writing shrunk mesh to " << mesh.time().timeName() << endl;
Info<< "Writing shrunk mesh to " << meshRefiner_.timeName() << endl;
// See comment in autoSnapDriver why we should not remove meshPhi
// using mesh.clearPout().
......@@ -3007,6 +3026,11 @@ void Foam::autoLayerDriver::addLayers
//?neccesary? Update fields
newMesh.updateMesh(map);
if (meshRefiner_.overwrite())
{
newMesh.setInstance(meshRefiner_.oldInstance());
}
// Update numbering on addLayer:
// - cell/point labels to be newMesh.
// - patchFaces to remain in oldMesh order.
......@@ -3029,7 +3053,7 @@ void Foam::autoLayerDriver::addLayers
if (debug)
{
Info<< "Writing layer mesh to " << mesh.time().timeName() << endl;
Info<< "Writing layer mesh to " << meshRefiner_.timeName() << endl;
newMesh.write();
cellSet addedCellSet
(
......@@ -3108,6 +3132,11 @@ void Foam::autoLayerDriver::addLayers
mesh.clearOut();
}
if (meshRefiner_.overwrite())
{
mesh.setInstance(meshRefiner_.oldInstance());
}
meshRefiner_.updateMesh(map, labelList(0));
......@@ -3176,8 +3205,6 @@ void Foam::autoLayerDriver::doLayers
<< "----------------------------------" << nl
<< endl;
const_cast<Time&>(mesh.time())++;
Info<< "Using mesh parameters " << motionDict << nl << endl;
// Merge coplanar boundary faces
......
......@@ -344,8 +344,8 @@ void Foam::autoRefineDriver::removeInsideCells
if (debug)
{
Pout<< "Writing subsetted mesh to time "
<< mesh.time().timeName() << '.' << endl;
meshRefiner_.write(debug, mesh.time().path()/mesh.time().timeName());
<< meshRefiner_.timeName() << '.' << endl;
meshRefiner_.write(debug, mesh.time().path()/meshRefiner_.timeName());
Pout<< "Dumped mesh in = "
<< mesh.time().cpuTimeIncrement() << " s\n" << nl << endl;
}
......@@ -561,11 +561,11 @@ void Foam::autoRefineDriver::zonify
if (debug)
{
Pout<< "Writing zoned mesh to time "
<< mesh.time().timeName() << '.' << endl;
<< meshRefiner_.timeName() << '.' << endl;
meshRefiner_.write
(
debug,
mesh.time().path()/mesh.time().timeName()
mesh.time().path()/meshRefiner_.timeName()
);
}
......@@ -653,8 +653,8 @@ void Foam::autoRefineDriver::splitAndMergeBaffles
if (debug)
{
Pout<< "Writing handleProblemCells mesh to time "
<< mesh.time().timeName() << '.' << endl;
meshRefiner_.write(debug, mesh.time().path()/mesh.time().timeName());
<< meshRefiner_.timeName() << '.' << endl;
meshRefiner_.write(debug, mesh.time().path()/meshRefiner_.timeName());
}
}
......@@ -712,9 +712,6 @@ void Foam::autoRefineDriver::doRefine
const fvMesh& mesh = meshRefiner_.mesh();
const_cast<Time&>(mesh.time())++;
// Check that all the keep points are inside the mesh.
refineParams.findCells(mesh);
......
......@@ -557,7 +557,7 @@ Foam::tmp<Foam::scalarField> Foam::autoSnapDriver::edgePatchDist
// IOobject
// (
// "pointDist",
// mesh.DB().timeName(),
// meshRefiner_.timeName(),
// mesh.DB(),
// IOobject::NO_READ,
// IOobject::AUTO_WRITE
......@@ -580,7 +580,7 @@ Foam::tmp<Foam::scalarField> Foam::autoSnapDriver::edgePatchDist
// pointDist[pointI] /= mesh.pointEdges()[pointI].size();
// }
// Info<< "Writing patch distance to " << pointDist.name()
// << " at time " << mesh.DB().timeName() << endl;
// << " at time " << meshRefiner_.timeName() << endl;
//
// pointDist.write();
//}
......@@ -750,7 +750,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::createZoneBaffles
{
const_cast<Time&>(mesh.time())++;
Pout<< "Writing baffled mesh to time "
<< mesh.time().timeName() << endl;
<< meshRefiner_.timeName() << endl;
mesh.write();
}
}
......@@ -899,7 +899,7 @@ void Foam::autoSnapDriver::preSmoothPatch
if (debug)
{
const_cast<Time&>(mesh.time())++;
Pout<< "Writing patch smoothed mesh to time " << mesh.time().timeName()
Pout<< "Writing patch smoothed mesh to time " << meshRefiner_.timeName()
<< endl;
mesh.write();
......@@ -1193,7 +1193,7 @@ void Foam::autoSnapDriver::smoothDisplacement
if (debug)
{
const_cast<Time&>(mesh.time())++;
Pout<< "Writing smoothed mesh to time " << mesh.time().timeName()
Pout<< "Writing smoothed mesh to time " << meshRefiner_.timeName()
<< endl;
// Moving mesh creates meshPhi. Can be cleared out by a mesh.clearOut
......@@ -1255,7 +1255,7 @@ void Foam::autoSnapDriver::scaleMesh
if (debug)
{
const_cast<Time&>(mesh.time())++;
Pout<< "Writing scaled mesh to time " << mesh.time().timeName()
Pout<< "Writing scaled mesh to time " << meshRefiner_.timeName()
<< endl;
mesh.write();
......@@ -1447,8 +1447,6 @@ void Foam::autoSnapDriver::doSnap
<< "--------------" << nl
<< endl;
const_cast<Time&>(mesh.time())++;
// Get the labels of added patches.
labelList adaptPatchIDs(meshRefiner_.meshedPatches());
......
......@@ -465,6 +465,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::doRemoveCells
mesh_.clearOut();
}
if (overwrite_)
{
mesh_.setInstance(oldInstance_);
}
// Update local mesh data
cellRemover.updateMesh(map);
......@@ -817,12 +822,15 @@ Foam::meshRefinement::meshRefinement
(
fvMesh& mesh,
const scalar mergeDistance,
const bool overwrite,
const refinementSurfaces& surfaces,
const shellSurfaces& shells
)
:
mesh_(mesh),
mergeDistance_(mergeDistance),
overwrite_(overwrite),
oldInstance_(mesh.pointsInstance()),
surfaces_(surfaces),
shells_(shells),
meshCutter_
......@@ -1199,8 +1207,6 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::meshRefinement::balance
// Helper function to get intersected faces
Foam::labelList Foam::meshRefinement::intersectedFaces() const
{
// Mark all faces that will become baffles
label nBoundaryFaces = 0;
forAll(surfaceIndex_, faceI)
......@@ -1226,9 +1232,7 @@ Foam::labelList Foam::meshRefinement::intersectedFaces() const
// Helper function to get points used by faces
Foam::labelList Foam::meshRefinement::intersectedPoints
(
) const
Foam::labelList Foam::meshRefinement::intersectedPoints() const
{
const faceList& faces = mesh_.faces();
......@@ -1384,7 +1388,7 @@ Foam::tmp<Foam::pointVectorField> Foam::meshRefinement::makeDisplacementField
IOobject
(
"pointDisplacement",
mesh.time().timeName(),
mesh.time().timeName(), //timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
......@@ -2059,6 +2063,20 @@ void Foam::meshRefinement::printMeshInfo(const bool debug, const string& msg)
}
//- Return either time().constant() or oldInstance
Foam::word Foam::meshRefinement::timeName() const
{
if (overwrite_ && mesh_.time().timeIndex() == 0)
{
return oldInstance_;
}
else
{
return mesh_.time().timeName();
}
}
void Foam::meshRefinement::dumpRefinementLevel() const
{
volScalarField volRefLevel
......@@ -2066,7 +2084,7 @@ void Foam::meshRefinement::dumpRefinementLevel() const
IOobject
(
"cellLevel",
mesh_.time().timeName(),
timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
......@@ -2093,7 +2111,7 @@ void Foam::meshRefinement::dumpRefinementLevel() const
IOobject
(
"pointLevel",
mesh_.time().timeName(),
timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
......
......@@ -110,6 +110,12 @@ private:
//- tolerance used for sorting coordinates (used in 'less' routine)
const scalar mergeDistance_;
//- overwrite the mesh?
const bool overwrite_;
//- Instance of mesh upon construction. Used when in overwrite_ mode.
const word oldInstance_;
//- All surface-intersection interaction
const refinementSurfaces& surfaces_;
......@@ -167,9 +173,6 @@ private:
//- Find any intersection of surface. Store in surfaceIndex_.
void updateIntersections(const labelList& changedFaces);
//- Set instance of all local IOobjects
void setInstance(const fileName&);
//- Remove cells. Put exposedFaces into exposedPatchIDs.
autoPtr<mapPolyMesh> doRemoveCells
(
......@@ -478,6 +481,7 @@ public:
(
fvMesh& mesh,
const scalar mergeDistance,
const bool overwrite,
const refinementSurfaces&,
const shellSurfaces&
);
......@@ -502,6 +506,18 @@ public:
return mergeDistance_;
}
//- Overwrite the mesh?
bool overwrite() const
{
return overwrite_;
}
//- (points)instance of mesh upon construction
const word& oldInstance() const
{
return oldInstance_;
}
//- reference to surface search engines
const refinementSurfaces& surfaces() const
{
......@@ -768,6 +784,13 @@ public:
//- Print some mesh stats.
void printMeshInfo(const bool, const string&) const;
//- Replacement for Time::timeName() : return oldInstance (if
// overwrite_)
word timeName() const;
//- Set instance of all local IOobjects
void setInstance(const fileName&);
//- Write mesh and all data
bool write() const;
......
......@@ -226,7 +226,13 @@ void Foam::meshRefinement::getBafflePatches
label vertI = 0;
if (debug&OBJINTERSECTIONS)
{
str.reset(new OFstream(mesh_.time().timePath()/"intersections.obj"));
str.reset
(
new OFstream
(
mesh_.time().path()/timeName()/"intersections.obj"
)
);
Pout<< "getBafflePatches : Writing surface intersections to file "
<< str().name() << nl << endl;
......@@ -461,6 +467,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::createBaffles
mesh_.clearOut();
}
if (overwrite())
{
mesh_.setInstance(oldInstance());
}
//- Redo the intersections on the newly create baffle faces. Note that
// this changes also the cell centre positions.
faceSet baffledFacesSet(mesh_, "baffledFacesSet", 2*nBaffles);
......@@ -820,6 +831,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::mergeBaffles
mesh_.clearOut();
}
if (overwrite())
{
mesh_.setInstance(oldInstance());
}
// Update intersections. Recalculate intersections on merged faces since
// this seems to give problems? Note: should not be nessecary since
// baffles preserve intersections from when they were created.
......@@ -1482,7 +1498,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
if (debug)
{
Pout<< "Writing baffled mesh to time " << mesh_.time().timeName()
Pout<< "Writing baffled mesh to time " << timeName()
<< endl;
write(debug, runTime.path()/"baffles");
Pout<< "Dumped debug data in = "
......@@ -1565,7 +1581,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
if (debug)
{
Pout<< "Writing extra baffled mesh to time "
<< mesh_.time().timeName() << endl;
<< timeName() << endl;
write(debug, runTime.path()/"extraBaffles");
Pout<< "Dumped debug data in = "
<< runTime.cpuTimeIncrement() << " s\n" << nl << endl;
......@@ -1600,9 +1616,9 @@ void Foam::meshRefinement::baffleAndSplitMesh
if (debug)
{
Pout<< "Writing subsetted mesh to time " << mesh_.time().timeName()
Pout<< "Writing subsetted mesh to time " << timeName()
<< endl;
write(debug, runTime.timePath());
write(debug, runTime.path()/timeName());
Pout<< "Dumped debug data in = "
<< runTime.cpuTimeIncrement() << " s\n" << nl << endl;
}
......@@ -1994,6 +2010,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::dupNonManifoldPoints()