SpatialVector.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::SpatialVector
29 
30 Description
31  Templated 3D spatial vector derived from VectorSpace used to represent the
32  anglular and linear components of position, velocity and acceleration of
33  rigid bodies.
34 
35  Reference:
36  \verbatim
37  Featherstone, R. (2008).
38  Rigid body dynamics algorithms.
39  Springer.
40  \endverbatim
41 
42 SourceFiles
43  SpatialVectorI.H
44 
45 See also
46  Foam::VectorSpace
47  Foam::Vector
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef Foam_SpatialVector_H
52 #define Foam_SpatialVector_H
53 
54 #include "Vector.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class SpatialVector Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class Cmpt>
66 class SpatialVector
67 :
68  public VectorSpace<SpatialVector<Cmpt>, Cmpt, 6>
69 {
70 
71 public:
72 
73  //- Component labeling enumeration
74  enum components { WX, WY, WZ, LX, LY, LZ };
75 
76 
77  //- Class to represent the dual spatial vector
78  class dual
79  {
80  const SpatialVector& v_;
81 
82  public:
83 
84  //- Construct the dual of the given SpatialVector
85  inline dual(const SpatialVector& v);
86 
87  //- Return the parent SpatialVector
88  inline const SpatialVector& v() const;
89  };
90 
91 
92  // Constructors
93 
94  //- Default construct
95  SpatialVector() = default;
96 
97  //- Construct initialized to zero
98  inline SpatialVector(const Foam::zero);
99 
100  //- Construct given VectorSpace of the same rank
101  inline SpatialVector(const typename SpatialVector::vsType&);
102 
103  //- Construct from the angular and linear vector components
104  inline SpatialVector
105  (
106  const Vector<Cmpt>& w,
107  const Vector<Cmpt>& l
108  );
109 
110  //- Construct given 6 components
111  inline SpatialVector
112  (
113  const Cmpt& wx,
114  const Cmpt& wy,
115  const Cmpt& wz,
116  const Cmpt& lx,
117  const Cmpt& ly,
118  const Cmpt& lz
119  );
120 
121  //- Construct from Istream
122  inline explicit SpatialVector(Istream&);
123 
124 
125  // Member Functions
126 
127  // Component Access
128 
129  const Cmpt& wx() const noexcept { return this->v_[WX]; }
130  const Cmpt& wy() const noexcept { return this->v_[WY]; }
131  const Cmpt& wz() const noexcept { return this->v_[WZ]; }
132 
133  const Cmpt& lx() const noexcept { return this->v_[LX]; }
134  const Cmpt& ly() const noexcept { return this->v_[LY]; }
135  const Cmpt& lz() const noexcept { return this->v_[LZ]; }
136 
137  Cmpt& wx() noexcept { return this->v_[WX]; }
138  Cmpt& wy() noexcept { return this->v_[WY]; }
139  Cmpt& wz() noexcept { return this->v_[WZ]; }
140 
141  Cmpt& lx() noexcept { return this->v_[LX]; }
142  Cmpt& ly() noexcept { return this->v_[LY]; }
143  Cmpt& lz() noexcept { return this->v_[LZ]; }
146  // Sub-vector access
147 
148  //- Return the angular part of the spatial vector as a vector
149  inline Vector<Cmpt> w() const;
151  //- Return the linear part of the spatial vector as a vector
152  inline Vector<Cmpt> l() const;
155  // Member Operators
157  //- Return the dual spatial vector
158  inline dual operator*() const;
159 };
160 
161 
162 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
163 
164 //- Data are contiguous if component type is contiguous
165 template<class Cmpt>
166 struct is_contiguous<SpatialVector<Cmpt>> : is_contiguous<Cmpt> {};
167 
168 //- Data are contiguous label if component type is label
169 template<class Cmpt>
170 struct is_contiguous_label<SpatialVector<Cmpt>>
171 :
172  is_contiguous_label<Cmpt>
173 {};
174 
175 //- Data are contiguous scalar if component type is scalar
176 template<class Cmpt>
177 struct is_contiguous_scalar<SpatialVector<Cmpt>>
178 :
179  is_contiguous_scalar<Cmpt>
180 {};
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 // Include inline implementations
190 #include "SpatialVectorI.H"
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
196 // ************************************************************************* //
const Cmpt & wx() const noexcept
components
Component labeling enumeration.
Definition: SpatialVector.H:71
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const Cmpt & wy() const noexcept
Templated vector space.
Definition: VectorSpace.H:52
const Cmpt & wz() const noexcept
dual operator*() const
Return the dual spatial vector.
Class to represent the dual spatial vector.
Definition: SpatialVector.H:77
const Cmpt & lz() const noexcept
const Cmpt & lx() const noexcept
const SpatialVector & v() const
Return the parent SpatialVector.
dual(const SpatialVector &v)
Construct the dual of the given SpatialVector.
Vector< Cmpt > l() const
Return the linear part of the spatial vector as a vector.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
Definition: Vector.H:58
const direction noexcept
Definition: Scalar.H:258
SpatialVector()=default
Default construct.
Templated 3D spatial vector derived from VectorSpace used to represent the anglular and linear compon...
Definition: SpatialVector.H:61
Vector< Cmpt > w() const
Return the angular part of the spatial vector as a vector.
A template class to specify that a data type can be considered as being contiguous in memory...
Definition: contiguous.H:70
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const Cmpt & ly() const noexcept
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
Namespace for OpenFOAM.