forked from pcafrica/electrophysiology_solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathionic.cpp
149 lines (116 loc) · 4.09 KB
/
ionic.cpp
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
#include <deal.II/base/config.h>
#include "ionic.hpp"
#include <fstream>
#include <iostream>
#include <vector>
BuenoOrovio::BuenoOrovio(const Parameters ¶ms)
: params(params)
{}
void
BuenoOrovio::setup(const IndexSet &locally_owned_dofs,
const IndexSet &locally_relevant_dofs,
const double &dt)
{
TimerOutput::Scope t(timer, "Setup ionic model");
this->locally_owned_dofs = locally_owned_dofs;
this->locally_relevant_dofs = locally_relevant_dofs;
this->dt = dt;
for (unsigned int i = 0; i < N_VARS; ++i)
{
w_old[i].reinit(locally_owned_dofs, mpi_comm);
w[i].reinit(locally_owned_dofs, mpi_comm);
w_old[i] = 1.;
w[i] = w_old[i];
}
Iion.reinit(locally_owned_dofs, locally_relevant_dofs, mpi_comm);
Iion = 0;
}
std::array<double, BuenoOrovio::N_VARS>
BuenoOrovio::alpha(const double u) const
{
std::array<double, N_VARS> a;
a[0] =
(1.0 - utils::heaviside_sharp(u, params.V1)) /
(utils::heaviside_sharp(u, params.V1m) * (params.tau1pp - params.tau1p) +
params.tau1p);
a[1] = (1.0 - utils::heaviside_sharp(u, params.V2)) /
(utils::heaviside(u, params.V2m, params.k2) *
(params.tau2pp - params.tau2p) +
params.tau2p);
a[2] = 1.0 / (utils::heaviside_sharp(u, params.V2) *
(params.tau3pp - params.tau3p) +
params.tau3p);
return a;
}
std::array<double, BuenoOrovio::N_VARS>
BuenoOrovio::beta(const double u) const
{
std::array<double, N_VARS> b;
b[0] = -utils::heaviside_sharp(u, params.V1) / params.tau1plus;
b[1] = -utils::heaviside_sharp(u, params.V2) / params.tau2plus;
b[2] = 0;
return b;
}
std::array<double, BuenoOrovio::N_VARS>
BuenoOrovio::w_inf(const double u) const
{
std::array<double, N_VARS> wi;
wi[0] = 1.0 - utils::heaviside_sharp(u, params.V1m);
wi[1] = utils::heaviside_sharp(u, params.Vo) *
(params.w_star_inf - 1.0 + u / params.tau2inf) +
1.0 - u / params.tau2inf;
wi[2] = utils::heaviside(u, params.V3, params.k3);
return wi;
}
double
BuenoOrovio::Iion_0d(const double u_old,
const std::array<double, BuenoOrovio::N_VARS> &w) const
{
// TimerOutput::Scope t(timer, "Compute Iion");
const double Iion_val =
utils::heaviside_sharp(u_old, params.V1) * (u_old - params.V1) *
(params.Vhat - u_old) * w[0] / params.taufi -
(1.0 - utils::heaviside_sharp(u_old, params.V2)) * (u_old - 0.) /
(utils::heaviside_sharp(u_old, params.Vo) *
(params.tauopp - params.tauop) +
params.tauop) -
utils::heaviside_sharp(u_old, params.V2) /
(utils::heaviside(u_old, params.Vso, params.kso) *
(params.tausopp - params.tausop) +
params.tausop) +
utils::heaviside_sharp(u_old, params.V2) * w[1] * w[2] / params.tausi;
return -Iion_val;
}
std::array<double, BuenoOrovio::N_VARS>
BuenoOrovio::solve_0d(const double u_old,
const std::array<double, BuenoOrovio::N_VARS> &w) const
{
TimerOutput::Scope t(timer, "Compute w");
std::array<double, N_VARS> w_new;
std::array<double, 3> a = alpha(u_old);
std::array<double, 3> b = beta(u_old);
std::array<double, 3> w_infs = w_inf(u_old);
for (unsigned int i = 0; i < N_VARS; ++i)
w_new[i] = w[i] + dt * ((b[i] - a[i]) * w[i] + a[i] * w_infs[i]);
return w_new;
}
void
BuenoOrovio::solve(const LinearAlgebra::distributed::Vector<double> &u_old)
{
TimerOutput::Scope t(timer, "Update w and Iion at DoFs");
// update w from t_n to t_{n+1} on the locally owned DoFs for all w's
// On top of that, evaluate Iion at DoFs
Iion.zero_out_ghost_values();
for (const types::global_dof_index idx : locally_owned_dofs)
{
std::array<double, N_VARS> w_new =
solve_0d(u_old[idx], {{w_old[0][idx], w_old[1][idx], w_old[2][idx]}});
for (unsigned int i = 0; i < N_VARS; ++i)
{
w[i][idx] = w_new[i];
}
Iion[idx] = Iion_0d(u_old[idx], {{w[0][idx], w[1][idx], w[2][idx]}});
}
Iion.update_ghost_values();
w_old = w;
}