From 72e8f44a5a8af1681678b6c36b8d760e35287de2 Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Mon, 20 May 2013 12:44:31 +0200
Subject: [PATCH] Fixing tnlCSRMatrix.

---
 src/implementation/mesh/tnlGrid2D_impl.h | 11 ++++++-----
 src/matrix/tnlCSRMatrix.h                |  4 +++-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/implementation/mesh/tnlGrid2D_impl.h b/src/implementation/mesh/tnlGrid2D_impl.h
index 760c113d7b..0879688ebc 100644
--- a/src/implementation/mesh/tnlGrid2D_impl.h
+++ b/src/implementation/mesh/tnlGrid2D_impl.h
@@ -201,7 +201,8 @@ Index tnlGrid< 2, Real, Device, Index, Geometry > :: getEdgeIndex( const Index i
    tnlAssert( dx == 0 && ( dy == 1 || dy == -1 ) ||
               dy == 0 && ( dx == 1 || dx == -1 ),
               cerr << "dx = " << dx << ", dy = " << dy << endl;);
-   return ( j + dy ) * this -> dimensions. x() + i + dx;
+   return ( j + 1 + dy ) * ( 2 * this -> dimensions. x() + 1 ) + i + dx;
+   //return j * ( 2 * this -> dimensions. x() + 1 ) + ( dy + 1 )
 }
 
 
@@ -221,13 +222,13 @@ void tnlGrid< 2, Real, Device, Index, Geometry > :: refresh()
       for( IndexType j = 1; j < dimensions. y() - 1; j ++ )
          for( IndexType i = 1; i < dimensions. x() - 1; i ++ )
          {
-            dualElementsMeasure[ getElementIndex( i + 1, j ) ] =
+            dualElementsMeasure[ getEdgeIndex( i, j,  1, 0 ) ] =
                      geometry. getDualElementMeasure<  1,  0 >( CoordinatesType( i, j ) );
-            dualElementsMeasure[ getElementIndex( i - 1, j ) ] =
+            dualElementsMeasure[ getEdgeIndex( i, j, -1, 0 ) ] =
                      geometry. getDualElementMeasure< -1,  0 >( CoordinatesType( i, j ) );
-            dualElementsMeasure[ getElementIndex( i, j + 1 ) ] =
+            dualElementsMeasure[ getEdgeIndex( i, j,  0,  1 ) ] =
                      geometry. getDualElementMeasure<  0,  1 >( CoordinatesType( i, j ) );
-            dualElementsMeasure[ getElementIndex( i, j - 1 ) ] =
+            dualElementsMeasure[ getEdgeIndex( i, j,  0, -1 ) ] =
                      geometry. getDualElementMeasure<  0, -1 >( CoordinatesType( i, j ) );
          }
 
diff --git a/src/matrix/tnlCSRMatrix.h b/src/matrix/tnlCSRMatrix.h
index 974fa7f0f9..bf694991b3 100644
--- a/src/matrix/tnlCSRMatrix.h
+++ b/src/matrix/tnlCSRMatrix.h
@@ -226,6 +226,8 @@ class tnlCSRMatrix : public tnlMatrix< Real, Device, Index >
     */
    bool backwardSpMV;
 
+   template< typename, typename, typename >
+      friend class tnlCSRMatrix;
    friend class tnlMatrix< Real, tnlHost, Index >;
    friend class tnlMatrix< Real, tnlCuda, Index >;
    friend class tnlCusparseCSRMatrix< Real, tnlCuda, Index >;
@@ -662,7 +664,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: performSORIteration( const Real& ome
          cerr << "There is zero on the diagonal in " << i << "-th row. I cannot perform SOR iteration." << endl;
          return false;
       }
-      x[ i ] = ( 1.0 - omega ) * x[ i ] + omega / diagonal * update;
+      x[ i ] = ( ( Real ) 1.0 - omega ) * x[ i ] + omega / diagonal * update;
    }
    return true;
 }
-- 
GitLab