Do hard walls conserve energy?
They should, but need to be carefully implemented. The potential energy depends on position – if you move the particle back into the box, you will change the energy. The kinetic energy depends on the magnitude of the velocity – if you reverse the sign of one component that should be OK. But there is a caveat about timestep – the displacement at each step in MD should be “small relative to change of the potential”. A hard wall is an infinite potential… Hard walls certainly do not conserve momentum. Indeed shock wave simulations are done by applying a hard wall boundary at one end of the simulation, and a free surface at the other. This is called a “momentum mirror”.