ENH: redistributePar: handle -overwrite. Fixes #1450.

This commit is contained in:
mattijs
2019-10-17 13:27:55 +01:00
committed by Andrew Heather
parent 1ddcdb083e
commit f64125c6d9
3 changed files with 113 additions and 43 deletions

View File

@ -135,6 +135,8 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
{ {
//Debug(lpi.size()); //Debug(lpi.size());
const label oldLpi = lpi.size();
labelListList subMap; labelListList subMap;
@ -229,8 +231,13 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
} }
} }
if (lagrangianPositions.size())
{
// Write coordinates file // Write coordinates file
IOPosition<passivePositionParticleCloud>(lagrangianPositions).write(); IOPosition<passivePositionParticleCloud>
(
lagrangianPositions
).write();
// Optionally write positions file in v1706 format and earlier // Optionally write positions file in v1706 format and earlier
if (particle::writeLagrangianPositions) if (particle::writeLagrangianPositions)
@ -241,6 +248,33 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
cloud::geometryType::POSITIONS cloud::geometryType::POSITIONS
).write(); ).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<passivePositionParticleCloud>
(
lagrangianPositions
).objectPath()
);
Foam::rm(oldCoords);
// Remove any existing positions
const fileName oldPos
(
IOPosition<passivePositionParticleCloud>
(
lagrangianPositions,
cloud::geometryType::POSITIONS
).objectPath()
);
Foam::rm(oldPos);
}
// Restore cloud name // Restore cloud name
lpi.rename(cloudName); lpi.rename(cloudName);

View File

@ -111,11 +111,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields
map.distribute(field); map.distribute(field);
if (field.size()) const IOobject fieldIO
{
IOField<Type>
(
IOobject
( (
objectName, objectName,
tgtMesh_.time().timeName(), tgtMesh_.time().timeName(),
@ -124,10 +120,24 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
), );
if (field.size())
{
IOField<Type>
(
fieldIO,
std::move(field) std::move(field)
).write(); ).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; return nFields;
@ -197,11 +207,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields
map.distribute(field); map.distribute(field);
// Write // Write
if (field.size()) const IOobject fieldIO
{
CompactIOField<Field<Type>, Type>
(
IOobject
( (
objectName, objectName,
tgtMesh_.time().timeName(), tgtMesh_.time().timeName(),
@ -210,10 +216,24 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
), );
if (field.size())
{
CompactIOField<Field<Type>, Type>
(
fieldIO,
std::move(field) std::move(field)
).write(); ).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; if (nFields) Info<< endl;
@ -297,11 +317,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields
map.distribute(field); map.distribute(field);
if (field.size()) const IOobject fieldIO
{
Container
(
IOobject
( (
field.name(), field.name(),
tgtMesh_.time().timeName(), tgtMesh_.time().timeName(),
@ -310,10 +326,24 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
), );
if (field.size())
{
Container
(
fieldIO,
std::move(field) std::move(field)
).write(); ).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; return nFields;

View File

@ -58,7 +58,7 @@ class passivePositionParticle
// Private Member Data // Private Member Data
//- Cached position //- Cached position
point position_; point cachedPosition_;
public: public:
@ -75,7 +75,7 @@ public:
) )
: :
passiveParticle(mesh, is, readFields, newFormat), passiveParticle(mesh, is, readFields, newFormat),
position_(position()) cachedPosition_(position())
{} {}
//- Construct from a position and a cell. //- Construct from a position and a cell.
@ -88,14 +88,14 @@ public:
) )
: :
passiveParticle(mesh, position, celli), passiveParticle(mesh, position, celli),
position_(position) cachedPosition_(position)
{} {}
//- Construct as copy //- Construct as copy
passivePositionParticle(const passivePositionParticle& p) passivePositionParticle(const passivePositionParticle& p)
: :
passiveParticle(p), passiveParticle(p),
position_(p.position_) cachedPosition_(p.cachedPosition_)
{} {}
//- Construct and return a clone //- Construct and return a clone
@ -128,6 +128,12 @@ public:
}; };
const point& cachedPosition() const
{
return cachedPosition_;
}
// Friend Operators // Friend Operators
friend Ostream& operator<< friend Ostream& operator<<
@ -140,7 +146,7 @@ public:
// particleIO.C reading old format. // particleIO.C reading old format.
particle::positionsCompat1706 p; particle::positionsCompat1706 p;
p.position = ppi.position_; p.position = ppi.cachedPosition_;
p.celli = ppi.cell(); p.celli = ppi.cell();
p.facei = ppi.face(); p.facei = ppi.face();
p.stepFraction = ppi.stepFraction(); p.stepFraction = ppi.stepFraction();