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

ENH: avoid references to temporaries in surfaceWriter

- previously wrapped raw points/faces with a meshedSurfRef on input,
  but now handle the raw -> meshedSurf logic directly within
  surfaceWriter to avoid holding references to temporaries

  Since the updated meshedSurfRef is now modifiable, it can be used
  directly as a redirection mechanism within surfaceWriter.

- add explicit close() in destructor
parent 0ca95ac0
......@@ -135,6 +135,8 @@ Foam::surfaceWriter::New
Foam::surfaceWriter::surfaceWriter()
:
surf_(std::cref<meshedSurf>(emptySurface_)),
surfComp_(),
useComponents_(false),
upToDate_(false),
parallel_(true),
useTimeDir_(false),
......@@ -188,7 +190,9 @@ Foam::surfaceWriter::surfaceWriter
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::surfaceWriter::~surfaceWriter()
{}
{
close();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -305,7 +309,9 @@ void Foam::surfaceWriter::clear()
{
close();
expire();
useComponents_ = false;
surf_ = std::cref<meshedSurf>(emptySurface_);
surfComp_.clear();
}
......@@ -316,7 +322,9 @@ void Foam::surfaceWriter::setSurface
)
{
expire();
useComponents_ = false;
surf_ = std::cref<meshedSurf>(surf);
surfComp_.clear();
parallel_ = (parallel && Pstream::parRun());
}
......@@ -329,7 +337,10 @@ void Foam::surfaceWriter::setSurface
)
{
expire();
setSurface(meshedSurfRef(points, faces), parallel);
useComponents_ = true;
surf_ = std::cref<meshedSurf>(emptySurface_);
surfComp_.reset(points, faces);
parallel_ = (parallel && Pstream::parRun());
}
......@@ -372,13 +383,18 @@ bool Foam::surfaceWriter::expire()
bool Foam::surfaceWriter::hasSurface() const
{
return (&emptySurface_ != &(surf_.get()));
return (useComponents_ || (&emptySurface_ != &(surf_.get())));
}
bool Foam::surfaceWriter::empty() const
{
const bool value = surf_.get().faces().empty();
const bool value =
(
useComponents_
? surfComp_.faces().empty()
: surf_.get().faces().empty()
);
return (parallel_ ? returnReduce(value, andOp<bool>()) : value);
}
......@@ -386,7 +402,12 @@ bool Foam::surfaceWriter::empty() const
Foam::label Foam::surfaceWriter::size() const
{
const label value = surf_.get().faces().size();
const bool value =
(
useComponents_
? surfComp_.faces().empty()
: surf_.get().faces().empty()
);
return (parallel_ ? returnReduce(value, sumOp<label>()) : value);
}
......@@ -411,7 +432,14 @@ bool Foam::surfaceWriter::merge() const
if (parallel_ && Pstream::parRun() && !upToDate_)
{
changed = merged_.merge(surf_.get(), mergeDim_);
if (useComponents_)
{
changed = merged_.merge(surfComp_, mergeDim_);
}
else
{
changed = merged_.merge(surf_.get(), mergeDim_);
}
}
upToDate_ = true;
......@@ -428,7 +456,14 @@ const Foam::meshedSurf& Foam::surfaceWriter::surface() const
return merged_;
}
return surf_.get();
if (useComponents_)
{
return surfComp_;
}
else
{
return surf_.get();
}
}
......
......@@ -98,17 +98,23 @@ class surfaceWriter
{
protected:
// Static data members
// Static Data Members
//- Placeholder
static const meshedSurf::emptySurface emptySurface_;
// Protected data
// Protected Data
//- Reference to the surface
//- Reference to a surface
std::reference_wrapper<const meshedSurf> surf_;
//- Reference to raw surface components
meshedSurfRef surfComp_;
//- Use raw surface components instead of surface reference
bool useComponents_;
//- The topology/surface is up-to-date?
mutable bool upToDate_;
......
......@@ -153,7 +153,9 @@ Foam::surfaceWriters::vtkWriter::vtkWriter
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::surfaceWriters::vtkWriter::~vtkWriter()
{}
{
close();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
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