All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sixDoFRigidBodyState.C
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) 2017-2019 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 #include "sixDoFRigidBodyState.H"
29 #include "unitConversion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(sixDoFRigidBodyState, 0);
39 
41  (
42  functionObject,
43  sixDoFRigidBodyState,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& name,
55  const Time& runTime,
56  const dictionary& dict
57 )
58 :
59  fvMeshFunctionObject(name, runTime, dict),
60  logFiles(obr_, name)
61 {
62  read(dict);
63  resetName(typeName);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
76 {
78  angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
79 
80  return true;
81 }
82 
83 
85 {
86  OFstream& file = this->file();
87 
88  writeHeader(file, "Motion State");
89  writeHeaderValue(file, "Angle Units", angleFormat_);
90  writeCommented(file, "Time");
91 
92  file<< tab
93  << "centreOfRotation" << tab
94  << "centreOfMass" << tab
95  << "rotation" << tab
96  << "velocity" << tab
97  << "omega" << endl;
98 }
99 
100 
102 {
103  return true;
104 }
105 
106 
108 Foam::functionObjects::sixDoFRigidBodyState::motion() const
109 {
111  refCast<const dynamicMotionSolverFvMesh>(obr_);
112 
113  return (refCast<const sixDoFRigidBodyMotion>(mesh.motion()));
114 }
115 
116 
119 {
120  return motion().v();
121 }
122 
123 
126 {
127  vector angularVelocity(motion().omega());
128 
129  if (angleFormat_ == "degrees")
130  {
131  angularVelocity.x() = radToDeg(angularVelocity.x());
132  angularVelocity.y() = radToDeg(angularVelocity.y());
133  angularVelocity.z() = radToDeg(angularVelocity.z());
134  }
135 
136  return angularVelocity;
137 }
138 
139 
141 {
142  logFiles::write();
143 
144  if (Pstream::master())
145  {
146  const sixDoFRigidBodyMotion& motion = this->motion();
147 
148  vector rotationAngle
149  (
150  quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
151  );
152 
153  vector angularVelocity(motion.omega());
154 
155  if (angleFormat_ == "degrees")
156  {
157  rotationAngle.x() = radToDeg(rotationAngle.x());
158  rotationAngle.y() = radToDeg(rotationAngle.y());
159  rotationAngle.z() = radToDeg(rotationAngle.z());
160 
161  angularVelocity.x() = radToDeg(angularVelocity.x());
162  angularVelocity.y() = radToDeg(angularVelocity.y());
163  angularVelocity.z() = radToDeg(angularVelocity.z());
164  }
165 
166  writeTime(file());
167  file()
168  << tab
169  << motion.centreOfRotation() << tab
170  << motion.centreOfMass() << tab
171  << rotationAngle << tab
172  << motion.v() << tab
173  << angularVelocity << endl;
174  }
175 
176  return true;
177 }
178 
179 
180 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
virtual bool write()
Write function.
Definition: logFiles.C:180
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
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
vector velocity() const
Return the current body velocity.
static const char tab
Definition: Ostream.H:259
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
point centreOfMass() const
Return the current centre of mass.
const point & centreOfRotation() const
Return the current centre of rotation.
Unit conversion functions.
Output to file stream.
Definition: OFstream.H:82
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
const Cmpt & z() const
Definition: VectorI.H:87
vector angularVelocity() const
Return the current body angular velocity.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
const Cmpt & y() const
Definition: VectorI.H:81
virtual bool execute()
Execute, currently does nothing.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
dynamicFvMesh & mesh
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
vector omega() const
Return the angular velocity in the global frame.
A class for handling words, derived from string.
Definition: word.H:59
const tensor & orientation() const
Return the orientation tensor, Q.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
virtual void writeFileHeader(const label i=0)
overloaded writeFileHeader from writeFile
const Cmpt & x() const
Definition: VectorI.H:75
defineTypeNameAndDebug(Qdot, 0)
sixDoFRigidBodyState(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool write()
Write the sixDoFRigidBodyState.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const motionSolver & motion() const
Return the motionSolver.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
The dynamicMotionSolverFvMesh.
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57