65 targetVolumeToCell::typeName,
66 "\n Usage: targetVolumeToCell (nx ny nz)\n\n"
67 " Adjust plane until obtained selected volume\n\n"
73Foam::scalar Foam::targetVolumeToCell::volumeOfSet
75 const bitSet& selected
81 for (
const label celli : selected)
90Foam::label Foam::targetVolumeToCell::selectCells
92 const scalar normalComp,
97 selected.resize(mesh_.nCells());
102 forAll(mesh_.cellCentres(), celli)
104 const point& cc = mesh_.cellCentres()[celli];
106 if (maskSet.test(celli) && ((cc & normal_) < normalComp))
117void Foam::targetVolumeToCell::combine(
topoSet& set,
const bool add)
const
125 bitSet maskSet(mesh_.nCells(),
true);
126 label nTotCells = mesh_.globalData().nTotalCells();
127 if (maskSetName_.size())
132 Info<<
" Operating on subset defined by cellSet "
133 << maskSetName_ <<
endl;
140 maskSet.setMany(cellLabels.begin(), cellLabels.end());
150 scalar maxComp = -GREAT;
153 scalar minComp = GREAT;
155 const boundBox& bb = mesh_.bounds();
159 label maxPointi = -1;
162 const scalar
c = (
points[pointi] & normal_);
168 else if (c < minComp)
175 bitSet maxSelected(mesh_.nCells());
176 maxCells = selectCells(maxComp, maskSet, maxSelected);
180 if (maxCells != nTotCells)
184 <<
" selects " << maxCells
185 <<
" cells instead of all " << nTotCells
186 <<
" cells. Results might be wrong." <<
endl;
194 bitSet selected(mesh_.nCells());
195 label nSelected = -1;
196 scalar selectedVol = 0.0;
200 scalar low = minComp;
201 scalar high = maxComp;
203 const scalar tolerance = SMALL*100*(maxComp-minComp);
205 while ((high-low) > tolerance)
207 const scalar mid = 0.5*(low + high);
209 nSelected = selectCells(mid, maskSet, selected);
210 selectedVol = volumeOfSet(selected);
217 if (selectedVol < vol_)
221 bitSet highSelected(mesh_.nCells());
222 label nHigh = selectCells(high, maskSet, selected);
223 if (nSelected == nHigh)
232 bitSet lowSelected(mesh_.nCells());
233 label nLow = selectCells(low, maskSet, selected);
234 if (nSelected == nLow)
241 nSelected = selectCells(high, maskSet, selected);
242 selectedVol = volumeOfSet(selected);
244 if (selectedVol < vol_)
250 nSelected = selectCells(low, maskSet, selected);
251 selectedVol = volumeOfSet(selected);
253 if (selectedVol < vol_)
260 <<
"Did not converge onto plane. " <<
nl
262 <<
plane(high*normal_, normal_)
265 <<
plane(low*normal_, normal_)
273 Info<<
" Selected " << nSelected <<
" with actual volume "
274 << selectedVol <<
endl;
288 const word& maskSetName
294 maskSetName_(maskSetName)
307 maskSetName_(
dict.getOrDefault<
word>(
"set",
""))
335 Info<<
" Adding cells up to target volume " << vol_
336 <<
" out of total volume "
337 <<
gSum(mesh_.cellVolumes()) <<
endl;
346 Info<<
" Removing cells up to target volume " << vol_
347 <<
" out of total volume "
348 <<
gSum(mesh_.cellVolumes()) <<
endl;
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
@ NO_REGISTER
Do not request registration (bool: false).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
A bounding box defined in terms of min/max extrema points.
A collection of cell labels.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Mesh consisting of general polyhedral cells.
const scalarField & cellVolumes() const
A topoSetCellSource to select cells based on a target volume of cells. Adapts a plane until it has en...
targetVolumeToCell(const polyMesh &mesh, const scalar vol, const vector &normal, const word &maskSetName="")
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
topoSetCellSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar c
Speed of light in a vacuum.
Type gSum(const FieldField< Field, Type > &f)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
messageStream Info
Information stream (stdout output on master, null elsewhere).
MinMax< scalar > scalarMinMax
A scalar min/max range.
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
vector point
Point is a vector.
vectorField pointField
pointField is a vectorField.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.