From 7065593b3f1b29602efbfac91a5ab558cbd9082a Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 19 Jun 2020 12:15:11 +0200
Subject: [PATCH] BUG: regression in fluxSummary cellZoneAndDirection (fixes
 #1736)

- related to change c3571b7357 (does not affect 1912 or older).

  Remnant check for data() should have used valid() method instead.

TUT: add fluxSummary cellZoneAndDirection to angledDuct/implicit
---
 .../field/fluxSummary/fluxSummary.C           | 28 ++++++++++++++-----
 .../angledDuct/implicit/system/controlDict    |  3 +-
 .../angledDuct/implicit/system/fluxSummary    | 24 ++++++++++++++++
 3 files changed, 47 insertions(+), 8 deletions(-)
 create mode 100644 tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/fluxSummary

diff --git a/src/functionObjects/field/fluxSummary/fluxSummary.C b/src/functionObjects/field/fluxSummary/fluxSummary.C
index c25cd5dd328..998fc4eeac1 100644
--- a/src/functionObjects/field/fluxSummary/fluxSummary.C
+++ b/src/functionObjects/field/fluxSummary/fluxSummary.C
@@ -519,6 +519,10 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
 
     label oldFaceID = 0;
     label regioni = 0;
+
+    // Dummy tracking data
+    bool dummyData{false};
+
     while (search)
     {
         DynamicList<label> changedEdges;
@@ -527,7 +531,7 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
         label seedFacei = labelMax;
         for (; oldFaceID < patch.size(); oldFaceID++)
         {
-            if (allFaceInfo[oldFaceID].data() == -1)
+            if (!allFaceInfo[oldFaceID].valid<bool>(dummyData))
             {
                 seedFacei = globalFaces.toGlobal(oldFaceID);
                 break;
@@ -542,21 +546,21 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
 
         if (globalFaces.isLocal(seedFacei))
         {
-            label localFacei = globalFaces.toLocal(seedFacei);
+            const label localFacei = globalFaces.toLocal(seedFacei);
             const labelList& fEdges = patch.faceEdges()[localFacei];
 
-            forAll(fEdges, i)
+            for (const label edgei : fEdges)
             {
-                if (allEdgeInfo[fEdges[i]].data() != -1)
+                if (allEdgeInfo[edgei].valid<bool>(dummyData))
                 {
                     WarningInFunction
                         << "Problem in edge face wave: attempted to assign a "
                         << "value to an edge that has already been visited. "
-                        << "Edge info: " << allEdgeInfo[fEdges[i]]
+                        << "Edge info: " << allEdgeInfo[edgei]
                         << endl;
                 }
 
-                changedEdges.append(fEdges[i]);
+                changedEdges.append(edgei);
                 changedInfo.append
                 (
                     edgeTopoDistanceData<label>
@@ -604,7 +608,17 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
     }
 
     // Collect the data per region
-    label nRegion = regioni;
+    const label nRegion = regioni;
+
+    #ifdef FULLDEBUG
+    // May wish to have enabled always
+    if (nRegion == 0)
+    {
+         FatalErrorInFunction
+            << "Region split failed" << nl
+            << exit(FatalError);
+    }
+    #endif
 
     List<DynamicList<label>> regionFaceIDs(nRegion);
     List<DynamicList<label>> regionFacePatchIDs(nRegion);
diff --git a/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/controlDict b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/controlDict
index ae43a3dba1d..1eb81c66ff5 100644
--- a/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/controlDict
+++ b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/controlDict
@@ -1,7 +1,7 @@
 /*--------------------------------*- C++ -*----------------------------------*\
 | =========                 |                                                 |
 | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  v1912                                 |
+|  \\    /   O peration     | Version:  v2006                                 |
 |   \\  /    A nd           | Website:  www.openfoam.com                      |
 |    \\/     M anipulation  |                                                 |
 \*---------------------------------------------------------------------------*/
@@ -50,6 +50,7 @@ runTimeModifiable true;
 functions
 {
     #include "sampling"
+    #include "fluxSummary"
 }
 
 
diff --git a/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/fluxSummary b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/fluxSummary
new file mode 100644
index 00000000000..5915a5050ea
--- /dev/null
+++ b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/fluxSummary
@@ -0,0 +1,24 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| =========                 |                                                 |
+| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
+|  \\    /   O peration     | Version:  v2006                                 |
+|   \\  /    A nd           | Website:  www.openfoam.com                      |
+|    \\/     M anipulation  |                                                 |
+\*---------------------------------------------------------------------------*/
+
+fluxSummary
+{
+    type    fluxSummary;
+    libs    (fieldFunctionObjects);
+
+    scaleFactor     1.205;
+    write           yes;
+    log             yes;
+    mode            cellZoneAndDirection;
+    cellZoneAndDirection
+    (
+        (porosity (1 1 0))
+    );
+}
+
+// ************************************************************************* //
-- 
GitLab