Skip to content
Snippets Groups Projects
Commit 710a717c authored by Andrew Heather's avatar Andrew Heather Committed by Mark OLESEN
Browse files

ENH: sixDoFRigidBodyState relocated and code improvements. Fixes #711

parent 55182e74
Branches
No related merge requests found
...@@ -79,6 +79,7 @@ functionObjects/Allwmake $targetType $* ...@@ -79,6 +79,7 @@ functionObjects/Allwmake $targetType $*
wmake $targetType lumpedPointMotion wmake $targetType lumpedPointMotion
wmake $targetType sixDoFRigidBodyMotion wmake $targetType sixDoFRigidBodyMotion
wmake $targetType sixDoFRigidBodyState
wmake $targetType rigidBodyDynamics wmake $targetType rigidBodyDynamics
wmake $targetType rigidBodyMeshMotion wmake $targetType rigidBodyMeshMotion
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -46,6 +46,34 @@ namespace functionObjects ...@@ -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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
...@@ -57,10 +85,11 @@ Foam::functionObjects::sixDoFRigidBodyState::sixDoFRigidBodyState ...@@ -57,10 +85,11 @@ Foam::functionObjects::sixDoFRigidBodyState::sixDoFRigidBodyState
) )
: :
fvMeshFunctionObject(name, runTime, dict), fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name) writeFile(mesh_, name, typeName, dict),
angleFormat_(angleTypes::RADIANS)
{ {
read(dict); read(dict);
resetName(typeName); writeFileHeader(file());
} }
...@@ -74,27 +103,20 @@ Foam::functionObjects::sixDoFRigidBodyState::~sixDoFRigidBodyState() ...@@ -74,27 +103,20 @@ Foam::functionObjects::sixDoFRigidBodyState::~sixDoFRigidBodyState()
bool Foam::functionObjects::sixDoFRigidBodyState::read(const dictionary& dict) bool Foam::functionObjects::sixDoFRigidBodyState::read(const dictionary& dict)
{ {
fvMeshFunctionObject::read(dict); if (fvMeshFunctionObject::read(dict))
angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians"); {
angleFormat_ =
return true; angleTypeNames_.lookupOrDefault
} (
"angleFormat",
dict,
void Foam::functionObjects::sixDoFRigidBodyState::writeFileHeader(const label) angleTypes::RADIANS
{ );
OFstream& file = this->file();
return true;
writeHeader(file, "Motion State"); }
writeHeaderValue(file, "Angle Units", angleFormat_);
writeCommented(file, "Time");
file<< tab return false;
<< "centreOfRotation" << tab
<< "centreOfMass" << tab
<< "rotation" << tab
<< "velocity" << tab
<< "omega" << endl;
} }
...@@ -106,26 +128,29 @@ bool Foam::functionObjects::sixDoFRigidBodyState::execute() ...@@ -106,26 +128,29 @@ bool Foam::functionObjects::sixDoFRigidBodyState::execute()
bool Foam::functionObjects::sixDoFRigidBodyState::write() bool Foam::functionObjects::sixDoFRigidBodyState::write()
{ {
logFiles::write(); const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);
if (Pstream::master())
{
const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);
const sixDoFRigidBodyMotionSolver& motionSolver_ = const sixDoFRigidBodyMotionSolver& motionSolver_ =
refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion()); refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());
const sixDoFRigidBodyMotion& motion = motionSolver_.motion(); const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
vector rotationAngle vector rotationAngle
( (
quaternion(motion.orientation()).eulerAngles(quaternion::XYZ) 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.x() = radToDeg(rotationAngle.x());
rotationAngle.y() = radToDeg(rotationAngle.y()); rotationAngle.y() = radToDeg(rotationAngle.y());
...@@ -134,18 +159,25 @@ bool Foam::functionObjects::sixDoFRigidBodyState::write() ...@@ -134,18 +159,25 @@ bool Foam::functionObjects::sixDoFRigidBodyState::write()
angularVelocity.x() = radToDeg(angularVelocity.x()); angularVelocity.x() = radToDeg(angularVelocity.x());
angularVelocity.y() = radToDeg(angularVelocity.y()); angularVelocity.y() = radToDeg(angularVelocity.y());
angularVelocity.z() = radToDeg(angularVelocity.z()); 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; return true;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -25,7 +25,7 @@ Class ...@@ -25,7 +25,7 @@ Class
Foam::functionObjects::sixDoFRigidBodyState Foam::functionObjects::sixDoFRigidBodyState
Group Group
grpFieldFunctionObjects grpSixDoFRigidBodyFunctionObjects
Description Description
Writes the 6-DoF motion state. Writes the 6-DoF motion state.
...@@ -49,7 +49,7 @@ Usage ...@@ -49,7 +49,7 @@ Usage
See also See also
Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles Foam::functionObjects::writeFile
SourceFiles SourceFiles
sixDoFRigidBodyState.C sixDoFRigidBodyState.C
...@@ -60,7 +60,8 @@ SourceFiles ...@@ -60,7 +60,8 @@ SourceFiles
#define sixDoFRigidBodyState_H #define sixDoFRigidBodyState_H
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "logFiles.H" #include "writeFile.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -70,17 +71,27 @@ namespace functionObjects ...@@ -70,17 +71,27 @@ namespace functionObjects
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class sixDoFRigidBodyState Declaration Class sixDoFRigidBodyState Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class sixDoFRigidBodyState class sixDoFRigidBodyState
: :
public fvMeshFunctionObject, public fvMeshFunctionObject,
public logFiles public writeFile
{ {
// Private data // 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 // Private Member Functions
...@@ -96,8 +107,8 @@ protected: ...@@ -96,8 +107,8 @@ protected:
// Protected Member Functions // Protected Member Functions
//- overloaded writeFileHeader from writeFile //- Overloaded writeFileHeader from writeFile
virtual void writeFileHeader(const label i = 0); virtual void writeFileHeader(Ostream& os);
public: public:
......
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