178 const word& instance,
204 const word& instance,
208 return procAddressing(procRegistry,
name, instance,
local);
222 const auto& procMesh = procMeshList[proci];
241 void decomposeUniform
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/
"..";
317 using namespace Foam;
321 int main(
int argc,
char *argv[])
325 "Decompose a mesh and fields of a case for parallel execution" 333 "Alternative decomposePar dictionary file" 340 "Test without writing the decomposition. " 341 "Changes -cellDist to only write VTK output." 348 "Override numberOfSubdomains (-dry-run only)",
355 "Override decomposition method (-dry-run only)",
362 "Suppress finiteArea mesh/field decomposition",
369 "Suppress lagrangian (cloud) decomposition",
376 "Write cell distribution as a labelList - for use with 'manual' " 377 "decomposition method and as a volScalarField for visualization." 382 "Copy 0/ directory to processor*/ rather than decompose the fields" 387 "Copy any uniform/ directories too" 392 "Use existing geometry decomposition and convert fields only" 397 "Suppress conversion of fields (volume, finite-area, lagrangian)" 403 "Skip decomposing cellSets, faceSets, pointSets" 410 "Remove existing processor*/ subdirs before decomposing the geometry" 415 "Only decompose geometry if the number of domains has changed" 423 const bool writeCellDist =
args.
found(
"cellDist");
426 const bool copyZero =
args.
found(
"copyZero");
427 const bool copyUniform =
args.
found(
"copyUniform");
428 const bool decomposeSets = !
args.
found(
"no-sets");
430 const bool decomposeIfRequired =
args.
found(
"ifRequired");
432 const bool doDecompFields = !
args.
found(
"no-fields");
433 const bool doFiniteArea = !
args.
found(
"no-finite-area");
434 const bool doLagrangian = !
args.
found(
"no-lagrangian");
436 bool decomposeFieldsOnly =
args.
found(
"fields");
437 bool forceOverwrite =
args.
found(
"force");
447 Info<<
"\ndry-run: ignoring -copy*, -fields, -force, time selection" 452 if (decomposeFieldsOnly && !doDecompFields)
455 <<
"Options -fields and -no-fields are mutually exclusive" 456 <<
" ... giving up" <<
nl 462 Info<<
"Skip decompose of all fields" <<
nl;
466 Info<<
"Skip decompose of finiteArea mesh/fields" <<
nl;
470 Info<<
"Skip decompose of lagrangian positions/fields" <<
nl;
482 && !decompDictFile.empty() && !decompDictFile.
isAbsolute()
491 const bool optRegions =
507 <<
"Create mesh..." <<
flush;
529 Info<<
"\n\nDecomposing mesh";
537 const label nProcsOld =
566 if (decomposeFieldsOnly)
569 if (nProcsOld != nDomains)
572 <<
"Specified -fields, but the case was decomposed with " 573 << nProcsOld <<
" domains" 575 <<
"instead of " << nDomains
576 <<
" domains as specified in decomposeParDict" <<
nl 582 bool procDirsProblem =
true;
584 if (decomposeIfRequired && nProcsOld == nDomains)
587 decomposeFieldsOnly =
true;
588 procDirsProblem =
false;
589 forceOverwrite =
false;
591 Info<<
"Using existing processor directories" <<
nl;
596 procDirsProblem =
false;
597 forceOverwrite =
false;
602 Info<<
"Removing " << nProcsOld
603 <<
" existing processor directories" <<
endl;
611 fileName::Type::DIRECTORY
640 procDirsProblem =
false;
646 <<
"Case is already decomposed with " << nProcsOld
647 <<
" domains, use the -force option or manually" <<
nl 648 <<
"remove processor directories before decomposing. e.g.," 650 <<
" rm -rf " <<
runTime.
path().c_str() <<
"/processor*" 675 if (!decomposeFieldsOnly)
677 mesh.decomposeMesh();
678 mesh.writeDecomposition(decomposeSets);
685 mesh.writeVolField(
"cellDist");
703 cellDecomposition.write();
705 Info<<
nl <<
"Wrote decomposition to " 706 << cellDecomposition.objectRelPath()
707 <<
" for use in manual decomposition." <<
endl;
725 inputDir.ext(
"orig");
734 for (label proci = 0; proci <
mesh.nProcs(); ++proci)
762 if (outputDir != prevOutputDir)
764 Info<<
"Processor " << proci
766 << inputDir.name() <<
"/\" to " 771 prevOutputDir = outputDir;
777 Info<<
"No 0/ or 0.orig/ directory to copy" <<
nl;
827 objects.
remove(
"cellDist");
834 const word boundaryInst =
851 faMeshDecompPtr.
reset 895 if (doDecompFields && doLagrangian)
922 for (
const fileName& cloudDir : cloudDirs)
935 cloudObjects.found(
"coordinates")
936 || cloudObjects.found(
"positions")
942 Info<<
"Identified lagrangian data set: " 945 lagrangianPositions.set
976 label celli =
p.cell();
982 <<
"Illegal cell number " << celli
983 <<
" for particle with index " 986 <<
p.position() <<
nl 987 <<
"Cell number should be between 0 and " 989 <<
"On this mesh the particle should" 995 if (!cellParticles[cloudI][celli])
997 cellParticles[cloudI][celli] =
1001 cellParticles[cloudI][celli]->
append(&
p);
1015 lagrangianFieldCache.readAllFields
1025 lagrangianPositions.
resize(cloudI);
1026 cellParticles.resize(cloudI);
1027 lagrangianFieldCache.resize(cloudI);
1035 doDecompFields && proci <
mesh.nProcs();
1039 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
1042 if (!processorDbList.set(proci))
1058 Time& processorDb = processorDbList[proci];
1064 if (!procMeshList.
set(proci))
1080 const fvMesh& procMesh = procMeshList[proci];
1082 const labelIOList& faceProcAddressing = procAddressing
1086 "faceProcAddressing",
1087 faceProcAddressingList
1090 const labelIOList& cellProcAddressing = procAddressing
1094 "cellProcAddressing",
1095 cellProcAddressingList
1098 const labelIOList& boundaryProcAddressing = procAddressing
1102 "boundaryProcAddressing",
1103 boundaryProcAddressingList
1109 if (!fieldDecomposerList.set(proci))
1111 fieldDecomposerList.set
1120 boundaryProcAddressing
1127 fieldDecomposerList[proci]
1130 if (times.
size() == 1)
1133 fieldDecomposerList.set(proci,
nullptr);
1139 if (!pointFieldCache.
empty())
1141 const labelIOList& pointProcAddressing = procAddressing
1145 "pointProcAddressing",
1146 pointProcAddressingList
1152 if (!pointBoundaryProcAddressingList.set(proci))
1154 pointBoundaryProcAddressingList.set
1161 "boundaryProcAddressing",
1170 boundaryProcAddressing
1174 const auto& pointBoundaryProcAddressing =
1175 pointBoundaryProcAddressingList[proci];
1178 if (!pointFieldDecomposerList.set(proci))
1180 pointFieldDecomposerList.set
1187 pointProcAddressing,
1188 pointBoundaryProcAddressing
1195 pointFieldDecomposerList[proci]
1198 if (times.
size() == 1)
1201 pointBoundaryProcAddressingList.set
1206 pointProcAddressingList.set(proci,
nullptr);
1207 pointFieldDecomposerList.set(proci,
nullptr);
1213 forAll(lagrangianPositions, cloudi)
1215 if (lagrangianPositions[cloudi].size())
1224 lagrangianPositions[cloudi],
1225 cellParticles[cloudi]
1229 lagrangianFieldCache.decomposeAllFields
1251 decomposeUniform(copyUniform,
mesh, processorDb);
1259 if (times.
size() == 1)
1261 boundaryProcAddressingList.set(proci,
nullptr);
1262 cellProcAddressingList.set(proci,
nullptr);
1263 faceProcAddressingList.set(proci,
nullptr);
1264 procMeshList.
set(proci,
nullptr);
1265 processorDbList.
set(proci,
nullptr);
1271 if (faMeshDecompPtr)
1273 Info<<
"\nFinite area mesh decomposition" <<
endl;
1291 const label nAreaFields = areaFieldCache.
size();
1294 Info<<
"Finite area field transfer: " 1295 << nAreaFields <<
" fields" <<
endl;
1301 nAreaFields && proci <
mesh.nProcs();
1305 Info<<
" Processor " << proci <<
endl;
1330 faMesh procMesh(procFvMesh);
1357 "faceProcAddressing",
1360 auto& faceProcAddressing = *tfaceProcAddr;
1366 "boundaryProcAddressing",
1369 auto& boundaryProcAddressing = *tboundaryProcAddr;
1375 "edgeProcAddressing",
1378 const auto& edgeProcAddressing = *tedgeProcAddr;
1386 boundaryProcAddressing
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
bool empty() const
No fields.
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
A class for handling file names.
Finite Area area and edge field decomposer.
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...
fileName timePath() const
Return current time path = path/timeName.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
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)
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.
static void noParallel()
Remove the parallel options.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
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()
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.
const Time & time() const
Return the top-level database.
Automatic domain decomposition class for finite-volume meshes.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
An encapsulation of filesystem-related operations.
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 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.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
virtual const fileName & dbDir() const
Local directory path of the objectRegistry relative to Time with override for the single-region case...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool allowLibs() const
The controlDict 'libs' entry is allowed to be used. (eg, has not been disabled by the -no-libs option...
void readAllFields(const fvMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
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)...
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName. Same as TimePaths::globalPath() ...
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.
bool writeDecomposition()
Write decomposition.
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].
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.
static word controlDictName
The default control dictionary name (normally "controlDict")
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.
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info.
void resize(label newCapacity)
Rehash the hash table with new number of buckets. Currently identical to setCapacity() ...
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 word & constant() const noexcept
Return constant name.
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.
static const word canonicalName
The canonical name ("decomposeParDict") under which the MeshObject is registered. ...
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)
void decomposeMesh()
Decompose mesh.
Ostream & flush(Ostream &os)
Flush stream.
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...
Mesh data needed to do the Finite Volume discretisation.
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)
Automatic faMesh decomposition class.
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
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)
label size() const
Number of fields.
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.
static IOobject selectIO(const IOobject &io, const fileName &altFile, const word &ioName="")
Return the IOobject, but also consider an alternative file name.
void decomposeAllFields(const faFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
Lagrangian field decomposer.
static const word prefix
The prefix to local: lagrangian.