50Foam::label Foam::hierarchGeomDecomp::findLower
52 const UList<scalar>& list,
66 while ((high - low) > 1)
68 const label mid = (low + high)/2;
82 if (list[high-1] < val)
96void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes
101 const label globalCurrentSize,
107 sortedWeightedSizes[0] = 0;
110 const label pointi = current[indices[i]];
111 sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointi];
116 sortedWeightedSizes[current.size()],
121 sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength);
127bool Foam::hierarchGeomDecomp::findBinary
130 const List<scalar>& values,
131 const label minIndex,
134 const scalar wantedSize,
144 label low = minIndex;
145 label high =
values.size();
148 scalar midValuePrev = VGREAT;
152 label size =
returnReduce(mid-minIndex, sumOp<label>());
156 Pout<<
" low:" << low <<
" lowValue:" << lowValue
157 <<
" high:" << high <<
" highValue:" << highValue
158 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
159 <<
" globalSize:" << size <<
" wantedSize:" << wantedSize
160 <<
" sizeTol:" << sizeTol <<
endl;
163 if (wantedSize < size - sizeTol)
166 highValue = midValue;
168 else if (wantedSize > size + sizeTol)
179 midValue = 0.5*(lowValue+highValue);
180 mid =
findLower(values, midValue, low, high);
183 bool hasNotChanged = (
mag(midValue-midValuePrev) < SMALL);
190 <<
"unable to find desired decomposition split, making do!"
197 midValuePrev = midValue;
206bool Foam::hierarchGeomDecomp::findBinary
209 const List<scalar>& sortedWeightedSizes,
210 const List<scalar>& values,
211 const label minIndex,
214 const scalar wantedSize,
221 label low = minIndex;
226 label high =
values.size();
229 scalar midValuePrev = VGREAT;
235 sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex],
241 Pout<<
" low:" << low <<
" lowValue:" << lowValue
242 <<
" high:" << high <<
" highValue:" << highValue
243 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
244 <<
" globalSize:" << weightedSize
245 <<
" wantedSize:" << wantedSize
246 <<
" sizeTol:" << sizeTol <<
endl;
249 if (wantedSize < weightedSize - sizeTol)
252 highValue = midValue;
254 else if (wantedSize > weightedSize + sizeTol)
265 midValue = 0.5*(lowValue+highValue);
266 mid =
findLower(values, midValue, low, high);
269 bool hasNotChanged = (
mag(midValue-midValuePrev) < SMALL);
276 <<
"Unable to find desired decomposition split, making do!"
283 midValuePrev = midValue;
291Foam::label Foam::hierarchGeomDecomp::sortComponent
302 const label compI = order_[componentIndex];
309 Pout<<
"sortComponent : Sorting slice of size " << current.size()
310 <<
" in component " << compI <<
endl;
314 SortableList<scalar> sortedCoord(current.size());
318 const label pointi = current[i];
320 sortedCoord[i] =
points[pointi][compI];
324 label globalCurrentSize =
returnReduce(current.size(), sumOp<label>());
330 ? sortedCoord.first()
348 Pout<<
"sortComponent : minCoord:" << minCoord
349 <<
" maxCoord:" << maxCoord <<
endl;
355 scalar leftCoord = minCoord;
358 for (label bin = 0; bin < n_[compI]; bin++)
366 label localSize = -1;
369 scalar rightCoord = -GREAT;
371 if (bin == n_[compI]-1)
374 localSize = current.size()-leftIndex;
375 rightCoord = maxCoord;
380 localSize = label(current.size()/n_[compI]);
381 if (leftIndex+localSize < sortedCoord.size())
383 rightCoord = sortedCoord[leftIndex+localSize];
387 rightCoord = maxCoord;
396 label rightIndex = current.size();
397 rightCoord = maxCoord;
407 globalCurrentSize/n_[compI],
412 localSize = rightIndex - leftIndex;
422 Pout<<
"For component " << compI <<
", bin " << bin
423 <<
" copying" <<
endl
424 <<
"from " << leftCoord <<
" at local index "
426 <<
"to " << rightCoord <<
" localSize:"
437 label pointi = current[sortedCoord.indices()[leftIndex+i]];
440 finalDecomp[pointi] += bin*mult;
447 if (componentIndex < 2)
456 nWarnings += sortComponent
473 leftIndex += localSize;
474 leftCoord = rightCoord;
482Foam::label Foam::hierarchGeomDecomp::sortComponent
494 const label compI = order_[componentIndex];
501 Pout<<
"sortComponent : Sorting slice of size " << current.size()
502 <<
" in component " << compI <<
endl;
506 SortableList<scalar> sortedCoord(current.size());
510 label pointi = current[i];
512 sortedCoord[i] =
points[pointi][compI];
516 label globalCurrentSize =
returnReduce(current.size(), sumOp<label>());
521 calculateSortedWeightedSizes
524 sortedCoord.indices(),
534 ? sortedCoord.first()
552 Pout<<
"sortComponent : minCoord:" << minCoord
553 <<
" maxCoord:" << maxCoord <<
endl;
559 scalar leftCoord = minCoord;
562 for (label bin = 0; bin < n_[compI]; bin++)
570 label localSize = -1;
573 scalar rightCoord = -GREAT;
575 if (bin == n_[compI]-1)
578 localSize = current.size()-leftIndex;
579 rightCoord = maxCoord;
588 label rightIndex = current.size();
589 rightCoord = maxCoord;
600 globalCurrentSize/n_[compI],
605 localSize = rightIndex - leftIndex;
615 Pout<<
"For component " << compI <<
", bin " << bin
616 <<
" copying" <<
endl
617 <<
"from " << leftCoord <<
" at local index "
619 <<
"to " << rightCoord <<
" localSize:"
630 label pointi = current[sortedCoord.indices()[leftIndex+i]];
633 finalDecomp[pointi] += bin*mult;
640 if (componentIndex < 2)
649 nWarnings += sortComponent
667 leftIndex += localSize;
668 leftCoord = rightCoord;
706 const label sizeTol =
max(1, label(1
e-3*allSize/nDomains_));
709 const label nWarnings = sortComponent
722 <<
"\nEncountered " << nWarnings <<
" occurrences where the desired"
723 " decomposition split could not be properly satisfied" <<
endl;
748 const label sizeTol =
max(1, label(1
e-3*allSize/nDomains_));
751 const label nWarnings = sortComponent
765 <<
"\nEncountered " << nWarnings <<
" occurrences where the desired"
766 " decomposition split could not be properly satisfied" <<
endl;
Inter-processor communication reduction functions.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
void size(const label n)
Older name for setAddressableSize.
Abstract base class for domain decomposition.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Base for geometrical domain decomposition methods.
Does hierarchical decomposition of points, selectable as hierarchical.
const string & prefix() const noexcept
Return the stream prefix.
bool decompose() const noexcept
Query the decompose flag (normally off)
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define WarningInFunction
Report a warning using Foam::Warning.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
List< label > labelList
A List of labels.
vectorField pointField
pointField is a vectorField.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
#define forAll(list, i)
Loop across all elements in list.