There are several university residences in Barcelona, for students, professors and research. For long term and short term stays:

Residència Torre Girona

At the Zona Universitària of Barcelona, close to the UPC School of Mathematics and Mathematics Departments.

Residència Campus del Mar

Close to the city centre, by the beach.

Residència d’Investigadors

Close to the city centre, and to the School of Mathematics of the UB and its Mathematics Departments.

La Vila Universitària

Apartments for rent for long term and short term stays, at the UAB campus, close to the Department of Mathematics of the UAB and close to the CRM.

If you wish to rent an apartment or share an apartment, these are the main web pages you can search:
RESA housing service (for universities):