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;
706 const label sizeTol =
max(1, label(1
e-3*allSize/nDomains_));
709 const label nWarnings = sortComponent
722 <<
"\nEncountered " << nWarnings <<
" occurrences where the desired"
723 " decomposition split could not be properly satisfied" <<
endl;
748 const label sizeTol =
max(1, label(1
e-3*allSize/nDomains_));
751 const label nWarnings = sortComponent
765 <<
"\nEncountered " << nWarnings <<
" occurrences where the desired"
766 " decomposition split could not be properly satisfied" <<
endl;