ENH: support writeLagrangianPositions in redistributePar (issue #702)

This commit is contained in:
Mark Olesen
2018-02-20 15:22:47 +01:00
parent 0d3d895d4d
commit 87b1bbacd8
8 changed files with 76 additions and 79 deletions

View File

@ -152,7 +152,7 @@ public:
void reconstructFvVolumeInternalFields void reconstructFvVolumeInternalFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const; ) const;
//- Read, reconstruct and write all/selected volume fields //- Read, reconstruct and write all/selected volume fields
@ -160,7 +160,7 @@ public:
void reconstructFvVolumeFields void reconstructFvVolumeFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const; ) const;
//- Read, reconstruct and write all/selected surface fields //- Read, reconstruct and write all/selected surface fields
@ -168,7 +168,7 @@ public:
void reconstructFvSurfaceFields void reconstructFvSurfaceFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const; ) const;
//- Helper: reconstruct and write mesh points //- Helper: reconstruct and write mesh points

View File

@ -420,7 +420,7 @@ template<class Type>
void Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields void Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const ) const
{ {
const word& fieldClassName = DimensionedField<Type, volMesh>::typeName; const word& fieldClassName = DimensionedField<Type, volMesh>::typeName;
@ -461,7 +461,7 @@ template<class Type>
void Foam::parFvFieldReconstructor::reconstructFvVolumeFields void Foam::parFvFieldReconstructor::reconstructFvVolumeFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const ) const
{ {
const word& fieldClassName = const word& fieldClassName =
@ -504,7 +504,7 @@ template<class Type>
void Foam::parFvFieldReconstructor::reconstructFvSurfaceFields void Foam::parFvFieldReconstructor::reconstructFvSurfaceFields
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const ) const
{ {
const word& fieldClassName = const word& fieldClassName =

View File

@ -86,30 +86,25 @@ void Foam::parLagrangianRedistributor::findClouds
objectNames.setSize(cloudNames.size()); objectNames.setSize(cloudNames.size());
forAll(localCloudDirs, i) for (const fileName& localCloudName : localCloudDirs)
{ {
// Do local scan for valid cloud objects // Do local scan for valid cloud objects
IOobjectList sprayObjs IOobjectList sprayObjs
( (
mesh, mesh,
mesh.time().timeName(), mesh.time().timeName(),
cloud::prefix/localCloudDirs[i] cloud::prefix/localCloudName
); );
if if (sprayObjs.found("coordinates") || sprayObjs.found("positions"))
(
sprayObjs.lookup(word("coordinates"))
|| sprayObjs.lookup(word("positions"))
)
{ {
// One of the objects is coordinates/positions so must be valid // Has coordinates/positions - so must be a valid cloud
// cloud
label cloudI = cloudNames.find(localCloudDirs[i]); const label cloudI = cloudNames.find(localCloudName);
objectNames[cloudI].setSize(sprayObjs.size()); objectNames[cloudI].setSize(sprayObjs.size());
label objectI = 0; label objectI = 0;
forAllConstIter(IOobjectList, sprayObjs, iter) forAllConstIters(sprayObjs, iter)
{ {
const word& name = iter.key(); const word& name = iter.key();
if (name != "coordinates" && name != "positions") if (name != "coordinates" && name != "positions")
@ -160,8 +155,8 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
{ {
passivePositionParticle& ppi = iter(); passivePositionParticle& ppi = iter();
label destProcI = destinationProcID_[ppi.cell()]; const label destProcI = destinationProcID_[ppi.cell()];
label destCellI = destinationCell_[ppi.cell()]; const label destCellI = destinationCell_[ppi.cell()];
ppi.cell() = destCellI; ppi.cell() = destCellI;
destProc[particleI++] = destProcI; destProc[particleI++] = destProcI;
@ -211,7 +206,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
// Retrieve from receive buffers // Retrieve from receive buffers
forAll(allNTrans, procI) forAll(allNTrans, procI)
{ {
label nRec = allNTrans[procI]; const label nRec = allNTrans[procI];
//Pout<< "From processor " << procI << " receiving bytes " << nRec //Pout<< "From processor " << procI << " receiving bytes " << nRec
// << endl; // << endl;
@ -240,9 +235,19 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
} }
} }
// Write coordinates file
IOPosition<passivePositionParticleCloud>(lagrangianPositions).write(); IOPosition<passivePositionParticleCloud>(lagrangianPositions).write();
// Optionally write positions file in v1706 format and earlier
if (particle::writeLagrangianPositions)
{
IOPosition<passivePositionParticleCloud>
(
lagrangianPositions,
cloud::geometryType::POSITIONS
).write();
}
// Restore cloud name // Restore cloud name
lpi.rename(cloudName); lpi.rename(cloudName);
} }
@ -262,7 +267,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
label constructSize = 0; label constructSize = 0;
forAll(constructMap, procI) forAll(constructMap, procI)
{ {
label nRecv = sizes[procI][UPstream::myProcNo()]; const label nRecv = sizes[procI][UPstream::myProcNo()];
labelList& map = constructMap[procI]; labelList& map = constructMap[procI];

View File

@ -126,7 +126,7 @@ public:
static wordList filterObjects static wordList filterObjects
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
); );
//- Read, redistribute and write all/selected lagrangian fields //- Read, redistribute and write all/selected lagrangian fields
@ -136,7 +136,7 @@ public:
const mapDistributeBase& map, const mapDistributeBase& map,
const word& cloudName, const word& cloudName,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const; ) const;
//- Read, redistribute and write all/selected lagrangian fieldFields //- Read, redistribute and write all/selected lagrangian fieldFields
@ -146,7 +146,7 @@ public:
const mapDistributeBase& map, const mapDistributeBase& map,
const word& cloudName, const word& cloudName,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const; ) const;
//- Read and store all fields of a cloud //- Read and store all fields of a cloud
@ -155,7 +155,7 @@ public:
( (
const passivePositionParticleCloud& cloud, const passivePositionParticleCloud& cloud,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
); );
//- Redistribute and write stored lagrangian fields //- Redistribute and write stored lagrangian fields

View File

@ -37,7 +37,7 @@ template<class Container>
Foam::wordList Foam::parLagrangianRedistributor::filterObjects Foam::wordList Foam::parLagrangianRedistributor::filterObjects
( (
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) )
{ {
const word fieldClassName(Container::typeName); const word fieldClassName(Container::typeName);
@ -69,7 +69,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields
const mapDistributeBase& map, const mapDistributeBase& map,
const word& cloudName, const word& cloudName,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const ) const
{ {
const wordList objectNames const wordList objectNames
@ -141,7 +141,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields
const mapDistributeBase& map, const mapDistributeBase& map,
const word& cloudName, const word& cloudName,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) const ) const
{ {
wordList objectNames wordList objectNames
@ -225,7 +225,7 @@ void Foam::parLagrangianRedistributor::readLagrangianFields
( (
const passivePositionParticleCloud& cloud, const passivePositionParticleCloud& cloud,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) )
{ {
const wordList objectNames const wordList objectNames

View File

@ -115,9 +115,9 @@ scalar getMergeDistance
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Your current settings specify ASCII writing with " << "Your current settings specify ASCII writing with "
<< IOstream::defaultPrecision() << " digits precision." << endl << IOstream::defaultPrecision() << " digits precision." << nl
<< "Your merging tolerance (" << mergeTol << ") is finer than this." << "Your merging tolerance (" << mergeTol << ") is finer than this."
<< endl << nl
<< "Please change your writeFormat to binary" << "Please change your writeFormat to binary"
<< " or increase the writePrecision" << endl << " or increase the writePrecision" << endl
<< "or adjust the merge tolerance (-mergeTol)." << "or adjust the merge tolerance (-mergeTol)."
@ -168,9 +168,9 @@ void printMeshData(const polyMesh& mesh)
label totProcPatches = 0; label totProcPatches = 0;
label maxProcFaces = 0; label maxProcFaces = 0;
for (label procI = 0; procI < Pstream::nProcs(); procI++) for (label procI = 0; procI < Pstream::nProcs(); ++procI)
{ {
Info<< endl Info<< nl
<< "Processor " << procI << nl << "Processor " << procI << nl
<< " Number of cells = " << globalCells.localSize(procI) << " Number of cells = " << globalCells.localSize(procI)
<< endl; << endl;
@ -312,9 +312,9 @@ void determineDecomposition
WarningInFunction WarningInFunction
<< "You have selected decomposition method " << "You have selected decomposition method "
<< decomposer.typeName << decomposer.typeName
<< " which does" << endl << " which does" << nl
<< "not synchronise the decomposition across" << "not synchronise the decomposition across"
<< " processor patches." << endl << " processor patches." << nl
<< " You might want to select a decomposition method" << " You might want to select a decomposition method"
<< " which is aware of this. Continuing." << " which is aware of this. Continuing."
<< endl; << endl;
@ -637,7 +637,7 @@ void readFields
{ {
FatalErrorInFunction FatalErrorInFunction
<< "differing fields of type " << GeoField::typeName << "differing fields of type " << GeoField::typeName
<< " on processors." << endl << " on processors." << nl
<< "Master has:" << masterNames << endl << "Master has:" << masterNames << endl
<< Pstream::myProcNo() << " has:" << objectNames << Pstream::myProcNo() << " has:" << objectNames
<< abort(FatalError); << abort(FatalError);
@ -662,7 +662,7 @@ void readFields
tmp<GeoField> tsubfld = subsetterPtr().interpolate(fields[i]); tmp<GeoField> tsubfld = subsetterPtr().interpolate(fields[i]);
// Send to all processors that don't have a mesh // Send to all processors that don't have a mesh
for (label procI = 1; procI < Pstream::nProcs(); procI++) for (label procI = 1; procI < Pstream::nProcs(); ++procI)
{ {
if (!haveMesh[procI]) if (!haveMesh[procI])
{ {
@ -752,10 +752,8 @@ void correctCoupledBoundaryConditions(fvMesh& mesh)
forAll(bfld, patchi) forAll(bfld, patchi)
{ {
typename GeoField::Patch& pfld = bfld[patchi]; auto& pfld = bfld[patchi];
//if (pfld.coupled())
//if (isA<CoupledPatchType>(pfld))
if (pfld.patch().coupled()) if (pfld.patch().coupled())
{ {
pfld.initEvaluate(Pstream::defaultCommsType); pfld.initEvaluate(Pstream::defaultCommsType);
@ -772,12 +770,8 @@ void correctCoupledBoundaryConditions(fvMesh& mesh)
Pstream::waitRequests(nReq); Pstream::waitRequests(nReq);
} }
forAll(bfld, patchi) for (auto& pfld : bfld)
{ {
typename GeoField::Patch& pfld = bfld[patchi];
//if (pfld.coupled())
//if (isA<CoupledPatchType>(pfld))
if (pfld.patch().coupled()) if (pfld.patch().coupled())
{ {
pfld.evaluate(Pstream::defaultCommsType); pfld.evaluate(Pstream::defaultCommsType);
@ -791,11 +785,9 @@ void correctCoupledBoundaryConditions(fvMesh& mesh)
forAll(patchSchedule, patchEvali) forAll(patchSchedule, patchEvali)
{ {
label patchi = patchSchedule[patchEvali].patch; const label patchi = patchSchedule[patchEvali].patch;
typename GeoField::Patch& pfld = bfld[patchi]; auto& pfld = bfld[patchi];
//if (pfld.coupled())
//if (isA<CoupledPatchType>(pfld))
if (pfld.patch().coupled()) if (pfld.patch().coupled())
{ {
if (patchSchedule[patchEvali].init) if (patchSchedule[patchEvali].init)
@ -869,7 +861,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
{ {
// Create 0 sized mesh to do all the generation of zero sized // Create 0 sized mesh to do all the generation of zero sized
// fields on processors that have zero sized meshes. Note that this is // fields on processors that have zero sized meshes. Note that this is
// only nessecary on master but since polyMesh construction with // only necessary on master but since polyMesh construction with
// Pstream::parRun does parallel comms we have to do it on all // Pstream::parRun does parallel comms we have to do it on all
// processors // processors
autoPtr<fvMeshSubset> subsetterPtr; autoPtr<fvMeshSubset> subsetterPtr;
@ -1695,7 +1687,7 @@ void reconstructMeshFields
( (
const parFvFieldReconstructor& fvReconstructor, const parFvFieldReconstructor& fvReconstructor,
const IOobjectList& objects, const IOobjectList& objects,
const HashSet<word>& selectedFields const wordHashSet& selectedFields
) )
{ {
// Dimensioned fields // Dimensioned fields
@ -1792,7 +1784,7 @@ void reconstructLagrangian
const fvMesh& baseMesh, const fvMesh& baseMesh,
const fvMesh& mesh, const fvMesh& mesh,
const mapDistributePolyMesh& distMap, const mapDistributePolyMesh& distMap,
const HashSet<word>& selectedLagrangianFields const wordHashSet& selectedLagrangianFields
) )
{ {
// Clouds (note: might not be present on all processors) // Clouds (note: might not be present on all processors)
@ -1820,62 +1812,62 @@ void reconstructLagrangian
const parLagrangianRedistributor& lagrangianReconstructor = const parLagrangianRedistributor& lagrangianReconstructor =
lagrangianReconstructorPtr(); lagrangianReconstructorPtr();
forAll(cloudNames, i) for (const word& cloudName : cloudNames)
{ {
Info<< "Reconstructing lagrangian fields for cloud " Info<< "Reconstructing lagrangian fields for cloud "
<< cloudNames[i] << nl << endl; << cloudName << nl << endl;
autoPtr<mapDistributeBase> lagrangianMap = autoPtr<mapDistributeBase> lagrangianMap =
lagrangianReconstructor.redistributeLagrangianPositions lagrangianReconstructor.redistributeLagrangianPositions
( (
cloudNames[i] cloudName
); );
IOobjectList sprayObjs IOobjectList sprayObjs
( (
mesh, mesh,
mesh.time().timeName(), mesh.time().timeName(),
cloud::prefix/cloudNames[i] cloud::prefix/cloudName
); );
lagrangianReconstructor.redistributeLagrangianFields<label> lagrangianReconstructor.redistributeLagrangianFields<label>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFieldFields<label> lagrangianReconstructor.redistributeLagrangianFieldFields<label>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFields<scalar> lagrangianReconstructor.redistributeLagrangianFields<scalar>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFieldFields<scalar> lagrangianReconstructor.redistributeLagrangianFieldFields<scalar>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFields<vector> lagrangianReconstructor.redistributeLagrangianFields<vector>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFieldFields<vector> lagrangianReconstructor.redistributeLagrangianFieldFields<vector>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
@ -1883,7 +1875,7 @@ void reconstructLagrangian
<sphericalTensor> <sphericalTensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
@ -1891,14 +1883,14 @@ void reconstructLagrangian
<sphericalTensor> <sphericalTensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFields<symmTensor> lagrangianReconstructor.redistributeLagrangianFields<symmTensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
@ -1906,21 +1898,21 @@ void reconstructLagrangian
<symmTensor> <symmTensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFields<tensor> lagrangianReconstructor.redistributeLagrangianFields<tensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
lagrangianReconstructor.redistributeLagrangianFieldFields<tensor> lagrangianReconstructor.redistributeLagrangianFieldFields<tensor>
( (
lagrangianMap, lagrangianMap,
cloudNames[i], cloudName,
sprayObjs, sprayObjs,
selectedLagrangianFields selectedLagrangianFields
); );
@ -1928,12 +1920,13 @@ void reconstructLagrangian
} }
} }
// Read clouds (note: might not be present on all processors) // Read clouds (note: might not be present on all processors)
void readLagrangian void readLagrangian
( (
const fvMesh& mesh, const fvMesh& mesh,
const wordList& cloudNames, const wordList& cloudNames,
const HashSet<word>& selectedLagrangianFields, const wordHashSet& selectedLagrangianFields,
PtrList<unmappedPassivePositionParticleCloud>& clouds PtrList<unmappedPassivePositionParticleCloud>& clouds
) )
{ {
@ -2313,8 +2306,8 @@ int main(int argc, char *argv[])
} }
const HashSet<word> selectedFields(0); const wordHashSet selectedFields(0);
const HashSet<word> selectedLagrangianFields(0); const wordHashSet selectedLagrangianFields(0);
if (decompose) if (decompose)
@ -2462,7 +2455,7 @@ int main(int argc, char *argv[])
); );
HashSet<word> masterTimeDirSet; wordHashSet masterTimeDirSet;
if (newTimes) if (newTimes)
{ {
instantList baseTimeDirs(baseRunTime.times()); instantList baseTimeDirs(baseRunTime.times());

View File

@ -3,7 +3,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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,7 +29,7 @@ template<class CloudType>
Foam::IOPosition<CloudType>::IOPosition Foam::IOPosition<CloudType>::IOPosition
( (
const CloudType& c, const CloudType& c,
const cloud::geometryType& geomType cloud::geometryType geomType
) )
: :
regIOobject regIOobject

View File

@ -3,7 +3,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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::IOPosition Foam::IOPosition
Description Description
Helper IO class to read and write particle positions Helper IO class to read and write particle coordinates (positions).
SourceFiles SourceFiles
IOPosition.C IOPosition.C
@ -77,8 +77,7 @@ public:
IOPosition IOPosition
( (
const CloudType& c, const CloudType& c,
const cloud::geometryType& geomType cloud::geometryType geomType = cloud::geometryType::COORDINATES
= cloud::geometryType::COORDINATES
); );