make the impulse scaled with nodal mass. all binary mode files contains all modes info.

This commit is contained in:
jingyuc 2021-07-19 15:26:00 -04:00
parent f6dbbd4e66
commit 237333d030
6 changed files with 11 additions and 14 deletions

View File

@ -223,13 +223,6 @@ void BasicTest::initPhysics()
for (int k = 0; k < 3; ++k)
psb->m_x0[3 * i + k] = psb->m_nodes[i].m_x[k];
std::ofstream outfile1("before_map.txt");
for (int i = 0; i < psb->m_nodes.size(); ++i) {
for (int k = 0; k < 3; ++k)
outfile1 << psb->m_nodes[i].m_x[k] << '\n';
}
outfile1.close();
getDeformableDynamicsWorld()->addSoftBody(psb);
psb->scale(btVector3(2, 2, 2));
psb->translate(btVector3(0, 7, 0));
@ -243,6 +236,13 @@ void BasicTest::initPhysics()
psb->m_sleepingThreshold = 0;
btSoftBodyHelpers::generateBoundaryFaces(psb);
std::string M_file("../../../examples/SoftDemo/M_diag_mat.bin");
btAlignedObjectArray<btScalar> mass_array;
btSoftBodyHelpers::readBinary(mass_array, 0, 3 * m_nFull, 3 * m_nFull, M_file.c_str());
// assign mass to nodes
for (int i = 0; i < psb->m_nodes.size(); ++i)
psb->m_nodes[i].m_im = mass_array[3 * i]; // here we use m_im as the actual mass not the mass inverse
psb->setVelocity(btVector3(0, -COLLIDING_VELOCITY, 0));
btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -168,7 +168,6 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
{
if (psb->m_reducedModel)
{
btScalar scale = 100;
// get reduced force
btAlignedObjectArray<btScalar> reduced_force;
reduced_force.resize(psb->m_reducedDofs.size(), 0);
@ -182,9 +181,7 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
// std::cout << reduced_force[r] << '\t';
//TODO: increase stiffness
// reduced_force[r] += scale * psb->m_Kr[r] * psb->m_reducedDofs[r];
reduced_force[r] += scale * psb->m_Kr[r] * (psb->m_reducedDofs[r] + 0.1 * psb->m_reducedVelocity[r]);
reduced_force[r] += psb->m_Kr[r] * (psb->m_reducedDofs[r] + 0.1 * psb->m_reducedVelocity[r]);
// std::cout << reduced_force[r] << '\n';
// std::cout << psb->m_Kr[r] << "\t" << psb->m_reducedDofs[r] << "\n";
}
@ -192,14 +189,14 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
// apply impulses to reduced deformable objects
static btScalar sim_time = 0;
static btScalar target_vel = 5;
static btScalar target_vel = 20;
static bool apply_impulse = true;
if (psb->m_reducedModel && apply_impulse && sim_time > 1)
{
sim_time += m_dt;
apply_impulse = false;
btScalar f_imp = (target_vel - psb->m_nodes[0].m_v[1]) / m_dt;// TODO: need full mass?
btScalar f_imp = psb->m_nodes[i].m_im * (target_vel - psb->m_nodes[0].m_v[1]) / m_dt;
for (int i = 0; i < psb->m_reducedDofs.size(); ++i)
{
reduced_force[i] += psb->m_modes[i][0 * 3 + 1] * f_imp;