39 namespace functionObjects
56 Foam::functionObjects::agglomerationInfo::agglomeration()
const 63 <<
"GAMGAgglomeration '" << agglomName_ <<
"' not found. " 64 <<
"Set cacheAgglomeration true for field " << fieldName_
73 void Foam::functionObjects::agglomerationInfo::writeLevel0()
78 const label statsComm = mesh_.comm();
88 for (label
n : allNCells0)
98 const scalar avg0 = nActive0 > 0 ? scalar(total0)/nActive0 : 0;
101 label myOffseti0 = 0;
104 myOffseti0 += allNCells0[
p];
107 const word writtenName0 =
"GAMGAgglom_" + fieldName_ +
"_level0_mesh";
114 mesh_.time().timeName(),
126 fineMesh[celli] = scalar(myOffseti0 + celli);
129 const label nP0 = label(allNCells0.size());
130 const word assignedStr0 =
Foam::name(nP0) +
" proc" + (nP0 != 1 ?
"s" :
"");
137 << label(avg0) <<
tab 139 << assignedStr0 <<
tab 140 << writtenName0 <<
tab 147 void Foam::functionObjects::agglomerationInfo::setCellsPerLevel
149 const GAMGAgglomeration& agglom,
151 const label& procAgglomLeveli,
155 if (leveli == 0)
return;
157 if (agglom.hasProcMesh(leveli))
163 const label comm = agglom.agglomCommunicator(leveli);
169 fineSizes[myRank] = agglom.nCells(leveli - 1);
175 for (label
p = 0;
p < myRank; ++
p)
177 myOffseti += fineSizes[
p];
185 combinedAddr = agglom.restrictAddressing(leveli);
193 next[celli] = combinedAddr[myOffseti + cellsPerLevel[celli]];
195 cellsPerLevel.transfer(next);
197 else if (procAgglomLeveli >= 0 && leveli > procAgglomLeveli)
203 const label comm = agglom.agglomCommunicator(procAgglomLeveli);
207 addr = agglom.restrictAddressing(leveli);
211 for (
auto& addri : cellsPerLevel)
219 const labelField& addr = agglom.restrictAddressing(leveli);
221 for (
auto& addri : cellsPerLevel)
230 Foam::functionObjects::agglomerationInfo::initAgglomField
232 const GAMGAgglomeration& agglom,
234 const label procAgglomLeveli
240 word levelSuffix =
"";
242 if (leveli == agglom.size() - 1)
244 levelSuffix =
"_coarsest";
245 if (procAgglomLeveli >= 0)
247 levelSuffix +=
"_procAgglom";
251 const word writtenName =
252 "GAMGAgglom_" + fieldName_
262 mesh_.time().timeName(),
298 fieldName_ =
dict.get<
word>(
"field");
300 const auto& solverDict = mesh_.solution().solver(fieldName_);
302 const word solverType = solverDict.get<
word>(
"solver");
304 if (solverType != GAMGSolver::typeName)
307 <<
"Solver for field '" << fieldName_ <<
"' is not a " 308 << GAMGSolver::typeName <<
" solver. " 309 <<
"Agglomeration info is only available for GAMG." 314 solverDict.getOrDefault<
word>(
"name", GAMGAgglomeration::typeName);
332 const label nLevels = agglom.
size();
337 <<
"GAMGAgglomeration '" << agglomName_ <<
"' has no levels. " 338 <<
"Nothing to write." <<
nl;
344 label procAgglomLeveli = -1;
345 for (label leveli = 0; leveli < nLevels; ++leveli)
349 procAgglomLeveli = leveli;
354 writeHeaderValue(os,
"name",
name());
355 writeHeaderValue(os,
"time", mesh_.time().timeName());
356 writeHeaderValue(os,
"field", fieldName_);
357 writeHeaderValue(os,
"levels", nLevels+1);
359 if (procAgglomLeveli >= 0)
361 writeHeaderValue(os,
"proc-agglom@level", procAgglomLeveli+1);
364 writeCommented(os,
"level");
365 writeTabbed(os,
"total");
366 writeTabbed(os,
"min");
367 writeTabbed(os,
"avg");
368 writeTabbed(os,
"max");
369 writeTabbed(os,
"assigned");
370 writeTabbed(os,
"field");
383 const label statsComm = mesh_.comm();
385 for (label leveli = 0; leveli < nLevels; ++leveli)
387 setCellsPerLevel(agglom, leveli, procAgglomLeveli, cellsPerLevel);
394 label displayNCells = 0;
399 for (label
n : allNCells)
404 minNCells =
min(minNCells,
n);
405 maxNCells =
max(maxNCells,
n);
411 const scalar avgNCells =
412 nActive > 0 ? scalar(displayNCells)/nActive : 0;
420 if (procAgglomLeveli < 0)
426 myOffseti += allNCells[
p];
443 const label myMasterRank =
445 label groupOffseti = 0;
446 for (label
p = 0;
p < myMasterRank; ++
p)
448 if (allNCells[
p] >= 0)
450 groupOffseti += allNCells[
p];
453 if (groupOffseti > 0)
462 auto tagglomField = initAgglomField(agglom, leveli, procAgglomLeveli);
463 auto& agglomField = tagglomField.ref();
466 forAll(agglomField, celli)
468 agglomField[celli] = scalar(
writeField[celli]);
479 if (procAgglomLeveli < 0 || leveli < procAgglomLeveli)
481 const label nP = label(allNCells.size());
484 else if (leveli == procAgglomLeveli)
492 assignedStr =
Foam::name(nActive) +
"_masters";
495 os << levelStr <<
tab 496 << displayNCells <<
tab 498 << label(avgNCells) <<
tab 500 << assignedStr <<
tab 501 << agglomField.name() <<
tab 502 << (leveli == nLevels - 1 ?
"\n\n" :
"\n");
504 Info<<
" Writing agglomeration field for level " << leveli + 1
505 <<
" : " << agglomField.name() <<
endl;
510 Info<<
" Written file: " << os.name() <<
nl <<
endl;
bool hasProcMesh(const label fineLeveli) const
Check that level has combined mesh.
Field< label > labelField
Specialisation of Field<T> for label.
defineTypeNameAndDebug(ObukhovLength, 0)
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...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static int myProcNo(label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
constexpr char tab
The tab '\t' character(0x09)
static int & msgType() noexcept
Message tag of standard messages.
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
bool writeField(ensightOutput::floatBufferType &scratch, ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
Write a field of cell values as an indirect list, using the cell ids from ensightCells.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Macros for easy insertion into run-time selection tables.
static void gatherList(UList< T > &values, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather data, but keep individual values separate.
bool read(const char *buf, int32_t &val)
Same as readInt32.
#define forAll(list, i)
Loop across all elements in list.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
virtual bool write()
Write the function-object results.
const labelList & agglomProcIDs(const label fineLeveli) const
Set of processors to agglomerate. Element 0 is the master processor. (local, same only on those proce...
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual bool read(const dictionary &dict)
Read.
agglomerationInfo(const agglomerationInfo &)=delete
No copy construct.
static label nProcs(label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const labelField & restrictAddressing(const label leveli) const
Return cell restrict addressing of given level.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
List< label > labelList
A List of labels.
A class for managing temporary objects.
Base class for writing single files from the function objects.
Geometric agglomerated algebraic multigrid agglomeration class.
const fvMesh & mesh_
Reference to the fvMesh.
Do not request registration (bool: false)
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)