From 3a374bf3157b5be27dc1f746ec31d4f87343f8de Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 7 Jan 2019 11:08:58 +0000
Subject: [PATCH] ENH: polyMesh: do not switch on auto-write. Fixes #1147.

---
 src/OpenFOAM/include/createMesh.H             |  1 +
 src/OpenFOAM/meshes/polyMesh/polyMesh.C       | 38 +++++++++----------
 src/OpenFOAM/meshes/polyMesh/polyMesh.H       |  8 +++-
 src/OpenFOAM/meshes/polyMesh/polyMeshIO.C     | 26 +++++++------
 .../singleCellFvMesh/singleCellFvMesh.C       |  6 ++-
 5 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/src/OpenFOAM/include/createMesh.H b/src/OpenFOAM/include/createMesh.H
index aab5576405d..06d07591b24 100644
--- a/src/OpenFOAM/include/createMesh.H
+++ b/src/OpenFOAM/include/createMesh.H
@@ -16,6 +16,7 @@ if (args.found("dry-run") || args.found("dry-run-write"))
     if (args.found("dry-run-write"))
     {
         // Using saWriteNow triggers function objects execute(), write()
+        meshPtr->setInstance(runTime.constant());
         runTime.stopAt(Foam::Time::saWriteNow);
     }
     else
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C
index 6db8ff11fa0..7324d8e4806 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -374,8 +374,8 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
-            IOobject::AUTO_WRITE
+            IOobject::NO_READ,
+            io.writeOpt()
         ),
         std::move(points)
     ),
@@ -387,8 +387,8 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
-            IOobject::AUTO_WRITE
+            IOobject::NO_READ,
+            io.writeOpt()
         ),
         std::move(faces)
     ),
@@ -400,8 +400,8 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
-            IOobject::AUTO_WRITE
+            IOobject::NO_READ,
+            io.writeOpt()
         ),
         std::move(owner)
     ),
@@ -413,8 +413,8 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
-            IOobject::AUTO_WRITE
+            IOobject::NO_READ,
+            io.writeOpt()
         ),
         std::move(neighbour)
     ),
@@ -427,8 +427,8 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
-            IOobject::AUTO_WRITE
+            IOobject::NO_READ,
+            io.writeOpt()
         ),
         *this,
         polyPatchList()
@@ -447,7 +447,7 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
+            IOobject::NO_READ,
             IOobject::NO_WRITE
         ),
         *this,
@@ -461,7 +461,7 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
+            IOobject::NO_READ,
             IOobject::NO_WRITE
         ),
         *this,
@@ -475,7 +475,7 @@ Foam::polyMesh::polyMesh
             instance(),
             meshSubDir,
             *this,
-            io.readOpt(),
+            IOobject::NO_READ,
             IOobject::NO_WRITE
         ),
         *this,
@@ -526,7 +526,7 @@ Foam::polyMesh::polyMesh
             meshSubDir,
             *this,
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            io.writeOpt()
         ),
         std::move(points)
     ),
@@ -539,7 +539,7 @@ Foam::polyMesh::polyMesh
             meshSubDir,
             *this,
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            io.writeOpt()
         ),
         std::move(faces)
     ),
@@ -552,7 +552,7 @@ Foam::polyMesh::polyMesh
             meshSubDir,
             *this,
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            io.writeOpt()
         ),
         0
     ),
@@ -565,7 +565,7 @@ Foam::polyMesh::polyMesh
             meshSubDir,
             *this,
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            io.writeOpt()
         ),
         0
     ),
@@ -579,7 +579,7 @@ Foam::polyMesh::polyMesh
             meshSubDir,
             *this,
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            io.writeOpt()
         ),
         *this,
         0
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H
index b442bfeb662..fbb24c527e1 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2018-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -399,7 +399,11 @@ public:
             const fileName& facesInstance() const;
 
             //- Set the instance for mesh files
-            void setInstance(const fileName&);
+            void setInstance
+            (
+                const fileName& instance,
+                const IOobject::writeOption wOpt = IOobject::AUTO_WRITE
+            );
 
 
         // Access
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C
index 9724bea7246..3ee27f95376 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -29,40 +29,44 @@ License
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-void Foam::polyMesh::setInstance(const fileName& inst)
+void Foam::polyMesh::setInstance
+(
+    const fileName& inst,
+    const IOobject::writeOption wOpt
+)
 {
     if (debug)
     {
         InfoInFunction << "Resetting file instance to " << inst << endl;
     }
 
-    points_.writeOpt() = IOobject::AUTO_WRITE;
+    points_.writeOpt() = wOpt;
     points_.instance() = inst;
 
-    faces_.writeOpt() = IOobject::AUTO_WRITE;
+    faces_.writeOpt() = wOpt;
     faces_.instance() = inst;
 
-    owner_.writeOpt() = IOobject::AUTO_WRITE;
+    owner_.writeOpt() = wOpt;
     owner_.instance() = inst;
 
-    neighbour_.writeOpt() = IOobject::AUTO_WRITE;
+    neighbour_.writeOpt() = wOpt;
     neighbour_.instance() = inst;
 
-    boundary_.writeOpt() = IOobject::AUTO_WRITE;
+    boundary_.writeOpt() = wOpt;
     boundary_.instance() = inst;
 
-    pointZones_.writeOpt() = IOobject::AUTO_WRITE;
+    pointZones_.writeOpt() = wOpt;
     pointZones_.instance() = inst;
 
-    faceZones_.writeOpt() = IOobject::AUTO_WRITE;
+    faceZones_.writeOpt() = wOpt;
     faceZones_.instance() = inst;
 
-    cellZones_.writeOpt() = IOobject::AUTO_WRITE;
+    cellZones_.writeOpt() = wOpt;
     cellZones_.instance() = inst;
 
     if (tetBasePtIsPtr_.valid())
     {
-        tetBasePtIsPtr_->writeOpt() = IOobject::AUTO_WRITE;
+        tetBasePtIsPtr_->writeOpt() = wOpt;
         tetBasePtIsPtr_->instance() = inst;
     }
 }
diff --git a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C
index eb008b47c57..cd973868f26 100644
--- a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C
+++ b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -379,6 +379,10 @@ void Foam::singleCellFvMesh::agglomerateMesh
             );
         }
     }
+
+    // Make sure we don't start dumping mesh every timestep (since
+    // resetPrimitives sets AUTO_WRITE)
+    setInstance(time().constant(), IOobject::NO_WRITE);
 }
 
 
-- 
GitLab