From 5ad239d7ec1d43e0c670b5a36ab694df6d62058b Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Tue, 24 Jan 2017 16:44:43 +0000 Subject: [PATCH] Bugfix: simple matrix operations --- .../matrices/lduMatrix/lduMatrix/lduMatrix.H | 31 ++++++++++--------- .../lduMatrix/lduMatrix/lduMatrixOperations.C | 12 +++++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/foam/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/foam/matrices/lduMatrix/lduMatrix/lduMatrix.H index d50fc6bf4..09c9805c7 100644 --- a/src/foam/matrices/lduMatrix/lduMatrix/lduMatrix.H +++ b/src/foam/matrices/lduMatrix/lduMatrix/lduMatrix.H @@ -258,10 +258,9 @@ public: ); - // Destructor - - virtual ~solver() - {} + //- Destructor + virtual ~solver() + {} // Member functions @@ -418,10 +417,9 @@ public: ); - // Destructor - - virtual ~smoother() - {} + //- Destructor + virtual ~smoother() + {} // Member functions @@ -556,10 +554,9 @@ public: ); - // Destructor - - virtual ~preconditioner() - {} + //- Destructor + virtual ~preconditioner() + {} // Member functions @@ -635,9 +632,8 @@ public: } - // Destructor - - virtual ~lduMatrix(); + //- Destructor + virtual ~lduMatrix(); // Member functions @@ -700,6 +696,11 @@ public: return (lowerPtr_); } + bool empty() const + { + return (!diagPtr_ && !lowerPtr_ && !upperPtr_); + } + bool diagonal() const { return (diagPtr_ && !lowerPtr_ && !upperPtr_); diff --git a/src/foam/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C b/src/foam/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C index a523b6198..6497d8374 100644 --- a/src/foam/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C +++ b/src/foam/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C @@ -143,6 +143,12 @@ void Foam::lduMatrix::negate() void Foam::lduMatrix::operator+=(const lduMatrix& A) { + // Escape empty matrix + if (A.empty()) + { + return; + } + if (A.diagPtr_) { diag() += A.diag(); @@ -211,6 +217,12 @@ void Foam::lduMatrix::operator+=(const lduMatrix& A) void Foam::lduMatrix::operator-=(const lduMatrix& A) { + // Escape empty matrix + if (A.empty()) + { + return; + } + if (A.diagPtr_) { diag() -= A.diag();