From 6594213995d4d45d093bdb176870e910c6bea63d Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 13 Oct 2009 07:57:59 +0000
Subject: [PATCH] fix template instanciation in TAUCS (if GMM is not available)

---
 CMakeLists.txt               |  3 ++
 Geo/GFaceCompound.cpp        |  1 -
 Mesh/highOrderSmoother.cpp   |  3 +-
 Solver/CMakeLists.txt        |  1 -
 Solver/elasticitySolver.cpp  |  4 +--
 Solver/linearSystemCSR.cpp   | 49 +++++++++++++++++++++++++++
 Solver/linearSystemCSR.h     | 20 +++++++++++
 Solver/linearSystemTAUCS.cpp | 64 ------------------------------------
 Solver/linearSystemTAUCS.h   | 31 -----------------
 9 files changed, 75 insertions(+), 101 deletions(-)
 delete mode 100644 Solver/linearSystemTAUCS.cpp
 delete mode 100644 Solver/linearSystemTAUCS.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c8ff67880..735e012a12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -511,6 +511,9 @@ if(ENABLE_MED OR ENABLE_CGNS)
 endif(ENABLE_MED OR ENABLE_CGNS)
 
 if(ENABLE_TAUCS)
+  if(NOT HAVE_METIS)
+    message(SEND_ERROR "You have to enable METIS in order to use TAUCS")
+  endif(NOT HAVE_METIS)
   find_library(TAUCS_LIB taucs PATH_SUFFIXES lib)
   if(TAUCS_LIB)
     find_path(TAUCS_INC "taucs.h" PATH_SUFFIXES src include)
diff --git a/Geo/GFaceCompound.cpp b/Geo/GFaceCompound.cpp
index 5cf441db68..e52b7fb9a4 100644
--- a/Geo/GFaceCompound.cpp
+++ b/Geo/GFaceCompound.cpp
@@ -22,7 +22,6 @@
 #include "crossConfTerm.h"
 #include "convexCombinationTerm.h"
 #include "linearSystemGMM.h"
-#include "linearSystemTAUCS.h"
 #include "linearSystemCSR.h"
 #include "linearSystemFull.h"
 #include "linearSystemPETSc.h"
diff --git a/Mesh/highOrderSmoother.cpp b/Mesh/highOrderSmoother.cpp
index b371c53226..79c5cf0578 100644
--- a/Mesh/highOrderSmoother.cpp
+++ b/Mesh/highOrderSmoother.cpp
@@ -23,8 +23,7 @@
 #include "Numeric.h"
 #include "dofManager.h"
 #include "elasticityTerm.h"
-#include "linearSystemTAUCS.h"
-#include "linearSystemGMM.h"
+#include "linearSystemCSR.h"
 
 #define SQU(a)      ((a)*(a))
 
diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt
index 89621c7419..699c6edc02 100644
--- a/Solver/CMakeLists.txt
+++ b/Solver/CMakeLists.txt
@@ -5,7 +5,6 @@
 
 set(SRC
   linearSystemCSR.cpp
-  linearSystemTAUCS.cpp
   groupOfElements.cpp
   elasticityTerm.cpp
   elasticitySolver.cpp
diff --git a/Solver/elasticitySolver.cpp b/Solver/elasticitySolver.cpp
index 40acc54b71..5b257e316a 100644
--- a/Solver/elasticitySolver.cpp
+++ b/Solver/elasticitySolver.cpp
@@ -9,9 +9,9 @@
 #include "MTriangle.h"
 #include "MTetrahedron.h"
 #include "elasticitySolver.h"
-#include "linearSystemTAUCS.h"
-#include "linearSystemGMM.h"
+#include "linearSystemCSR.h"
 #include "linearSystemPETSc.h"
+#include "linearSystemGMM.h"
 #include "Numeric.h"
 
 #if !defined(HAVE_NO_POST)
diff --git a/Solver/linearSystemCSR.cpp b/Solver/linearSystemCSR.cpp
index dd2a3b92fa..65d98a9e4c 100644
--- a/Solver/linearSystemCSR.cpp
+++ b/Solver/linearSystemCSR.cpp
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <time.h>
 #include "GmshConfig.h"
 #include "GmshMessage.h"
 #include "linearSystemCSR.h"
@@ -312,3 +313,51 @@ int linearSystemCSRGmm<double>::systemSolve()
 }
 
 #endif
+
+#if defined(HAVE_TAUCS)
+
+extern "C" {
+#include "taucs.h"
+}
+
+template<>
+int linearSystemCSRTaucs<double>::systemSolve()
+{
+  if(!sorted){
+    sortColumns_(_b->size(),
+                CSRList_Nbr(_a),
+                (INDEX_TYPE *) _ptr->array,
+                (INDEX_TYPE *) _jptr->array, 
+                (INDEX_TYPE *) _ai->array, 
+                (double*) _a->array);
+  }
+  sorted = true;
+  
+  taucs_ccs_matrix myVeryCuteTaucsMatrix;
+  myVeryCuteTaucsMatrix.n = myVeryCuteTaucsMatrix.m = _b->size();
+  //myVeryCuteTaucsMatrix.rowind = (INDEX_TYPE*)_ptr->array;
+  //myVeryCuteTaucsMatrix.colptr = (INDEX_TYPE*)_ai->array;
+  myVeryCuteTaucsMatrix.rowind = (INDEX_TYPE*)_ai->array;
+  myVeryCuteTaucsMatrix.colptr = (INDEX_TYPE*)_jptr->array;
+  myVeryCuteTaucsMatrix.values.d = (double*)_a->array;
+  myVeryCuteTaucsMatrix.flags = TAUCS_SYMMETRIC | TAUCS_LOWER | TAUCS_DOUBLE; 
+  
+  char* options[] = { "taucs.factor.LLT=true", NULL };  
+  clock_t t1 = clock();
+  int result = taucs_linsolve(&myVeryCuteTaucsMatrix, 
+                              NULL, 
+                              1, 
+                              &(*_x)[0],
+                              &(*_b)[0],
+                              options,
+                              NULL);                         
+  clock_t t2 = clock();
+  Msg::Info("TAUCS has solved %d unknowns in %8.3f seconds", 
+            _b->size(), (double)(t2 - t1) / CLOCKS_PER_SEC);
+  if (result != TAUCS_SUCCESS){
+    Msg::Error("Taucs Was Not Successfull %d", result);
+  }  
+  return 1;
+}
+
+#endif
diff --git a/Solver/linearSystemCSR.h b/Solver/linearSystemCSR.h
index 9d8e39b9e2..d7bad23a1e 100644
--- a/Solver/linearSystemCSR.h
+++ b/Solver/linearSystemCSR.h
@@ -133,4 +133,24 @@ class linearSystemCSRGmm : public linearSystemCSR<scalar> {
   ;
 };
 
+template <class scalar>
+class linearSystemCSRTaucs : public linearSystemCSR<scalar> {
+ public:
+  linearSystemCSRTaucs(){}
+  virtual ~linearSystemCSRTaucs(){}
+  virtual void addToMatrix(int il, int ic, double val)
+  {
+    if (il <= ic)
+      linearSystemCSR<scalar>::addToMatrix(il, ic, val);
+  }
+  virtual int systemSolve() 
+#if !defined(HAVE_TAUCS)
+  {
+    Msg::Error("TAUCS is not available in this version of Gmsh");
+    return 0;
+  }
+#endif
+  ;
+};
+
 #endif
diff --git a/Solver/linearSystemTAUCS.cpp b/Solver/linearSystemTAUCS.cpp
deleted file mode 100644
index 2d95cc0c2c..0000000000
--- a/Solver/linearSystemTAUCS.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
-//
-// See the LICENSE.txt file for license information. Please report all
-// bugs and problems to <gmsh@geuz.org>.
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include "linearSystemTAUCS.h"
-
-#if defined(HAVE_TAUCS)
-extern "C" {
-#include "taucs.h"
-}
-
-template <class scalar>
-void sortColumns_(int NbLines, 
-                 int nnz, 
-                 INDEX_TYPE *ptr, 
-                 INDEX_TYPE *jptr, 
-                 INDEX_TYPE *ai, 
-                 scalar *a);
-
-template<>
-int linearSystemCSRTaucs<double>::systemSolve()
-{
-  if(!sorted){
-    sortColumns_(_b->size(),
-                CSRList_Nbr(_a),
-                (INDEX_TYPE *) _ptr->array,
-                (INDEX_TYPE *) _jptr->array, 
-                (INDEX_TYPE *) _ai->array, 
-                (double*) _a->array);
-  }
-  sorted = true;
-  
-  taucs_ccs_matrix myVeryCuteTaucsMatrix;
-  myVeryCuteTaucsMatrix.n = myVeryCuteTaucsMatrix.m = _b->size();
-  //myVeryCuteTaucsMatrix.rowind = (INDEX_TYPE*)_ptr->array;
-  //myVeryCuteTaucsMatrix.colptr = (INDEX_TYPE*)_ai->array;
-  myVeryCuteTaucsMatrix.rowind = (INDEX_TYPE*)_ai->array;
-  myVeryCuteTaucsMatrix.colptr = (INDEX_TYPE*)_jptr->array;
-  myVeryCuteTaucsMatrix.values.d = (double*)_a->array;
-  myVeryCuteTaucsMatrix.flags = TAUCS_SYMMETRIC | TAUCS_LOWER | TAUCS_DOUBLE; 
-  
-  char* options[] = { "taucs.factor.LLT=true", NULL };  
-  clock_t t1 = clock();
-  int result = taucs_linsolve(&myVeryCuteTaucsMatrix, 
-                              NULL, 
-                              1, 
-                              &(*_x)[0],
-                              &(*_b)[0],
-                              options,
-                              NULL);                         
-  clock_t t2 = clock();
-  Msg::Info("TAUCS has solved %d unknowns in %8.3f seconds", _b->size(),(double)(t2-t1)/CLOCKS_PER_SEC);
-  if (result != TAUCS_SUCCESS){
-    Msg::Error("Taucs Was Not Successfull %d",result);
-  }  
-  return 1;
-}
-
-#endif
diff --git a/Solver/linearSystemTAUCS.h b/Solver/linearSystemTAUCS.h
deleted file mode 100644
index eaf9266f68..0000000000
--- a/Solver/linearSystemTAUCS.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
-//
-// See the LICENSE.txt file for license information. Please report all
-// bugs and problems to <gmsh@geuz.org>.
-
-#ifndef _LINEAR_SYSTEM_TAUCS_H_
-#define _LINEAR_SYSTEM_TAUCS_H_
-
-#include "linearSystemCSR.h"
-
-template <class scalar>
-class linearSystemCSRTaucs : public linearSystemCSR<scalar> {
- public:
-  linearSystemCSRTaucs(){}
-  virtual ~linearSystemCSRTaucs(){}
-  virtual void addToMatrix(int il, int ic, double val)
-  {
-    if (il <= ic)
-      linearSystemCSR<scalar>::addToMatrix(il, ic, val);
-  }
-  virtual int systemSolve() 
-#if !defined(HAVE_TAUCS)
-  {
-    Msg::Error("TAUCS is not available in this version of Gmsh");
-    return 0;
-  }
-#endif
-  ;
-};
-
-#endif
-- 
GitLab