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,
93 const bitSet& maskSet,
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))
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;
137 cellSet
subset(mesh_, maskSetName_);
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)
183 <<
"Plane " << plane(
points[maxPointi], normal_)
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;
277 addOrDelete(set, selected,
add);
288 const word& maskSetName
294 maskSetName_(maskSetName)
321 vol_(readScalar(checkIs(is))),
338 Info<<
" Adding cells up to target volume " << vol_
339 <<
" out of total volume "
340 <<
gSum(mesh_.cellVolumes()) <<
endl;
349 Info<<
" Removing cells up to target volume " << vol_
350 <<
" out of total volume "
351 <<
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.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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...
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.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
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.
const polyMesh & mesh_
Reference to the mesh.
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)
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
vector point
Point is a vector.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.