From 05e733ce3a0149953aed1a10fa3d428eb58ae8e0 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Wed, 27 Aug 2008 18:01:17 +0100
Subject: [PATCH] extra checks

---
 .../parMetisDecomp/parMetisDecomp.C           | 47 +++++++++++++++++--
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/decompositionAgglomeration/parMetisDecomp/parMetisDecomp.C b/src/decompositionAgglomeration/parMetisDecomp/parMetisDecomp.C
index a5778bcdf05..8b3092f08f6 100644
--- a/src/decompositionAgglomeration/parMetisDecomp/parMetisDecomp.C
+++ b/src/decompositionAgglomeration/parMetisDecomp/parMetisDecomp.C
@@ -41,8 +41,7 @@ extern "C"
 #   include "parmetis.h"
 }
 
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 namespace Foam
 {
@@ -57,6 +56,8 @@ namespace Foam
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
 //- Does prevention of 0 cell domains and calls parmetis.
 Foam::label Foam::parMetisDecomp::decompose
 (
@@ -76,6 +77,16 @@ Foam::label Foam::parMetisDecomp::decompose
     // Number of dimensions
     int nDims = 3;
 
+
+    if (cellCentres.size() != xadj.size()-1)
+    {
+        FatalErrorIn("parMetisDecomp::decompose(..)")
+            << "cellCentres:" << cellCentres.size()
+            << " xadj:" << xadj.size()
+            << abort(FatalError);
+    }
+
+
     // Get number of cells on all processors
     List<int> nLocalCells(Pstream::nProcs());
     nLocalCells[Pstream::myProcNo()] = xadj.size()-1;
@@ -106,12 +117,12 @@ Foam::label Foam::parMetisDecomp::decompose
     // Make sure every domain has at least one cell
     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     // (Metis falls over with zero sized domains)
-    // Trickle cells from processors that have them down to those that
+    // Trickle cells from processors that have them up to those that
     // don't.
 
 
-    // Number of cells to send down (is same as number of cells next processor
-    // has to receive)
+    // Number of cells to send to the next processor
+    // (is same as number of cells next processor has to receive)
     List<int> nSendCells(Pstream::nProcs(), 0);
 
     for (label procI = nLocalCells.size()-1; procI >=1; procI--)
@@ -135,6 +146,15 @@ Foam::label Foam::parMetisDecomp::decompose
         Field<int> prevCellWeights(fromPrevProc);
         Field<int> prevFaceWeights(fromPrevProc);
 
+        if (prevXadj.size() != nSendCells[Pstream::myProcNo()-1])
+        {
+            FatalErrorIn("parMetisDecomp::decompose(..)")
+                << "Expected from processor " << Pstream::myProcNo()-1
+                << " connectivity for " << nSendCells[Pstream::myProcNo()-1]
+                << " nCells but only received " << prevXadj.size()
+                << abort(FatalError);
+        }
+
         // Insert adjncy
         prepend(prevAdjncy, adjncy);
         // Adapt offsets and prepend xadj
@@ -222,6 +242,14 @@ Foam::label Foam::parMetisDecomp::decompose
     }
 
 
+    if (nLocalCells[Pstream::myProcNo()] != (xadj.size()-1))
+    {
+        FatalErrorIn("parMetisDecomp::decompose(..)")
+            << "Have connectivity for " << xadj.size()-1
+            << " cells but nLocalCells:" << nLocalCells[Pstream::myProcNo()]
+            << abort(FatalError);
+    }
+
     // Weight info
     int wgtFlag = 0;
     int* vwgtPtr = NULL;
@@ -292,6 +320,15 @@ Foam::label Foam::parMetisDecomp::decompose
 
         List<int> nextFinalDecomp(fromNextProc);
 
+        if (nextFinalDecomp.size() != nSendCells[Pstream::myProcNo()])
+        {
+            FatalErrorIn("parMetisDecomp::decompose(..)")
+                << "Expected from processor " << Pstream::myProcNo()+1
+                << " decomposition for " << nSendCells[Pstream::myProcNo()]
+                << " nCells but only received " << nextFinalDecomp.size()
+                << abort(FatalError);
+        }
+
         append(nextFinalDecomp, finalDecomp);
     }
 
-- 
GitLab