The paper describes a novel approach to include longitudinal train dynamics within multibody codes by means of a dummy user force element. The latter solves the ordinary differential equations describing longitudinal train dynamics through the definition of additional dynamic states, and it calculates the in-train forces, which have a strong effect on the running safety of railway vehicles. The novel strategy allows to evaluate longitudinal train dynamics and multibody dynamics within the same computational framework, thus solving the dynamic states of both problems with the same numerical integrator. The method is first validated in simulation scenarios of an international benchmarking activity against traditional approaches and then it is applied to evaluate the dynamic safety of an emergency braking operation of a European freight train. With respect to developing multibody models with one body per vehicle in the train consist, the novel approach can be up to four times faster. Moreover, the novel method proves to be faster by up to one order of magnitude when compared to co-simulation strategies, whose accuracy is strongly related to a proper tuning of the communication rate.