mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
rigidBodyModel: Added support for body lookup by name
This commit is contained in:
@ -44,6 +44,7 @@ void Foam::RBD::rigidBodyModel::initializeRootBody()
|
||||
{
|
||||
bodies_.append(new masslessBody);
|
||||
lambda_.append(0);
|
||||
bodyIDs_.insert("root", 0);
|
||||
joints_.append(new joints::null(*this));
|
||||
XT_.append(spatialTransform());
|
||||
|
||||
@ -96,7 +97,10 @@ Foam::label Foam::RBD::rigidBodyModel::join
|
||||
)
|
||||
{
|
||||
// Append the body
|
||||
const rigidBody& body = bodyPtr();
|
||||
bodies_.append(bodyPtr);
|
||||
const label bodyID = nBodies()-1;
|
||||
bodyIDs_.insert(body.name(), bodyID);
|
||||
|
||||
// If the parentID refers to a merged body find the parent into which it has
|
||||
// been merged and set lambda and XT accordingly
|
||||
@ -126,7 +130,7 @@ Foam::label Foam::RBD::rigidBodyModel::join
|
||||
|
||||
resizeState();
|
||||
|
||||
return nBodies()-1;
|
||||
return bodyID;
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +204,10 @@ Foam::label Foam::RBD::rigidBodyModel::merge
|
||||
// Merge the sub-body with the parent
|
||||
bodies_[sBody.parentID()].merge(sBody);
|
||||
|
||||
return mergedBodyID(mergedBodies_.size() - 1);
|
||||
const label sBodyID = mergedBodyID(mergedBodies_.size() - 1);
|
||||
bodyIDs_.insert(sBody.name(), sBodyID);
|
||||
|
||||
return sBodyID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ SourceFiles
|
||||
#include "subBody.H"
|
||||
#include "joint.H"
|
||||
#include "PtrList.H"
|
||||
#include "HashTable.H"
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
@ -89,6 +90,9 @@ protected:
|
||||
// this list.
|
||||
PtrList<subBody> mergedBodies_;
|
||||
|
||||
//- Lookup-table of the IDs of the bodies
|
||||
HashTable<label, word> bodyIDs_;
|
||||
|
||||
//- List of indices of the parent of each body
|
||||
DynamicList<label> lambda_;
|
||||
|
||||
@ -267,6 +271,9 @@ public:
|
||||
//- Return the merged body for the given body ID
|
||||
inline const subBody& mergedBody(label mergedBodyID) const;
|
||||
|
||||
//- Return the ID of the body with the given name
|
||||
inline label bodyID(const word& name) const;
|
||||
|
||||
//- Return the current transform to the global frame for the given body
|
||||
spatialTransform X0(const label bodyId) const;
|
||||
|
||||
|
||||
@ -117,4 +117,10 @@ Foam::RBD::rigidBodyModel::mergedBody(label mergedBodyID) const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::RBD::rigidBodyModel::bodyID(const word& name) const
|
||||
{
|
||||
return bodyIDs_[name];
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user