Commit 1a35a3ef authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

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.
parent 47b0de6d
......@@ -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();
}
}
......
......@@ -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);
};
......
......@@ -159,6 +159,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
//pts.writeEndDivider(os);
}
wroteGeom_ = true;
return surfaceDir;
}
......@@ -264,6 +265,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
OFstream(outputFile)() << tfield();
}
wroteGeom_ = true;
return surfaceDir;
}
......
......@@ -185,6 +185,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::write()
// {
// return writeUncollated();
// }
return writeUncollated();
}
......
......@@ -34,7 +34,8 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated()
// Geometry: rootdir/surfaceName/surfaceName.case
// Geometry: rootdir/surfaceName/surfaceName.mesh
return fileName();
wroteGeom_ = true;
return fileName::null;
}
......@@ -368,7 +369,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
}
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -97,6 +97,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated()
osGeom << ensPart;
}
wroteGeom_ = true;
return outputFile;
}
......@@ -245,6 +246,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
}
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -142,6 +142,7 @@ Foam::fileName Foam::surfaceWriters::foamWriter::write()
OFstream(surfaceDir/"faceCentres")() << faceCentres;
}
wroteGeom_ = true;
return surfaceDir;
}
......@@ -155,6 +156,12 @@ Foam::fileName Foam::surfaceWriters::foamWriter::writeTemplate
const Field<Type>& localValues
)
{
// Separate geometry
if (!wroteGeom_)
{
write();
}
checkOpen();
// Geometry should already have been written
......@@ -197,6 +204,7 @@ Foam::fileName Foam::surfaceWriters::foamWriter::writeTemplate
OFstream(outputFile)() << tfield();
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -437,6 +437,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::write()
<< "ENDDATA" << nl;
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -255,6 +255,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
<< "ENDDATA" << endl;
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -87,6 +87,12 @@ bool Foam::surfaceWriters::nullWriter::needsUpdate() const
}
bool Foam::surfaceWriters::nullWriter::wroteData() const
{
return true;
}
bool Foam::surfaceWriters::nullWriter::enabled() const
{
return false;
......@@ -116,6 +122,7 @@ void Foam::surfaceWriters::nullWriter::open(const fileName& outputPath)
Foam::fileName Foam::surfaceWriters::nullWriter::write()
{
wroteGeom_ = true;
return fileName::null;
}
......
......@@ -94,10 +94,13 @@ public:
// Capability
//- Never needs an update.
//- False: never needs an update.
virtual bool needsUpdate() const;
//- The null writer is always disabled, which lets the caller
//- True: like a /dev/null device.
virtual bool wroteData() const;
//- False: The null writer is never enabled, which lets the caller
//- skip various (possibly expensive) preparatory operations.
virtual bool enabled() const;
......
......@@ -135,6 +135,7 @@ Foam::fileName Foam::surfaceWriters::proxyWriter::write()
);
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -178,6 +178,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
os << nl;
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -197,6 +197,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
}
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -145,6 +145,7 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::write()
).write(outputFile, "inp");
}
wroteGeom_ = true;
return outputFile;
}
......@@ -158,6 +159,12 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::writeTemplate
const Field<Type>& localValues
)
{
// Separate geometry
if (!wroteGeom_)
{
write();
}
checkOpen();
// Field: rootdir/<TIME>/<field>_surfaceName.usr
......@@ -206,6 +213,7 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::writeTemplate
}
}
wroteGeom_ = true;
return outputFile;
}
......
......@@ -138,6 +138,7 @@ Foam::surfaceWriter::surfaceWriter()
surfComp_(),
useComponents_(false),
upToDate_(false),
wroteGeom_(false),
parallel_(true),
useTimeDir_(false),
isPointData_(false),
......@@ -244,6 +245,7 @@ void Foam::surfaceWriter::endTime()
void Foam::surfaceWriter::open(const fileName& outputPath)
{
outputPath_ = outputPath;
wroteGeom_ = false;
}
......@@ -302,6 +304,7 @@ void Foam::surfaceWriter::open
void Foam::surfaceWriter::close()
{
outputPath_.clear();
wroteGeom_ = false;
}
......@@ -369,11 +372,18 @@ bool Foam::surfaceWriter::needsUpdate() const
}
bool Foam::surfaceWriter::wroteData() const
{
return wroteGeom_;
}
bool Foam::surfaceWriter::expire()
{
const bool changed = upToDate_;
upToDate_ = false;
wroteGeom_ = false;
nFields_ = 0;
merged_.clear();
......@@ -443,6 +453,11 @@ bool Foam::surfaceWriter::merge() const
}
upToDate_ = true;
if (changed)
{
wroteGeom_ = false;
}
return changed;
}
......
......@@ -56,10 +56,14 @@ Description
verbose | Additional output verbosity | no | no
\endtable
Note
For surface formats that require geometry in a separate file,
it is the responsibility of the implementation (not the caller)
to ensure that this occurs.
SourceFiles
sampledWriter.C
sampledWriterI.H
sampledWriterImpl.C
surfaceWriter.C
surfaceWriterI.H
\*---------------------------------------------------------------------------*/
......@@ -83,7 +87,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class Time;
class surfaceWriter;
......@@ -118,10 +122,13 @@ protected:
//- The topology/surface is up-to-date?
mutable bool upToDate_;
//- Writing in parallel (vai master)
//- Track if geometry has been written since the last open
mutable bool wroteGeom_;
//- Writing in parallel (via master)
bool parallel_;
//- Writer should do something funny
//- Insert additional time sub-directory in the output path
bool useTimeDir_;
//- Is point vs cell data
......@@ -185,13 +192,17 @@ protected:
const Field<Type>& localValues //!< Local field values to write
)
{
if (!wroteGeom_)
{
return this->write();
}
return fileName::null;
}
public:
// Public data
// Public Data
//- The default merge dimension (1e-8)
static scalar defaultMergeDim;
......@@ -294,6 +305,9 @@ public:
//- Does the writer need an update (eg, lagging behind surface changes)
virtual bool needsUpdate() const;
//- Geometry or fields written since the last open?
virtual bool wroteData() const;
//- Mark that surface changed and the writer will need an update,
//- and set nFields = 0.
// May also free up unneeded data.
......
......@@ -248,6 +248,7 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::write()
writer_->writeGeometry();
}
wroteGeom_ = true;
return outputFile;
}
......@@ -288,6 +289,7 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::writeTemplate
writer_->write(fieldName, tfield());
}
wroteGeom_ = true;
return outputFile;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment