diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H index bfcc8262ca..7ca8a28cb4 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,7 +32,7 @@ inline Foam::point Foam::RBD::restraint::bodyPoint const point& p ) const { - return (model_.X0(bodyID_).inv() && spatialVector(Zero, p)).l(); + return model_.p(bodyID_, p); } diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H index 5759e534e1..ced8e0e864 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -320,10 +320,16 @@ public: spatialTransform X0(const label bodyId) const; // Find the corresponding point in the master body frame - vector masterPoint(const label bodyID, const vector& p) const; + inline vector masterPoint(const label bodyID, const vector& p) const; + + //- Return the current position of the given point on the given body + inline vector p(const label bodyID, const vector& p) const; //- Return the velocity of the given point on the given body - spatialVector v(const label bodyID, const vector& p) const; + inline spatialVector v(const label bodyID, const vector& p) const; + + //- Return the acceleration of the given point on the given body + inline spatialVector a(const label bodyID, const vector& p) const; //- Apply the restraints and accumulate the internal joint forces // into the tau field and external forces into the fx field diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H index 4764da4536..906790abb8 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -180,6 +180,16 @@ inline Foam::vector Foam::RBD::rigidBodyModel::masterPoint } +inline Foam::vector Foam::RBD::rigidBodyModel::p +( + const label bodyID, + const vector& p +) const +{ + return (X0(bodyID).inv() && spatialVector(Zero, p)).l(); +} + + inline Foam::spatialVector Foam::RBD::rigidBodyModel::v ( const label bodyID, @@ -198,4 +208,22 @@ inline Foam::spatialVector Foam::RBD::rigidBodyModel::v } +inline Foam::spatialVector Foam::RBD::rigidBodyModel::a +( + const label bodyID, + const vector& p +) const +{ + return + ( + spatialTransform + ( + X0_[master(bodyID)].E().T(), + masterPoint(bodyID, p) + ) + & a_[master(bodyID)] + ); +} + + // ************************************************************************* // diff --git a/src/rigidBodyState/Make/files b/src/rigidBodyState/Make/files index af2ca0e779..f4cff49787 100644 --- a/src/rigidBodyState/Make/files +++ b/src/rigidBodyState/Make/files @@ -1,3 +1,4 @@ -rigidBodyState.C +rigidBodyState/rigidBodyState.C +rigidBodyPoints/rigidBodyPoints.C LIB = $(FOAM_LIBBIN)/librigidBodyState diff --git a/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.C b/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.C new file mode 100644 index 0000000000..e8f67b7bdf --- /dev/null +++ b/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.C @@ -0,0 +1,179 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "rigidBodyPoints.H" +#include "fvMeshMoversMotionSolver.H" +#include "motionSolver.H" +#include "unitConversion.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(rigidBodyPoints, 0); + + addToRunTimeSelectionTable + ( + functionObject, + rigidBodyPoints, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +const Foam::RBD::rigidBodyMotion& +Foam::functionObjects::rigidBodyPoints::motion() const +{ + const fvMeshMovers::motionSolver& mover = + refCast(mesh_.mover()); + + return (refCast(mover.motion())); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::rigidBodyPoints::rigidBodyPoints +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + logFiles(obr_, name) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::rigidBodyPoints::~rigidBodyPoints() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::rigidBodyPoints::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + angleUnits_ = dict.lookupOrDefault("angleUnits", "radians"); + + dict.lookup("body") >> body_; + + const HashTable pointsTable(dict.lookup("points")); + names_.setSize(pointsTable.size()); + points_.setSize(pointsTable.size()); + + label i = 0; + forAllConstIter(HashTable, pointsTable, iter) + { + names_[i] = iter.key(); + points_[i++] = iter(); + } + + resetNames(names_); + + return true; +} + + +void Foam::functionObjects::rigidBodyPoints::writeFileHeader(const label i) +{ + writeHeader(this->files()[i], "Body point motion"); + writeHeaderValue(this->files()[i], "Body", body_); + writeHeaderValue(this->files()[i], "Point", points_[i]); + writeHeaderValue(this->files()[i], "Angle Units", angleUnits_); + writeCommented(this->files()[i], "Time"); + + this->files()[i]<< tab + << "Position" << tab + << "Linear velocity" << tab + << "Angular velocity" << tab + << "Linear acceleration" << tab + << "Angular acceleration" << endl; +} + + +bool Foam::functionObjects::rigidBodyPoints::execute() +{ + return true; +} + + +bool Foam::functionObjects::rigidBodyPoints::write() +{ + logFiles::write(); + + if (Pstream::master()) + { + const RBD::rigidBodyMotion& motion = this->motion(); + + const label bodyID = motion.bodyID(body_); + + forAll(points_, i) + { + const vector p(motion.p(bodyID, points_[i])); + const spatialVector v(motion.v(bodyID, points_[i])); + const spatialVector a(motion.a(bodyID, points_[i])); + + vector angularVelocity(v.w()); + vector angularAcceleration(a.w()); + + if (angleUnits_ == "degrees") + { + angularVelocity.x() = radToDeg(angularVelocity.x()); + angularVelocity.y() = radToDeg(angularVelocity.y()); + angularVelocity.z() = radToDeg(angularVelocity.z()); + + angularAcceleration.x() = radToDeg(angularAcceleration.x()); + angularAcceleration.y() = radToDeg(angularAcceleration.y()); + angularAcceleration.z() = radToDeg(angularAcceleration.z()); + } + + writeTime(files()[i]); + files()[i] + << tab + << p << tab + << v.l() << tab + << angularVelocity << tab + << a.l() << tab + << angularAcceleration << endl; + } + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.H b/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.H new file mode 100644 index 0000000000..4fb6b70281 --- /dev/null +++ b/src/rigidBodyState/rigidBodyPoints/rigidBodyPoints.H @@ -0,0 +1,177 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::rigidBodyPoints + +Description + Writes the position, linear and angular velocities and accelerations of a + list of points on a body specified in the body local coordinate system. + +Usage + \table + Property | Description | Required | Default value + type | type name: rigidBodyPoints | yes | + angleUnits | degrees or radians | no | radians + body | name of the body | yes | + points | list of points on the body | yes | + \endtable + + Example of function object specification: + \verbatim + rigidBodyPoints + { + type rigidBodyPoints; + libs ("librigidBodyState.so"); + + angleUnits degrees; + + body floatingObject; + + points + ( + point1 (0 0 0) + point2 (0.1 0.1 0.25) + ); + } + \endverbatim + +See also + Foam::functionObjects::fvMeshFunctionObject + Foam::functionObjects::logFiles + +SourceFiles + rigidBodyPoints.C + +\*---------------------------------------------------------------------------*/ + +#ifndef rigidBodyPoints_H +#define rigidBodyPoints_H + +#include "fvMeshFunctionObject.H" +#include "logFiles.H" +#include "rigidBodyMotion.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class rigidBodyPoints Declaration +\*---------------------------------------------------------------------------*/ + +class rigidBodyPoints +: + public fvMeshFunctionObject, + public logFiles +{ + // Private Data + + //- Angle units, radians (default) or degrees + word angleUnits_; + + //- Name of the body + word body_; + + //- List of points on the body + List points_; + + //- Names of the body point files + wordList names_; + + + // Private Member Functions + + const RBD::rigidBodyMotion& motion() const; + + +protected: + + // Protected Member Functions + + //- overloaded writeFileHeader from writeFile + virtual void writeFileHeader(const label i = 0); + + +public: + + //- Runtime type information + TypeName("rigidBodyPoints"); + + + // Constructors + + //- Construct from Time and dictionary + rigidBodyPoints + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + //- Disallow default bitwise copy construction + rigidBodyPoints(const rigidBodyPoints&) = delete; + + + //- Destructor + virtual ~rigidBodyPoints(); + + + // Member Functions + + //- Read the rigidBodyPoints data + virtual bool read(const dictionary&); + + //- Return the list of fields required + virtual wordList fields() const + { + return wordList::null(); + } + + //- Execute, currently does nothing + virtual bool execute(); + + //- Write the rigidBodyPoints + virtual bool write(); + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const rigidBodyPoints&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/rigidBodyState/rigidBodyState.C b/src/rigidBodyState/rigidBodyState/rigidBodyState.C similarity index 93% rename from src/rigidBodyState/rigidBodyState.C rename to src/rigidBodyState/rigidBodyState/rigidBodyState.C index 4dfb0c9a48..017ed813e4 100644 --- a/src/rigidBodyState/rigidBodyState.C +++ b/src/rigidBodyState/rigidBodyState/rigidBodyState.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2019-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,18 @@ namespace functionObjects } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +const Foam::RBD::rigidBodyMotion& +Foam::functionObjects::rigidBodyState::motion() const +{ + const fvMeshMovers::motionSolver& mover = + refCast(mesh_.mover()); + + return (refCast(mover.motion())); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::rigidBodyState::rigidBodyState @@ -72,21 +84,11 @@ Foam::functionObjects::rigidBodyState::~rigidBodyState() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::RBD::rigidBodyMotion& -Foam::functionObjects::rigidBodyState::motion() const -{ - const fvMeshMovers::motionSolver& mover = - refCast(mesh_.mover()); - - return (refCast(mover.motion())); -} - - bool Foam::functionObjects::rigidBodyState::read(const dictionary& dict) { fvMeshFunctionObject::read(dict); - angleFormat_ = dict.lookupOrDefault("angleFormat", "radians"); + angleUnits_ = dict.lookupOrDefault("angleUnits", "radians"); resetNames(names_); @@ -97,7 +99,7 @@ bool Foam::functionObjects::rigidBodyState::read(const dictionary& dict) void Foam::functionObjects::rigidBodyState::writeFileHeader(const label i) { writeHeader(this->files()[i], "Motion State"); - writeHeaderValue(this->files()[i], "Angle Units", angleFormat_); + writeHeaderValue(this->files()[i], "Angle Units", angleUnits_); writeCommented(this->files()[i], "Time"); this->files()[i]<< tab @@ -137,7 +139,7 @@ bool Foam::functionObjects::rigidBodyState::write() vector angularVelocity(vCofR.w()); - if (angleFormat_ == "degrees") + if (angleUnits_ == "degrees") { rotationAngle.x() = radToDeg(rotationAngle.x()); rotationAngle.y() = radToDeg(rotationAngle.y()); diff --git a/src/rigidBodyState/rigidBodyState.H b/src/rigidBodyState/rigidBodyState/rigidBodyState.H similarity index 92% rename from src/rigidBodyState/rigidBodyState.H rename to src/rigidBodyState/rigidBodyState/rigidBodyState.H index 5ef863f7ed..4282a1dbd5 100644 --- a/src/rigidBodyState/rigidBodyState.H +++ b/src/rigidBodyState/rigidBodyState/rigidBodyState.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2019-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,23 +27,23 @@ Class Description Writes the rigid body motion state. +Usage + \table + Property | Description | Required | Default value + type | type name: rigidBodyState | yes | + angleUnits | degrees or radians | no | radians + \endtable + Example of function object specification: \verbatim rigidBodyState { type rigidBodyState; libs ("librigidBodyState.so"); - angleFormat degrees; + angleUnits degrees; } \endverbatim -Usage - \table - Property | Description | Required | Default value - type | type name: rigidBodyState | yes | - angleFormat | degrees or radians | no | radian - \endtable - See also Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::logFiles @@ -78,12 +78,17 @@ class rigidBodyState { // Private Data - word angleFormat_; + word angleUnits_; //- List of the names of the rigid bodies wordList names_; + // Private Member Functions + + const RBD::rigidBodyMotion& motion() const; + + protected: // Protected Member Functions @@ -118,8 +123,6 @@ public: // Member Functions - const RBD::rigidBodyMotion& motion() const; - //- Read the rigidBodyState data virtual bool read(const dictionary&);