Commit 17cbbd0f authored by mattijs's avatar mattijs

ENH: polyMesh2D: utility to collapse meshes

parent ec114c21
collapse2DMesh.C
EXE = $(FOAM_APPBIN)/collapse2DMesh
EXE_INC = \
-DFULLDEBUG -g -O0 \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/parallel/reconstruct/reconstruct/lnInclude \
-Iextrude2DMesh/lnInclude \
-I$(LIB_SRC)/mesh/extrudeModel/lnInclude
EXE_LIBS = \
-lsurfMesh \
-ldynamicMesh \
-lreconstruct \
-lextrude2DMesh \
-lextrudeModel
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
collapse2DMesh
Group
grpMeshGenerationUtilities
Description
Takes 3D mesh with empty front and back and generate 2D version
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "polyTopoChange.H"
#include "topoSet.H"
#include "processorMeshes.H"
#include "emptyPolyPatch.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Converts 2D polyMesh into polyMesh2D"
);
//argList::addArgument("patch", "The (empty) patch giving the geometry");
argList::validArgs.append("patch");
#include "addOverwriteOption.H"
#include "setRootCase.H"
#include "createTime.H"
#include "createPolyMesh.H"
const word oldInstance = mesh.pointsInstance();
const word patchName = args[1];
//const bool overwrite = args.found("overwrite");
const bool overwrite = args.optionFound("overwrite");
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const label keepPatchi = pbm.findPatchID(patchName);
if (keepPatchi == -1 || !isA<emptyPolyPatch>(pbm[keepPatchi]))
{
FatalErrorInFunction
<< "Patch " << patchName << " does not exist or is not empty"
<< exit(FatalError);
}
// Constructing a 2D mesh
polyTopoChange meshMod(mesh, true, 2);
const labelList& own = mesh.faceOwner();
const labelList& nei = mesh.faceNeighbour();
for (label facei = 0; facei < mesh.nInternalFaces(); ++facei)
{
face f(2);
f[0] = mesh.faces()[facei][0];
f[1] = mesh.faces()[facei][1];
meshMod.modifyFace
(
f,
facei,
own[facei],
nei[facei],
false,
-1,
-1,
false
);
}
forAll(pbm, patchi)
{
const polyPatch& pp = pbm[patchi];
if (!isA<emptyPolyPatch>(pp)) // || patchi == keepPatchi)
{
forAll(pp, patchFacei)
{
face f(2);
f[0] = pp[patchFacei][0];
f[1] = pp[patchFacei][1];
label meshFacei = pp.start()+patchFacei;
meshMod.modifyFace
(
f,
meshFacei,
own[meshFacei],
-1,
false,
patchi,
-1,
false
);
}
}
else
{
forAll(pp, patchFacei)
{
meshMod.removeFace(pp.start()+patchFacei, -1);
}
}
}
// Create a mesh from topo changes.
autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
mesh.updateMesh(morphMap);
if (!overwrite)
{
runTime++;
}
else
{
mesh.setInstance(oldInstance);
}
Info<< "\nWriting collapsed mesh to time = " << runTime.timeName()
<< nl << endl;
mesh.write();
//topoSet::removeFiles(mesh); // only (boundary)faceSets are wrong
processorMeshes::removeFiles(mesh);
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
......@@ -404,7 +404,14 @@ void Foam::polyTopoChange::checkFace
}
}
if (f.size() < 3 || findIndex(f, -1) != -1)
if
(
(
(nTopologicalD_ == 3 && f.size() < 3)
|| (nTopologicalD_ == 2 && f.size() != 2)
)
|| findIndex(f, -1) != -1
)
{
FatalErrorInFunction
<< "Illegal vertices in face"
......@@ -1100,7 +1107,14 @@ void Foam::polyTopoChange::compact
//labelList oldF(f);
renumberCompact(localPointMap, f);
if (!faceRemoved(facei) && f.size() < 3)
if
(
!faceRemoved(facei)
&& (
(nTopologicalD_ == 3 && f.size() < 3)
|| (nTopologicalD_ == 2 && f.size() != 2)
)
)
{
FatalErrorInFunction
<< "Created illegal face " << f
......@@ -2181,9 +2195,15 @@ void Foam::polyTopoChange::compactAndReorder
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::polyTopoChange::polyTopoChange(const label nPatches, const bool strict)
Foam::polyTopoChange::polyTopoChange
(
const label nPatches,
const bool strict,
const label nTopologicalD
)
:
strict_(strict),
nTopologicalD_(nTopologicalD),
nPatches_(nPatches),
points_(0),
pointMap_(0),
......@@ -2208,17 +2228,24 @@ Foam::polyTopoChange::polyTopoChange(const label nPatches, const bool strict)
cellFromEdge_(0),
cellFromFace_(0),
cellZone_(0)
{}
{
if (nTopologicalD_ != 2 && nTopologicalD_ != 3)
{
FatalErrorInFunction << "Only 3D and 2D supported" << exit(FatalError);
}
}
// Construct from components
Foam::polyTopoChange::polyTopoChange
(
const polyMesh& mesh,
const bool strict
const bool strict,
const label nTopologicalD
)
:
strict_(strict),
nTopologicalD_(nTopologicalD),
nPatches_(0),
points_(0),
pointMap_(0),
......@@ -2244,6 +2271,10 @@ Foam::polyTopoChange::polyTopoChange
cellFromFace_(0),
cellZone_(0)
{
if (nTopologicalD_ != 2 && nTopologicalD_ != 3)
{
FatalErrorInFunction << "Only 3D and 2D supported" << exit(FatalError);
}
addMesh
(
mesh,
......
......@@ -103,6 +103,9 @@ class polyTopoChange
// when adding/removing data.
bool strict_;
//- Type of mesh to generate: 3D (default) or 2D (faMesh)
label nTopologicalD_;
// Patches
......@@ -408,10 +411,20 @@ public:
//- Construct without mesh. Either specify nPatches or use
// setNumPatches before trying to make a mesh (makeMesh, changeMesh)
polyTopoChange(const label nPatches, const bool strict = true);
polyTopoChange
(
const label nPatches,
const bool strict = true,
const label nTopologicalD = 3
);
//- Construct from mesh. Adds all points/face/cells from mesh.
polyTopoChange(const polyMesh& mesh, const bool strict = true);
polyTopoChange
(
const polyMesh& mesh,
const bool strict = true,
const label nTopologicalD = 3
);
// Member Functions
......
Markdown is supported
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