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;
140 maskSet.setMany(cellLabels.begin(), cellLabels.end());
142 nTotCells =
returnReduce(cellLabels.size(), sumOp<label>());
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)
307 maskSetName_(
dict.getOrDefault<
word>(
"set",
""))
318 vol_(readScalar(checkIs(is))),
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;
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
targetVolumeToCell(const polyMesh &mesh, const scalar vol, const vector &normal, const word &maskSetName="")
Construct from components.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells...
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
vectorField pointField
pointField is a vectorField.
Type gSum(const FieldField< Field, Type > &f)
A class for handling words, derived from Foam::string.
setAction
Enumeration defining various actions.
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Subtract elements from current set.
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
const dimensionedScalar c
Speed of light in a vacuum.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Do not request registration (bool: false)
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
const scalarField & cellVolumes() const