178 const word& instance,
204 const word& instance,
208 return procAddressing(procMesh,
name, instance,
local);
221 const fvMesh& procMesh = procMeshList[proci];
223 if (!procAddressingList.
set(proci))
225 procAddressingList.
set 231 return procAddressingList[proci];
235 void decomposeUniform
237 const bool copyUniform,
239 const Time& processorDb,
250 Info<<
"Detected additional non-decomposed files in " 271 if (copyUniform ||
mesh.distributed())
285 string parentPath =
string(
"..")/
"..";
289 parentPath = parentPath/
"..";
311 using namespace Foam;
315 int main(
int argc,
char *argv[])
319 "Decompose a mesh and fields of a case for parallel execution" 327 "Alternative decomposePar dictionary file" 334 "Test without writing the decomposition. " 335 "Changes -cellDist to only write VTK output." 342 "Override numberOfSubdomains (-dry-run only)",
349 "Override decomposition method (-dry-run only)",
356 "Suppress finiteArea mesh/field decomposition",
363 "Suppress lagrangian (cloud) decomposition",
370 "Write cell distribution as a labelList - for use with 'manual' " 371 "decomposition method and as a volScalarField for visualization." 376 "Copy 0/ directory to processor*/ rather than decompose the fields" 381 "Copy any uniform/ directories too" 386 "Use existing geometry decomposition and convert fields only" 391 "Suppress conversion of fields (volume, finite-area, lagrangian)" 397 "Skip decomposing cellSets, faceSets, pointSets" 404 "Remove existing processor*/ subdirs before decomposing the geometry" 409 "Only decompose geometry if the number of domains has changed" 417 const bool writeCellDist =
args.
found(
"cellDist");
420 const bool copyZero =
args.
found(
"copyZero");
421 const bool copyUniform =
args.
found(
"copyUniform");
422 const bool decomposeSets = !
args.
found(
"no-sets");
424 const bool decomposeIfRequired =
args.
found(
"ifRequired");
426 const bool doDecompFields = !
args.
found(
"no-fields");
427 const bool doFiniteArea = !
args.
found(
"no-finite-area");
428 const bool doLagrangian = !
args.
found(
"no-lagrangian");
430 bool decomposeFieldsOnly =
args.
found(
"fields");
431 bool forceOverwrite =
args.
found(
"force");
441 Info<<
"\ndry-run: ignoring -copy*, -fields, -force, time selection" 446 if (decomposeFieldsOnly && !doDecompFields)
449 <<
"Options -fields and -no-fields are mutually exclusive" 450 <<
" ... giving up" <<
nl 456 Info<<
"Skip decompose of all fields" <<
nl;
460 Info<<
"Skip decompose of finiteArea mesh/fields" <<
nl;
464 Info<<
"Skip decompose of lagrangian positions/fields" <<
nl;
476 && !decompDictFile.empty() && !decompDictFile.
isAbsolute()
485 const bool optRegions =
501 <<
"Create mesh..." <<
flush;
523 Info<<
"\n\nDecomposing mesh";
531 const label nProcsOld =
560 if (decomposeFieldsOnly)
563 if (nProcsOld != nDomains)
566 <<
"Specified -fields, but the case was decomposed with " 567 << nProcsOld <<
" domains" 569 <<
"instead of " << nDomains
570 <<
" domains as specified in decomposeParDict" <<
nl 576 bool procDirsProblem =
true;
578 if (decomposeIfRequired && nProcsOld == nDomains)
581 decomposeFieldsOnly =
true;
582 procDirsProblem =
false;
583 forceOverwrite =
false;
585 Info<<
"Using existing processor directories" <<
nl;
590 procDirsProblem =
false;
591 forceOverwrite =
false;
596 Info<<
"Removing " << nProcsOld
597 <<
" existing processor directories" <<
endl;
605 fileName::Type::DIRECTORY
634 procDirsProblem =
false;
640 <<
"Case is already decomposed with " << nProcsOld
641 <<
" domains, use the -force option or manually" <<
nl 642 <<
"remove processor directories before decomposing. e.g.," 644 <<
" rm -rf " <<
runTime.
path().c_str() <<
"/processor*" 666 if (!decomposeFieldsOnly)
668 mesh.decomposeMesh();
669 mesh.writeDecomposition(decomposeSets);
676 mesh.writeVolField(
"cellDist");
694 cellDecomposition.write();
696 Info<<
nl <<
"Wrote decomposition to " 697 << cellDecomposition.objectRelPath()
698 <<
" for use in manual decomposition." <<
endl;
716 inputDir.ext(
"orig");
725 for (label proci = 0; proci <
mesh.nProcs(); ++proci)
753 if (outputDir != prevOutputDir)
755 Info<<
"Processor " << proci
757 << inputDir.name() <<
"/\" to " 762 prevOutputDir = outputDir;
768 Info<<
"No 0/ or 0.orig/ directory to copy" <<
nl;
806 objects.
remove(
"cellDist");
827 faMeshDecompPtr.
reset 868 if (doDecompFields && doLagrangian)
895 for (
const fileName& cloudDir : cloudDirs)
908 cloudObjects.found(
"coordinates")
909 || cloudObjects.found(
"positions")
915 Info<<
"Identified lagrangian data set: " 918 lagrangianPositions.set
949 label celli =
p.cell();
955 <<
"Illegal cell number " << celli
956 <<
" for particle with index " 959 <<
p.position() <<
nl 960 <<
"Cell number should be between 0 and " 962 <<
"On this mesh the particle should" 968 if (!cellParticles[cloudI][celli])
970 cellParticles[cloudI][celli] =
974 cellParticles[cloudI][celli]->
append(&
p);
988 lagrangianFieldCache.readAllFields
998 lagrangianPositions.
resize(cloudI);
999 cellParticles.resize(cloudI);
1000 lagrangianFieldCache.resize(cloudI);
1008 doDecompFields && proci <
mesh.nProcs();
1012 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
1015 if (!processorDbList.set(proci))
1031 Time& processorDb = processorDbList[proci];
1037 if (!procMeshList.
set(proci))
1053 const fvMesh& procMesh = procMeshList[proci];
1055 const labelIOList& faceProcAddressing = procAddressing
1059 "faceProcAddressing",
1060 faceProcAddressingList
1063 const labelIOList& cellProcAddressing = procAddressing
1067 "cellProcAddressing",
1068 cellProcAddressingList
1071 const labelIOList& boundaryProcAddressing = procAddressing
1075 "boundaryProcAddressing",
1076 boundaryProcAddressingList
1082 if (!fieldDecomposerList.set(proci))
1084 fieldDecomposerList.set
1093 boundaryProcAddressing
1100 fieldDecomposerList[proci]
1103 if (times.
size() == 1)
1106 fieldDecomposerList.set(proci,
nullptr);
1112 if (!pointFieldCache.
empty())
1114 const labelIOList& pointProcAddressing = procAddressing
1118 "pointProcAddressing",
1119 pointProcAddressingList
1124 if (!pointFieldDecomposerList.set(proci))
1126 pointFieldDecomposerList.set
1133 pointProcAddressing,
1134 boundaryProcAddressing
1141 pointFieldDecomposerList[proci]
1144 if (times.
size() == 1)
1146 pointProcAddressingList.set(proci,
nullptr);
1147 pointFieldDecomposerList.set(proci,
nullptr);
1153 forAll(lagrangianPositions, cloudi)
1155 if (lagrangianPositions[cloudi].size())
1164 lagrangianPositions[cloudi],
1165 cellParticles[cloudi]
1169 lagrangianFieldCache.decomposeAllFields
1191 decomposeUniform(copyUniform,
mesh, processorDb);
1199 if (times.
size() == 1)
1201 boundaryProcAddressingList.set(proci,
nullptr);
1202 cellProcAddressingList.set(proci,
nullptr);
1203 faceProcAddressingList.set(proci,
nullptr);
1204 procMeshList.
set(proci,
nullptr);
1205 processorDbList.
set(proci,
nullptr);
1211 if (faMeshDecompPtr)
1213 Info<<
"\nFinite area mesh decomposition" <<
endl;
1231 const label nAreaFields = areaFieldCache.
size();
1234 Info<<
"Finite area field transfer: " 1235 << nAreaFields <<
" fields" <<
endl;
1241 nAreaFields && proci <
mesh.nProcs();
1245 Info<<
" Processor " << proci <<
endl;
1270 faMesh procMesh(procFvMesh);
1297 "faceProcAddressing",
1300 auto& faceProcAddressing = *tfaceProcAddr;
1306 "boundaryProcAddressing",
1309 auto& boundaryProcAddressing = *tboundaryProcAddr;
1315 "edgeProcAddressing",
1318 const auto& edgeProcAddressing = *tedgeProcAddr;
1326 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.
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
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.
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
void readAllFields(const faMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
Template class for non-intrusive linked lists.
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.
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?
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.
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.
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.
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 select0) otherwise return just the current ti...
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.
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
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.
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)
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.