35 namespace decompositionMethods
58 void Foam::decompositionMethods::hierarchical::setDecompOrder()
62 if (
order.size() != 3)
67 ) <<
"number of characters in order (" <<
order <<
") != 3"
71 for (
label i = 0; i < 3; ++i)
77 else if (
order[i] ==
'y')
81 else if (
order[i] ==
'z')
90 ) <<
"Illegal decomposition order " <<
order <<
endl
97 Foam::label Foam::decompositionMethods::hierarchical::findLower
99 const List<scalar>& l,
105 if (initHigh <= initLow)
111 label high = initHigh;
113 while ((high - low) > 1)
115 label mid = (low + high)/2;
147 void Foam::decompositionMethods::hierarchical::calculateSortedWeightedSizes
152 const label globalCurrentSize,
158 sortedWeightedSizes[0] = 0;
161 label pointi = current[indices[i]];
162 sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointi];
167 sortedWeightedSizes[current.size()],
172 sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength);
178 void Foam::decompositionMethods::hierarchical::findBinary
181 const List<scalar>& values,
182 const label minIndex,
185 const scalar wantedSize,
192 label low = minIndex;
197 label high = values.size();
200 scalar midValuePrev = vGreat;
208 Pout<<
" low:" << low <<
" lowValue:" << lowValue
209 <<
" high:" << high <<
" highValue:" << highValue
210 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
211 <<
" globalSize:" << size <<
" wantedSize:" << wantedSize
212 <<
" sizeTol:" << sizeTol <<
endl;
215 if (wantedSize < size - sizeTol)
218 highValue = midValue;
220 else if (wantedSize > size + sizeTol)
231 midValue = 0.5*(lowValue+highValue);
232 mid =
findLower(values, midValue, low, high);
235 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
240 <<
"unable to find desired decomposition split, making do!"
245 midValuePrev = midValue;
252 void Foam::decompositionMethods::hierarchical::findBinary
255 const List<scalar>& sortedWeightedSizes,
256 const List<scalar>& values,
257 const label minIndex,
260 const scalar wantedSize,
267 label low = minIndex;
272 label high = values.size();
275 scalar midValuePrev = vGreat;
281 sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex],
287 Pout<<
" low:" << low <<
" lowValue:" << lowValue
288 <<
" high:" << high <<
" highValue:" << highValue
289 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
290 <<
" globalSize:" << weightedSize
291 <<
" wantedSize:" << wantedSize
292 <<
" sizeTol:" << sizeTol <<
endl;
295 if (wantedSize < weightedSize - sizeTol)
298 highValue = midValue;
300 else if (wantedSize > weightedSize + sizeTol)
311 midValue = 0.5*(lowValue+highValue);
312 mid =
findLower(values, midValue, low, high);
315 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
320 <<
"unable to find desired decomposition split, making do!"
325 midValuePrev = midValue;
331 void Foam::decompositionMethods::hierarchical::sortComponent
342 label compI = decompOrder_[componentIndex];
346 Pout<<
"sortComponent : Sorting slice of size " << current.size()
347 <<
" in component " << compI <<
endl;
351 SortableList<scalar> sortedCoord(current.size());
355 label pointi = current[i];
357 sortedCoord[i] =
points[pointi][compI];
385 Pout<<
"sortComponent : minCoord:" << minCoord
386 <<
" maxCoord:" << maxCoord <<
endl;
392 scalar leftCoord = minCoord;
395 for (
label bin = 0; bin < n_[compI]; bin++)
403 label localSize = -1;
406 scalar rightCoord = -great;
408 if (bin == n_[compI]-1)
411 localSize = current.size()-leftIndex;
412 rightCoord = maxCoord;
417 localSize =
label(current.size()/n_[compI]);
418 rightCoord = sortedCoord[leftIndex+localSize];
426 label rightIndex = current.size();
427 rightCoord = maxCoord;
437 globalCurrentSize/n_[compI],
442 localSize = rightIndex - leftIndex;
447 Pout<<
"For component " << compI <<
", bin " << bin
448 <<
" copying" <<
endl
449 <<
"from " << leftCoord <<
" at local index "
451 <<
"to " << rightCoord <<
" localSize:"
462 label pointi = current[sortedCoord.indices()[leftIndex+i]];
465 finalDecomp[pointi] += bin*mult;
472 if (componentIndex < 2)
498 leftIndex += localSize;
499 leftCoord = rightCoord;
505 void Foam::decompositionMethods::hierarchical::sortComponent
517 label compI = decompOrder_[componentIndex];
521 Pout<<
"sortComponent : Sorting slice of size " << current.size()
522 <<
" in component " << compI <<
endl;
526 SortableList<scalar> sortedCoord(current.size());
530 label pointi = current[i];
532 sortedCoord[i] =
points[pointi][compI];
540 scalarField sortedWeightedSizes(current.size()+1, 0);
541 calculateSortedWeightedSizes
544 sortedCoord.indices(),
572 Pout<<
"sortComponent : minCoord:" << minCoord
573 <<
" maxCoord:" << maxCoord <<
endl;
579 scalar leftCoord = minCoord;
582 for (
label bin = 0; bin < n_[compI]; bin++)
590 label localSize = -1;
593 scalar rightCoord = -great;
595 if (bin == n_[compI]-1)
598 localSize = current.size()-leftIndex;
599 rightCoord = maxCoord;
608 label rightIndex = current.size();
609 rightCoord = maxCoord;
620 globalCurrentSize/n_[compI],
625 localSize = rightIndex - leftIndex;
630 Pout<<
"For component " << compI <<
", bin " << bin
631 <<
" copying" <<
endl
632 <<
"from " << leftCoord <<
" at local index "
634 <<
"to " << rightCoord <<
" localSize:"
645 label pointi = current[sortedCoord.indices()[leftIndex+i]];
648 finalDecomp[pointi] += bin*mult;
655 if (componentIndex < 2)
682 leftIndex += localSize;
683 leftCoord = rightCoord;
734 checkWeights(
points, weights);
Inter-processor communication reduction functions.
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Abstract base class for decomposition.
dictionary decompositionDict_
Geometrical domain decomposition.
const dictionary & geometricDict_
Does hierarchical decomposition of points. Works by first sorting the points in x direction into equa...
hierarchical(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
virtual labelList decompose(const pointField &, const scalarField &weights)
Return for every coordinate the wanted processor number.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const string & prefix() const
Return the prefix of the stream.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define WarningInFunction
Report a warning using Foam::Warning.
defineTypeNameAndDebug(metis, 0)
addToRunTimeSelectionTable(decompositionMethod, metis, decomposer)
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
int order(const scalar s)
vectorField pointField
pointField is a vectorField.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")