Particle merging algorithm for PIC codes