From af522b30c23932e29019fdbccb43a5311806ec8e Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Sat, 16 Jul 2016 11:56:49 +0200
Subject: [PATCH] [T] pass global dim explicitly

---
 Tests/MeshLib/TestCoordinatesMappingLocal.cpp | 25 +++++++++++-----
 Tests/NumLib/TestCoordinatesMapping.cpp       | 29 ++++++++++---------
 Tests/NumLib/TestFe.cpp                       | 12 ++++----
 Tests/NumLib/TestFunctionInterpolation.cpp    |  2 +-
 4 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
index bc028b1a5a8..45b8573b536 100644
--- a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
+++ b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
@@ -153,7 +153,9 @@ void debugOutput(MeshLib::Element *ele, MeshLib::ElementCoordinatesMappingLocal
 TEST(MeshLib, CoordinatesMappingLocalLowerDimLineY)
 {
     auto ele = TestLine2::createY();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(MeshLib::CoordinateSystemType::Y));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(MeshLib::CoordinateSystemType::Y)
+                  .getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -171,8 +173,10 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineY)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimLineZ)
 {
     auto ele = TestLine2::createZ();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele,
-            MeshLib::CoordinateSystem(MeshLib::CoordinateSystemType::Z));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele,
+        MeshLib::CoordinateSystem(MeshLib::CoordinateSystemType::Z)
+            .getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -188,7 +192,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineZ)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXY)
 {
     auto ele = TestLine2::createXY();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(*ele).getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -206,7 +211,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXY)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXYZ)
 {
     auto ele = TestLine2::createXYZ();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(*ele).getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -224,7 +230,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXYZ)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXZ)
 {
     auto ele = TestQuad4::createXZ();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(*ele).getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -244,7 +251,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXZ)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadYZ)
 {
     auto ele = TestQuad4::createYZ();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(*ele).getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
@@ -264,7 +272,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadYZ)
 TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXYZ)
 {
     auto ele = TestQuad4::createXYZ();
-    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
+    MeshLib::ElementCoordinatesMappingLocal mapping(
+        *ele, MeshLib::CoordinateSystem(*ele).getDimension());
     auto matR(mapping.getRotationMatrixToGlobal());
     //debugOutput(ele, mapping);
 
diff --git a/Tests/NumLib/TestCoordinatesMapping.cpp b/Tests/NumLib/TestCoordinatesMapping.cpp
index 027f54fc585..cced072d9ed 100644
--- a/Tests/NumLib/TestCoordinatesMapping.cpp
+++ b/Tests/NumLib/TestCoordinatesMapping.cpp
@@ -62,7 +62,7 @@ public:
 
 public:
     NumLibFemNaturalCoordinatesMappingTest()
-    : eps(std::numeric_limits<double>::epsilon())
+    : eps(2*std::numeric_limits<double>::epsilon())
     {
         // create four elements used for testing
         naturalEle   = this->createNaturalShape();
@@ -106,7 +106,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_N)
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
 
     //only N
-    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::N>(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::N>(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     ASSERT_FALSE(shape.N.isZero());
     ASSERT_TRUE(shape.dNdr.isZero());
     ASSERT_TRUE(shape.J.isZero());
@@ -122,7 +122,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_DNDR)
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
 
     // dNdr
-    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::DNDR>(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::DNDR>(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     ASSERT_TRUE(shape.N.isZero());
     ASSERT_FALSE(shape.dNdr.isZero());
     ASSERT_TRUE(shape.J.isZero());
@@ -139,7 +139,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_N_J)
 
     // N_J
     shape.setZero();
-    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::N_J>(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::N_J>(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     ASSERT_FALSE(shape.N.isZero());
     ASSERT_FALSE(shape.dNdr.isZero());
     ASSERT_FALSE(shape.J.isZero());
@@ -155,7 +155,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_DNDR_
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
 
     // dNdr, J
-    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::DNDR_J>(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::DNDR_J>(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     ASSERT_TRUE(shape.N.isZero());
     ASSERT_FALSE(shape.dNdr.isZero());
     ASSERT_FALSE(shape.J.isZero());
@@ -172,7 +172,9 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_DNDX)
 
     // DNDX
     shape.setZero();
-    NaturalCoordsMappingType::template computeShapeMatrices<ShapeMatrixType::DNDX>(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::template computeShapeMatrices<
+        ShapeMatrixType::DNDX>(*this->naturalEle, this->r, shape,
+                               this->dim);  // TODO check dim
     ASSERT_TRUE(shape.N.isZero());
     ASSERT_FALSE(shape.dNdr.isZero());
     ASSERT_FALSE(shape.J.isZero());
@@ -189,7 +191,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckFieldSpecification_ALL)
 
     // ALL
     shape.setZero();
-    NaturalCoordsMappingType::computeShapeMatrices(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::computeShapeMatrices(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     ASSERT_FALSE(shape.N.isZero());
     ASSERT_FALSE(shape.dNdr.isZero());
     ASSERT_FALSE(shape.J.isZero());
@@ -205,7 +207,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckNaturalShape)
 
     // identical to natural coordinates
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
-    NaturalCoordsMappingType::computeShapeMatrices(*this->naturalEle, this->r, shape);
+    NaturalCoordsMappingType::computeShapeMatrices(*this->naturalEle, this->r, shape, this->dim); // TODO check dim
     double exp_J[TestFixture::dim*TestFixture::dim]= {0.0};
     for (unsigned i=0; i<this->dim; i++)
         exp_J[i+this->dim*i] = 1.0;
@@ -225,7 +227,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckIrregularShape)
 
     // irregular shape
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
-    NaturalCoordsMappingType::computeShapeMatrices(*this->irregularEle, this->r, shape);
+    NaturalCoordsMappingType::computeShapeMatrices(*this->irregularEle, this->r, shape, this->dim); // TODO check dim
     //std::cout <<  std::setprecision(16) << shape;
 
     ASSERT_ARRAY_NEAR(this->nat_exp_N, shape.N.data(), shape.N.size(), this->eps);
@@ -243,7 +245,7 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckClockwise)
 
     // clockwise node ordering, which is invalid)
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
-    NaturalCoordsMappingType::computeShapeMatrices(*this->clockwiseEle, this->r, shape);
+    NaturalCoordsMappingType::computeShapeMatrices(*this->clockwiseEle, this->r, shape, this->dim); // TODO check dim
     //std::cout <<  std::setprecision(16) << shape;
     // Inverse of the Jacobian matrix doesn't exist
     double exp_invJ[TestFixture::dim*TestFixture::dim]= {0.0};
@@ -263,8 +265,9 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckZeroVolume)
     typedef typename TestFixture::NaturalCoordsMappingType NaturalCoordsMappingType;
 
     ShapeMatricesType shape(this->dim, this->global_dim, this->e_nnodes);
-    NaturalCoordsMappingType::computeShapeMatrices(*this->zeroVolumeEle, this->r, shape);
-    //std::cout <<  std::setprecision(16) << shape;
+    NaturalCoordsMappingType::computeShapeMatrices(
+        *this->zeroVolumeEle, this->r, shape, this->dim);  // TODO check dim
+    // std::cout <<  std::setprecision(16) << shape;
     // Inverse of the Jacobian matrix doesn't exist
     double exp_invJ[TestFixture::dim*TestFixture::dim]= {0.0};
     double exp_dNdx[TestFixture::dim*TestFixture::e_nnodes]= {0.0};
@@ -291,7 +294,7 @@ TEST(NumLib, FemNaturalCoordinatesMappingLineY)
     static const unsigned dim = 1;
     static const unsigned e_nnodes = 2;
     ShapeMatricesType shape(dim, 2, e_nnodes);
-    MappingType::computeShapeMatrices(*line, r, shape);
+    MappingType::computeShapeMatrices(*line, r, shape, 2);
 
     double exp_J[dim*dim]= {0.0};
     for (unsigned i=0; i<dim; i++)
diff --git a/Tests/NumLib/TestFe.cpp b/Tests/NumLib/TestFe.cpp
index 0be3ad9a914..6b031f20d81 100644
--- a/Tests/NumLib/TestFe.cpp
+++ b/Tests/NumLib/TestFe.cpp
@@ -119,7 +119,7 @@ class NumLibFemIsoTest : public ::testing::Test, public T::TestFeType
         setIdentityMatrix(dim, D);
         D *= conductivity;
         MeshLib::ElementCoordinatesMappingLocal ele_local_coord(
-            *mesh_element, MeshLib::CoordinateSystem(*mesh_element));
+            *mesh_element, MeshLib::CoordinateSystem(*mesh_element).getDimension());
         auto R = ele_local_coord.getRotationMatrixToGlobal().topLeftCorner(
             TestFeType::dim, TestFeType::global_dim);
         globalD.noalias() = R.transpose() * (D * R);
@@ -161,7 +161,7 @@ template <class T>
 const double NumLibFemIsoTest<T>::conductivity = 1e-11;
 
 template <class T>
-const double NumLibFemIsoTest<T>::eps = std::numeric_limits<double>::epsilon();
+const double NumLibFemIsoTest<T>::eps = 2*std::numeric_limits<double>::epsilon();
 
 template <class T>
 const unsigned NumLibFemIsoTest<T>::dim;
@@ -194,7 +194,8 @@ TYPED_TEST(NumLibFemIsoTest, CheckMassMatrix)
     for (std::size_t i=0; i < this->integration_method.getNumberOfPoints(); i++) {
         shape.setZero();
         auto wp = this->integration_method.getWeightedPoint(i);
-        fe.template computeShapeFunctions<ShapeMatrixType::N_J>(wp.getCoords(), shape);
+        fe.template computeShapeFunctions<ShapeMatrixType::N_J>(
+            wp.getCoords(), shape, this->global_dim);
         M.noalias() += shape.N.transpose() * shape.N * shape.detJ * wp.getWeight();
     }
     //std::cout << "M=\n" << M;
@@ -218,7 +219,8 @@ TYPED_TEST(NumLibFemIsoTest, CheckLaplaceMatrix)
     for (std::size_t i=0; i < this->integration_method.getNumberOfPoints(); i++) {
         shape.setZero();
         auto wp = this->integration_method.getWeightedPoint(i);
-        fe.template computeShapeFunctions<ShapeMatrixType::DNDX>(wp.getCoords(), shape);
+        fe.template computeShapeFunctions<ShapeMatrixType::DNDX>(
+            wp.getCoords(), shape, this->global_dim);
         K.noalias() += shape.dNdx.transpose() * this->globalD * shape.dNdx * shape.detJ * wp.getWeight();
     }
     //std::cout << "K=\n" << K << std::endl;
@@ -244,7 +246,7 @@ TYPED_TEST(NumLibFemIsoTest, CheckMassLaplaceMatrices)
     for (std::size_t i=0; i < this->integration_method.getNumberOfPoints(); i++) {
         shape.setZero();
         auto wp = this->integration_method.getWeightedPoint(i);
-        fe.computeShapeFunctions(wp.getCoords(), shape);
+        fe.computeShapeFunctions(wp.getCoords(), shape, this->global_dim);
         M.noalias() += shape.N.transpose() * shape.N * shape.detJ * wp.getWeight();
         K.noalias() += shape.dNdx.transpose() * (this->globalD * shape.dNdx) * shape.detJ * wp.getWeight();
     }
diff --git a/Tests/NumLib/TestFunctionInterpolation.cpp b/Tests/NumLib/TestFunctionInterpolation.cpp
index c2b951dbfe4..f8012ebda9e 100644
--- a/Tests/NumLib/TestFunctionInterpolation.cpp
+++ b/Tests/NumLib/TestFunctionInterpolation.cpp
@@ -71,7 +71,7 @@ TEST(NumLibFunctionInterpolationTest, Linear1DElement)
 
     finite_element.computeShapeFunctions(
             integration_method.getWeightedPoint(0).getCoords(),
-            shape_matrix);
+            shape_matrix, ShapeFunction::DIM); // TODO check DIM
     ASSERT_EQ(2, shape_matrix.N.size());
 
     // actual test
-- 
GitLab