Ouigo has opened reservations for tickets in summer and last side 2024.   They have only five Barcelona - Madrid trains but if you can get them.... just have a look for prices       If it is not possible to use these schedules, just use Renfe or Iryo but... 9 euro is not bad for a journey