From f71567a71dba3310d0257279edab6d2a8f8e3083 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Fri, 17 Feb 2012 12:45:10 +0000
Subject: [PATCH] fvMatrix: Improved the relaxation of the matrix in the case
 that the diagonal is initially negative

---
 src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C
index fd78acb546c..f9937b532cd 100644
--- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C
+++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -596,7 +596,7 @@ void Foam::fvMatrix<Type>::relax(const scalar alpha)
         scalar sumNon = 0.0;
         forAll(D, celli)
         {
-            scalar d = (sumOff[celli] - D[celli])/D[celli];
+            scalar d = (sumOff[celli] - D[celli])/mag(D[celli]);
 
             if (d > 0)
             {
@@ -621,8 +621,11 @@ void Foam::fvMatrix<Type>::relax(const scalar alpha)
 
 
     // Ensure the matrix is diagonally dominant...
-    // (assumes that the central coefficient is positive)
-    max(D, D, sumOff);
+    // Assumes that the central coefficient is positive and ensures it is
+    forAll(D, celli)
+    {
+        D[celli] = max(mag(D[celli]), sumOff[celli]);
+    }
 
     // ... then relax
     D /= alpha;
-- 
GitLab