178 const word& instance,
204 const word& instance,
208 return procAddressing(procRegistry,
name, instance,
local);
222 const auto& procMesh = procMeshList[proci];
243 const bool copyUniform,
245 const Time& processorDb,
256 Info<<
"Detected additional non-decomposed files in "
277 if (copyUniform ||
mesh.distributed())
291 string parentPath =
string(
"..")/
"..";
295 parentPath = parentPath/
"..";
321int main(
int argc,
char *argv[])
325 "Decompose a mesh and fields of a case for parallel execution"
333 "Alternative decomposePar dictionary file"
341 "Test without writing the decomposition. "
342 "Changes -cellDist to only write VTK output."
349 "Override numberOfSubdomains (-dry-run only)",
356 "Override decomposition method (-dry-run only)",
363 "Suppress finiteArea mesh/field decomposition",
370 "Suppress lagrangian (cloud) decomposition",
377 "Write cell distribution as a labelList - for use with 'manual' "
378 "decomposition method and as a volScalarField for visualization."
383 "Copy 0/ directory to processor*/ rather than decompose the fields"
388 "Copy any uniform/ directories too"
393 "Use existing geometry decomposition and convert fields only"
398 "Suppress conversion of fields (volume, finite-area, lagrangian)"
404 "Skip decomposing cellSets, faceSets, pointSets"
411 "Remove existing processor*/ subdirs before decomposing the geometry"
416 "Only decompose geometry if the number of domains has changed"
430 const bool writeCellDist =
args.found(
"cellDist");
433 const bool copyZero =
args.found(
"copyZero");
434 const bool copyUniform =
args.found(
"copyUniform");
435 const bool decomposeSets = !
args.found(
"no-sets");
437 const bool decomposeIfRequired =
args.found(
"ifRequired");
439 const bool doDecompFields = !
args.found(
"no-fields");
440 const bool doFiniteArea = !
args.found(
"no-finite-area");
441 const bool doLagrangian = !
args.found(
"no-lagrangian");
443 bool decomposeFieldsOnly =
args.found(
"fields");
444 bool forceOverwrite =
args.found(
"force");
453 Info<<
"\ndry-run: ignoring -copy*, -fields, -force, time selection"
458 if (decomposeFieldsOnly && !doDecompFields)
461 <<
"Options -fields and -no-fields are mutually exclusive"
462 <<
" ... giving up" <<
nl
468 Info<<
"Skip decompose of all fields" <<
nl;
472 Info<<
"Skip decompose of finiteArea mesh/fields" <<
nl;
476 Info<<
"Skip decompose of lagrangian positions/fields" <<
nl;
487 args.readIfPresent(
"decomposeParDict", decompDictFile)
488 && !decompDictFile.empty() && !decompDictFile.
isAbsolute()
491 decompDictFile =
runTime.globalPath()/decompDictFile;
505 const bool optRegions =
521 <<
"Create mesh..." <<
flush;
535 args.getOrDefault<label>(
"domains", 0),
539 decompTest.execute(writeCellDist,
args.verbose());
543 Info<<
"\n\nDecomposing mesh";
551 const label nProcsOld =
580 if (decomposeFieldsOnly)
583 if (nProcsOld != nDomains)
586 <<
"Specified -fields, but the case was decomposed with "
587 << nProcsOld <<
" domains"
589 <<
"instead of " << nDomains
590 <<
" domains as specified in decomposeParDict" <<
nl
596 bool procDirsProblem =
true;
598 if (decomposeIfRequired && nProcsOld == nDomains)
601 decomposeFieldsOnly =
true;
602 procDirsProblem =
false;
603 forceOverwrite =
false;
605 Info<<
"Using existing processor directories" <<
nl;
610 procDirsProblem =
false;
611 forceOverwrite =
false;
616 Info<<
"Removing " << nProcsOld
617 <<
" existing processor directories" <<
endl;
654 procDirsProblem =
false;
660 <<
"Case is already decomposed with " << nProcsOld
661 <<
" domains, use the -force option or manually" <<
nl
662 <<
"remove processor directories before decomposing. e.g.,"
664 <<
" rm -rf " <<
runTime.path().c_str() <<
"/processor*"
689 if (!decomposeFieldsOnly)
691 mesh.decomposeMesh();
692 mesh.writeDecomposition(decomposeSets);
699 mesh.writeVolField(
"cellDist");
709 mesh.facesInstance(),
717 cellDecomposition.write();
719 Info<<
nl <<
"Wrote decomposition to "
720 << cellDecomposition.objectRelPath()
721 <<
" for use in manual decomposition." <<
endl;
739 inputDir.ext(
"orig");
748 for (label proci = 0; proci <
mesh.nProcs(); ++proci)
776 if (outputDir != prevOutputDir)
778 Info<<
"Processor " << proci
780 << inputDir.name() <<
"/\" to "
781 <<
runTime.relativePath(outputDir)
785 prevOutputDir = outputDir;
791 Info<<
"No 0/ or 0.orig/ directory to copy" <<
nl;
818 runTime.setTime(times[timei], timei);
834 objects.
remove(
"cellDist");
863 const word boundaryInst =
864 mesh.time().findInstance(
mesh.meshDir(),
"boundary");
882 faMeshDecompHashes.
set
929 if (doDecompFields && doLagrangian)
956 for (
const fileName& cloudDir : cloudDirs)
969 cloudObjects.found(
"coordinates")
970 || cloudObjects.found(
"positions")
976 Info<<
"Identified lagrangian data set: "
979 lagrangianPositions.set
1010 label celli =
p.cell();
1013 if (celli < 0 || celli >=
mesh.nCells())
1016 <<
"Illegal cell number " << celli
1017 <<
" for particle with index "
1020 <<
p.position() <<
nl
1021 <<
"Cell number should be between 0 and "
1023 <<
"On this mesh the particle should"
1025 <<
mesh.findCell(
p.position())
1029 if (!cellParticles[cloudI][celli])
1031 cellParticles[cloudI][celli] =
1035 cellParticles[cloudI][celli]->append(&
p);
1049 lagrangianFieldCache.readAllFields
1059 lagrangianPositions.resize(cloudI);
1060 cellParticles.resize(cloudI);
1061 lagrangianFieldCache.resize(cloudI);
1069 doDecompFields && proci <
mesh.nProcs();
1073 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
1076 if (!processorDbList.set(proci))
1087 args.allowFunctionObjects(),
1092 Time& processorDb = processorDbList[proci];
1098 if (!procMeshList.
set(proci))
1114 const fvMesh& procMesh = procMeshList[proci];
1116 const labelIOList& faceProcAddressing = procAddressing
1120 "faceProcAddressing",
1121 faceProcAddressingList
1124 const labelIOList& cellProcAddressing = procAddressing
1128 "cellProcAddressing",
1129 cellProcAddressingList
1132 const labelIOList& boundaryProcAddressing = procAddressing
1136 "boundaryProcAddressing",
1137 boundaryProcAddressingList
1143 if (!fieldDecomposerList.set(proci))
1145 fieldDecomposerList.set
1154 boundaryProcAddressing
1161 fieldDecomposerList[proci]
1164 if (times.
size() == 1)
1167 fieldDecomposerList.set(proci,
nullptr);
1173 if (!pointFieldCache.
empty())
1175 const labelIOList& pointProcAddressing = procAddressing
1179 "pointProcAddressing",
1180 pointProcAddressingList
1186 if (!pointBoundaryProcAddressingList.set(proci))
1188 pointBoundaryProcAddressingList.set
1195 "boundaryProcAddressing",
1204 boundaryProcAddressing
1208 const auto& pointBoundaryProcAddressing =
1209 pointBoundaryProcAddressingList[proci];
1212 if (!pointFieldDecomposerList.set(proci))
1214 pointFieldDecomposerList.set
1221 pointProcAddressing,
1222 pointBoundaryProcAddressing
1229 pointFieldDecomposerList[proci]
1232 if (times.
size() == 1)
1235 pointBoundaryProcAddressingList.set
1240 pointProcAddressingList.set(proci,
nullptr);
1241 pointFieldDecomposerList.set(proci,
nullptr);
1247 forAll(lagrangianPositions, cloudi)
1249 if (lagrangianPositions[cloudi].size())
1258 lagrangianPositions[cloudi],
1259 cellParticles[cloudi]
1263 lagrangianFieldCache.decomposeAllFields
1285 decomposeUniform(copyUniform,
mesh, processorDb);
1293 if (times.
size() == 1)
1295 boundaryProcAddressingList.set(proci,
nullptr);
1296 cellProcAddressingList.set(proci,
nullptr);
1297 faceProcAddressingList.set(proci,
nullptr);
1298 procMeshList.
set(proci,
nullptr);
1299 processorDbList.set(proci,
nullptr);
1305 for (
auto& iter : faMeshDecompHashes.
sorted())
1307 const word& areaName = iter.key();
1311 Info<<
"\nFinite area mesh decomposition: "
1312 << areaName <<
endl;
1325 const auto objs = faObjects.
cfind(areaName);
1326 doDecompFields && objs.
good()
1332 const label nAreaFields = areaFieldCache.
size();
1335 Info<<
"Finite area field transfer: "
1336 << nAreaFields <<
" fields" <<
endl;
1342 nAreaFields && proci <
mesh.nProcs();
1346 Info<<
" Processor " << proci <<
endl;
1371 faMesh procMesh(areaName, procFvMesh);
1398 "faceProcAddressing",
1401 auto& faceProcAddressing = *tfaceProcAddr;
1407 "boundaryProcAddressing",
1410 auto& boundaryProcAddressing = *tboundaryProcAddr;
1416 "edgeProcAddressing",
1419 const auto& edgeProcAddressing = *tedgeProcAddr;
1427 boundaryProcAddressing
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Base cloud calls templated on particle type.
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
bool set(const Key &key, T *ptr)
Assign a new entry, overwrites existing.
bool good() const noexcept
True if iterator points to an entry.
A HashTable similar to std::unordered_map.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
bool emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
UPtrList< node_type > sorted()
Non-const access to the hash-table contents in sorted order (sorted by keys).
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
autoPtr< IOobject > remove(const IOobject &io)
Remove object from the list by its IOobject::name().
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static IOobject selectIO(const IOobject &io, const fileName &altFile, const word &ioName="")
Return the IOobject, but also consider an alternative file name.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
T & try_emplace(const label i, Args &&... args)
Like emplace_set() but will not overwrite an occupied (non-null) location.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
static word controlDictName
The default control dictionary name (normally "controlDict").
fileName timePath() const
Return current time path = path/timeName.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
void size(const label n)
Older name for setAddressableSize.
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void noParallel()
Remove the parallel options.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
static const word prefix
The prefix to local: lagrangian.
static label nDomains(const dictionary &decompDict, const word ®ionName="")
Return region-specific or top-level numberOfSubdomains entry.
static const word canonicalName
The canonical name ("decomposeParDict") under which the MeshObject is registered.
Testing of domain decomposition for finite-volume meshes.
Automatic domain decomposition class for finite-volume meshes.
Finite area boundary mesh, which is a faPatch list with registered IO, a reference to the associated ...
label size() const
Number of fields.
void readAllFields(const faMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
void decomposeAllFields(const faFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
Finite Area area and edge field decomposer.
Automatic faMesh decomposition class.
bool writeDecomposition() const
Write decomposition.
void decomposeMesh()
Decompose mesh.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
static const objectRegistry & Registry(const polyMesh &pMesh)
Return the singleton parent registry (on the polyMesh) that contains all objects related to finite-ar...
static word meshSubDir
The mesh sub-directory name (usually "faMesh").
A class for handling file names.
static std::string path(const std::string &str)
Return directory path name (part before last /).
static bool isAbsolute(const std::string &str)
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root.
An encapsulation of filesystem-related operations.
void readAllFields(const fvMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
void decomposeAllFields(const fvFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
Finite Volume volume and surface field decomposer.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
Adds label index to base particle.
Lagrangian field decomposer.
Registry of regIOobjects.
void readAllFields(const pointMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
bool empty() const noexcept
No fields.
void decomposeAllFields(const pointFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
Mesh representing a set of points created from polyMesh.
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
static word meshSubDir
Return the mesh sub-directory name (usually "pointMesh").
static const word & regionName(const word ®ion)
The mesh region name or word::null if polyMesh::defaultRegion.
const fileName & facesInstance() const
Return the current instance directory for faces.
static word defaultRegion
Return the default region name.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
A class for handling character strings derived from std::string.
bool starts_with(char c) const
True if string starts with given character (cf. C++20).
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times - as per select0() - otherwise return just the cu...
A class for handling words, derived from Foam::string.
static const word null
An empty word.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
bool allowFaModels() noexcept
The enable/disable state for regionFaModel (default: true).
fileName cwd()
The physical or logical current working directory path name.
LList< SLListBase, T > SLList
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
IOList< label > labelIOList
IO for a List of label.
List< fileName > fileNameList
List of fileName.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Ostream & endl(Ostream &os)
Add newline and flush stream.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Ostream & flush(Ostream &os)
Flush stream.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
constexpr char nl
The newline '\n' character (0x0a).
bool chDir(const fileName &dir)
Change current directory to the one specified and return true on success.
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
#define FOAM_NO_DANGLING_REFERENCE
#define forAllReverse(list, i)
Reverse loop across all elements in list.