From 98c25d163a8cd02362f362d2b4f4cb9ee86dbf65 Mon Sep 17 00:00:00 2001
From: Andrew Heather <>
Date: Thu, 11 Nov 2021 13:44:49 +0000
Subject: [PATCH] ENH: sampledSets - enable writer construction from dictionary

Users can now include additional controls via a new formatOptions dictionary.
---
 .../sampledSetWriters/csv/csvSetWriter.C      |  8 ++++
 .../sampledSetWriters/csv/csvSetWriter.H      |  6 ++-
 .../ensight/ensightSetWriter.C                |  7 ++++
 .../ensight/ensightSetWriter.H                |  6 ++-
 .../gnuplot/gnuplotSetWriter.C                |  9 ++++-
 .../gnuplot/gnuplotSetWriter.H                |  7 +++-
 .../sampledSetWriters/jplot/jplotSetWriter.C  |  9 ++++-
 .../sampledSetWriters/jplot/jplotSetWriter.H  |  6 ++-
 .../nastran/nastranSetWriter.C                |  9 ++++-
 .../nastran/nastranSetWriter.H                | 18 ++++-----
 .../sampledSetWriters/raw/rawSetWriter.C      |  8 ++++
 .../sampledSetWriters/raw/rawSetWriter.H      |  7 +++-
 .../sampledSetWriters/vtk/vtkSetWriter.C      |  9 ++++-
 .../sampledSetWriters/vtk/vtkSetWriter.H      |  7 +++-
 src/fileFormats/sampledSetWriters/writer.C    | 29 +++++++++++++--
 src/fileFormats/sampledSetWriters/writer.H    | 29 +++++++++++++--
 src/fileFormats/sampledSetWriters/writers.C   |  4 +-
 src/fileFormats/sampledSetWriters/writers.H   |  6 ++-
 .../xmgrace/xmgraceSetWriter.C                |  8 ++++
 .../xmgrace/xmgraceSetWriter.H                |  7 +++-
 .../sampledSet/sampledSets/sampledSets.C      | 10 +++--
 .../sampledSet/sampledSets/sampledSets.H      | 37 +++++++------------
 .../sampledSets/sampledSetsTemplates.C        |  2 +-
 23 files changed, 186 insertions(+), 62 deletions(-)

diff --git a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
index b0a92cd3759..c24ebead345 100644
--- a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -39,6 +40,13 @@ Foam::csvSetWriter<Type>::csvSetWriter()
 {}
 
 
+template<class Type>
+Foam::csvSetWriter<Type>::csvSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.H b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.H
index e2f464affb1..81026527ae5 100644
--- a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -74,9 +75,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         csvSetWriter();
 
+        //- Construct with dictionary
+        explicit csvSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~csvSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C
index 17754ff2dc3..44c896bb194 100644
--- a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C
@@ -42,6 +42,13 @@ Foam::ensightSetWriter<Type>::ensightSetWriter()
 {}
 
 
+template<class Type>
+Foam::ensightSetWriter<Type>::ensightSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.H b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.H
index 2629b3c68b4..c0ebfd1e717 100644
--- a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -61,9 +62,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         ensightSetWriter();
 
+        //- Construct with dictionary
+        explicit ensightSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~ensightSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.C b/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.C
index df3fafc5e3e..771dddfd148 100644
--- a/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -42,6 +42,13 @@ Foam::gnuplotSetWriter<Type>::gnuplotSetWriter()
 {}
 
 
+template<class Type>
+Foam::gnuplotSetWriter<Type>::gnuplotSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.H b/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.H
index 08c237d0912..da889409540 100644
--- a/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/gnuplot/gnuplotSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -52,7 +53,6 @@ class gnuplotSetWriter
 :
     public writer<Type>
 {
-
 public:
 
     //- Runtime type information
@@ -61,9 +61,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         gnuplotSetWriter();
 
+        //- Construct with dictionary
+        explicit gnuplotSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~gnuplotSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.C b/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.C
index c3c4eb31909..dcb841af45c 100644
--- a/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2012 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -31,7 +32,6 @@ License
 #include "fileName.H"
 #include "OFstream.H"
 
-
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class Type>
@@ -53,6 +53,13 @@ Foam::jplotSetWriter<Type>::jplotSetWriter()
 {}
 
 
+template<class Type>
+Foam::jplotSetWriter<Type>::jplotSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.H b/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.H
index 39f19ccf322..26c0c8f5036 100644
--- a/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/jplot/jplotSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,9 +66,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         jplotSetWriter();
 
+        //- Construct with dictionary
+        explicit jplotSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~jplotSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C
index 218384cb590..5747dda8853 100644
--- a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2019 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -39,6 +39,13 @@ Foam::nastranSetWriter<Type>::nastranSetWriter()
 {}
 
 
+template<class Type>
+Foam::nastranSetWriter<Type>::nastranSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H
index 34ec75ffce1..6cdb208c256 100644
--- a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -56,13 +56,6 @@ class nastranSetWriter
 :
     public writer<Type>
 {
-public:
-
-    //- File field formats
-    using fieldFormat = Foam::fileFormats::NASCore::fieldFormat;
-
-private:
-
     // Private Member Functions
 
         //- Write the formatted keyword to the output stream
@@ -75,15 +68,22 @@ private:
 
 public:
 
+    //- File field formats
+    using fieldFormat = Foam::fileFormats::NASCore::fieldFormat;
+
+
     //- Runtime type information
     TypeName("nastran");
 
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         nastranSetWriter();
 
+        //- Construct with dictionary
+        explicit nastranSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~nastranSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/raw/rawSetWriter.C b/src/fileFormats/sampledSetWriters/raw/rawSetWriter.C
index dc6a120606f..6026e6508ae 100644
--- a/src/fileFormats/sampledSetWriters/raw/rawSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/raw/rawSetWriter.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -39,6 +40,13 @@ Foam::rawSetWriter<Type>::rawSetWriter()
 {}
 
 
+template<class Type>
+Foam::rawSetWriter<Type>::rawSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/raw/rawSetWriter.H b/src/fileFormats/sampledSetWriters/raw/rawSetWriter.H
index 817c80ce1de..87071a9285c 100644
--- a/src/fileFormats/sampledSetWriters/raw/rawSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/raw/rawSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -52,7 +53,6 @@ class rawSetWriter
 :
     public writer<Type>
 {
-
 public:
 
     //- Runtime type information
@@ -61,9 +61,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         rawSetWriter();
 
+        //- Construct with dictionary
+        explicit rawSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~rawSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C
index ab0dde0a658..e6f806d4a45 100644
--- a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -42,6 +42,13 @@ Foam::vtkSetWriter<Type>::vtkSetWriter()
 {}
 
 
+template<class Type>
+Foam::vtkSetWriter<Type>::vtkSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.H b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.H
index da000a0acc5..7e2e9493a4e 100644
--- a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -55,7 +56,6 @@ class vtkSetWriter
 :
     public writer<Type>
 {
-
 public:
 
     //- Runtime type information
@@ -64,9 +64,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         vtkSetWriter();
 
+        //- Construct with dictionary
+        explicit vtkSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~vtkSetWriter() = default;
diff --git a/src/fileFormats/sampledSetWriters/writer.C b/src/fileFormats/sampledSetWriters/writer.C
index ea142332876..09a6b884594 100644
--- a/src/fileFormats/sampledSetWriters/writer.C
+++ b/src/fileFormats/sampledSetWriters/writer.C
@@ -31,7 +31,7 @@ License
 #include "OFstream.H"
 #include "OSspecific.H"
 
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 template<class Type>
 Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
@@ -55,6 +55,29 @@ Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
 }
 
 
+template<class Type>
+Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
+(
+    const word& writeType,
+    const dictionary& formatOptions
+)
+{
+    auto ctorPtr = dictConstructorTable(writeType);
+
+    if (!ctorPtr)
+    {
+        FatalErrorInLookup
+        (
+            "writer",
+            writeType,
+            *dictConstructorTablePtr_
+        ) << exit(FatalError);
+    }
+
+    return autoPtr<writer<Type>>(ctorPtr(formatOptions));
+}
+
+
 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
 
 template<class Type>
@@ -143,10 +166,8 @@ Foam::writer<Type>::writer()
 {}
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
 template<class Type>
-Foam::writer<Type>::~writer()
+Foam::writer<Type>::writer(const dictionary& dict)
 {}
 
 
diff --git a/src/fileFormats/sampledSetWriters/writer.H b/src/fileFormats/sampledSetWriters/writer.H
index da591db0f30..47438ff2215 100644
--- a/src/fileFormats/sampledSetWriters/writer.H
+++ b/src/fileFormats/sampledSetWriters/writer.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -70,7 +71,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of classes
+// Forward Declarations
 class coordSet;
 
 /*---------------------------------------------------------------------------*\
@@ -80,7 +81,6 @@ class coordSet;
 template<class Type>
 class writer
 {
-
 protected:
 
     //- Generates filename from coordSet and sampled fields
@@ -123,21 +123,42 @@ public:
             ()
         );
 
+        declareRunTimeSelectionTable
+        (
+            autoPtr,
+            writer,
+            dict,
+            (
+                const dictionary& formatOptions
+            ),
+            (formatOptions)
+        );
+
 
     // Selectors
 
         //- Return a reference to the selected writer
         static autoPtr<writer> New(const word& writeFormat);
 
+        //- Return a reference to the selected writer
+        static autoPtr<writer> New
+        (
+            const word& writeFormat,
+            const dictionary& formatOptions
+        );
+
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         writer();
 
+        //- Construct with dictionary
+        explicit writer(const dictionary& dict);
+
 
     //- Destructor
-    virtual ~writer() = 0;
+    virtual ~writer() = default;
 
 
     // Member Functions
diff --git a/src/fileFormats/sampledSetWriters/writers.C b/src/fileFormats/sampledSetWriters/writers.C
index a730aae8343..c94fc450cef 100644
--- a/src/fileFormats/sampledSetWriters/writers.C
+++ b/src/fileFormats/sampledSetWriters/writers.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,7 +37,8 @@ namespace Foam
 
 #define defineSetWriterType(dataType)                                          \
     defineNamedTemplateTypeNameAndDebug(writer<dataType >, 0);                 \
-    defineTemplatedRunTimeSelectionTable(writer, word, dataType);
+    defineTemplatedRunTimeSelectionTable(writer, word, dataType);              \
+    defineTemplatedRunTimeSelectionTable(writer, dict, dataType);
 
 defineSetWriterType(scalar);
 defineSetWriterType(vector);
diff --git a/src/fileFormats/sampledSetWriters/writers.H b/src/fileFormats/sampledSetWriters/writers.H
index f931e523cbb..c1e7f75a764 100644
--- a/src/fileFormats/sampledSetWriters/writers.H
+++ b/src/fileFormats/sampledSetWriters/writers.H
@@ -61,7 +61,11 @@ SourceFiles
     addTemplatedToRunTimeSelectionTable                                        \
     (                                                                          \
         writer, typeWriter, dataType, word                                     \
-    )
+    );                                                                         \
+    addTemplatedToRunTimeSelectionTable                                        \
+    (                                                                          \
+        writer, typeWriter, dataType, dict                                     \
+    );
 
 
 // Define type info for scalar, vector etc. instantiations
diff --git a/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.C b/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.C
index 74b6d19a85f..6faca89cffc 100644
--- a/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -40,6 +41,13 @@ Foam::xmgraceSetWriter<Type>::xmgraceSetWriter()
 {}
 
 
+template<class Type>
+Foam::xmgraceSetWriter<Type>::xmgraceSetWriter(const dictionary& dict)
+:
+    writer<Type>(dict)
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.H b/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.H
index 31ec5e41e37..d3f064106d4 100644
--- a/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.H
+++ b/src/fileFormats/sampledSetWriters/xmgrace/xmgraceSetWriter.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -52,7 +53,6 @@ class xmgraceSetWriter
 :
     public writer<Type>
 {
-
 public:
 
     //- Runtime type information
@@ -61,9 +61,12 @@ public:
 
     // Constructors
 
-        //- Construct null
+        //- Default construct
         xmgraceSetWriter();
 
+        //- Construct with dictionary
+        explicit xmgraceSetWriter(const dictionary& dict);
+
 
     //- Destructor
     virtual ~xmgraceSetWriter() = default;
diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C
index 2420bc7ac59..06601d251e3 100644
--- a/src/sampling/sampledSet/sampledSets/sampledSets.C
+++ b/src/sampling/sampledSet/sampledSets/sampledSets.C
@@ -97,7 +97,8 @@ Foam::sampledSets::sampledSets
     outputPath_(fileName::null),
     searchEngine_(mesh_),
     interpolationScheme_(word::null),
-    writeFormat_(word::null)
+    writeFormat_(word::null),
+    writeFormatOptions_(dict.subOrEmptyDict("formatOptions"))
 {
     outputPath_ =
     (
@@ -106,7 +107,7 @@ Foam::sampledSets::sampledSets
 
     if (mesh_.name() != polyMesh::defaultRegion)
     {
-        outputPath_ = outputPath_/mesh_.name();
+        outputPath_ /= mesh_.name();
     }
 
     outputPath_.clean();  // Remove unneeded ".."
@@ -130,7 +131,8 @@ Foam::sampledSets::sampledSets
     outputPath_(fileName::null),
     searchEngine_(mesh_),
     interpolationScheme_(word::null),
-    writeFormat_(word::null)
+    writeFormat_(word::null),
+    writeFormatOptions_(dict.subOrEmptyDict("formatOptions"))
 {
     outputPath_ =
     (
@@ -139,7 +141,7 @@ Foam::sampledSets::sampledSets
 
     if (mesh_.name() != polyMesh::defaultRegion)
     {
-        outputPath_ = outputPath_/mesh_.name();
+        outputPath_ /= mesh_.name();
     }
 
     outputPath_.clean();  // Remove unneeded ".."
diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.H b/src/sampling/sampledSet/sampledSets/sampledSets.H
index 0f38753b7d2..d148f485147 100644
--- a/src/sampling/sampledSet/sampledSets/sampledSets.H
+++ b/src/sampling/sampledSet/sampledSets/sampledSets.H
@@ -53,7 +53,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
+// Forward Declarations
 class Time;
 class objectRegistry;
 class dictionary;
@@ -68,7 +68,7 @@ class sampledSets
     public functionObjects::regionFunctionObject,
     public PtrList<sampledSet>
 {
-    // Private classes
+    // Private Classes
 
         //- Class used for grouping field types
         template<class Type>
@@ -82,18 +82,7 @@ class sampledSets
             autoPtr<writer<Type>> formatter;
 
             //- Construct null
-            fieldGroup()
-            :
-                DynamicList<word>(0),
-                formatter(nullptr)
-            {}
-
-            //- Construct for a particular format
-            fieldGroup(const word& writeFormat)
-            :
-                DynamicList<word>(0),
-                formatter(writer<Type>::New(writeFormat))
-            {}
+            fieldGroup() = default;
 
             //- Reset format and field list
             void clear()
@@ -102,10 +91,9 @@ class sampledSets
                 formatter.clear();
             }
 
-            //- Assign a new formatter
-            void operator=(const word& writeFormat)
+            void setFormatter(const word& writeFormat, const dictionary& dict)
             {
-                formatter = writer<Type>::New(writeFormat);
+                formatter = writer<Type>::New(writeFormat, dict);
             }
         };
 
@@ -151,13 +139,13 @@ class sampledSets
         };
 
 
-    // Static data members
+    // Static Data Members
 
         //- Output verbosity
         static bool verbose_;
 
 
-    // Private data
+    // Private Data
 
         //- Const reference to fvMesh
         const fvMesh& mesh_;
@@ -175,7 +163,7 @@ class sampledSets
         meshSearch searchEngine_;
 
 
-      // Read from dictonary
+    // Read from dictionary
 
         //- Names of fields to sample
         wordRes fieldSelection_;
@@ -186,8 +174,11 @@ class sampledSets
         //- Output format to use
         word writeFormat_;
 
+        //- Dictionary containing writer options
+        dictionary writeFormatOptions_;
 
-      // Categorized scalar/vector/tensor fields
+
+    // Categorized scalar/vector/tensor fields
 
         fieldGroup<scalar> scalarFields_;
         fieldGroup<vector> vectorFields_;
@@ -196,7 +187,7 @@ class sampledSets
         fieldGroup<tensor> tensorFields_;
 
 
-      // Merging structures
+    // Merging structures
 
         PtrList<coordSet> masterSampledSets_;
         labelListList indexSets_;
@@ -211,7 +202,7 @@ class sampledSets
         label classifyFields();
 
         //- Combine points from all processors. Sort by curveDist and produce
-        //  index list. Valid result only on master processor.
+        //- index list. Valid result only on master processor.
         void combineSampledSets
         (
             PtrList<coordSet>& masterSampledSets,
diff --git a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C
index 82dad524a24..c9441dd28c1 100644
--- a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C
+++ b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C
@@ -231,7 +231,7 @@ void Foam::sampledSets::sampleAndWrite(fieldGroup<Type>& fields)
         // Create or use existing writer
         if (!fields.formatter)
         {
-            fields = writeFormat_;
+            fields.setFormatter(writeFormat_, writeFormatOptions_);
         }
 
         // Storage for interpolated values
-- 
GitLab