Generalized Energy-Conserving Dissipative Particle Dynamics with Mass Transfer. Part 1: Theoretical Foundation and Algorithm.