35 namespace decompositionMethods
58 void Foam::decompositionMethods::hierarchical::setDecompOrder
60 const dictionary& methodDict
63 const word
order(methodDict.lookup(
"order"));
65 if (
order.size() != 3)
70 ) <<
"number of characters in order (" <<
order <<
") != 3"
74 for (
label i = 0; i < 3; ++i)
80 else if (
order[i] ==
'y')
84 else if (
order[i] ==
'z')
93 ) <<
"Illegal decomposition order " <<
order <<
endl
100 Foam::label Foam::decompositionMethods::hierarchical::findLower
102 const List<scalar>& l,
108 if (initHigh <= initLow)
114 label high = initHigh;
116 while ((high - low) > 1)
118 label mid = (low + high)/2;
150 void Foam::decompositionMethods::hierarchical::calculateSortedWeightedSizes
155 const label globalCurrentSize,
161 sortedWeightedSizes[0] = 0;
164 label pointi = current[indices[i]];
165 sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointi];
170 sortedWeightedSizes[current.size()],
175 sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength);
181 void Foam::decompositionMethods::hierarchical::findBinary
184 const List<scalar>& values,
185 const label minIndex,
188 const scalar wantedSize,
195 label low = minIndex;
200 label high = values.size();
203 scalar midValuePrev = vGreat;
211 Pout<<
" low:" << low <<
" lowValue:" << lowValue
212 <<
" high:" << high <<
" highValue:" << highValue
213 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
214 <<
" globalSize:" << size <<
" wantedSize:" << wantedSize
215 <<
" sizeTol:" << sizeTol <<
endl;
218 if (wantedSize < size - sizeTol)
221 highValue = midValue;
223 else if (wantedSize > size + sizeTol)
234 midValue = 0.5*(lowValue+highValue);
235 mid =
findLower(values, midValue, low, high);
238 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
243 <<
"unable to find desired decomposition split, making do!"
248 midValuePrev = midValue;
255 void Foam::decompositionMethods::hierarchical::findBinary
258 const List<scalar>& sortedWeightedSizes,
259 const List<scalar>& values,
260 const label minIndex,
263 const scalar wantedSize,
270 label low = minIndex;
275 label high = values.size();
278 scalar midValuePrev = vGreat;
284 sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex],
290 Pout<<
" low:" << low <<
" lowValue:" << lowValue
291 <<
" high:" << high <<
" highValue:" << highValue
292 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl
293 <<
" globalSize:" << weightedSize
294 <<
" wantedSize:" << wantedSize
295 <<
" sizeTol:" << sizeTol <<
endl;
298 if (wantedSize < weightedSize - sizeTol)
301 highValue = midValue;
303 else if (wantedSize > weightedSize + sizeTol)
314 midValue = 0.5*(lowValue+highValue);
315 mid =
findLower(values, midValue, low, high);
318 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
323 <<
"unable to find desired decomposition split, making do!"
328 midValuePrev = midValue;
334 void Foam::decompositionMethods::hierarchical::sortComponent
345 label compI = decompOrder_[componentIndex];
349 Pout<<
"sortComponent : Sorting slice of size " << current.size()
350 <<
" in component " << compI <<
endl;
354 SortableList<scalar> sortedCoord(current.size());
358 label pointi = current[i];
360 sortedCoord[i] =
points[pointi][compI];
388 Pout<<
"sortComponent : minCoord:" << minCoord
389 <<
" maxCoord:" << maxCoord <<
endl;
395 scalar leftCoord = minCoord;
398 for (
label bin = 0; bin < n_[compI]; bin++)
406 label localSize = -1;
409 scalar rightCoord = -great;
411 if (bin == n_[compI]-1)
414 localSize = current.size()-leftIndex;
415 rightCoord = maxCoord;
420 localSize =
label(current.size()/n_[compI]);
421 rightCoord = sortedCoord[leftIndex+localSize];
429 label rightIndex = current.size();
430 rightCoord = maxCoord;
440 globalCurrentSize/n_[compI],
445 localSize = rightIndex - leftIndex;
450 Pout<<
"For component " << compI <<
", bin " << bin
451 <<
" copying" <<
endl
452 <<
"from " << leftCoord <<
" at local index "
454 <<
"to " << rightCoord <<
" localSize:"
465 label pointi = current[sortedCoord.indices()[leftIndex+i]];
468 finalDecomp[pointi] += bin*mult;
475 if (componentIndex < 2)
501 leftIndex += localSize;
502 leftCoord = rightCoord;
508 void Foam::decompositionMethods::hierarchical::sortComponent
520 label compI = decompOrder_[componentIndex];
524 Pout<<
"sortComponent : Sorting slice of size " << current.size()
525 <<
" in component " << compI <<
endl;
529 SortableList<scalar> sortedCoord(current.size());
533 label pointi = current[i];
535 sortedCoord[i] =
points[pointi][compI];
543 scalarField sortedWeightedSizes(current.size()+1, 0);
544 calculateSortedWeightedSizes
547 sortedCoord.indices(),
575 Pout<<
"sortComponent : minCoord:" << minCoord
576 <<
" maxCoord:" << maxCoord <<
endl;
582 scalar leftCoord = minCoord;
585 for (
label bin = 0; bin < n_[compI]; bin++)
593 label localSize = -1;
596 scalar rightCoord = -great;
598 if (bin == n_[compI]-1)
601 localSize = current.size()-leftIndex;
602 rightCoord = maxCoord;
611 label rightIndex = current.size();
612 rightCoord = maxCoord;
623 globalCurrentSize/n_[compI],
628 localSize = rightIndex - leftIndex;
633 Pout<<
"For component " << compI <<
", bin " << bin
634 <<
" copying" <<
endl
635 <<
"from " << leftCoord <<
" at local index "
637 <<
"to " << rightCoord <<
" localSize:"
648 label pointi = current[sortedCoord.indices()[leftIndex+i]];
651 finalDecomp[pointi] += bin*mult;
658 if (componentIndex < 2)
685 leftIndex += localSize;
686 leftCoord = rightCoord;
737 checkWeights(
points, weights);
783 geometric(decompositionDict, methodDict),
786 setDecompOrder(methodDict);
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.
Geometrical domain decomposition.
Does hierarchical decomposition of points. Works by first sorting the points in x direction into equa...
hierarchical(const dictionary &decompositionDict, const dictionary &methodDict)
Construct given the decomposition dictionary.
virtual labelList decompose(const pointField &, const scalarField &weights)
Return for every coordinate the wanted processor number.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
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)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")