95 #include "readFields.H" 109 const PtrList<fvMesh>& procMeshList,
112 PtrList<labelIOList>& procAddressingList
115 const fvMesh& procMesh = procMeshList[proci];
117 if (!procAddressingList.set(proci))
119 procAddressingList.set
127 procMesh.facesInstance(),
137 return procAddressingList[proci];
141 void decomposeUniform
143 const bool copyUniform,
144 const domainDecomposition& mesh,
145 const Time& processorDb,
149 const Time& runTime = mesh.
time();
152 const fileName uniformDir(regionDir/
"uniform");
154 if (
isDir(runTime.timePath()/uniformDir))
156 Info<<
"Detected additional non-decomposed files in " 157 << runTime.timePath()/uniformDir
160 const fileName timePath = processorDb.timePath();
162 if (copyUniform || mesh.distributed())
166 runTime.timePath()/uniformDir,
173 string parentPath = string(
"..")/
"..";
177 parentPath = parentPath/
"..";
180 fileName currentDir(
cwd());
184 parentPath/runTime.timeName()/uniformDir,
197 int main(
int argc,
char *argv[])
201 "decompose a mesh and fields of a case for parallel execution" 209 "operate on all regions in regionProperties" 214 "write cell distribution as a labelList - for use with 'manual' " 215 "decomposition method or as a volScalarField for post-processing." 220 "copy any uniform/ directories too" 225 "use existing geometry decomposition and convert fields only" 230 "skip decomposing cellSets, faceSets, pointSets" 235 "remove existing processor*/ subdirs before decomposing the geometry" 240 "only decompose geometry if the number of domains has changed" 266 Info<<
"Decomposing all regions in regionProperties" <<
nl <<
endl;
267 regionProperties
rp(runTime);
273 if (
findIndex(regionNames, regions[i]) == -1)
275 regionNames.append(regions[i]);
279 regionDirs = regionNames;
286 regionNames =
wordList(1, regionName);
287 regionDirs = regionNames;
298 forAll(regionNames, regioni)
300 const word& regionName = regionNames[regioni];
301 const word& regionDir = regionDirs[regioni];
303 Info<<
"\n\nDecomposing mesh " << regionName <<
nl <<
endl;
313 / (word(
"processor") +
name(nProcs))
332 runTime.time().system(),
339 ).lookup(
"numberOfSubdomains")
342 if (decomposeFieldsOnly)
345 if (nProcs != nDomains)
348 <<
"Specified -fields, but the case was decomposed with " 349 << nProcs <<
" domains" 351 <<
"instead of " << nDomains
352 <<
" domains as specified in decomposeParDict" 359 bool procDirsProblem =
true;
361 if (ifRequiredDecomposition && nProcs == nDomains)
364 decomposeFieldsOnly =
true;
365 procDirsProblem =
false;
366 forceOverwrite =
false;
368 Info<<
"Using existing processor directories" <<
nl;
373 Info<<
"Removing " << nProcs
374 <<
" existing processor directories" <<
endl;
378 for (
label proci = nProcs-1; proci >= 0; --proci)
382 runTime.path()/(word(
"processor") +
name(proci))
388 procDirsProblem =
false;
394 <<
"Case is already decomposed with " << nProcs
395 <<
" domains, use the -force option or manually" <<
nl 396 <<
"remove processor directories before decomposing. e.g.," 398 <<
" rm -rf " << runTime.path().c_str() <<
"/processor*" 405 domainDecomposition
mesh 419 if (!decomposeFieldsOnly)
421 mesh.decomposeMesh();
423 mesh.writeDecomposition(decomposeSets);
427 const labelList& procIds = mesh.cellToProc();
436 mesh.facesInstance(),
444 cellDecomposition.write();
446 Info<<
nl <<
"Wrote decomposition to " 447 << cellDecomposition.objectPath()
448 <<
" for use in manual decomposition." <<
endl;
467 cellDist[celli] = procIds[celli];
472 Info<<
nl <<
"Wrote decomposition as volScalarField to " 473 << cellDist.name() <<
" for use in postprocessing." 484 PtrList<Time> processorDbList(mesh.nProcs());
485 PtrList<fvMesh> procMeshList(mesh.nProcs());
486 PtrList<labelIOList> faceProcAddressingList(mesh.nProcs());
487 PtrList<labelIOList> cellProcAddressingList(mesh.nProcs());
488 PtrList<labelIOList> boundaryProcAddressingList(mesh.nProcs());
489 PtrList<fvFieldDecomposer> fieldDecomposerList(mesh.nProcs());
490 PtrList<dimFieldDecomposer> dimFieldDecomposerList(mesh.nProcs());
491 PtrList<labelIOList> pointProcAddressingList(mesh.nProcs());
492 PtrList<pointFieldDecomposer> pointFieldDecomposerList(mesh.nProcs());
499 runTime.setTime(times[timeI], timeI);
501 Info<<
"Time = " << runTime.timeName() <<
endl;
504 IOobjectList objects(mesh, runTime.timeName());
509 PtrList<volScalarField> volScalarFields;
511 PtrList<volVectorField> volVectorFields;
513 PtrList<volSphericalTensorField> volSphericalTensorFields;
514 readFields(mesh, objects, volSphericalTensorFields);
515 PtrList<volSymmTensorField> volSymmTensorFields;
516 readFields(mesh, objects, volSymmTensorFields);
517 PtrList<volTensorField> volTensorFields;
523 PtrList<DimensionedField<scalar, volMesh>> dimScalarFields;
525 PtrList<DimensionedField<vector, volMesh>> dimVectorFields;
527 PtrList<DimensionedField<sphericalTensor, volMesh>>
528 dimSphericalTensorFields;
529 readFields(mesh, objects, dimSphericalTensorFields);
530 PtrList<DimensionedField<symmTensor, volMesh>> dimSymmTensorFields;
531 readFields(mesh, objects, dimSymmTensorFields);
532 PtrList<DimensionedField<tensor, volMesh>> dimTensorFields;
538 PtrList<surfaceScalarField> surfaceScalarFields;
539 readFields(mesh, objects, surfaceScalarFields);
540 PtrList<surfaceVectorField> surfaceVectorFields;
541 readFields(mesh, objects, surfaceVectorFields);
542 PtrList<surfaceSphericalTensorField> surfaceSphericalTensorFields;
543 readFields(mesh, objects, surfaceSphericalTensorFields);
544 PtrList<surfaceSymmTensorField> surfaceSymmTensorFields;
545 readFields(mesh, objects, surfaceSymmTensorFields);
546 PtrList<surfaceTensorField> surfaceTensorFields;
547 readFields(mesh, objects, surfaceTensorFields);
554 PtrList<pointScalarField> pointScalarFields;
555 readFields(pMesh, objects, pointScalarFields);
556 PtrList<pointVectorField> pointVectorFields;
557 readFields(pMesh, objects, pointVectorFields);
558 PtrList<pointSphericalTensorField> pointSphericalTensorFields;
559 readFields(pMesh, objects, pointSphericalTensorFields);
560 PtrList<pointSymmTensorField> pointSymmTensorFields;
561 readFields(pMesh, objects, pointSymmTensorFields);
562 PtrList<pointTensorField> pointTensorFields;
563 readFields(pMesh, objects, pointTensorFields);
575 PtrList<Cloud<indexedParticle>> lagrangianPositions
580 PtrList<List<SLList<indexedParticle*>*>> cellParticles
585 PtrList<PtrList<labelIOField>> lagrangianLabelFields
589 PtrList<PtrList<labelFieldCompactIOField>>
590 lagrangianLabelFieldFields
594 PtrList<PtrList<scalarIOField>> lagrangianScalarFields
598 PtrList<PtrList<scalarFieldCompactIOField>>
599 lagrangianScalarFieldFields
603 PtrList<PtrList<vectorIOField>> lagrangianVectorFields
607 PtrList<PtrList<vectorFieldCompactIOField>>
608 lagrangianVectorFieldFields
612 PtrList<PtrList<sphericalTensorIOField>>
613 lagrangianSphericalTensorFields
617 PtrList<PtrList<sphericalTensorFieldCompactIOField>>
618 lagrangianSphericalTensorFieldFields(cloudDirs.size());
619 PtrList<PtrList<symmTensorIOField>> lagrangianSymmTensorFields
623 PtrList<PtrList<symmTensorFieldCompactIOField>>
624 lagrangianSymmTensorFieldFields
628 PtrList<PtrList<tensorIOField>> lagrangianTensorFields
632 PtrList<PtrList<tensorFieldCompactIOField>>
633 lagrangianTensorFieldFields
642 IOobjectList sprayObjs
652 IOobject* positionsPtr = sprayObjs.lookup(word(
"positions"));
659 Info<<
"Identified lagrangian data set: " << cloudDirs[i]
662 lagrangianPositions.set
665 new Cloud<indexedParticle>
680 new List<SLList<indexedParticle*>*>
683 static_cast<SLList<indexedParticle*>*
>(NULL)
691 Cloud<indexedParticle>,
692 lagrangianPositions[cloudI],
696 iter().index() = i++;
698 label celli = iter().cell();
701 if (celli < 0 || celli >= mesh.nCells())
704 <<
"Illegal cell number " << celli
705 <<
" for particle with index " << iter().index()
706 <<
" at position " << iter().position() <<
nl 707 <<
"Cell number should be between 0 and " 708 << mesh.nCells()-1 <<
nl 709 <<
"On this mesh the particle should" 711 << mesh.findCell(iter().position())
715 if (!cellParticles[cloudI][celli])
717 cellParticles[cloudI][celli] =
718 new SLList<indexedParticle*>();
721 cellParticles[cloudI][celli]->append(&iter());
727 IOobjectList lagrangianObjects
741 lagrangianLabelFields
748 lagrangianLabelFieldFields
755 lagrangianScalarFields
762 lagrangianScalarFieldFields
769 lagrangianVectorFields
776 lagrangianVectorFieldFields
783 lagrangianSphericalTensorFields
790 lagrangianSphericalTensorFieldFields
797 lagrangianSymmTensorFields
804 lagrangianSymmTensorFieldFields
811 lagrangianTensorFields
818 lagrangianTensorFieldFields
825 lagrangianPositions.setSize(cloudI);
826 cellParticles.setSize(cloudI);
827 lagrangianLabelFields.setSize(cloudI);
828 lagrangianLabelFieldFields.setSize(cloudI);
829 lagrangianScalarFields.setSize(cloudI);
830 lagrangianScalarFieldFields.setSize(cloudI);
831 lagrangianVectorFields.setSize(cloudI);
832 lagrangianVectorFieldFields.setSize(cloudI);
833 lagrangianSphericalTensorFields.setSize(cloudI);
834 lagrangianSphericalTensorFieldFields.setSize(cloudI);
835 lagrangianSymmTensorFields.setSize(cloudI);
836 lagrangianSymmTensorFieldFields.setSize(cloudI);
837 lagrangianTensorFields.setSize(cloudI);
838 lagrangianTensorFieldFields.setSize(cloudI);
843 for (
label proci = 0; proci < mesh.nProcs(); proci++)
845 Info<<
"Processor " << proci <<
": field transfer" <<
endl;
849 if (!processorDbList.set(proci))
859 /fileName(word(
"processor") +
name(proci))
863 Time& processorDb = processorDbList[proci];
866 processorDb.setTime(runTime);
869 if (!procMeshList.set(proci))
879 processorDb.timeName(),
885 const fvMesh& procMesh = procMeshList[proci];
887 const labelIOList& faceProcAddressing = procAddressing
891 "faceProcAddressing",
892 faceProcAddressingList
895 const labelIOList& cellProcAddressing = procAddressing
899 "cellProcAddressing",
900 cellProcAddressingList
903 const labelIOList& boundaryProcAddressing = procAddressing
907 "boundaryProcAddressing",
908 boundaryProcAddressingList
914 if (!fieldDecomposerList.set(proci))
916 fieldDecomposerList.set
919 new fvFieldDecomposer
925 boundaryProcAddressing
929 const fvFieldDecomposer& fieldDecomposer =
930 fieldDecomposerList[proci];
932 fieldDecomposer.decomposeFields(volScalarFields);
933 fieldDecomposer.decomposeFields(volVectorFields);
934 fieldDecomposer.decomposeFields(volSphericalTensorFields);
935 fieldDecomposer.decomposeFields(volSymmTensorFields);
936 fieldDecomposer.decomposeFields(volTensorFields);
938 fieldDecomposer.decomposeFields(surfaceScalarFields);
939 fieldDecomposer.decomposeFields(surfaceVectorFields);
940 fieldDecomposer.decomposeFields
942 surfaceSphericalTensorFields
944 fieldDecomposer.decomposeFields(surfaceSymmTensorFields);
945 fieldDecomposer.decomposeFields(surfaceTensorFields);
947 if (times.size() == 1)
950 fieldDecomposerList.set(proci, NULL);
956 if (!dimFieldDecomposerList.set(proci))
958 dimFieldDecomposerList.set
961 new dimFieldDecomposer
970 const dimFieldDecomposer& dimDecomposer =
971 dimFieldDecomposerList[proci];
973 dimDecomposer.decomposeFields(dimScalarFields);
974 dimDecomposer.decomposeFields(dimVectorFields);
975 dimDecomposer.decomposeFields(dimSphericalTensorFields);
976 dimDecomposer.decomposeFields(dimSymmTensorFields);
977 dimDecomposer.decomposeFields(dimTensorFields);
979 if (times.size() == 1)
981 dimFieldDecomposerList.set(proci, NULL);
989 pointScalarFields.size()
990 || pointVectorFields.size()
991 || pointSphericalTensorFields.size()
992 || pointSymmTensorFields.size()
993 || pointTensorFields.size()
996 const labelIOList& pointProcAddressing = procAddressing
1000 "pointProcAddressing",
1001 pointProcAddressingList
1006 if (!pointFieldDecomposerList.set(proci))
1008 pointFieldDecomposerList.set
1011 new pointFieldDecomposer
1015 pointProcAddressing,
1016 boundaryProcAddressing
1020 const pointFieldDecomposer& pointDecomposer =
1021 pointFieldDecomposerList[proci];
1023 pointDecomposer.decomposeFields(pointScalarFields);
1024 pointDecomposer.decomposeFields(pointVectorFields);
1025 pointDecomposer.decomposeFields(pointSphericalTensorFields);
1026 pointDecomposer.decomposeFields(pointSymmTensorFields);
1027 pointDecomposer.decomposeFields(pointTensorFields);
1030 if (times.size() == 1)
1032 pointProcAddressingList.set(proci, NULL);
1033 pointFieldDecomposerList.set(proci, NULL);
1039 forAll(lagrangianPositions, cloudI)
1041 if (lagrangianPositions[cloudI].size())
1043 lagrangianFieldDecomposer fieldDecomposer
1050 lagrangianPositions[cloudI],
1051 cellParticles[cloudI]
1056 fieldDecomposer.decomposeFields
1059 lagrangianLabelFields[cloudI]
1061 fieldDecomposer.decomposeFieldFields
1064 lagrangianLabelFieldFields[cloudI]
1066 fieldDecomposer.decomposeFields
1069 lagrangianScalarFields[cloudI]
1071 fieldDecomposer.decomposeFieldFields
1074 lagrangianScalarFieldFields[cloudI]
1076 fieldDecomposer.decomposeFields
1079 lagrangianVectorFields[cloudI]
1081 fieldDecomposer.decomposeFieldFields
1084 lagrangianVectorFieldFields[cloudI]
1086 fieldDecomposer.decomposeFields
1089 lagrangianSphericalTensorFields[cloudI]
1091 fieldDecomposer.decomposeFieldFields
1094 lagrangianSphericalTensorFieldFields[cloudI]
1096 fieldDecomposer.decomposeFields
1099 lagrangianSymmTensorFields[cloudI]
1101 fieldDecomposer.decomposeFieldFields
1104 lagrangianSymmTensorFieldFields[cloudI]
1106 fieldDecomposer.decomposeFields
1109 lagrangianTensorFields[cloudI]
1111 fieldDecomposer.decomposeFieldFields
1114 lagrangianTensorFieldFields[cloudI]
1122 decomposeUniform(copyUniform, mesh, processorDb, regionDir);
1126 if (regionNames.size() > 1 && regioni == 0)
1128 decomposeUniform(copyUniform, mesh, processorDb);
1134 if (times.size() == 1)
1136 boundaryProcAddressingList.set(proci, NULL);
1137 cellProcAddressingList.set(proci, NULL);
1138 faceProcAddressingList.set(proci, NULL);
1139 procMeshList.set(proci, NULL);
1140 processorDbList.set(proci, NULL);
List< instant > instantList
List of instants.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool chDir(const fileName &dir)
Change the current directory to the one given and return true,.
static void noParallel()
Remove the parallel options.
bool cp(const fileName &src, const fileName &dst)
Copy, recursively if necessary, the source to the destination.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
const fileName & rootPath() const
Return root path.
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the specified type.
static const pointMesh & New(const polyMesh &mesh)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
static void readFieldFields(const label cloudI, const IOobjectList &lagrangianObjects, PtrList< PtrList< CompactIOField< Field< Type >, Type >> > &lagrangianFields)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool optionFound(const word &opt) const
Return true if the named option is found.
const Time & time() const
Return time.
regionProperties rp(runTime)
static const word null
An empty word.
List< label > labelList
A List of labels.
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times (as select0)
static word controlDictName
The default control dictionary name (normally "controlDict")
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
label readLabel(Istream &is)
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
bool rmDir(const fileName &)
Remove a dirctory and its contents.
static const word prefix
The prefix to local: lagrangian.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
List< word > wordList
A List of words.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
fileName cwd()
Return current working directory path name.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
static void addNote(const string &)
Add extra notes for the usage information.
static void readFields(const label cloudI, const IOobjectList &lagrangianObjects, PtrList< PtrList< IOField< Type >>> &lagrangianFields)
Foam::argList args(argc, argv)
List< fileName > fileNameList
A List of fileNames.
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
IOList< label > labelIOList
Label container classes.