From e809171540f804af238ddffce415b0de9ea922e9 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 18 Mar 2016 21:52:27 +0000 Subject: [PATCH] SpatialVector: Added cross-product and dual cross-product operators SpatialTensor: Added SpatialVector cross-product and dual cross-product -> SpatialTensor operators --- .../SpatialTensor/SpatialTensorI.H | 55 +++++++++++++- .../SpatialVector/SpatialVector.H | 18 +++++ .../SpatialVector/SpatialVectorI.H | 75 +++++++++++++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H index 4f76522bf..f3d431bce 100644 --- a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H +++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H @@ -23,6 +23,8 @@ License \*---------------------------------------------------------------------------*/ +#include "Identity.H" + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -131,7 +133,7 @@ inline Foam::SpatialTensor::SpatialTensor(Istream& is) {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline void Foam::SpatialTensor::operator=(const Foam::zero z) @@ -140,4 +142,55 @@ inline void Foam::SpatialTensor::operator=(const Foam::zero z) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + +//- Return the cross-product tensor +template +inline Foam::SpatialTensor operator^ +( + const SpatialVector& v, + const Identity& +) +{ + return SpatialTensor + ( + 0, -v.wz(), v.wy(), 0, 0, 0, + v.wz(), 0, -v.wx(), 0, 0, 0, + -v.wy(), v.wx(), 0, 0, 0, 0, + 0, -v.lz(), v.ly(), 0, -v.wz(), v.wy(), + v.lz(), 0, -v.lx(), v.wz(), 0, -v.wx(), + -v.ly(), v.lx(), 0, -v.wy(), v.wx(), 0 + ); +} + + +//- Return the dual cross-product tensor +template +inline Foam::SpatialTensor operator^ +( + const SpatialVector& f, + const typename Identity::dual& +) +{ + return SpatialTensor + ( + 0, -f.wz(), f.wy(), 0, -f.lz(), f.ly(), + f.wz(), 0, -f.wx(), f.lz(), 0, -f.lx(), + -f.wy(), f.wx(), 0, -f.ly(), f.lx(), 0, + 0, 0, 0, 0, -f.wz(), f.wy(), + 0, 0, 0, f.wz(), 0, -f.wx(), + 0, 0, 0, -f.wy(), f.wx(), 0 + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVector.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVector.H index d60710d30..33741f314 100644 --- a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVector.H +++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVector.H @@ -71,6 +71,21 @@ public: enum components { WX, WY, WZ, LX, LY, LZ }; + //- Class to represent the dual spatial vector + class dual + { + const SpatialVector& v_; + + public: + + //- Construct the dual of the given SpatialVector + inline dual(const SpatialVector& v); + + //- Return the parent SpatialVector + inline const SpatialVector& v() const; + }; + + // Constructors //- Construct null @@ -137,6 +152,9 @@ public: // Member Operators inline void operator=(const Foam::zero); + + //- Return the dual spatial vector + inline dual operator*() const; }; diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H index 6dd73d36f..9c8c862c5 100644 --- a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H +++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H @@ -90,6 +90,13 @@ inline Foam::SpatialVector::SpatialVector(Istream& is) {} +template +inline Foam::SpatialVector::dual::dual(const SpatialVector& v) +: + v_(v) +{} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -189,6 +196,13 @@ inline Foam::Vector Foam::SpatialVector::l() const } +template +const Foam::SpatialVector& Foam::SpatialVector::dual::v() const +{ + return v_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template @@ -198,4 +212,65 @@ inline void Foam::SpatialVector::operator=(const Foam::zero z) } +template +inline typename Foam::SpatialVector::dual +Foam::SpatialVector::operator*() const +{ + return dual(*this); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + +//- Return the cross-product between two spatial vectors +template +inline SpatialVector operator^ +( + const SpatialVector& u, + const SpatialVector& v +) +{ + return SpatialVector + ( + -u.wz()*v.wy() + u.wy()*v.wz(), + u.wz()*v.wx() - u.wx()*v.wz(), + -u.wy()*v.wx() + u.wx()*v.wy(), + -u.lz()*v.wy() + u.ly()*v.wz() - u.wz()*v.ly() + u.wy()*v.lz(), + u.lz()*v.wx() - u.lx()*v.wz() + u.wz()*v.lx() - u.wx()*v.lz(), + -u.ly()*v.wx() + u.lx()*v.wy() - u.wy()*v.lx() + u.wx()*v.ly() + ); +} + + +//- Return the dual cross-product between two spatial vectors +template +inline SpatialVector operator^ +( + const SpatialVector& v, + const typename SpatialVector::dual& df +) +{ + const SpatialVector& f = df.v(); + + return SpatialVector + ( + -v.wz()*f.wy() + v.wy()*f.wz() - v.lz()*f.ly() + v.ly()*f.lz(), + v.wz()*f.wx() - v.wx()*f.wz() + v.lz()*f.lx() - v.lx()*f.lz(), + -v.wy()*f.wx() + v.wx()*f.wy() - v.ly()*f.lx() + v.lx()*f.ly(), + -v.wz()*f.ly() + v.wy()*f.lz(), + v.wz()*f.lx() - v.wx()*f.lz(), + -v.wy()*f.lx() + v.wx()*f.ly() + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + // ************************************************************************* //