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  Copyright (C) 2020 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 \*---------------------------------------------------------------------------*/
28 
29 #include "septernion.H"
30 #include "IOstreams.H"
31 #include "StringStream.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 const char* const Foam::septernion::typeName = "septernion";
37 
39 (
40  vector(Zero),
41  quaternion(scalar(1))
42 );
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 {
49  is >> *this;
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
56 {
57  OStringStream buf;
58  buf << '(' << s.t() << ',' << s.r() << ')';
59  return buf.str();
60 }
61 
62 
64 (
65  const septernion& sa,
66  const septernion& sb,
67  const scalar t
68 )
69 {
70  return septernion((1 - t)*sa.t() + t*sb.t(), slerp(sa.r(), sb.r(), t));
71 }
72 
73 
75 (
76  const UList<septernion>& ss,
77  const UList<scalar> w
78 )
79 {
80  septernion sa(w[0]*ss[0]);
81 
82  for (label i=1; i<ss.size(); i++)
83  {
84  sa.t() += w[i]*ss[i].t();
85 
86  // Invert quaternion if it has the opposite sign to the average
87  if ((sa.r() & ss[i].r()) > 0)
88  {
89  sa.r() += w[i]*ss[i].r();
90  }
91  else
92  {
93  sa.r() -= w[i]*ss[i].r();
94  }
95  }
96 
97  sa.r().normalize();
98 
99  return sa;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
104 
106 {
107  is.readBegin("septernion");
108 
109  is >> s.t() >> s.r();
110 
111  is.readEnd("septernion");
112 
113  is.check(FUNCTION_NAME);
114  return is;
115 }
116 
117 
119 {
121  << s.t() << token::SPACE << s.r()
122  << token::END_LIST;
123 
124  return os;
125 }
126 
127 
128 // ************************************************************************* //
Foam::quaternion::normalize
void normalize()
Normalize the quaternion by its magnitude.
Definition: quaternionI.H:315
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:65
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::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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:230
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
septernion.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::septernion::t
const vector & t() const
Definition: septernionI.H:68
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
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:88
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
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:295
Foam::septernion::I
static const septernion I
Definition: septernion.H:84
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::septernion::r
const quaternion & r() const
Definition: septernionI.H:74
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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:155
Foam::septernion::septernion
septernion()=default
Default construct.
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:328