Simple One-Ventricle Open Circulation

Tags: ArtVen Capacitor Chamber2022 Resistance Diode

Todo

Make One-Ventricle Circulation figure

(Source code, png, hires.png, pdf)

../../../_images/Chamber_windkessel.png

The full code to generate this plot is shown below.

python
  1# -*- coding: utf-8 -*-
  2
  3
  4# import sys
  5# sys.path.append('../../../../src/')
  6
  7import circadapt
  8
  9# circadapt.DEFAULT_PATH_TO_CIRCADAPT = "../../../../core/out/build/x64-Release/CircAdaptLib.dll"
 10
 11
 12import numpy as np
 13import matplotlib.pyplot as plt
 14
 15import time
 16
 17def create_model():
 18    ###
 19    n_beat = 100
 20
 21    dT = 0.001
 22    solver = "SolverFE"
 23
 24    # open model
 25    model = circadapt.CircAdapt("Custom",
 26                    solver,
 27                    )
 28
 29    model.set('Solver.dT', dT)
 30    model.set('Solver.dTexport', dT)
 31
 32    # Build the cavity C using a Chamber2022 object. This object automatically
 33    # gets an Wall2022 object with no patches, so a patch must be added.
 34    model.add_component('Chamber2022', 'C')
 35    model.add_component('Patch2022', 'P', 'C.wC')
 36
 37    # add windkessel
 38    model.add_component('NodePressure', 'Prox')
 39    model.add_component('NodePressure', 'Dist')
 40    model.add_component('Capacitor', 'Art')
 41    model.add_component('Resistance', 'Resistance')
 42
 43    model.add_component('Diode', 'ValveIn')
 44    model.add_component('Diode', 'ValveOut')
 45
 46    model.set_component('ValveIn.Prox', 'Prox')
 47    model.set_component('ValveIn.Dist', 'C')
 48
 49    model.set_component('ValveOut.Prox', 'C')
 50    model.set_component('ValveOut.Dist', 'Art')
 51
 52    model.set_component('Resistance.Prox', 'Art')
 53    model.set_component('Resistance.Dist', 'Dist')
 54
 55    # parameters
 56    # model.set('Model.Valve.R', 10)
 57    model.set('Model.ValveIn.R', 10e5)
 58    model.set('Model.ValveOut.R', 1e7)
 59    model.set('Model.Resistance.R', 1e8)
 60    model.set('Model.Art.C', 1e-8)
 61
 62    # set proximal pressure
 63    model.set('Model.Prox.Pressure.set_time', 0)
 64    model.set('Model.Prox.Pressure.set_value', 2000)
 65
 66
 67    # set state variables
 68    model.set('Model.C.V', 10e-6)
 69    # model.set('Model.SyArt.V',   200e-6)
 70    # model.set('Model.SyVen.V',   300e-6)
 71
 72    # parameterize patch
 73    model['Patch2022']['dT'] = 0.1
 74    model['Patch2022']['SfAct'] = 100e3
 75    model['Patch2022']['SfPas'] = 1e3
 76    model['Patch2022']['AmRef'] = 0.011
 77    model['Patch2022']['k1'] = 10
 78    model['Patch2022']['vMax'] = 7
 79    model['Patch2022']['VWall'] = 1e-04
 80    model['Patch2022']['TR'] = 0.25
 81    model['Patch2022']['TD'] = 0.25
 82    model['Patch2022']['TimeAct'] =  0.2
 83    model.set('Model.C.wC.P.Lsi', 2.0)
 84    model.set('Model.Art.V', 10e-4)
 85    model.set('Model.Art.V0', 1e-4)
 86    # model.set('Model.Art.C', 2e-8)
 87    # model.set('Model.Art.V', 200)
 88
 89
 90    # model['Tube0D']['p0'][0] = 900
 91    # model['Tube0D']['A0'][0] = 6e-4
 92
 93    # Run beats
 94    t0 = time.time()
 95    model.run(n_beat)
 96    print(time.time()-t0)
 97
 98    return model
 99
100# %% Run model and plot
101if __name__ == '__main__':
102    model = create_model()
103    plt.figure(1, clear=True, figsize=(12, 4))
104
105    t = model.get('Solver.Time') * 1e3
106
107    m=1
108    n=3
109
110    ax = plt.subplot(m,n,1)
111    ax.plot(t, model.get('Model.C.p')/133, label='Chamber', color='k')
112    ax.plot(t, model.get('Model.Prox.p')/133, label='Prox', color='r')
113    ax.plot(t, model.get('Model.Art.p')/133, label='Art', color='r')
114    ax.plot(t, model.get('Model.Dist.p')/133, label='Dist', color='b')
115    plt.legend()
116    ax.set_ylabel('Pressure [mmHg]')
117    ax.set_xlabel('Time [ms]')
118
119    ax = plt.subplot(m,n,2)
120    ax.plot(t, model.get('Model.C.V')*1e6, label='Chamber', color='k')
121    ax.set_ylabel('Volume [mL]')
122    ax.set_xlabel('Time [ms]')
123    plt.legend()
124
125    ax = plt.subplot(m,n,3)
126    ax.plot(t, model.get('Model.ValveIn.q')*1e3, label='ValveIn')
127    ax.plot(t, model.get('Model.ValveOut.q')*1e3, label='ValveOut')
128    ax.plot(t, model.get('Model.Resistance.q')*1e3, label='Resistance')
129    plt.legend()
130
131    ax.axhline(0, color='k', linestyle='--')
132    ax.set_ylabel('Flow [mL/ms]')
133    ax.set_xlabel('Time [ms]')
134    plt.legend()
135
136    plt.suptitle('Simple one-ventricle model setup', fontsize=16, weight='bold')
137
138
139    # ax = plt.subplot(m,n,4)
140    # ax.axhline(0, color='k', linestyle='--', lw=1)
141    # ax.set_ylabel('C')
142    # plt.legend()
143
144    plt.tight_layout()
145    plt.draw()
146    plt.show()
147