From 73c7534429f4998ef45cd34d1ec4ffce2805912a Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Fri, 29 Jun 2018 16:09:27 +0200
Subject: [PATCH] Added cross product for TinyVector<3,T>

- just remind that cross product is only defined for dimension 3 vectors
---
 src/algebra/TinyVector.hpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/algebra/TinyVector.hpp b/src/algebra/TinyVector.hpp
index 88f200720..35cdb5d35 100644
--- a/src/algebra/TinyVector.hpp
+++ b/src/algebra/TinyVector.hpp
@@ -10,7 +10,7 @@
 template <size_t N, typename T=double>
 class TinyVector
 {
-private:
+ private:
   T m_values[N];
   static_assert((N>0),"TinyVector size must be strictly positive");
 
@@ -26,7 +26,7 @@ private:
     this->_unpackVariadicInput(args...);
   }
 
-public:
+ public:
   KOKKOS_INLINE_FUNCTION
   TinyVector operator-() const
   {
@@ -247,4 +247,15 @@ T l2Norm(const TinyVector<N,T>& x)
   return std::sqrt((x,x));
 }
 
+// Cross product is only defined for K^3 vectors
+template <typename T>
+KOKKOS_INLINE_FUNCTION
+TinyVector<3,T> crossProduct(const TinyVector<3,T>& u, const TinyVector<3,T>& v)
+{
+  TinyVector<3,T> cross_product(u[1]*v[2]-u[2]*v[1],
+                                u[2]*v[0]-u[0]*v[2],
+                                u[0]*v[1]-u[1]*v[0]);
+  return std::move(cross_product);
+}
+
 #endif // TINYVECTOR_HPP
-- 
GitLab