From e50d8ece5747c6349240004df65c8c0136675034 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Mon, 4 Apr 2016 09:26:37 +0100
Subject: [PATCH] applications/test/rigidBodyDynamics/pendulum: Add a test for
 merging bodies

---
 .../rigidBodyDynamics/pendulum/pendulum.C     | 37 +++++++++++++++----
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/applications/test/rigidBodyDynamics/pendulum/pendulum.C b/applications/test/rigidBodyDynamics/pendulum/pendulum.C
index 23c35c4af34..ac6455b0f74 100644
--- a/applications/test/rigidBodyDynamics/pendulum/pendulum.C
+++ b/applications/test/rigidBodyDynamics/pendulum/pendulum.C
@@ -31,6 +31,7 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "rigidBodyModel.H"
+#include "masslessBody.H"
 #include "joints.H"
 
 using namespace Foam;
@@ -40,18 +41,40 @@ using namespace RBD;
 
 int main(int argc, char *argv[])
 {
+    bool testMerge = false;
+
     // Create a model for the pendulum
     rigidBodyModel pendulum;
 
     // Join a weight to the origin with a centre of mass -1m below the origin
     // by a hinge which rotates about the z-axis
-    pendulum.join
-    (
-        0,
-        Xt(vector(0, 0, 0)),
-        joint::New(new joints::Rz(pendulum)),
-        rigidBody::New("hinge", 1, vector(0, -1, 0), 0.02*I)
-    );
+    if (testMerge)
+    {
+        label hingeID = pendulum.join
+        (
+            0,
+            Xt(Zero),
+            joint::New(new joints::Rz(pendulum)),
+            autoPtr<rigidBody>(new masslessBody("hinge"))
+        );
+
+        pendulum.merge
+        (
+            hingeID,
+            Xt(vector(0, -1, 0)),
+            rigidBody::New("weight", 1, Zero, 0.02*I)
+        );
+    }
+    else
+    {
+        pendulum.join
+        (
+            0,
+            Xt(Zero),
+            joint::New(new joints::Rz(pendulum)),
+            rigidBody::New("pendulum", 1, vector(0, -1, 0), 0.02*I)
+        );
+    }
 
     // Create the joint-space state fields
     scalarField q(pendulum.nDoF(), Zero);
-- 
GitLab