From da70f6734acb3007d573e1aa94e32f385e78eed8 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Fri, 7 Oct 2016 20:31:36 +0100
Subject: [PATCH] blockMesh: Simplify reading of curvedEdges

---
 .../blockMesh/blockMesh/blockMeshTopology.C   | 81 ++++---------------
 src/mesh/blockMesh/curvedEdges/curvedEdge.H   | 19 +++++
 2 files changed, 35 insertions(+), 65 deletions(-)

diff --git a/src/mesh/blockMesh/blockMesh/blockMeshTopology.C b/src/mesh/blockMesh/blockMesh/blockMeshTopology.C
index dfc1d93b2df..1db9016344d 100644
--- a/src/mesh/blockMesh/blockMesh/blockMeshTopology.C
+++ b/src/mesh/blockMesh/blockMesh/blockMeshTopology.C
@@ -112,7 +112,7 @@ void Foam::blockMesh::readPatches
 {
     ITstream& patchStream(meshDescription.lookup("patches"));
 
-    // read number of patches in mesh
+    // Read number of patches in mesh
     label nPatches = 0;
 
     token firstToken(patchStream);
@@ -213,6 +213,7 @@ void Foam::blockMesh::readPatches
             // Update halfA info
             patchNames[nPatches-1] = halfA;
             nbrPatchNames[nPatches-1] = halfB;
+
             // Update halfB info
             patchTypes[nPatches] = patchTypes[nPatches-1];
             patchNames[nPatches] = halfB;
@@ -326,7 +327,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
     word defaultPatchName = "defaultFaces";
     word defaultPatchType = emptyPolyPatch::typeName;
 
-    // get names/types for the unassigned patch faces
+    // Read the names/types for the unassigned patch faces
     // this is a bit heavy handed (and ugly), but there is currently
     // no easy way to rename polyMesh patches subsequently
     if (const dictionary* dictPtr = meshDescription.subDictPtr("defaultPatch"))
@@ -335,85 +336,36 @@ Foam::polyMesh* Foam::blockMesh::createTopology
         dictPtr->readIfPresent("type", defaultPatchType);
     }
 
-    // optional 'convertToMeters' or 'scale'  scaling factor
+    // Optional 'convertToMeters' or 'scale' scaling factor
     if (!meshDescription.readIfPresent("convertToMeters", scaleFactor_))
     {
         meshDescription.readIfPresent("scale", scaleFactor_);
     }
 
 
-    //
-    // get the non-linear edges in mesh
-    //
+    // Read the block edges
     if (meshDescription.found("edges"))
     {
         if (verboseOutput)
         {
-            Info<< "Creating curved edges" << endl;
+            Info<< "Creating block edges" << endl;
         }
 
-        ITstream& is(meshDescription.lookup("edges"));
-
-        // read number of edges in mesh
-        label nEdges = 0;
-
-        token firstToken(is);
-
-        if (firstToken.isLabel())
-        {
-            nEdges = firstToken.labelToken();
-            edges_.setSize(nEdges);
-        }
-        else
-        {
-            is.putBack(firstToken);
-        }
-
-        // Read beginning of edges
-        is.readBegin("edges");
-
-        nEdges = 0;
-
-        token lastToken(is);
-        while
+        curvedEdgeList blockEdges
         (
-           !(
-                 lastToken.isPunctuation()
-              && lastToken.pToken() == token::END_LIST
-            )
-        )
-        {
-            if (edges_.size() <= nEdges)
-            {
-                edges_.setSize(nEdges + 1);
-            }
-
-            is.putBack(lastToken);
-
-            edges_.set
-            (
-                nEdges,
-                curvedEdge::New(blockPointField_, is)
-            );
-
-            nEdges++;
-
-            is >> lastToken;
-        }
-        is.putBack(lastToken);
+            meshDescription.lookup("edges"),
+            curvedEdge::iNew(blockPointField_)
+        );
 
-        // Read end of edges
-        is.readEnd("edges");
+        edges_.transfer(blockEdges);
     }
     else if (verboseOutput)
     {
-        Info<< "No non-linear edges defined" << endl;
+        Info<< "No non-linear block edges defined" << endl;
     }
 
 
-    //
     // Create the blocks
-    //
     if (verboseOutput)
     {
         Info<< "Creating topology blocks" << endl;
@@ -422,7 +374,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
     {
         ITstream& is(meshDescription.lookup("blocks"));
 
-        // read number of blocks in mesh
+        // Read number of blocks in mesh
         label nBlocks = 0;
 
         token firstToken(is);
@@ -482,9 +434,8 @@ Foam::polyMesh* Foam::blockMesh::createTopology
 
     polyMesh* blockMeshPtr = nullptr;
 
-    //
     // Create the patches
-    //
+
     if (verboseOutput)
     {
         Info<< "Creating topology patches" << endl;
@@ -574,7 +525,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
                 IOobject::NO_WRITE,
                 false
             ),
-            xferCopy(blockPointField_),   // copy these points, do NOT move
+            xferCopy(blockPointField_),   // Copy these points, do NOT move
             tmpBlockCells,
             tmpBlocksPatches,
             patchNames,
@@ -613,7 +564,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
                 IOobject::NO_WRITE,
                 false
             ),
-            xferCopy(blockPointField_),   // copy these points, do NOT move
+            xferCopy(blockPointField_),   // Copy these points, do NOT move
             tmpBlockCells,
             tmpBlocksPatches,
             patchNames,
diff --git a/src/mesh/blockMesh/curvedEdges/curvedEdge.H b/src/mesh/blockMesh/curvedEdges/curvedEdge.H
index c46457ba3e1..0b2c007267c 100644
--- a/src/mesh/blockMesh/curvedEdges/curvedEdge.H
+++ b/src/mesh/blockMesh/curvedEdges/curvedEdge.H
@@ -123,6 +123,25 @@ public:
         //- New function which constructs and returns pointer to a curvedEdge
         static autoPtr<curvedEdge> New(const pointField&, Istream&);
 
+        //- Class used for the read-construction of
+        //  PtrLists of curvedEdge
+        class iNew
+        {
+            const pointField& points_;
+
+        public:
+
+            iNew(const pointField& points)
+            :
+                points_(points)
+            {}
+
+            autoPtr<curvedEdge> operator()(Istream& is) const
+            {
+                return curvedEdge::New(points_, is);
+            }
+        };
+
 
     //- Destructor
     virtual ~curvedEdge(){}
-- 
GitLab