From e112eb503bc985a1040444efb174929b206e4a96 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 14 Nov 2016 00:45:41 +0100
Subject: [PATCH] ENH: provide ModifiableMeshedSurface class

- A special purpose MeshedSurface that exposes the stored values
  for direct modification.

- Its usage should be restricted to special cases where the surface
  needs modifications as an atomic operation.
---
 .../surfaceMeshConvertTesting.C               |  39 +++++++
 .../ModifiableMeshedSurface.H                 | 110 ++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100644 src/surfMesh/ModifiableMeshedSurface/ModifiableMeshedSurface.H

diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C
index edb8527698e..bc7d50f495e 100644
--- a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C
+++ b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C
@@ -41,6 +41,9 @@ Usage
       - \par -orient
         Check face orientation on the input surface
 
+      - \par -testModify
+        Test modification mechanism
+
       - \par -scale \<scale\>
         Specify a scaling factor for writing the files
 
@@ -65,6 +68,7 @@ Note
 #include "PackedBoolList.H"
 
 #include "MeshedSurfaces.H"
+#include "ModifiableMeshedSurface.H"
 #include "UnsortedMeshedSurfaces.H"
 
 #include "IStringStream.H"
@@ -93,6 +97,13 @@ int main(int argc, char *argv[])
         "orient",
         "check surface orientation"
     );
+
+    argList::addBoolOption
+    (
+        "testModify",
+        "Test modification mechanism (MeshedSurface)"
+    );
+
     argList::addBoolOption
     (
         "surfMesh",
@@ -389,6 +400,34 @@ int main(int argc, char *argv[])
             Info<< endl;
         }
 
+        if (args.optionFound("testModify"))
+        {
+            Info<< "Use ModifiableMeshedSurface to shift (1, 0, 0)" << endl;
+            Info<< "original" << nl;
+            surf.writeStats(Info);
+            Info<< endl;
+
+            ModifiableMeshedSurface<face> tsurf(surf.xfer());
+            // ModifiableMeshedSurface<face> tsurf;
+            // tsurf.reset(surf.xfer());
+
+            Info<< "in-progress" << nl;
+            surf.writeStats(Info);
+            Info<< endl;
+
+            tsurf.storedPoints() += vector(1, 0, 0);
+
+            surf.transfer(tsurf);
+
+            Info<< "updated" << nl;
+            surf.writeStats(Info);
+            Info<< endl;
+
+            Info<< "modifier" << nl;
+            tsurf.writeStats(Info);
+            Info<< endl;
+        }
+
         Info<< "writing " << exportName;
         if (scaleFactor <= 0)
         {
diff --git a/src/surfMesh/ModifiableMeshedSurface/ModifiableMeshedSurface.H b/src/surfMesh/ModifiableMeshedSurface/ModifiableMeshedSurface.H
new file mode 100644
index 00000000000..160198dff1f
--- /dev/null
+++ b/src/surfMesh/ModifiableMeshedSurface/ModifiableMeshedSurface.H
@@ -0,0 +1,110 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2016 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 3 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, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::ModifiableMeshedSurface
+
+Description
+    A special purpose MeshedSurface that exposes the stored values
+    for direct modification.
+
+    Its usage should be restricted to special cases where the surface
+    needs modifications as an atomic operation.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef ModifiableMeshedSurface_H
+#define ModifiableMeshedSurface_H
+
+#include "MeshedSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                   Class ModifiableMeshedSurface Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Face>
+class ModifiableMeshedSurface
+:
+    public MeshedSurface<Face>
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        ModifiableMeshedSurface(const ModifiableMeshedSurface<Face>&) = delete;
+
+        //- Disallow default bitwise assignment
+        void operator=(const ModifiableMeshedSurface<Face>&) = delete;
+
+
+public:
+
+    // Constructors
+
+        //- Construct null, use reset/transfer to adjust contents
+        ModifiableMeshedSurface()
+        :
+            MeshedSurface<Face>()
+        {}
+
+
+        //- Construct by transferring the contents from a MeshedSurface
+        explicit ModifiableMeshedSurface
+        (
+            const Xfer<MeshedSurface<Face>>& surf
+        )
+        :
+            MeshedSurface<Face>(surf)
+        {}
+
+
+    //- Destructor
+    virtual ~ModifiableMeshedSurface()
+    {}
+
+
+    // Member Functions
+
+        // Edit
+
+            // Expose protected methods
+            using MeshedSurface<Face>::storedFaces;
+            using MeshedSurface<Face>::storedPoints;
+            using MeshedSurface<Face>::storedZones;
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab