45 targetVolumeToCell::typeName,
46 "\n Usage: targetVolumeToCell (nx ny nz)\n\n" 47 " Adjust plane until obtained selected volume\n\n" 53 Foam::scalar Foam::targetVolumeToCell::volumeOfSet
55 const PackedBoolList& selected
63 sumVol += mesh_.cellVolumes()[celli];
72 const scalar normalComp,
73 const PackedBoolList& maskSet,
74 PackedBoolList& selected
77 selected.setSize(mesh_.nCells());
82 forAll(mesh_.cellCentres(), celli)
84 const point& cc = mesh_.cellCentres()[celli];
86 if (maskSet[celli] && ((cc&n_) < normalComp))
88 selected[celli] =
true;
96 void Foam::targetVolumeToCell::combine(topoSet&
set,
const bool add)
const 105 PackedBoolList maskSet(mesh_.nCells(), 1);
106 label nTotCells = mesh_.globalData().nTotalCells();
107 if (maskSetName_.size())
110 Info<<
" Operating on subset defined by cellSet " << maskSetName_
114 cellSet
subset(mesh_, maskSetName_);
118 maskSet[iter.key()] = 1;
129 scalar maxComp = -great;
132 scalar minComp = great;
134 const boundBox& bb = mesh_.bounds();
138 label maxPointi = -1;
141 scalar c = (
points[pointi]&n_);
147 else if (c < minComp)
154 PackedBoolList maxSelected(mesh_.nCells());
155 maxCells = selectCells(maxComp, maskSet, maxSelected);
159 if (maxCells != nTotCells)
162 <<
"Plane " << plane(
points[maxPointi], n_)
163 <<
" selects " << maxCells
164 <<
" cells instead of all " << nTotCells
165 <<
" cells. Results might be wrong." <<
endl;
174 PackedBoolList selected(mesh_.nCells());
175 label nSelected = -1;
176 scalar selectedVol = 0.0;
180 scalar low = minComp;
181 scalar high = maxComp;
183 const scalar tolerance = small*100*(maxComp-minComp);
185 while ((high-low) > tolerance)
187 scalar mid = 0.5*(low + high);
189 nSelected = selectCells(mid, maskSet, selected);
190 selectedVol = volumeOfSet(selected);
197 if (selectedVol < vol_)
201 PackedBoolList highSelected(mesh_.nCells());
202 label nHigh = selectCells(high, maskSet, selected);
203 if (nSelected == nHigh)
212 PackedBoolList lowSelected(mesh_.nCells());
213 label nLow = selectCells(low, maskSet, selected);
214 if (nSelected == nLow)
221 nSelected = selectCells(high, maskSet, selected);
222 selectedVol = volumeOfSet(selected);
224 if (selectedVol < vol_)
230 nSelected = selectCells(low, maskSet, selected);
231 selectedVol = volumeOfSet(selected);
233 if (selectedVol < vol_)
240 <<
"Did not converge onto plane. " <<
nl 242 << plane(high*n_, n_)
251 Info<<
" Selected " << nSelected <<
" with actual volume " << selectedVol
258 addOrDelete(
set, celli, add);
286 vol_(dict.
lookup<scalar>(
"volume")),
287 n_(dict.
lookup(
"normal")),
319 Info<<
" Adding cells up to target volume " << vol_
320 <<
" out of total volume " <<
gSum(mesh_.cellVolumes()) << endl;
326 Info<<
" Removing cells up to target volume " << vol_
327 <<
" out of total volume " <<
gSum(mesh_.cellVolumes()) << endl;
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
A list of keyword definitions, which are a keyword followed by any number of values (e...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual ~targetVolumeToCell()
Destructor.
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
const dimensionedScalar c
Speed of light in a vacuum.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
vectorField pointField
pointField is a vectorField.
Type gSum(const FieldField< Field, Type > &f)
A class for handling words, derived from string.
setAction
Enumeration defining the valid actions.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
vector point
Point is a vector.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
targetVolumeToCell(const polyMesh &mesh, const scalar vol, const vector &)
Construct from components.
ListType subset(const UList< T > &select, const T &value, const ListType &)
Extract elements of List when select is a certain value.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Mesh consisting of general polyhedral cells.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.