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-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 #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 
52 Foam::functionObjects::sixDoFRigidBodyState::sixDoFRigidBodyState
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 {
109  logFiles::write();
110 
111  if (Pstream::master())
112  {
114  refCast<const dynamicMotionSolverFvMesh>(obr_);
115 
116  const sixDoFRigidBodyMotionSolver& motionSolver_ =
117  refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());
118 
119  const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
120 
121  vector rotationAngle
122  (
123  quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
124  );
125 
126  vector angularVelocity(motion.omega());
127 
128  if (angleFormat_ == "degrees")
129  {
130  rotationAngle.x() = radToDeg(rotationAngle.x());
131  rotationAngle.y() = radToDeg(rotationAngle.y());
132  rotationAngle.z() = radToDeg(rotationAngle.z());
133 
134  angularVelocity.x() = radToDeg(angularVelocity.x());
135  angularVelocity.y() = radToDeg(angularVelocity.y());
136  angularVelocity.z() = radToDeg(angularVelocity.z());
137  }
138 
139  writeTime(file());
140  file()
141  << tab
142  << motion.centreOfRotation() << tab
143  << motion.centreOfMass() << tab
144  << rotationAngle << tab
145  << motion.v() << tab
146  << angularVelocity << endl;
147  }
148 
149  return true;
150 }
151 
152 
153 // ************************************************************************* //
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.
6-DoF solid-body mesh motion solver for an fvMesh.
static const char tab
Definition: Ostream.H:264
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Unit conversion functions.
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:421
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.
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
A class for handling words, derived from string.
Definition: word.H:59
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
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.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, add, dictionary)
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57