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-------------------------------------------------------------------------------
11License
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
35const 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().normalise();
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
114 return is;
115}
116
117
119{
121 << s.t() << token::SPACE << s.r()
123
124 return os;
125}
126
127
128// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Input/output from string buffers.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
quaternion & normalise()
Inplace normalise the quaternion by its magnitude.
Definition: quaternionI.H:309
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:67
septernion()=default
Default construct.
const quaternion & r() const
Definition: septernionI.H:74
static const septernion zero
Definition: septernion.H:83
static const septernion I
Definition: septernion.H:84
const vector & t() const
Definition: septernionI.H:68
static const char *const typeName
Definition: septernion.H:81
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
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))
#define FUNCTION_NAME
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
quaternion slerp(const quaternion &qa, const quaternion &qb, const scalar t)
Spherical linear interpolation of quaternions.
Definition: quaternion.C:82