rigidBodyModel: Added support for body lookup by name
This commit is contained in:
parent
09ba40bf26
commit
947f04ac9e
3 changed files with 22 additions and 2 deletions
|
|
@ -44,6 +44,7 @@ void Foam::RBD::rigidBodyModel::initializeRootBody()
|
||||||
{
|
{
|
||||||
bodies_.append(new masslessBody);
|
bodies_.append(new masslessBody);
|
||||||
lambda_.append(0);
|
lambda_.append(0);
|
||||||
|
bodyIDs_.insert("root", 0);
|
||||||
joints_.append(new joints::null(*this));
|
joints_.append(new joints::null(*this));
|
||||||
XT_.append(spatialTransform());
|
XT_.append(spatialTransform());
|
||||||
|
|
||||||
|
|
@ -96,7 +97,10 @@ Foam::label Foam::RBD::rigidBodyModel::join
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Append the body
|
// Append the body
|
||||||
|
const rigidBody& body = bodyPtr();
|
||||||
bodies_.append(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
|
// If the parentID refers to a merged body find the parent into which it has
|
||||||
// been merged and set lambda and XT accordingly
|
// been merged and set lambda and XT accordingly
|
||||||
|
|
@ -126,7 +130,7 @@ Foam::label Foam::RBD::rigidBodyModel::join
|
||||||
|
|
||||||
resizeState();
|
resizeState();
|
||||||
|
|
||||||
return nBodies()-1;
|
return bodyID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -200,7 +204,10 @@ Foam::label Foam::RBD::rigidBodyModel::merge
|
||||||
// Merge the sub-body with the parent
|
// Merge the sub-body with the parent
|
||||||
bodies_[sBody.parentID()].merge(sBody);
|
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 "subBody.H"
|
||||||
#include "joint.H"
|
#include "joint.H"
|
||||||
#include "PtrList.H"
|
#include "PtrList.H"
|
||||||
|
#include "HashTable.H"
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
@ -89,6 +90,9 @@ protected:
|
||||||
// this list.
|
// this list.
|
||||||
PtrList<subBody> mergedBodies_;
|
PtrList<subBody> mergedBodies_;
|
||||||
|
|
||||||
|
//- Lookup-table of the IDs of the bodies
|
||||||
|
HashTable<label, word> bodyIDs_;
|
||||||
|
|
||||||
//- List of indices of the parent of each body
|
//- List of indices of the parent of each body
|
||||||
DynamicList<label> lambda_;
|
DynamicList<label> lambda_;
|
||||||
|
|
||||||
|
|
@ -267,6 +271,9 @@ public:
|
||||||
//- Return the merged body for the given body ID
|
//- Return the merged body for the given body ID
|
||||||
inline const subBody& mergedBody(label mergedBodyID) const;
|
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
|
//- Return the current transform to the global frame for the given body
|
||||||
spatialTransform X0(const label bodyId) const;
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue