functionObjects::rigidBodyPoints: New functionObject to track the motion of points on a rigid body

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
This commit is contained in:
Henry Weller
2022-11-24 18:09:37 +00:00
parent e52c4e52a5
commit 386588b544
8 changed files with 429 additions and 33 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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)]
);
}
// ************************************************************************* //

View File

@ -1,3 +1,4 @@
rigidBodyState.C
rigidBodyState/rigidBodyState.C
rigidBodyPoints/rigidBodyPoints.C
LIB = $(FOAM_LIBBIN)/librigidBodyState

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<const fvMeshMovers::motionSolver>(mesh_.mover());
return (refCast<const RBD::rigidBodyMotion>(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<word>("angleUnits", "radians");
dict.lookup("body") >> body_;
const HashTable<point> pointsTable(dict.lookup("points"));
names_.setSize(pointsTable.size());
points_.setSize(pointsTable.size());
label i = 0;
forAllConstIter(HashTable<point>, 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;
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<point> 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
// ************************************************************************* //

View File

@ -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<const fvMeshMovers::motionSolver>(mesh_.mover());
return (refCast<const RBD::rigidBodyMotion>(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<const fvMeshMovers::motionSolver>(mesh_.mover());
return (refCast<const RBD::rigidBodyMotion>(mover.motion()));
}
bool Foam::functionObjects::rigidBodyState::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
angleUnits_ = dict.lookupOrDefault<word>("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());

View File

@ -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&);