From 53bc9ee2b57b18f106912eb7f6d390f46ff2d75d Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Tue, 26 Oct 2010 17:25:57 +0000
Subject: [PATCH] linearSystemPETSc : mechanism to pass petsc options
 (unfinished)

---
 Solver/linearSystemPETSc.cpp | 4 ++++
 Solver/linearSystemPETSc.h   | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp
index a3466d4a2f..ebffba0519 100644
--- a/Solver/linearSystemPETSc.cpp
+++ b/Solver/linearSystemPETSc.cpp
@@ -98,6 +98,8 @@ void linearSystemPETSc<fullMatrix<PetscScalar> >::allocate(int nbRows)
   } else {
     _try(MatSetType(_a, MATSEQBAIJ));
   }
+  if (_parameters.count("petscPrefix"))
+    _try(MatAppendOptionsPrefix(_a, _parameters["petscPrefix"].c_str()));
   _try(MatSetFromOptions(_a));
   _try(MatGetOwnershipRange(_a, &_localRowStart, &_localRowEnd));
   _try(MatGetSize(_a, &_globalSize, &_localSize));
@@ -111,6 +113,8 @@ void linearSystemPETSc<fullMatrix<PetscScalar> >::allocate(int nbRows)
   _try(VecSetSizes(_x, nbRows * _blockSize, PETSC_DETERMINE));
   // override the default options with the ones from the option
   // database (if any)
+  if (_parameters.count("petscPrefix"))
+    _try(VecAppendOptionsPrefix(_x, _parameters["petscPrefix"].c_str()));
   _try(VecSetFromOptions(_x));
   _try(VecDuplicate(_x, &_b));
   _isAllocated = true;
diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h
index 761a3c3a4f..343ee7776c 100644
--- a/Solver/linearSystemPETSc.h
+++ b/Solver/linearSystemPETSc.h
@@ -66,6 +66,8 @@ class linearSystemPETSc : public linearSystem<scalar> {
     _try(KSPSetTolerances(_ksp, 1.e-8, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT));
     // override the default options with the ones from the option
     // database (if any)
+    if (linearSystemBase::_parameters.count("petscPrefix"))
+      _try(KSPAppendOptionsPrefix(_ksp, linearSystemBase::_parameters["petscPrefix"].c_str()));
     _try(KSPSetFromOptions(_ksp));
     _kspAllocated = true;
   }
@@ -124,6 +126,10 @@ class linearSystemPETSc : public linearSystem<scalar> {
     _try(MatSetSizes(_a, nbRows, nbRows, PETSC_DETERMINE, PETSC_DETERMINE));
     // override the default options with the ones from the option
     // database (if any)
+    if (linearSystemBase::_parameters.count("petscOptions"))
+      _try(PetscOptionsInsertString(linearSystemBase::_parameters["petscOptions"].c_str()));
+    if (linearSystemBase::_parameters.count("petscPrefix"))
+      _try(MatAppendOptionsPrefix(_a, linearSystemBase::_parameters["petscPrefix"].c_str()));
     _try(MatSetFromOptions(_a));
     _try(MatGetOwnershipRange(_a, &_localRowStart, &_localRowEnd));
     _try(MatGetSize(_a, &_globalSize, &_localSize));
@@ -132,6 +138,8 @@ class linearSystemPETSc : public linearSystem<scalar> {
     _try(VecSetSizes(_x, nbRows, PETSC_DETERMINE));
     // override the default options with the ones from the option
     // database (if any)
+    if (linearSystemBase::_parameters.count("petscPrefix"))
+      _try(VecAppendOptionsPrefix(_x, linearSystemBase::_parameters["petscPrefix"].c_str()));
     _try(VecSetFromOptions(_x));
     _try(VecDuplicate(_x, &_b));
     _isAllocated = true;
-- 
GitLab