A thermal periodic boundary condition for heating and cooling processes