Build your own model class

Todo

Explain how to create a custom model class

When the model is created, it must be parameterized properly. It is explained here how to create your own reference model state.

The model VanOsta2023 is build following this standard. This model is constructed by the following code.

python
  1"""
  2VanOsta2023 model.
  3
  4"""
  5
  6import circadapt
  7from circadapt.model import Model
  8
  9class VanOsta2023(Model):
 10    def __init__(self, solver='SolverCA'):
 11        Model.__init__(self, solver)
 12
 13    def build(self):
 14        # Circulation
 15        self.add_smart_component('ArtVen', build='SystemicCirculation')
 16        self.add_smart_component('ArtVen', build='PulmonaryCirculation')
 17        self.add_smart_component('Heart', patch_type='Patch2022')
 18        self.add_smart_component('Timings')
 19        self.add_smart_component('PressureFlowControl')
 20
 21    def set_reference(self):
 22        self['Chamber2022']['buckling'] = False
 23        self['Valve2022']['soft_closure'] = True
 24
 25        self['Solver']['dT'] = 0.0005
 26        self['Solver']['dTexport'] = self['Solver']['dT']
 27
 28        self.set('Model.tCycle', 0.85)
 29
 30        self.set('Model.PFC.fac',  0.5)
 31        self.set('Model.PFC.epsilon', 0.1)
 32        self.set('Model.PFC.fac_pfc', 1)
 33        self.set('Model.PFC.stable_thresh', 0.001)
 34
 35        # Set parameters Circulation
 36        self['Tube0D']['A0'] = [
 37            0.00049833,
 38            0.00050034,
 39            0.0004684 ,
 40            0.00051849,
 41            ]
 42        self['Tube0D']['A_wall'] = [
 43            1.14408188e-04,
 44            4.81082964e-05,
 45            5.19472921e-05,
 46            5.79933632e-05,
 47            ]
 48        self['Tube0D']['k'] = [ 8., 10.,  8., 10.]
 49        self['Tube0D']['l'] = [0.4, 0.4, 0.2, 0.2]
 50        self['Tube0D']['p0'] = [
 51            12161.21763497,
 52            112.09788908,
 53            1899.95009955,
 54            572.39790382,
 55            ]
 56
 57        self['ArtVen']['p0'] = [6395.43973044,  500.]
 58        self['ArtVen']['q0'] = [4.5e-05, 4.5e-05]
 59        self['ArtVen']['k'] = [1, 2]
 60
 61        # Set volume state variables
 62        # not needed to reset, only if initial model crashes
 63        if True:
 64            self.set('Model.SyArt.V', 2e-4)
 65            self.set('Model.PuArt.V', 1e-4)
 66            self.set('Model.SyVen.V', 4e-4)
 67            self.set('Model.PuVen.V', 2e-4)
 68
 69            self.set('Model.Peri.TriSeg.V', 44e-6)
 70            self.set('Model.Peri.TriSeg.Y', 34.6e-3)
 71
 72            self.set('Model.Peri.TriSeg.cLv.V',  150e-6)
 73            self.set('Model.Peri.TriSeg.cRv.V',  100e-6)
 74            self.set('Model.Peri.La.V',  100e-6)
 75            self.set('Model.Peri.Ra.V',  50e-6)
 76
 77        # all wall parameters
 78        self['Patch2022']['l_se'] = 0.04
 79        self['Patch2022']['LsRef'] = 2.0
 80        self['Patch2022']['Ls0Pas'] = 1.8
 81        self['Patch2022']['dLsPas'] = 0.6
 82        self['Patch2022']['k1'] = 10
 83        self['Patch2022']['dT'] = 0
 84        self['Patch2022']['CRest'] = 0
 85        self['Patch2022']['Lsi0Act'] = 1.51
 86        self['Patch2022']['LDAD'] = 1.057
 87        self['Patch2022']['ADO'] = 0.65
 88        self['Patch2022']['LDCC'] = 4.
 89        self['Patch2022']['vMax'] = 7.
 90        self['Patch2022']['TR'] = 0.25
 91        self['Patch2022']['TD'] = 0.25
 92
 93        # wall specific
 94        self['Patch2022']['AmRef'] = [
 95            0.00706159,
 96            0.00603949,
 97            0.0093191 ,
 98            0.00507053,
 99            0.01313792,
100            ]
101        self['Patch2022']['VWall'] = [
102            1.86518494e-05,
103            6.12511827e-06,
104            9.51121820e-05,
105            3.74835076e-05,
106            4.97478018e-05,
107            ]
108        self['Patch2022']['SfPas'] = [
109            51591.64007141,
110            52277.48834349,
111            22370.46712926,
112            22051.80366169,
113            23278.22158555,
114            ]
115        self['Patch2022']['SfAct'] = [84e3, 84e3, 120e3, 120e3, 120e3]
116
117        # Valves
118        self['Valve2022']['adaptation_A_open_fac'] = [
119            1.,
120            1.5,
121            1.,
122            1.,
123            1.5,
124            1.]
125        self['Valve2022']['A_open'] = [
126            0.00050078,
127            0.0007021,
128            0.00046806,
129            0.00051776,
130            0.00074755,
131            0.00049837]
132        self['Valve2022']['A_leak'] = [
133            2.64705882e-04,
134            2.64705882e-10,
135            2.64705882e-10,
136            2.64705882e-04,
137            2.64705882e-10,
138            2.64705882e-10]
139        self['Valve2022']['l'] = 0.01626978
140        self['Valve2022']['rho_b'] = 1050
141        self['Valve2022']['papillary_muscles'] = False
142        self['Valve2022']['papillary_muscles_slope'] = 100
143        self['Valve2022']['papillary_muscles_min'] = 0.1
144        self['Valve2022']['papillary_muscles_A_open_fac'] = 0.1
145        self['Valve2022']['soft_closure'] = True
146
147        self['Bag']['k'] = 10
148        self['Bag']['V_ref'] = 0.0005
149        self['Bag']['p_ref'] = 100
150
151        self.set('Model.Peri.TriSeg.Y', 0.035)
152
153        self.run(run_stable=True)
154