From 003a6ee0a945c72ff627d8e3055a2fca716567fa Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 19 Jan 2018 15:41:26 +0100
Subject: [PATCH] ENH: added -decomposeParDict support for preparePar (fixes
 #4)

---
 tutorials/pMesh/bunnyPoly/Allrun-parallel     | 19 +++++
 .../pMesh/bunnyPoly/system/decomposeParDict.6 | 20 ++++++
 .../importSurfaceAsSubset.C                   |  4 +-
 utilities/preparePar/Make/options             | 11 +--
 utilities/preparePar/preparePar.C             | 71 ++++++++++++-------
 utilities/scaleSurfaceMesh/scaleSurfaceMesh.C |  1 -
 .../surfaceFeatureEdges/surfaceFeatureEdges.C |  3 -
 7 files changed, 87 insertions(+), 42 deletions(-)
 create mode 100755 tutorials/pMesh/bunnyPoly/Allrun-parallel
 create mode 100644 tutorials/pMesh/bunnyPoly/system/decomposeParDict.6

diff --git a/tutorials/pMesh/bunnyPoly/Allrun-parallel b/tutorials/pMesh/bunnyPoly/Allrun-parallel
new file mode 100755
index 00000000..25349171
--- /dev/null
+++ b/tutorials/pMesh/bunnyPoly/Allrun-parallel
@@ -0,0 +1,19 @@
+#!/bin/sh
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/bin/tools/RunFunctions    # Tutorial run functions
+
+decompDict="-decomposeParDict system/decomposeParDict.6"
+runApplication $decompDict preparePar
+
+# An ugly way to make things available
+for dir in processor*
+do
+    (cd $dir 2> /dev/null && ln -sf ../bunnyWrapped.stl .)
+done
+
+echo "WARNING WARNING: this seems to have problems in parallel"
+
+runParallel $decompDict pMesh
+runParallel $decompDict checkMesh
+
+#------------------------------------------------------------------------------
diff --git a/tutorials/pMesh/bunnyPoly/system/decomposeParDict.6 b/tutorials/pMesh/bunnyPoly/system/decomposeParDict.6
new file mode 100644
index 00000000..d30cfdd8
--- /dev/null
+++ b/tutorials/pMesh/bunnyPoly/system/decomposeParDict.6
@@ -0,0 +1,20 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| =========                 |                                                 |
+| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
+|  \\    /   O peration     | Version:  -                                     |
+|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
+|    \\/     M anipulation  |                                                 |
+\*---------------------------------------------------------------------------*/
+FoamFile
+{
+    version     2.0;
+    format      ascii;
+    class       dictionary;
+    object      decomposeParDict;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+numberOfSubdomains  6;
+
+// ************************************************************************* //
diff --git a/utilities/importSurfaceAsSubset/importSurfaceAsSubset.C b/utilities/importSurfaceAsSubset/importSurfaceAsSubset.C
index a59d2dea..9c351410 100644
--- a/utilities/importSurfaceAsSubset/importSurfaceAsSubset.C
+++ b/utilities/importSurfaceAsSubset/importSurfaceAsSubset.C
@@ -34,8 +34,6 @@ Description
 #include "OSspecific.H"
 #include "demandDrivenData.H"
 #include "triSurfaceImportSurfaceAsSubset.H"
-#include <cstdlib>
-#include <sstream>
 
 using namespace Foam;
 using namespace Foam::Module;
@@ -70,7 +68,7 @@ int main(int argc, char *argv[])
     {
         fileName newName = inFileName.lessExt();
         newName.append(".fms");
-        Warning << "Writting surface as " << newName
+        Warning << "Writing surface as " << newName
             << " to preserve the subset!!" << endl;
 
         originalSurface.writeSurface(newName);
diff --git a/utilities/preparePar/Make/options b/utilities/preparePar/Make/options
index 267dbcc3..b6388847 100644
--- a/utilities/preparePar/Make/options
+++ b/utilities/preparePar/Make/options
@@ -1,11 +1,6 @@
 EXE_INC = \
-    -I$(LIB_SRC)/fileFormats/lnInclude \
-    -I$(LIB_SRC)/surfMesh/lnInclude \
-    -I$(LIB_SRC)/meshTools/lnInclude \
-    -I$(LIB_SRC)/finiteVolume/lnInclude \
-    -I../../meshLibrary/lnInclude
+    -I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \
+    -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude
 
 EXE_LIBS = \
-    -lfiniteVolume -lmeshTools \
-    -L$(FOAM_LIBBIN) \
-    -lmeshLibrary
+    -ldecompose
diff --git a/utilities/preparePar/preparePar.C b/utilities/preparePar/preparePar.C
index 72f3267a..30dd92ad 100644
--- a/utilities/preparePar/preparePar.C
+++ b/utilities/preparePar/preparePar.C
@@ -30,68 +30,85 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "polyMeshGen.H"
-
-#include <sstream>
+#include "Time.H"
+#include "decompositionModel.H"
 
 using namespace Foam;
-using namespace Foam::Module;
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 int main(int argc, char *argv[])
 {
+    argList::addNote
+    (
+        "Create processor directories in preparation for a parallel run"
+    );
+
+    argList::noParallel();
+    argList::addOption
+    (
+        "decomposeParDict",
+        "file",
+        "read decomposePar dictionary from specified location"
+    );
+
     #include "setRootCase.H"
     #include "createTime.H"
 
+    // Allow override of decomposeParDict location
+    fileName decompDictFile;
+    args.readIfPresent("decomposeParDict", decompDictFile);
+
     IOdictionary meshDict
     (
         IOobject
         (
             "meshDict",
-            runTime.system(),
+            runTime.time().system(),
             runTime,
             IOobject::MUST_READ,
             IOobject::NO_WRITE
         )
     );
 
-    IOdictionary decomposeParDict
+    // Get requested numberOfSubdomains directly from the dictionary.
+    // Note: have no mesh yet so cannot use decompositionModel::New
+    const label nDomains = decompositionMethod::nDomains
     (
-        IOobject
+        IOdictionary
         (
-            "decomposeParDict",
-            runTime.system(),
-            runTime,
-            IOobject::MUST_READ,
-            IOobject::NO_WRITE
+            decompositionModel::selectIO
+            (
+                IOobject
+                (
+                    "decomposeParDict",
+                    runTime.time().system(),
+                    runTime,
+                    IOobject::MUST_READ,
+                    IOobject::NO_WRITE,
+                    false
+                ),
+                decompDictFile
+            )
         )
     );
 
-    const label nProcessors
-    (
-        readLabel(decomposeParDict.lookup("numberOfSubdomains"))
-    );
-
-    for (label procI = 0; procI < nProcessors; ++procI)
+    for (label proci = 0; proci < nDomains; ++proci)
     {
-        fileName file("processor");
-        std::ostringstream ss;
-        ss << procI;
-        file += ss.str();
-        Info<< "Creating " << file << endl;
+        fileName dir("processor" + Foam::name(proci));
+        Info<< "Creating " << dir << endl;
 
         // create a directory for processor data
-        mkDir(runTime.path()/file);
+        mkDir(runTime.path()/dir);
 
         // copy the contents of the const directory into processor*
-        cp(runTime.path()/"constant", runTime.path()/file);
+        cp(runTime.path()/"constant", runTime.path()/dir);
 
         // generate 0 directories for
-        mkDir(runTime.path()/file/"0");
+        mkDir(runTime.path()/dir/"0");
     }
 
-    Info<< "End\n" << endl;
+    Info<< "\nEnd\n" << endl;
     return 0;
 }
 
diff --git a/utilities/scaleSurfaceMesh/scaleSurfaceMesh.C b/utilities/scaleSurfaceMesh/scaleSurfaceMesh.C
index 94193791..6248249e 100644
--- a/utilities/scaleSurfaceMesh/scaleSurfaceMesh.C
+++ b/utilities/scaleSurfaceMesh/scaleSurfaceMesh.C
@@ -31,7 +31,6 @@ Description
 #include "fileName.H"
 #include "triSurf.H"
 #include "triSurfModifier.H"
-#include <sstream>
 
 using namespace Foam;
 using namespace Foam::Module;
diff --git a/utilities/surfaceFeatureEdges/surfaceFeatureEdges.C b/utilities/surfaceFeatureEdges/surfaceFeatureEdges.C
index 980cb8f5..c422b4be 100644
--- a/utilities/surfaceFeatureEdges/surfaceFeatureEdges.C
+++ b/utilities/surfaceFeatureEdges/surfaceFeatureEdges.C
@@ -33,9 +33,6 @@ Description
 #include "OFstream.H"
 #include "OSspecific.H"
 #include "demandDrivenData.H"
-#include <cstdlib>
-#include <sstream>
-
 #include "triSurfaceDetectFeatureEdges.H"
 #include "triSurfacePatchManipulator.H"
 
-- 
GitLab