diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensorI.H index 4f76522bfe17f2036a9ee22f92ea0762269b7856..f3d431bce93f5fb1953063170e76ede1639ed27e 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<class Cmpt> @@ -131,7 +133,7 @@ inline Foam::SpatialTensor<Cmpt>::SpatialTensor(Istream& is) {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class Cmpt> inline void Foam::SpatialTensor<Cmpt>::operator=(const Foam::zero z) @@ -140,4 +142,55 @@ inline void Foam::SpatialTensor<Cmpt>::operator=(const Foam::zero z) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + +//- Return the cross-product tensor +template<class Cmpt> +inline Foam::SpatialTensor<Cmpt> operator^ +( + const SpatialVector<Cmpt>& v, + const Identity<Cmpt>& +) +{ + return SpatialTensor<Cmpt> + ( + 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<class Cmpt> +inline Foam::SpatialTensor<Cmpt> operator^ +( + const SpatialVector<Cmpt>& f, + const typename Identity<Cmpt>::dual& +) +{ + return SpatialTensor<Cmpt> + ( + 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 d60710d305bd7660c41ccb73fcd968320695bd7a..33741f31434138efb3dae028d29a2686269081cd 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 6dd73d36fc47f0f4416e41533ee28643ceaf850a..9c8c862c5dd4fc86f2b114b6577c5aa063d8dcbc 100644 --- a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H +++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialVector/SpatialVectorI.H @@ -90,6 +90,13 @@ inline Foam::SpatialVector<Cmpt>::SpatialVector(Istream& is) {} +template<class Cmpt> +inline Foam::SpatialVector<Cmpt>::dual::dual(const SpatialVector& v) +: + v_(v) +{} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Cmpt> @@ -189,6 +196,13 @@ inline Foam::Vector<Cmpt> Foam::SpatialVector<Cmpt>::l() const } +template<class Cmpt> +const Foam::SpatialVector<Cmpt>& Foam::SpatialVector<Cmpt>::dual::v() const +{ + return v_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class Cmpt> @@ -198,4 +212,65 @@ inline void Foam::SpatialVector<Cmpt>::operator=(const Foam::zero z) } +template<class Cmpt> +inline typename Foam::SpatialVector<Cmpt>::dual +Foam::SpatialVector<Cmpt>::operator*() const +{ + return dual(*this); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + +//- Return the cross-product between two spatial vectors +template<class Cmpt> +inline SpatialVector<Cmpt> operator^ +( + const SpatialVector<Cmpt>& u, + const SpatialVector<Cmpt>& v +) +{ + return SpatialVector<Cmpt> + ( + -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<class Cmpt> +inline SpatialVector<Cmpt> operator^ +( + const SpatialVector<Cmpt>& v, + const typename SpatialVector<Cmpt>::dual& df +) +{ + const SpatialVector<Cmpt>& f = df.v(); + + return SpatialVector<Cmpt> + ( + -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 + // ************************************************************************* //