From d48da0cfacf2402f6c568bdee82b4f430750aecd Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 20 Dec 2011 09:36:53 +0000
Subject: [PATCH] ENH: GaussSeidelSmoother: avoid memory allocation - use
 in-place negation

---
 .../GaussSeidel/GaussSeidelSmoother.C         | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/OpenFOAM/matrices/lduMatrix/smoothers/GaussSeidel/GaussSeidelSmoother.C b/src/OpenFOAM/matrices/lduMatrix/smoothers/GaussSeidel/GaussSeidelSmoother.C
index 842771aed6d..b0cb88ed6eb 100644
--- a/src/OpenFOAM/matrices/lduMatrix/smoothers/GaussSeidel/GaussSeidelSmoother.C
+++ b/src/OpenFOAM/matrices/lduMatrix/smoothers/GaussSeidel/GaussSeidelSmoother.C
@@ -107,16 +107,29 @@ void Foam::GaussSeidelSmoother::smooth
     // To compensate for this, it is necessary to turn the
     // sign of the contribution.
 
-    FieldField<Field, scalar> mBouCoeffs(interfaceBouCoeffs_.size());
-
+    //FieldField<Field, scalar> mBouCoeffs(interfaceBouCoeffs_.size());
+    //
+    //forAll(mBouCoeffs, patchi)
+    //{
+    //    if (interfaces_.set(patchi))
+    //    {
+    //        mBouCoeffs.set(patchi, -interfaceBouCoeffs_[patchi]);
+    //    }
+    //}
+    FieldField<Field, scalar>& mBouCoeffs =
+        const_cast<FieldField<Field, scalar>&>
+        (
+            interfaceBouCoeffs_
+        );
     forAll(mBouCoeffs, patchi)
     {
         if (interfaces_.set(patchi))
         {
-            mBouCoeffs.set(patchi, -interfaceBouCoeffs_[patchi]);
+            mBouCoeffs[patchi].negate();
         }
     }
 
+
     for (label sweep=0; sweep<nSweeps; sweep++)
     {
         bPrime = source;
@@ -170,6 +183,15 @@ void Foam::GaussSeidelSmoother::smooth
             psiPtr[cellI] = curPsi;
         }
     }
+
+    // Restore interfaceBouCoeffs_
+    forAll(mBouCoeffs, patchi)
+    {
+        if (interfaces_.set(patchi))
+        {
+            mBouCoeffs[patchi].negate();
+        }
+    }
 }
 
 
-- 
GitLab