From 33901032856e770b2794fddb02351b0abc6dd640 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 22 Feb 2019 10:21:01 +0100
Subject: [PATCH] BUG: new surface writer loses serial/parallel preference
 (fixes #1214)

---
 src/surfMesh/writers/null/nullSurfaceWriter.H |  4 +-
 src/surfMesh/writers/surfaceWriter.C          | 51 +++++++++++++++++++
 src/surfMesh/writers/surfaceWriter.H          | 46 ++++++++++++++---
 src/surfMesh/writers/vtk/vtkSurfaceWriter.C   |  6 +++
 src/surfMesh/writers/vtk/vtkSurfaceWriter.H   |  2 +-
 5 files changed, 99 insertions(+), 10 deletions(-)

diff --git a/src/surfMesh/writers/null/nullSurfaceWriter.H b/src/surfMesh/writers/null/nullSurfaceWriter.H
index 2174a566945..e8817c4e026 100644
--- a/src/surfMesh/writers/null/nullSurfaceWriter.H
+++ b/src/surfMesh/writers/null/nullSurfaceWriter.H
@@ -108,7 +108,7 @@ public:
         virtual void setSurface
         (
             const meshedSurf& s,
-            bool parallel = Pstream::parRun()
+            bool parallel
         ); // override
 
         //- Change association with a surface (no-op).
@@ -116,7 +116,7 @@ public:
         (
             const pointField& points,
             const faceList& faces,
-            bool parallel = Pstream::parRun()
+            bool parallel
         ); // override
 
 
diff --git a/src/surfMesh/writers/surfaceWriter.C b/src/surfMesh/writers/surfaceWriter.C
index 625a8250562..dbdc60e2d08 100644
--- a/src/surfMesh/writers/surfaceWriter.C
+++ b/src/surfMesh/writers/surfaceWriter.C
@@ -185,6 +185,12 @@ Foam::surfaceWriter::surfaceWriter
 }
 
 
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::surfaceWriter::~surfaceWriter()
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::surfaceWriter::setTime(const instant& inst)
@@ -264,6 +270,31 @@ void Foam::surfaceWriter::open
 }
 
 
+void Foam::surfaceWriter::open
+(
+    const meshedSurf& surf,
+    const fileName& outputPath
+)
+{
+    close();
+    setSurface(surf, parallel_);
+    open(outputPath);
+}
+
+
+void Foam::surfaceWriter::open
+(
+    const pointField& points,
+    const faceList& faces,
+    const fileName& outputPath
+)
+{
+    close();
+    setSurface(points, faces, parallel_);
+    open(outputPath);
+}
+
+
 void Foam::surfaceWriter::close()
 {
     outputPath_.clear();
@@ -286,6 +317,7 @@ void Foam::surfaceWriter::setSurface
 {
     expire();
     surf_ = std::cref<meshedSurf>(surf);
+    parallel_ = (parallel && Pstream::parRun());
 }
 
 
@@ -301,6 +333,25 @@ void Foam::surfaceWriter::setSurface
 }
 
 
+void Foam::surfaceWriter::setSurface
+(
+    const meshedSurf& surf
+)
+{
+    setSurface(surf, parallel_);
+}
+
+
+void Foam::surfaceWriter::setSurface
+(
+    const pointField& points,
+    const faceList& faces
+)
+{
+    setSurface(points, faces, parallel_);
+}
+
+
 bool Foam::surfaceWriter::needsUpdate() const
 {
     return !upToDate_;
diff --git a/src/surfMesh/writers/surfaceWriter.H b/src/surfMesh/writers/surfaceWriter.H
index 47ff7613716..0686d333047 100644
--- a/src/surfMesh/writers/surfaceWriter.H
+++ b/src/surfMesh/writers/surfaceWriter.H
@@ -261,7 +261,7 @@ public:
 
 
     //- Destructor
-    virtual ~surfaceWriter() = default;
+    virtual ~surfaceWriter();
 
 
     // Member Functions
@@ -301,19 +301,36 @@ public:
 
     // Surface association
 
-        //- Change association with a surface and expire the writer
+        //- Change association with a surface, expire the writer
+        //- with defined parallel/serial treatment
         virtual void setSurface
         (
             const meshedSurf& surf,
-            bool parallel = Pstream::parRun()
+            bool parallel
         );
 
-        //- Change association with a surface and expire the writer
+        //- Change association with a surface, expire the writer
+        //- with defined parallel/serial treatment
         virtual void setSurface
         (
             const pointField& points,
             const faceList& faces,
-            bool parallel = Pstream::parRun()
+            bool parallel
+        );
+
+        //- Change association with a surface, expire the writer
+        //- with the current parallel/serial treatment
+        virtual void setSurface
+        (
+            const meshedSurf& surf
+        );
+
+        //- Change association with a surface, expire the writer
+        //- with the current parallel/serial treatment
+        virtual void setSurface
+        (
+            const pointField& points,
+            const faceList& faces
         );
 
 
@@ -407,7 +424,7 @@ public:
             const pointField& points,
             const faceList& faces,
             const fileName& outputPath,
-            bool parallel = Pstream::parRun()
+            bool parallel
         );
 
         //- Open from components
@@ -415,7 +432,22 @@ public:
         (
             const meshedSurf& surf,
             const fileName& outputPath,
-            bool parallel = Pstream::parRun()
+            bool parallel
+        );
+
+        //- Open from components, with the current parallel/serial treatment
+        virtual void open
+        (
+            const pointField& points,
+            const faceList& faces,
+            const fileName& outputPath
+        );
+
+        //- Open from components, with the current parallel/serial treatment
+        virtual void open
+        (
+            const meshedSurf& surf,
+            const fileName& outputPath
         );
 
         //- Finish output, performing any necessary cleanup
diff --git a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C
index 65fd1b122e5..a259d8dc183 100644
--- a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C
+++ b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C
@@ -150,6 +150,12 @@ Foam::surfaceWriters::vtkWriter::vtkWriter
 }
 
 
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::surfaceWriters::vtkWriter::~vtkWriter()
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::surfaceWriters::vtkWriter::close()
diff --git a/src/surfMesh/writers/vtk/vtkSurfaceWriter.H b/src/surfMesh/writers/vtk/vtkSurfaceWriter.H
index d9872b35cfb..2c4e2652fd5 100644
--- a/src/surfMesh/writers/vtk/vtkSurfaceWriter.H
+++ b/src/surfMesh/writers/vtk/vtkSurfaceWriter.H
@@ -159,7 +159,7 @@ public:
 
 
     //- Destructor
-    virtual ~vtkWriter() = default;
+    virtual ~vtkWriter();
 
 
     // Member Functions
-- 
GitLab