From 710a717c67303fb002eadf10666a7a7d4fc04283 Mon Sep 17 00:00:00 2001 From: Andrew Heather <a.heather@opencfd.co.uk> Date: Thu, 18 Jan 2018 09:26:22 +0000 Subject: [PATCH] ENH: sixDoFRigidBodyState relocated and code improvements. Fixes #711 --- src/Allwmake | 1 + .../sixDoFRigidBodyState/Make/files | 0 .../sixDoFRigidBodyState/Make/options | 0 .../sixDoFRigidBodyState.C | 126 +++++++++++------- .../sixDoFRigidBodyState.H | 29 ++-- 5 files changed, 100 insertions(+), 56 deletions(-) rename src/{functionObjects => }/sixDoFRigidBodyState/Make/files (100%) rename src/{functionObjects => }/sixDoFRigidBodyState/Make/options (100%) rename src/{functionObjects => }/sixDoFRigidBodyState/sixDoFRigidBodyState.C (61%) rename src/{functionObjects => }/sixDoFRigidBodyState/sixDoFRigidBodyState.H (84%) diff --git a/src/Allwmake b/src/Allwmake index c91fb6de5c8..c7fbd7d2ca1 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -79,6 +79,7 @@ functionObjects/Allwmake $targetType $* wmake $targetType lumpedPointMotion wmake $targetType sixDoFRigidBodyMotion +wmake $targetType sixDoFRigidBodyState wmake $targetType rigidBodyDynamics wmake $targetType rigidBodyMeshMotion diff --git a/src/functionObjects/sixDoFRigidBodyState/Make/files b/src/sixDoFRigidBodyState/Make/files similarity index 100% rename from src/functionObjects/sixDoFRigidBodyState/Make/files rename to src/sixDoFRigidBodyState/Make/files diff --git a/src/functionObjects/sixDoFRigidBodyState/Make/options b/src/sixDoFRigidBodyState/Make/options similarity index 100% rename from src/functionObjects/sixDoFRigidBodyState/Make/options rename to src/sixDoFRigidBodyState/Make/options diff --git a/src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.C b/src/sixDoFRigidBodyState/sixDoFRigidBodyState.C similarity index 61% rename from src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.C rename to src/sixDoFRigidBodyState/sixDoFRigidBodyState.C index dd7dde334d4..a77e0dc024d 100644 --- a/src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.C +++ b/src/sixDoFRigidBodyState/sixDoFRigidBodyState.C @@ -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; } diff --git a/src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.H b/src/sixDoFRigidBodyState/sixDoFRigidBodyState.H similarity index 84% rename from src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.H rename to src/sixDoFRigidBodyState/sixDoFRigidBodyState.H index 731a2909ed9..e35e14044a0 100644 --- a/src/functionObjects/sixDoFRigidBodyState/sixDoFRigidBodyState.H +++ b/src/sixDoFRigidBodyState/sixDoFRigidBodyState.H @@ -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: -- GitLab