jointI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 inline Foam::RBD::joint::joint(const rigidBodyModel& model, const label nDoF)
29 :
30  model_(model),
31  S_(nDoF),
32  index_(0),
33  qIndex_(0)
34 {}
35 
36 
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 
40 {
41  return S_.size();
42 }
43 
45 {
46  return false;
47 }
48 
49 inline Foam::label Foam::RBD::joint::index() const
50 {
51  return index_;
52 }
53 
54 inline Foam::label Foam::RBD::joint::qIndex() const
55 {
56  return qIndex_;
57 }
58 
60 {
61  return S_;
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
66 
67 inline void Foam::RBD::joint::operator=(const joint& j)
68 {
69  S_ = j.S_;
70  index_ = j.index_;
71  qIndex_ = j.qIndex_;
72 }
73 
74 
76 (
77  const scalarField& q
78 ) const
79 {
80  if (!unitQuaternion())
81  {
83  << "Attempt to get the quaternion for a non-spherical joint"
84  << abort(FatalError);
85  }
86 
87  return quaternion::unit(q.block<vector>(qIndex_));
88 }
89 
90 
92 (
93  const quaternion& quat,
94  scalarField& q
95 ) const
96 {
97  if (!unitQuaternion())
98  {
100  << "Attempt to set quaternion for a non-spherical joint"
101  << abort(FatalError);
102  }
103 
104  q[qIndex_] = quat.v().x();
105  q[qIndex_+1] = quat.v().y();
106  q[qIndex_+2] = quat.v().z();
107 }
108 
109 
110 Foam::autoPtr<Foam::RBD::joint> Foam::RBD::joint::iNew::operator()
111 (
112  Istream& is
113 ) const
114 {
115  dictionary dict(is);
116  return New(model_, dict);
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
121 
123 {
124  os << indent << token::BEGIN_BLOCK << incrIndent << endl;
125  j.write(os);
126  os << decrIndent << indent << token::END_BLOCK;
127 
128  return os;
129 }
130 
131 
132 // ************************************************************************* //
VSForm block(const label start) const
Definition: Field.C:527
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Abstract base-class for all rigid-body joints.
Definition: joint.H:81
joint(const rigidBodyModel &model, const label nDoF)
Construct joint setting the size of the motion sub-space.
Definition: jointI.H:28
List< spatialVector > S_
Joint motion sub-space.
Definition: joint.H:91
virtual void write(Ostream &) const
Write.
Definition: joint.C:82
label qIndex_
Index of this joints data in the rigidBodyModel state.
Definition: joint.H:97
label nDoF() const
Return the number of degrees of freedom in this joint.
Definition: jointI.H:39
const List< spatialVector > & S() const
Return the joint motion sub-space.
Definition: jointI.H:59
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
Definition: jointI.H:44
label index_
Index of this joint in the rigidBodyModel.
Definition: joint.H:94
void operator=(const joint &j)
Assignment.
Definition: jointI.H:67
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:61
const vector & v() const
Vector part of the quaternion ( = axis of rotation)
Definition: quaternionI.H:260
static quaternion unit(const vector &v)
Return the unit quaternion (versor) from the given vector.
Definition: quaternionI.H:81
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Ostream & operator<<(Ostream &, const rigidBody &)
Definition: rigidBodyI.H:73
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
dictionary dict