Port-Based Modeling and Simulation of Mechanical Systems With Rigid and Flexible Links