forked from cmrg-lab/dATP_multiscale_modeling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardiovascularMechanics.m
1443 lines (1218 loc) · 50.6 KB
/
CardiovascularMechanics.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%% Main code to run ventricular model
% Adapted by Abby Teitgen based on code from:
% Tewari, S. G., Bugenhagen, S. M., Palmer, B. M, Beard,
% D. A. (2016). Dynamics of corss-bridge cycling, ATP hydrolysis, force
% generation, and deformation in cardiac muscle. J. Mol. Cell Cardiol. 96:
% 11-25.
% Tewari, S. G., Bugenhagen, S. M., Vinnakota, K. C., Rice, J. J., Janssen,
% M. L., Beard, D. A. (2016). Influence of metabolic dysfuntion on cardiac
% mechanics in decompensated hypertrophy and heart failure. J. Mol.
% Cell Cardiol. 94: 162-175.
% Lopez, R. Marzban, B., Gao, X. Lauinger, E., Van den Bergh, F.,
% Whitesall, S. E., Converso-Baran, K., Burant, C. F., Michele, D. E.,
% Beard, D. A. (2020). Impaired myocardial energetics causes mechanical dysfunction
% in decompensated failing hearts. Function, 1(2): zqaa018
% Marzban, B., Lopez, R., Beard, D. A. (2020). Computational modeling of coupled
% energetics and mechanics in the rat ventricular myocardium. Physiome.
function [V_LV_store_F, P_LV_store_F, max_force, FS, CO, EF, LVDP, work_rate_F, ATP_F, ADP_F, Pi_F, MVO2_F, PCrATP_F, XB_turnover_F, ATPase_F, efficiency_F] = CardiovascularMechanics(Ca, HF, dATP_percent, kf_i, k_f_i, kw_i, k_w_i, kp_i, k_p_i, kg_i, k_recruit_i, k_on_i, k_off_i, k_coop_i, a_i, b_i, c_i)
%% Flags
% Calcium
Ca_flag = Ca; % 0 = ATP, 1 = dATP
% Protocol
HF_flag = HF; % 0 = healthy, 1 = HF
% Percent dATP
dATP = dATP_percent;
ATP = 100-dATP_percent;
%% Parameters
% Heart
BW = 614; % Body weight (g)
LVW = 1.1127e+03; % LV weight (mg)
RVW = 335.8125; % RV weight (mg)
LW = 2.3414e+03; % Lung weight (mg)
HR = 344.75; % Heart rate (beats/min)
C_Ao = 0.0015; % Proximal aortic compliance (mL/mmHg)
C_SA = 0.0077157; % Systemic arterial compliance (mL/mmHg)
C_SV = 2.5; %2.5; % Systemic venous compliance (mL/mmHg)
C_PV = 0.25; % Pulmonary venous compliance (mL/mmHg)
C_PA = 0.013778; % Pulmonary arterial compliance (mL/mmHg)
R_Ao = 2.5; % Aortic resistance (mmHg*sec/mL)
R_SA = 56.4565; % Systemic vasculature resistance (mmHg*sec/mL)
R_PA = 7.6986; % Pulmonary arterial resistance (mmHg*sec/mL)
R_SV = 0.25; % Systemic venous resistance (mmHg*sec/mL)
R_PV = 0.25; % Pulmonary venous resistance (mmHg*sec/mL)
R_vlv = 0.05; % Valve resistance (mmHg*sec/mL)
R_AV = R_vlv; % Resistance across aortic valve (mmHg*sec/mL)
R_tAo = 0.5; % Transmural aortic resistance (mmHg*sec/mL)
R_tSA = 4; % Transmural systemic arterial resistance (mmHg*sec/mL)
% Geometry
Amref_LV = 2.0776*1.28; % LV midwall reference surface area (cm^2)
Amref_SEP = 1.2475*1.28; % SEP midwall reference surface area (cm^2)
Amref_RV = 3.1751*1.28; % RV midwall reference surface area (cm^2)
Vw_LV = 0.7065; % LV wall volume (mL)
Vw_SEP = 0.35335; % SEP wall volume (mL)
Vw_RV = 0.31985; % RV wall volume (mL)
% Energetics
TAN = 0.0076; % Total adenine nucleotide pool (M/L cell)
CRtot = 0.0303; % Total creatine pool (M/L cell)
Ox_capacity = 1; % Oxidative capacity
Ox_capacity_sham = 1; % Oxidative capacity for mean sham
Ox_capacity_TAC = 0.7482; %Oxidative capacity for mean TAC
TAN_sham = 0.0076; % Total adenine nucleotide pool for mean sham (M/L cell)
CRtot_sham = 0.0303; % Total creatine pool for mean sham (M/L cell)
TAN_TAC = 0.0070; % Total adenine nucleotide pool for mean TAC (M/L cell)
CRtot_TAC = 0.0230; % Total creatine pool for mean TAC (M/L cell)
Ao = 10.260e-3; % (M/L cell)
Co = 43.007e-3; % (M/L cell)
Po = 35.446e-3; % (M/L cell)
TEP = Po - (0.283e-3)*(Ao-TAN)/(0.082e-3); % Total exchangeable phosphate (M/L cell)
TEP_sham = Po - (0.283e-3)*(Ao-TAN_sham)/(0.082e-3); % Total exchangeable phosphate for mean sham (M/L cell)
TEP_TAC = Po - (0.283e-3)*(Ao-TAN_TAC)/(0.082e-3); % Total exchangeable phosphate pool (failure), mol/L cell
tune_ATPase_LV = 0.0019; % ATP hydrolysis rate (M/s/L cytosol)
rate_of_XB_turnover_mean_sham = 5.0147; % Crossbridge turnover rate (1/s)
if HF_flag == 0 % Healthy
TAN = TAN_sham;
CRtot = CRtot_sham;
TEP = TEP_sham;
Ox_capacity = Ox_capacity_sham;
else % HF
TAN = TAN_TAC;
CRtot = CRtot_TAC;
TEP = TEP_TAC;
Ox_capacity = Ox_capacity_TAC;
end
% Crossbridge
Lsref = 1.9; % Resting sarcomere length (um)
L_rest_pas = 1.51; % Length at which passive force = 0 (um)
gamma = 8; % For calculating passive force
K_Pi = 4.00;
K_T = 0.4897;
K_D = 0.194;
alpha1 = 10.0; % Stretch sensing parameter for kw and k_w (1/um)
alpha2 = 9.1; % Stretch sensing parameter for kp and k_p (1/um)
alpha3 = 0.1*59.3; % Stretch sensing parameter for k_3 (1/um)
s3 = 9.9e-3; % Strain at which kg is minimum (um)
Kse = 10000; % Series stiffness (mmHg/um)
k_passive_LV = 58000; % Passive stiffness (mmHg/um)
k_passive_SEP = 58000;
k_passive_RV = 58000;
eta = 0.0001; % Viscosity (mmHg*s/um)
L_thick = 1.67; % Length of thick filament (um)
L_hbare = 0.10; % Length of bare region of thick filament (um)
L_thin = 1.20; % Length of thin filament (um)
deltaR = 0.010; % um
kstiff1 = 1.4*1.7351e+03*7.5; % Stiffness constant due to myosin actin interaction (kPa/um)
kstiff2 = 1.4*45545*7.5; % Stiffness constant due to working stroke of XBs (kPa/um)
kf = 250*(ATP/100) + kf_i*(dATP/100); % P to A1 transition rate (1/s)
k_f = 304.6708*(ATP/100) + k_f_i*(dATP/100); % A1 to P transition rate (1/s)
kw = 112.3727*(ATP/100) + kw_i*(dATP/100); % A1 to A2 transition rate (1/s)
km1 = 21.296*(ATP/100) + k_w_i*(dATP/100); % A2 to A1 transition rate (1/s)
kp = 811.72*(ATP/100) + kp_i*(dATP/100); % A2 to A3 transition rate (1/s)
km2 = 43.25*(ATP/100) + k_p_i*(dATP/100); % A3 to A2 transition rate (1/s)
kg = 144.5586*(ATP/100) + kg_i*(dATP/100); % A3 to P transition rate (1/s)
K_coop = k_coop_i; % Cooperative constant
k_on = k_on_i; % N to P transition rate (1/Ms)
k_off = k_off_i; % P to N transition rate (1/s)
km = 15.4691375; % OFF to ON transition rate (N^-1 m^-1)
k_recruit = 0.2069*(ATP/100) + k_recruit_i*(dATP/100); % Force dependent constant (1/Nm^s)
k_m = 50.032; % ON to OFF transition rate (1/s)
% Calcium
% para_fitted_Ca = [2 3 4 5 6 7 8 9 10;
% 0.0838 0.1306 0.1802 0.2557 0.3099 0.3613 0.408 0.4539 0.4602;
% 0.7513 0.8756 1.0274 1.4988 1.6107 1.6741 1.7902 2.1398 1.9832;
% 2.237 2.0486 1.948 1.852 1.6932 1.6773 1.5988 1.4952 1.4524;
% 0.1865 0.1815 0.1709 0.1693 0.161 0.1661 0.1425 0.1458 0.1222];
% freq_all = para_fitted_Ca(1,:);
% A_HR_pchip = pchip(freq_all,para_fitted_Ca(2,:));
% A_HR = ppval(A_HR_pchip,HR/60);
% B_HR_pchip = pchip(freq_all,para_fitted_Ca(3,:));
% B_HR = ppval(B_HR_pchip,HR/60);
% C_HR_pchip = pchip(freq_all,para_fitted_Ca(4,:));
% C_HR = ppval(C_HR_pchip,HR/60);
% Ca0_HR_pchip = pchip(freq_all,para_fitted_Ca(5,:));
% Ca0_HR = ppval(Ca0_HR_pchip,HR/60);
A_HR = a_i;
B_HR = b_i;
C_HR = c_i;
Ca0_HR = 0.1622;
%% Initial conditions
% Heart
V_LV = 0.6167+0.1; % LV volume (mL)
V_RV = 0.6167+0.1; % RV volume (mL)
V_SA = 3.3043; % Systemic arteries volume (mL)
V_SV = 5.2868; % Systemic veins volume (mL)
V_PA = 0.5507; % Pulmonary arteries volume (mL)
V_PV = 1.1014; % Pulmonary veins volume (mL)
V_Ao = 1.1014; % Aorta volume (mL)
% Geometry
xm_LV = -0.60; % Maximal axial distance from LV midwall surface to origin (cm)
xm_SEP = 0.40; % Maximal axial distance from SEP midwall surface to origin (cm)
xm_RV = 1.0; % Maximal axial distance from RV midwall surface to origin (cm)
ym = 0.50; % Radius of midwall junction circle (cm)
% Energetics
energtics_output = EnergeticsModelScript(TAN, CRtot, TEP, Ox_capacity, tune_ATPase_LV); % Get metabolite concentrations
MgATP_cyto = energtics_output(1); % Cytosolic MgATP concentration (M/(L cytosol water)^-1)
MgADP_cyto = energtics_output(2); % Cytosolic MgADP concentration (M/(L cytosol water)^-1)
fPi_cytoplasm = energtics_output(3); % Cytosolic unchelated Pi concentration (M/(L cytosol water)^-1)
MVO2_tissue = energtics_output(5); % Oxygen consumption rate (uM/min^-1(g tissue)^-1)
dGrATPase = energtics_output(6); % ATP hydrolysis free energy, kJ/mol
PCrATP = energtics_output(7); % Creatine phoosphate ATP ratio, unitless
ATP_cyto = energtics_output(8); % Cytosolic total ATP concentration (M/(L cytosol water)^-1)
ADP_cyto = energtics_output(9); % Cytosolic total ADP concentration (M/(L cytosol water)^-1)
Pi_cyto = energtics_output(10)*1000; % Cytosolic total Pi concentration (M/(L cytosol water)^-1)
ATP_store(1) = MgATP_cyto;
ADP_store(1) = MgADP_cyto*1000;
Pi_store(1) = Pi_cyto;
MVO2_tissue_store(1) = MVO2_tissue;
PCrATP_store(1) = PCrATP;
% Crossbridge
SL_LV = 2.2; % LV sarcomere length (um)
SL_SEP = 2.2; % SEP sarcomere length (um)
SL_RV = 2.2; % RV sarcomere length (um)
P1_0_LV = 0; % 0th moment state A1, LV
P1_1_LV = 0; % 1st moment state A1, LV
P1_2_LV = 0; % 2nd moment state A1, LV
P2_0_LV = 0; % 0th moment state A2, LV
P2_1_LV = 0; % 1st moment state A2, LV
P2_2_LV = 0; % 2nd moment state A2, LV
P3_0_LV = 0; % 0th moment state A3, LV
P3_1_LV = 0; % 1st moment state A3, LV
P3_2_LV = 0; % 2nd moment state A3, LV
N_LV = 1; % Non permissible state, LV
U_NR_LV = 0; % ON state, LV
P1_0_SEP = 0; % 0th moment state A1, SEP
P1_1_SEP = 0; % 1st moment state A1, SEP
P1_2_SEP = 0; % 2nd moment state A1, SEP
P2_0_SEP = 0; % 0th moment state A2, SEP
P2_1_SEP= 0; % 1st moment state A2, SEP
P2_2_SEP = 0; % 2nd moment state A2, SEP
P3_0_SEP = 0; % 0th moment state A3, SEP
P3_1_SEP = 0; % 1st moment state A3, SEP
P3_2_SEP = 0; % 2nd moment state A3, SEP
N_SEP = 1; % Non permissible state, SEP
U_NR_SEP = 0; % ON state, SEP
P1_0_RV = 0; % 0th moment state A1, RV
P1_1_RV = 0; % 1st moment state A1, RV
P1_2_RV = 0; % 2nd moment state A1, RV
P2_0_RV = 0; % 0th moment state A2, RV
P2_1_RV = 0; % 1st moment state A2, RV
P2_2_RV = 0; % 2nd moment state A2, RV
P3_0_RV = 0; % 0th moment state A3, RV
P3_1_RV = 0; % 1st moment state A3, RV
P3_2_RV = 0; % 2nd moment state A3, RV
N_RV = 1; % Non permissible state, RV
U_NR_RV = 0; % ON state, RV
init = [xm_LV ,xm_SEP ,xm_RV ,ym , SL_LV, SL_SEP, SL_RV, V_LV, V_RV, ...
P1_0_LV, P1_1_LV, P1_2_LV ,P2_0_LV, P2_1_LV, P2_2_LV, P3_0_LV, P3_1_LV, P3_2_LV, N_LV, U_NR_LV,...
P1_0_SEP,P1_1_SEP,P1_2_SEP,P2_0_SEP,P2_1_SEP,P2_2_SEP,P3_0_SEP,P3_1_SEP,P3_2_SEP,N_SEP,U_NR_SEP,...
P1_0_RV, P1_1_RV, P1_2_RV, P2_0_RV, P2_1_RV, P2_2_RV, P3_0_RV, P3_1_RV, P3_2_RV, N_RV, U_NR_RV,...
V_SV, V_PV ,V_SA ,V_PA, V_Ao]';
% Get consistent initial conditions for solving DAE
opts = optimset('MaxFunEvals',10000,'MaxIter',1000);
x_triseg = fsolve(@TrisegEquations,init(1:4), opts, Vw_LV, Vw_SEP, Vw_RV, SL_LV, SL_SEP, SL_RV, V_LV, V_RV, Amref_LV, Amref_SEP, Amref_RV);
init(1:4) = x_triseg;
%% Run initially to steady state without coupled energetics model
stim_period = 1/(HR/60);
M = speye(47);
M(1,1) = 0;
M(2,2) = 0;
M(3,3) = 0;
M(4,4) = 0;
input = [stim_period, C_Ao, C_SA, C_SV, C_PV, C_PA, R_Ao, R_SA, R_PA, R_SV, R_PV, R_vlv, R_AV, ...
R_tAo, R_tSA, Amref_LV, Amref_SEP, Amref_RV, Vw_LV, Vw_SEP, Vw_RV, MgATP_cyto, ...
MgADP_cyto, Pi_cyto, MgATP_cyto, MgADP_cyto, Pi_cyto, MgATP_cyto, MgADP_cyto, ...
Pi_cyto, Lsref, L_rest_pas, gamma, K_Pi, K_T, K_D, alpha1, alpha2, alpha3, s3, Kse, ...
k_passive_LV, k_passive_SEP, k_passive_RV, eta, L_thick, L_hbare, L_thin, deltaR, kstiff1, kstiff2, kf, k_f, kw, ...
km1, kp, km2, kg, K_coop, k_on, k_off, km, k_recruit, k_m, A_HR, B_HR, C_HR, Ca0_HR, dATP, Ca_flag];
options = odeset('Mass',M,'MassSingular','yes','RelTol',1e-7,'AbsTol',1e-7,'MaxStep',stim_period/200);
[t,Y] = ode15s(@dXdT_cardiovascular_mechanics,[0 120*stim_period], init, options, input);
t_store{1} = t;
Y_store{1} = Y;
% Calculate
% State variables
xm_LV = Y(:,1); % Maximal axial distance from LV midwall surface to origin (cm)
xm_SEP = Y(:,2); % Maximal axial distance from SEP midwall surface to origin (cm)
xm_RV = Y(:,3); % Maximal axial distance from RV midwall surface to origin (cm)
ym = Y(:,4); % Radius of midwall junction circle (cm)
SL_LV = Y(:,5); % LV sarcomere length (um)
SL_SEP = Y(:,6); % SEP sarcomere length (um)
SL_RV = Y(:,7); % RV sarcomere length (um)
V_LV = Y(:,8); % LV volume (mL)
V_RV = Y(:,9); % RV volume (mL)
% Store
xm_LV_store{1} = xm_LV;
xm_SEP_store{1} = xm_SEP;
xm_RV_store{1} = xm_RV;
ym_store{1} = ym;
SL_LV_store{1} = SL_LV;
SL_SEP_store{1} = SL_SEP;
SL_RV_store{1} = SL_RV;
V_LV_store{1} = V_LV;
V_RV_store{1} = V_RV;
P1_0_LV = Y(:,10); % 0th moment state A1, LV
P1_1_LV = Y(:,11); % 1st moment state A1, LV
P1_2_LV = Y(:,12); % 2nd moment state A1, LV
P2_0_LV = Y(:,13); % 0th moment state A2, LV
P2_1_LV = Y(:,14); % 1st moment state A2, LV
P2_2_LV = Y(:,15); % 2nd moment state A2, LV
P3_0_LV = Y(:,16); % 0th moment state A3, LV
P3_1_LV = Y(:,17); % 1st moment state A3, LV
P3_2_LV = Y(:,18); % 2nd moment state A3, LV
N_LV = Y(:,19); % Non permissible state, LV
U_NR_LV = Y(:,20); % ON, LV
% Store
A1_LV_store{1} = P1_0_LV;
A2_LV_store{1} = P2_0_LV;
A3_LV_store{1} = P3_0_LV;
N_LV_store{1} = N_LV;
P1_0_SEP = Y(:,21); % 0th moment state A1, SEP
P1_1_SEP = Y(:,22); % 1st moment state A1, SEP
P1_2_SEP = Y(:,23); % 2nd moment state A1, SEP
P2_0_SEP = Y(:,24); % 0th moment state A2, SEP
P2_1_SEP = Y(:,25); % 1st moment state A2, SEP
P2_2_SEP = Y(:,26); % 2nd moment state A2, SEP
P3_0_SEP = Y(:,27); % 0th moment state A3, SEP
P3_1_SEP = Y(:,28); % 1st moment state A3, SEP
P3_2_SEP = Y(:,29); % 2nd moment state A3, SEP
N_SEP = Y(:,30); % Non permissible state, SEP
U_NR_SEP = Y(:,31); % ON state, SEP
% Store
A1_SEP_store{1} = P1_0_SEP;
A2_SEP_store{1} = P2_0_SEP;
A3_SEP_store{1} = P3_0_SEP;
N_SEP_store{1} = N_SEP;
P1_0_RV = Y(:,32); % 0th moment state A1, RV
P1_1_RV = Y(:,33); % 1st moment state A1, RV
P1_2_RV = Y(:,34); % 2nd moment state A1, RV
P2_0_RV = Y(:,35); % 0th moment state A2, RV
P2_1_RV = Y(:,36); % 1st moment state A2, RV
P2_2_RV = Y(:,37); % 2nd moment state A2, RV
P3_0_RV = Y(:,38); % 0th moment state A3, RV
P3_1_RV = Y(:,39); % 1st moment state A3, RV
P3_2_RV = Y(:,40); % 2nd moment state A3, RV
N_RV = Y(:,41); % Non permissible state, RV
U_NR_RV = Y(:,42); % ON state, RV
% Store
A1_RV_store{1} = P1_0_RV;
A2_RV_store{1} = P2_0_RV;
A3_RV_store{1} = P3_0_RV;
N_RV_store{1} = N_RV;
V_SV = Y(:,43); % Systemic veins volume (mL)
V_PV = Y(:,44); % Pulmonary veins volume (mL)
V_SA = Y(:,45); % Systemic arteries volume (mL)
V_PA = Y(:,46); % Pulmonary arteries volume (mL)
V_Ao = Y(:,47); % Aorta volume (mL)
% V_T = V_LV + V_RV + V_SV + V_PV + V_SA + V_PA + V_Ao;
% Store
V_SV_store{1} = V_SV;
V_PV_store{1} = V_PV;
V_SA_store{1} = V_SA;
V_PA_store{1} = V_PA;
V_Ao_store{1} = V_Ao;
% Geometry
Vm_LV = (pi/6).*xm_LV.*(xm_LV.^2 + 3.*ym.^2); % LV midwall volume (mL)
Vm_SEP = (pi/6).*xm_SEP.*(xm_SEP.^2 + 3.*ym.^2); % SEP midwall volume (mL)
Vm_RV = (pi/6).*xm_RV.*(xm_RV.^2 + 3.*ym.^2); % RV midwall volume (mL)
Am_LV = pi.*(xm_LV.^2 + ym.^2); % LV midwall surface area (cm^2)
Am_SEP = pi.*(xm_SEP.^2 + ym.^2); % SEP midwall surface area (cm^2)
Am_RV = pi.*(xm_RV.^2 + ym.^2); % RV midwall surface area (cm^2)
Cm_LV = 2.*xm_LV./(xm_LV.^2 + ym.^2); % LV midwall surface curvature
Cm_SEP = 2.*xm_SEP./(xm_SEP.^2 + ym.^2); % SEP midwall surface curvature
Cm_RV = 2.*xm_RV./(xm_RV.^2 + ym.^2); % RV midwall surface curvature
z_LV = 3.*Cm_LV.*Vw_LV./(2.*Am_LV);
z_SEP = 3.*Cm_SEP.*Vw_SEP./(2.*Am_SEP);
z_RV = 3.*Cm_RV.*Vw_RV./(2.*Am_RV);
% Store
Vm_LV_store{1} = Vm_LV;
Vm_SEP_store{1} = Vm_SEP;
Vm_RV_store{1} = Vm_RV;
Am_LV_store{1} = Am_LV;
Am_SEP_store{1} = Am_SEP;
Am_RV_store{1} = Am_RV;
Cm_LV_store{1} = Cm_LV;
Cm_SEP_store{1} = Cm_SEP;
Cm_RV_store{1} = Cm_RV;
z_LV_store{1} = z_LV;
z_SEP_store{1} = z_SEP;
z_RV_store{1} = z_RV;
% Fiber strain
epsf_LV = 0.5.*log(Am_LV./Amref_LV) - 0.083333.*z_LV.^2 - 0.019.*z_LV.^4;
epsf_SEP = 0.5.*log(Am_SEP./Amref_SEP) - 0.083333.*z_SEP.^2 - 0.019.*z_SEP.^4;
epsf_RV = 0.5.*log(Am_RV./Amref_RV) - 0.083333.*z_RV.^2 - 0.019.*z_RV.^4;
% Sarcomere length
SLo_LV = Lsref.*exp(epsf_LV);
SLo_SEP = Lsref.*exp(epsf_SEP);
SLo_RV = Lsref.*exp(epsf_RV);
% Store
epsf_LV_store{1} = epsf_LV;
epsf_SEP_store{1} = epsf_SEP;
epsf_RV_store{1} = epsf_RV;
SLo_LV_store{1} = SLo_LV;
SLo_SEP_store{1} = SLo_SEP;
SLo_RV_store{1} = SLo_RV;
% Passive force
sigmapas_LV = k_passive_LV.*(SLo_LV - L_rest_pas).^(gamma);
sigmapas_SEP = k_passive_SEP.*(SLo_SEP - L_rest_pas).^(gamma);
sigmapas_RV = k_passive_RV.*(SLo_RV - L_rest_pas).^(gamma);
% Store
sigmapas_LV_store{1} = sigmapas_LV;
sigmapas_SEP_store{1} = sigmapas_SEP;
sigmapas_RV_store{1} = sigmapas_RV;
% Active force
sovr_ze = min(L_thick*0.5, SL_LV*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_LV*0.5 - (SL_LV-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_LV = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sovr_ze = min(L_thick*0.5, SL_SEP*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_SEP*0.5 - (SL_SEP-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_SEP = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sovr_ze = min(L_thick*0.5, SL_RV*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_RV*0.5 - (SL_RV-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_RV = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sigmaact_LV = N_overlap_LV.*(kstiff2.*deltaR.*(P3_0_LV) + kstiff1.*(P2_1_LV + P3_1_LV)); % Includes force due to XB ratcheting and stretching of XBs
sigmaact_SEP = N_overlap_SEP.*(kstiff2.*deltaR.*(P3_0_SEP) + kstiff1.*(P2_1_SEP + P3_1_SEP)); % Includes force due to XB ratcheting and stretching of XBs
sigmaact_RV = N_overlap_RV.*(kstiff2.*deltaR.*(P3_0_RV) + kstiff1.*(P2_1_RV + P3_1_RV)); % Includes force due to XB ratcheting and stretching of XBs
% Store
sigmaact_LV_store{1} = sigmaact_LV;
sigmaact_SEP_store{1} = sigmaact_SEP;
sigmaact_RV_store{1} = sigmaact_RV;
% Total force
sigmaf_LV = -Kse.*(SL_LV - SLo_LV);
sigmaf_SEP = -Kse.*(SL_SEP - SLo_SEP);
sigmaf_RV = -Kse.*(SL_RV - SLo_RV);
% Store
sigmaf_LV_store{1} = sigmaf_LV;
sigmaf_SEP_store{1} = sigmaf_SEP;
sigmaf_RV_store{1} = sigmaf_RV;
% Tension
Tm_LV = (Vw_LV.*sigmaf_LV./(2.*Am_LV)).*(1 + (z_LV.^2)/3 + (z_LV.^4)/5); % LV midwall tension
Tm_SEP = (Vw_SEP.*sigmaf_SEP./(2.*Am_SEP)).*(1 + (z_SEP.^2)/3 + (z_SEP.^4)/5); % SEP midwall tension
Tm_RV = (Vw_RV.*sigmaf_RV./(2.*Am_RV)).*(1 + (z_RV.^2)/3 + (z_RV.^4)/5); % RV midwall tension
Tx_LV = Tm_LV.*2.*xm_LV.*ym./(xm_LV.^2 + ym.^2); % LV axial tension
Tx_SEP = Tm_SEP.*2.*xm_SEP.*ym./(xm_SEP.^2 + ym.^2); % SEP axial tension
Tx_RV = Tm_RV.*2.*xm_RV.*ym./(xm_RV.^2 + ym.^2); % RV axial tension
Ty_LV = Tm_LV.*(-xm_LV.^2 + ym.^2)./(xm_LV.^2 + ym.^2); % LV radial tension
Ty_SEP = Tm_SEP.*(-xm_SEP.^2 + ym.^2)./(xm_SEP.^2 + ym.^2); % SEP radial tension
Ty_RV = Tm_RV.*(-xm_RV.^2 + ym.^2)./(xm_RV.^2 + ym.^2); % RV radial tension
% Store
Tm_LV_store{1} = Tm_LV;
Tm_SEP_store{1} = Tm_SEP;
Tm_RV_store{1} = Tm_RV;
Tx_LV_store{1} = Tx_LV;
Tx_SEP_store{1} = Tx_SEP;
Tx_RV_store{1} = Tx_RV;
Ty_LV_store{1} = Ty_LV;
Ty_SEP_store{1} = Ty_SEP;
Ty_RV_store{1} = Ty_RV;
% Ventricular pressures
ptrans1 = 2.*Tx_LV./ym;
ptrans3 = 2.*Tx_RV./ym;
P_LV = -ptrans1; % LV transmural pressure (mmHg)
P_RV = ptrans3; % RV transmural pressure (mmHg)
% Store
P_LV_store{1} = P_LV;
P_RV_store{1} = P_RV;
% Pulmonary pressures
P_PV = V_PV./C_PV; % Pulmonary venous pressure (mmHg)
P_SV = V_SV./C_SV; % Systemic venous pressure (mmHg)
P_PA = V_PA./C_PA; % Pulmonary arterial pressure (mmHg)
P_SA = V_SA./C_SA; % Systemic arterial pressure (mmHg)
% Store
P_PV_store{1} = P_PV;
P_SV_store{1} = P_SV;
P_PA_store{1} = P_PA;
P_SA_store{1} = P_SA;
% Lumped circulatory model
% Ao valve closed equations
P_Ao_closed = (C_SA*R_Ao*R_SA*V_Ao + C_SA*R_Ao*R_tSA*V_Ao + C_SA*R_SA*R_tSA*V_Ao + C_Ao*R_SA*R_tAo*V_SA + C_Ao*C_SA*P_SV*R_tSA*R_tAo)/(C_Ao*C_SA*(R_Ao*R_SA + R_Ao*R_tSA + R_SA*R_tSA + R_SA*R_tAo + R_tSA*R_tAo));
% Ao valve open equations
P_Ao_open = (C_SA*R_Ao*R_SA*R_AV*V_Ao + C_SA*R_Ao*R_tSA*R_AV*V_Ao + C_SA*R_SA*R_tSA*R_AV*V_Ao + C_Ao*R_SA*R_tAo*R_AV*V_SA + C_Ao*C_SA*P_LV*R_Ao*R_SA*R_tAo + C_Ao*C_SA*P_LV*R_Ao*R_tSA*R_tAo + C_Ao*C_SA*P_LV*R_SA*R_tSA*R_tAo + C_Ao*C_SA*P_SV*R_tSA*R_tAo*R_AV)/(C_Ao*C_SA*(R_Ao*R_SA*R_tAo + R_Ao*R_SA*R_AV + R_Ao*R_tSA*R_tAo + R_Ao*R_tSA*R_AV + R_SA*R_tSA*R_tAo + R_SA*R_tSA*R_AV + R_SA*R_tAo*R_AV + R_tSA*R_tAo*R_AV));
P_Ao = P_Ao_open.*(P_LV>P_Ao_open) + P_Ao_closed.*(P_LV<=P_Ao_open);
P_Ao_store{1} = P_Ao;
SV_LV_sim = max(1e3*V_LV) - min(1e3*V_LV); % Stroke volume
EF_LV_sim = SV_LV_sim/max(1e3*V_LV) * 100; % Ejection fraction
edLV_sim = max(1e3*V_LV);
esLV_sim = min(1e3*V_LV);
edRV_sim = max(1e3*V_RV);
esRV_sim = min(1e3*V_RV);
% Defining the metabolite dependent coeficient, rapid equilibrium of the
% cross bridge sub-states
g2_LV = (MgATP_cyto/K_T)/(1.0 + MgATP_cyto/K_T + MgADP_cyto/K_D);
kg_LV = kg*g2_LV;
g2_SEP = (MgATP_cyto/K_T)/(1.0 + MgATP_cyto/K_T + MgADP_cyto/K_D);
kg_SEP = kg*g2_SEP;
f_alpha3o_LV = (P3_0_LV + alpha3*(s3*s3*P3_0_LV + 2.0*s3*P3_1_LV + P3_2_LV));
f_alpha3o_SEP = (P3_0_SEP + alpha3*(s3*s3*P3_0_SEP + 2.0*s3*P3_1_SEP + P3_2_SEP));
% Detachment rates
ti = 0:0.00001:stim_period;
MAP = mean(interp1(t,P_Ao,ti)); % Mean arterial pressure (mmHg)
r_LV = interp1(t,kg_LV*f_alpha3o_LV,ti);
r_SEP = interp1(t,kg_SEP*f_alpha3o_SEP,ti);
% Crossbridge turnover rate
Vw_LV_W = (2/3)*LVW/1000;
Vw_SEP_W= (1/3)*LVW/1000;
rate_of_XB_turnover_ave = (Vw_LV_W*mean(r_LV) + Vw_SEP_W*mean(r_SEP))/(Vw_LV_W + Vw_SEP_W);
ATP_ase_mechanics_Averge_LV_SEP = (1.3/rate_of_XB_turnover_mean_sham)*rate_of_XB_turnover_ave; % 1.31 Kstiff - ATP hydrolized (mM/s/L cell) per X-bridge turnover rate in LV
tune_ATPase_LV = ATP_ase_mechanics_Averge_LV_SEP * (1/ 0.6801) *1.0e-3; % ATP hydrolysis rate (M/s/L cytosol)
ATPase_store(1) = tune_ATPase_LV;
%% Run coupled cardiovascular mechanics/energetics model
p = 2;
beat = 1;
jspan = 122:420;
for j = jspan % Run for 300 beats
tspan_beat = [(stim_period)*(j-1) (stim_period)*j];
% Run energetics model
if rem(j,3) == 0 % Run every 3 beats (for model stability)
energtics_output = EnergeticsModelScript(TAN, CRtot, TEP, Ox_capacity, tune_ATPase_LV); % Get metabolite concentrations
MgATP_cyto = energtics_output(1); % Cytosolic MgATP concentration (M/(L cytosol water)^-1)
MgADP_cyto = energtics_output(2); % Cytosolic MgADP concentration (M/(L cytosol water)^-1)
fPi_cytoplasm = energtics_output(3); % Cytosolic unchelated Pi concentration (M/(L cytosol water)^-1)
MVO2_tissue = energtics_output(5); % Oxygen consumption rate (uM/min^-1(g tissue)^-1)
dGrATPase = energtics_output(6); % ATP hydrolysis free energy, kJ/mol
PCrATP = energtics_output(7); % Creatine phoosphate ATP ratio, unitless
ATP_cyto = energtics_output(8); % Cytosolic total ATP concentration (M/(L cytosol water)^-1)
ADP_cyto = energtics_output(9); % Cytosolic total ADP concentration (M/(L cytosol water)^-1)
Pi_cyto = energtics_output(10)*1000; % Cytosolic total Pi concentration (M/(L cytosol water)^-1)
end
% Store
ATP_store(p) = MgATP_cyto;
ADP_store(p) = MgADP_cyto*1000;
Pi_store(p) = Pi_cyto;
MVO2_tissue_store(p) = MVO2_tissue;
PCrATP_store(p) = PCrATP;
% Run mechanics model
init = Y(end,:);
input = [stim_period, C_Ao, C_SA, C_SV, C_PV, C_PA, R_Ao, R_SA, R_PA, R_SV, R_PV, R_vlv, R_AV, ...
R_tAo, R_tSA, Amref_LV, Amref_SEP, Amref_RV, Vw_LV, Vw_SEP, Vw_RV, MgATP_cyto, ...
MgADP_cyto, Pi_cyto, MgATP_cyto, MgADP_cyto, Pi_cyto, MgATP_cyto, MgADP_cyto, ...
Pi_cyto, Lsref, L_rest_pas, gamma, K_Pi, K_T, K_D, alpha1, alpha2, alpha3, s3, Kse, ...
k_passive_LV, k_passive_SEP, k_passive_RV, eta, L_thick, L_hbare, L_thin, deltaR, kstiff1, kstiff2, kf, k_f, kw, ...
km1, kp, km2, kg, K_coop, k_on, k_off, km, k_recruit, k_m, A_HR, B_HR, C_HR, Ca0_HR, dATP, Ca_flag];
options = odeset('Mass',M,'MassSingular','yes','RelTol',1e-7,'AbsTol',1e-7,'MaxStep',stim_period/200);
[t,Y] = ode15s(@dXdT_cardiovascular_mechanics,tspan_beat, init, options, input);
t_store{p} = t;
Y_store{p} = Y;
% Calculate
% State variables
xm_LV = Y(:,1); % Maximal axial distance from LV midwall surface to origin (cm)
xm_SEP = Y(:,2); % Maximal axial distance from SEP midwall surface to origin (cm)
xm_RV = Y(:,3); % Maximal axial distance from RV midwall surface to origin (cm)
ym = Y(:,4); % Radius of midwall junction circle (cm)
SL_LV = Y(:,5); % LV sarcomere length (um)
SL_SEP = Y(:,6); % SEP sarcomere length (um)
SL_RV = Y(:,7); % RV sarcomere length (um)
V_LV = Y(:,8); % LV volume (mL)
V_RV = Y(:,9); % RV volume (mL)
% Store
xm_LV_store{p} = xm_LV;
xm_SEP_store{p} = xm_SEP;
xm_RV_store{p} = xm_RV;
ym_store{p} = ym;
SL_LV_store{p} = SL_LV;
SL_SEP_store{p} = SL_SEP;
SL_RV_store{p} = SL_RV;
V_LV_store{p} = V_LV;
V_RV_store{p} = V_RV;
P1_0_LV = Y(:,10); % 0th moment state A1, LV
P1_1_LV = Y(:,11); % 1st moment state A1, LV
P1_2_LV = Y(:,12); % 2nd moment state A1, LV
P2_0_LV = Y(:,13); % 0th moment state A2, LV
P2_1_LV = Y(:,14); % 1st moment state A2, LV
P2_2_LV = Y(:,15); % 2nd moment state A2, LV
P3_0_LV = Y(:,16); % 0th moment state A3, LV
P3_1_LV = Y(:,17); % 1st moment state A3, LV
P3_2_LV = Y(:,18); % 2nd moment state A3, LV
N_LV = Y(:,19); % Non permissible state, LV
U_NR_LV = Y(:,20); % ON state, LV
% Store
A1_LV_store{p} = P1_0_LV;
A2_LV_store{p} = P2_0_LV;
A3_LV_store{p} = P3_0_LV;
N_LV_store{p} = N_LV;
P1_0_SEP = Y(:,21); % 0th moment state A1, SEP
P1_1_SEP = Y(:,22); % 1st moment state A1, SEP
P1_2_SEP = Y(:,23); % 2nd moment state A1, SEP
P2_0_SEP = Y(:,24); % 0th moment state A2, SEP
P2_1_SEP = Y(:,25); % 1st moment state A2, SEP
P2_2_SEP = Y(:,26); % 2nd moment state A2, SEP
P3_0_SEP = Y(:,27); % 0th moment state A3, SEP
P3_1_SEP = Y(:,28); % 1st moment state A3, SEP
P3_2_SEP = Y(:,29); % 2nd moment state A3, SEP
N_SEP = Y(:,30); % Non permissible state, SEP
U_NR_SEP = Y(:,31); % ON state, SEP
% Store
A1_SEP_store{p} = P1_0_SEP;
A2_SEP_store{p} = P2_0_SEP;
A3_SEP_store{p} = P3_0_SEP;
N_SEP_store{p} = N_SEP;
P1_0_RV = Y(:,32); % 0th moment state A1, RV
P1_1_RV = Y(:,33); % 1st moment state A1, RV
P1_2_RV = Y(:,34); % 2nd moment state A1, RV
P2_0_RV = Y(:,35); % 0th moment state A2, RV
P2_1_RV = Y(:,36); % 1st moment state A2, RV
P2_2_RV = Y(:,37); % 2nd moment state A2, RV
P3_0_RV = Y(:,38); % 0th moment state A3, RV
P3_1_RV = Y(:,39); % 1st moment state A3, RV
P3_2_RV = Y(:,40); % 2nd moment state A3, RV
N_RV = Y(:,41); % Non permissible state, RV
U_NR_RV = Y(:,42); % ON state, RV
% Store
A1_RV_store{p} = P1_0_RV;
A2_RV_store{p} = P2_0_RV;
A3_RV_store{p} = P3_0_RV;
N_RV_store{p} = N_RV;
V_SV = Y(:,43); % Systemic veins volume (mL)
V_PV = Y(:,44); % Pulmonary veins volume (mL)
V_SA = Y(:,45); % Systemic arteries volume (mL)
V_PA = Y(:,46); % Pulmonary arteries volume (mL)
V_Ao = Y(:,47); % Aorta volume (mL)
% V_T = V_LV + V_RV + V_SV + V_PV + V_SA + V_PA + V_Ao;
% Store
V_SV_store{p} = V_SV;
V_PV_store{p} = V_PV;
V_SA_store{p} = V_SA;
V_PA_store{p} = V_PA;
V_Ao_store{p} = V_Ao;
% Geometry
Vm_LV = (pi/6).*xm_LV.*(xm_LV.^2 + 3.*ym.^2); % LV midwall volume (mL)
Vm_SEP = (pi/6).*xm_SEP.*(xm_SEP.^2 + 3.*ym.^2); % SEP midwall volume (mL)
Vm_RV = (pi/6).*xm_RV.*(xm_RV.^2 + 3.*ym.^2); % RV midwall volume (mL)
Am_LV = pi.*(xm_LV.^2 + ym.^2); % LV midwall surface area (cm^2)
Am_SEP = pi.*(xm_SEP.^2 + ym.^2); % SEP midwall surface area (cm^2)
Am_RV = pi.*(xm_RV.^2 + ym.^2); % RV midwall surface area (cm^2)
Cm_LV = 2.*xm_LV./(xm_LV.^2 + ym.^2); % LV midwall surface curvature
Cm_SEP = 2.*xm_SEP./(xm_SEP.^2 + ym.^2); % LV midwall surface curvature
Cm_RV = 2.*xm_RV./(xm_RV.^2 + ym.^2); % LV midwall surface curvature
z_LV = 3.*Cm_LV.*Vw_LV./(2.*Am_LV);
z_SEP = 3.*Cm_SEP.*Vw_SEP./(2.*Am_SEP);
z_RV = 3.*Cm_RV.*Vw_RV./(2.*Am_RV);
% Store
Vm_LV_store{p} = Vm_LV;
Vm_SEP_store{p} = Vm_SEP;
Vm_RV_store{p} = Vm_RV;
Am_LV_store{p} = Am_LV;
Am_SEP_store{p} = Am_SEP;
Am_RV_store{p} = Am_RV;
Cm_LV_store{p} = Cm_LV;
Cm_SEP_store{p} = Cm_SEP;
Cm_RV_store{p} = Cm_RV;
z_LV_store{p} = z_LV;
z_SEP_store{p} = z_SEP;
z_RV_store{p} = z_RV;
% Fiber strain
epsf_LV = 0.5.*log(Am_LV./Amref_LV) - 0.083333.*z_LV.^2 - 0.019.*z_LV.^4;
epsf_SEP = 0.5.*log(Am_SEP./Amref_SEP) - 0.083333.*z_SEP.^2 - 0.019.*z_SEP.^4;
epsf_RV = 0.5.*log(Am_RV./Amref_RV) - 0.083333.*z_RV.^2 - 0.019.*z_RV.^4;
SLo_LV = Lsref.*exp(epsf_LV);
SLo_SEP = Lsref.*exp(epsf_SEP);
SLo_RV = Lsref.*exp(epsf_RV);
% Store
epsf_LV_store{p} = epsf_LV;
epsf_SEP_store{p} = epsf_SEP;
epsf_RV_store{p} = epsf_RV;
SLo_LV_store{p} = SLo_LV;
SLo_SEP_store{p} = SLo_SEP;
SLo_RV_store{p} = SLo_RV;
% Passive force
sigmapas_LV = k_passive_LV.*(SLo_LV - L_rest_pas).^(gamma);
sigmapas_SEP = k_passive_SEP.*(SLo_SEP - L_rest_pas).^(gamma);
sigmapas_RV = k_passive_RV.*(SLo_RV - L_rest_pas).^(gamma);
% Store
sigmapas_LV_store{p} = sigmapas_LV;
sigmapas_SEP_store{p} = sigmapas_SEP;
sigmapas_RV_store{p} = sigmapas_RV;
% Active force
sovr_ze = min(L_thick*0.5, SL_LV*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_LV*0.5 - (SL_LV-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_LV = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sovr_ze = min(L_thick*0.5, SL_SEP*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_SEP*0.5 - (SL_SEP-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_SEP = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sovr_ze = min(L_thick*0.5, SL_RV*0.5); % Overlap region closest to Z-axis (nm)
sovr_cle = max(SL_RV*0.5 - (SL_RV-L_thin),L_hbare*0.5); % Overlap region closes to M-line (nm)
L_sovr = sovr_ze - sovr_cle; % Length of overlap (nm)
N_overlap_RV = L_sovr*2/(L_thick - L_hbare); % Fraction of thick filament overlap
sigmaact_LV = N_overlap_LV.*(kstiff2.*deltaR.*(P3_0_LV) + kstiff1.*(P2_1_LV + P3_1_LV)); % Includes force due to XB ratcheting and stretching of XBs
sigmaact_SEP = N_overlap_SEP.*(kstiff2.*deltaR.*(P3_0_SEP) + kstiff1.*(P2_1_SEP + P3_1_SEP)); % Includes force due to XB ratcheting and stretching of XBs
sigmaact_RV = N_overlap_RV.*(kstiff2.*deltaR.*(P3_0_RV) + kstiff1.*(P2_1_RV + P3_1_RV)); % Includes force due to XB ratcheting and stretching of XBs
% Store
sigmaact_LV_store{p} = sigmaact_LV;
sigmaact_SEP_store{p} = sigmaact_SEP;
sigmaact_RV_store{p} = sigmaact_RV;
% Total force
sigmaf_LV = -Kse.*(SL_LV - SLo_LV);
sigmaf_SEP = -Kse.*(SL_SEP - SLo_SEP);
sigmaf_RV = -Kse.*(SL_RV - SLo_RV);
% Store
sigmaf_LV_store{p} = sigmaf_LV;
sigmaf_SEP_store{p} = sigmaf_SEP;
sigmaf_RV_store{p} = sigmaf_RV;
% Tension
Tm_LV = (Vw_LV.*sigmaf_LV./(2.*Am_LV)).*(1 + (z_LV.^2)/3 + (z_LV.^4)/5); % LV midwall tension
Tm_SEP = (Vw_SEP.*sigmaf_SEP./(2.*Am_SEP)).*(1 + (z_SEP.^2)/3 + (z_SEP.^4)/5); % SEP midwall tension
Tm_RV = (Vw_RV.*sigmaf_RV./(2.*Am_RV)).*(1 + (z_RV.^2)/3 + (z_RV.^4)/5); % RV midwall tension
Tx_LV = Tm_LV.*2.*xm_LV.*ym./(xm_LV.^2 + ym.^2); % LV axial tension
Tx_SEP = Tm_SEP.*2.*xm_SEP.*ym./(xm_SEP.^2 + ym.^2); % SEP axial tension
Tx_RV = Tm_RV.*2.*xm_RV.*ym./(xm_RV.^2 + ym.^2); % RV axial tension
Ty_LV = Tm_LV.*(-xm_LV.^2 + ym.^2)./(xm_LV.^2 + ym.^2); % LV radial tension
Ty_SEP = Tm_SEP.*(-xm_SEP.^2 + ym.^2)./(xm_SEP.^2 + ym.^2); % SEP radial tension
Ty_RV = Tm_RV.*(-xm_RV.^2 + ym.^2)./(xm_RV.^2 + ym.^2); % RV radial tension
% Store
Tm_LV_store{p} = Tm_LV;
Tm_SEP_store{p} = Tm_SEP;
Tm_RV_store{p} = Tm_RV;
Tx_LV_store{p} = Tx_LV;
Tx_SEP_store{p} = Tx_SEP;
Tx_RV_store{p} = Tx_RV;
Ty_LV_store{p} = Ty_LV;
Ty_SEP_store{p} = Ty_SEP;
Ty_RV_store{p} = Ty_RV;
% Ventricular pressures
ptrans1 = 2.*Tx_LV./ym;
ptrans3 = 2.*Tx_RV./ym;
P_LV = -ptrans1; % LV transmural pressure (mmHg)
P_RV = ptrans3; % RV transmural pressure (mmHg)
% Store
P_LV_store{p} = P_LV;
P_RV_store{p} = P_RV;
% Pulmonary pressures
P_PV = V_PV./C_PV; % Pulmonary venous pressure (mmHg)
P_SV = V_SV./C_SV; % Systemic venous pressure (mmHg)
P_PA = V_PA./C_PA; % Pulmonary arterial pressure (mmHg)
P_SA = V_SA./C_SA; % Systemic arterial pressure (mmHg)
% Store
P_PV_store{p} = P_PV;
P_SV_store{p} = P_SV;
P_PA_store{p} = P_PA;
P_SA_store{p} = P_SA;
% Lumped circulatory model
% Ao valve closed equations
P_Ao_closed = (C_SA*R_Ao*R_SA*V_Ao + C_SA*R_Ao*R_tSA*V_Ao + C_SA*R_SA*R_tSA*V_Ao + C_Ao*R_SA*R_tAo*V_SA + C_Ao*C_SA*P_SV*R_tSA*R_tAo)/(C_Ao*C_SA*(R_Ao*R_SA + R_Ao*R_tSA + R_SA*R_tSA + R_SA*R_tAo + R_tSA*R_tAo));
% Ao valve open equations
P_Ao_open = (C_SA*R_Ao*R_SA*R_AV*V_Ao + C_SA*R_Ao*R_tSA*R_AV*V_Ao + C_SA*R_SA*R_tSA*R_AV*V_Ao + C_Ao*R_SA*R_tAo*R_AV*V_SA + C_Ao*C_SA*P_LV*R_Ao*R_SA*R_tAo + C_Ao*C_SA*P_LV*R_Ao*R_tSA*R_tAo + C_Ao*C_SA*P_LV*R_SA*R_tSA*R_tAo + C_Ao*C_SA*P_SV*R_tSA*R_tAo*R_AV)/(C_Ao*C_SA*(R_Ao*R_SA*R_tAo + R_Ao*R_SA*R_AV + R_Ao*R_tSA*R_tAo + R_Ao*R_tSA*R_AV + R_SA*R_tSA*R_tAo + R_SA*R_tSA*R_AV + R_SA*R_tAo*R_AV + R_tSA*R_tAo*R_AV));
P_Ao = P_Ao_open.*(P_LV>P_Ao_open) + P_Ao_closed.*(P_LV<=P_Ao_open);
P_Ao_store{p} = P_Ao;
SV_LV_sim = max(1e3*V_LV) - min(1e3*V_LV); % Stroke volume
EF_LV_sim = SV_LV_sim/max(1e3*V_LV) * 100; % Ejection fraction
edLV_sim = max(1e3*V_LV);
esLV_sim = min(1e3*V_LV);
edRV_sim = max(1e3*V_RV);
esRV_sim = min(1e3*V_RV);
g2_LV = (MgATP_cyto/K_T)/(1.0 + MgATP_cyto/K_T + MgADP_cyto/K_D);
kg_LV = kg*g2_LV;
g2_SEP = (MgATP_cyto/K_T)/(1.0 + MgATP_cyto/K_T + MgADP_cyto/K_D);
kg_SEP = kg*g2_SEP;
f_alpha3o_LV = (P3_0_LV + alpha3*(s3*s3*P3_0_LV + 2.0*s3*P3_1_LV + P3_2_LV));
f_alpha3o_SEP = (P3_0_SEP + alpha3*(s3*s3*P3_0_SEP + 2.0*s3*P3_1_SEP + P3_2_SEP));
% Detachment rates
ti = stim_period*(j-1):0.00001:stim_period*j;
MAP = mean(interp1(t,P_Ao,ti)); % Mean arterial pressure (mmHg)
r_LV = interp1(t,kg_LV*f_alpha3o_LV,ti);
r_SEP = interp1(t,kg_SEP*f_alpha3o_SEP,ti);
% Crossbridge turnover rate
Vw_LV_W = (2/3)*LVW/1000;
Vw_SEP_W= (1/3)*LVW/1000;
rate_of_XB_turnover_ave = (Vw_LV_W*mean(r_LV) + Vw_SEP_W*mean(r_SEP))/(Vw_LV_W + Vw_SEP_W);
ATP_ase_mechanics_Averge_LV_SEP = (1.3/rate_of_XB_turnover_mean_sham)*rate_of_XB_turnover_ave; % 1.31 Kstiff - ATP hydrolized (mM/s/L cell) per XB turnover rate in LV
tune_ATPase_LV = ATP_ase_mechanics_Averge_LV_SEP * (1/ 0.6801) *1.0e-3; % ATP hydrolysis rate (M/s/L cytosol)
ATPase_store(p) = tune_ATPase_LV;
beat = p
p = p+1;
end
%% Finalize output
% Initialize
k = 1;
t_f = [];
xm_LV_f = [];
xm_SEP_f = [];
xm_RV_f = [];
ym_f = [];
SL_LV_f = [];
SL_SEP_f = [];
SL_RV_f = [];
V_LV_f = [];
V_RV_f = [];
A1_LV_f = [];
A2_LV_f = [];
A3_LV_f = [];
N_LV_f = [];
A1_SEP_f = [];
A2_SEP_f = [];
A3_SEP_f = [];
N_SEP_f = [];
A1_RV_f = [];
A2_RV_f = [];
A3_RV_f = [];
N_RV_f = [];
V_SV_f = [];
V_PV_f = [];
V_SA_f = [];
V_PA_f = [];
V_Ao_f = [];
Vm_LV_f = [];
Vm_SEP_f = [];
Vm_RV_f = [];
Am_LV_f = [];
Am_SEP_f = [];
Am_RV_f = [];
Cm_LV_f = [];
Cm_SEP_f = [];
Cm_RV_f = [];
z_LV_f = [];
z_SEP_f = [];
z_RV_f = [];
epsf_LV_f = [];
epsf_SEP_f = [];
epsf_RV_f = [];
SLo_LV_f = [];
SLo_SEP_f = [];
SLo_RV_f = [];
sigmapas_LV_f = [];
sigmapas_SEP_f = [];
sigmapas_RV_f = [];
sigmaact_LV_f = [];
sigmaact_SEP_f = [];
sigmaact_RV_f = [];
sigmaf_LV_f = [];
sigmaf_SEP_f = [];
sigmaf_RV_f = [];
Tm_LV_f = [];
Tm_SEP_f = [];
Tm_RV_f = [];
Tx_LV_f = [];
Tx_SEP_f = [];
Tx_RV_f = [];
Ty_LV_f = [];
Ty_SEP_f = [];
Ty_RV_f = [];
P_LV_f = [];
P_RV_f = [];
P_SV_f = [];
P_PV_f = [];
P_SA_f = [];
P_PA_f = [];
P_Ao_f = [];
while k < p-1
t_1 = t_store{k};
t_2 = t_store{k+1};
t_new = vertcat(t_1(2:end),t_2(2:end));
t_f = vertcat(t_f,t_new);
xm_LV1 = xm_LV_store{k};
xm_LV2 = xm_LV_store{k+1};
xm_LV_new = vertcat(xm_LV1(2:end),xm_LV2(2:end));
xm_LV_f = vertcat(xm_LV_f,xm_LV_new);
xm_SEP1 = xm_SEP_store{k};
xm_SEP2 = xm_SEP_store{k+1};
xm_SEP_new = vertcat(xm_SEP1(2:end),xm_SEP2(2:end));
xm_SEP_f = vertcat(xm_SEP_f,xm_SEP_new);
xm_RV1 = xm_RV_store{k};
xm_RV2 = xm_RV_store{k+1};
xm_RV_new = vertcat(xm_RV1(2:end),xm_RV2(2:end));
xm_RV_f = vertcat(xm_RV_f,xm_RV_new);
ym1 = ym_store{k};
ym2 = ym_store{k+1};
ym_new = vertcat(ym1(2:end),ym2(2:end));
ym_f = vertcat(ym_f,ym_new);
SL_LV1 = SL_LV_store{k};
SL_LV2 = SL_LV_store{k+1};
SL_LV_new = vertcat(SL_LV1(2:end),SL_LV2(2:end));
SL_LV_f = vertcat(SL_LV_f,SL_LV_new);
SL_SEP1 = SL_SEP_store{k};
SL_SEP2 = SL_SEP_store{k+1};
SL_SEP_new = vertcat(SL_SEP1(2:end),SL_SEP2(2:end));
SL_SEP_f = vertcat(SL_SEP_f,SL_SEP_new);
SL_RV1 = SL_RV_store{k};
SL_RV2 = SL_RV_store{k+1};
SL_RV_new = vertcat(SL_RV1(2:end),SL_RV2(2:end));
SL_RV_f = vertcat(SL_RV_f,SL_RV_new);
V_LV1 = V_LV_store{k};
V_LV2 = V_LV_store{k+1};
V_LV_new = vertcat(V_LV1(2:end),V_LV2(2:end));
V_LV_f = vertcat(V_LV_f,V_LV_new);
V_RV1 = V_RV_store{k};
V_RV2 = V_RV_store{k+1};
V_RV_new = vertcat(V_RV1(2:end),V_RV2(2:end));
V_RV_f = vertcat(V_RV_f,V_RV_new);
A1_LV1 = A1_LV_store{k};
A1_LV2 = A1_LV_store{k+1};
A1_LV_new = vertcat(A1_LV1(2:end),A1_LV2(2:end));
A1_LV_f = vertcat(A1_LV_f,A1_LV_new);
A2_LV1 = A2_LV_store{k};
A2_LV2 = A2_LV_store{k+1};
A2_LV_new = vertcat(A2_LV1(2:end),A2_LV2(2:end));
A2_LV_f = vertcat(A2_LV_f,A2_LV_new);
A3_LV1 = A3_LV_store{k};
A3_LV2 = A3_LV_store{k+1};
A3_LV_new = vertcat(A3_LV1(2:end),A3_LV2(2:end));
A3_LV_f = vertcat(A3_LV_f,A3_LV_new);