Commit e2c9cb45 authored by Henry Weller's avatar Henry Weller
Browse files

rigidBodyDynamics: Added dictionary-based IO of the rigidBodyModel, bodies and joints

Added support for composite joints including a specialized 6-DoF form for floating bodies.
parent b701ec9f
......@@ -5,7 +5,9 @@ bodies/subBody/subBody.C
bodies/sphere/sphere.C
joints/joint/joint.C
joints/nullJoint/nullJoint.C
joints/null/nullJoint.C
joints/composite/compositeJoint.C
joints/floating/floatingJoint.C
joints/Rx/Rx.C
joints/Ry/Ry.C
......
......@@ -54,7 +54,7 @@ Foam::RBD::joints::Pa::Pa(const vector& axis)
:
joint(1)
{
S_[0] = spatialVector(Zero, axis);
S_[0] = spatialVector(Zero, axis/mag(axis));
}
......@@ -62,7 +62,8 @@ Foam::RBD::joints::Pa::Pa(const dictionary& dict)
:
joint(1)
{
S_[0] = spatialVector(Zero, dict.lookup("axis"));
vector axis(dict.lookup("axis"));
S_[0] = spatialVector(Zero, axis/mag(axis));
}
......@@ -95,4 +96,12 @@ void Foam::RBD::joints::Pa::jcalc
}
void Foam::RBD::joints::Pa::write(Ostream& os) const
{
joint::write(os);
os.writeKeyword("axis")
<< S_[0].l() << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -95,6 +95,9 @@ public:
const scalarField& w,
const scalarField& qDot
) const;
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -54,7 +54,7 @@ Foam::RBD::joints::Ra::Ra(const vector& axis)
:
joint(1)
{
S_[0] = spatialVector(axis, Zero);
S_[0] = spatialVector(axis/mag(axis), Zero);
}
......@@ -62,7 +62,8 @@ Foam::RBD::joints::Ra::Ra(const dictionary& dict)
:
joint(1)
{
S_[0] = spatialVector(dict.lookup("axis"), Zero);
vector axis(dict.lookup("axis"));
S_[0] = spatialVector(axis/mag(axis), Zero);
}
......@@ -95,4 +96,12 @@ void Foam::RBD::joints::Ra::jcalc
}
void Foam::RBD::joints::Ra::write(Ostream& os) const
{
joint::write(os);
os.writeKeyword("axis")
<< S_[0].w() << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -95,6 +95,9 @@ public:
const scalarField& w,
const scalarField& qDot
) const;
//- Write
virtual void write(Ostream&) const;
};
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 "compositeJoint.H"
#include "rigidBodyModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace RBD
{
namespace joints
{
defineTypeNameAndDebug(composite, 0);
addToRunTimeSelectionTable
(
joint,
composite,
dictionary
);
}
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::RBD::joints::composite::setLastJoint()
{
last().joint::operator=(*this);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::RBD::joints::composite::composite(const PtrList<joint>& joints)
:
PtrList<joint>(joints),
joint(last())
{}
Foam::RBD::joints::composite::composite(const dictionary& dict)
:
PtrList<joint>(dict.lookup("joints")),
joint(last())
{}
Foam::autoPtr<Foam::RBD::joint> Foam::RBD::joints::composite::clone() const
{
return autoPtr<joint>(new composite(*this));
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::RBD::joints::composite::~composite()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::RBD::joints::composite::nw() const
{
return last().nw();
}
void Foam::RBD::joints::composite::jcalc
(
joint::XSvc& J,
const scalarField& q,
const scalarField& w,
const scalarField& qDot
) const
{
last().jcalc(J, q, w, qDot);
}
void Foam::RBD::joints::composite::write(Ostream& os) const
{
joint::write(os);
os.writeKeyword("joints");
os << static_cast<const PtrList<joint>&>(*this);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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::RBD::joints::composite
Description
Prismatic joint for translation along the specified arbitrary axis.
Reference:
\verbatim
Featherstone, R. (2008).
Rigid body dynamics algorithms.
Springer.
Chapter 4.
\endverbatim
SourceFiles
composite.C
\*---------------------------------------------------------------------------*/
#ifndef RBD_joints_composite_H
#define RBD_joints_composite_H
#include "joint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace RBD
{
// Forward declaration of classes
class rigidBodyModel;
namespace joints
{
/*---------------------------------------------------------------------------*\
Class composite Declaration
\*---------------------------------------------------------------------------*/
class composite
:
public PtrList<joint>,
public joint
{
// Private member functions
//- Set the properties of the last joint following construction
// of the body containing the joint
void setLastJoint();
public:
//- Runtime type information
TypeName("composite");
//- Allow the rigidBodyModel class to set the last joint state
friend class Foam::RBD::rigidBodyModel;
// Constructors
//- Construct for given PtrList<joint>
composite(const PtrList<joint>& joints);
//- Construct for given model from dictionary
composite(const dictionary& dict);
//- Clone this joint
virtual autoPtr<joint> clone() const;
//- Destructor
virtual ~composite();
// Member Functions
//- Return the number of additional state variables need by this joint
virtual label nw() const;
//- Update the model state for this joint
virtual void jcalc
(
joint::XSvc& J,
const scalarField& q,
const scalarField& w,
const scalarField& qDot
) const;
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace joints
} // End namespace RBD
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 "floatingJoint.H"
#include "rigidBodyModel.H"
#include "addToRunTimeSelectionTable.H"
#include "Rs.H"
#include "Rzyx.H"
#include "Pxyz.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace RBD
{
namespace joints
{
defineTypeNameAndDebug(floating, 0);
addToRunTimeSelectionTable
(
joint,
floating,
dictionary
);
}
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::autoPtr<Foam::RBD::joints::composite>
Foam::RBD::joints::floating::sixDoF()
{
PtrList<joint> cj(2);
cj.set(0, new joints::Pxyz());
// The quaternion-based spherical joint could be used
// but then w must be set appropriately
//cj.set(1, new joints::Rs());
// Alternatively the Euler-angle joint can be used
cj.set(1, new joints::Rzyx());
return autoPtr<composite>(new composite(cj));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::RBD::joints::floating::floating()
:
composite(sixDoF())
{}
Foam::RBD::joints::floating::floating(const dictionary& dict)
:
composite(sixDoF())
{}
Foam::autoPtr<Foam::RBD::joint> Foam::RBD::joints::floating::clone() const
{
return autoPtr<joint>(new floating(*this));
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::RBD::joints::floating::~floating()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::RBD::joints::floating::write(Ostream& os) const
{
joint::write(os);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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::RBD::joints::floating
Description
Prismatic joint for translation along the specified arbitrary axis.
Reference:
\verbatim
Featherstone, R. (2008).
Rigid body dynamics algorithms.
Springer.
Chapter 4.
\endverbatim
SourceFiles
floating.C
\*---------------------------------------------------------------------------*/
#ifndef RBD_joints_floating_H
#define RBD_joints_floating_H
#include "compositeJoint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace RBD
{
namespace joints
{
/*---------------------------------------------------------------------------*\
Class floating Declaration
\*---------------------------------------------------------------------------*/
class floating
:
public composite
{
// Private member functions
//- Return a list of joints needed to emulate a floating body
static autoPtr<composite> sixDoF();
public:
//- Runtime type information
TypeName("floating");
// Constructors
//- Construct
floating();
//- Construct for given model from dictionary
floating(const dictionary& dict);
//- Clone this joint
virtual autoPtr<joint> clone() const;
//- Destructor
virtual ~floating();
// Member Functions
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace joints
} // End namespace RBD
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -25,9 +25,6 @@ License
#include "joint.H"
#include "rigidBodyModel.H"
#include "Rs.H"
#include "Rzyx.H"
#include "Pxyz.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -81,18 +78,10 @@ Foam::RBD::joint::~joint()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::PtrList<Foam::RBD::joint> Foam::RBD::joint::floating()
void Foam::RBD::joint::write(Ostream& os) const
{
PtrList<joint> cj(2);
cj.set(0, new joints::Pxyz());
//cj.set(1, new joints::Rs());
cj.set(1, new joints::Rzyx());
return cj;
os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
}
void Foam::RBD::joint::write(Ostream& os) const
{}
// ************************************************************************* //
......@@ -61,6 +61,12 @@ namespace RBD
// Forward declaration of classes
class rigidBodyModel;
// Forward declaration of friend functions and operators
class joint;
inline Ostream& operator<<(Ostream&, const joint&);
/*---------------------------------------------------------------------------*\
Class joint Declaration
\*---------------------------------------------------------------------------*/
......@@ -171,6 +177,17 @@ public:
//- Clone this joint (needed by PtrList)
virtual autoPtr<joint> clone() const = 0;
class iNew
{
public: