Stan ODE intervention

Hi guys, I would like to use a model with intervention in stan, but the problem is the time consuming for running the code. I was wondering there might be an issue. It is appended here.

functions {
  real[] seiurc(real t, real[] y, real[] theta, 
               real[] x_r, int[] x_i) {
      
      real S = y[1];
      real E = y[2];
      real I = y[3];
      real U = y[4];
      real R = y[5];
      real C = y[6];
      real N = x_i[1];
      
      real beta0 = theta[1];
      real beta1 = theta[2];
      real q = theta[3];
      real rho = theta[4];
      real betaf;
      
      if (t < 42) {
          betaf=beta0;
      } else {
          betaf = beta1+(beta0-beta1)*exp(-q*t);
      }
      
      real dS_dt = -betaf * (I+U) * S / N;
      real dE_dt = betaf * (I+U) * S / N - 0.5 * E;
      real dI_dt =  0.5 * rho * E - 0.25 * I;
      real dU_dt = 0.5 * (1-rho) * E - 0.25 * U;
      real dR_dt =  0.25 * (I+U);
      real dC_dt = rho * 0.5 * E;
      
      return {dS_dt, dE_dt, dI_dt, dU_dt, dR_dt, dC_dt};
  }
}

In fact, after 42 days, we can see a parameter beta1 is added to the model.

That betaf is discontinuous. You may have better luck with

      if (t < 42) {
          betaf=beta0;
      } else {
          betaf = beta1+(beta0-beta1)*exp(-q*(t-42));
      }

hmmm…I see what you mean. thanks.