50 Foam::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)
96 void 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);
127 bool 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);
183 bool hasNotChanged = (
mag(midValue-midValuePrev) < SMALL);
190 <<
"unable to find desired decomposition split, making do!" 197 midValuePrev = midValue;
206 bool 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);
269 bool hasNotChanged = (
mag(midValue-midValuePrev) < SMALL);
276 <<
"Unable to find desired decomposition split, making do!" 283 midValuePrev = midValue;
291 Foam::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;
482 Foam::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;
716 const label sizeTol =
max(1, label(1
e-3*allSize/nDomains_));
722 nWarnings = sortComponent
735 nWarnings = sortComponent
749 <<
"\nEncountered " << nWarnings <<
" occurrences where the desired" 750 " decomposition split could not be properly satisfied" <<
endl;
void size(const label n)
Older name for setAddressableSize.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
Inter-processor communication reduction functions.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual labelList decompose(const pointField &points, const scalarField &weights=scalarField::null()) const
Return for every coordinate the wanted processor number. using uniform or specified point weights...
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.
#define forAll(list, i)
Loop across all elements in list.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
Base for geometrical domain decomposition methods.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const string & prefix() const noexcept
Return the stream prefix.
hierarchGeomDecomp(const hierarchGeomDecomp &)=delete
No copy construct.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
List< label > labelList
A List of labels.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)