55 void Foam::hierarchGeomDecomp::setDecompOrder()
57 const word order(geomDecomDict_.lookup(
"order"));
59 if (order.size() != 3)
64 ) <<
"number of characters in order (" << order <<
") != 3" 68 for (
label i = 0; i < 3; ++i)
74 else if (order[i] ==
'y')
78 else if (order[i] ==
'z')
87 ) <<
"Illegal decomposition order " << order <<
endl 96 const List<scalar>& l,
102 if (initHigh <= initLow)
108 label high = initHigh;
110 while ((high - low) > 1)
112 label mid = (low + high)/2;
144 void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes
149 const label globalCurrentSize,
155 sortedWeightedSizes[0] = 0;
158 label pointi = current[indices[i]];
159 sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointi];
164 sortedWeightedSizes[current.size()],
169 sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength);
175 void Foam::hierarchGeomDecomp::findBinary
178 const List<scalar>& values,
179 const label minIndex,
180 const scalar minValue,
181 const scalar maxValue,
182 const scalar wantedSize,
189 label low = minIndex;
194 label high = values.size();
197 scalar midValuePrev = vGreat;
205 Pout<<
" low:" << low <<
" lowValue:" << lowValue
206 <<
" high:" << high <<
" highValue:" << highValue
207 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl 208 <<
" globalSize:" << size <<
" wantedSize:" << wantedSize
209 <<
" sizeTol:" << sizeTol <<
endl;
212 if (wantedSize < size - sizeTol)
215 highValue = midValue;
217 else if (wantedSize > size + sizeTol)
228 midValue = 0.5*(lowValue+highValue);
229 mid =
findLower(values, midValue, low, high);
232 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
237 <<
"unable to find desired decomposition split, making do!" 242 midValuePrev = midValue;
249 void Foam::hierarchGeomDecomp::findBinary
252 const List<scalar>& sortedWeightedSizes,
253 const List<scalar>& values,
254 const label minIndex,
255 const scalar minValue,
256 const scalar maxValue,
257 const scalar wantedSize,
264 label low = minIndex;
269 label high = values.size();
272 scalar midValuePrev = vGreat;
278 sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex],
284 Pout<<
" low:" << low <<
" lowValue:" << lowValue
285 <<
" high:" << high <<
" highValue:" << highValue
286 <<
" mid:" << mid <<
" midValue:" << midValue <<
endl 287 <<
" globalSize:" << weightedSize
288 <<
" wantedSize:" << wantedSize
289 <<
" sizeTol:" << sizeTol <<
endl;
292 if (wantedSize < weightedSize - sizeTol)
295 highValue = midValue;
297 else if (wantedSize > weightedSize + sizeTol)
308 midValue = 0.5*(lowValue+highValue);
309 mid =
findLower(values, midValue, low, high);
312 bool hasNotChanged = (
mag(midValue-midValuePrev) < small);
317 <<
"unable to find desired decomposition split, making do!" 322 midValuePrev = midValue;
328 void Foam::hierarchGeomDecomp::sortComponent
339 label compI = decompOrder_[componentIndex];
343 Pout<<
"sortComponent : Sorting slice of size " << current.size()
344 <<
" in component " << compI <<
endl;
348 SortableList<scalar> sortedCoord(current.size());
352 label pointi = current[i];
354 sortedCoord[i] = points[pointi][compI];
382 Pout<<
"sortComponent : minCoord:" << minCoord
383 <<
" maxCoord:" << maxCoord <<
endl;
389 scalar leftCoord = minCoord;
392 for (
label bin = 0; bin < n_[compI]; bin++)
400 label localSize = -1;
403 scalar rightCoord = -great;
405 if (bin == n_[compI]-1)
408 localSize = current.size()-leftIndex;
409 rightCoord = maxCoord;
414 localSize =
label(current.size()/n_[compI]);
415 rightCoord = sortedCoord[leftIndex+localSize];
423 label rightIndex = current.size();
424 rightCoord = maxCoord;
434 globalCurrentSize/n_[compI],
439 localSize = rightIndex - leftIndex;
444 Pout<<
"For component " << compI <<
", bin " << bin
445 <<
" copying" <<
endl 446 <<
"from " << leftCoord <<
" at local index " 448 <<
"to " << rightCoord <<
" localSize:" 459 label pointi = current[sortedCoord.indices()[leftIndex+i]];
462 finalDecomp[pointi] += bin*mult;
469 if (componentIndex < 2)
495 leftIndex += localSize;
496 leftCoord = rightCoord;
502 void Foam::hierarchGeomDecomp::sortComponent
514 label compI = decompOrder_[componentIndex];
518 Pout<<
"sortComponent : Sorting slice of size " << current.size()
519 <<
" in component " << compI <<
endl;
523 SortableList<scalar> sortedCoord(current.size());
527 label pointi = current[i];
529 sortedCoord[i] = points[pointi][compI];
537 scalarField sortedWeightedSizes(current.size()+1, 0);
538 calculateSortedWeightedSizes
541 sortedCoord.indices(),
569 Pout<<
"sortComponent : minCoord:" << minCoord
570 <<
" maxCoord:" << maxCoord <<
endl;
576 scalar leftCoord = minCoord;
579 for (
label bin = 0; bin < n_[compI]; bin++)
587 label localSize = -1;
590 scalar rightCoord = -great;
592 if (bin == n_[compI]-1)
595 localSize = current.size()-leftIndex;
596 rightCoord = maxCoord;
605 label rightIndex = current.size();
606 rightCoord = maxCoord;
617 globalCurrentSize/n_[compI],
622 localSize = rightIndex - leftIndex;
627 Pout<<
"For component " << compI <<
", bin " << bin
628 <<
" copying" <<
endl 629 <<
"from " << leftCoord <<
" at local index " 631 <<
"to " << rightCoord <<
" localSize:" 642 label pointi = current[sortedCoord.indices()[leftIndex+i]];
645 finalDecomp[pointi] += bin*mult;
652 if (componentIndex < 2)
679 leftIndex += localSize;
680 leftCoord = rightCoord;
705 label allSize = points.size();
746 label allSize = points.size();
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > 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...
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Holds information (coordinate and normal) regarding nearest wall point.
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.