  We present a conservative/dissipative time integration scheme for nonlinear
mechanical systems. Starting from a weak form, we derive algorithmic forces and
velocities that guarantee the desired conservation/dissipation properties. Our
approach relies on a collection of linearly constrained quadratic programs
defining high order correction terms that modify, in the minimum possible way,
the classical midpoint rule so as to guarantee the strict energy
conservation/dissipation properties. The solution of these programs provides
explicit formulas for the algorithmic forces and velocities which can be easily
incorporated into existing implementations. Similarities and differences
between our approach and well-established methods are discussed as well. The
approach, suitable for reduced-order models, finite element models, or
multibody systems, is tested and its capabilities are illustrated by means of
several examples.
