decomposePar: Added 'copyZero' option

Using

decomposePar -copyZero

The mesh is decomposed as usual but the '0' directory is recursively copied to
the 'processor.*' directories rather than decomposing the fields.  This is a
convenient option to handle cases where the initial field files are generic and
can be used for serial or parallel running.  See for example the
incompressible/simpleFoam/motorBike tutorial case.
This commit is contained in:
Henry Weller
2017-03-08 11:48:06 +00:00
parent 7a99465d2a
commit 1be5f699e5
4 changed files with 700 additions and 642 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -43,6 +43,9 @@ Usage
Decompose all regions in regionProperties. Does not check for Decompose all regions in regionProperties. Does not check for
existence of processor*. existence of processor*.
- \par -copyZero \n
Copy \a 0 directory to processor* rather than decompose the fields.
- \par -copyUniform \n - \par -copyUniform \n
Copy any \a uniform directories too. Copy any \a uniform directories too.
@ -215,6 +218,11 @@ int main(int argc, char *argv[])
"decomposition method or as a volScalarField for post-processing." "decomposition method or as a volScalarField for post-processing."
); );
argList::addBoolOption argList::addBoolOption
(
"copyZero",
"Copy \a 0 directory to processor* rather than decompose the fields"
);
argList::addBoolOption
( (
"copyUniform", "copyUniform",
"copy any uniform/ directories too" "copy any uniform/ directories too"
@ -247,6 +255,7 @@ int main(int argc, char *argv[])
bool allRegions = args.optionFound("allRegions"); bool allRegions = args.optionFound("allRegions");
bool writeCellDist = args.optionFound("cellDist"); bool writeCellDist = args.optionFound("cellDist");
bool copyZero = args.optionFound("copyZero");
bool copyUniform = args.optionFound("copyUniform"); bool copyUniform = args.optionFound("copyUniform");
bool decomposeFieldsOnly = args.optionFound("fields"); bool decomposeFieldsOnly = args.optionFound("fields");
bool decomposeSets = !args.optionFound("noSets"); bool decomposeSets = !args.optionFound("noSets");
@ -476,11 +485,36 @@ int main(int argc, char *argv[])
} }
if (copyZero)
{
// Link the 0 directory into each of the processor directories
for (label proci = 0; proci < mesh.nProcs(); proci++)
{
Time processorDb
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
);
processorDb.setTime(runTime);
// Caches if (isDir(runTime.timePath()))
// ~~~~~~ {
// Cached processor meshes and maps. These are only preserved if running const fileName timePath = processorDb.timePath();
// with multiple times.
Info<< "Processor " << proci
<< ": linking " << runTime.timePath() << nl
<< " to " << processorDb.timePath() << endl;
cp(runTime.timePath(), processorDb.timePath());
}
}
}
else
{
// Decompose the field files
// Cached processor meshes and maps. These are only preserved if
// running with multiple times.
PtrList<Time> processorDbList(mesh.nProcs()); PtrList<Time> processorDbList(mesh.nProcs());
PtrList<fvMesh> procMeshList(mesh.nProcs()); PtrList<fvMesh> procMeshList(mesh.nProcs());
PtrList<labelIOList> faceProcAddressingList(mesh.nProcs()); PtrList<labelIOList> faceProcAddressingList(mesh.nProcs());
@ -489,8 +523,10 @@ int main(int argc, char *argv[])
PtrList<fvFieldDecomposer> fieldDecomposerList(mesh.nProcs()); PtrList<fvFieldDecomposer> fieldDecomposerList(mesh.nProcs());
PtrList<dimFieldDecomposer> dimFieldDecomposerList(mesh.nProcs()); PtrList<dimFieldDecomposer> dimFieldDecomposerList(mesh.nProcs());
PtrList<labelIOList> pointProcAddressingList(mesh.nProcs()); PtrList<labelIOList> pointProcAddressingList(mesh.nProcs());
PtrList<pointFieldDecomposer> pointFieldDecomposerList(mesh.nProcs()); PtrList<pointFieldDecomposer> pointFieldDecomposerList
(
mesh.nProcs()
);
// Loop over all times // Loop over all times
@ -527,7 +563,8 @@ int main(int argc, char *argv[])
PtrList<DimensionedField<sphericalTensor, volMesh>> PtrList<DimensionedField<sphericalTensor, volMesh>>
dimSphericalTensorFields; dimSphericalTensorFields;
readFields(mesh, objects, dimSphericalTensorFields); readFields(mesh, objects, dimSphericalTensorFields);
PtrList<DimensionedField<symmTensor, volMesh>> dimSymmTensorFields; PtrList<DimensionedField<symmTensor, volMesh>>
dimSymmTensorFields;
readFields(mesh, objects, dimSymmTensorFields); readFields(mesh, objects, dimSymmTensorFields);
PtrList<DimensionedField<tensor, volMesh>> dimTensorFields; PtrList<DimensionedField<tensor, volMesh>> dimTensorFields;
readFields(mesh, objects, dimTensorFields); readFields(mesh, objects, dimTensorFields);
@ -539,7 +576,8 @@ int main(int argc, char *argv[])
readFields(mesh, objects, surfaceScalarFields); readFields(mesh, objects, surfaceScalarFields);
PtrList<surfaceVectorField> surfaceVectorFields; PtrList<surfaceVectorField> surfaceVectorFields;
readFields(mesh, objects, surfaceVectorFields); readFields(mesh, objects, surfaceVectorFields);
PtrList<surfaceSphericalTensorField> surfaceSphericalTensorFields; PtrList<surfaceSphericalTensorField>
surfaceSphericalTensorFields;
readFields(mesh, objects, surfaceSphericalTensorFields); readFields(mesh, objects, surfaceSphericalTensorFields);
PtrList<surfaceSymmTensorField> surfaceSymmTensorFields; PtrList<surfaceSymmTensorField> surfaceSymmTensorFields;
readFields(mesh, objects, surfaceSymmTensorFields); readFields(mesh, objects, surfaceSymmTensorFields);
@ -568,7 +606,10 @@ int main(int argc, char *argv[])
fileNameList cloudDirs fileNameList cloudDirs
( (
readDir(runTime.timePath()/cloud::prefix, fileName::DIRECTORY) readDir
(
runTime.timePath()/cloud::prefix, fileName::DIRECTORY
)
); );
// Particles // Particles
@ -649,15 +690,18 @@ int main(int argc, char *argv[])
false false
); );
IOobject* positionsPtr = sprayObjs.lookup(word("positions")); IOobject* positionsPtr = sprayObjs.lookup
(
word("positions")
);
if (positionsPtr) if (positionsPtr)
{ {
// Read lagrangian particles // Read lagrangian particles
// ~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~
Info<< "Identified lagrangian data set: " << cloudDirs[i] Info<< "Identified lagrangian data set: "
<< endl; << cloudDirs[i] << endl;
lagrangianPositions.set lagrangianPositions.set
( (
@ -702,8 +746,10 @@ int main(int argc, char *argv[])
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Illegal cell number " << celli << "Illegal cell number " << celli
<< " for particle with index " << iter().index() << " for particle with index "
<< " at position " << iter().position() << nl << iter().index()
<< " at position "
<< iter().position() << nl
<< "Cell number should be between 0 and " << "Cell number should be between 0 and "
<< mesh.nCells()-1 << nl << mesh.nCells()-1 << nl
<< "On this mesh the particle should" << "On this mesh the particle should"
@ -931,7 +977,10 @@ int main(int argc, char *argv[])
fieldDecomposer.decomposeFields(volScalarFields); fieldDecomposer.decomposeFields(volScalarFields);
fieldDecomposer.decomposeFields(volVectorFields); fieldDecomposer.decomposeFields(volVectorFields);
fieldDecomposer.decomposeFields(volSphericalTensorFields); fieldDecomposer.decomposeFields
(
volSphericalTensorFields
);
fieldDecomposer.decomposeFields(volSymmTensorFields); fieldDecomposer.decomposeFields(volSymmTensorFields);
fieldDecomposer.decomposeFields(volTensorFields); fieldDecomposer.decomposeFields(volTensorFields);
@ -941,7 +990,10 @@ int main(int argc, char *argv[])
( (
surfaceSphericalTensorFields surfaceSphericalTensorFields
); );
fieldDecomposer.decomposeFields(surfaceSymmTensorFields); fieldDecomposer.decomposeFields
(
surfaceSymmTensorFields
);
fieldDecomposer.decomposeFields(surfaceTensorFields); fieldDecomposer.decomposeFields(surfaceTensorFields);
if (times.size() == 1) if (times.size() == 1)
@ -1022,7 +1074,10 @@ int main(int argc, char *argv[])
pointDecomposer.decomposeFields(pointScalarFields); pointDecomposer.decomposeFields(pointScalarFields);
pointDecomposer.decomposeFields(pointVectorFields); pointDecomposer.decomposeFields(pointVectorFields);
pointDecomposer.decomposeFields(pointSphericalTensorFields); pointDecomposer.decomposeFields
(
pointSphericalTensorFields
);
pointDecomposer.decomposeFields(pointSymmTensorFields); pointDecomposer.decomposeFields(pointSymmTensorFields);
pointDecomposer.decomposeFields(pointTensorFields); pointDecomposer.decomposeFields(pointTensorFields);
@ -1129,8 +1184,8 @@ int main(int argc, char *argv[])
} }
// We have cached all the constant mesh data for the current // We have cached all the constant mesh data for the current
// processor. This is only important if running with multiple // processor. This is only important if running with
// times, otherwise it is just extra storage. // multiple times, otherwise it is just extra storage.
if (times.size() == 1) if (times.size() == 1)
{ {
boundaryProcAddressingList.set(proci, nullptr); boundaryProcAddressingList.set(proci, nullptr);
@ -1142,6 +1197,7 @@ int main(int argc, char *argv[])
} }
} }
} }
}
Info<< "\nEnd\n" << endl; Info<< "\nEnd\n" << endl;

View File

@ -135,8 +135,12 @@ void Foam::timeSelector::addOptions
argList::addBoolOption argList::addBoolOption
( (
"noZero", "noZero",
"exclude the '0/' dir from the times list, " string("exclude the '0/' dir from the times list")
"has precedence over the -withZero option" + (
withZero
? ", has precedence over the -withZero option"
: ""
)
); );
argList::addBoolOption argList::addBoolOption
( (

View File

@ -1,9 +1,10 @@
#!/bin/sh #!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial clean functions # Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions . $WM_PROJECT_DIR/bin/tools/CleanFunctions
# remove surface and features # Remove surface and features
rm -f constant/triSurface/motorBike.obj.gz > /dev/null 2>&1 rm -f constant/triSurface/motorBike.obj.gz > /dev/null 2>&1
rm -rf constant/extendedFeatureEdgeMesh > /dev/null 2>&1 rm -rf constant/extendedFeatureEdgeMesh > /dev/null 2>&1
rm -f constant/triSurface/motorBike.eMesh > /dev/null 2>&1 rm -f constant/triSurface/motorBike.eMesh > /dev/null 2>&1
@ -11,3 +12,5 @@ rm -f constant/triSurface/motorBike.eMesh > /dev/null 2>&1
rm -rf 0 > /dev/null 2>&1 rm -rf 0 > /dev/null 2>&1
cleanCase cleanCase
#------------------------------------------------------------------------------

View File

@ -4,22 +4,17 @@ cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions # Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions . $WM_PROJECT_DIR/bin/tools/RunFunctions
# copy motorbike surface from resources directory # Copy motorbike surface from resources directory
cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/ cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
runApplication surfaceFeatureExtract runApplication surfaceFeatureExtract
runApplication blockMesh runApplication blockMesh
runApplication decomposePar [ ! -d 0 ] && cp -r 0.orig 0
runApplication decomposePar -copyZero
runParallel snappyHexMesh -overwrite runParallel snappyHexMesh -overwrite
#- For non-parallel running
#cp -r 0.orig 0 > /dev/null 2>&1
#- For parallel running
ls -d processor* | xargs -I {} rm -rf ./{}/0
ls -d processor* | xargs -I {} cp -r 0.orig ./{}/0
runParallel patchSummary runParallel patchSummary
runParallel potentialFoam runParallel potentialFoam
runParallel $(getApplication) runParallel $(getApplication)