septernion.C
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) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "septernion.H"
29 #include "IOstreams.H"
30 #include "StringStream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 const char* const Foam::septernion::typeName = "septernion";
36 (
37  vector(0, 0, 0),
38  quaternion(0, vector(0, 0, 0))
39 );
41 (
42  vector(0, 0, 0),
43  quaternion(1, vector(0, 0, 0))
44 );
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 {
50  is >> *this;
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
57 {
58  OStringStream buf;
59  buf << '(' << s.t() << ',' << s.r() << ')';
60  return buf.str();
61 }
62 
63 
65 (
66  const septernion& sa,
67  const septernion& sb,
68  const scalar t
69 )
70 {
71  return septernion((1 - t)*sa.t() + t*sb.t(), slerp(sa.r(), sb.r(), t));
72 }
73 
74 
76 (
77  const UList<septernion>& ss,
78  const UList<scalar> w
79 )
80 {
81  septernion sa(w[0]*ss[0]);
82 
83  for (label i=1; i<ss.size(); i++)
84  {
85  sa.t() += w[i]*ss[i].t();
86 
87  // Invert quaternion if it has the opposite sign to the average
88  if ((sa.r() & ss[i].r()) > 0)
89  {
90  sa.r() += w[i]*ss[i].r();
91  }
92  else
93  {
94  sa.r() -= w[i]*ss[i].r();
95  }
96  }
97 
98  sa.r().normalize();
99 
100  return sa;
101 }
102 
103 
104 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
105 
107 {
108  is.readBegin("septernion");
109 
110  is >> s.t() >> s.r();
111 
112  is.readEnd("septernion");
113 
114  is.check(FUNCTION_NAME);
115  return is;
116 }
117 
118 
120 {
121  os << token::BEGIN_LIST
122  << s.t() << token::SPACE << s.r()
123  << token::END_LIST;
124 
125  return os;
126 }
127 
128 
129 // ************************************************************************* //
Foam::quaternion::normalize
void normalize()
Normalize the quaternion by its magnitude.
Definition: quaternionI.H:319
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::septernion
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:66
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::slerp
quaternion slerp(const quaternion &qa, const quaternion &qb, const scalar t)
Spherical linear interpolation of quaternions.
Definition: quaternion.C:78
Foam::septernion::zero
static const septernion zero
Definition: septernion.H:83
StringStream.H
Input/output from string buffers.
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:127
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:109
septernion.H
Foam::label
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:62
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::septernion::t
const vector & t() const
Definition: septernionI.H:60
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:92
Foam::septernion::septernion
septernion()
Construct null.
Definition: septernionI.H:30
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:189
Foam::token::SPACE
Space [isspace].
Definition: token.H:112
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::septernion::I
static const septernion I
Definition: septernion.H:84
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:118
Foam::septernion::r
const quaternion & r() const
Definition: septernionI.H:66
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::septernion::typeName
static const char *const typeName
Definition: septernion.H:81
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:117
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:328