From ef5aa6e73bb69fd2b1e96e37641a5167453f6f36 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Thu, 19 Sep 2019 16:56:55 -0700 Subject: [PATCH] add options to toggle between whether line search is used & add more documentation --- examples/DeformableDemo/ClothFriction.cpp | 5 ++-- examples/DeformableDemo/DeformableContact.cpp | 4 +--- .../DeformableDemo/DeformableMultibody.cpp | 14 ----------- examples/DeformableDemo/DeformableRigid.cpp | 19 +-------------- examples/DeformableDemo/GraspDeformable.cpp | 4 +--- examples/DeformableDemo/Pinch.cpp | 24 +------------------ examples/DeformableDemo/PinchFriction.cpp | 4 +--- .../DeformableDemo/VolumetricDeformable.cpp | 19 +-------------- src/BulletSoftBody/btDeformableBodySolver.cpp | 5 ++++ src/BulletSoftBody/btDeformableBodySolver.h | 22 +++++++++++++++++ .../btDeformableMultiBodyDynamicsWorld.cpp | 16 +++++-------- .../btDeformableMultiBodyDynamicsWorld.h | 6 +++++ 12 files changed, 47 insertions(+), 95 deletions(-) diff --git a/examples/DeformableDemo/ClothFriction.cpp b/examples/DeformableDemo/ClothFriction.cpp index 6626560c6..cd09a17d8 100644 --- a/examples/DeformableDemo/ClothFriction.cpp +++ b/examples/DeformableDemo/ClothFriction.cpp @@ -25,9 +25,7 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The ClothFriction shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The ClothFriction shows the use of deformable friction. class ClothFriction : public CommonRigidBodyBase { btAlignedObjectArray m_forces; @@ -197,6 +195,7 @@ void ClothFriction::initPhysics() getDeformableDynamicsWorld()->addForce(psb2, gravity_force2); m_forces.push_back(gravity_force2); } + getDeformableDynamicsWorld()->setImplicit(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } diff --git a/examples/DeformableDemo/DeformableContact.cpp b/examples/DeformableDemo/DeformableContact.cpp index ce12b8b12..68ffd26c0 100644 --- a/examples/DeformableDemo/DeformableContact.cpp +++ b/examples/DeformableDemo/DeformableContact.cpp @@ -25,9 +25,7 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The DeformableContact shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The DeformableContact shows the contact between deformable objects class DeformableContact : public CommonRigidBodyBase { btAlignedObjectArray m_forces; diff --git a/examples/DeformableDemo/DeformableMultibody.cpp b/examples/DeformableDemo/DeformableMultibody.cpp index 5ffaefc36..a4b03f430 100644 --- a/examples/DeformableDemo/DeformableMultibody.cpp +++ b/examples/DeformableDemo/DeformableMultibody.cpp @@ -11,20 +11,6 @@ 3. This notice may not be removed or altered from any source distribution. */ -///create 125 (5x5x5) dynamic object -#define ARRAY_SIZE_X 5 -#define ARRAY_SIZE_Y 5 -#define ARRAY_SIZE_Z 5 - -//maximum number of objects (and allow user to shoot additional boxes) -#define MAX_PROXIES (ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z + 1024) - -///scaling of the objects (0.1 = 20 centimeter boxes ) -#define SCALING 1. -#define START_POS_X -5 -#define START_POS_Y -5 -#define START_POS_Z -3 - #include "DeformableMultibody.h" ///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files. #include "btBulletDynamicsCommon.h" diff --git a/examples/DeformableDemo/DeformableRigid.cpp b/examples/DeformableDemo/DeformableRigid.cpp index f34b2a0e8..920cd79a6 100644 --- a/examples/DeformableDemo/DeformableRigid.cpp +++ b/examples/DeformableDemo/DeformableRigid.cpp @@ -10,21 +10,6 @@ 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - -///create 125 (5x5x5) dynamic object -#define ARRAY_SIZE_X 5 -#define ARRAY_SIZE_Y 5 -#define ARRAY_SIZE_Z 5 - -//maximum number of objects (and allow user to shoot additional boxes) -#define MAX_PROXIES (ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z + 1024) - -///scaling of the objects (0.1 = 20 centimeter boxes ) -#define SCALING 1. -#define START_POS_X -5 -#define START_POS_Y -5 -#define START_POS_Z -3 - #include "DeformableRigid.h" ///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files. #include "btBulletDynamicsCommon.h" @@ -39,9 +24,7 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The DeformableRigid shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The DeformableRigid shows contact between deformable objects and rigid objects. class DeformableRigid : public CommonRigidBodyBase { btAlignedObjectArray m_forces; diff --git a/examples/DeformableDemo/GraspDeformable.cpp b/examples/DeformableDemo/GraspDeformable.cpp index 08368398d..41f75a4cf 100644 --- a/examples/DeformableDemo/GraspDeformable.cpp +++ b/examples/DeformableDemo/GraspDeformable.cpp @@ -34,9 +34,7 @@ #include "../CommonInterfaces/CommonFileIOInterface.h" #include "Bullet3Common/b3FileUtils.h" -///The GraspDeformable shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The GraspDeformable shows grasping a volumetric deformable objects with multibody gripper with moter constraints. static btScalar sGripperVerticalVelocity = 0.f; static btScalar sGripperClosingTargetVelocity = 0.f; static float friction = 1.; diff --git a/examples/DeformableDemo/Pinch.cpp b/examples/DeformableDemo/Pinch.cpp index 661698a06..0887453f5 100644 --- a/examples/DeformableDemo/Pinch.cpp +++ b/examples/DeformableDemo/Pinch.cpp @@ -11,20 +11,6 @@ 3. This notice may not be removed or altered from any source distribution. */ -///create 125 (5x5x5) dynamic object -#define ARRAY_SIZE_X 5 -#define ARRAY_SIZE_Y 5 -#define ARRAY_SIZE_Z 5 - -//maximum number of objects (and allow user to shoot additional boxes) -#define MAX_PROXIES (ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z + 1024) - -///scaling of the objects (0.1 = 20 centimeter boxes ) -#define SCALING 1. -#define START_POS_X -5 -#define START_POS_Y -5 -#define START_POS_Z -3 - #include "Pinch.h" ///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files. #include "btBulletDynamicsCommon.h" @@ -39,21 +25,13 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The Pinch shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The Pinch shows the frictional contact between kinematic rigid objects with deformable objects struct TetraCube { #include "../SoftDemo/cube.inl" }; -struct TetraBunny -{ -#include "../SoftDemo/bunny.inl" -}; - - class Pinch : public CommonRigidBodyBase { btAlignedObjectArray m_forces; diff --git a/examples/DeformableDemo/PinchFriction.cpp b/examples/DeformableDemo/PinchFriction.cpp index 4aa2ba0d1..ed69ddfd8 100644 --- a/examples/DeformableDemo/PinchFriction.cpp +++ b/examples/DeformableDemo/PinchFriction.cpp @@ -24,9 +24,7 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The PinchFriction shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). +///The PinchFriction shows the frictional contacts among volumetric deformable objects struct TetraCube { diff --git a/examples/DeformableDemo/VolumetricDeformable.cpp b/examples/DeformableDemo/VolumetricDeformable.cpp index cff07a175..3f663562f 100644 --- a/examples/DeformableDemo/VolumetricDeformable.cpp +++ b/examples/DeformableDemo/VolumetricDeformable.cpp @@ -11,20 +11,6 @@ 3. This notice may not be removed or altered from any source distribution. */ -///create 125 (5x5x5) dynamic object -#define ARRAY_SIZE_X 5 -#define ARRAY_SIZE_Y 5 -#define ARRAY_SIZE_Z 5 - -//maximum number of objects (and allow user to shoot additional boxes) -#define MAX_PROXIES (ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z + 1024) - -///scaling of the objects (0.1 = 20 centimeter boxes ) -#define SCALING 1. -#define START_POS_X -5 -#define START_POS_Y -5 -#define START_POS_Z -3 - #include "VolumetricDeformable.h" ///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files. #include "btBulletDynamicsCommon.h" @@ -39,10 +25,7 @@ #include "../CommonInterfaces/CommonRigidBodyBase.h" #include "../Utils/b3ResourcePath.h" -///The VolumetricDeformable shows the use of rolling friction. -///Spheres will come to a rest on a sloped plane using a constraint. Damping cannot achieve the same. -///Generally it is best to leave the rolling friction coefficient zero (or close to zero). - +///The VolumetricDeformable shows the contact between volumetric deformable objects and rigid objects. struct TetraCube { diff --git a/src/BulletSoftBody/btDeformableBodySolver.cpp b/src/BulletSoftBody/btDeformableBodySolver.cpp index 7ee4d4bea..a9de66454 100644 --- a/src/BulletSoftBody/btDeformableBodySolver.cpp +++ b/src/BulletSoftBody/btDeformableBodySolver.cpp @@ -429,3 +429,8 @@ void btDeformableBodySolver::setImplicit(bool implicit) m_implicit = implicit; m_objective->setImplicit(implicit); } + +void btDeformableBodySolver::setLineSearch(bool lineSearch) +{ + m_lineSearch = lineSearch; +} diff --git a/src/BulletSoftBody/btDeformableBodySolver.h b/src/BulletSoftBody/btDeformableBodySolver.h index ffce06937..b0c458029 100644 --- a/src/BulletSoftBody/btDeformableBodySolver.h +++ b/src/BulletSoftBody/btDeformableBodySolver.h @@ -103,16 +103,38 @@ public: virtual bool checkInitialized(){return true;} + // If true, implicit time stepping scheme is used. + // Otherwise, explicit time stepping scheme is used void setImplicit(bool implicit); + // If true, newton's method with line search is used when implicit time stepping scheme is turned on + void setLineSearch(bool lineSearch); + + // set temporary position x^* = x_n + dt * v + // update the deformation gradient at position x^* void updateState(); + // set dv = dv + scale * ddv void updateDv(btScalar scale = 1); + // set temporary position x^* = x_n + dt * v^* void updateTempPosition(); + + // save the current dv to m_backup_dv; void backupDv(); + + // set dv to the backed-up value void revertDv(); + + // set dv = dv + scale * ddv + // set v^* = v_n + dv + // set temporary position x^* = x_n + dt * v^* + // update the deformation gradient at position x^* void updateEnergy(btScalar scale); + + // calculates the appropriately scaled kinetic energy in the system, which is + // 1/2 * dv^T * M * dv + // used in line search btScalar kineticEnergy(); }; diff --git a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp index 8b6d80814..39d2d61bb 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp +++ b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp @@ -69,14 +69,14 @@ void btDeformableMultiBodyDynamicsWorld::internalSingleStepSimulation(btScalar t // End solver-wise simulation step // /////////////////////////////// } - +// //void btDeformableMultiBodyDynamicsWorld::positionCorrection(btScalar timeStep) //{ -// // perform position correction for all constraints +// // perform position correction for all constraints // BT_PROFILE("positionCorrection"); -// for (int index = 0; index < m_deformableBodySolver->m_objective->projection.m_constraints.size(); ++index) +// for (int index = 0; index < m_deformableBodySolver->m_objective->m_projection.m_constraints.size(); ++index) // { -// DeformableContactConstraint& constraint = *m_deformableBodySolver->m_objective->projection.m_constraints.getAtIndex(index); +// DeformableContactConstraint& constraint = *m_deformableBodySolver->m_objective->m_projection.m_constraints.getAtIndex(index); // for (int j = 0; j < constraint.m_contact.size(); ++j) // { // const btSoftBody::RContact* c = constraint.m_contact[j]; @@ -144,16 +144,11 @@ void btDeformableMultiBodyDynamicsWorld::internalSingleStepSimulation(btScalar t // } //} -void btDeformableMultiBodyDynamicsWorld::positionCorrection(btScalar timeStep) -{ -} - - void btDeformableMultiBodyDynamicsWorld::integrateTransforms(btScalar timeStep) { BT_PROFILE("integrateTransforms"); //m_deformableBodySolver->backupVelocity(); - //positionCorrection(timeStep); + //positionCorrection(timeStep); // looks like position correction is no longer necessary btMultiBodyDynamicsWorld::integrateTransforms(timeStep); for (int i = 0; i < m_softBodies.size(); ++i) { @@ -329,6 +324,7 @@ void btDeformableMultiBodyDynamicsWorld::reinitialize(btScalar timeStep) { m_internalTime += timeStep; m_deformableBodySolver->setImplicit(m_implicit); + m_deformableBodySolver->setLineSearch(m_lineSearch); m_deformableBodySolver->reinitialize(m_softBodies, timeStep); btDispatcherInfo& dispatchInfo = btMultiBodyDynamicsWorld::getDispatchInfo(); dispatchInfo.m_timeStep = timeStep; diff --git a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.h b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.h index 36f0b1218..dc060a8e8 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.h +++ b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.h @@ -47,6 +47,7 @@ class btDeformableMultiBodyDynamicsWorld : public btMultiBodyDynamicsWorld btScalar m_internalTime; int m_contact_iterations; bool m_implicit; + bool m_lineSearch; typedef void (*btSolverCallback)(btScalar time, btDeformableMultiBodyDynamicsWorld* world); btSolverCallback m_solverCallback; @@ -159,6 +160,11 @@ public: { m_implicit = implicit; } + + void setLineSearch(bool lineSearch) + { + m_lineSearch = lineSearch; + } }; #endif //BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD_H