add damping energy to mass spring
This commit is contained in:
@@ -133,7 +133,7 @@ void DeformableContact::initPhysics()
|
|||||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
||||||
btRigidBody* body = new btRigidBody(rbInfo);
|
btRigidBody* body = new btRigidBody(rbInfo);
|
||||||
body->setFriction(1);
|
body->setFriction(2);
|
||||||
|
|
||||||
//add the ground to the dynamics world
|
//add the ground to the dynamics world
|
||||||
m_dynamicsWorld->addRigidBody(body);
|
m_dynamicsWorld->addRigidBody(body);
|
||||||
@@ -156,12 +156,12 @@ void DeformableContact::initPhysics()
|
|||||||
psb->setTotalMass(1);
|
psb->setTotalMass(1);
|
||||||
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
||||||
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
|
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
|
||||||
psb->m_cfg.kDF = 2;
|
psb->m_cfg.kDF = 1;
|
||||||
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
||||||
psb->m_cfg.collisions |= btSoftBody::fCollision::VF_DD;
|
psb->m_cfg.collisions |= btSoftBody::fCollision::VF_DD;
|
||||||
getDeformableDynamicsWorld()->addSoftBody(psb);
|
getDeformableDynamicsWorld()->addSoftBody(psb);
|
||||||
|
|
||||||
btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(20,0.1, true);
|
btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(10,1, true);
|
||||||
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
|
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
|
||||||
m_forces.push_back(mass_spring);
|
m_forces.push_back(mass_spring);
|
||||||
|
|
||||||
@@ -183,13 +183,13 @@ void DeformableContact::initPhysics()
|
|||||||
psb2->setTotalMass(1);
|
psb2->setTotalMass(1);
|
||||||
psb2->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
psb2->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
||||||
psb2->m_cfg.kCHR = 1; // collision hardness with rigid body
|
psb2->m_cfg.kCHR = 1; // collision hardness with rigid body
|
||||||
psb2->m_cfg.kDF = 2;
|
psb2->m_cfg.kDF = 1;
|
||||||
psb2->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
psb2->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
||||||
psb2->m_cfg.collisions |= btSoftBody::fCollision::VF_DD;
|
psb2->m_cfg.collisions |= btSoftBody::fCollision::VF_DD;
|
||||||
psb->translate(btVector3(3,0,0));
|
psb->translate(btVector3(3,0,0));
|
||||||
getDeformableDynamicsWorld()->addSoftBody(psb2);
|
getDeformableDynamicsWorld()->addSoftBody(psb2);
|
||||||
|
|
||||||
btDeformableMassSpringForce* mass_spring2 = new btDeformableMassSpringForce(20,0.1, true);
|
btDeformableMassSpringForce* mass_spring2 = new btDeformableMassSpringForce(10,1, true);
|
||||||
getDeformableDynamicsWorld()->addForce(psb2, mass_spring2);
|
getDeformableDynamicsWorld()->addForce(psb2, mass_spring2);
|
||||||
m_forces.push_back(mass_spring2);
|
m_forces.push_back(mass_spring2);
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ void DeformableRigid::initPhysics()
|
|||||||
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
|
||||||
getDeformableDynamicsWorld()->addSoftBody(psb);
|
getDeformableDynamicsWorld()->addSoftBody(psb);
|
||||||
|
|
||||||
btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(2,0.1, true);
|
btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(30,1, true);
|
||||||
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
|
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
|
||||||
m_forces.push_back(mass_spring);
|
m_forces.push_back(mass_spring);
|
||||||
|
|
||||||
|
|||||||
@@ -274,10 +274,10 @@ void GraspDeformable::initPhysics()
|
|||||||
{
|
{
|
||||||
char relative_path[1024];
|
char relative_path[1024];
|
||||||
// b3FileUtils::findFile("banana.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("banana.vtk", relative_path, 1024);
|
||||||
b3FileUtils::findFile("ball.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("ball.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("paper_collision.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("paper_collision.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("single_tet.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("single_tet.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("tube.vtk", relative_path, 1024);
|
b3FileUtils::findFile("tube.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("torus.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("torus.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("paper_roll.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("paper_roll.vtk", relative_path, 1024);
|
||||||
// b3FileUtils::findFile("bread.vtk", relative_path, 1024);
|
// b3FileUtils::findFile("bread.vtk", relative_path, 1024);
|
||||||
@@ -291,12 +291,12 @@ void GraspDeformable::initPhysics()
|
|||||||
btSoftBody* psb = btSoftBodyHelpers::CreateFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), relative_path);
|
btSoftBody* psb = btSoftBodyHelpers::CreateFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), relative_path);
|
||||||
|
|
||||||
// psb->scale(btVector3(30, 30, 30)); // for banana
|
// psb->scale(btVector3(30, 30, 30)); // for banana
|
||||||
psb->scale(btVector3(.05, .05, .05));
|
// psb->scale(btVector3(.2, .2, .2));
|
||||||
// psb->scale(btVector3(2, 2, 2));
|
// psb->scale(btVector3(2, 2, 2));
|
||||||
// psb->scale(btVector3(.3, .3, .3)); // for tube, torus, boot
|
psb->scale(btVector3(.3, .3, .3)); // for tube, torus, boot
|
||||||
// psb->scale(btVector3(1, 1, 1)); // for ditto
|
// psb->scale(btVector3(.1, .1, .1)); // for ditto
|
||||||
psb->translate(btVector3(.25, 2, 0.4));
|
// psb->translate(btVector3(.25, 2, 0.4));
|
||||||
psb->getCollisionShape()->setMargin(0.02);
|
psb->getCollisionShape()->setMargin(0.01);
|
||||||
psb->setTotalMass(.01);
|
psb->setTotalMass(.01);
|
||||||
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
|
||||||
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
|
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
|
||||||
@@ -308,7 +308,7 @@ void GraspDeformable::initPhysics()
|
|||||||
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
|
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
|
||||||
m_forces.push_back(gravity_force);
|
m_forces.push_back(gravity_force);
|
||||||
|
|
||||||
btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(250,500);
|
btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(10,20, 0.01);
|
||||||
getDeformableDynamicsWorld()->addForce(psb, neohookean);
|
getDeformableDynamicsWorld()->addForce(psb, neohookean);
|
||||||
m_forces.push_back(neohookean);
|
m_forces.push_back(neohookean);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public:
|
|||||||
m_preconditioner->operator()(x,b);
|
m_preconditioner->operator()(x,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reindex all the vertices
|
||||||
virtual void updateId()
|
virtual void updateId()
|
||||||
{
|
{
|
||||||
size_t node_id = 0;
|
size_t node_id = 0;
|
||||||
@@ -125,6 +126,7 @@ public:
|
|||||||
m_implicit = implicit;
|
m_implicit = implicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the total potential energy in the system
|
||||||
btScalar totalEnergy(btScalar dt);
|
btScalar totalEnergy(btScalar dt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ public:
|
|||||||
btVector3 scaled_force = scale * m_dampingStiffness * v_diff;
|
btVector3 scaled_force = scale * m_dampingStiffness * v_diff;
|
||||||
if (m_momentum_conserving)
|
if (m_momentum_conserving)
|
||||||
{
|
{
|
||||||
if ((node2->m_q - node1->m_q).norm() > SIMD_EPSILON)
|
if ((node2->m_x - node1->m_x).norm() > SIMD_EPSILON)
|
||||||
{
|
{
|
||||||
btVector3 dir = (node2->m_q - node1->m_q).normalized();
|
btVector3 dir = (node2->m_x - node1->m_x).normalized();
|
||||||
scaled_force = scale * m_dampingStiffness * v_diff.dot(dir) * dir;
|
scaled_force = scale * m_dampingStiffness * v_diff.dot(dir) * dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,9 +118,9 @@ public:
|
|||||||
btVector3 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]);
|
btVector3 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]);
|
||||||
if (m_momentum_conserving)
|
if (m_momentum_conserving)
|
||||||
{
|
{
|
||||||
if ((node2->m_q - node1->m_q).norm() > SIMD_EPSILON)
|
if ((node2->m_x - node1->m_x).norm() > SIMD_EPSILON)
|
||||||
{
|
{
|
||||||
btVector3 dir = (node2->m_q - node1->m_q).normalized();
|
btVector3 dir = (node2->m_x - node1->m_x).normalized();
|
||||||
local_scaled_df= scaled_k_damp * (dv[id2] - dv[id1]).dot(dir) * dir;
|
local_scaled_df= scaled_k_damp * (dv[id2] - dv[id1]).dot(dir) * dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,6 +129,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual double totalElasticEnergy(btScalar dt)
|
virtual double totalElasticEnergy(btScalar dt)
|
||||||
{
|
{
|
||||||
double energy = 0;
|
double energy = 0;
|
||||||
@@ -150,6 +151,35 @@ public:
|
|||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual double totalDampingEnergy(btScalar dt)
|
||||||
|
{
|
||||||
|
double energy = 0;
|
||||||
|
int sz = 0;
|
||||||
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
|
{
|
||||||
|
btSoftBody* psb = m_softBodies[i];
|
||||||
|
for (int j = 0; j < psb->m_nodes.size(); ++j)
|
||||||
|
{
|
||||||
|
sz = btMax(sz, psb->m_nodes[j].index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TVStack dampingForce;
|
||||||
|
dampingForce.resize(sz+1);
|
||||||
|
for (int i = 0; i < dampingForce.size(); ++i)
|
||||||
|
dampingForce[i].setZero();
|
||||||
|
addScaledDampingForce(0.5, dampingForce);
|
||||||
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
|
{
|
||||||
|
btSoftBody* psb = m_softBodies[i];
|
||||||
|
for (int j = 0; j < psb->m_nodes.size(); ++j)
|
||||||
|
{
|
||||||
|
const btSoftBody::Node& node = psb->m_nodes[j];
|
||||||
|
energy -= dampingForce[node.index].dot(node.m_v) / dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return energy;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack& dx, TVStack& df)
|
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack& dx, TVStack& df)
|
||||||
{
|
{
|
||||||
// implicit damping force differential
|
// implicit damping force differential
|
||||||
|
|||||||
Reference in New Issue
Block a user