- The bitSet class replaces the old PackedBoolList class. The redesign provides better block-wise access and reduced method calls. This helps both in cases where the bitSet may be relatively sparse, and in cases where advantage of contiguous operations can be made. This makes it easier to work with a bitSet as top-level object. In addition to the previously available count() method to determine if a bitSet is being used, now have simpler queries: - all() - true if all bits in the addressable range are empty - any() - true if any bits are set at all. - none() - true if no bits are set. These are faster than count() and allow early termination. The new test() method tests the value of a single bit position and returns a bool without any ambiguity caused by the return type (like the get() method), nor the const/non-const access (like operator[] has). The name corresponds to what std::bitset uses. The new find_first(), find_last(), find_next() methods provide a faster means of searching for bits that are set. This can be especially useful when using a bitSet to control an conditional: OLD (with macro): forAll(selected, celli) { if (selected[celli]) { sumVol += mesh_.cellVolumes()[celli]; } } NEW (with const_iterator): for (const label celli : selected) { sumVol += mesh_.cellVolumes()[celli]; } or manually for ( label celli = selected.find_first(); celli != -1; celli = selected.find_next() ) { sumVol += mesh_.cellVolumes()[celli]; } - When marking up contiguous parts of a bitset, an interval can be represented more efficiently as a labelRange of start/size. For example, OLD: if (isA<processorPolyPatch>(pp)) { forAll(pp, i) { ignoreFaces.set(i); } } NEW: if (isA<processorPolyPatch>(pp)) { ignoreFaces.set(pp.range()); }
258 lines
7.3 KiB
C
258 lines
7.3 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
|
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
|
-------------------------------------------------------------------------------
|
|
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
|
|
refineWallLayer
|
|
|
|
Group
|
|
grpMeshAdvancedUtilities
|
|
|
|
Description
|
|
Utility to refine cells next to patches.
|
|
|
|
Arguments:
|
|
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 "Time.H"
|
|
#include "polyTopoChange.H"
|
|
#include "cellCuts.H"
|
|
#include "cellSet.H"
|
|
#include "meshCutter.H"
|
|
#include "processorMeshes.H"
|
|
|
|
using namespace Foam;
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
#include "addOverwriteOption.H"
|
|
argList::addArgument("patches");
|
|
argList::addArgument("edgeFraction");
|
|
|
|
argList::addOption
|
|
(
|
|
"useSet",
|
|
"name",
|
|
"restrict cells to refine based on specified cellSet name"
|
|
);
|
|
|
|
|
|
#include "setRootCase.H"
|
|
#include "createTime.H"
|
|
runTime.functionObjects().off();
|
|
|
|
#include "createPolyMesh.H"
|
|
const word oldInstance = mesh.pointsInstance();
|
|
|
|
// Find set of patches from the list of regular expressions provided
|
|
const wordRes patches(args.readList<wordRe>(1));
|
|
const scalar weight = args.read<scalar>(2);
|
|
const bool overwrite = args.found("overwrite");
|
|
|
|
const labelHashSet patchSet(mesh.boundaryMesh().patchSet(patches));
|
|
if (!patchSet.size())
|
|
{
|
|
FatalErrorInFunction
|
|
<< "Cannot find any patches in set " << patches << endl
|
|
<< "Valid patches are " << mesh.boundaryMesh().names()
|
|
<< exit(FatalError);
|
|
}
|
|
|
|
label nPatchFaces = 0;
|
|
label nPatchEdges = 0;
|
|
|
|
for (const label patchi : patchSet)
|
|
{
|
|
nPatchFaces += mesh.boundaryMesh()[patchi].size();
|
|
nPatchEdges += mesh.boundaryMesh()[patchi].nEdges();
|
|
}
|
|
|
|
// 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
|
|
for (const label patchi : patchSet)
|
|
{
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
|
const labelList& meshPoints = pp.meshPoints();
|
|
|
|
for (const label meshPointi : meshPoints)
|
|
{
|
|
const labelList& pCells = mesh.pointCells()[meshPointi];
|
|
|
|
cutCells.insertMany(pCells);
|
|
}
|
|
}
|
|
|
|
// Edit list of cells to refine according to specified set
|
|
word setName;
|
|
if (args.readIfPresent("useSet", setName))
|
|
{
|
|
Info<< "Subsetting cells to cut based on cellSet"
|
|
<< setName << nl << endl;
|
|
|
|
cellSet cells(mesh, setName);
|
|
|
|
Info<< "Read " << cells.size() << " cells from cellSet "
|
|
<< cells.instance()/cells.local()/cells.name()
|
|
<< nl << endl;
|
|
|
|
for (const label celli : cells)
|
|
{
|
|
cutCells.erase(celli);
|
|
}
|
|
Info<< "Removed from cells to cut all the ones not in set "
|
|
<< setName << nl << endl;
|
|
}
|
|
|
|
// Mark all mesh points on patch
|
|
bitSet vertOnPatch(mesh.nPoints());
|
|
|
|
for (const label patchi : patchSet)
|
|
{
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
|
const labelList& meshPoints = pp.meshPoints();
|
|
|
|
vertOnPatch.setMany(meshPoints);
|
|
}
|
|
|
|
for (const label patchi : patchSet)
|
|
{
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
|
const labelList& meshPoints = pp.meshPoints();
|
|
|
|
for (const label meshPointi : meshPoints)
|
|
{
|
|
const labelList& pEdges = mesh.pointEdges()[meshPointi];
|
|
|
|
for (const label edgei : pEdges)
|
|
{
|
|
const edge& e = mesh.edges()[edgei];
|
|
|
|
label otherPointi = e.otherVertex(meshPointi);
|
|
|
|
if (!vertOnPatch.test(otherPointi))
|
|
{
|
|
allCutEdges.append(edgei);
|
|
|
|
if (e.start() == meshPointi)
|
|
{
|
|
allCutEdgeWeights.append(weight);
|
|
}
|
|
else
|
|
{
|
|
allCutEdgeWeights.append(1 - weight);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
allCutEdges.shrink();
|
|
allCutEdgeWeights.shrink();
|
|
|
|
Info<< "Refining:" << nl
|
|
<< " cells:" << cutCells.size() << nl
|
|
<< " edges:" << allCutEdges.size() << 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(), // cut vertices
|
|
allCutEdges, // cut edges
|
|
cutEdgeWeights // weight on cut edges
|
|
);
|
|
|
|
polyTopoChange meshMod(mesh);
|
|
|
|
// Cutting engine
|
|
meshCutter cutter(mesh);
|
|
|
|
// Insert mesh refinement into polyTopoChange.
|
|
cutter.setRefinement(cuts, meshMod);
|
|
|
|
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());
|
|
|
|
Info<< "Finished refining" << endl;
|
|
|
|
if (overwrite)
|
|
{
|
|
mesh.setInstance(oldInstance);
|
|
}
|
|
|
|
// Write resulting mesh
|
|
Info<< "Writing refined mesh to time " << runTime.timeName() << endl;
|
|
|
|
mesh.write();
|
|
topoSet::removeFiles(mesh);
|
|
processorMeshes::removeFiles(mesh);
|
|
|
|
Info<< "End\n" << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|