src/OpenFOAM/primitives/spatialVectorAlgebra: New classes to support spatial vector algebra

Based on definitions in chapter 2 of the book:
    Featherstone, R. (2008).
    Rigid body dynamics algorithms.
    Springer.

This work is sponsored by Carnegie Wave Energy Ltd
This commit is contained in:
Henry Weller
2016-03-15 18:14:03 +00:00
parent 6057695f4f
commit 05455d50ea
15 changed files with 1530 additions and 0 deletions

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::SpatialVector
Description
Templated 3D spatial vector derived from VectorSpace used to represent the
anglular and linear components of position, velocity and acceleration of
rigid bodies.
Reference:
\verbatim
Featherstone, R. (2008).
Rigid body dynamics algorithms.
Springer.
\endverbatim
SourceFiles
SpatialVectorI.H
SeeAlso
Foam::VectorSpace
Foam::Vector
\*---------------------------------------------------------------------------*/
#ifndef SpatialVector_H
#define SpatialVector_H
#include "Vector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class SpatialVector Declaration
\*---------------------------------------------------------------------------*/
template<class Cmpt>
class SpatialVector
:
public VectorSpace<SpatialVector<Cmpt>, Cmpt, 6>
{
public:
// Constructors
//- Construct null
inline SpatialVector();
//- Construct initialized to zero
inline explicit SpatialVector(const Foam::zero);
//- Construct given VectorSpace of the same rank
inline SpatialVector(const typename SpatialVector::vsType&);
//- Construct from the angular and linear vector components
inline SpatialVector
(
const Vector<Cmpt>& angular,
const Vector<Cmpt>& linear
);
//- Construct given 6 components
inline SpatialVector
(
const Cmpt& v0,
const Cmpt& v1,
const Cmpt& v2,
const Cmpt& v3,
const Cmpt& v4,
const Cmpt& v5
);
//- Construct from Istream
inline SpatialVector(Istream&);
// Member Functions
//- Return the angular part of the spatial vector as a vector
inline Vector<Cmpt> angular() const;
//- Return the linear part of the spatial vector as a vector
inline Vector<Cmpt> linear() const;
// Member Operators
inline void operator=(const Foam::zero);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Include inline implementations
#include "SpatialVectorI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,117 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector()
{}
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector(const Foam::zero z)
:
SpatialVector::vsType(z)
{}
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector
(
const typename SpatialVector::vsType& vs
)
:
SpatialVector::vsType(vs)
{}
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector
(
const Vector<Cmpt>& angular,
const Vector<Cmpt>& linear
)
{
this->v_[0] = angular.x();
this->v_[1] = angular.y();
this->v_[2] = angular.z();
this->v_[3] = linear.x();
this->v_[4] = linear.y();
this->v_[5] = linear.z();
}
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector
(
const Cmpt& v0,
const Cmpt& v1,
const Cmpt& v2,
const Cmpt& v3,
const Cmpt& v4,
const Cmpt& v5
)
{
this->v_[0] = v0;
this->v_[1] = v1;
this->v_[2] = v2;
this->v_[3] = v3;
this->v_[4] = v4;
this->v_[5] = v5;
}
template<class Cmpt>
inline Foam::SpatialVector<Cmpt>::SpatialVector(Istream& is)
:
SpatialVector::vsType(is)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::Vector<Cmpt> Foam::SpatialVector<Cmpt>::angular() const
{
return Vector<Cmpt>(this->v_[0], this->v_[1], this->v_[2]);
}
template<class Cmpt>
inline Foam::Vector<Cmpt> Foam::SpatialVector<Cmpt>::linear() const
{
return Vector<Cmpt>(this->v_[3], this->v_[4], this->v_[5]);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Cmpt>
inline void Foam::SpatialVector<Cmpt>::operator=(const Foam::zero z)
{
SpatialVector::vsType::operator=(z);
}
// ************************************************************************* //

View File

@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
SpatialVector of scalars.
\*---------------------------------------------------------------------------*/
#include "spatialVector.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<>
const char* const Foam::spatialVector::vsType::typeName = "spatialVector";
template<>
const char* const Foam::spatialVector::vsType::componentNames[] =
{
"x", "y", "z"
};
template<>
const Foam::spatialVector Foam::spatialVector::vsType::zero
(
Foam::spatialVector::uniform(0)
);
template<>
const Foam::spatialVector Foam::spatialVector::vsType::one
(
spatialVector::uniform(1)
);
template<>
const Foam::spatialVector Foam::spatialVector::vsType::max
(
spatialVector::uniform(VGREAT)
);
template<>
const Foam::spatialVector Foam::spatialVector::vsType::min
(
spatialVector::uniform(-VGREAT)
);
template<>
const Foam::spatialVector Foam::spatialVector::vsType::rootMax
(
spatialVector::uniform(ROOTVGREAT)
);
template<>
const Foam::spatialVector Foam::spatialVector::vsType::rootMin
(
spatialVector::uniform(-ROOTVGREAT)
);
// ************************************************************************* //

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::spatialVector
Description
SpatialVector of scalars.
SourceFiles
spatialVector.C
\*---------------------------------------------------------------------------*/
#ifndef spatialVector_H
#define spatialVector_H
#include "SpatialVector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef SpatialVector<scalar> spatialVector;
//- Data associated with spatialVector type are contiguous
template<>
inline bool contiguous<spatialVector>() {return true;}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //