diff --git a/src/model/ChamberSphere.cpp b/src/model/ChamberSphere.cpp index 6971e7713..b3a086c72 100644 --- a/src/model/ChamberSphere.cpp +++ b/src/model/ChamberSphere.cpp @@ -119,8 +119,16 @@ void ChamberSphere::get_elastance_values(std::vector& parameters) { const auto T_cardiac = model->cardiac_cycle_period; const auto t_in_cycle = fmod(model->time, T_cardiac); - const double S_plus = 0.5 * (1.0 + tanh((t_in_cycle - tsys) / steepness)); - const double S_minus = 0.5 * (1.0 - tanh((t_in_cycle - tdias) / steepness)); + + auto warp_signed = [T_cardiac](double dt){ + return fmod(dt + 1.5 * T_cardiac, T_cardiac) - 0.5 * T_cardiac; + }; + + const double phase_tsys = warp_signed(t_in_cycle - tsys); + const double phase_tdias = warp_signed(t_in_cycle - tdias); + + const double S_plus = 0.5 * (1.0 + tanh((phase_tsys) / steepness)); + const double S_minus = 0.5 * (1.0 - tanh((phase_tdias - tdias) / steepness)); // indicator function const double f = S_plus * S_minus;