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;
473 if (!decompDictFile.empty() && !decompDictFile.isAbsolute())
481 const bool optRegions =
497 <<
"Create mesh..." <<
flush;
519 Info<<
"\n\nDecomposing mesh";
527 const label nProcsOld =
556 if (decomposeFieldsOnly)
559 if (nProcsOld != nDomains)
562 <<
"Specified -fields, but the case was decomposed with " 563 << nProcsOld <<
" domains" 565 <<
"instead of " << nDomains
566 <<
" domains as specified in decomposeParDict" <<
nl 572 bool procDirsProblem =
true;
574 if (decomposeIfRequired && nProcsOld == nDomains)
577 decomposeFieldsOnly =
true;
578 procDirsProblem =
false;
579 forceOverwrite =
false;
581 Info<<
"Using existing processor directories" <<
nl;
586 procDirsProblem =
false;
587 forceOverwrite =
false;
592 Info<<
"Removing " << nProcsOld
593 <<
" existing processor directories" <<
endl;
601 fileName::Type::DIRECTORY
630 procDirsProblem =
false;
636 <<
"Case is already decomposed with " << nProcsOld
637 <<
" domains, use the -force option or manually" <<
nl 638 <<
"remove processor directories before decomposing. e.g.," 640 <<
" rm -rf " <<
runTime.
path().c_str() <<
"/processor*" 662 if (!decomposeFieldsOnly)
664 mesh.decomposeMesh();
665 mesh.writeDecomposition(decomposeSets);
672 mesh.writeVolField(
"cellDist");
690 cellDecomposition.write();
692 Info<<
nl <<
"Wrote decomposition to " 693 << cellDecomposition.objectRelPath()
694 <<
" for use in manual decomposition." <<
endl;
712 inputDir.ext(
"orig");
721 for (label proci = 0; proci <
mesh.nProcs(); ++proci)
747 if (outputDir != prevOutputDir)
749 Info<<
"Processor " << proci
751 << inputDir.name() <<
"/\" to " 756 prevOutputDir = outputDir;
762 Info<<
"No 0/ or 0.orig/ directory to copy" <<
nl;
800 objects.
remove(
"cellDist");
825 faMeshDecompPtr.
reset 866 if (doDecompFields && doLagrangian)
893 for (
const fileName& cloudDir : cloudDirs)
906 cloudObjects.found(
"coordinates")
907 || cloudObjects.found(
"positions")
913 Info<<
"Identified lagrangian data set: " 916 lagrangianPositions.set
947 label celli =
p.cell();
953 <<
"Illegal cell number " << celli
954 <<
" for particle with index " 957 <<
p.position() <<
nl 958 <<
"Cell number should be between 0 and " 960 <<
"On this mesh the particle should" 966 if (!cellParticles[cloudI][celli])
968 cellParticles[cloudI][celli] =
972 cellParticles[cloudI][celli]->
append(&
p);
986 lagrangianFieldCache.readAllFields
996 lagrangianPositions.
resize(cloudI);
997 cellParticles.resize(cloudI);
998 lagrangianFieldCache.resize(cloudI);
1006 doDecompFields && proci <
mesh.nProcs();
1010 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
1013 if (!processorDbList.set(proci))
1029 Time& processorDb = processorDbList[proci];
1035 if (!procMeshList.
set(proci))
1051 const fvMesh& procMesh = procMeshList[proci];
1053 const labelIOList& faceProcAddressing = procAddressing
1057 "faceProcAddressing",
1058 faceProcAddressingList
1061 const labelIOList& cellProcAddressing = procAddressing
1065 "cellProcAddressing",
1066 cellProcAddressingList
1069 const labelIOList& boundaryProcAddressing = procAddressing
1073 "boundaryProcAddressing",
1074 boundaryProcAddressingList
1080 if (!fieldDecomposerList.set(proci))
1082 fieldDecomposerList.set
1091 boundaryProcAddressing
1098 fieldDecomposerList[proci]
1101 if (times.
size() == 1)
1104 fieldDecomposerList.set(proci,
nullptr);
1110 if (!pointFieldCache.
empty())
1112 const labelIOList& pointProcAddressing = procAddressing
1116 "pointProcAddressing",
1117 pointProcAddressingList
1122 if (!pointFieldDecomposerList.set(proci))
1124 pointFieldDecomposerList.set
1131 pointProcAddressing,
1132 boundaryProcAddressing
1139 pointFieldDecomposerList[proci]
1142 if (times.
size() == 1)
1144 pointProcAddressingList.set(proci,
nullptr);
1145 pointFieldDecomposerList.set(proci,
nullptr);
1151 forAll(lagrangianPositions, cloudi)
1153 if (lagrangianPositions[cloudi].size())
1162 lagrangianPositions[cloudi],
1163 cellParticles[cloudi]
1167 lagrangianFieldCache.decomposeAllFields
1189 decomposeUniform(copyUniform,
mesh, processorDb);
1197 if (times.
size() == 1)
1199 boundaryProcAddressingList.set(proci,
nullptr);
1200 cellProcAddressingList.set(proci,
nullptr);
1201 faceProcAddressingList.set(proci,
nullptr);
1202 procMeshList.
set(proci,
nullptr);
1203 processorDbList.
set(proci,
nullptr);
1209 if (faMeshDecompPtr)
1211 Info<<
"\nFinite area mesh decomposition" <<
endl;
1215 aMesh.decomposeMesh();
1216 aMesh.writeDecomposition();
1229 const label nAreaFields = areaFieldCache.
size();
1232 Info<<
"Finite area field transfer: " 1233 << nAreaFields <<
" fields" <<
endl;
1239 nAreaFields && proci <
mesh.nProcs();
1243 Info<<
" Processor " << proci <<
endl;
1267 faMesh procMesh(procFvMesh);
1294 "faceProcAddressing",
1297 auto& faceProcAddressing = *tfaceProcAddr;
1303 "boundaryProcAddressing",
1306 auto& boundaryProcAddressing = *tboundaryProcAddr;
1312 "edgeProcAddressing",
1315 const auto& edgeProcAddressing = *tedgeProcAddr;
1323 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.
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.
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.
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.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
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 resize(const label sz)
Resize the hash table for efficiency.
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...
Foam::word regionName(Foam::polyMesh::defaultRegion)
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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 INVALID.
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.
const word & system() const noexcept
Return system name.
static void addVerboseOption(const string &usage, bool advanced=false)
Enable a 'verbose' bool option, with usage information.
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 (uses typeFilePath to find file) and check its info.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time 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)
Ostream & flush(Ostream &os)
Flush stream.
T get(const label index) const
Get a value from the argument at index.
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 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.
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.
fileName globalPath() const
Return global path for the case.
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.