From 84fc5ca77f7378243c70f335dc7c3bd446bc06d7 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 27 Mar 2009 17:41:16 +0000
Subject: [PATCH] invert vandermonde matrix numerically (jf pirenne)

---
 Common/DefaultOptions.h   |  2 +-
 Numeric/FunctionSpace.cpp | 16 ++--------------
 2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 992865cb39..646af460e7 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1084,7 +1084,7 @@ StringXNumber MeshOptions_Number[] = {
   { F|O, "RadiusSup" , opt_mesh_radius_sup , 0.0 , 
     "Only display elements whose longest edge is smaller than RadiusSup" },
   { F|O, "RandomFactor" , opt_mesh_rand_factor , 1.e-9 ,
-    "Random factor used in the 2D meshing algorithm (use larger values if lc * rand approaches machine accuracy)" },
+    "Random factor used in the 2D meshing algorithm (should be increased if RandomFactor * size(triangle)/size(model) approaches machine accuracy)" },
   { F|O, "RefineSteps" , opt_mesh_refine_steps , 10 ,
     "Number of refinement steps in the MeshAdapt-based 2D algorithms" }, 
   { F|O, "ReverseAllNormals" , opt_mesh_reverse_all_normals , 0. , 
diff --git a/Numeric/FunctionSpace.cpp b/Numeric/FunctionSpace.cpp
index eb18b8e322..461bfca03b 100644
--- a/Numeric/FunctionSpace.cpp
+++ b/Numeric/FunctionSpace.cpp
@@ -537,21 +537,9 @@ gmshMatrix<double> generateLagrangeMonomialCoefficients(const gmshMatrix<double>
     }
   }
 
-  double det = Vandermonde.determinant();
-
-  if (det == 0.){
-    Msg::Fatal("Vandermonde matrix has zero determinant!?");
-    return gmshMatrix<double>(1, 1);
-  }
   gmshMatrix<double> coefficient(ndofs, ndofs);
-  for (int i = 0; i < ndofs; i++) {
-    for (int j = 0; j < ndofs; j++) {
-      int f = (i + j) % 2 == 0 ? 1 : -1;
-      gmshMatrix<double> cofactor = Vandermonde.cofactor(i, j);
-      coefficient(i, j) = f * cofactor.determinant() / det;
-    }
-  }
-  return coefficient;
+  Vandermonde.invert(coefficient);
+  return coefficient.transpose();
 }
 
 std::map<int, gmshFunctionSpace> gmshFunctionSpaces::fs;
-- 
GitLab