SpatialVector: Added cross-product and dual cross-product operators

SpatialTensor: Added SpatialVector cross-product and dual cross-product -> SpatialTensor operators
This commit is contained in:
Henry Weller
2016-03-18 21:52:27 +00:00
parent e3bbe40748
commit e809171540
3 changed files with 147 additions and 1 deletions

View File

@ -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;
};

View File

@ -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
// ************************************************************************* //