From 5f7d4e4502696fb639d11e991701510b7b393568 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Mon, 4 May 2015 16:38:03 +0100
Subject: [PATCH] refineMesh: Improved command-line argument handling to be
 more consistent with other OpenFOAM utilities

    Command-line option handling:
    + If -all specified or no refineMeshDict exists or, refine all cells
    + If -dict <file> specified refine according to <file>
    + If refineMeshDict exists refine according to refineMeshDict

    When the refinement or all cells is selected apply 3D refinement for 3D
    cases and 2D refinement for 2D cases.
---
 .../mesh/manipulation/refineMesh/refineMesh.C | 68 +++++++++++++++++--
 1 file changed, 61 insertions(+), 7 deletions(-)

diff --git a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C
index 065cfafb8ad..3714b3a7125 100644
--- a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C
+++ b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C
@@ -27,10 +27,13 @@ Application
 Description
     Utility to refine cells in multiple directions.
 
-    Either supply -all option to refine all cells (3D refinement for 3D
-    cases; 2D for 2D cases) or reads a refineMeshDict with
-    - cellSet to refine
-    - directions to refine
+    Command-line option handling:
+    + If -all specified or no refineMeshDict exists or, refine all cells
+    + If -dict <file> specified refine according to <file>
+    + If refineMeshDict exists refine according to refineMeshDict
+
+    When the refinement or all cells is selected apply 3D refinement for 3D
+    cases and 2D refinement for 2D cases.
 
 \*---------------------------------------------------------------------------*/
 
@@ -139,6 +142,13 @@ int main(int argc, char *argv[])
     #include "addOverwriteOption.H"
     #include "addRegionOption.H"
     #include "addDictOption.H"
+
+    Foam::argList::addBoolOption
+    (
+        "all",
+        "Refine all cells"
+    );
+
     #include "setRootCase.H"
     #include "createTime.H"
     runTime.functionObjects().off();
@@ -152,6 +162,7 @@ int main(int argc, char *argv[])
     //
 
     const bool readDict = args.optionFound("dict");
+    const bool refineAllCells = args.optionFound("all");
     const bool overwrite = args.optionFound("overwrite");
 
     // List of cells to refine
@@ -159,16 +170,59 @@ int main(int argc, char *argv[])
 
     // Dictionary to control refinement
     dictionary refineDict;
+    const word dictName("refineMeshDict");
 
     if (readDict)
     {
-        const word dictName("refineMeshDict");
-        #include "setSystemMeshDictionaryIO.H"
+        fileName dictPath = args["dict"];
+        if (isDir(dictPath))
+        {
+            dictPath = dictPath/dictName;
+        }
+
+        IOobject dictIO
+        (
+            dictPath,
+            mesh,
+            IOobject::MUST_READ
+        );
+
+        if (!dictIO.headerOk())
+        {
+            FatalErrorIn(args.executable())
+                << "Cannot open specified refinement dictionary "
+                << dictPath
+                << exit(FatalError);
+        }
 
-        Info<< "Refining according to " << dictName << nl << endl;
+        Info<< "Refining according to " << dictPath << nl << endl;
 
         refineDict = IOdictionary(dictIO);
+    }
+    else if (!refineAllCells)
+    {
+        IOobject dictIO
+        (
+            dictName,
+            runTime.system(),
+            mesh,
+            IOobject::MUST_READ
+        );
 
+        if (dictIO.headerOk())
+        {
+            Info<< "Refining according to " << dictName << nl << endl;
+
+            refineDict = IOdictionary(dictIO);
+        }
+        else
+        {
+            Info<< "Refinement dictionary " << dictName << " not found" << endl;
+        }
+    }
+
+    if (refineDict.size())
+    {
         const word setName(refineDict.lookup("set"));
 
         cellSet cells(mesh, setName);
-- 
GitLab