From 3a0ebe2a955eba953c2301b78adecf207ee0583a Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Tue, 7 Jul 2020 13:48:21 +0200
Subject: [PATCH] Implement calculation of Nlr (face normal at node) in 2D

---
 src/mesh/MeshData.hpp | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp
index 01eccadce..6a525a6aa 100644
--- a/src/mesh/MeshData.hpp
+++ b/src/mesh/MeshData.hpp
@@ -105,7 +105,25 @@ class MeshData : public IMeshData
     if constexpr (Dimension == 1) {
       static_assert(Dimension != 1, "Nlr does not make sense in 1d");
     } else if constexpr (Dimension == 2) {
-      throw NotImplementedError("Nlr are not yet computed in 2d");
+      const NodeValue<const Rd>& xr = m_mesh.xr();
+
+      NodeValuePerFace<Rd> Nlr(m_mesh.connectivity());
+      const auto& face_to_node_matrix = m_mesh.connectivity().faceToNodeMatrix();
+
+      parallel_for(
+        m_mesh.numberOfFaces(), PUGS_LAMBDA(FaceId l) {
+          const auto& face_nodes = face_to_node_matrix[l];
+
+          const Rd xr0 = xr[face_nodes[0]];
+          const Rd xr1 = xr[face_nodes[1]];
+          const Rd dx  = xr1 - xr0;
+
+          const Rd Nr = 0.5 * Rd{dx[1], -dx[0]};
+
+          Nlr(l, 0) = Nr;
+          Nlr(l, 1) = Nr;
+        });
+      m_Nlr = std::make_shared<NodeValuePerFace<const Rd>>(Nlr);
     } else {
       const NodeValue<const Rd>& xr = m_mesh.xr();
 
-- 
GitLab