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:
Henry
2015-02-14 22:50:59 +00:00
parent 7bb7701512
commit 04af7672af

View File

@ -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,29 +73,45 @@ 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)
{
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
nPatchEdges += mesh.boundaryMesh()[iter.key()].nEdges();
}
labelHashSet cutCells(4*pp.size()); // Construct from estimate for the number of cells to refine
labelHashSet cutCells(4*nPatchFaces);
// 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(); const labelList& meshPoints = pp.meshPoints();
forAll(meshPoints, pointI) forAll(meshPoints, pointI)
@ -100,14 +125,9 @@ int main(int argc, char *argv[])
cutCells.insert(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,23 +148,24 @@ 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);
forAllConstIter(labelHashSet, patchSet, iter)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
const labelList& meshPoints = pp.meshPoints();
forAll(meshPoints, pointI) forAll(meshPoints, pointI)
{ {
const label meshPointI = meshPoints[pointI]; vertOnPatch[meshPoints[pointI]] = true;
}
vertOnPatch[meshPointI] = true;
} }
forAllConstIter(labelHashSet, patchSet, iter)
// Mark cut edges. {
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
DynamicList<label> allCutEdges(pp.nEdges()); const labelList& meshPoints = pp.meshPoints();
DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
forAll(meshPoints, pointI) forAll(meshPoints, pointI)
{ {
@ -174,14 +195,14 @@ 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();