ENH: snappyHexMesh: write leak-closure faces

This commit is contained in:
mattijs
2023-07-19 12:55:02 +01:00
parent a8df552998
commit ab0d4d95ff
7 changed files with 124 additions and 31 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -52,6 +52,7 @@ Description
#include "snapParameters.H" #include "snapParameters.H"
#include "layerParameters.H" #include "layerParameters.H"
#include "vtkCoordSetWriter.H" #include "vtkCoordSetWriter.H"
#include "vtkSurfaceWriter.H"
#include "faceSet.H" #include "faceSet.H"
#include "motionSmoother.H" #include "motionSmoother.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
@ -859,19 +860,36 @@ int main(int argc, char *argv[])
// Writer for writing lines // Writer for writing lines
autoPtr<coordSetWriter> setFormatter; autoPtr<coordSetWriter> setFormatter;
{ {
const word setFormat const word writerType
( (
meshDict.getOrDefault<word> meshDict.getOrDefault<word>
( (
"setFormat", "setFormat",
coordSetWriters::vtkWriter::typeName // Default: "vtk" coordSetWriters::vtkWriter::typeName // Default: "vtk"
) )
); );
setFormatter = coordSetWriter::New setFormatter = coordSetWriter::New
( (
setFormat, writerType,
meshDict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat) meshDict.subOrEmptyDict("formatOptions").optionalSubDict(writerType)
);
}
// Writer for writing surfaces
refPtr<surfaceWriter> surfFormatter;
{
const word type
(
meshDict.getOrDefault<word>
(
"surfaceFormat",
surfaceWriters::vtkWriter::typeName // Default: "vtk"
)
);
surfFormatter = surfaceWriter::New
(
type,
meshDict.subOrEmptyDict("formatOptions").optionalSubDict(type)
); );
} }
@ -1774,6 +1792,7 @@ int main(int argc, char *argv[])
globalToMasterPatch, globalToMasterPatch,
globalToSlavePatch, globalToSlavePatch,
setFormatter(), setFormatter(),
surfFormatter,
dryRun dryRun
); );

View File

@ -868,6 +868,9 @@ meshQualityControls
//// Format for writing lines. E.g. leak path. Default is vtk format. //// Format for writing lines. E.g. leak path. Default is vtk format.
//setFormat ensight; //setFormat ensight;
//// Format to use for surfaces. E.g. leak-closure faces. Default is vtk format.
//surfaceFormat vtk;
// Merge tolerance. Is fraction of overall bounding box of initial mesh. // Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this. // Note: the write tolerance needs to be higher than this.
mergeTolerance 1e-6; mergeTolerance 1e-6;

View File

@ -60,6 +60,7 @@ SourceFiles
#include "volumeType.H" #include "volumeType.H"
#include "DynamicField.H" #include "DynamicField.H"
#include "coordSetWriter.H" #include "coordSetWriter.H"
#include "surfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -613,6 +614,7 @@ private:
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
const labelList& neiLevel, const labelList& neiLevel,
const pointField& neiCc, const pointField& neiCc,
@ -873,6 +875,7 @@ private:
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
labelList& cellToZone, labelList& cellToZone,
labelList& unnamedRegion1, labelList& unnamedRegion1,
@ -1343,7 +1346,8 @@ public:
const wordList& regionsInMesh, const wordList& regionsInMesh,
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter
); );
//- Merge free-standing baffles //- Merge free-standing baffles
@ -1375,7 +1379,8 @@ public:
const wordList& regionsInMesh, const wordList& regionsInMesh,
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter
); );
//- Remove cells from limitRegions if level -1 //- Remove cells from limitRegions if level -1
@ -1479,6 +1484,7 @@ public:
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
wordPairHashTable& zonesToFaceZone wordPairHashTable& zonesToFaceZone
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2014 OpenFOAM Foundation Copyright (C) 2011-2014 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -291,6 +291,7 @@ void Foam::meshRefinement::getBafflePatches
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
const labelList& neiLevel, const labelList& neiLevel,
const pointField& neiCc, const pointField& neiCc,
@ -326,6 +327,7 @@ void Foam::meshRefinement::getBafflePatches
locationsOutsideMesh, locationsOutsideMesh,
exitIfLeakPath, exitIfLeakPath,
leakPathFormatter, leakPathFormatter,
surfFormatter,
cellToZone, cellToZone,
unnamedRegion1, unnamedRegion1,
@ -2848,6 +2850,7 @@ void Foam::meshRefinement::zonify
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
labelList& cellToZone, labelList& cellToZone,
labelList& unnamedRegion1, labelList& unnamedRegion1,
@ -3221,27 +3224,66 @@ void Foam::meshRefinement::zonify
str.write(mesh_.points()[pointi]); str.write(mesh_.points()[pointi]);
} }
} }
if (debug && returnReduceOr(unnamedClosureFaces.size()))
if (returnReduceOr(unnamedClosureFaces.size()) && surfFormatter)
{ {
mkDir(mesh_.time().timePath()); fileName outputName
OBJstream str(mesh_.time().timePath()/"unnamedClosureFaces.obj"); (
Pout<< "Writing " << unnamedClosureFaces.size() mesh_.time().globalPath()
<< " unnamedClosureFaces to " << str.name() << endl; / functionObject::outputPrefix
for (const label facei : unnamedClosureFaces) / mesh_.pointsInstance()
{ / "unnamedClosureFaces"
str.write(mesh_.faces()[facei], mesh_.points(), false); );
} outputName.clean(); // Remove unneeded ".."
Info<< "Writing "
<< returnReduce(unnamedClosureFaces.size(), sumOp<label>())
<< " unnamedClosureFaces to " << outputName << endl;
const indirectPrimitivePatch setPatch
(
IndirectList<face>(mesh_.faces(), unnamedClosureFaces),
mesh_.points()
);
surfFormatter->open
(
setPatch.localPoints(),
setPatch.localFaces(),
outputName
);
surfFormatter->write();
surfFormatter->clear();
} }
if (debug && returnReduceOr(namedClosureFaces.size())) if (returnReduceOr(namedClosureFaces.size()) && surfFormatter)
{ {
mkDir(mesh_.time().timePath()); fileName outputName
OBJstream str(mesh_.time().timePath()/"namedClosureFaces.obj"); (
Pout<< "Writing " << namedClosureFaces.size() mesh_.time().globalPath()
<< " namedClosureFaces to " << str.name() << endl; / functionObject::outputPrefix
for (const label facei : namedClosureFaces) / mesh_.pointsInstance()
{ / "namedClosureFaces"
str.write(mesh_.faces()[facei], mesh_.points(), false); );
} outputName.clean(); // Remove unneeded ".."
Info<< "Writing "
<< returnReduce(namedClosureFaces.size(), sumOp<label>())
<< " namedClosureFaces to " << outputName << endl;
const indirectPrimitivePatch setPatch
(
IndirectList<face>(mesh_.faces(), namedClosureFaces),
mesh_.points()
);
surfFormatter->open
(
setPatch.localPoints(),
setPatch.localFaces(),
outputName
);
surfFormatter->write();
surfFormatter->clear();
} }
} }
@ -4541,7 +4583,8 @@ void Foam::meshRefinement::baffleAndSplitMesh
const wordList& zonesInMesh, const wordList& zonesInMesh,
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter
) )
{ {
// Introduce baffles // Introduce baffles
@ -4560,6 +4603,8 @@ void Foam::meshRefinement::baffleAndSplitMesh
calcNeighbourData(neiLevel, neiCc); calcNeighbourData(neiLevel, neiCc);
labelList ownPatch, neiPatch; labelList ownPatch, neiPatch;
refPtr<surfaceWriter> dummyWriter(nullptr);
getBafflePatches getBafflePatches
( (
nErodeCellZones, nErodeCellZones,
@ -4570,6 +4615,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
locationsOutsideMesh, locationsOutsideMesh,
exitIfLeakPath, exitIfLeakPath,
refPtr<coordSetWriter>(nullptr), refPtr<coordSetWriter>(nullptr),
dummyWriter,
neiLevel, neiLevel,
neiCc, neiCc,
@ -4635,6 +4681,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
calcNeighbourData(neiLevel, neiCc); calcNeighbourData(neiLevel, neiCc);
labelList ownPatch, neiPatch; labelList ownPatch, neiPatch;
refPtr<surfaceWriter> dummyWriter(nullptr);
getBafflePatches getBafflePatches
( (
nErodeCellZones, nErodeCellZones,
@ -4645,6 +4692,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
locationsOutsideMesh, locationsOutsideMesh,
exitIfLeakPath, exitIfLeakPath,
refPtr<coordSetWriter>(nullptr), refPtr<coordSetWriter>(nullptr),
dummyWriter,
neiLevel, neiLevel,
neiCc, neiCc,
@ -4819,7 +4867,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::splitMesh
const wordList& zonesInMesh, const wordList& zonesInMesh,
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter
) )
{ {
// Determine patches to put intersections into // Determine patches to put intersections into
@ -4843,6 +4892,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::splitMesh
locationsOutsideMesh, locationsOutsideMesh,
exitIfLeakPath, exitIfLeakPath,
leakPathFormatter, leakPathFormatter,
surfFormatter,
neiLevel, neiLevel,
neiCc, neiCc,
@ -5384,6 +5434,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::removeLimitShells
// Find intersections with all unnamed(!) surfaces // Find intersections with all unnamed(!) surfaces
labelList ownPatch, neiPatch; labelList ownPatch, neiPatch;
refPtr<surfaceWriter> dummyWriter(nullptr);
getBafflePatches getBafflePatches
( (
nErodeCellZones, nErodeCellZones,
@ -5394,6 +5445,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::removeLimitShells
locationsOutsideMesh, locationsOutsideMesh,
false, // do not exit. Use leak-closure instead. false, // do not exit. Use leak-closure instead.
refPtr<coordSetWriter>(nullptr), refPtr<coordSetWriter>(nullptr),
dummyWriter,
neiLevel, neiLevel,
neiCc, neiCc,
@ -5705,6 +5757,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
const pointField& locationsOutsideMesh, const pointField& locationsOutsideMesh,
const bool exitIfLeakPath, const bool exitIfLeakPath,
const refPtr<coordSetWriter>& leakPathFormatter, const refPtr<coordSetWriter>& leakPathFormatter,
refPtr<surfaceWriter>& surfFormatter,
wordPairHashTable& zonesToFaceZone wordPairHashTable& zonesToFaceZone
) )
{ {
@ -5787,6 +5840,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
locationsOutsideMesh, locationsOutsideMesh,
exitIfLeakPath, exitIfLeakPath,
leakPathFormatter, leakPathFormatter,
surfFormatter,
cellToZone, cellToZone,
unnamedRegion1, unnamedRegion1,

View File

@ -68,6 +68,7 @@ Foam::snappyRefineDriver::snappyRefineDriver
const labelUList& globalToMasterPatch, const labelUList& globalToMasterPatch,
const labelUList& globalToSlavePatch, const labelUList& globalToSlavePatch,
coordSetWriter& setFormatter, coordSetWriter& setFormatter,
refPtr<surfaceWriter>& surfFormatter,
const bool dryRun const bool dryRun
) )
: :
@ -77,6 +78,7 @@ Foam::snappyRefineDriver::snappyRefineDriver
globalToMasterPatch_(globalToMasterPatch), globalToMasterPatch_(globalToMasterPatch),
globalToSlavePatch_(globalToSlavePatch), globalToSlavePatch_(globalToSlavePatch),
setFormatter_(setFormatter), setFormatter_(setFormatter),
surfFormatter_(surfFormatter),
dryRun_(dryRun) dryRun_(dryRun)
{} {}
@ -1810,7 +1812,8 @@ void Foam::snappyRefineDriver::removeInsideCells
refineParams.zonesInMesh(), refineParams.zonesInMesh(),
refineParams.locationsOutsideMesh(), refineParams.locationsOutsideMesh(),
!refineParams.useLeakClosure(), !refineParams.useLeakClosure(),
setFormatter_ setFormatter_,
surfFormatter_
); );
if (debug&meshRefinement::MESH) if (debug&meshRefinement::MESH)
@ -2793,7 +2796,8 @@ void Foam::snappyRefineDriver::baffleAndSplitMesh
refineParams.zonesInMesh(), refineParams.zonesInMesh(),
refineParams.locationsOutsideMesh(), refineParams.locationsOutsideMesh(),
!refineParams.useLeakClosure(), !refineParams.useLeakClosure(),
setFormatter_ setFormatter_,
surfFormatter_
); );
@ -2859,6 +2863,7 @@ void Foam::snappyRefineDriver::zonify
refineParams.locationsOutsideMesh(), refineParams.locationsOutsideMesh(),
!refineParams.useLeakClosure(), !refineParams.useLeakClosure(),
setFormatter_, setFormatter_,
surfFormatter_,
zonesToFaceZone zonesToFaceZone
); );
@ -2931,7 +2936,8 @@ void Foam::snappyRefineDriver::splitAndMergeBaffles
refineParams.zonesInMesh(), refineParams.zonesInMesh(),
refineParams.locationsOutsideMesh(), refineParams.locationsOutsideMesh(),
!refineParams.useLeakClosure(), !refineParams.useLeakClosure(),
setFormatter_ setFormatter_,
surfFormatter_
); );
// Merge free-standing baffles always // Merge free-standing baffles always

View File

@ -85,6 +85,9 @@ class snappyRefineDriver
//- How to write lines. Used e.g. when writing leak-paths //- How to write lines. Used e.g. when writing leak-paths
coordSetWriter& setFormatter_; coordSetWriter& setFormatter_;
//- How to write surfaces. Used e.g. when writing leak closure faces
refPtr<surfaceWriter>& surfFormatter_;
//- Are we operating in test mode? //- Are we operating in test mode?
const bool dryRun_; const bool dryRun_;
@ -276,6 +279,7 @@ public:
const labelUList& globalToMasterPatch, const labelUList& globalToMasterPatch,
const labelUList& globalToSlavePatch, const labelUList& globalToSlavePatch,
coordSetWriter& setFormatter, coordSetWriter& setFormatter,
refPtr<surfaceWriter>& surfFormatter,
const bool dryRun = false const bool dryRun = false
); );

View File

@ -15,6 +15,7 @@ runApplication blockMesh
runParallel -s decompose redistributePar -decompose -constant $fileHandler runParallel -s decompose redistributePar -decompose -constant $fileHandler
runParallel snappyHexMesh -overwrite $fileHandler runParallel snappyHexMesh -overwrite $fileHandler
runParallel checkMesh -allTopology -allGeometry $fileHandler runParallel checkMesh -allTopology -allGeometry $fileHandler
runParallel -s reconstruct redistributePar -reconstruct $fileHandler
# runParallel -s redistrib $decomp16 redistributePar -constant $fileHandler # runParallel -s redistrib $decomp16 redistributePar -constant $fileHandler