From 14ad2448ffb8d2c8a5e6f56e57e5d3a5ab5498e2 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 21 Feb 2008 12:42:40 +0000
Subject: [PATCH] fix compile without gsl

---
 Box/Makefile                |  13 +++--
 Common/GmshMatrix.h         | 106 ++++++++++++++++--------------------
 benchmarks/2d/recombine.geo |  12 ++++
 3 files changed, 67 insertions(+), 64 deletions(-)
 create mode 100644 benchmarks/2d/recombine.geo

diff --git a/Box/Makefile b/Box/Makefile
index 5191d8a4d2..a41fad49ef 100644
--- a/Box/Makefile
+++ b/Box/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.46 2008-02-17 08:47:56 geuzaine Exp $
+# $Id: Makefile,v 1.47 2008-02-21 12:42:40 geuzaine Exp $
 #
 # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 #
@@ -71,8 +71,9 @@ Box.o: Box.cpp ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h \
   ../Post/PView.h ../Post/PViewData.h ../Post/PViewOptions.h \
   ../Post/ColorTable.h ../Post/PViewDataList.h ../Post/PViewData.h \
   ../Post/AdaptiveViews.h ../Common/GmshMatrix.h ../Mesh/Field.h \
-  ../Geo/Geo.h ../Common/GmshDefines.h ../Geo/gmshSurface.h ../Geo/Pair.h \
-  ../Geo/Range.h ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/SVector3.h \
-  ../Geo/SBoundingBox3d.h ../Geo/SPoint2.h ../Geo/ExtrudeParams.h \
-  ../Common/SmoothData.h ../Post/OctreePost.h ../Common/Octree.h \
-  ../Common/OctreeInternals.h ../Mesh/BackgroundMesh.h
+  ../contrib/ANN/include/ANN/ANN.h ../Geo/Geo.h ../Common/GmshDefines.h \
+  ../Geo/gmshSurface.h ../Geo/Pair.h ../Geo/Range.h ../Geo/SPoint2.h \
+  ../Geo/SPoint3.h ../Geo/SVector3.h ../Geo/SBoundingBox3d.h \
+  ../Geo/SPoint2.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \
+  ../Post/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \
+  ../Mesh/BackgroundMesh.h
diff --git a/Common/GmshMatrix.h b/Common/GmshMatrix.h
index 41a2c069b0..8e87a6fc99 100644
--- a/Common/GmshMatrix.h
+++ b/Common/GmshMatrix.h
@@ -30,17 +30,15 @@ public:
   inline int size() const { return r; }
   SCALAR *data;
   ~Gmsh_Vector() { delete [] data; }
-  Gmsh_Vector(int R)
-    : r(R)
+  Gmsh_Vector(int R) : r(R)
   {
     data = new SCALAR[r];
-    scal(0);
+    scale(0);
   }
-  Gmsh_Vector(const Gmsh_Vector<SCALAR> &other)
-    : r(other.r)
+  Gmsh_Vector(const Gmsh_Vector<SCALAR> &other) : r(other.r)
   {
     data = new double[r];
-    copy(other.data);
+    for (int i = 0; i < r; ++i) data[i] = other.data[i];
   }
   inline SCALAR operator () (int i) const
   {
@@ -50,22 +48,16 @@ public:
   {
     return data[i];
   }
-  inline SCALAR operator *(const Gmsh_Vector<SCALAR> &other)
+  inline double norm()
   {
-    throw;
+    double n = 0.;
+    for(int i = 0; i < r; ++i) n += data[i] * data[i];
+    return sqrt(n);
   }
-  inline void scal(const SCALAR s)
+  inline void scale(const SCALAR s)
   {
     for (int i = 0; i < r; ++i) data[i] *= s;
   }
-  inline void copy(const SCALAR **other)
-  {
-    for (int i = 0; i < r; ++i) data[i] = other.data[i];
-  }
-  inline void lu_solve (const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
-  {
-    throw;
-  }
 };
 
 template <class SCALAR>
@@ -78,17 +70,20 @@ public:
   inline int size2() const { return c; }
   SCALAR *data;
   ~Gmsh_Matrix() { delete [] data; }
-  Gmsh_Matrix(int R,int C)
-    : r(R), c(C)
+  Gmsh_Matrix(int R,int C) : r(R), c(C)
   {
     data = new SCALAR[r * c];
-    scal(0);
+    scale(0);
   }
-  Gmsh_Matrix(const Gmsh_Matrix<SCALAR> &other)
-    : r(other.r), c(other.c)
+  Gmsh_Matrix(const Gmsh_Matrix<SCALAR> &other) : r(other.r), c(other.c)
   {
     data = new double[r * c];
-    copy(other.data);
+    memcpy(other);
+  }
+  Gmsh_Matrix() : r(0), c(0), data(0) {}
+  void memcpy(const Gmsh_Matrix &other)
+  {
+    for (int i = 0; i < r * c; ++i) data[i] = other.data[i];
   }
   inline SCALAR operator () (int i, int j) const
   {
@@ -98,47 +93,50 @@ public:
   {
     return data[i + r * j];
   }
-  inline Gmsh_Matrix operator *(const Gmsh_Matrix<SCALAR> &other)
+  inline void mult(const Gmsh_Matrix<SCALAR> &x, const Gmsh_Matrix<SCALAR> &b)
   {
     throw;
   }
-  inline void scal(const SCALAR s)
+  inline void mult(const Gmsh_Vector<SCALAR> &x, Gmsh_Vector<SCALAR> &b)
   {
-    for (int i = 0; i < r * c; ++i) data[i] *= s;
+    throw;
   }
-  inline void copy(const SCALAR **other)
+  inline void set_all(const double &m) 
   {
-    for (int i = 0; i < r * c; ++i) data[i] = other.data[i];
+    throw;
   }
-  inline void mult(const Gmsh_Matrix<SCALAR> &x, const Gmsh_Matrix<SCALAR> &b)
+  inline void lu_solve(const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
   {
     throw;
   }
-  inline void mult (const Gmsh_Vector<SCALAR> &x, Gmsh_Vector<SCALAR> &b)
+  Gmsh_Matrix cofactor(int i, int j) const 
   {
     throw;
   }
-  inline void least_squares(const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
+  inline void invert()
   {
     throw;
   }
-  inline void lu_solve (const Gmsh_Vector<SCALAR> &rhs, Gmsh_Vector<SCALAR> &result)
+  double determinant() const 
   {
     throw;
   }
-  Gmsh_Matrix cofactor(int i, int j) const 
+  inline Gmsh_Matrix touchSubmatrix(int i0, int ni, int j0, int nj) 
   {
     throw;
+  }  
+  inline void scale(const SCALAR s)
+  {
+    for (int i = 0; i < r * c; ++i) data[i] *= s;
   }
-  inline void invert()
+  inline void add(const double &a) 
   {
     throw;
   }
-  double determinant() const 
+  inline void add(const Gmsh_Matrix &m) 
   {
     throw;
   }
-
 };
 
 #ifdef HAVE_GSL
@@ -173,7 +171,8 @@ public:
   {
     return *gsl_vector_ptr(data, i);
   }
-  inline double norm(){
+  inline double norm()
+{
     return gsl_blas_dnrm2(data);
   }
   inline void scale(const double &y)
@@ -187,22 +186,20 @@ class GSL_Matrix
 {
 private:
   gsl_matrix_view view;
-  int r, c;
 public:
   inline size_t size1() const { return data->size1; }
   inline size_t size2() const { return data->size2; }
   gsl_matrix *data;
-  GSL_Matrix(gsl_matrix_view _data) : view(_data),data(&view.matrix) {}
-  GSL_Matrix(size_t R, size_t C) { data = gsl_matrix_calloc (R, C); }
-  GSL_Matrix() : data(0) {}
-  GSL_Matrix(const GSL_Matrix&other) : data(0)
+  GSL_Matrix(gsl_matrix_view _data) : view(_data), data(&view.matrix) {}
+  GSL_Matrix(size_t R, size_t C) { data = gsl_matrix_calloc(R, C); }
+  GSL_Matrix() : r(0), c(0), data(0) {}
+  GSL_Matrix(const GSL_Matrix &other) : data(0)
   {
     if(data) gsl_matrix_free(data);
     data = gsl_matrix_calloc(other.data->size1, other.data->size2);
     gsl_matrix_memcpy(data, other.data);
   }
   virtual ~GSL_Matrix() { if(data && data->owner == 1) gsl_matrix_free(data); }
-  
   GSL_Matrix & operator = (const GSL_Matrix&other)
   {
     if (&other != this){
@@ -232,19 +229,6 @@ public:
   {
     gsl_matrix_set_all(data, m);
   }
-  inline void least_squares (const GSL_Vector &rhs, GSL_Vector &result)
-  {
-    assert(r > c);
-    assert(rhs.size() == r);
-    assert(result.size() == c);
-    GSL_Matrix *ls = new GSL_Matrix(c, c);
-    GSL_Vector *ls_rhs = new GSL_Vector(c);
-    gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, data, data, 1.0, ls->data);
-    gsl_blas_dgemv(CblasTrans, 1.0, data, rhs.data, 1.0, ls_rhs->data);
-    ls->lu_solve (*ls_rhs,result);
-    delete ls;
-    delete ls_rhs;
-  }
   inline void lu_solve(const GSL_Vector &rhs, GSL_Vector &result)
   {
     int s;
@@ -262,7 +246,7 @@ public:
     gsl_linalg_LU_invert(data, p, data_inv) ;
     gsl_matrix_memcpy(data, data_inv);
     gsl_matrix_free(data_inv);
-    gsl_permutation_free (p);
+    gsl_permutation_free(p);
   }
   inline bool invertSecure(double &det)
   {
@@ -307,7 +291,7 @@ public:
     }      
     return cof;
   }
-   inline void mult(const GSL_Vector &x, GSL_Vector &b)
+  inline void mult(const GSL_Vector &x, GSL_Vector &b)
   {
     gsl_blas_dgemv(CblasNoTrans, 1.0, data, x.data, 1.0, b.data);
   }
@@ -333,12 +317,18 @@ public:
     gsl_matrix_add (data, m.data);
   }
 };
+
 typedef GSL_Matrix Double_Matrix;
 typedef GSL_Vector Double_Vector;
+
 #else
+
 typedef Gmsh_Matrix<double> Double_Matrix;
 typedef Gmsh_Vector<double> Double_Vector;
+
 #endif
+
 typedef Gmsh_Matrix<int> Int_Matrix;
 typedef Gmsh_Vector<int> Int_Vector;
+
 #endif
diff --git a/benchmarks/2d/recombine.geo b/benchmarks/2d/recombine.geo
new file mode 100644
index 0000000000..7f2f386287
--- /dev/null
+++ b/benchmarks/2d/recombine.geo
@@ -0,0 +1,12 @@
+lc = 0.01;
+Point(1) = {0, 0, 0, lc/5};
+Point(2) = {.1, 0,  0, lc/5};
+Point(3) = {.1, .3, 0, lc};
+Point(4) = {0,  .3, 0, lc};
+Line(1) = {1,2} ;
+Line(2) = {3,2} ;
+Line(3) = {3,4} ;
+Line(4) = {4,1} ;
+Line Loop(5) = {4,1,-2,3} ;
+Plane Surface(6) = {5} ;
+Recombine Surface{6};
-- 
GitLab