add damping energy to mass spring
This commit is contained in:
@@ -93,6 +93,7 @@ public:
|
||||
m_preconditioner->operator()(x,b);
|
||||
}
|
||||
|
||||
// reindex all the vertices
|
||||
virtual void updateId()
|
||||
{
|
||||
size_t node_id = 0;
|
||||
@@ -125,6 +126,7 @@ public:
|
||||
m_implicit = implicit;
|
||||
}
|
||||
|
||||
// Calculate the total potential energy in the system
|
||||
btScalar totalEnergy(btScalar dt);
|
||||
};
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ public:
|
||||
btVector3 scaled_force = scale * m_dampingStiffness * v_diff;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -118,9 +118,9 @@ public:
|
||||
btVector3 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual double totalElasticEnergy(btScalar dt)
|
||||
{
|
||||
double energy = 0;
|
||||
@@ -150,6 +151,35 @@ public:
|
||||
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)
|
||||
{
|
||||
// implicit damping force differential
|
||||
|
||||
Reference in New Issue
Block a user