65 targetVolumeToCell::typeName,
66 "\n Usage: targetVolumeToCell (nx ny nz)\n\n"
67 " Adjust plane until obtained selected volume\n\n"
73 Foam::scalar Foam::targetVolumeToCell::volumeOfSet
75 const bitSet& selected
81 for (
const label celli : selected)
90 Foam::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))
117 void 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;
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;