diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C index bc4ae9a571..32811e2ad1 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C @@ -135,6 +135,8 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions { //Debug(lpi.size()); + const label oldLpi = lpi.size(); + labelListList subMap; @@ -229,17 +231,49 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions } } - // Write coordinates file - IOPosition(lagrangianPositions).write(); - - // Optionally write positions file in v1706 format and earlier - if (particle::writeLagrangianPositions) + if (lagrangianPositions.size()) { + // Write coordinates file IOPosition ( - lagrangianPositions, - cloud::geometryType::POSITIONS - ).write(); + lagrangianPositions + ).write(); + + // Optionally write positions file in v1706 format and earlier + if (particle::writeLagrangianPositions) + { + IOPosition + ( + lagrangianPositions, + cloud::geometryType::POSITIONS + ).write(); + } + } + else if (oldLpi) + { + // When running with -overwrite it should also delete the old + // files. Below works but is not optimal. + + // Remove any existing coordinates + const fileName oldCoords + ( + IOPosition + ( + lagrangianPositions + ).objectPath() + ); + Foam::rm(oldCoords); + + // Remove any existing positions + const fileName oldPos + ( + IOPosition + ( + lagrangianPositions, + cloud::geometryType::POSITIONS + ).objectPath() + ); + Foam::rm(oldPos); } // Restore cloud name diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C index bb86206989..fb5268cd98 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C @@ -111,23 +111,33 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields map.distribute(field); + const IOobject fieldIO + ( + objectName, + tgtMesh_.time().timeName(), + cloud::prefix/cloudName, + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ); + if (field.size()) { IOField ( - IOobject - ( - objectName, - tgtMesh_.time().timeName(), - cloud::prefix/cloudName, - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), + fieldIO, std::move(field) ).write(); } + else + { + // When running with -overwrite it should also delete the old + // files. Below works but is not optimal. + + const fileName fldName(fieldIO.objectPath()); + Foam::rm(fldName); + } } return nFields; @@ -197,23 +207,33 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields map.distribute(field); // Write + const IOobject fieldIO + ( + objectName, + tgtMesh_.time().timeName(), + cloud::prefix/cloudName, + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ); + if (field.size()) { CompactIOField, Type> ( - IOobject - ( - objectName, - tgtMesh_.time().timeName(), - cloud::prefix/cloudName, - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), + fieldIO, std::move(field) ).write(); } + else + { + // When running with -overwrite it should also delete the old + // files. Below works but is not optimal. + + const fileName fldName(fieldIO.objectPath()); + Foam::rm(fldName); + } } if (nFields) Info<< endl; @@ -297,23 +317,33 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields map.distribute(field); + const IOobject fieldIO + ( + field.name(), + tgtMesh_.time().timeName(), + cloud::prefix/cloud.name(), + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ); + if (field.size()) { Container ( - IOobject - ( - field.name(), - tgtMesh_.time().timeName(), - cloud::prefix/cloud.name(), - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), + fieldIO, std::move(field) ).write(); } + else + { + // When running with -overwrite it should also delete the old + // files. Below works but is not optimal. + + const fileName fldName(fieldIO.objectPath()); + Foam::rm(fldName); + } } return nFields; diff --git a/applications/utilities/parallelProcessing/redistributePar/passivePositionParticle.H b/applications/utilities/parallelProcessing/redistributePar/passivePositionParticle.H index 0177c810bc..b41c15e59f 100644 --- a/applications/utilities/parallelProcessing/redistributePar/passivePositionParticle.H +++ b/applications/utilities/parallelProcessing/redistributePar/passivePositionParticle.H @@ -58,7 +58,7 @@ class passivePositionParticle // Private Member Data //- Cached position - point position_; + point cachedPosition_; public: @@ -75,7 +75,7 @@ public: ) : passiveParticle(mesh, is, readFields, newFormat), - position_(position()) + cachedPosition_(position()) {} //- Construct from a position and a cell. @@ -88,14 +88,14 @@ public: ) : passiveParticle(mesh, position, celli), - position_(position) + cachedPosition_(position) {} //- Construct as copy passivePositionParticle(const passivePositionParticle& p) : passiveParticle(p), - position_(p.position_) + cachedPosition_(p.cachedPosition_) {} //- Construct and return a clone @@ -128,6 +128,12 @@ public: }; + const point& cachedPosition() const + { + return cachedPosition_; + } + + // Friend Operators friend Ostream& operator<< @@ -140,7 +146,7 @@ public: // particleIO.C reading old format. particle::positionsCompat1706 p; - p.position = ppi.position_; + p.position = ppi.cachedPosition_; p.celli = ppi.cell(); p.facei = ppi.face(); p.stepFraction = ppi.stepFraction();