Skip to content

Commit

Permalink
[Backward] Fix trapezoidal rule in EulerImplicitSolver
Browse files Browse the repository at this point in the history
  • Loading branch information
hugtalbot committed Dec 17, 2024
1 parent 75f342c commit e3304b6
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,30 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::

{
SCOPED_TIMER("ComputeRHTerm");

if (firstOrder)
{
b.eq(f);
b.eq(f); // b = f
}
else
{
// new more powerful visitors

// force in the current configuration
b.eq(f, 1.0 / tr); // b = f
b.eq(f); // b = f

msg_info() << "EulerImplicitSolver, f = " << f;

// add the change of force due to stiffness + Rayleigh damping
mop.addMBKv(b, -d_rayleighMass.getValue(), 0,
h + d_rayleighStiffness.getValue()); // b = f + ( rm M + (h+rs) K ) v
h * tr + d_rayleighStiffness.getValue()); // b = f + ( rm M + (h+rs) K ) v

// integration over a time step
b.teq(h *
tr); // b = h(f + ( rm M + (h+rs) K ) v )
b.teq(h); // b = h(f + ( rm M + (h+rs) K ) v )
}

msg_info() << "EulerImplicitSolver, b = " << b;

mop.projectResponse(b); // b is projected to the constrained space
mop.projectResponse(b); // b is projected to the constrained space

msg_info() << "EulerImplicitSolver, projected b = " << b;
}
Expand All @@ -173,7 +171,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
{
mFact = 1 + tr * h * d_rayleighMass.getValue();
bFact = -tr * h;
kFact = -tr * h * (h + d_rayleighStiffness.getValue());
kFact = -tr * h * (tr * h + d_rayleighStiffness.getValue());
}
mop.setSystemMBKMatrix(mFact, bFact, kFact, l_linearSolver.get());

Expand Down Expand Up @@ -234,7 +232,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
sofa::helper::AdvancedTimer::stepBegin(prevStep);
#define SOFATIMER_NEXTSTEP(s) { sofa::helper::AdvancedTimer::stepNext(prevStep,s); prevStep=s; }

// vel = vel + x
// v(t+dt) = Δv + v(t)
newVel.eq(vel, x);

if (solveConstraint)
Expand All @@ -244,7 +242,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
}
SOFATIMER_NEXTSTEP("UpdateX");

// pos = pos + h vel
// x(t+dt) = x(t) + dt * v(t+dt)
newPos.eq(pos, newVel, h);

if (solveConstraint)
Expand Down

0 comments on commit e3304b6

Please sign in to comment.