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-2018 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 
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 // ************************************************************************* //
Abstract base-class for all rigid-body joints.
Definition: joint.H:80
Ostream & operator<<(Ostream &, const rigidBody &)
Definition: rigidBodyI.H:73
dictionary dict
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 & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
label qIndex_
Index of this joints data in the rigidBodyModel state.
Definition: joint.H:97
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static quaternion unit(const vector &v)
Return the unit quaternion (versor) from the given vector.
Definition: quaternionI.H:81
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void operator=(const joint &j)
Assignment.
Definition: jointI.H:67
const Cmpt & z() const
Definition: VectorI.H:87
label index_
Index of this joint in the rigidBodyModel.
Definition: joint.H:94
const Cmpt & y() const
Definition: VectorI.H:81
virtual void write(Ostream &) const
Write.
Definition: joint.C:82
const vector & v() const
Vector part of the quaternion ( = axis of rotation)
Definition: quaternionI.H:260
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
VSForm block(const label start) const
Definition: Field.C:508
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const Cmpt & x() const
Definition: VectorI.H:75
joint(const rigidBodyModel &model, const label nDoF)
Construct joint setting the size of the motion sub-space.
Definition: jointI.H:28
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
label nDoF() const
Return the number of degrees of freedom in this joint.
Definition: jointI.H:39
List< spatialVector > S_
Joint motion sub-space.
Definition: joint.H:91
const List< spatialVector > & S() const
Return the joint motion sub-space.
Definition: jointI.H:59
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
static autoPtr< joint > New(joint *jointPtr)
Simple selector to return an autoPtr<joint> of the given joint*.
Definition: joint.C:43
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const rigidBodyModel & model_
Reference to the model.
Definition: joint.H:88
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
Definition: jointI.H:44