51 void Foam::multiLevelDecomp::createMethodsDict()
73 nTotal = (domains.empty() ? 0 : 1);
75 for (
const label
n : domains)
98 domains.setSize(old.size()+1);
103 domains[i+1] = old[i];
105 nTotal *= domains[0];
107 Info<<
" inferred level0 with " << domains[0]
108 <<
" domains" <<
nl <<
nl;
111 if (!nLevels || nTotal !=
nDomains())
114 <<
"Top level decomposition specifies " <<
nDomains()
115 <<
" domains which is not equal to the product of" 116 <<
" all sub domains " << nTotal
124 const dictionary& subMethodCoeffsDict
129 defaultMethod +
"Coeffs",
130 selectionType::NULL_DICT
134 for (
const label
n : domains)
136 const word levelName(
"level" +
Foam::name(nLevels++));
138 entry* dictptr = methodsDict_.set(levelName, dictionary());
140 dictionary&
dict = dictptr->dict();
141 dict.add(
"method", defaultMethod);
142 dict.add(
"numberOfSubdomains",
n);
145 if (subMethodCoeffsDict.size())
147 dict.add(subMethodCoeffsDict.dictName(), subMethodCoeffsDict);
159 for (
const entry& dEntry : coeffsDict_)
172 const bool addDefaultMethod
175 && !defaultMethod.empty()
178 entry*
e = methodsDict_.add(dEntry);
180 if (addDefaultMethod &&
e &&
e->isDict())
182 e->dict().add(
"method", defaultMethod);
190 void Foam::multiLevelDecomp::setMethods()
198 methods_.setSize(methodsDict_.size());
199 for (
const entry& dEntry : methodsDict_)
214 methods_.setSize(nLevels);
219 <<
"Decompose " <<
type() <<
" [" << nDomains() <<
"] in " 220 << nLevels <<
" levels:" <<
endl;
225 Info<<
" level " << i <<
" : " << methods_[i].type()
226 <<
" [" << methods_[i].nDomains() <<
"]" <<
endl;
228 nTotal *= methods_[i].nDomains();
231 if (nTotal != nDomains())
234 <<
"Top level decomposition specifies " << nDomains()
235 <<
" domains which is not equal to the product of" 236 <<
" all sub domains " << nTotal
244 void Foam::multiLevelDecomp::subsetGlobalCellCells
246 const label nDomains,
256 const globalIndex globalCells(cellCells.size());
262 subCellCells = UIndirectList<labelList>(cellCells,
set);
265 List<Map<label>> compactMap;
266 mapDistribute map(globalCells, subCellCells, compactMap);
267 map.distribute(oldToNew);
269 map.distribute(allDist);
278 const globalIndex globalSubCells(
set.size());
283 cutConnections.setSize(nDomains);
286 forAll(subCellCells, subCelli)
288 labelList& cCells = subCellCells[subCelli];
295 const label nbrCelli = oldToNew[cCells[i]];
298 cutConnections[allDist[cCells[i]]]++;
305 const label celli =
set[subCelli];
306 const label oldNbrCelli = cellCells[celli][i];
308 const label proci = globalCells.whichProcID(oldNbrCelli);
310 cCells[newI++] = globalSubCells.toGlobal(proci, nbrCelli);
313 cCells.setSize(newI);
318 void Foam::multiLevelDecomp::decompose
324 const label currLevel,
325 const label leafOffset,
332 methods_[currLevel].decompose
341 const label nextLevel = currLevel+1;
344 const label nCurrDomains = methods_[currLevel].nDomains();
354 for (label i = 0; i <= currLevel; ++i)
356 sizes *= methods_[i].nDomains();
360 sizes = this->nDomains() / sizes;
364 domainLookup[i] = i * sizes + leafOffset;
370 Info<<
"Distribute at level " << currLevel
371 <<
" to domains" <<
nl 378 const label orig = pointMap[i];
379 finalDecomp[orig] = domainLookup[dist[i]];
382 if (nextLevel < methods_.size())
392 Pout<<
"Decomposition at level " << currLevel <<
" :" <<
endl;
395 for (label domainI = 0; domainI < nCurrDomains; ++domainI)
402 scalarField subWeights(pointWeights, domainPoints);
407 subsetGlobalCellCells
425 for (
const label nConnect : nOutsideConnections)
437 Pout<<
" Domain " << domainI <<
nl 438 <<
" Number of cells = " <<
nPoints <<
nl 439 <<
" Number of inter-domain patches = " <<
nPatches 441 <<
" Number of inter-domain faces = " << nFaces <<
nl 454 domainLookup[domainI],
468 const label nNext = methods_[nextLevel].nDomains();
469 const label nTotal = nCurrDomains * nNext;
472 dictionary level0Dict;
473 for (
const entry& dEntry : methodsDict_)
477 level0Dict = dEntry.dict();
481 level0Dict.set(
"numberOfSubdomains", nTotal);
485 Pout<<
"Reference decomposition with " << level0Dict <<
" :" 503 for (label blockI = 0; blockI < nCurrDomains; ++blockI)
509 forAll(pointPoints, pointi)
511 if ((dist[pointi] / nNext) == blockI)
515 const labelList& pPoints = pointPoints[pointi];
519 const label distBlockI = dist[pPoints[i]] / nNext;
520 if (distBlockI != blockI)
522 nOutsideConnections[distBlockI]++;
537 for (
const label nConnect : nOutsideConnections)
548 Pout<<
" Domain " << blockI <<
nl 549 <<
" Number of cells = " <<
nPoints <<
nl 550 <<
" Number of inter-domain patches = " 552 <<
" Number of inter-domain faces = " << nFaces
563 Foam::multiLevelDecomp::multiLevelDecomp
565 const dictionary& decompDict,
575 (selectionType::EXACT | selectionType::MANDATORY)
592 if (!meth.parallelAware())
604 const polyMesh&
mesh,
609 CompactListList<label> cellCells;
void size(const label n)
Older name for setAddressableSize.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
constexpr char nl
The newline '\n' character (0x0a)
UIndirectList< label > labelUIndList
UIndirectList of labels.
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
List< labelList > labelListList
List of labelList.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
#define forAll(list, i)
Loop across all elements in list.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Foam::word regionName(Foam::polyMesh::defaultRegion)
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const string & prefix() const noexcept
Return the stream prefix.
Abstract base class for domain decomposition.
static const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing dictionary...
label nDomains() const noexcept
Number of domains.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
static autoPtr< decompositionMethod > New(const dictionary &decompDict, const word ®ionName="")
Return a reference to the selected decomposition method, optionally region-specific.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool parallelAware() const
Is method parallel aware?
List< label > labelList
A List of labels.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static void listCombineReduce(List< T > &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
After completion all processors have the same data.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
static constexpr const zero Zero
Global zero (0)