From 0a146530d76370a0396ee3577487e3f86336046c Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 14 Nov 2008 13:15:07 +0100
Subject: [PATCH] surfMesh - more code refactoring

---
 src/surfMesh/Make/files                       |  10 +-
 src/surfMesh/MeshedSurface/MeshedSurface.C    |  18 +--
 src/surfMesh/MeshedSurface/MeshedSurface.H    |   6 -
 .../UnsortedMeshedSurface.C                   |  18 +--
 .../UnsortedMeshedSurface.H                   |   8 +-
 .../surfaceFormats/ac3d/AC3DsurfaceFormat.C   |   7 +-
 .../ac3d/AC3DsurfaceFormatCore.C              |  11 --
 .../ac3d/AC3DsurfaceFormatCore.H              |   4 +
 .../ac3d/AC3DsurfaceFormatCoreTemplates.C     |  44 ++++++
 .../surfaceFormats/obj/OBJsurfaceFormat.C     |  51 +------
 .../surfaceFormats/obj/OBJsurfaceFormat.H     |   4 +-
 .../surfaceFormats/obj/OBJsurfaceFormatCore.C |  74 ++++++++++
 .../surfaceFormats/obj/OBJsurfaceFormatCore.H |  96 +++++++++++++
 .../surfaceFormats/off/OFFsurfaceFormat.C     |  52 +-------
 .../surfaceFormats/off/OFFsurfaceFormat.H     |   4 +-
 .../surfaceFormats/off/OFFsurfaceFormatCore.C |  78 +++++++++++
 .../surfaceFormats/off/OFFsurfaceFormatCore.H |  95 +++++++++++++
 .../surfaceFormats/smesh/SMESHsurfaceFormat.C |  47 +------
 .../surfaceFormats/smesh/SMESHsurfaceFormat.H |   7 +-
 .../smesh/SMESHsurfaceFormatCore.C            |  72 ++++++++++
 .../smesh/SMESHsurfaceFormatCore.H            |  99 ++++++++++++++
 .../starcd/STARCDsurfaceFormat.C              | 102 +-------------
 .../starcd/STARCDsurfaceFormat.H              |  20 +--
 .../starcd/STARCDsurfaceFormatCore.C          | 126 ++++++++++++++++++
 .../starcd/STARCDsurfaceFormatCore.H          |  95 +++++++++++++
 .../surfaceFormats/surfaceFormatsCore.C       |  29 +++-
 .../surfaceFormats/surfaceFormatsCore.H       |  19 ++-
 .../surfaceFormats/vtk/VTKsurfaceFormat.C     |  72 ++--------
 .../surfaceFormats/vtk/VTKsurfaceFormat.H     |  11 +-
 .../surfaceFormats/vtk/VTKsurfaceFormatCore.C | 103 ++++++++++++++
 .../surfaceFormats/vtk/VTKsurfaceFormatCore.H |  97 ++++++++++++++
 31 files changed, 1089 insertions(+), 390 deletions(-)
 create mode 100644 src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCoreTemplates.C
 create mode 100644 src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C
 create mode 100644 src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H
 create mode 100644 src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C
 create mode 100644 src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H
 create mode 100644 src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C
 create mode 100644 src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H
 create mode 100644 src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
 create mode 100644 src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H
 create mode 100644 src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C
 create mode 100644 src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H

diff --git a/src/surfMesh/Make/files b/src/surfMesh/Make/files
index 5273d674043..d6e808f6f06 100644
--- a/src/surfMesh/Make/files
+++ b/src/surfMesh/Make/files
@@ -7,18 +7,26 @@ UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
 
 surfaceFormats = surfaceFormats
 $(surfaceFormats)/surfaceFormatsCore.C
+
+$(surfaceFormats)/ac3d/AC3DsurfaceFormatCore.C
 $(surfaceFormats)/ac3d/AC3DsurfaceFormatRunTime.C
 $(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C
 $(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
+$(surfaceFormats)/nas/NASsurfaceFormatCore.C
 $(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
+$(surfaceFormats)/obj/OBJsurfaceFormatCore.C
 $(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
+$(surfaceFormats)/off/OFFsurfaceFormatCore.C
 $(surfaceFormats)/off/OFFsurfaceFormatRunTime.C
+$(surfaceFormats)/smesh/SMESHsurfaceFormatCore.C
 $(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C
+$(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C
 $(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C
+$(surfaceFormats)/stl/STLsurfaceFormatCore.C
 $(surfaceFormats)/stl/STLsurfaceFormatRunTime.C
 $(surfaceFormats)/stl/STLsurfaceFormatASCII.L
-$(surfaceFormats)/stl/STLsurfaceFormatCore.C
 $(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C
+$(surfaceFormats)/vtk/VTKsurfaceFormatCore.C
 $(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C
 
 LIB = $(FOAM_LIBBIN)/libsurfMesh
diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C
index f9733790049..724a51e6405 100644
--- a/src/surfMesh/MeshedSurface/MeshedSurface.C
+++ b/src/surfMesh/MeshedSurface/MeshedSurface.C
@@ -44,20 +44,6 @@ License
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
 
-template<class Face>
-Foam::fileName Foam::MeshedSurface<Face>::triSurfInstance(const Time& d)
-{
-    return triSurfInstance(d, typeName);
-}
-
-
-template<class Face>
-Foam::fileName Foam::MeshedSurface<Face>::triSurfName(const Time& d)
-{
-    return triSurfName(d, typeName);
-}
-
-
 template<class Face>
 bool Foam::MeshedSurface<Face>::canRead(const word& ext, const bool verbose)
 {
@@ -462,7 +448,7 @@ Foam::MeshedSurface<Face>::MeshedSurface(const Time& d)
 :
     ParentType(List<Face>(), pointField())
 {
-    read(IFstream(triSurfName(d))());
+    read(IFstream(findMeshName(d))());
     // setDefaultPatches();
 }
 
@@ -845,7 +831,7 @@ bool Foam::MeshedSurface<Face>::read
 template<class Face>
 void Foam::MeshedSurface<Face>::write(const Time& d) const
 {
-    write(OFstream(triSurfName(d))());
+    write(OFstream(findMeshName(d))());
 }
 
 
diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H
index 6e1851b1b17..2216a22f9fa 100644
--- a/src/surfMesh/MeshedSurface/MeshedSurface.H
+++ b/src/surfMesh/MeshedSurface/MeshedSurface.H
@@ -141,12 +141,6 @@ public:
 
     // Static
 
-        //- Name of MeshedSurface directory to use.
-        static fileName triSurfInstance(const Time&);
-
-        //- Name of MeshedSurface directory to use.
-        static fileName triSurfName(const Time&);
-
         //- Can we read this file format?
         static bool canRead(const word& ext, const bool verbose=false);
 
diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
index 0280a2f3542..b530cd9d9d4 100644
--- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
+++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
@@ -39,20 +39,6 @@ License
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
 
-template<class Face>
-Foam::fileName Foam::UnsortedMeshedSurface<Face>::triSurfInstance(const Time& d)
-{
-    return triSurfInstance(d, typeName);
-}
-
-
-template<class Face>
-Foam::fileName Foam::UnsortedMeshedSurface<Face>::triSurfName(const Time& d)
-{
-    return triSurfName(d, typeName);
-}
-
-
 template<class Face>
 bool Foam::UnsortedMeshedSurface<Face>::canRead
 (
@@ -442,7 +428,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const Time& d)
 :
     ParentType(List<Face>(), pointField())
 {
-    read(IFstream(triSurfName(d))());
+    read(IFstream(findMeshName(d))());
 }
 
 
@@ -830,7 +816,7 @@ bool Foam::UnsortedMeshedSurface<Face>::read
 template<class Face>
 void Foam::UnsortedMeshedSurface<Face>::write(const Time& d) const
 {
-    write(OFstream(triSurfName(d))());
+    write(OFstream(findMeshName(d))());
 }
 
 
diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H
index 1249007c12e..dd803e93f95 100644
--- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H
+++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H
@@ -85,7 +85,7 @@ template<class Face>
 class UnsortedMeshedSurface
 :
     public PrimitivePatchExtra<Face, ::Foam::List, pointField, point>,
-    public fileFormats::surfaceFormatsCore      
+    public fileFormats::surfaceFormatsCore
 {
     friend class MeshedSurface<Face>;
 
@@ -173,12 +173,6 @@ public:
 
     // Static
 
-        //- Name of UnsortedMeshedSurface directory to use.
-        static fileName triSurfInstance(const Time&);
-
-        //- Name of UnsortedMeshedSurface directory to use.
-        static fileName triSurfName(const Time&);
-
         //- Can we read this file format?
         static bool canRead(const word& ext, const bool verbose=false);
 
diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
index c6e857523d9..408643719fe 100644
--- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
@@ -241,7 +241,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
 
                     UList<label>& f = static_cast<UList<label>&>(verts);
 
-                    if (mustTriangulate)
+                    if (mustTriangulate && f.size() > 3)
                     {
                         triFace fTri;
 
@@ -298,7 +298,6 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
     // transfer to normal lists
     ParentType::points().transfer(pointLst);
     ParentType::faces().transfer(faceLst);
-
     ParentType::regions().transfer(regionLst);
 
     ParentType::setPatches(regionNames);
@@ -359,7 +358,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
 
         forAll(patch.localFaces(), faceI)
         {
-            const face& f = patch.localFaces()[faceI];
+            const Face& f = patch.localFaces()[faceI];
 
             os  << "SURF 0x20" << nl          // polygon
                 << "mat " << patchI << nl
@@ -417,7 +416,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
 
         forAll(patch.localFaces(), faceI)
         {
-            const face& f = patch.localFaces()[faceI];
+            const Face& f = patch.localFaces()[faceI];
 
             os  << "SURF 0x20" << nl          // polygon
                 << "mat " << patchI << nl
diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C
index 8923aceb655..9b4dcfd145e 100644
--- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C
+++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C
@@ -33,17 +33,6 @@ License
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-template<class Type>
-Type Foam::fileFormats::AC3DsurfaceFormatCore::parse(const string& str)
-{
-    IStringStream ss(str);
-
-    Type t;
-    ss >> t;
-    return t;
-}
-
-
 bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
 (
     IFstream& is,
diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H
index 60a10cf911b..ce09696a734 100644
--- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H
+++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H
@@ -104,6 +104,10 @@ public:
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+#ifdef NoRepository
+#   include "AC3DsurfaceFormatCoreTemplates.C"
+#endif
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #endif
diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCoreTemplates.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCoreTemplates.C
new file mode 100644
index 00000000000..dbe23f611b5
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCoreTemplates.C
@@ -0,0 +1,44 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "AC3DsurfaceFormatCore.H"
+#include "IStringStream.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+template<class Type>
+Type Foam::fileFormats::AC3DsurfaceFormatCore::parse(const string& s)
+{
+    IStringStream ss(s);
+
+    Type t;
+    ss >> t;
+    return t;
+}
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
index 4920b12abc5..c19eb2a325a 100644
--- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
@@ -31,47 +31,6 @@ License
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-template<class Face>
-void Foam::fileFormats::OBJsurfaceFormat<Face>::writeHead
-(
-    Ostream& os,
-    const pointField& pointLst,
-    const List<Face>& faceLst,
-    const List<surfGroup>& patchLst
-)
-{
-    os  << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
-        << "o " << os.name().lessExt().name() << nl
-        << nl
-        << "# points : " << pointLst.size() << nl
-        << "# faces  : " << faceLst.size() << nl
-        << "# patches: " << patchLst.size() << nl;
-
-    // Print patch names as comment
-    forAll(patchLst, patchI)
-    {
-        os  << "#   " << patchI << "  " << patchLst[patchI].name()
-            << "  (nFaces: " << patchLst[patchI].size() << ")" << nl;
-    }
-
-    os  << nl
-        << "# <points count=\"" << pointLst.size() << "\">" << endl;
-
-    // Write vertex coords
-    forAll(pointLst, ptI)
-    {
-        os  << "v " << pointLst[ptI].x()
-            << ' '  << pointLst[ptI].y()
-            << ' '  << pointLst[ptI].z() << nl;
-    }
-
-    os  << "# </points>" << nl
-        << nl
-        << "# <faces count=\"" << faceLst.size() << "\">" << endl;
-}
-
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class Face>
@@ -229,7 +188,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
 
             UList<label>& f = static_cast<UList<label>&>(dynVertices);
 
-            if (mustTriangulate)
+            if (mustTriangulate && f.size() > 3)
             {
                 triFace fTri;
 
@@ -277,7 +236,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
     labelList faceMap;
     List<surfGroup> patchLst = surf.sortedRegions(faceMap);
 
-    writeHead(os, surf.points(), faceLst, patchLst);
+    writeHeader(os, surf.points(), faceLst.size(), patchLst);
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
@@ -289,7 +248,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
 
         forAll(patch, patchFaceI)
         {
-            const face& f = faceLst[faceMap[faceIndex++]];
+            const Face& f = faceLst[faceMap[faceIndex++]];
 
             os  << 'f';
             forAll(f, fp)
@@ -314,7 +273,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
     const List<Face>& faceLst = surf.faces();
     const List<surfGroup>& patchLst = surf.patches();
 
-    writeHead(os, surf.points(), faceLst, patchLst);
+    writeHeader(os, surf.points(), faceLst.size(), patchLst);
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
@@ -325,7 +284,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
 
         forAll(patch, patchFaceI)
         {
-            const face& f = faceLst[faceIndex++];
+            const Face& f = faceLst[faceIndex++];
 
             os  << 'f';
             forAll(f, fp)
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H
index a0a31f641e8..9b3a16649fd 100644
--- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H
@@ -42,6 +42,7 @@ SourceFiles
 #include "OFstream.H"
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "OBJsurfaceFormatCore.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -57,7 +58,8 @@ namespace fileFormats
 template<class Face>
 class OBJsurfaceFormat
 :
-    public UnsortedMeshedSurface<Face>
+    public UnsortedMeshedSurface<Face>,
+    public OBJsurfaceFormatCore
 {
     //- Private typedefs for convenience
     typedef OBJsurfaceFormat<Face>      ThisType;
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C
new file mode 100644
index 00000000000..efd4d917de2
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C
@@ -0,0 +1,74 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "OBJsurfaceFormatCore.H"
+#include "clock.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::fileFormats::OBJsurfaceFormatCore::writeHeader
+(
+    Ostream& os,
+    const pointField& pointLst,
+    const label nFaces,
+    const List<surfGroup>& patchLst
+)
+{
+    os  << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
+        << "o " << os.name().lessExt().name() << nl
+        << nl
+        << "# points : " << pointLst.size() << nl
+        << "# faces  : " << nFaces << nl
+        << "# patches: " << patchLst.size() << nl;
+
+    // Print patch names as comment
+    forAll(patchLst, patchI)
+    {
+        os  << "#   " << patchI << "  " << patchLst[patchI].name()
+            << "  (nFaces: " << patchLst[patchI].size() << ")" << nl;
+    }
+
+    os  << nl
+        << "# <points count=\"" << pointLst.size() << "\">" << endl;
+
+    // Write vertex coords
+    forAll(pointLst, ptI)
+    {
+        os  << "v " << pointLst[ptI].x()
+            << ' '  << pointLst[ptI].y()
+            << ' '  << pointLst[ptI].z() << nl;
+    }
+
+    os  << "# </points>" << nl
+        << nl
+        << "# <faces count=\"" << nFaces << "\">" << endl;
+}
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H
new file mode 100644
index 00000000000..c2c28c58347
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H
@@ -0,0 +1,96 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::fileFormats::OBJsurfaceFormatCore
+
+Description
+    Internal class used by the OBJsurfaceFormat
+
+SourceFiles
+    OBJsurfaceFormatCore.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef OBJsurfaceFormatCore_H
+#define OBJsurfaceFormatCore_H
+
+#include "Ostream.H"
+#include "OFstream.H"
+#include "MeshedSurface.H"
+#include "UnsortedMeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace fileFormats
+{
+
+/*---------------------------------------------------------------------------*\
+                      Class AC3DfileFormat Declaration
+\*---------------------------------------------------------------------------*/
+
+class OBJsurfaceFormatCore
+{
+protected:
+        // Protected Member Functions
+
+        //- Write header information with points
+        static void writeHeader
+        (
+            Ostream&,
+            const pointField&,
+            const label nFaces,
+            const List<surfGroup>&
+        );
+
+public:
+
+    // Constructors
+
+        //- Construct null
+        OBJsurfaceFormatCore()
+        {}
+
+    // Destructor
+
+        ~OBJsurfaceFormatCore()
+        {}
+
+    // Member Functions
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace fileFormats
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C
index 19a06b752e1..c5b058bfebf 100644
--- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C
@@ -33,52 +33,6 @@ License
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-template<class Face>
-void Foam::fileFormats::OFFsurfaceFormat<Face>::writeHead
-(
-    Ostream& os,
-    const pointField& pointLst,
-    const List<Face>& faceLst,
-    const List<surfGroup>& patchLst
-)
-{
-    // Write header
-    os  << "OFF" << endl
-        << "# Geomview OFF file written " << clock::dateTime().c_str() << nl
-        << nl
-        << "# points : " << pointLst.size() << nl
-        << "# faces  : " << faceLst.size() << nl
-        << "# patches: " << patchLst.size() << nl;
-
-    // Print patch names as comment
-    forAll(patchLst, patchI)
-    {
-        os  << "#   " << patchI << "  " << patchLst[patchI].name()
-            << "  (nFaces: " << patchLst[patchI].size() << ")" << nl;
-    }
-
-    os  << nl
-        << "# nPoints  nFaces  nEdges" << nl
-        << pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl;
-
-    os  << nl
-        << "# <points count=\"" << pointLst.size() << "\">" << endl;
-
-    // Write vertex coords
-    forAll(pointLst, ptI)
-    {
-        os  << pointLst[ptI].x() << ' '
-            << pointLst[ptI].y() << ' '
-            << pointLst[ptI].z() << " #" << ptI << endl;
-    }
-
-    os  << "# </points>" << nl
-        << nl
-        << "# <faces count=\"" << faceLst.size() << "\">" << endl;
-}
-
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class Face>
@@ -188,7 +142,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
 
             UList<label>& f = static_cast<UList<label>&>(verts);
 
-            if (mustTriangulate)
+            if (mustTriangulate && f.size() > 3)
             {
                 triFace fTri;
 
@@ -237,7 +191,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
     labelList faceMap;
     List<surfGroup> patchLst = surf.sortedRegions(faceMap);
 
-    writeHead(os, surf.points(), faceLst, patchLst);
+    writeHeader(os, surf.points(), faceLst.size(), patchLst);
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
@@ -273,7 +227,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
     const List<Face>& faceLst = surf.faces();
     const List<surfGroup>& patchLst = surf.patches();
 
-    writeHead(os, surf.points(), faceLst, patchLst);
+    writeHeader(os, surf.points(), faceLst.size(), patchLst);
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H
index 02a4f1f2c10..e3abd042d2e 100644
--- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H
+++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H
@@ -50,6 +50,7 @@ SourceFiles
 #include "OFstream.H"
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "OFFsurfaceFormatCore.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -65,7 +66,8 @@ namespace fileFormats
 template<class Face>
 class OFFsurfaceFormat
 :
-    public UnsortedMeshedSurface<Face>
+    public UnsortedMeshedSurface<Face>,
+    public OFFsurfaceFormatCore
 {
     //- Private typedefs for convenience
     typedef OFFsurfaceFormat<Face>      ThisType;
diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C
new file mode 100644
index 00000000000..27e96a0a103
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C
@@ -0,0 +1,78 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "OFFsurfaceFormatCore.H"
+#include "clock.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::fileFormats::OFFsurfaceFormatCore::writeHeader
+(
+    Ostream& os,
+    const pointField& pointLst,
+    const label nFaces,
+    const List<surfGroup>& patchLst
+)
+{
+    // Write header
+    os  << "OFF" << endl
+        << "# Geomview OFF file written " << clock::dateTime().c_str() << nl
+        << nl
+        << "# points : " << pointLst.size() << nl
+        << "# faces  : " << nFaces << nl
+        << "# patches: " << patchLst.size() << nl;
+
+    // Print patch names as comment
+    forAll(patchLst, patchI)
+    {
+        os  << "#   " << patchI << "  " << patchLst[patchI].name()
+            << "  (nFaces: " << patchLst[patchI].size() << ")" << nl;
+    }
+
+    os  << nl
+        << "# nPoints  nFaces  nEdges" << nl
+        << pointLst.size() << ' ' << nFaces << ' ' << 0 << nl;
+
+    os  << nl
+        << "# <points count=\"" << pointLst.size() << "\">" << endl;
+
+    // Write vertex coords
+    forAll(pointLst, ptI)
+    {
+        os  << pointLst[ptI].x() << ' '
+            << pointLst[ptI].y() << ' '
+            << pointLst[ptI].z() << " #" << ptI << endl;
+    }
+
+    os  << "# </points>" << nl
+        << nl
+        << "# <faces count=\"" << nFaces << "\">" << endl;
+}
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H
new file mode 100644
index 00000000000..29cee497abd
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H
@@ -0,0 +1,95 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::fileFormats::OFFsurfaceFormatCore
+
+Description
+    Internal class used by the OFFsurfaceFormat
+
+SourceFiles
+    OFFsurfaceFormatCore.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef OFFsurfaceFormatCore_H
+#define OFFsurfaceFormatCore_H
+
+#include "Ostream.H"
+#include "OFstream.H"
+#include "MeshedSurface.H"
+#include "UnsortedMeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace fileFormats
+{
+
+/*---------------------------------------------------------------------------*\
+                   Class OFFsurfaceFormatCore Declaration
+\*---------------------------------------------------------------------------*/
+
+class OFFsurfaceFormatCore
+{
+protected:
+        // Protected Member Functions
+
+        //- Write header information with points
+        static void writeHeader
+        (
+            Ostream&,
+            const pointField&,
+            const label nFaces,
+            const List<surfGroup>&
+        );
+
+public:
+
+    // Constructors
+
+        //- Construct null
+        OFFsurfaceFormatCore()
+        {}
+
+    // Destructor
+        ~OFFsurfaceFormatCore()
+        {}
+
+    // Member Functions
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace fileFormats
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
index fa5b2c9bcfd..213cea1bfda 100644
--- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
@@ -27,52 +27,11 @@ License
 #include "SMESHsurfaceFormat.H"
 #include "clock.H"
 #include "IStringStream.H"
-#include "addToRunTimeSelectionTable.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-template<class Face>
-void Foam::fileFormats::SMESHsurfaceFormat<Face>::writeHead
-(
-    Ostream& os,
-    const pointField& pointLst,
-    const List<Face>& faceLst
-)
-{
-    // Write header
-    os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl;
-    os << "# <points count=\"" << pointLst.size() << "\">" << endl;
-    os << pointLst.size() << " 3" << nl;    // 3: dimensions
-
-    // Write vertex coords
-    forAll(pointLst, ptI)
-    {
-        os  << ptI
-            << ' ' << pointLst[ptI].x()
-            << ' ' << pointLst[ptI].y()
-            << ' ' << pointLst[ptI].z() << nl;
-    }
-    os  << "# </points>" << nl
-        << nl
-        << "# <faces count=\"" << faceLst.size() << "\">" << endl;
-
-    os  << faceLst.size() << " 1" << endl;   // one attribute: region number
-}
-
-
-template<class Face>
-void Foam::fileFormats::SMESHsurfaceFormat<Face>::writeTail(Ostream& os)
-{
-    os  << "# </faces>" << nl
-        << nl
-        << "# no holes or regions:" << nl
-        << '0' << nl        // holes
-        << '0' << endl;     // regions
-}
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class Face>
@@ -92,7 +51,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
 {
     const List<Face>& faceLst = surf.faces();
 
-    writeHead(os, surf.points(), faceLst);
+    writeHeader(os, surf.points(), faceLst.size());
 
     labelList faceMap;
     List<surfGroup> patchLst = surf.sortedRegions(faceMap);
@@ -127,14 +86,14 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
     const List<Face>& faceLst = surf.faces();
     const List<surfGroup>& patchLst = surf.patches();
 
-    writeHead(os, surf.points(), faceLst);
+    writeHeader(os, surf.points(), faceLst.size());
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
     {
         forAll(patchLst[patchI], patchFaceI)
         {
-            const face& f = faceLst[faceIndex++];
+            const Face& f = faceLst[faceIndex++];
 
             os  << f.size();
             forAll(f, fp)
diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H
index 341b90e7262..4b4b13fb41f 100644
--- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H
+++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H
@@ -47,6 +47,7 @@ SourceFiles
 #include "Ostream.H"
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "SMESHsurfaceFormatCore.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -62,7 +63,8 @@ namespace fileFormats
 template<class Face>
 class SMESHsurfaceFormat
 :
-    public UnsortedMeshedSurface<Face>
+    public UnsortedMeshedSurface<Face>,
+    public SMESHsurfaceFormatCore
 {
     //- Private typedefs for convenience
     typedef SMESHsurfaceFormat<Face>    ThisType;
@@ -76,9 +78,6 @@ class SMESHsurfaceFormat
         //- Disallow default bitwise assignment
         void operator=(const SMESHsurfaceFormat<Face>&);
 
-        static void writeHead(Ostream&, const pointField&, const List<Face>&);
-        static void writeTail(Ostream&);
-
 public:
 
     // Constructors
diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C
new file mode 100644
index 00000000000..6b44da6e2e9
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C
@@ -0,0 +1,72 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "SMESHsurfaceFormatCore.H"
+#include "clock.H"
+#include "IStringStream.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::fileFormats::SMESHsurfaceFormatCore::writeHeader
+(
+    Ostream& os,
+    const pointField& pointLst,
+    const label nFaces
+)
+{
+    // Write header
+    os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl;
+    os << "# <points count=\"" << pointLst.size() << "\">" << endl;
+    os << pointLst.size() << " 3" << nl;    // 3: dimensions
+
+    // Write vertex coords
+    forAll(pointLst, ptI)
+    {
+        os  << ptI
+            << ' ' << pointLst[ptI].x()
+            << ' ' << pointLst[ptI].y()
+            << ' ' << pointLst[ptI].z() << nl;
+    }
+    os  << "# </points>" << nl
+        << nl
+        << "# <faces count=\"" << nFaces << "\">" << endl;
+
+    os  << nFaces << " 1" << endl;   // one attribute: region number
+}
+
+
+void Foam::fileFormats::SMESHsurfaceFormatCore::writeTail(Ostream& os)
+{
+    os  << "# </faces>" << nl
+        << nl
+        << "# no holes or regions:" << nl
+        << '0' << nl        // holes
+        << '0' << endl;     // regions
+}
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H
new file mode 100644
index 00000000000..9343fa53d06
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H
@@ -0,0 +1,99 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::fileFormats::SMESHsurfaceFormatCore
+
+Description
+    Internal class used by the SMESHsurfaceFormat
+
+SourceFiles
+    SMESHsurfaceFormatCore.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef SMESHsurfaceFormatCore_H
+#define SMESHsurfaceFormatCore_H
+
+#include "IFstream.H"
+#include "OFstream.H"
+#include "Ostream.H"
+#include "MeshedSurface.H"
+#include "UnsortedMeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace fileFormats
+{
+
+/*---------------------------------------------------------------------------*\
+                  Class SMESHsurfaceFormatCore Declaration
+\*---------------------------------------------------------------------------*/
+
+class SMESHsurfaceFormatCore
+{
+protected:
+    // Protected Member Functions
+
+        //- Write header information with points
+        static void writeHeader
+        (
+            Ostream&,
+            const pointField&,
+            const label nFaces
+        );
+
+        //- Write tail information
+        static void writeTail(Ostream&);
+
+public:
+
+    // Constructors
+
+        //- Construct null
+        SMESHsurfaceFormatCore()
+        {}
+
+    // Destructor
+
+        ~SMESHsurfaceFormatCore()
+        {}
+
+    // Member Functions
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace fileFormats
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
index bedf9c5e88e..574e969a0d0 100644
--- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
@@ -31,100 +31,8 @@ License
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
-//! @cond localscope
-const int starcdShellShape = 3;
-const int starcdShellType  = 4;
-//! @endcond localscope
-
-
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-template<class Face>
-bool Foam::fileFormats::STARCDsurfaceFormat<Face>::readHeader
-(
-    IFstream& is,
-    const word& signature
-)
-{
-    if (!is.good())
-    {
-        FatalErrorIn
-        (
-            "fileFormats::STARCDsurfaceFormat::readHeader(...)"
-        )
-            << "cannot read " << signature  << "  " << is.name()
-            << abort(FatalError);
-    }
-
-    word header;
-    label majorVersion;
-
-    string line;
-
-    is.getLine(line);
-    IStringStream(line)() >> header;
-
-    is.getLine(line);
-    IStringStream(line)() >> majorVersion;
-
-    // add other checks ...
-    if (header != signature)
-    {
-        Info<< "header mismatch " << signature << "  " << is.name()
-            << endl;
-    }
-
-    return true;
-}
-
-
-template<class Face>
-void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeHeader
-(
-    Ostream& os,
-    const char* filetype
-)
-{
-    os  << "PROSTAR_" << filetype << nl
-        << 4000
-        << " " << 0
-        << " " << 0
-        << " " << 0
-        << " " << 0
-        << " " << 0
-        << " " << 0
-        << " " << 0
-        << endl;
-}
-
-
-template<class Face>
-void Foam::fileFormats::STARCDsurfaceFormat<Face>::writePoints
-(
-    Ostream& os,
-    const pointField& pointLst
-)
-{
-    writeHeader(os, "VERTEX");
-
-    // Set the precision of the points data to 10
-    os.precision(10);
-
-    // force decimal point for Fortran input
-    os.setf(std::ios::showpoint);
-
-    forAll(pointLst, ptI)
-    {
-        os
-            << ptI + 1 << " "
-            << pointLst[ptI].x() << " "
-            << pointLst[ptI].y() << " "
-            << pointLst[ptI].z() << nl;
-    }
-    os.flush();
-}
-
-
 template<class Face>
 void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
 (
@@ -135,11 +43,11 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
 )
 {
     os
-        << cellId                // includes 1 offset
-        << " " << starcdShellShape  // 3(shell)
+        << cellId                    // includes 1 offset
+        << " " << starcdShellShape_  // 3(shell) shape
         << " " << f.size()
         << " " << cellTableId
-        << " " << starcdShellType;  // 4(shell)
+        << " " << starcdShellType_;  // 4(shell)
 
     // primitives have <= 8 vertices, but prevent overrun anyhow
     // indent following lines for ease of reading
@@ -189,7 +97,7 @@ Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
 :
     ParentType()
 {
-    ThisType::read(fName);
+    read(fName);
 }
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
@@ -312,7 +220,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
             isPtr() >> starLabels[i];
         }
 
-        if (typeId == starcdShellType)
+        if (typeId == starcdShellType_)
         {
             // Convert groupID into patchID
             Map<label>::const_iterator iter =
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H
index 02fca9b175b..250cd9205e9 100644
--- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H
@@ -47,6 +47,7 @@ SourceFiles
 #include "OFstream.H"
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "STARCDsurfaceFormatCore.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -56,18 +57,26 @@ namespace fileFormats
 {
 
 /*---------------------------------------------------------------------------*\
-                     Class STARCDsurfaceFormat Declaration
+                    Class STARCDsurfaceFormat Declaration
 \*---------------------------------------------------------------------------*/
 
 template<class Face>
 class STARCDsurfaceFormat
 :
-    public UnsortedMeshedSurface<Face>
+    public UnsortedMeshedSurface<Face>,
+    public STARCDsurfaceFormatCore
 {
     //- Private typedefs for convenience
     typedef STARCDsurfaceFormat<Face>   ThisType;
     typedef UnsortedMeshedSurface<Face> ParentType;
 
+    // Private Data
+    //- STAR-CD identifier for shell shapes (2d elements)
+    static const int starcdShellShape_ = 3;
+
+    //- STAR-CD identifier for shell type (shells vs. baffles)
+    static const int starcdShellType_  = 4;
+
     // Private Member Functions
 
         //- Disallow default bitwise copy construct
@@ -76,13 +85,6 @@ class STARCDsurfaceFormat
         //- Disallow default bitwise assignment
         void operator=(const STARCDsurfaceFormat<Face>&);
 
-
-        static bool readHeader(IFstream&, const word&);
-
-        static void writeHeader(Ostream&, const char* filetype);
-
-        static void writePoints(Ostream&, const pointField&);
-
         static inline void writeShell
         (
             Ostream&,
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
new file mode 100644
index 00000000000..a232c68bde1
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
@@ -0,0 +1,126 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "STARCDsurfaceFormatCore.H"
+#include "clock.H"
+#include "OSspecific.H"
+#include "IStringStream.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+//! @cond localscope
+const int starcdShellShape = 3;
+const int starcdShellType  = 4;
+//! @endcond localscope
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
+(
+    IFstream& is,
+    const word& signature
+)
+{
+    if (!is.good())
+    {
+        FatalErrorIn
+        (
+            "fileFormats::STARCDsurfaceFormatCore::readHeader(...)"
+        )
+            << "cannot read " << signature  << "  " << is.name()
+            << abort(FatalError);
+    }
+
+    word header;
+    label majorVersion;
+
+    string line;
+
+    is.getLine(line);
+    IStringStream(line)() >> header;
+
+    is.getLine(line);
+    IStringStream(line)() >> majorVersion;
+
+    // add other checks ...
+    if (header != signature)
+    {
+        Info<< "header mismatch " << signature << "  " << is.name()
+            << endl;
+    }
+
+    return true;
+}
+
+
+void Foam::fileFormats::STARCDsurfaceFormatCore::writeHeader
+(
+    Ostream& os,
+    const char* filetype
+)
+{
+    os  << "PROSTAR_" << filetype << nl
+        << 4000
+        << " " << 0
+        << " " << 0
+        << " " << 0
+        << " " << 0
+        << " " << 0
+        << " " << 0
+        << " " << 0
+        << endl;
+}
+
+
+void Foam::fileFormats::STARCDsurfaceFormatCore::writePoints
+(
+    Ostream& os,
+    const pointField& pointLst
+)
+{
+    writeHeader(os, "VERTEX");
+
+    // Set the precision of the points data to 10
+    os.precision(10);
+
+    // force decimal point for Fortran input
+    os.setf(std::ios::showpoint);
+
+    forAll(pointLst, ptI)
+    {
+        os
+            << ptI + 1 << " "
+            << pointLst[ptI].x() << " "
+            << pointLst[ptI].y() << " "
+            << pointLst[ptI].z() << nl;
+    }
+    os.flush();
+}
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H
new file mode 100644
index 00000000000..9142232a66f
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H
@@ -0,0 +1,95 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::fileFormats::STARCDsurfaceFormatCore
+
+Description
+    Internal class used by the OBJsurfaceFormat
+
+SourceFiles
+    STARCDsurfaceFormatCore.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef STARCDsurfaceFormatCore_H
+#define STARCDsurfaceFormatCore_H
+
+#include "IFstream.H"
+#include "Ostream.H"
+#include "OFstream.H"
+#include "MeshedSurface.H"
+#include "UnsortedMeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace fileFormats
+{
+
+/*---------------------------------------------------------------------------*\
+                  Class STARCDsurfaceFormatCore Declaration
+\*---------------------------------------------------------------------------*/
+
+class STARCDsurfaceFormatCore
+{
+protected:
+    // Protected Member Functions
+
+        static bool readHeader(IFstream&, const word&);
+
+        static void writeHeader(Ostream&, const char* filetype);
+
+        static void writePoints(Ostream&, const pointField&);
+
+public:
+
+    // Constructors
+
+        //- Construct null
+        STARCDsurfaceFormatCore()
+        {}
+
+    // Destructor
+        ~STARCDsurfaceFormatCore()
+        {}
+
+    // Member Functions
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace fileFormats
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
index 0b5cb98322a..c5af959f8e9 100644
--- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
+++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
@@ -32,7 +32,7 @@ License
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
-// File extension for 'native' raw format
+Foam::word Foam::fileFormats::surfaceFormatsCore::meshSubDir("meshedSurface");
 Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@@ -63,13 +63,13 @@ Foam::fileFormats::surfaceFormatsCore::getLineNoComment
 
 
 Foam::fileName
-Foam::fileFormats::surfaceFormatsCore::triSurfInstance
+Foam::fileFormats::surfaceFormatsCore::findMeshInstance
 (
     const Time& d,
     const word& subdirName
 )
 {
-    fileName foamName(d.caseName() + ".ofs");
+    fileName foamName(d.caseName() + "." + nativeExt);
 
     // Search back through the time directories list to find the time
     // closest to and lower than current time
@@ -104,13 +104,13 @@ Foam::fileFormats::surfaceFormatsCore::triSurfInstance
 
 
 Foam::fileName
-Foam::fileFormats::surfaceFormatsCore::triSurfName
+Foam::fileFormats::surfaceFormatsCore::findMeshName
 (
     const Time& d,
     const word& subdirName
 )
 {
-    fileName foamName(d.caseName() + ".ofs");
+    fileName foamName(d.caseName() + "." + nativeExt);
 
     // Search back through the time directories list to find the time
     // closest to and lower than current time
@@ -146,6 +146,25 @@ Foam::fileFormats::surfaceFormatsCore::triSurfName
 }
 
 
+Foam::fileName
+Foam::fileFormats::surfaceFormatsCore::findMeshInstance
+(
+    const Time& d
+)
+{
+    return findMeshInstance(d, meshSubDir);
+}
+
+
+Foam::fileName
+Foam::fileFormats::surfaceFormatsCore::findMeshName
+(
+    const Time& d
+)
+{
+    return findMeshName(d, meshSubDir);
+}
+
 // Returns patch info.
 // Sets faceMap to the indexing according to patch numbers.
 // Patch numbers start at 0.
diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
index 835471887ef..f8c9d0f8125 100644
--- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
+++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
@@ -50,7 +50,7 @@ namespace Foam
 
 class IFstream;
 class Time;
-   
+
 namespace fileFormats
 {
 
@@ -64,8 +64,11 @@ public:
 
     // Static Data
 
-        //- The file extension corresponding to 'native' surface format
-        static word nativeExt;
+    //- Return the mesh sub-directory name (usually "meshedSurface")
+    static word meshSubDir;
+
+    //- The file extension corresponding to 'native' surface format
+    static word nativeExt;
 
     // Static Member Functions
 
@@ -76,10 +79,16 @@ public:
         static string getLineNoComment(IFstream&);
 
         //- Name of UnsortedMeshedSurface directory to use.
-        static fileName triSurfInstance(const Time&, const word& subdirName);
+        static fileName findMeshInstance(const Time&, const word& subdirName);
+
+        //- Name of UnsortedMeshedSurface directory to use.
+        static fileName findMeshName(const Time&, const word& subdirName);
+
+        //- Name of UnsortedMeshedSurface directory to use.
+        static fileName findMeshInstance(const Time&);
 
         //- Name of UnsortedMeshedSurface directory to use.
-        static fileName triSurfName(const Time&, const word& subdirName);
+        static fileName findMeshName(const Time&);
 
         //- Determine the sort order from the region list.
         //  Returns patch list and sets faceMap to indices within faceLst
diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
index 70f095c7cbb..64cd8472dd3 100644
--- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
@@ -33,30 +33,14 @@ License
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 template<class Face>
-void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHead
+void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHeaderPolygons
 (
     Ostream& os,
-    const pointField& pointLst,
     const List<Face>& faceLst
 )
 {
-    // Write header
-    os  << "# vtk DataFile Version 2.0" << nl
-        << "surface written " << clock::dateTime().c_str() << nl
-        << "ASCII" << nl
-        << nl
-        << "DATASET POLYDATA" << nl;
-
-    // Write vertex coords
-    os  << "POINTS " << pointLst.size() << " float" << nl;
-    forAll(pointLst, ptI)
-    {
-        os  << pointLst[ptI].x() << ' '
-            << pointLst[ptI].y() << ' '
-            << pointLst[ptI].z() << nl;
-    }
-
     label nNodes = 0;
+
     forAll(faceLst, faceI)
     {
         nNodes += faceLst[faceI].size();
@@ -68,48 +52,6 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHead
 }
 
 
-template<class Face>
-void Foam::fileFormats::VTKsurfaceFormat<Face>::writeTail
-(
-    Ostream& os,
-    const List<surfGroup>& patchLst
-)
-{
-    label nFaces = 0;
-    forAll(patchLst, patchI)
-    {
-        nFaces += patchLst[patchI].size();
-    }
-
-    // Print region numbers
-    os  << nl
-        << "CELL_DATA " << nFaces << nl
-        << "FIELD attributes 1" << nl
-        << "region 1 " << nFaces << " float" << nl;
-
-
-    forAll(patchLst, patchI)
-    {
-        forAll(patchLst[patchI], patchFaceI)
-        {
-            if (patchFaceI)
-            {
-                if ((patchFaceI % 20) == 0)
-                {
-                    os  << nl;
-                }
-                else
-                {
-                    os  << ' ';
-                }
-            }
-            os  << patchI + 1;
-        }
-        os  << nl;
-    }
-}
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class Face>
@@ -130,7 +72,8 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
 {
     const List<Face>& faceLst = surf.faces();
 
-    writeHead(os, surf.points(), faceLst);
+    writeHeader(os, surf.points());
+    writeHeaderPolygons(os, faceLst);
 
     labelList faceMap;
     List<surfGroup> patchLst = surf.sortedRegions(faceMap);
@@ -140,7 +83,7 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
     {
         forAll(patchLst[patchI], patchFaceI)
         {
-            const face& f = faceLst[faceMap[faceIndex++]];
+            const Face& f = faceLst[faceMap[faceIndex++]];
 
             os  << f.size();
             forAll(f, fp)
@@ -166,14 +109,15 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
     const List<Face>& faceLst = surf.faces();
     const List<surfGroup>& patchLst = surf.patches();
 
-    writeHead(os, surf.points(), faceLst);
+    writeHeader(os, surf.points());
+    writeHeaderPolygons(os, faceLst);
 
     label faceIndex = 0;
     forAll(patchLst, patchI)
     {
         forAll(patchLst[patchI], patchFaceI)
         {
-            const face& f = faceLst[faceIndex++];
+            const Face& f = faceLst[faceIndex++];
 
             os  << f.size();
             forAll(f, fp)
diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H
index 066501457d5..bf2ba5db502 100644
--- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H
+++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H
@@ -40,6 +40,7 @@ SourceFiles
 #include "OFstream.H"
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "VTKsurfaceFormatCore.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -55,7 +56,8 @@ namespace fileFormats
 template<class Face>
 class VTKsurfaceFormat
 :
-    public UnsortedMeshedSurface<Face>
+    public UnsortedMeshedSurface<Face>,
+    public VTKsurfaceFormatCore
 {
     //- Private typedefs for convenience
     typedef VTKsurfaceFormat<Face>      ThisType;
@@ -63,15 +65,16 @@ class VTKsurfaceFormat
 
     // Private Member Functions
 
+        //- Write header information about number of polygon points
+        static void writeHeaderPolygons(Ostream&, const List<Face>&);
+
+
         //- Disallow default bitwise copy construct
         VTKsurfaceFormat(const VTKsurfaceFormat<Face>&);
 
         //- Disallow default bitwise assignment
         void operator=(const VTKsurfaceFormat<Face>&);
 
-        static void writeHead(Ostream&, const pointField&, const List<Face>&);
-        static void writeTail(Ostream&, const List<surfGroup>&);
-
 public:
 
     // Constructors
diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C
new file mode 100644
index 00000000000..0032d4a08d8
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C
@@ -0,0 +1,103 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "VTKsurfaceFormatCore.H"
+#include "clock.H"
+#include "IFstream.H"
+#include "IStringStream.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader
+(
+    Ostream& os,
+    const pointField& pointLst
+)
+{
+    // Write header
+    os  << "# vtk DataFile Version 2.0" << nl
+        << "surface written " << clock::dateTime().c_str() << nl
+        << "ASCII" << nl
+        << nl
+        << "DATASET POLYDATA" << nl;
+
+    // Write vertex coords
+    os  << "POINTS " << pointLst.size() << " float" << nl;
+    forAll(pointLst, ptI)
+    {
+        os  << pointLst[ptI].x() << ' '
+            << pointLst[ptI].y() << ' '
+            << pointLst[ptI].z() << nl;
+    }
+}
+
+
+void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
+(
+    Ostream& os,
+    const List<surfGroup>& patchLst
+)
+{
+    label nFaces = 0;
+    forAll(patchLst, patchI)
+    {
+        nFaces += patchLst[patchI].size();
+    }
+
+    // Print region numbers
+    os  << nl
+        << "CELL_DATA " << nFaces << nl
+        << "FIELD attributes 1" << nl
+        << "region 1 " << nFaces << " float" << nl;
+
+
+    forAll(patchLst, patchI)
+    {
+        forAll(patchLst[patchI], patchFaceI)
+        {
+            if (patchFaceI)
+            {
+                if ((patchFaceI % 20) == 0)
+                {
+                    os  << nl;
+                }
+                else
+                {
+                    os  << ' ';
+                }
+            }
+            os  << patchI + 1;
+        }
+        os  << nl;
+    }
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H
new file mode 100644
index 00000000000..c8fa662cb70
--- /dev/null
+++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H
@@ -0,0 +1,97 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::fileFormats::VTKsurfaceFormatCore
+
+Description
+    Internal class used by the VTKsurfaceFormat
+
+SourceFiles
+    VTKsurfaceFormatCore.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef VTKsurfaceFormatCore_H
+#define VTKsurfaceFormatCore_H
+
+#include "Ostream.H"
+#include "OFstream.H"
+#include "MeshedSurface.H"
+#include "UnsortedMeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace fileFormats
+{
+
+/*---------------------------------------------------------------------------*\
+                   Class VTKsurfaceFormatCore Declaration
+\*---------------------------------------------------------------------------*/
+
+class VTKsurfaceFormatCore
+{
+protected:
+    // Protected Member Functions
+
+        //- Write header information with points
+        static void writeHeader
+        (
+            Ostream&,
+            const pointField&
+        );
+
+        //- Write header information with patch informattion
+        static void writeTail(Ostream&, const List<surfGroup>&);
+
+public:
+
+    // Constructors
+
+        //- Construct null
+        VTKsurfaceFormatCore()
+        {}
+
+    // Destructor
+
+        virtual ~VTKsurfaceFormatCore()
+        {}
+
+    // Member Functions
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace fileFormats
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab