From 3f5fab8ef1140dee7ede533d231d7720a7003b51 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Fri, 29 Jun 2012 12:49:59 +0000
Subject: [PATCH] Added possibility to analyze matrices from FETI-DP.

---
 AMDiS/src/parallel/PetscSolverFeti.cc | 39 +++++++++++++++++++++++++++
 AMDiS/src/parallel/PetscSolverFeti.h  |  4 +++
 2 files changed, 43 insertions(+)

diff --git a/AMDiS/src/parallel/PetscSolverFeti.cc b/AMDiS/src/parallel/PetscSolverFeti.cc
index 85461d15..7dbacfb1 100644
--- a/AMDiS/src/parallel/PetscSolverFeti.cc
+++ b/AMDiS/src/parallel/PetscSolverFeti.cc
@@ -1099,6 +1099,40 @@ namespace AMDiS {
   }
 
 
+  void PetscSolverFeti::dbgMatrix()
+  {
+    FUNCNAME("PetscSolverFeti::dbgMatrix()");
+
+#if (DEBUG != 0)
+    int writeInteriorMatrix = -1;
+    Parameters::get("parallel->debug->write interior matrix", 
+		    writeInteriorMatrix);
+
+    if (writeInteriorMatrix >= 0 &&
+	writeInteriorMatrix == MPI::COMM_WORLD.Get_rank()) {
+      PetscViewer petscView;
+      PetscViewerBinaryOpen(PETSC_COMM_SELF, "interior.mat", 
+			    FILE_MODE_WRITE, &petscView);
+      MatView(subdomain->getMatIntInt(), petscView);
+      PetscViewerDestroy(&petscView);
+    }
+
+
+    int writeCoarseMatrix = 0;
+    Parameters::get("parallel->debug->write coarse matrix", 
+		    writeCoarseMatrix);
+    
+    if (writeCoarseMatrix > 0) {
+      PetscViewer petscView;
+      PetscViewerBinaryOpen(PETSC_COMM_WORLD, "coarse.mat", 
+			    FILE_MODE_WRITE, &petscView);
+      MatView(subdomain->getMatCoarseCoarse(), petscView);
+      PetscViewerDestroy(&petscView);
+    }
+#endif
+  }
+
+
   void PetscSolverFeti::recoverSolution(Vec &vec_sol_b,
 					Vec &vec_sol_primal,
 					SystemVector &vec)
@@ -1412,6 +1446,11 @@ namespace AMDiS {
     // === Create PETSc solver for the FETI-DP operator. ===
 
     createFetiKsp(feSpaces);
+
+
+    // === If required, run debug tests. ===
+
+    dbgMatrix();
   }
 
 
diff --git a/AMDiS/src/parallel/PetscSolverFeti.h b/AMDiS/src/parallel/PetscSolverFeti.h
index cbe71f87..c5e8c345 100644
--- a/AMDiS/src/parallel/PetscSolverFeti.h
+++ b/AMDiS/src/parallel/PetscSolverFeti.h
@@ -135,6 +135,10 @@ namespace AMDiS {
     /// Destroys FETI-DP operator, \ref ksp_feti
     void destroyFetiKsp();
 
+    /// In debug modes, this function runs some debug tests on the FETI
+    /// matrices. In optimized mode, nothing is done here.
+    void dbgMatrix();
+
     /** \brief
      * Recovers AMDiS solution vector from PETSc's solution vectors of the
      * FETI-DP system. First, the B variables can locally be copied to the
-- 
GitLab