From cfba5616abc2fb3e112dd9b39ffb77bca6173949 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 14 Mar 2012 14:11:52 +0000
Subject: [PATCH] Changed handling of removing rhs null space in parallel
 computations for multiple stationary problems.

---
 AMDiS/src/parallel/PetscProblemStat.h         | 5 +++++
 AMDiS/src/parallel/PetscSolver.cc             | 5 ++++-
 AMDiS/src/parallel/PetscSolver.h              | 9 +++++++++
 AMDiS/src/parallel/PetscSolverGlobalMatrix.cc | 1 +
 AMDiS/src/parallel/PetscSolverGlobalMatrix.h  | 8 +-------
 5 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/AMDiS/src/parallel/PetscProblemStat.h b/AMDiS/src/parallel/PetscProblemStat.h
index 491c4d0c..a844b5c9 100644
--- a/AMDiS/src/parallel/PetscProblemStat.h
+++ b/AMDiS/src/parallel/PetscProblemStat.h
@@ -57,6 +57,11 @@ namespace AMDiS {
 	       bool createMatrixData = true,
 	       bool storeMatrixData = false);
 
+    PetscSolver* getPetscSolver()
+    {
+      return petscSolver;
+    }
+
   protected:
     PetscSolver *petscSolver;
 
diff --git a/AMDiS/src/parallel/PetscSolver.cc b/AMDiS/src/parallel/PetscSolver.cc
index ad2d7cc9..da03fe93 100644
--- a/AMDiS/src/parallel/PetscSolver.cc
+++ b/AMDiS/src/parallel/PetscSolver.cc
@@ -21,12 +21,15 @@ namespace AMDiS {
   PetscSolver::PetscSolver()
     : meshDistributor(NULL),
       mpiRank(-1),
-      kspPrefix("")
+      kspPrefix(""),
+      removeRhsNullSpace(false)
   {
     string kspStr = "";
     Parameters::get("parallel->solver->petsc->ksp", kspStr);
     if (kspStr != "")
       PetscOptionsInsertString(kspStr.c_str());
+
+    Parameters::get("parallel->remove rhs null space", removeRhsNullSpace);
   }
 
 
diff --git a/AMDiS/src/parallel/PetscSolver.h b/AMDiS/src/parallel/PetscSolver.h
index 3c2e3e1d..b3331055 100644
--- a/AMDiS/src/parallel/PetscSolver.h
+++ b/AMDiS/src/parallel/PetscSolver.h
@@ -98,6 +98,11 @@ namespace AMDiS {
       kspPrefix = s;
     }
 
+    void setRemoveRhsNullSpace(bool b)
+    {
+      removeRhsNullSpace = b;
+    }
+
   protected:
     void printSolutionInfo(AdaptInfo* adaptInfo,
 			   bool iterationCounter = true,
@@ -149,6 +154,10 @@ namespace AMDiS {
 
     /// KSP database prefix
     string kspPrefix;
+
+    /// If true, the constant null space is projected out of the RHS vector. It
+    /// depends on the specific PETSc solver if it considers this value.
+    bool removeRhsNullSpace;
   };
 
 
diff --git a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
index b5300c8d..a621412e 100644
--- a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
+++ b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
@@ -153,6 +153,7 @@ namespace AMDiS {
     VecAssemblyEnd(petscRhsVec);
 
     if (removeRhsNullSpace) {
+      MSG("Remove constant null space from the RHS!\n");
       MatNullSpace sp;
       MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, &sp);
       MatNullSpaceRemove(sp, petscRhsVec, PETSC_NULL);
diff --git a/AMDiS/src/parallel/PetscSolverGlobalMatrix.h b/AMDiS/src/parallel/PetscSolverGlobalMatrix.h
index 9bafdf50..ed2abcf9 100644
--- a/AMDiS/src/parallel/PetscSolverGlobalMatrix.h
+++ b/AMDiS/src/parallel/PetscSolverGlobalMatrix.h
@@ -41,14 +41,11 @@ namespace AMDiS {
 	o_nnz(NULL),
 	lastMeshNnz(0),
 	zeroStartVector(false),
-	alwaysCreateNnzStructure(false),
-	removeRhsNullSpace(false)
+	alwaysCreateNnzStructure(false)
     {
       Parameters::get("parallel->use zero start vector", zeroStartVector);
       Parameters::get("parallel->always create nnz structure", 
 		      alwaysCreateNnzStructure);
-      Parameters::get("parallel->remove rhs null space", 
-		      removeRhsNullSpace);
     }
 
     void fillPetscMatrix(Matrix<DOFMatrix*> *mat);
@@ -97,9 +94,6 @@ namespace AMDiS {
     /// Mapping from global DOF indices to global matrix indices under 
     /// consideration of possibly multiple components.
     DofToMatIndex dofToMatIndex;
-
-    /// If true, the constant null space is projected out of the RHS vector.
-    bool removeRhsNullSpace;
   };
 
 
-- 
GitLab