From cc1e03a81fc64e44f21ccdb289088ef22d76da12 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Fri, 22 Feb 2013 17:14:21 +0000
Subject: [PATCH] ENH: lduMatrix: added I/O

---
 .../matrices/lduMatrix/lduMatrix/lduMatrix.C  | 118 ++++++++++++++----
 .../matrices/lduMatrix/lduMatrix/lduMatrix.H  |  14 ++-
 2 files changed, 108 insertions(+), 24 deletions(-)

diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C
index 1e4e5b8c42d..69a01236c13 100644
--- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C
+++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -25,6 +25,7 @@ License
 
 #include "lduMatrix.H"
 #include "IOstreams.H"
+#include "Switch.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -116,17 +117,27 @@ Foam::lduMatrix::lduMatrix(lduMatrix& A, bool reUse)
 }
 
 
-Foam::lduMatrix::lduMatrix
-(
-    const lduMesh& mesh,
-    Istream& is
-)
+Foam::lduMatrix::lduMatrix(const lduMesh& mesh, Istream& is)
 :
-    lduMesh_(mesh),
-    lowerPtr_(new scalarField(is)),
-    diagPtr_(new scalarField(is)),
-    upperPtr_(new scalarField(is))
-{}
+    lduMesh_(mesh)
+{
+    Switch hasLow(is);
+    Switch hasDiag(is);
+    Switch hasUp(is);
+
+    if (hasLow)
+    {
+        lowerPtr_ = new scalarField(is);
+    }
+    if (hasDiag)
+    {
+        diagPtr_ = new scalarField(is);
+    }
+    if (hasUp)
+    {
+        upperPtr_ = new scalarField(is);
+    }
+}
 
 
 Foam::lduMatrix::~lduMatrix()
@@ -252,25 +263,86 @@ const Foam::scalarField& Foam::lduMatrix::upper() const
 
 Foam::Ostream& Foam::operator<<(Ostream& os, const lduMatrix& ldum)
 {
-    if (ldum.lowerPtr_)
+    Switch hasLow = ldum.hasLower();
+    Switch hasDiag = ldum.hasDiag();
+    Switch hasUp = ldum.hasUpper();
+
+    os  << hasLow << token::SPACE << hasDiag << token::SPACE
+        << hasUp << token::SPACE;
+
+    if (hasLow)
+    {
+        os  << ldum.lower();
+    }
+
+    if (hasDiag)
     {
-        os  << "Lower triangle = "
-            << *ldum.lowerPtr_
-            << endl << endl;
+        os  << ldum.diag();
     }
 
-    if (ldum.diagPtr_)
+    if (hasUp)
+    {
+        os  << ldum.upper();
+    }
+
+    os.check("Ostream& operator<<(Ostream&, const lduMatrix&");
+
+    return os;
+}
+
+
+Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<lduMatrix>& ip)
+{
+    const lduMatrix& ldum = ip.t_;
+
+    Switch hasLow = ldum.hasLower();
+    Switch hasDiag = ldum.hasDiag();
+    Switch hasUp = ldum.hasUpper();
+
+    os  << "Lower:" << hasLow
+        << " Diag:" << hasDiag
+        << " Upper:" << hasUp << endl;
+
+    if (hasLow)
+    {
+        os  << "lower:" << ldum.lower().size() << endl;
+    }
+    if (hasDiag)
+    {
+        os  << "diag :" << ldum.diag().size() << endl;
+    }
+    if (hasUp)
     {
-        os  << "diagonal = "
-            << *ldum.diagPtr_
-            << endl << endl;
+        os  << "upper:" << ldum.upper().size() << endl;
     }
 
-    if (ldum.upperPtr_)
+
+    if (hasLow)
+    {
+        os  << "lower contents:" << endl;
+        forAll(ldum.lower(), i)
+        {
+            os  << "i:" << i << "\t" << ldum.lower()[i] << endl;
+        }
+        os  << endl;
+    }
+    if (hasDiag)
     {
-        os  << "Upper triangle = "
-            << *ldum.upperPtr_
-            << endl << endl;
+        os  << "diag contents:" << endl;
+        forAll(ldum.diag(), i)
+        {
+            os  << "i:" << i << "\t" << ldum.diag()[i] << endl;
+        }
+        os  << endl;
+    }
+    if (hasUp)
+    {
+        os  << "upper contents:" << endl;
+        forAll(ldum.upper(), i)
+        {
+            os  << "i:" << i << "\t" << ldum.upper()[i] << endl;
+        }
+        os  << endl;
     }
 
     os.check("Ostream& operator<<(Ostream&, const lduMatrix&");
diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H
index ec5d7a89d5d..320f9d4c85d 100644
--- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H
+++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -58,6 +58,7 @@ SourceFiles
 #include "autoPtr.H"
 #include "runTimeSelectionTables.H"
 #include "solverPerformance.H"
+#include "InfoProxy.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -691,6 +692,16 @@ public:
             tmp<Field<Type> > faceH(const tmp<Field<Type> >&) const;
 
 
+        // Info
+
+            //- Return info proxy.
+            //  Used to print matrix information to a stream
+            InfoProxy<lduMatrix> info() const
+            {
+                return *this;
+            }
+
+
     // Member operators
 
         void operator=(const lduMatrix&);
@@ -707,6 +718,7 @@ public:
     // Ostream operator
 
         friend Ostream& operator<<(Ostream&, const lduMatrix&);
+        friend Ostream& operator<<(Ostream&, const InfoProxy<lduMatrix>&);
 };
 
 
-- 
GitLab