From 3000d2c854e8ae5b5dc562151cc3ea142ae1ca19 Mon Sep 17 00:00:00 2001
From: Matti Pellika <matti.pellikka@tut.fi>
Date: Mon, 30 Mar 2009 13:31:51 +0000
Subject: [PATCH] Added Geo/CellCompelex.cpp and Geo/CellComplex.h They
 construct a cell complex of a finite elemement mesh of a model, and are able
 to reduce and coreduce it in order to compute model's homology groups.

Also added contrib/kbipack to by Saku Suuriniemi for future use to
compute Smith normal forms of the boundary operator matrices of the
reduced cell complex.

Modified Makefiles and configure.in accordingly.
---
 Geo/MFace.cpp |  1 +
 Geo/MFace.h   |  3 ++-
 Geo/Makefile  |  7 ++++++-
 Makefile      |  5 ++++-
 configure     | 40 ++++++++++++++++++++++++++++++++++++++++
 configure.in  | 15 +++++++++++++++
 6 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/Geo/MFace.cpp b/Geo/MFace.cpp
index 4ef4dbfa13..005ba9581e 100644
--- a/Geo/MFace.cpp
+++ b/Geo/MFace.cpp
@@ -74,6 +74,7 @@ MFace::MFace(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3)
   }
   else
     _si[3] = 3;
+    
 }
 
 SVector3 MFace::normal() const
diff --git a/Geo/MFace.h b/Geo/MFace.h
index ce8a8b088f..7fce754ffb 100644
--- a/Geo/MFace.h
+++ b/Geo/MFace.h
@@ -9,13 +9,14 @@
 #include <functional>
 #include <vector>
 #include "MVertex.h"
+#include "MEdge.h"
 #include "SVector3.h"
 
 // A mesh face.
 class MFace {
  private:
   MVertex *_v[4];
-  char _si[4]; // sorted indices
+  char _si[4]; // sorted indices 
 
  public:
   MFace();
diff --git a/Geo/Makefile b/Geo/Makefile
index 7c84e081cd..1359693f44 100644
--- a/Geo/Makefile
+++ b/Geo/Makefile
@@ -10,6 +10,7 @@ LIB = ../lib/libGmshGeo${LIBEXT}
 INC = ${DASH}I../Common ${DASH}I../Geo ${DASH}I../Mesh\
       ${DASH}I../Post ${DASH}I../Numeric ${DASH}I../Parser\
       ${DASH}I../contrib/ANN/include\
+      ${DASH}I../contrib/kbipack\
       ${DASH}I../contrib/MathEval ${DASH}I../contrib/gmm
 
 CFLAGS = ${OPTIM} ${FLAGS} ${INC} ${SYSINCLUDE}
@@ -37,7 +38,9 @@ SRC = GEntity.cpp\
       MElement.cpp\
         MLine.cpp MTriangle.cpp MQuadrangle.cpp MTetrahedron.cpp\
         MHexahedron.cpp MPrism.cpp MPyramid.cpp\
-      MZone.cpp MZoneBoundary.cpp
+      MZone.cpp MZoneBoundary.cpp\
+      CellComplex.cpp
+
 
 OBJ = ${SRC:.cpp=${OBJEXT}}
 
@@ -375,3 +378,5 @@ MPyramid${OBJEXT}: MPyramid.cpp MPyramid.h MElement.h ../Common/GmshDefines.h \
   ../Numeric/Numeric.h ../Numeric/GmshMatrix.h
 MZone${OBJEXT}: MZone.cpp ../Common/GmshConfig.h
 MZoneBoundary${OBJEXT}: MZoneBoundary.cpp ../Common/GmshConfig.h
+CellComplex${OBJEXT}: CellComplex.cpp CellComplex.h 
+  
diff --git a/Makefile b/Makefile
index 9dcb102aac..36c7086ca7 100644
--- a/Makefile
+++ b/Makefile
@@ -26,13 +26,16 @@ GMSH_API =\
   Geo/MTetrahedron.h Geo/MHexahedron.h Geo/MPrism.h Geo/MPyramid.h\
   Geo/discreteVertex.h Geo/discreteEdge.h Geo/discreteFace.h Geo/discreteRegion.h\
   Geo/SPoint2.h Geo/SPoint3.h Geo/SVector3.h Geo/SBoundingBox3d.h Geo/Pair.h Geo/Range.h\
+  Geo/CellComplex.h\
+  contrib/kbipack/gmp_normal_form.h contrib/kbipack/gmp_matrix.h contrib/kbipack/gmp_blas.h\
   Numeric/Gauss.h Numeric/FunctionSpace.h Numeric/GmshMatrix.h\
   Numeric/gmshAssembler.h Numeric/gmshTermOfFormulation.h Numeric/gmshLaplace.h\
   Numeric/gmshElasticity.h Numeric/gmshLinearSystem.h Numeric/gmshLinearSystemGmm.h\
   Numeric/gmshLinearSystemFull.h Numeric/gmshFunction.h\
   Post/PView.h Post/PViewData.h Plugin/PluginManager.h\
   Common/VertexArray.h Common/GmshMessage.h\
-  Common/Gmsh.h Common/GmshConfig.h Common/GmshDefines.h Common/GmshVersion.h 
+  Common/Gmsh.h Common/GmshConfig.h Common/GmshDefines.h Common/GmshVersion.h
+
 
 GMSH_EMBEDDED = ${GMSH_API}\
   Geo/GModel.cpp Geo/GModelIO_Mesh.cpp Geo/GEntity.cpp\
diff --git a/configure b/configure
index 334641fefd..2eefd1d2e1 100755
--- a/configure
+++ b/configure
@@ -1277,6 +1277,7 @@ Optional Features:
   --enable-chaco          compile Chaco partitioner (default=yes)
   --enable-tetgen         compile Tetgen if available (default=yes)
   --enable-matheval       compile MathEval if available (default=yes)
+  --enable-kbipack        compile kbipack if available (default=yes)
   --enable-gmm            use gmm++ if available (default=yes)
   --enable-osmesa         use OSMesa for offscreen rendering (default=no)
   --enable-cgns           enable CGNS output (default=no)
@@ -1911,6 +1912,11 @@ if test "${enable_matheval+set}" = set; then
   enableval=$enable_matheval;
 fi
 
+# Check whether --enable-kbipack was given.
+if test "${enable_kbipack+set}" = set; then
+  enableval=$enable_kbipack;
+fi
+
 # Check whether --enable-gmm was given.
 if test "${enable_gmm+set}" = set; then
   enableval=$enable_gmm;
@@ -1978,6 +1984,7 @@ if test "x$enable_minimal" = "xyes"; then
   enable_netgen=no;
   enable_tetgen=no;
   enable_matheval=no;
+  enable_kbipack=no;
   enable_gmm=no;
   enable_ann=no;
   enable_metis=no;
@@ -4746,6 +4753,39 @@ _ACEOF
     fi
   fi
 
+    if test "x$enable_kbipack" != "xno"; then
+    { echo "$as_me:$LINENO: checking for ./contrib/kbipack/gmp_normal_form.h" >&5
+echo $ECHO_N "checking for ./contrib/kbipack/gmp_normal_form.h... $ECHO_C" >&6; }
+if test "${ac_cv_file___contrib_kbipack_gmp_normal_form_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  test "$cross_compiling" = yes &&
+  { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5
+echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
+   { (exit 1); exit 1; }; }
+if test -r "./contrib/kbipack/gmp_normal_form.h"; then
+  ac_cv_file___contrib_kbipack_gmp_normal_form_h=yes
+else
+  ac_cv_file___contrib_kbipack_gmp_normal_form_h=no
+fi
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_file___contrib_kbipack_gmp_normal_form_h" >&5
+echo "${ECHO_T}$ac_cv_file___contrib_kbipack_gmp_normal_form_h" >&6; }
+if test $ac_cv_file___contrib_kbipack_gmp_normal_form_h = yes; then
+  KBIPACK="yes"
+fi
+
+    if test "x${KBIPACK}" = "xyes"; then
+      GMSH_DIRS="${GMSH_DIRS} contrib/kbipack"
+      GMSH_LIBS="${GMSH_LIBS} -lGmshKbi -lgmp"
+      cat >>confdefs.h <<\_ACEOF
+#define HAVE_kbipack 1
+_ACEOF
+
+      BO="${BO} kbipack"
+    fi
+  fi
+
 fi
 
 if test "x${OCC_PREFIX}" != "x"; then
diff --git a/configure.in b/configure.in
index e10e4fc0bb..e253c4745d 100644
--- a/configure.in
+++ b/configure.in
@@ -109,6 +109,9 @@ AC_ARG_ENABLE(tetgen,
 AC_ARG_ENABLE(matheval,
               AC_HELP_STRING([--enable-matheval],
                              [compile MathEval if available (default=yes)]))
+AC_ARG_ENABLE(kbipack,
+              AC_HELP_STRING([--enable-kbipack],
+                             [compile kbipack if available (default=yes)]))
 AC_ARG_ENABLE(gmm,
               AC_HELP_STRING([--enable-gmm],
                              [use gmm++ if available (default=yes)]))
@@ -153,6 +156,7 @@ if test "x$enable_minimal" = "xyes"; then
   enable_netgen=no;
   enable_tetgen=no;
   enable_matheval=no;
+  enable_kbipack=no;
   enable_gmm=no;
   enable_ann=no;
   enable_metis=no;
@@ -500,6 +504,17 @@ if test "x$enable_contrib" != "xno"; then
       BO="${BO} MathEval"
     fi
   fi
+  
+  dnl Check for kbipack
+  if test "x$enable_kbipack" != "xno"; then
+    AC_CHECK_FILE(./contrib/kbipack/gmp_normal_form.h,KBIPACK="yes")
+    if test "x${KBIPACK}" = "xyes"; then
+      GMSH_DIRS="${GMSH_DIRS} contrib/kbipack"
+      GMSH_LIBS="${GMSH_LIBS} -lGmshKbi -lgmp"
+      AC_DEFINE(HAVE_kbipack)
+      BO="${BO} kbipack"
+    fi
+  fi
 
 fi
 
-- 
GitLab