From 8d83c024db5f802833eb599170dc5508892a59d7 Mon Sep 17 00:00:00 2001 From: jthomas475 Date: Mon, 8 Jun 2026 10:33:39 -0400 Subject: [PATCH] ChamberSphere Periodicity Fix Updated phase_tsys and phase_tdias calculations for elastance values in ChamberSphere --- src/model/ChamberSphere.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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;