diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C index 74a6565efd..4d859be759 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C @@ -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; } diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H index aa3db57876..57c7a17e87 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H @@ -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 mergedBodies_; + //- Lookup-table of the IDs of the bodies + HashTable bodyIDs_; + //- List of indices of the parent of each body DynamicList