Simple One-Ventricle Closed Circulation

Tags: ArtVen Chamber Patch Valve

Todo

Make One-Ventricle Circulation figure

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

../../../_images/Chamber_small_circulation.png

The full code to generate this plot is shown below.

  1# -*- coding: utf-8 -*-
  2import sys
  3
  4# check if should include path for development modus
  5# try:
  6#     __import__('circadapt')
  7# except:
  8#     sys.path.append('../../../src/')
  9
 10# actual import
 11from circadapt import CircAdapt
 12import numpy as np
 13import matplotlib.pyplot as plt
 14
 15import time
 16
 17def create_model():
 18    ###
 19    n_beat = 10
 20
 21    dt = 0.001
 22    solver = "forward_euler"
 23
 24    # open model
 25    model = CircAdapt(solver)
 26
 27    model.set('Solver.dt', dt)
 28    model.set('Solver.dt_export', dt)
 29
 30    # Build the cavity C using a Chamber2022 object. This object automatically
 31    # gets an Wall2022 object with no patches, so a patch must be added.
 32    model.add_component('Chamber2022', 'C')
 33    model.add_component('Patch2022', 'P', 'C.wC')
 34
 35    # Use 'smart component' function to add an ArtVen combination.
 36    model.add_smart_component('ArtVen')
 37
 38    # Add and connect valves for inflow and outflow of the cavity
 39    model.add_component('Valve2022', 'ChaSyArt')
 40    model.add_component('Valve2022', 'SyVenCha')
 41
 42    model.set_component('ChaSyArt.prox', 'C')
 43    model.set_component('ChaSyArt.dist', 'SyArt')
 44    model.set_component('SyVenCha.prox', 'SyVen')
 45    model.set_component('SyVenCha.dist', 'C')
 46
 47    # set state variables
 48    model.set('Model.C.V', 125e-6)
 49    model.set('Model.SyArt.V',   200e-6)
 50    model.set('Model.SyVen.V',   300e-6)
 51
 52    # parameterize patch
 53    model['Patch2022']['dt'] = 0.1
 54    model['Patch2022']['Sf_act'] = 200e3
 55    model['Patch2022']['Sf_pas'] = 5e3
 56    model['Patch2022']['Am_ref'] = 0.014
 57    model['Patch2022']['k1'] = 10
 58    model['Patch2022']['v_max'] = 7
 59    model['Patch2022']['V_wall'] = 1e-04
 60    # model['Patch2022']['l_si'] = par_Lsi
 61    model['Patch2022']['tr'] = 0.25
 62    model['Patch2022']['td'] = 0.25
 63    model['Patch2022']['time_act'] =  0.5
 64    model.set('Model.C.wC.P.l_si', 2.0)
 65
 66
 67    model['ArtVen']['p0'][0] = 9000
 68
 69    # Run beats
 70    t0 = time.time()
 71    model.run(n_beat)
 72    print(time.time()-t0)
 73
 74    return model
 75
 76# %% Run model and plot
 77if __name__ == '__main__':
 78    model = create_model()
 79    plt.figure(1, clear=True, figsize=(9, 3))
 80
 81    t = model.get('Solver.t') * 1e3
 82
 83    m=1
 84    n=3
 85
 86    ax = plt.subplot(m,n,1)
 87    ax.plot(t, model.get('Model.C.p')/133, label='Chamber', color='k')
 88    ax.plot(t, model.get('Model.SyArt.p')/133, label='SyArt', color='r')
 89    ax.plot(t, model.get('Model.SyVen.p')/133, label='SyVen', color='b')
 90    plt.legend()
 91    ax.set_ylabel('Pressure [mmHg]')
 92    ax.set_xlabel('Time [ms]')
 93
 94    ax = plt.subplot(m,n,2)
 95    ax.plot(t, model.get('Model.C.V')*1e6, label='Chamber', color='k')
 96    ax.set_ylabel('Volume [mL]')
 97    ax.set_xlabel('Time [ms]')
 98    plt.legend()
 99
100    ax = plt.subplot(m,n,3)
101    ax.plot(t, model.get('Model.CiSy.q')*1e3, label='ArtVen')
102    ax.plot(t, model.get('Model.ChaSyArt.q')*1e3, label='ChaSyArt')
103    ax.plot(t, model.get('Model.SyVenCha.q')*1e3, label='SyVenCha')
104    plt.legend()
105
106    ax.axhline(0, color='k', linestyle='--')
107    ax.set_ylabel('Flow [mL/ms]')
108    ax.set_xlabel('Time [ms]')
109    plt.legend()
110
111    plt.suptitle('Simple one-ventricle model setup', fontsize=16, weight='bold')
112
113
114    # ax = plt.subplot(m,n,4)
115    # ax.axhline(0, color='k', linestyle='--', lw=1)
116    # ax.set_ylabel('C')
117    # plt.legend()
118
119    plt.tight_layout()
120    plt.draw()
121    plt.show()