From 679bc4ba66de83a01aa9e0a7f6b2da604331ea70 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Fri, 30 Oct 2020 12:23:41 +0100
Subject: [PATCH] Add Cartesian 1D, 2D and 3D meshes to the
 MeshDataBaseForTests

These mesh can be accessed using
```
MeshDataBaseForTests::instance().cartesianMesh<Dimension>();
```
where Dimension parameter is a constexpr integer.

The result is a `const Mesh<Connectivity<Dimension>>&`
---
 tests/MeshDataBaseForTests.cpp | 30 ++++++++++++++++++++++++++----
 tests/MeshDataBaseForTests.hpp | 13 +++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/tests/MeshDataBaseForTests.cpp b/tests/MeshDataBaseForTests.cpp
index 8a873625a..8debe252a 100644
--- a/tests/MeshDataBaseForTests.cpp
+++ b/tests/MeshDataBaseForTests.cpp
@@ -1,14 +1,19 @@
 #include <MeshDataBaseForTests.hpp>
-#include <utils/PugsAssert.hpp>
-
 #include <mesh/CartesianMeshBuilder.hpp>
+#include <mesh/Connectivity.hpp>
+#include <utils/PugsAssert.hpp>
 
 const MeshDataBaseForTests* MeshDataBaseForTests::m_instance = nullptr;
 
 MeshDataBaseForTests::MeshDataBaseForTests()
 {
-  std::make_shared<CartesianMeshBuilder>(TinyVector<3>{0, 1, 0}, TinyVector<3>{2, -1, 3},
-                                         TinyVector<3, size_t>{6, 7, 3});
+  m_cartesian_1d_mesh = CartesianMeshBuilder{TinyVector<1>{-1}, TinyVector<1>{3}, TinyVector<1, size_t>{23}}.mesh();
+
+  m_cartesian_2d_mesh =
+    CartesianMeshBuilder{TinyVector<2>{0, -1}, TinyVector<2>{3, 2}, TinyVector<2, size_t>{6, 7}}.mesh();
+
+  m_cartesian_3d_mesh =
+    CartesianMeshBuilder{TinyVector<3>{0, 1, 0}, TinyVector<3>{2, -1, 3}, TinyVector<3, size_t>{6, 7, 4}}.mesh();
 }
 
 const MeshDataBaseForTests&
@@ -31,3 +36,20 @@ MeshDataBaseForTests::destroy()
   delete m_instance;
   m_instance = nullptr;
 }
+
+template <size_t Dimension>
+const Mesh<Connectivity<Dimension>>&
+MeshDataBaseForTests::cartesianMesh() const
+{
+  if constexpr (Dimension == 1) {
+    return dynamic_cast<const Mesh<Connectivity<Dimension>>&>(*m_cartesian_1d_mesh);
+  } else if constexpr (Dimension == 2) {
+    return dynamic_cast<const Mesh<Connectivity<Dimension>>&>(*m_cartesian_2d_mesh);
+  } else if constexpr (Dimension == 3) {
+    return dynamic_cast<const Mesh<Connectivity<Dimension>>&>(*m_cartesian_3d_mesh);
+  }
+}
+
+template const Mesh<Connectivity<1>>& MeshDataBaseForTests::cartesianMesh<1>() const;
+template const Mesh<Connectivity<2>>& MeshDataBaseForTests::cartesianMesh<2>() const;
+template const Mesh<Connectivity<3>>& MeshDataBaseForTests::cartesianMesh<3>() const;
diff --git a/tests/MeshDataBaseForTests.hpp b/tests/MeshDataBaseForTests.hpp
index 31dad8f38..2a1b1c06c 100644
--- a/tests/MeshDataBaseForTests.hpp
+++ b/tests/MeshDataBaseForTests.hpp
@@ -3,6 +3,12 @@
 
 #include <mesh/IMesh.hpp>
 
+template <size_t Dimension>
+class Connectivity;
+
+template <typename ConnectivityT>
+class Mesh;
+
 #include <memory>
 
 class MeshDataBaseForTests
@@ -12,7 +18,14 @@ class MeshDataBaseForTests
 
   static const MeshDataBaseForTests* m_instance;
 
+  std::shared_ptr<const IMesh> m_cartesian_1d_mesh;
+  std::shared_ptr<const IMesh> m_cartesian_2d_mesh;
+  std::shared_ptr<const IMesh> m_cartesian_3d_mesh;
+
  public:
+  template <size_t Dimension>
+  const Mesh<Connectivity<Dimension>>& cartesianMesh() const;
+
   static const MeshDataBaseForTests& get();
   static void create();
   static void destroy();
-- 
GitLab