2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Description
|
|
|
|
Divides external faces into patches based on (user supplied) feature
|
|
|
|
angle.
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
|
|
|
#include "polyMesh.H"
|
|
|
|
#include "Time.H"
|
|
|
|
#include "boundaryMesh.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
#include "repatchPolyTopoChanger.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "mathematicalConstants.H"
|
|
|
|
#include "OFstream.H"
|
|
|
|
#include "ListOps.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Get all feature edges.
|
|
|
|
void collectFeatureEdges(const boundaryMesh& bMesh, labelList& markedEdges)
|
|
|
|
{
|
|
|
|
markedEdges.setSize(bMesh.mesh().nEdges());
|
|
|
|
|
|
|
|
label markedI = 0;
|
|
|
|
|
|
|
|
forAll(bMesh.featureSegments(), i)
|
|
|
|
{
|
|
|
|
const labelList& segment = bMesh.featureSegments()[i];
|
|
|
|
|
|
|
|
forAll(segment, j)
|
|
|
|
{
|
|
|
|
label featEdgeI = segment[j];
|
|
|
|
|
|
|
|
label meshEdgeI = bMesh.featureToEdge()[featEdgeI];
|
|
|
|
|
|
|
|
markedEdges[markedI++] = meshEdgeI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
markedEdges.setSize(markedI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
argList::noParallel();
|
|
|
|
argList::validArgs.append("feature angle[0-180]");
|
|
|
|
argList::validOptions.insert("overwrite", "");
|
|
|
|
|
|
|
|
# include "setRootCase.H"
|
|
|
|
# include "createTime.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
runTime.functionObjects().off();
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "createPolyMesh.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
const word oldInstance = mesh.pointsInstance();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Mesh read in = "
|
|
|
|
<< runTime.cpuTimeIncrement()
|
|
|
|
<< " s\n" << endl << endl;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Use boundaryMesh to reuse all the featureEdge stuff in there.
|
|
|
|
//
|
|
|
|
|
|
|
|
boundaryMesh bMesh;
|
|
|
|
|
|
|
|
scalar featureAngle(readScalar(IStringStream(args.additionalArgs()[0])()));
|
2010-08-25 21:42:57 +00:00
|
|
|
bool overwrite = args.optionFound("overwrite");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
scalar minCos = Foam::cos(featureAngle * mathematicalConstant::pi/180.0);
|
|
|
|
|
|
|
|
Info<< "Feature:" << featureAngle << endl
|
|
|
|
<< "minCos :" << minCos << endl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
bMesh.read(mesh);
|
|
|
|
|
|
|
|
// Set feature angle (calculate feature edges)
|
|
|
|
bMesh.setFeatureEdges(minCos);
|
|
|
|
|
|
|
|
// Collect all feature edges as edge labels
|
|
|
|
labelList markedEdges;
|
|
|
|
|
|
|
|
collectFeatureEdges(bMesh, markedEdges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (new) patch ID for every face in mesh.
|
|
|
|
labelList patchIDs(bMesh.mesh().size(), -1);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill patchIDs with values for every face by floodfilling without
|
|
|
|
// crossing feature edge.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Current patch number.
|
|
|
|
label newPatchI = bMesh.patches().size();
|
|
|
|
|
|
|
|
label suffix = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
// Find first unset face.
|
|
|
|
label unsetFaceI = findIndex(patchIDs, -1);
|
|
|
|
|
|
|
|
if (unsetFaceI == -1)
|
|
|
|
{
|
|
|
|
// All faces have patchID set. Exit.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found unset face. Create patch for it.
|
|
|
|
word patchName;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
patchName = "auto" + name(suffix++);
|
|
|
|
}
|
|
|
|
while (bMesh.findPatchID(patchName) != -1);
|
|
|
|
|
|
|
|
bMesh.addPatch(patchName);
|
|
|
|
|
|
|
|
bMesh.changePatchType(patchName, "patch");
|
|
|
|
|
|
|
|
|
|
|
|
// Fill visited with all faces reachable from unsetFaceI.
|
|
|
|
boolList visited(bMesh.mesh().size());
|
|
|
|
|
|
|
|
bMesh.markFaces(markedEdges, unsetFaceI, visited);
|
|
|
|
|
|
|
|
|
|
|
|
// Assign all visited faces to current patch
|
|
|
|
label nVisited = 0;
|
|
|
|
|
|
|
|
forAll(visited, faceI)
|
|
|
|
{
|
|
|
|
if (visited[faceI])
|
|
|
|
{
|
|
|
|
nVisited++;
|
|
|
|
|
|
|
|
patchIDs[faceI] = newPatchI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "Assigned " << nVisited << " faces to patch " << patchName
|
|
|
|
<< endl << endl;
|
|
|
|
|
|
|
|
newPatchI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const PtrList<boundaryPatch>& patches = bMesh.patches();
|
|
|
|
|
|
|
|
// Create new list of patches with old ones first
|
|
|
|
List<polyPatch*> newPatchPtrList(patches.size());
|
|
|
|
|
|
|
|
newPatchI = 0;
|
|
|
|
|
|
|
|
// Copy old patches
|
|
|
|
forAll(mesh.boundaryMesh(), patchI)
|
|
|
|
{
|
|
|
|
const polyPatch& patch = mesh.boundaryMesh()[patchI];
|
|
|
|
|
|
|
|
newPatchPtrList[newPatchI] =
|
|
|
|
patch.clone
|
|
|
|
(
|
|
|
|
mesh.boundaryMesh(),
|
|
|
|
newPatchI,
|
|
|
|
patch.size(),
|
|
|
|
patch.start()
|
|
|
|
).ptr();
|
|
|
|
|
|
|
|
newPatchI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new ones with empty size.
|
|
|
|
for (label patchI = newPatchI; patchI < patches.size(); patchI++)
|
|
|
|
{
|
|
|
|
const boundaryPatch& bp = patches[patchI];
|
|
|
|
|
|
|
|
newPatchPtrList[newPatchI] = polyPatch::New
|
|
|
|
(
|
|
|
|
polyPatch::typeName,
|
|
|
|
bp.name(),
|
|
|
|
0,
|
|
|
|
mesh.nFaces(),
|
|
|
|
newPatchI,
|
|
|
|
mesh.boundaryMesh()
|
|
|
|
).ptr();
|
|
|
|
|
|
|
|
newPatchI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overwrite)
|
|
|
|
{
|
|
|
|
runTime++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Change patches
|
2010-08-25 21:42:57 +00:00
|
|
|
repatchPolyTopoChanger polyMeshRepatcher(mesh);
|
2010-05-12 13:27:55 +00:00
|
|
|
polyMeshRepatcher.changePatches(newPatchPtrList);
|
|
|
|
|
|
|
|
|
|
|
|
// Change face ordering
|
|
|
|
|
|
|
|
// Since bMesh read from mesh there is one to one mapping so we don't
|
|
|
|
// have to do the geometric stuff.
|
|
|
|
const labelList& meshFace = bMesh.meshFace();
|
|
|
|
|
|
|
|
forAll(patchIDs, faceI)
|
|
|
|
{
|
|
|
|
label meshFaceI = meshFace[faceI];
|
|
|
|
|
|
|
|
polyMeshRepatcher.changePatchID(meshFaceI, patchIDs[faceI]);
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
polyMeshRepatcher.repatch();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Write resulting mesh
|
2010-08-25 21:42:57 +00:00
|
|
|
if (overwrite)
|
|
|
|
{
|
|
|
|
mesh.setInstance(oldInstance);
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
mesh.write();
|
|
|
|
|
|
|
|
|
|
|
|
Info<< "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|