From bfea95a67f8a2b343ca42b8af0684b79bbcf0ad5 Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Fri, 17 May 2013 13:12:25 +0000
Subject: [PATCH] linearSystemPETSc.h remove #include "petsc.h" when building
 python bindings (a better solution would be welcome)

---
 Solver/linearSystemPETSc.h   | 17 ++++++++++++++---
 Solver/linearSystemPETSc.hpp | 10 ++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h
index c2ed187e37..5de035d364 100644
--- a/Solver/linearSystemPETSc.h
+++ b/Solver/linearSystemPETSc.h
@@ -41,12 +41,17 @@
 #include "fullMatrix.h"
 #include <vector>
 #if defined(HAVE_PETSC)
+#ifndef SWIG
 #include "petsc.h"
-#include <petscksp.h>
+#else
+typedef struct _p_Mat* Mat;
+typedef struct _p_Vec* Vec;
+typedef struct _p_KSP* KSP;
+#endif
+
 template <class scalar>
 class linearSystemPETSc : public linearSystem<scalar> {
   protected:
-  MPI_Comm _comm;
   int _blockSize; // for block Matrix
   bool _isAllocated, _kspAllocated, _entriesPreAllocated, _matrixModified;
   Mat _a;
@@ -55,8 +60,10 @@ class linearSystemPETSc : public linearSystem<scalar> {
   int _localRowStart, _localRowEnd, _localSize, _globalSize;
   sparsityPattern _sparsity;
   void _kspCreate();
+  #ifndef SWIG
+  MPI_Comm _comm;
+  #endif
  public:
-  linearSystemPETSc(MPI_Comm com = PETSC_COMM_WORLD);
   virtual ~linearSystemPETSc();
   void insertInSparsityPattern (int i, int j);
   virtual bool isAllocated() const { return _isAllocated; }
@@ -79,7 +86,11 @@ class linearSystemPETSc : public linearSystem<scalar> {
   std::vector<scalar> getData();
   std::vector<int> getRowPointers();
   std::vector<int> getColumnsIndices();
+  #ifndef SWIG
+  linearSystemPETSc(MPI_Comm com);
   MPI_Comm& getComm() {return _comm;}
+  #endif
+  linearSystemPETSc();
 };
 
 class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > {
diff --git a/Solver/linearSystemPETSc.hpp b/Solver/linearSystemPETSc.hpp
index ac1d2f06f7..7922ec42bc 100644
--- a/Solver/linearSystemPETSc.hpp
+++ b/Solver/linearSystemPETSc.hpp
@@ -43,6 +43,16 @@ linearSystemPETSc<scalar>::linearSystemPETSc(MPI_Comm com)
   _matrixModified=true;
 }
 
+template <class scalar>
+linearSystemPETSc<scalar>::linearSystemPETSc()
+{
+  _comm = PETSC_COMM_WORLD;
+  _isAllocated = false;
+  _blockSize = 0;
+  _kspAllocated = false;
+  _matrixModified=true;
+}
+
 template <class scalar>
 linearSystemPETSc<scalar>::~linearSystemPETSc()
 {
-- 
GitLab