From 430895eea54de7c652e01da5655e096cc6751921 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 25 Oct 2017 16:22:59 +0100
Subject: [PATCH] ENH: snappyHexMesh: allow restart through suppression of
 refinement. Fixes #626.

---
 .../snappyHexMesh/snappyHexMeshDict           |  7 ++-
 .../snappyHexMeshDriver/snappyRefineDriver.C  | 58 ++++++++++++++++++-
 2 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict
index bf257a8ff5..46d570e206 100644
--- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict
+++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict
@@ -101,8 +101,11 @@ castellatedMeshControls
 
     // The surface refinement loop might spend lots of iterations refining just
     // a few cells. This setting will cause refinement to stop if
-    // <= minimumRefine cells are selected for refinement. Note: it will
-    // at least do one iteration (unless the number of cells to refine is 0)
+    // <= minRefinementCells cells are selected for refinement. Note: it will
+    // at least do one iteration unless
+    //  a: the number of cells to refine is 0
+    //  b: minRefinementCells = -1. This is a special value indicating
+    //     no refinement.
     minRefinementCells 0;
 
     // Allow a certain level of imbalance during refining
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
index 1040094bb1..956fb4366f 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -80,6 +80,13 @@ Foam::label Foam::snappyRefineDriver::featureEdgeRefine
     const label minRefine
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(edge, "snappyHexMesh::refine::edge");
     const fvMesh& mesh = meshRefiner_.mesh();
 
@@ -190,6 +197,13 @@ Foam::label Foam::snappyRefineDriver::smallFeatureRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(feature, "snappyHexMesh::refine::smallFeature");
     const fvMesh& mesh = meshRefiner_.mesh();
 
@@ -313,6 +327,13 @@ Foam::label Foam::snappyRefineDriver::surfaceOnlyRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(surface, "snappyHexMesh::refine::surface");
     const fvMesh& mesh = meshRefiner_.mesh();
 
@@ -437,6 +458,13 @@ Foam::label Foam::snappyRefineDriver::gapOnlyRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     const fvMesh& mesh = meshRefiner_.mesh();
 
     // Determine the maximum refinement level over all surfaces. This
@@ -669,6 +697,13 @@ Foam::label Foam::snappyRefineDriver::bigGapOnlyRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     const fvMesh& mesh = meshRefiner_.mesh();
 
     label iter = 0;
@@ -811,6 +846,13 @@ Foam::label Foam::snappyRefineDriver::danglingCellRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(dangling, "snappyHexMesh::refine::danglingCell");
     const fvMesh& mesh = meshRefiner_.mesh();
 
@@ -957,6 +999,13 @@ Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(interface, "snappyHexMesh::refine::transition");
     const fvMesh& mesh = meshRefiner_.mesh();
 
@@ -1348,6 +1397,13 @@ Foam::label Foam::snappyRefineDriver::shellRefine
     const label maxIter
 )
 {
+    if (refineParams.minRefineCells() == -1)
+    {
+        // Special setting to be able to restart shm on meshes with inconsistent
+        // cellLevel/pointLevel
+        return 0;
+    }
+
     addProfiling(shell, "snappyHexMesh::refine::shell");
     const fvMesh& mesh = meshRefiner_.mesh();
 
-- 
GitLab