183 const auto& procMesh = procMeshList[proci];
186 if (procAddressingList.
size() < procMeshList.
size())
188 procAddressingList.
resize(procMeshList.
size());
197 procMesh.facesInstance(),
219 const auto& procMesh = procMeshList[proci];
222 if (procAddressingList.
size() < procMeshList.
size())
224 procAddressingList.
resize(procMeshList.
size());
233 procMesh.facesInstance(),
252 if (!procTimes.
test(proci))
267 return procTimes[proci];
271 void decomposeUniform
273 const bool copyUniform,
275 const Time& processorDb,
286 Info<<
"Detected additional non-decomposed files in " 306 if (copyUniform ||
mesh.distributed())
320 string parentPath =
string(
"..")/
"..";
324 parentPath = parentPath/
"..";
346 using namespace Foam;
350 int main(
int argc,
char *argv[])
354 "Decompose a mesh and fields of a case for parallel execution" 362 "Alternative decomposePar dictionary file" 370 "Test without writing the decomposition. " 371 "Changes -cellDist to only write VTK output." 378 "Override numberOfSubdomains (-dry-run only)",
385 "Override decomposition method (-dry-run only)",
392 "Suppress finiteArea mesh/field decomposition",
399 "Suppress lagrangian (cloud) decomposition",
405 "disable-edge-encoding",
406 "Emit edgeProcAddressing without encoding edge flips, " 407 "as per 2512 and earlier [special use]",
414 "Write cell distribution as a labelList - for use with 'manual' " 415 "decomposition method and as a volScalarField for visualization." 420 "Copy 0/ directory to processor*/ rather than decompose the fields" 425 "Copy any uniform/ directories too" 430 "Use existing geometry decomposition and convert fields only" 435 "Suppress conversion of fields (volume, finite-area, lagrangian)" 441 "Skip decomposing cellSets, faceSets, pointSets" 448 "Remove existing processor*/ subdirs before decomposing the geometry" 453 "Only decompose geometry if the number of domains has changed" 467 const bool writeCellDist =
args.
found(
"cellDist");
470 const bool copyZero =
args.
found(
"copyZero");
471 const bool copyUniform =
args.
found(
"copyUniform");
472 const bool decomposeSets = !
args.
found(
"no-sets");
474 const bool decomposeIfRequired =
args.
found(
"ifRequired");
476 const bool doDecompFields = !
args.
found(
"no-fields");
477 const bool doFiniteArea = !
args.
found(
"no-finite-area");
478 const bool doLagrangian = !
args.
found(
"no-lagrangian");
480 bool decomposeFieldsOnly =
args.
found(
"fields");
481 bool forceOverwrite =
args.
found(
"force");
497 Info<<
"\ndry-run: ignoring -copy*, -fields, -force, time selection" 502 if (decomposeFieldsOnly && !doDecompFields)
505 <<
"Options -fields and -no-fields are mutually exclusive" 506 <<
" ... giving up" <<
nl 512 Info<<
"Skip decompose of all fields" <<
nl;
516 Info<<
"Skip decompose of finiteArea mesh/fields" <<
nl;
520 Info<<
"Skip decompose of lagrangian positions/fields" <<
nl;
532 && !decompDictFile.empty() && !decompDictFile.
isAbsolute()
549 const bool optRegions =
565 <<
"Create mesh..." <<
flush;
587 Info<<
"\n\nDecomposing mesh";
595 const label nProcsOld =
624 if (decomposeFieldsOnly)
627 if (nProcsOld != nDomains)
630 <<
"Specified -fields, but the case was decomposed with " 631 << nProcsOld <<
" domains" 633 <<
"instead of " << nDomains
634 <<
" domains as specified in decomposeParDict" <<
nl 640 bool procDirsProblem =
true;
642 if (decomposeIfRequired && nProcsOld == nDomains)
645 decomposeFieldsOnly =
true;
646 procDirsProblem =
false;
647 forceOverwrite =
false;
649 Info<<
"Using existing processor directories" <<
nl;
654 procDirsProblem =
false;
655 forceOverwrite =
false;
660 Info<<
"Removing " << nProcsOld
661 <<
" existing processor directories" <<
endl;
669 fileName::Type::DIRECTORY
698 procDirsProblem =
false;
704 <<
"Case is already decomposed with " << nProcsOld
705 <<
" domains, use the -force option or manually" <<
nl 706 <<
"remove processor directories before decomposing. e.g.," 708 <<
" rm -rf " <<
runTime.
path().c_str() <<
"/processor*" 733 if (!decomposeFieldsOnly)
735 mesh.decomposeMesh();
736 mesh.writeDecomposition(decomposeSets);
743 mesh.writeVolField(
"cellDist");
761 Info<<
nl <<
"Wrote decomposition to " 762 <<
io.objectRelPath()
763 <<
" for use in manual decomposition." <<
endl;
776 const word boundaryInst =
808 if (!decomposeFieldsOnly)
811 auto& aMesh = faDecompPtr();
812 Info<<
"\nFinite area mesh decomposition: " 815 aMesh.decomposeMesh();
816 aMesh.writeDecomposition();
819 faMeshEdgeEncoding.
set 827 faMeshes.
set(areaName, std::move(faDecompPtr));
844 inputDir.ext(
"orig");
853 for (label proci = 0; proci <
mesh.nProcs(); ++proci)
881 if (outputDir != prevOutputDir)
883 Info<<
"Processor " << proci
885 << inputDir.name() <<
"/\" to " 890 prevOutputDir = outputDir;
896 Info<<
"No 0/ or 0.orig/ directory to copy" <<
nl;
902 const auto numProcs =
mesh.nProcs();
933 && !faMeshes.
empty() && faMeshEdgeEncoding.
empty()
936 for (label proci = numProcs-1; proci >= 0; --proci)
938 auto& procTime = emplaceTime(processorDbList, proci,
args);
942 const word& areaName = iter.key();
944 if (faMeshEdgeEncoding.
contains(areaName))
952 "edgeProcAddressing",
977 faMeshEdgeEncoding.
set 980 (edgeProcAddr[i] < 0)
988 if (!faMeshEdgeEncoding.
empty())
993 const auto& areaName = iter.key();
994 const bool encoding = iter.val();
1001 Info<<
"Area region without edge encoding:" <<
nl;
1003 Info<<
" " << areaName;
1029 objects.
remove(
"cellDist");
1036 if (doDecompFields && doFiniteArea && faMeshes.
size())
1043 const word& areaName = iter.key();
1089 if (doDecompFields && doLagrangian)
1116 for (
const fileName& cloudDir : cloudDirs)
1129 cloudObjects.found(
"coordinates")
1130 || cloudObjects.found(
"positions")
1136 Info<<
"Identified lagrangian data set: " 1137 << cloudDir <<
endl;
1139 lagrangianPositions.set
1170 label celli =
p.cell();
1176 <<
"Illegal cell number " << celli
1177 <<
" for particle with index " 1180 <<
p.position() <<
nl 1181 <<
"Cell number should be between 0 and " 1183 <<
"On this mesh the particle should" 1189 if (!cellParticles[cloudI][celli])
1191 cellParticles[cloudI][celli] =
1195 cellParticles[cloudI][celli]->
append(&
p);
1209 lagrangianFieldCache.readAllFields
1219 lagrangianPositions.
resize(cloudI);
1220 cellParticles.resize(cloudI);
1221 lagrangianFieldCache.resize(cloudI);
1229 if (doDecompFields && doFiniteArea)
1233 const word& areaName = iter.key();
1234 const auto& objs = iter.val();
1238 const auto meshIter = faMeshes.
cfind(areaName);
1239 (meshIter.good() && !objs.empty())
1242 const faMesh& aMesh = *(meshIter.val());
1243 auto& cache = areaFieldCaches.
emplace_set(areaName);
1256 doDecompFields && proci < numProcs;
1260 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
1263 emplaceTime(processorDbList, proci,
args);
1267 const auto& procMesh = procMeshList.try_emplace
1278 const auto& faceProcAddressing = procAddressing
1282 "faceProcAddressing",
1283 faceProcAddressingList
1286 const auto& cellProcAddressing = procAddressing
1290 "cellProcAddressing",
1291 cellProcAddressingList
1294 const auto& boundaryProcAddressing = procAddressing
1298 "boundaryProcAddressing",
1299 boundaryProcAddressingList
1305 if (!fieldDecomposerList.test(proci))
1307 fieldDecomposerList.set
1316 boundaryProcAddressing
1323 fieldDecomposerList[proci]
1326 if (times.
size() == 1)
1329 fieldDecomposerList.set(proci,
nullptr);
1335 if (!pointFieldCache.
empty())
1337 const auto& pointProcAddressing = procAddressing
1341 "pointProcAddressing",
1342 pointProcAddressingList
1348 if (!pointBoundaryProcAddressingList.test(proci))
1350 pointBoundaryProcAddressingList.set
1357 "boundaryProcAddressing",
1358 procMesh.facesInstance(),
1366 boundaryProcAddressing
1370 const auto& pointBoundaryProcAddressing =
1371 pointBoundaryProcAddressingList[proci];
1374 if (!pointFieldDecomposerList.test(proci))
1376 pointFieldDecomposerList.set
1383 pointProcAddressing,
1384 pointBoundaryProcAddressing
1391 pointFieldDecomposerList[proci]
1394 if (times.
size() == 1)
1397 pointBoundaryProcAddressingList.set
1402 pointProcAddressingList.set(proci,
nullptr);
1403 pointFieldDecomposerList.set(proci,
nullptr);
1409 forAll(lagrangianPositions, cloudi)
1411 if (lagrangianPositions[cloudi].size())
1420 lagrangianPositions[cloudi],
1421 cellParticles[cloudi]
1425 lagrangianFieldCache.decomposeAllFields
1447 decomposeUniform(copyUniform,
mesh, processorDb);
1451 if (times.
size() == 1)
1454 boundaryProcAddressingList.set(proci,
nullptr);
1455 cellProcAddressingList.set(proci,
nullptr);
1456 faceProcAddressingList.set(proci,
nullptr);
1460 for (
const auto& iter : areaFieldCaches.
csorted())
1462 const word& areaName = iter.key();
1463 const auto& areaCache = *(iter.val());
1466 const faMesh& aMesh = *(faMeshes[areaName]);
1469 auto& faProcMeshList =
1474 .try_emplace(proci, areaName, procMesh);
1476 const auto& faFaceProcAddr =
1481 "faceProcAddressing",
1485 const auto& faBoundProcAddr =
1490 "boundaryProcAddressing",
1494 const auto& faEdgeProcAddr =
1499 "edgeProcAddressing",
1504 auto& faFieldDecomposerList =
1505 faFieldDecomposers.
try_emplace(areaName, numProcs);
1507 if (!faFieldDecomposerList.test(proci))
1509 faFieldDecomposerList.emplace
1519 (!faMeshEdgeEncoding.
lookup(areaName,
true))
1523 auto& fieldDecomposer = faFieldDecomposerList[proci];
1525 areaCache.decomposeAllFields
1535 if (times.
size() == 1)
1539 iter.val()->set(proci,
nullptr);
1543 iter.val()->set(proci,
nullptr);
1547 iter.val()->set(proci,
nullptr);
1551 iter.val()->set(proci,
nullptr);
1555 iter.val()->set(proci,
nullptr);
1558 procMeshList.
set(proci,
nullptr);
1559 processorDbList.
set(proci,
nullptr);
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
T & try_emplace(const Key &key, Args &&... args)
Like emplace_set() but will not overwrite an occupied (non-null) location.
const T * test(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const fileName & facesInstance() const
Return the current instance directory for faces.
void append(const T &elem)
Add copy at back of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
bool empty() const noexcept
No fields.
fileName timePath() const
Return current time path = path/timeName.
fileName path() const
The path for the case = rootPath/caseName.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
bool allowFaModels() noexcept
The enable/disable state for regionFaModel (default: true)
void readAllFields(const faMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
Template class for non-intrusive linked lists.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool chDir(const fileName &dir)
Change current directory to the one specified and return true on success.
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath...
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
UPtrList< const node_type > csorted() const
Const access to the hash-table contents in sorted order (sorted by keys).
static void noParallel()
Remove the parallel options.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
static const word canonicalName
The canonical name ("decomposeParDict") under which the MeshObject is registered. ...
fileName globalPath() const
The global path for the case = rootPath/globalCaseName.
static bool isAbsolute(const std::string &str)
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root.
Ignore writing from objectRegistry::writeObject()
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
void decomposeAllFields(const fvFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
static void writeContents(const IOobject &io, const UList< label > &content)
Write contents. The IOobject is never registered.
const Time & time() const
Return the top-level database.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Automatic domain decomposition class for finite-volume meshes.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool allowFunctionObjects() const
The controlDict 'functions' entry is allowed to be used.
#define FOAM_NO_DANGLING_REFERENCE
void readAllFields(const pointMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
bool emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
bool read(const char *buf, int32_t &val)
Same as readInt32.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Mesh representing a set of points created from polyMesh.
#define forAll(list, i)
Loop across all elements in list.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
label size() const noexcept
The number of elements in table.
bool allowLibs() const
The controlDict 'libs' entry is allowed to be used. (eg, has not been disabled by the -no-libs option...
static const objectRegistry & Registry(const polyMesh &pMesh)
Return the singleton parent registry (on the polyMesh) that contains all objects related to finite-ar...
void readAllFields(const fvMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
static List< label > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
T & emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
bool contains(const Key &key) const
True if hashed key is contained (found) in table.
word findInstance(const fileName &directory, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null, const bool constant_fallback=true) const
Return time instance (location) of directory containing the file name (eg, used in reading mesh data)...
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
void clear()
Clear the list, i.e. set size to zero.
A class for handling words, derived from Foam::string.
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
const Time & time() const noexcept
Return time registry.
const word & executable() const noexcept
Name of executable without the path.
int dryRun() const noexcept
Return the dry-run flag.
static word defaultRegion
Return the default region name.
Extract command arguments and options from the supplied argc and argv parameters. ...
label size() const noexcept
The number of entries in the list.
bool set(const Key &key, T *ptr)
Assign a new entry, overwrites existing.
const word & system() const noexcept
Return system name.
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
Reading is optional [identical to LAZY_READ].
#define forAllIters(container, iter)
Iterate across all elements in the container object.
static const word null
An empty word.
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?
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
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...
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
A HashTable similar to std::unordered_map.
static word controlDictName
The default control dictionary name (normally "controlDict")
A list of pointers to objects of type <T>, without 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...
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
label nDomains() const noexcept
Number of domains.
void resize(label newCapacity)
Rehash the hash table with new number of buckets. Currently identical to setCapacity() ...
bool empty() const noexcept
True if the hash table is empty.
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
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.
const fileName & rootPath() const noexcept
Return root path.
T & try_emplace(const label i, Args &&... args)
Like emplace_set() but will not overwrite an occupied (non-null) location.
Finite Volume volume and surface field decomposer.
void resize(const label newLen)
Adjust size of PtrList.
void decomposeAllFields(const pointFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
static word meshSubDir
Return the mesh sub-directory name (usually "pointMesh")
static word meshSubDir
The mesh sub-directory name (usually "faMesh")
bool starts_with(char c) const
True if string starts with given character (cf. C++20)
Ostream & flush(Ostream &os)
Flush stream.
const T & lookup(const Key &key, const T &deflt) const
Return hashed entry if it exists, or return the given default.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
label nCells() const noexcept
Number of mesh cells.
autoPtr< IOobject > remove(const IOobject &io)
Remove object from the list by its IOobject::name().
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
fileName cwd()
The physical or logical current working directory path name.
Finite area boundary mesh, which is a faPatch list with registered IO, a reference to the associated ...
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label find_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
#define forAllReverse(list, i)
Reverse loop across all elements in list.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Testing of domain decomposition for finite-volume meshes.
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.
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
A class for handling character strings derived from std::string.
Adds label index to base particle.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
int verbose() const noexcept
Return the verbose flag.
Do not request registration (bool: false)
bool found(const word &optName) const
Return true if the named option is found.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
forAllConstIters(mixture.phases(), phase)
static IOobject selectIO(const IOobject &io, const fileName &altFile, const word &ioName="")
Return the IOobject, but also consider an alternative file name.
static bool allowEdgeEncoding() noexcept
The enable/disable state for allowing encoding of edgeProcAddressing edge flips (default: true) ...
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Lagrangian field decomposer.
static const word prefix
The prefix to local: lagrangian.