HOWTO make the simulation better
Contents
How To Make Good Simulations
(just notes for now)
Integrator accuracy and stability
- integrator will not give exact solution
- what is stabilty
- integrator types (exp & imp, order)
- tradeoff between accuracy, stability and work
Behavior may depend on step size
- smaller step = more accurate, more stable
- 10*0.1 not the same as 5*0.2
- tweak at final frame rate
Making things go faster
What factors does execution speed depend on? Each joint removes a number of degrees of freedom (DOFs) from the system. For example the ball and socket removes three, and the hinge removes five. For each separate group of bodies connected by joints, where:
- m1 is the number of joints in the group,
- m2 is the total number of DOFs removed by those joints, and
- n is the number of bodies in the group, then the computing time per step for the group is proportional to: k1 O(m1) + k2 O(m23) + k2 O(n)
ODE currently relies on factorization of a "system" matrix that has one row/column for each DOF removed (this is where the O(m23) comes from). In a 10 body chain that uses ball and socket joints, roughly 30-40% of the time is spent filling in this matrix, and 30-40% of the time is spent factorizing it.
Thus, to speed up your simulation you might consider:
- Using less joints - often small bodies and their associated joints can be replaced by purely kinematic "fakes" without harming physical realism.
- Replacing multiple joints with simpler alternatives. This will become easier as more specialized joint types are defined.
- Using less contacts.
- Preferring frictionless or viscous friction contacts (that remove one DOF) over Coulomb friction contacts (that remove three DOFs) where possible. In the future ODE will implement techniques that scale better with the number of joints.
Making things stable
- stiff springs / stiff forces are bad.
- hard constraints are good.
- dependence on integration timestep.
- Use powered joint, joint limits, built-in springs as much as possible, avoid explicit forces.
- if bodies move faster than is reasonable for the timestep
- inertias with long axes
- mass ratios - e.g. a whip. Joints that connect large and small masses together will have a harder time keeping their error low.
- object size ratios. If a sphere of size 1 has to roll over a polygon a 1000 units long, you might start to see the ball jitter slightly, or in some cases even start to suddenly bounce while it was lying still on the ground. This can easily be solved by subdividing the polygon into several smaller polygons.
- Increasing the global CFM will make the system more numerically robust and less susceptible to stability problems. It will also make the system look more "spongy", so a tradeoff has to be found.
- Redundant constraints (two or more constraints that "try and do the same job") will fight each other and cause stability problems. The numerical cause of this problem is singularity in the system matrix. One example of this is if two contacts joints connect the same pair of bodies at the same point. Another example is if a virtual hinge joint is created between two bodies by connecting them with two ball joints, spaced apart along the hinge axis (this is bad because the two ball joints try to remove six degrees of freedom from the system, but a real hinge joint would only remove five). Redundant constraints fight each other and generate strange forces in the system that can swamp the normal forces. For example, an affected body might fly around as though it has a life of its own, with complete disregard for gravity.
Using constraint force mixing (CFM)
- allow singular configurations
- effects: jitter or strange forces due to error amplification, LCP solver may go slow
- allow compliant joints (this may be unwanted also)
Avoiding singularities
- Singularity occurs when there are more joints than needed to constrain the bodies motions.
- Multiple (incompatible) joints between bodies, esp joint + contact (don't collide objects that are joined together).
- increasing CFM
- unintentional - box chain on floor, other assemblies
- use minimum joints for correct behavior. use correct joints for desired behavior
- adding global CFM usually helps
Other stuff
- contact jitter when pushed out too far - soln: use softness
- keep lengths and masses around 1
- LCP solver takes a variable number of iterations (only non-deterministic part). if it takes too long, increase global CFM, prevent multiple contacts (or similar), and limit high ratio of force magnitudes (tree grabbing problem)
- hinge limits outside +/- pi