Constraint damping in the Z4 formulation and harmonic gauge