ENH: redistributePar: handle -overwrite. Fixes #1450.
This commit is contained in:
parent
1ddcdb083e
commit
f64125c6d9
@ -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<passivePositionParticleCloud>(lagrangianPositions).write();
|
||||
|
||||
// Optionally write positions file in v1706 format and earlier
|
||||
if (particle::writeLagrangianPositions)
|
||||
if (lagrangianPositions.size())
|
||||
{
|
||||
// Write coordinates file
|
||||
IOPosition<passivePositionParticleCloud>
|
||||
(
|
||||
lagrangianPositions,
|
||||
cloud::geometryType::POSITIONS
|
||||
).write();
|
||||
lagrangianPositions
|
||||
).write();
|
||||
|
||||
// Optionally write positions file in v1706 format and earlier
|
||||
if (particle::writeLagrangianPositions)
|
||||
{
|
||||
IOPosition<passivePositionParticleCloud>
|
||||
(
|
||||
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<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
|
||||
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
||||
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<Field<Type>, 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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user