Commit 8716ca25 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: sixDoFRigidBodyState relocated and code improvements. Fixes #711

parent e3c4696a
......@@ -79,6 +79,7 @@ functionObjects/Allwmake $targetType $*
wmake $targetType lumpedPointMotion
wmake $targetType sixDoFRigidBodyMotion
wmake $targetType sixDoFRigidBodyState
wmake $targetType rigidBodyDynamics
wmake $targetType rigidBodyMeshMotion
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -46,6 +46,34 @@ namespace functionObjects
}
}
const Foam::Enum
<
Foam::functionObjects::sixDoFRigidBodyState::angleTypes
>
Foam::functionObjects::sixDoFRigidBodyState::angleTypeNames_
{
{ angleTypes::RADIANS, "radians" },
{ angleTypes::DEGREES, "degrees" }
};
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::sixDoFRigidBodyState::writeFileHeader(Ostream& os)
{
writeHeader(os, "Motion State");
writeHeaderValue(os, "Angle Units", angleTypeNames_[angleFormat_]);
writeCommented(os, "Time");
os << tab
<< "centreOfRotation" << tab
<< "centreOfMass" << tab
<< "rotation" << tab
<< "velocity" << tab
<< "omega" << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -57,10 +85,11 @@ Foam::functionObjects::sixDoFRigidBodyState::sixDoFRigidBodyState
)
:
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name)
writeFile(mesh_, name, typeName, dict),
angleFormat_(angleTypes::RADIANS)
{
read(dict);
resetName(typeName);
writeFileHeader(file());
}
......@@ -74,27 +103,20 @@ Foam::functionObjects::sixDoFRigidBodyState::~sixDoFRigidBodyState()
bool Foam::functionObjects::sixDoFRigidBodyState::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
return true;
}
void Foam::functionObjects::sixDoFRigidBodyState::writeFileHeader(const label)
{
OFstream& file = this->file();
writeHeader(file, "Motion State");
writeHeaderValue(file, "Angle Units", angleFormat_);
writeCommented(file, "Time");
if (fvMeshFunctionObject::read(dict))
{
angleFormat_ =
angleTypeNames_.lookupOrDefault
(
"angleFormat",
dict,
angleTypes::RADIANS
);
return true;
}
file<< tab
<< "centreOfRotation" << tab
<< "centreOfMass" << tab
<< "rotation" << tab
<< "velocity" << tab
<< "omega" << endl;
return false;
}
......@@ -106,26 +128,29 @@ bool Foam::functionObjects::sixDoFRigidBodyState::execute()
bool Foam::functionObjects::sixDoFRigidBodyState::write()
{
logFiles::write();
if (Pstream::master())
{
const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);
const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);
const sixDoFRigidBodyMotionSolver& motionSolver_ =
refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());
const sixDoFRigidBodyMotionSolver& motionSolver_ =
refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());
const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
vector rotationAngle
(
quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
);
vector rotationAngle
(
quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
);
vector angularVelocity(motion.omega());
vector angularVelocity(motion.omega());
if (angleFormat_ == "degrees")
switch (angleFormat_)
{
case angleTypes::RADIANS:
{
// Nothing to do - already in radians
break;
}
case angleTypes::DEGREES:
{
rotationAngle.x() = radToDeg(rotationAngle.x());
rotationAngle.y() = radToDeg(rotationAngle.y());
......@@ -134,18 +159,25 @@ bool Foam::functionObjects::sixDoFRigidBodyState::write()
angularVelocity.x() = radToDeg(angularVelocity.x());
angularVelocity.y() = radToDeg(angularVelocity.y());
angularVelocity.z() = radToDeg(angularVelocity.z());
break;
}
default:
{
FatalErrorInFunction
<< "Unhandled enumeration " << angleTypeNames_[angleFormat_]
<< abort(FatalError);
}
writeTime(file());
file()
<< tab
<< motion.centreOfRotation() << tab
<< motion.centreOfMass() << tab
<< rotationAngle << tab
<< motion.v() << tab
<< angularVelocity << endl;
}
writeTime(file());
file()
<< tab
<< motion.centreOfRotation() << tab
<< motion.centreOfMass() << tab
<< rotationAngle << tab
<< motion.v() << tab
<< angularVelocity << endl;
return true;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -25,7 +25,7 @@ Class
Foam::functionObjects::sixDoFRigidBodyState
Group
grpFieldFunctionObjects
grpSixDoFRigidBodyFunctionObjects
Description
Writes the 6-DoF motion state.
......@@ -49,7 +49,7 @@ Usage
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
Foam::functionObjects::writeFile
SourceFiles
sixDoFRigidBodyState.C
......@@ -60,7 +60,8 @@ SourceFiles
#define sixDoFRigidBodyState_H
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "writeFile.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -70,17 +71,27 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class sixDoFRigidBodyState Declaration
Class sixDoFRigidBodyState Declaration
\*---------------------------------------------------------------------------*/
class sixDoFRigidBodyState
:
public fvMeshFunctionObject,
public logFiles
public writeFile
{
// Private data
word angleFormat_;
enum class angleTypes
{
RADIANS, //!< Radians
DEGREES //!< Degrees
};
//- Angle type names
static const Enum<angleTypes> angleTypeNames_;
//- Angle format
angleTypes angleFormat_;
// Private Member Functions
......@@ -96,8 +107,8 @@ protected:
// Protected Member Functions
//- overloaded writeFileHeader from writeFile
virtual void writeFileHeader(const label i = 0);
//- Overloaded writeFileHeader from writeFile
virtual void writeFileHeader(Ostream& os);
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment