ENH: surface writers now track their own write status

- instead of deciding beforehand if a surface format requires a separate
  geometry file (or if a geometry file should be written if no fields were
  written) now determine afterwards if something was written.

  This improves the overall reliability (consistency) and is more
  convenient for the caller as well.
This commit is contained in:
Mark Olesen
2019-03-13 14:13:04 +01:00
parent 15a224ec4c
commit 044876bfe9
18 changed files with 96 additions and 30 deletions

View File

@ -536,6 +536,7 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
// Only seems to be needed for VTK legacy
countFields();
// Update writers
forAll(*this, surfi)
@ -544,7 +545,6 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
if (((request & actions_[surfi]) & ACTION_WRITE) && nFaces_[surfi])
{
// Output writers
surfaceWriter& outWriter = writers_[surfi];
if (outWriter.needsUpdate())
@ -556,24 +556,14 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
outWriter.beginTime(obr_.time());
// Write geometry if no fields would otherwise be written
if (!outWriter.nFields() || outWriter.separateGeometry())
{
outWriter.write();
continue;
}
// Write original ids - as label or scalar field
const word fieldName("Ids");
// Write original ids
if (s.hasFaceIds() && !s.interpolate())
{
writeSurface
(
outWriter,
Field<label>(s.originalIds()),
fieldName
"Ids"
);
}
}
@ -610,8 +600,16 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
// Finish this time step
forAll(writers_, surfi)
{
if ((request & actions_[surfi]) & ACTION_WRITE)
if (((request & actions_[surfi]) & ACTION_WRITE) && nFaces_[surfi])
{
// Write geometry if no fields were written so that we still
// can have something to look at
if (!writers_[surfi].wroteData())
{
writers_[surfi].write();
}
writers_[surfi].endTime();
}
}

View File

@ -352,19 +352,19 @@ public:
void verbose(const bool verbosity = true);
//- Read the sampledSurfaces dictionary
virtual bool read(const dictionary&);
virtual bool read(const dictionary& dict);
//- Execute, currently does nothing
//- Sample and store if the sampleOnExecute is enabled.
virtual bool execute();
//- Sample and write
virtual bool write();
//- Update for changes of mesh - expires the surfaces
virtual void updateMesh(const mapPolyMesh&);
virtual void updateMesh(const mapPolyMesh& mpm);
//- Update for mesh point-motion - expires the surfaces
virtual void movePoints(const polyMesh&);
virtual void movePoints(const polyMesh& mesh);
//- Update for changes of mesh due to readUpdate - expires the surfaces
virtual void readUpdate(const polyMesh::readUpdateState state);
@ -372,7 +372,7 @@ public:
//- Get merge tolerance
static scalar mergeTol();
//- Set tolerance (and return old tolerance)
//- Set tolerance and return old tolerance
static scalar mergeTol(const scalar tol);
};