Skip to content

Commit 500ab3c

Browse files
added rush-larsen treatment to rush-larsen-c output
1 parent f493de2 commit 500ab3c

File tree

7 files changed

+183
-12
lines changed

7 files changed

+183
-12
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
8+
python-version: [3.6, 3.7, 3.8, 3.9]
99
steps:
1010
- name: Checkout repository and submodules
1111
uses: actions/checkout@v1

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Release 0.9.4
2+
- Corrected Rush-Larsen output for `--rush-larsen-c`
3+
14
# Release 0.9.3
25
- Performance upgrade for `--rush-larsen` using caching on linearity checking.
36

chaste_codegen/data/tests/chaste_reference_models/RL_C/aslanidi_Purkinje_model_2009.c

Lines changed: 105 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chaste_codegen/data/tests/chaste_reference_models/RL_C/aslanidi_Purkinje_model_2009.h

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chaste_codegen/templates/labview.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
// State variables
2323
//------------------------------------------------------------------------------
2424

25-
double Y[_NB_OF_STATE_VARIABLES_];
25+
extern double Y[_NB_OF_STATE_VARIABLES_];
2626
double dY[_NB_OF_STATE_VARIABLES_];
27+
double Ynew[_NB_OF_STATE_VARIABLES_];
28+
2729
{%- for state_var in state_vars %}
2830
// {{loop.index0}}: {{state_var.var}} (units: {{state_var.units}}, initial value: {{state_var.initial_value}}, component: {{components[loop.index0]}})
2931
{%- endfor %}
3032

33+
double Vmem;
34+
double time;
35+
3136
char YNames[_NB_OF_STATE_VARIABLES_][{{stat_var_name_max_length +1}}];
3237
char YUnits[_NB_OF_STATE_VARIABLES_][{{unit_name_max_length +1}}];
3338
char YComponents[_NB_OF_STATE_VARIABLES_][{{component_name_max_length +1 }}];
@@ -61,12 +66,17 @@ void init()
6166
{%for state_var in state_vars %}
6267
Y[{{loop.index0}}] = {{state_var.initial_value}}; // {{state_var.var}} ({{state_var.units}}) (in {{components[loop.index0]}})
6368
{%- endfor %}
69+
Y[{{state_vars | length}}]; // ({{free_variable.var_name}}} (milliseconds)
70+
6471
{%for state_var in state_vars %}
6572
strcpy(YNames[{{loop.index0}}], "{{state_var.var}}");
6673
{%- endfor %}
74+
strcpy(YNames[{{state_vars | length}}], "{{free_variable.var_name}}");
75+
6776
{%for state_var in state_vars %}
6877
strcpy(YUnits[{{loop.index0}}], "{{state_var.units}}");
6978
{%- endfor %}
79+
strcpy(YUnits[{{state_vars | length}}], "milliseconds");
7080

7181
//------------------------------------------------------------------------------
7282
// Constants
@@ -79,7 +89,10 @@ void init()
7989
{% endif %}{%- endfor %}
8090
}
8191

82-
void compute(double {{free_variable.var_name}})
92+
//---------------------------------------------------------------------------
93+
// Computation
94+
//---------------------------------------------------------------------------
95+
void compute()
8396
{
8497
// time: {{free_variable.var_name}} (millisecond)
8598
{% for deriv in y_derivative_equations %}
@@ -96,6 +109,46 @@ void compute(double {{free_variable.var_name}})
96109
{%- endfor %}
97110
}
98111

112+
//------------------------------------------------------------------------------
113+
// Integration & Output
114+
//------------------------------------------------------------------------------
115+
// Rush-Larsen method
116+
117+
118+
// get tau/inf or alpha/beta
119+
void computeTauInf()
120+
{% for deriv in derivative_alpha_beta %}{% if deriv.type!='non_linear'%}double alphaOrTau_{{loop.index0}} = {{deriv.r_alpha_or_tau}};
121+
double betaOrInf_{{loop.index0}} = {{deriv.r_beta_or_inf}};
122+
{% endif %}{%- endfor %}
123+
// gating variables: Exponential integration
124+
{% for deriv in derivative_alpha_beta %}{%- if deriv.type=='inftau'%}
125+
Ynew[{{loop.index0}}] = betaOrInf_{{loop.index0}} + (Y[{{loop.index0}}] - betaOrInf_{{loop.index0}})*exp(-dt/alphaOrTau_{{loop.index0}});
126+
{%- elif deriv.type!='non_linear'%}
127+
double tau_inv_{{loop.index0}} = alphaOrTau_{{loop.index0}} + betaOrInf_{{loop.index0}};
128+
double y_inf_{{loop.index0}} = alphaOrTau_{{loop.index0}} / tau_inv_{{loop.index0}};
129+
Ynew[{{loop.index0}}] = y_inf_{{loop.index0}} + (Y[{{loop.index0}}] - y_inf_{{loop.index0}})*exp(-dt*tau_inv_{{loop.index0}});
130+
{%- endif %}
131+
{%- endfor %}
132+
}
133+
134+
// Remainder: Forward Euler
135+
void computeRemainderForaredEuler(){
136+
{% for deriv in derivative_alpha_beta %}
137+
{%- if deriv.type=='non_linear'%}
138+
Ynew[{{loop.index0}}] = Y[{{loop.index0}}] + dt * {{deriv.deriv}};{%- endif %}{%- endfor %}
139+
Ynew[{{state_vars | length}}] = Y[{{state_vars | length}}] + dt;
140+
}
141+
142+
compute();
143+
computeTauInf();
144+
computeRemainderForaredEuler();
145+
146+
147+
Vmem = Ynew[0];
148+
time = Ynew[{{state_vars | length}}];
149+
150+
151+
99152
//==============================================================================
100153
// End of file
101154
//==============================================================================

chaste_codegen/templates/labview.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
// State variables
1818
//------------------------------------------------------------------------------
1919

20-
#define _NB_OF_STATE_VARIABLES_ {{state_vars | length}}
20+
#define _NB_OF_STATE_VARIABLES_ {{state_vars | length +1}}
2121

2222
extern double Y[_NB_OF_STATE_VARIABLES_];
23-
extern double dY[_NB_OF_STATE_VARIABLES_];
23+
extern double Y[_NB_OF_STATE_VARIABLES_];
24+
extern double double dY[_NB_OF_STATE_VARIABLES_];
2425
{%- for state_var in state_vars %}
2526
// {{loop.index0}}: {{state_var.var}} ({{state_var.units}}) (in {{components[loop.index0]}}) (Initial value: {{state_var.initial_value}})
2627
{%- endfor %}
2728

29+
extern double Vmem;
30+
extern double time;
31+
2832
extern char YNames[_NB_OF_STATE_VARIABLES_][{{stat_var_name_max_length +1}}];
2933
extern char YUnits[_NB_OF_STATE_VARIABLES_][{{unit_name_max_length +1}}];
3034
extern char YComponents[_NB_OF_STATE_VARIABLES_][{{component_name_max_length +1 }}];
@@ -51,7 +55,9 @@ extern double {{param["comment_name"]}}; // {{param["units"]}} (in {{param["comp
5155
//------------------------------------------------------------------------------
5256

5357
extern void init();
54-
extern void compute(double {{free_variable.var_name}});
58+
extern void compute();
59+
extern void computeTauInf();
60+
extern void computeRemainderForaredEuler();
5561

5662
//------------------------------------------------------------------------------
5763

chaste_codegen/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.3
1+
0.9.4

0 commit comments

Comments
 (0)