mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
refineWallLayer: Rationalize and add support for operating on a list of patch name regular expressions
Resolves bug-report http://openfoam.org/mantisbt/view.php?id=1525
This commit is contained in:
@ -27,17 +27,26 @@ Application
|
|||||||
Description
|
Description
|
||||||
Utility to refine cells next to patches.
|
Utility to refine cells next to patches.
|
||||||
|
|
||||||
Takes a patchName and number of layers to refine. Works out cells within
|
Arguments:
|
||||||
these layers and refines those in the wall-normal direction.
|
1: List of patch name regular expressions
|
||||||
|
2: The size of the refined cells as a fraction of the edge-length.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
Split the near-wall cells of patch Wall in the middle
|
||||||
|
refineWallLayer "(Wall)" 0.5
|
||||||
|
|
||||||
|
Split the near-wall cells of patches Wall1 and Wall2 in the middle
|
||||||
|
refineWallLayer "(Wall1 Wall2)" 0.5
|
||||||
|
|
||||||
|
Split the near-wall cells of all patches with names beginning with wall
|
||||||
|
with the near-wall cells 10% of the thickness of the original cells
|
||||||
|
refineWallLayer '("Wall.*")' 0.1
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "polyTopoChange.H"
|
#include "polyTopoChange.H"
|
||||||
#include "polyTopoChanger.H"
|
|
||||||
#include "mapPolyMesh.H"
|
|
||||||
#include "polyMesh.H"
|
|
||||||
#include "cellCuts.H"
|
#include "cellCuts.H"
|
||||||
#include "cellSet.H"
|
#include "cellSet.H"
|
||||||
#include "meshCutter.H"
|
#include "meshCutter.H"
|
||||||
@ -50,8 +59,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
#include "addOverwriteOption.H"
|
#include "addOverwriteOption.H"
|
||||||
argList::noParallel();
|
argList::noParallel();
|
||||||
argList::validArgs.append("patchName");
|
argList::validArgs.append("patches");
|
||||||
argList::validArgs.append("edgeWeight");
|
argList::validArgs.append("edgeFraction");
|
||||||
|
|
||||||
argList::addOption
|
argList::addOption
|
||||||
(
|
(
|
||||||
@ -64,50 +73,61 @@ int main(int argc, char *argv[])
|
|||||||
#include "setRootCase.H"
|
#include "setRootCase.H"
|
||||||
#include "createTime.H"
|
#include "createTime.H"
|
||||||
runTime.functionObjects().off();
|
runTime.functionObjects().off();
|
||||||
|
|
||||||
#include "createPolyMesh.H"
|
#include "createPolyMesh.H"
|
||||||
const word oldInstance = mesh.pointsInstance();
|
const word oldInstance = mesh.pointsInstance();
|
||||||
|
|
||||||
const word patchName = args[1];
|
// Find set of patches from the list of regular expressions provided
|
||||||
|
const wordReList patches((IStringStream(args[1])()));
|
||||||
|
const labelHashSet patchSet(mesh.boundaryMesh().patchSet(patches));
|
||||||
|
|
||||||
const scalar weight = args.argRead<scalar>(2);
|
const scalar weight = args.argRead<scalar>(2);
|
||||||
const bool overwrite = args.optionFound("overwrite");
|
const bool overwrite = args.optionFound("overwrite");
|
||||||
|
|
||||||
label patchID = mesh.boundaryMesh().findPatchID(patchName);
|
if (!patchSet.size())
|
||||||
|
|
||||||
if (patchID == -1)
|
|
||||||
{
|
{
|
||||||
FatalErrorIn(args.executable())
|
FatalErrorIn(args.executable())
|
||||||
<< "Cannot find patch " << patchName << endl
|
<< "Cannot find any patches in set " << patches << endl
|
||||||
<< "Valid patches are " << mesh.boundaryMesh().names()
|
<< "Valid patches are " << mesh.boundaryMesh().names()
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
const polyPatch& pp = mesh.boundaryMesh()[patchID];
|
|
||||||
|
|
||||||
|
label nPatchFaces = 0;
|
||||||
|
label nPatchEdges = 0;
|
||||||
|
|
||||||
// Cells cut
|
forAllConstIter(labelHashSet, patchSet, iter)
|
||||||
|
|
||||||
labelHashSet cutCells(4*pp.size());
|
|
||||||
|
|
||||||
const labelList& meshPoints = pp.meshPoints();
|
|
||||||
|
|
||||||
forAll(meshPoints, pointI)
|
|
||||||
{
|
{
|
||||||
label meshPointI = meshPoints[pointI];
|
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
|
||||||
|
nPatchEdges += mesh.boundaryMesh()[iter.key()].nEdges();
|
||||||
|
}
|
||||||
|
|
||||||
const labelList& pCells = mesh.pointCells()[meshPointI];
|
// Construct from estimate for the number of cells to refine
|
||||||
|
labelHashSet cutCells(4*nPatchFaces);
|
||||||
|
|
||||||
forAll(pCells, pCellI)
|
// Construct from total patch edges in selected patches
|
||||||
|
DynamicList<label> allCutEdges(nPatchEdges);
|
||||||
|
DynamicList<scalar> allCutEdgeWeights(nPatchEdges);
|
||||||
|
|
||||||
|
// Find cells to refine
|
||||||
|
forAllConstIter(labelHashSet, patchSet, iter)
|
||||||
|
{
|
||||||
|
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||||
|
const labelList& meshPoints = pp.meshPoints();
|
||||||
|
|
||||||
|
forAll(meshPoints, pointI)
|
||||||
{
|
{
|
||||||
cutCells.insert(pCells[pCellI]);
|
label meshPointI = meshPoints[pointI];
|
||||||
|
|
||||||
|
const labelList& pCells = mesh.pointCells()[meshPointI];
|
||||||
|
|
||||||
|
forAll(pCells, pCellI)
|
||||||
|
{
|
||||||
|
cutCells.insert(pCells[pCellI]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< "Selected " << cutCells.size()
|
// Edit list of cells to refine according to specified set
|
||||||
<< " cells connected to patch " << pp.name() << endl << endl;
|
|
||||||
|
|
||||||
//
|
|
||||||
// List of cells to refine
|
|
||||||
//
|
|
||||||
|
|
||||||
word setName;
|
word setName;
|
||||||
if (args.optionReadIfPresent("useSet", setName))
|
if (args.optionReadIfPresent("useSet", setName))
|
||||||
{
|
{
|
||||||
@ -128,48 +148,50 @@ int main(int argc, char *argv[])
|
|||||||
<< setName << nl << endl;
|
<< setName << nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark all meshpoints on patch
|
// Mark all mesh points on patch
|
||||||
|
|
||||||
boolList vertOnPatch(mesh.nPoints(), false);
|
boolList vertOnPatch(mesh.nPoints(), false);
|
||||||
|
|
||||||
forAll(meshPoints, pointI)
|
forAllConstIter(labelHashSet, patchSet, iter)
|
||||||
{
|
{
|
||||||
const label meshPointI = meshPoints[pointI];
|
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||||
|
const labelList& meshPoints = pp.meshPoints();
|
||||||
|
|
||||||
vertOnPatch[meshPointI] = true;
|
forAll(meshPoints, pointI)
|
||||||
|
{
|
||||||
|
vertOnPatch[meshPoints[pointI]] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forAllConstIter(labelHashSet, patchSet, iter)
|
||||||
// Mark cut edges.
|
|
||||||
|
|
||||||
DynamicList<label> allCutEdges(pp.nEdges());
|
|
||||||
|
|
||||||
DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
|
|
||||||
|
|
||||||
forAll(meshPoints, pointI)
|
|
||||||
{
|
{
|
||||||
label meshPointI = meshPoints[pointI];
|
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||||
|
const labelList& meshPoints = pp.meshPoints();
|
||||||
|
|
||||||
const labelList& pEdges = mesh.pointEdges()[meshPointI];
|
forAll(meshPoints, pointI)
|
||||||
|
|
||||||
forAll(pEdges, pEdgeI)
|
|
||||||
{
|
{
|
||||||
const label edgeI = pEdges[pEdgeI];
|
label meshPointI = meshPoints[pointI];
|
||||||
const edge& e = mesh.edges()[edgeI];
|
|
||||||
|
|
||||||
label otherPointI = e.otherVertex(meshPointI);
|
const labelList& pEdges = mesh.pointEdges()[meshPointI];
|
||||||
|
|
||||||
if (!vertOnPatch[otherPointI])
|
forAll(pEdges, pEdgeI)
|
||||||
{
|
{
|
||||||
allCutEdges.append(edgeI);
|
const label edgeI = pEdges[pEdgeI];
|
||||||
|
const edge& e = mesh.edges()[edgeI];
|
||||||
|
|
||||||
if (e.start() == meshPointI)
|
label otherPointI = e.otherVertex(meshPointI);
|
||||||
|
|
||||||
|
if (!vertOnPatch[otherPointI])
|
||||||
{
|
{
|
||||||
allCutEdgeWeights.append(weight);
|
allCutEdges.append(edgeI);
|
||||||
}
|
|
||||||
else
|
if (e.start() == meshPointI)
|
||||||
{
|
{
|
||||||
allCutEdgeWeights.append(1 - weight);
|
allCutEdgeWeights.append(weight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
allCutEdgeWeights.append(1 - weight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,10 +200,9 @@ int main(int argc, char *argv[])
|
|||||||
allCutEdges.shrink();
|
allCutEdges.shrink();
|
||||||
allCutEdgeWeights.shrink();
|
allCutEdgeWeights.shrink();
|
||||||
|
|
||||||
Info<< "Cutting:" << nl
|
Info<< "Refining:" << nl
|
||||||
<< " cells:" << cutCells.size() << nl
|
<< " cells:" << cutCells.size() << nl
|
||||||
<< " edges:" << allCutEdges.size() << nl
|
<< " edges:" << allCutEdges.size() << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
// Transfer DynamicLists to straight ones.
|
// Transfer DynamicLists to straight ones.
|
||||||
scalarField cutEdgeWeights;
|
scalarField cutEdgeWeights;
|
||||||
@ -207,9 +228,6 @@ int main(int argc, char *argv[])
|
|||||||
// Insert mesh refinement into polyTopoChange.
|
// Insert mesh refinement into polyTopoChange.
|
||||||
cutter.setRefinement(cuts, meshMod);
|
cutter.setRefinement(cuts, meshMod);
|
||||||
|
|
||||||
// Do all changes
|
|
||||||
Info<< "Morphing ..." << endl;
|
|
||||||
|
|
||||||
if (!overwrite)
|
if (!overwrite)
|
||||||
{
|
{
|
||||||
runTime++;
|
runTime++;
|
||||||
@ -225,13 +243,15 @@ int main(int argc, char *argv[])
|
|||||||
// Update stored labels on meshCutter.
|
// Update stored labels on meshCutter.
|
||||||
cutter.updateMesh(morphMap());
|
cutter.updateMesh(morphMap());
|
||||||
|
|
||||||
|
Info<< "Finished refining" << endl;
|
||||||
|
|
||||||
if (overwrite)
|
if (overwrite)
|
||||||
{
|
{
|
||||||
mesh.setInstance(oldInstance);
|
mesh.setInstance(oldInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write resulting mesh
|
// Write resulting mesh
|
||||||
Info<< "Writing refined morphMesh to time " << runTime.timeName() << endl;
|
Info<< "Writing refined mesh to time " << runTime.timeName() << endl;
|
||||||
|
|
||||||
mesh.write();
|
mesh.write();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user