Minor island solver simplification
This commit is contained in:
committed by
Sébastien Crozet
parent
0bb0e412e6
commit
e740493b98
@@ -11,7 +11,7 @@ use crate::dynamics::{
|
|||||||
};
|
};
|
||||||
use crate::dynamics::{IslandManager, RigidBodyVelocity};
|
use crate::dynamics::{IslandManager, RigidBodyVelocity};
|
||||||
use crate::geometry::{ContactManifold, ContactManifoldIndex};
|
use crate::geometry::{ContactManifold, ContactManifoldIndex};
|
||||||
use crate::prelude::{MultibodyJointSet, RigidBodyActivation};
|
use crate::prelude::MultibodyJointSet;
|
||||||
|
|
||||||
pub struct IslandSolver {
|
pub struct IslandSolver {
|
||||||
contact_constraints: SolverConstraints<AnyVelocityConstraint, AnyGenericVelocityConstraint>,
|
contact_constraints: SolverConstraints<AnyVelocityConstraint, AnyGenericVelocityConstraint>,
|
||||||
@@ -51,113 +51,54 @@ impl IslandSolver {
|
|||||||
+ ComponentSetMut<RigidBodyPosition>
|
+ ComponentSetMut<RigidBodyPosition>
|
||||||
+ ComponentSetMut<RigidBodyVelocity>
|
+ ComponentSetMut<RigidBodyVelocity>
|
||||||
+ ComponentSetMut<RigidBodyMassProps>
|
+ ComponentSetMut<RigidBodyMassProps>
|
||||||
+ ComponentSetMut<RigidBodyActivation>
|
|
||||||
+ ComponentSet<RigidBodyDamping>
|
+ ComponentSet<RigidBodyDamping>
|
||||||
+ ComponentSet<RigidBodyIds>
|
+ ComponentSet<RigidBodyIds>
|
||||||
+ ComponentSet<RigidBodyType>,
|
+ ComponentSet<RigidBodyType>,
|
||||||
{
|
{
|
||||||
let mut has_constraints = manifold_indices.len() != 0 || joint_indices.len() != 0;
|
// Init the solver id for multibody_joints.
|
||||||
if !has_constraints {
|
// We need that for building the constraints.
|
||||||
// Check if the multibody_joints have internal constraints.
|
let mut solver_id = 0;
|
||||||
for handle in islands.active_island(island_id) {
|
for (_, multibody) in multibody_joints.multibodies.iter_mut() {
|
||||||
if let Some(link) = multibody_joints.rigid_body_link(*handle) {
|
multibody.solver_id = solver_id;
|
||||||
let multibody = multibody_joints.get_multibody(link.multibody).unwrap();
|
solver_id += multibody.ndofs();
|
||||||
|
|
||||||
if (link.id == 0 || link.id == 1 && !multibody.root_is_dynamic)
|
|
||||||
&& multibody.has_active_internal_constraints()
|
|
||||||
{
|
|
||||||
has_constraints = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_constraints {
|
counters.solver.velocity_assembly_time.resume();
|
||||||
// Init the solver id for multibody_joints.
|
self.contact_constraints.init(
|
||||||
// We need that for building the constraints.
|
island_id,
|
||||||
let mut solver_id = 0;
|
params,
|
||||||
for (_, multibody) in multibody_joints.multibodies.iter_mut() {
|
islands,
|
||||||
multibody.solver_id = solver_id;
|
bodies,
|
||||||
solver_id += multibody.ndofs();
|
multibody_joints,
|
||||||
}
|
manifolds,
|
||||||
|
manifold_indices,
|
||||||
|
);
|
||||||
|
self.joint_constraints.init(
|
||||||
|
island_id,
|
||||||
|
params,
|
||||||
|
islands,
|
||||||
|
bodies,
|
||||||
|
multibody_joints,
|
||||||
|
impulse_joints,
|
||||||
|
joint_indices,
|
||||||
|
);
|
||||||
|
counters.solver.velocity_assembly_time.pause();
|
||||||
|
|
||||||
counters.solver.velocity_assembly_time.resume();
|
counters.solver.velocity_resolution_time.resume();
|
||||||
self.contact_constraints.init(
|
self.velocity_solver.solve(
|
||||||
island_id,
|
island_id,
|
||||||
params,
|
params,
|
||||||
islands,
|
islands,
|
||||||
bodies,
|
bodies,
|
||||||
multibody_joints,
|
multibody_joints,
|
||||||
manifolds,
|
manifolds,
|
||||||
manifold_indices,
|
impulse_joints,
|
||||||
);
|
&mut self.contact_constraints.velocity_constraints,
|
||||||
self.joint_constraints.init(
|
&mut self.contact_constraints.generic_velocity_constraints,
|
||||||
island_id,
|
&self.contact_constraints.generic_jacobians,
|
||||||
params,
|
&mut self.joint_constraints.velocity_constraints,
|
||||||
islands,
|
&self.joint_constraints.generic_jacobians,
|
||||||
bodies,
|
);
|
||||||
multibody_joints,
|
counters.solver.velocity_resolution_time.pause();
|
||||||
impulse_joints,
|
|
||||||
joint_indices,
|
|
||||||
);
|
|
||||||
counters.solver.velocity_assembly_time.pause();
|
|
||||||
|
|
||||||
counters.solver.velocity_resolution_time.resume();
|
|
||||||
self.velocity_solver.solve(
|
|
||||||
island_id,
|
|
||||||
params,
|
|
||||||
islands,
|
|
||||||
bodies,
|
|
||||||
multibody_joints,
|
|
||||||
manifolds,
|
|
||||||
impulse_joints,
|
|
||||||
&mut self.contact_constraints.velocity_constraints,
|
|
||||||
&mut self.contact_constraints.generic_velocity_constraints,
|
|
||||||
&self.contact_constraints.generic_jacobians,
|
|
||||||
&mut self.joint_constraints.velocity_constraints,
|
|
||||||
&self.joint_constraints.generic_jacobians,
|
|
||||||
);
|
|
||||||
counters.solver.velocity_resolution_time.pause();
|
|
||||||
} else {
|
|
||||||
self.contact_constraints.clear();
|
|
||||||
self.joint_constraints.clear();
|
|
||||||
counters.solver.velocity_update_time.resume();
|
|
||||||
|
|
||||||
for handle in islands.active_island(island_id) {
|
|
||||||
if let Some(link) = multibody_joints.rigid_body_link(*handle).copied() {
|
|
||||||
let multibody = multibody_joints
|
|
||||||
.get_multibody_mut_internal(link.multibody)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if link.id == 0 || link.id == 1 && !multibody.root_is_dynamic {
|
|
||||||
let accels = &multibody.accelerations;
|
|
||||||
multibody.velocities.axpy(params.dt, accels, 1.0);
|
|
||||||
multibody.integrate(params.dt);
|
|
||||||
multibody.forward_kinematics(bodies, false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Since we didn't run the velocity solver we need to integrate the accelerations here
|
|
||||||
let (poss, vels, forces, damping, mprops): (
|
|
||||||
&RigidBodyPosition,
|
|
||||||
&RigidBodyVelocity,
|
|
||||||
&RigidBodyForces,
|
|
||||||
&RigidBodyDamping,
|
|
||||||
&RigidBodyMassProps,
|
|
||||||
) = bodies.index_bundle(handle.0);
|
|
||||||
|
|
||||||
let mut new_poss = *poss;
|
|
||||||
let new_vels = forces
|
|
||||||
.integrate(params.dt, vels, mprops)
|
|
||||||
.apply_damping(params.dt, &damping);
|
|
||||||
new_poss.next_position =
|
|
||||||
vels.integrate(params.dt, &poss.position, &mprops.local_mprops.local_com);
|
|
||||||
|
|
||||||
bodies.set_internal(handle.0, new_vels);
|
|
||||||
bodies.set_internal(handle.0, new_poss);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
counters.solver.velocity_update_time.pause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use crate::dynamics::{
|
|||||||
use crate::dynamics::{IslandManager, RigidBodyIds, RigidBodyMassProps};
|
use crate::dynamics::{IslandManager, RigidBodyIds, RigidBodyMassProps};
|
||||||
use crate::geometry::ContactManifold;
|
use crate::geometry::ContactManifold;
|
||||||
use crate::math::Real;
|
use crate::math::Real;
|
||||||
use crate::prelude::{RigidBodyActivation, RigidBodyDamping, RigidBodyPosition};
|
use crate::prelude::{RigidBodyDamping, RigidBodyPosition};
|
||||||
use crate::utils::WAngularInertia;
|
use crate::utils::WAngularInertia;
|
||||||
use na::DVector;
|
use na::DVector;
|
||||||
|
|
||||||
@@ -47,7 +47,6 @@ impl VelocitySolver {
|
|||||||
+ ComponentSetMut<RigidBodyVelocity>
|
+ ComponentSetMut<RigidBodyVelocity>
|
||||||
+ ComponentSetMut<RigidBodyMassProps>
|
+ ComponentSetMut<RigidBodyMassProps>
|
||||||
+ ComponentSetMut<RigidBodyPosition>
|
+ ComponentSetMut<RigidBodyPosition>
|
||||||
+ ComponentSetMut<RigidBodyActivation>
|
|
||||||
+ ComponentSet<RigidBodyDamping>,
|
+ ComponentSet<RigidBodyDamping>,
|
||||||
{
|
{
|
||||||
let cfm_factor = params.cfm_factor();
|
let cfm_factor = params.cfm_factor();
|
||||||
|
|||||||
Reference in New Issue
Block a user