#include <stdio.h>
#include <stdlib.h>

#include "util.h"

#define CFL 0.5

/*********************************************************************/
/* TVD (superbee)                                                    */
/*********************************************************************/

double get_r(double *current){
  if(*(current+1) == *current){return (double)0;}
  else{return (*current - *(current-1)) / (*(current+1) - *current);} 
}

double get_B(double *current){
  double r = get_r(current);
  return max(0, max(min(r * 2, 1.0), min(2, r)));
}

double get_f(double *current){
  return *current \
            + get_B(current) * (*(current+1) - *current) * (1.0 - CFL) / 2;
}

double get_delta(double *current){
  return -CFL * (get_f(current) - get_f(current-1));
}
