2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2016-06-20 15:00:40 +00:00
|
|
|
\\ / O peration | Version: 4.0
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / 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
|
2010-08-25 21:42:57 +00:00
|
|
|
Utility to refine cells next to patches.
|
|
|
|
|
|
|
|
Takes a patchName and number of layers to refine. Works out cells within
|
|
|
|
these layers and refines those in the wall-normal direction.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
2013-11-03 20:28:05 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "directTopoChange.H"
|
|
|
|
#include "mapPolyMesh.H"
|
|
|
|
#include "polyMesh.H"
|
|
|
|
#include "cellCuts.H"
|
|
|
|
#include "cellSet.H"
|
|
|
|
#include "meshCutter.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
Foam::argList::noParallel();
|
|
|
|
Foam::argList::validArgs.append("patchName");
|
|
|
|
Foam::argList::validArgs.append("edgeWeight");
|
|
|
|
Foam::argList::validOptions.insert("useSet", "cellSet");
|
|
|
|
Foam::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
|
|
|
|
|
|
|
word patchName(args.additionalArgs()[0]);
|
|
|
|
|
|
|
|
scalar weight(readScalar(IStringStream(args.additionalArgs()[1])()));
|
2010-08-25 21:42:57 +00:00
|
|
|
bool overwrite = args.optionFound("overwrite");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
label patchID = mesh.boundaryMesh().findPatchID(patchName);
|
|
|
|
|
|
|
|
if (patchID == -1)
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Cannot find patch " << patchName << endl
|
|
|
|
<< "Valid patches are " << mesh.boundaryMesh().names()
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchID];
|
|
|
|
|
|
|
|
|
|
|
|
// Cells cut
|
|
|
|
|
|
|
|
labelHashSet cutCells(4*pp.size());
|
|
|
|
|
|
|
|
const labelList& meshPoints = pp.meshPoints();
|
|
|
|
|
|
|
|
forAll(meshPoints, pointI)
|
|
|
|
{
|
|
|
|
label meshPointI = meshPoints[pointI];
|
|
|
|
|
|
|
|
const labelList& pCells = mesh.pointCells()[meshPointI];
|
|
|
|
|
|
|
|
forAll(pCells, pCellI)
|
|
|
|
{
|
|
|
|
cutCells.insert(pCells[pCellI]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "Selected " << cutCells.size()
|
|
|
|
<< " cells connected to patch " << pp.name() << endl << endl;
|
|
|
|
|
|
|
|
//
|
|
|
|
// List of cells to refine
|
|
|
|
//
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
bool useSet = args.optionFound("useSet");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (useSet)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
word setName(args.option("useSet"));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Subsetting cells to cut based on cellSet" << setName << endl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
cellSet cells(mesh, setName);
|
|
|
|
|
|
|
|
Info<< "Read " << cells.size() << " cells from cellSet "
|
|
|
|
<< cells.instance()/cells.local()/cells.name()
|
|
|
|
<< endl << endl;
|
|
|
|
|
|
|
|
for
|
|
|
|
(
|
|
|
|
cellSet::const_iterator iter = cells.begin();
|
|
|
|
iter != cells.end();
|
|
|
|
++iter
|
|
|
|
)
|
|
|
|
{
|
|
|
|
cutCells.erase(iter.key());
|
|
|
|
}
|
|
|
|
Info<< "Removed from cells to cut all the ones not in set " << setName
|
|
|
|
<< endl << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark all meshpoints on patch
|
|
|
|
|
|
|
|
boolList vertOnPatch(mesh.nPoints(), false);
|
|
|
|
|
|
|
|
forAll(meshPoints, pointI)
|
|
|
|
{
|
|
|
|
label meshPointI = meshPoints[pointI];
|
|
|
|
|
|
|
|
vertOnPatch[meshPointI] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Mark cut edges.
|
|
|
|
|
|
|
|
DynamicList<label> allCutEdges(pp.nEdges());
|
|
|
|
|
|
|
|
DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
|
|
|
|
|
|
|
|
forAll(meshPoints, pointI)
|
|
|
|
{
|
|
|
|
label meshPointI = meshPoints[pointI];
|
|
|
|
|
|
|
|
const labelList& pEdges = mesh.pointEdges()[meshPointI];
|
|
|
|
|
|
|
|
forAll(pEdges, pEdgeI)
|
|
|
|
{
|
|
|
|
label edgeI = pEdges[pEdgeI];
|
|
|
|
|
|
|
|
const edge& e = mesh.edges()[edgeI];
|
|
|
|
|
|
|
|
label otherPointI = e.otherVertex(meshPointI);
|
|
|
|
|
|
|
|
if (!vertOnPatch[otherPointI])
|
|
|
|
{
|
|
|
|
allCutEdges.append(edgeI);
|
|
|
|
|
|
|
|
if (e.start() == meshPointI)
|
|
|
|
{
|
|
|
|
allCutEdgeWeights.append(weight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
allCutEdgeWeights.append(1 - weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allCutEdges.shrink();
|
|
|
|
allCutEdgeWeights.shrink();
|
|
|
|
|
|
|
|
Info<< "Cutting:" << endl
|
|
|
|
<< " cells:" << cutCells.size() << endl
|
|
|
|
<< " edges:" << allCutEdges.size() << endl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
// Transfer DynamicLists to straight ones.
|
|
|
|
scalarField cutEdgeWeights;
|
|
|
|
cutEdgeWeights.transfer(allCutEdgeWeights);
|
|
|
|
allCutEdgeWeights.clear();
|
|
|
|
|
|
|
|
|
|
|
|
// Gets cuts across cells from cuts through edges.
|
|
|
|
cellCuts cuts
|
|
|
|
(
|
|
|
|
mesh,
|
|
|
|
cutCells.toc(), // cells candidate for cutting
|
|
|
|
labelList(0), // cut vertices
|
2010-08-25 21:42:57 +00:00
|
|
|
allCutEdges, // cut edges
|
2010-05-12 13:27:55 +00:00
|
|
|
cutEdgeWeights // weight on cut edges
|
|
|
|
);
|
|
|
|
|
|
|
|
directTopoChange meshMod(mesh);
|
|
|
|
|
|
|
|
// Cutting engine
|
|
|
|
meshCutter cutter(mesh);
|
|
|
|
|
|
|
|
// Insert mesh refinement into directTopoChange.
|
|
|
|
cutter.setRefinement(cuts, meshMod);
|
|
|
|
|
|
|
|
// Do all changes
|
|
|
|
Info<< "Morphing ..." << endl;
|
|
|
|
|
|
|
|
if (!overwrite)
|
|
|
|
{
|
|
|
|
runTime++;
|
|
|
|
}
|
|
|
|
|
|
|
|
autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
|
|
|
|
|
|
|
|
if (morphMap().hasMotionPoints())
|
|
|
|
{
|
|
|
|
mesh.movePoints(morphMap().preMotionPoints());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update stored labels on meshCutter.
|
|
|
|
cutter.updateMesh(morphMap());
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (overwrite)
|
|
|
|
{
|
|
|
|
mesh.setInstance(oldInstance);
|
|
|
|
}
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
// Write resulting mesh
|
2010-08-25 21:42:57 +00:00
|
|
|
Info << "Writing refined morphMesh to time " << runTime.timeName() << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
mesh.write();
|
|
|
|
|
|
|
|
Info << "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|