-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIonicModel.cpp
More file actions
154 lines (133 loc) · 2.65 KB
/
IonicModel.cpp
File metadata and controls
154 lines (133 loc) · 2.65 KB
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
#include<stdio.h>
#include<cstdlib>
#include<math.h>
#include "IonicModel.hpp"
#ifndef NEWTON_TOLL
#define NEWTON_TOLL 1E-4
#endif
#ifndef NEWTON_MAXIT
#define NEWTON_MAXIT 100
#endif
//Default constructor
IonicModel::IonicModel()
:_nlSolver(1),
_Variables(0),
_VariablesN(0),
_VariablesInit(0),
_Parameters(0),
_VariablesOut(0),
_VariablesOutNames(0),
_Cm(1.0),
_vmin(-80.0),
_vmax(20.0),
_IEiko(1.0),
_Idiff(NULL),
_Iapp(NULL),
_diffCurr(false),
_Vm(NULL),
_Vmn(NULL),
_tstim(0.4),
_arest(1.0),
_APD(0.0),
_RP(0.0),
_DI(1.e32),
_tdep(0.0),
_trep(0.0),
_dep(false),
_rep(false),
nb_of_ionic_variables(0),
nb_of_ionic_parameters(0),
_nsubiter(0),
_dt(0.0),
_dtGlobal(0.0),
_tau_cell_react(0.0),
_isExcitable(true)
{
clearData();
}
//Destructor
IonicModel::~IonicModel()
{
clearData();
}
void IonicModel::reset()
{
initVar();
setExcitable();
}
// Set time step and number of subiterations
void IonicModel::set_dt(const double & theDtGlobal, const int & nsubit)
{
_dtGlobal=theDtGlobal;
_nsubiter=nsubit;
_dt = _dtGlobal/static_cast<double>(_nsubiter);
}
//Set the ionic parameters
void IonicModel::set_ionic_parameters(const std::vector<double> & vectorParam)
{
nb_of_ionic_parameters=static_cast<unsigned>(vectorParam.size());
_Parameters=vectorParam;
}
//Protected functions
//Convert Vm between dimensionless (0,1) and dimensional (vmin,vmax) forms
double IonicModel::convertVm(const double & vmValue, bool toAdim)
{
double result=0.0;
double _dV=(_vmax-_vmin);
if(toAdim)
{
result=(vmValue-_vmin)/_dV;
}
else
{
result=_dV*vmValue+_vmin;
}
return(result);
}
void IonicModel::initVar()
{
_VariablesN=_VariablesInit;
_Variables=_VariablesInit;
if(_Vmn!=NULL)
{
(*_Vmn)=convertVm(_VariablesN[0],false);
}
if(_Vm!=NULL)
{
(*_Vm)=convertVm(_Variables[0],false);
}
}
// Private functions
// Clear the variable vectors
void IonicModel::clearData()
{
_Variables.clear();
_VariablesN.clear();
_VariablesInit.clear();
_Parameters.clear();
_VariablesOut.clear();
_VariablesOutNames.clear();
nb_of_ionic_variables=0;
nb_of_ionic_parameters=0;
_Idiff=NULL;
_Iapp=NULL;
_diffCurr=false;
_Vm=NULL;
_Vmn=NULL;
}
//Set the initial state
void IonicModel::set_InitialState(const std::vector<double> & u0)
{
nb_of_ionic_variables=static_cast<unsigned>(u0.size());
_VariablesInit=u0;
_VariablesN=u0;
_Variables=u0;
if(_Vmn!=NULL)
{
(*_Vmn)=convertVm(_VariablesN[0],false);
}
if(_Vm!=NULL)
{
(*_Vm)=convertVm(_Variables[0],false);
}
}