47 void Foam::hierarchGeomDecomp::setDecompOrder()
49 const word order(geomDecomDict_.lookup(
"order"));
51 if (order.size() != 3)
56 ) <<
"number of characters in order (" << order <<
") != 3" 60 for (
label i = 0; i < 3; ++i)
66 else if (order[i] ==
'y')
70 else if (order[i] ==
'z')
79 ) <<
"Illegal decomposition order " << order <<
endl 88 const List<scalar>& l,
94 if (initHigh <= initLow)
100 label high = initHigh;
102 while ((high - low) > 1)
104 label mid = (low + high)/2;
136 void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes
141 const label globalCurrentSize,
147 sortedWeightedSizes[0] = 0;
150 label pointi = current[indices[i]];
151 sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointi];
156 sortedWeightedSizes[current.size()],
161 sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength);
167 void Foam::hierarchGeomDecomp::findBinary
170 const List<scalar>& values,
171 const label minIndex,
172 const scalar minValue,
173 const scalar maxValue,
174 const scalar wantedSize,
181 label low = minIndex;
186 label high = values.size();
189 scalar midValuePrev = vGreat;
197 Pout<<
" low:" << low <<
" lowValue:" << lowValue
198 <<
" high:" << high <<
" highValue:" << highValue
199 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl 200 <<
" globalSize:" << size <<
" wantedSize:" << wantedSize
201 <<
" sizeTol:" << sizeTol <<
endl;
204 if (wantedSize < size - sizeTol)
207 highValue = midValue;
209 else if (wantedSize > size + sizeTol)
220 midValue = 0.5*(lowValue+highValue);
221 mid =
findLower(values, midValue, low, high);
224 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
229 <<
"unable to find desired decomposition split, making do!" 234 midValuePrev = midValue;
241 void Foam::hierarchGeomDecomp::findBinary
244 const List<scalar>& sortedWeightedSizes,
245 const List<scalar>& values,
246 const label minIndex,
247 const scalar minValue,
248 const scalar maxValue,
249 const scalar wantedSize,
256 label low = minIndex;
261 label high = values.size();
264 scalar midValuePrev = vGreat;
270 sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex],
276 Pout<<
" low:" << low <<
" lowValue:" << lowValue
277 <<
" high:" << high <<
" highValue:" << highValue
278 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl 279 <<
" globalSize:" << weightedSize
280 <<
" wantedSize:" << wantedSize
281 <<
" sizeTol:" << sizeTol <<
endl;
284 if (wantedSize < weightedSize - sizeTol)
287 highValue = midValue;
289 else if (wantedSize > weightedSize + sizeTol)
300 midValue = 0.5*(lowValue+highValue);
301 mid =
findLower(values, midValue, low, high);
304 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
309 <<
"unable to find desired decomposition split, making do!" 314 midValuePrev = midValue;
320 void Foam::hierarchGeomDecomp::sortComponent
331 label compI = decompOrder_[componentIndex];
335 Pout<<
"sortComponent : Sorting slice of size " << current.size()
336 <<
" in component " << compI <<
endl;
340 SortableList<scalar> sortedCoord(current.size());
344 label pointi = current[i];
346 sortedCoord[i] = points[pointi][compI];
374 Pout<<
"sortComponent : minCoord:" << minCoord
375 <<
" maxCoord:" << maxCoord <<
endl;
381 scalar leftCoord = minCoord;
384 for (
label bin = 0; bin < n_[compI]; bin++)
392 label localSize = -1;
395 scalar rightCoord = -great;
397 if (bin == n_[compI]-1)
400 localSize = current.size()-leftIndex;
401 rightCoord = maxCoord;
406 localSize =
label(current.size()/n_[compI]);
407 rightCoord = sortedCoord[leftIndex+localSize];
415 label rightIndex = current.size();
416 rightCoord = maxCoord;
426 globalCurrentSize/n_[compI],
431 localSize = rightIndex - leftIndex;
436 Pout<<
"For component " << compI <<
", bin " << bin
437 <<
" copying" <<
endl 438 <<
"from " << leftCoord <<
" at local index " 440 <<
"to " << rightCoord <<
" localSize:" 451 label pointi = current[sortedCoord.indices()[leftIndex+i]];
454 finalDecomp[pointi] += bin*mult;
461 if (componentIndex < 2)
487 leftIndex += localSize;
488 leftCoord = rightCoord;
494 void Foam::hierarchGeomDecomp::sortComponent
506 label compI = decompOrder_[componentIndex];
510 Pout<<
"sortComponent : Sorting slice of size " << current.size()
511 <<
" in component " << compI <<
endl;
515 SortableList<scalar> sortedCoord(current.size());
519 label pointi = current[i];
521 sortedCoord[i] = points[pointi][compI];
529 scalarField sortedWeightedSizes(current.size()+1, 0);
530 calculateSortedWeightedSizes
533 sortedCoord.indices(),
561 Pout<<
"sortComponent : minCoord:" << minCoord
562 <<
" maxCoord:" << maxCoord <<
endl;
568 scalar leftCoord = minCoord;
571 for (
label bin = 0; bin < n_[compI]; bin++)
579 label localSize = -1;
582 scalar rightCoord = -great;
584 if (bin == n_[compI]-1)
587 localSize = current.size()-leftIndex;
588 rightCoord = maxCoord;
597 label rightIndex = current.size();
598 rightCoord = maxCoord;
609 globalCurrentSize/n_[compI],
614 localSize = rightIndex - leftIndex;
619 Pout<<
"For component " << compI <<
", bin " << bin
620 <<
" copying" <<
endl 621 <<
"from " << leftCoord <<
" at local index " 623 <<
"to " << rightCoord <<
" localSize:" 634 label pointi = current[sortedCoord.indices()[leftIndex+i]];
637 finalDecomp[pointi] += bin*mult;
644 if (componentIndex < 2)
671 leftIndex += localSize;
672 leftCoord = rightCoord;
697 label allSize = points.size();
738 label allSize = points.size();
#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.
Inter-processor communication reduction functions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Macros for easy insertion into run-time selection tables.
const string & prefix() const
Return the prefix of the stream.
vectorField pointField
pointField is a vectorField.
Geometrical domain decomposition.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
hierarchGeomDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
List< label > labelList
A List of labels.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
virtual labelList decompose(const pointField &, const scalarField &weights)
Return for every coordinate the wanted processor number.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
prefixOSstream Pout(cout, "Pout")
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,.
dimensioned< scalar > mag(const dimensioned< Type > &)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
const doubleScalar e
Elementary charge.