mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 05:10:08 +00:00
kinematic tested. specified delta_v as a cosine function.
This commit is contained in:
parent
d390360f9e
commit
4b6eaeed4c
@ -96,7 +96,7 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
clock.reset();
|
||||
exampleBrowser->update(1.0);
|
||||
exampleBrowser->update(deltaTimeInSeconds);
|
||||
}
|
||||
} while (!exampleBrowser->requestedExit() && !interrupted);
|
||||
}
|
||||
|
@ -53,24 +53,16 @@ class BasicTest : public CommonDeformableBodyBase
|
||||
void mapToReducedDofs(btSoftBody* psb)
|
||||
{
|
||||
btAssert(psb->m_reducedDofs.size() == m_nReduced);
|
||||
for (int j = 0; j < m_nReduced; ++j) {
|
||||
if (j == selected_mode)
|
||||
psb->m_reducedDofs[j] = sin(psb->m_eigenvalues[j] * sim_time);
|
||||
else
|
||||
psb->m_reducedDofs[j] = 0;
|
||||
for (int j = 0; j < m_nReduced; ++j)
|
||||
{
|
||||
for (int i = 0; i < m_nFull; ++i)
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
int idx_f = 3 * i + k;
|
||||
psb->m_reducedDofs[j] = psb->m_modes[j][idx_f] * (psb->m_nodes[i].m_x[k] - psb->m_x0[idx_f]);
|
||||
// psb->m_reducedVelocity[j] = psb->m_modes[j][idx_f] * psb->m_nodes[i].m_v[k];
|
||||
}
|
||||
}
|
||||
// for (int j = 0; j < m_nReduced; ++j)
|
||||
// {
|
||||
// // if (j != selected_mode)
|
||||
// // continue;
|
||||
// for (int i = 0; i < m_nFull; ++i)
|
||||
// for (int k = 0; k < 3; ++k)
|
||||
// {
|
||||
// int idx_f = 3 * i + k;
|
||||
// psb->m_reducedNodes[j] = psb->m_modes[j][idx_f] * (psb->m_nodes[i].m_x[k] - psb->m_x0[idx_f]);
|
||||
// psb->m_reducedVelocity[j] = psb->m_modes[j][idx_f] * psb->m_nodes[i].m_v[k];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// compute full degree of freedoms
|
||||
@ -79,14 +71,12 @@ class BasicTest : public CommonDeformableBodyBase
|
||||
btAssert(psb->m_nodes.size() == m_nFull);
|
||||
for (int j = 0; j < m_nReduced; ++j)
|
||||
{
|
||||
// if (j != selected_mode)
|
||||
// continue;
|
||||
for (int i = 0; i < m_nFull; ++i)
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
int idx_f = 3 * i + k;
|
||||
psb->m_nodes[i].m_x[k] = psb->m_x0[idx_f] + psb->m_modes[j][idx_f] * psb->m_reducedDofs[j];
|
||||
psb->m_nodes[i].m_v[k] = psb->m_modes[j][idx_f] * psb->m_reducedVelocity[j];
|
||||
// psb->m_nodes[i].m_v[k] = psb->m_modes[j][idx_f] * psb->m_reducedVelocity[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,6 +140,7 @@ public:
|
||||
{
|
||||
getDeformedShape(psb, 0);
|
||||
first_step = false;
|
||||
mapToReducedDofs(psb);
|
||||
}
|
||||
|
||||
// compute reduced dofs
|
||||
@ -157,10 +148,10 @@ public:
|
||||
psb->m_reducedVelocity.resize(m_nReduced);
|
||||
sim_time += deltaTime;
|
||||
// std::cout << psb->m_eigenvalues[0] << "\t" << sim_time << "\t" << deltaTime << "\t" << sin(psb->m_eigenvalues[0] * sim_time) << "\n";
|
||||
mapToReducedDofs(psb);
|
||||
|
||||
float internalTimeStep = 1. / 60.f;
|
||||
m_dynamicsWorld->stepSimulation(deltaTime, 1, internalTimeStep);
|
||||
// float internalTimeStep = 1. / 60.f;
|
||||
float internalTimeStep = 1;
|
||||
m_dynamicsWorld->stepSimulation(1, 1, internalTimeStep);
|
||||
|
||||
// for (int i = 0; i < m_nReduced; ++i)
|
||||
// std::cout << psb->m_reducedDofs[i] << "\t";
|
||||
@ -213,6 +204,7 @@ void BasicTest::initPhysics()
|
||||
std::string filename("../../../examples/SoftDemo/mesh.vtk");
|
||||
btSoftBody* psb = btSoftBodyHelpers::CreateFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str());
|
||||
m_nFull = psb->m_nodes.size();
|
||||
psb->m_reducedModel = true;
|
||||
|
||||
// read in eigenmodes, stiffness and mass matrices
|
||||
std::string eigenvalues_file("../../../examples/SoftDemo/eigenvalues.bin");
|
||||
@ -295,7 +287,6 @@ void BasicTest::initPhysics()
|
||||
getDeformableDynamicsWorld()->addForce(psb, m_massSpring);
|
||||
m_forces.push_back(m_massSpring);
|
||||
}
|
||||
getDeformableDynamicsWorld()->setReducedModelFlag(false);
|
||||
getDeformableDynamicsWorld()->setImplicit(false);
|
||||
getDeformableDynamicsWorld()->setLineSearch(false);
|
||||
getDeformableDynamicsWorld()->setUseProjection(true);
|
||||
|
@ -23,7 +23,6 @@ btDeformableBackwardEulerObjective::btDeformableBackwardEulerObjective(btAligned
|
||||
m_massPreconditioner = new MassPreconditioner(m_softBodies);
|
||||
m_KKTPreconditioner = new KKTPreconditioner(m_softBodies, m_projection, m_lf, m_dt, m_implicit);
|
||||
m_preconditioner = m_KKTPreconditioner;
|
||||
m_reducedModel = false;
|
||||
}
|
||||
|
||||
btDeformableBackwardEulerObjective::~btDeformableBackwardEulerObjective()
|
||||
@ -137,6 +136,8 @@ void btDeformableBackwardEulerObjective::updateVelocity(const TVStack& dv)
|
||||
|
||||
void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero)
|
||||
{
|
||||
static btScalar sim_time = 0;
|
||||
|
||||
size_t counter = 0;
|
||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||
{
|
||||
@ -148,7 +149,7 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
|
||||
}
|
||||
if (m_implicit)
|
||||
{
|
||||
if (m_reducedModel)
|
||||
if (psb->m_reducedModel)
|
||||
{
|
||||
// for (int j = 0; j < psb->m_reducedNodes.size(); ++j) // TODO: reduced soft body
|
||||
// {
|
||||
@ -171,25 +172,30 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_reducedModel)
|
||||
if (psb->m_reducedModel)
|
||||
{
|
||||
// get reduced force
|
||||
// btAlignedObjectArray<btScalar> reduced_force;
|
||||
// reduced_force.resize(psb->m_reducedNodes.size());
|
||||
// for (int r = 0; r < psb->m_reducedNodes.size(); ++r)
|
||||
// reduced_force[r] = psb->m_Kr[r] * psb->m_reducedNodes[r];
|
||||
btAlignedObjectArray<btScalar> reduced_force;
|
||||
reduced_force.resize(psb->m_reducedDofs.size());
|
||||
for (int r = 0; r < psb->m_reducedDofs.size(); ++r)
|
||||
reduced_force[r] = psb->m_Kr[r] * psb->m_reducedDofs[r];
|
||||
|
||||
// // update reduced velocity
|
||||
// for (int r = 0; r < psb->m_reducedNodes.size(); ++r) // TODO: reduced soft body
|
||||
// {
|
||||
// btScalar mass_inv = (psb->m_Mr[r] == 0) ? 0 : 1.0 / psb->m_Mr[r];
|
||||
// // btScalar delta_v = m_dt * mass_inv * reduced_force[r];
|
||||
// btScalar delta_v = 1.0;
|
||||
// update reduced velocity
|
||||
for (int r = 0; r < psb->m_reducedDofs.size(); ++r) // TODO: reduced soft body
|
||||
{
|
||||
btScalar mass_inv = (psb->m_Mr[r] == 0) ? 0 : 1.0 / psb->m_Mr[r];
|
||||
// btScalar delta_v = m_dt * mass_inv * reduced_force[r];
|
||||
|
||||
// psb->m_reducedVelocity[r] += delta_v;
|
||||
// std::cout << psb->m_reducedVelocity[r] << "\t";
|
||||
// }
|
||||
// std::cout << "\n";
|
||||
sim_time += m_dt;
|
||||
// btScalar delta_v = 1;
|
||||
// btScalar delta_v = 0.02 * cos(psb->m_eigenvalues[r] * sim_time);
|
||||
btScalar delta_v = 0.02 * cos(psb->m_eigenvalues[r] * sim_time);
|
||||
|
||||
// psb->m_reducedVelocity[r] = sin(psb->m_eigenvalues[r] * sim_time);
|
||||
psb->m_reducedVelocity[r] -= delta_v;
|
||||
|
||||
// std::cout << sim_time << "\t" << psb->m_reducedDofs[r] << "\t" << psb->m_reducedVelocity[r] << "\t" << delta_v << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
const TVStack& m_backupVelocity;
|
||||
btAlignedObjectArray<btSoftBody::Node*> m_nodes;
|
||||
bool m_implicit;
|
||||
bool m_reducedModel;
|
||||
MassPreconditioner* m_massPreconditioner;
|
||||
KKTPreconditioner* m_KKTPreconditioner;
|
||||
|
||||
@ -131,16 +130,6 @@ public:
|
||||
m_implicit = implicit;
|
||||
}
|
||||
|
||||
void setReducedModel(bool reduced_model)
|
||||
{
|
||||
m_reducedModel = reduced_model;
|
||||
}
|
||||
|
||||
bool getReducedModelFlag() const
|
||||
{
|
||||
return m_reducedModel;
|
||||
}
|
||||
|
||||
// Calculate the total potential energy in the system
|
||||
btScalar totalEnergy(btScalar dt);
|
||||
|
||||
|
@ -72,12 +72,6 @@ btDeformableMultiBodyDynamicsWorld::~btDeformableMultiBodyDynamicsWorld()
|
||||
delete m_solverDeformableBodyIslandCallback;
|
||||
}
|
||||
|
||||
void btDeformableMultiBodyDynamicsWorld::setReducedModelFlag(bool reduced_model)
|
||||
{
|
||||
m_reducedModel = reduced_model;
|
||||
m_deformableBodySolver->m_objective->setReducedModel(reduced_model);
|
||||
}
|
||||
|
||||
void btDeformableMultiBodyDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
||||
{
|
||||
BT_PROFILE("internalSingleStepSimulation");
|
||||
@ -306,10 +300,10 @@ void btDeformableMultiBodyDynamicsWorld::integrateTransforms(btScalar timeStep)
|
||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||
{
|
||||
btSoftBody* psb = m_softBodies[i];
|
||||
if (m_reducedModel)
|
||||
if (psb->m_reducedModel)
|
||||
{
|
||||
for (int r = 0; r < psb->m_reducedDofs.size(); ++r)
|
||||
psb->m_reducedDofs[r] += timeStep * psb->m_reducedVelocity[r];
|
||||
psb->m_reducedDofs[r] = timeStep * psb->m_reducedVelocity[r];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -48,7 +48,6 @@ class btDeformableMultiBodyDynamicsWorld : public btMultiBodyDynamicsWorld
|
||||
btScalar m_internalTime;
|
||||
int m_ccdIterations;
|
||||
bool m_implicit;
|
||||
bool m_reducedModel;
|
||||
bool m_lineSearch;
|
||||
bool m_useProjection;
|
||||
DeformableBodyInplaceSolverIslandCallback* m_solverDeformableBodyIslandCallback;
|
||||
@ -155,8 +154,6 @@ public:
|
||||
|
||||
void softBodySelfCollision();
|
||||
|
||||
void setReducedModelFlag(bool reduced_model);
|
||||
|
||||
void setImplicit(bool implicit)
|
||||
{
|
||||
m_implicit = implicit;
|
||||
|
@ -855,7 +855,8 @@ public:
|
||||
|
||||
btScalar m_restLengthScale;
|
||||
|
||||
btAlignedObjectArray<btScalar> m_reducedDofs; // Reduced degree of freedom
|
||||
bool m_reducedModel; // Reduced deformable model flag
|
||||
btAlignedObjectArray<btScalar> m_reducedDofs; // Reduced degree of freedom
|
||||
btAlignedObjectArray<btScalar> m_reducedVelocity; // Reduced velocity array
|
||||
btAlignedObjectArray<btScalar> m_x0; // Rest position
|
||||
btAlignedObjectArray<btScalar> m_eigenvalues; // eigenvalues of the reduce deformable model
|
||||
|
Loading…
Reference in New Issue
Block a user