SpaceQuester

Untitled

Aug 4th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.33 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #define _USE_MATH_DEFINES
  4. #include "math.h"
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <locale.h>
  8. #include <time.h>
  9. #include <stdbool.h>
  10. #include <list>
  11. #include <omp.h>
  12.  
  13. using namespace std;
  14.  
  15. #define Node_count 100
  16.  
  17. #define Equations_per_node 12 // !!! 12 - Don't change !!!
  18. #define Equations_count Node_count * Equations_per_node
  19.  
  20. int MaxDeep = 25;
  21.  
  22. double* f;
  23. double* f_diff;
  24.  
  25. double** k;
  26. double* phi_k1;
  27. double* phi_k2;
  28. double* phi_k3;
  29.  
  30. bool enable_I_syn_out = false;
  31.  
  32. double c_0 = 2; // uM
  33. double c_1 = 0.185;
  34. double v_1 = 6; // s^-1
  35. double v_2 = 0.11; // s^-1
  36. double v_3 = 2.2; // uM/s
  37. double* v_4; // uM/s - Controling parameter // 0.5 //double v_4[Node_count]; // uM/s - Controling parameter //0.495
  38. double v_5 = 0.025; // uM/s
  39. double v_6 = 0.2; // uM/s
  40. double k_1 = 0.5; // s^-1
  41. double k_2 = 1; // uM
  42. double k_3 = 0.1;
  43. double k_4 = 1.1; // uM/s
  44. double a_2 = 0.14; // uM/s
  45. double d_1 = 0.13; // uM
  46. double d_2 = 1.049; // uM
  47. double d_3 = 0.9434; // uM
  48. double d_5 = 0.082; // uM
  49. double alpha = 0.8;
  50. double tau_IP3 = 7.143; // s
  51. double IP3_star = 0.16; // uM
  52. double d_Ca = 0.001; // 0.001
  53. double d_IP3 = 0.2; // 0.12
  54. double alpha_Glu = 2; // 2
  55. double g_astro; // 3
  56.  
  57. // https://neuronaldynamics.epfl.ch/online/Ch2.S2.html
  58. double C_m = 1; // muF/cm^2
  59. double g_K = 35; // mS/cm^2
  60. double g_Na = 40; // mS/cm^2
  61. double g_L = 0.3; // mS/cm^2
  62. double E_K = -77; // mV
  63. double E_Na = 55; // mV
  64. double E_L = -65; // mV
  65.  
  66. double C_m_P = 1; // muF/cm^2
  67. double g_K_P = 35; // mS/cm^2
  68. double g_Na_P = 40; // mS/cm^2
  69. double g_L_P = 0.3; // mS/cm^2
  70. double E_K_P = -77; // mV
  71. double E_Na_P = 55; // mV
  72. double E_L_P = -65; // mV
  73.  
  74. double p_rewir;
  75. double p_inhib;
  76.  
  77. double I_app_min;
  78. double I_app_max;
  79.  
  80. double g_syn;
  81. double k_syn = 0.2;
  82. double* E_syn;
  83.  
  84. double g_syn_P;
  85. double k_syn_P = 0.2;
  86. double* E_syn_P;
  87.  
  88. double alpha_G_P = 25; //s^-1
  89. double beta_G_P = 500; //s^-1
  90.  
  91. double* I_app;
  92. double* I_app_P;
  93.  
  94. double** A_A;
  95. double** B_A;
  96. double* C_A;
  97.  
  98. double** A_N;
  99. double** B_N;
  100. double* C_N;
  101.  
  102. double** A_N_P;
  103. double** B_N_P;
  104. double* C_N_P;
  105.  
  106. list<double>* V_spikes;
  107. list<double>* V_spikes_Freq;
  108.  
  109. FILE* fp_I_syn;
  110.  
  111. double** tau;
  112.  
  113. #define tau_min 2 // ms
  114. #define tau_max 12 // ms
  115.  
  116. #define ms_to_step 40 // (0.001 / dt) !!! Don't forget !!!
  117.  
  118. #define Max_delay tau_max * ms_to_step
  119. double** V_old_array;
  120.  
  121. const double Poisson_Freq = 50; // Hz
  122. //const double Min_magintude = -0.20; // muA/cm^2
  123. double Max_magnitude; // muA/cm^2 // 0.20
  124. const double Duration = 0.002; // sec
  125.  
  126. double* Meander_start_from_zero;
  127. double* Meander_width;
  128. double* Meander_height;
  129. double* Meander_interval;
  130. double* last_meander_end;
  131.  
  132. //bool thread_count_printed = false;
  133.  
  134. double I_stim(int i, double t)
  135. {
  136. if (t < Meander_start_from_zero[i])
  137. return 0;
  138.  
  139. t -= Meander_start_from_zero[i];
  140. t = fmod(t, Meander_width[i] + Meander_interval[i]);
  141.  
  142. return t < Meander_width[i] ? Meander_height[i] : 0;
  143. }
  144.  
  145. double Ca(int i)
  146. {
  147. return f[i * Equations_per_node];
  148. }
  149.  
  150. void SetCa(int i, double value)
  151. {
  152. f[i * Equations_per_node] = value;
  153. }
  154.  
  155. double IP3(int i)
  156. {
  157. return f[i * Equations_per_node + 1];
  158. }
  159.  
  160. void SetIP3(int i, double value)
  161. {
  162. f[i * Equations_per_node + 1] = value;
  163. }
  164.  
  165. double z(int i)
  166. {
  167. return f[i * Equations_per_node + 2];
  168. }
  169.  
  170. void Setz(int i, double value)
  171. {
  172. f[i * Equations_per_node + 2] = value;
  173. }
  174.  
  175. double G_P(int i)
  176. {
  177. return f[i * Equations_per_node + 3];
  178. }
  179.  
  180. void SetG_P(int i, double value)
  181. {
  182. f[i * Equations_per_node + 3] = value;
  183. }
  184.  
  185. double V(int i)
  186. {
  187. return f[i * Equations_per_node + 4];
  188. }
  189.  
  190. void SetV(int i, double value)
  191. {
  192. f[i * Equations_per_node + 4] = value;
  193. }
  194.  
  195. double m(int i)
  196. {
  197. return f[i * Equations_per_node + 5];
  198. }
  199.  
  200. void Setm(int i, double value)
  201. {
  202. f[i * Equations_per_node + 5] = value;
  203. }
  204.  
  205. double n(int i)
  206. {
  207. return f[i * Equations_per_node + 6];
  208. }
  209.  
  210. void Setn(int i, double value)
  211. {
  212. f[i * Equations_per_node + 6] = value;
  213. }
  214.  
  215. double h(int i)
  216. {
  217. return f[i * Equations_per_node + 7];
  218. }
  219.  
  220. void Seth(int i, double value)
  221. {
  222. f[i * Equations_per_node + 7] = value;
  223. }
  224.  
  225. ///
  226.  
  227. double V_P(int i)
  228. {
  229. return f[i * Equations_per_node + 8];
  230. }
  231.  
  232. void SetV_P(int i, double value)
  233. {
  234. f[i * Equations_per_node + 8] = value;
  235. }
  236.  
  237. double m_P(int i)
  238. {
  239. return f[i * Equations_per_node + 9];
  240. }
  241.  
  242. void Setm_P(int i, double value)
  243. {
  244. f[i * Equations_per_node + 9] = value;
  245. }
  246.  
  247. double n_P(int i)
  248. {
  249. return f[i * Equations_per_node + 10];
  250. }
  251.  
  252. void Setn_P(int i, double value)
  253. {
  254. f[i * Equations_per_node + 10] = value;
  255. }
  256.  
  257. double h_P(int i)
  258. {
  259. return f[i * Equations_per_node + 11];
  260. }
  261.  
  262. void Seth_P(int i, double value)
  263. {
  264. f[i * Equations_per_node + 11] = value;
  265. }
  266.  
  267. double V_old(int i, int delay)
  268. {
  269. return V_old_array[i][Max_delay - 1 - delay];
  270. }
  271.  
  272. int RandomI(int min, int max)
  273. {
  274. return ((double)rand() / (RAND_MAX - 1)) * (max - min) + min;
  275. }
  276.  
  277. double RandomD(double min, double max)
  278. {
  279. return ((double)rand() / RAND_MAX) * (max - min) + min;
  280. }
  281.  
  282. double J_channel(double* f, int i)
  283. {
  284. return c_1 * v_1 * pow(IP3(i), 3) * pow(Ca(i), 3) * pow(z(i), 3) * (c_0 / c_1 - (1 + 1 / c_1) * Ca(i)) / pow((IP3(i) + d_1) * (Ca(i) + d_5), 3);
  285. }
  286.  
  287. double J_PLC(double* f, int i)
  288. {
  289. return v_4[i] * (Ca(i) + (1 - alpha) * k_4) / (Ca(i) + k_4);
  290. }
  291.  
  292. double J_leak(double* f, int i)
  293. {
  294. return c_1 * v_2 * (c_0 / c_1 - (1 + 1 / c_1) * Ca(i));
  295. }
  296.  
  297. double J_pump(double* f, int i)
  298. {
  299. return v_3 * pow(Ca(i), 2) / (pow(k_3, 2) + pow(Ca(i), 2));
  300. }
  301.  
  302. double J_in(double* f, int i)
  303. {
  304. return v_5 + v_6 * pow(IP3(i), 2) / (pow(k_2, 2) + pow(IP3(i), 2));
  305. }
  306.  
  307. double J_out(double* f, int i)
  308. {
  309. return k_1 * Ca(i);
  310. }
  311.  
  312. double J_Glu(double* f, int i)
  313. {
  314. /*double J = 0;
  315. if (E_syn_P[i] == 0)
  316. {
  317. J += alpha_Glu / (1 + exp(-(G_P(i) - 0.25) / 0.01));
  318. }
  319. return J;*/
  320.  
  321. return alpha_Glu / (1 + exp(-(G_P(i) - 0.25) / 0.01));
  322. }
  323.  
  324. double alpha_m(double* f, int i)
  325. {
  326. return 0.182 * (V(i) + 35) / (1 - exp(-(V(i) + 35) / 9));
  327. }
  328.  
  329. double beta_m(double* f, int i)
  330. {
  331. return -0.124 * (V(i) + 35) / (1 - exp((V(i) + 35) / 9));
  332. }
  333.  
  334. double alpha_n(double* f, int i)
  335. {
  336. return 0.02 * (V(i) - 25) / (1 - exp(-(V(i) - 25) / 9));
  337. }
  338.  
  339. double beta_n(double* f, int i)
  340. {
  341. return -0.002 * (V(i) - 25) / (1 - exp((V(i) - 25) / 9));
  342. }
  343.  
  344. double alpha_h(double* f, int i)
  345. {
  346. return 0.25 * exp(-(V(i) + 90) / 12);
  347. }
  348.  
  349. double beta_h(double* f, int i)
  350. {
  351. return 0.25 * exp((V(i) + 62) / 6) / exp((V(i) + 90) / 12);
  352. }
  353.  
  354. //
  355.  
  356. double alpha_m_P(double* f, int i)
  357. {
  358. return 0.182 * (V_P(i) + 35) / (1 - exp(-(V_P(i) + 35) / 9));
  359. }
  360.  
  361. double beta_m_P(double* f, int i)
  362. {
  363. return -0.124 * (V_P(i) + 35) / (1 - exp((V_P(i) + 35) / 9));
  364. }
  365.  
  366. double alpha_n_P(double* f, int i)
  367. {
  368. return 0.02 * (V_P(i) - 25) / (1 - exp(-(V_P(i) - 25) / 9));
  369. }
  370.  
  371. double beta_n_P(double* f, int i)
  372. {
  373. return -0.002 * (V_P(i) - 25) / (1 - exp((V_P(i) - 25) / 9));
  374. }
  375.  
  376. double alpha_h_P(double* f, int i)
  377. {
  378. return 0.25 * exp(-(V_P(i) + 90) / 12);
  379. }
  380.  
  381. double beta_h_P(double* f, int i)
  382. {
  383. return 0.25 * exp((V_P(i) + 62) / 6) / exp((V_P(i) + 90) / 12);
  384. }
  385.  
  386. double UllahJung_HodgkinHuxley(int i, double* f, double t)
  387. {
  388. int in = i / Equations_per_node;
  389. int il = i % Equations_per_node;
  390.  
  391. switch (il)
  392. {
  393. case 0: // Ca
  394. {
  395. double sum_1 = 0;
  396.  
  397. /*for (int j = 0; j < Node_count; j++)
  398. {
  399. sum_1 += d_Ca * (Ca(j) - Ca(in));
  400. }*/
  401.  
  402. for (int j = 0; j < C_A[in]; j++)
  403. {
  404. sum_1 += d_Ca * (Ca((int)B_A[in][j]) - Ca(in));
  405. }
  406.  
  407. return J_channel(f, in) - J_pump(f, in) + J_leak(f, in) + J_in(f, in) - J_out(f, in) + sum_1;
  408. }
  409.  
  410. case 1: // IP3
  411. {
  412. double sum_2 = 0;
  413.  
  414. /*for (int j = 0; j < Node_count; j++)
  415. {
  416. sum_2 += d_IP3 * (IP3(j) - IP3(in));
  417. }*/
  418.  
  419. for (int j = 0; j < C_A[in]; j++)
  420. {
  421. sum_2 += d_IP3 * (IP3((int)B_A[in][j]) - IP3(in));
  422. }
  423.  
  424. return (IP3_star - IP3(in)) / tau_IP3 + J_PLC(f, in) + sum_2 + J_Glu(f, in);
  425. }
  426.  
  427. case 2: // z
  428. {
  429. return a_2 * (d_2 * (IP3(in) + d_1) / (IP3(in) + d_3) * (1 - z(in)) - Ca(in) * z(in));
  430. }
  431.  
  432. case 3: // G_P
  433. {
  434. return -alpha_G_P * G_P(in) + beta_G_P * (1 / (1 + exp(-V_P(in) / 0.5)));
  435. }
  436.  
  437. case 4: // V
  438. {
  439. double I_syn = 0;
  440. double I_syn_P = 0;
  441.  
  442. /*for (int j = 0; j < Node_count; j++)
  443. {
  444. //sum += A[in][j] * g_syn * (V(in) - V_old(j, tau[in][j]));
  445. //sum += A[in][j] * g_syn * (V(j) - V(in));
  446. //sum += A[in][j] * g_syn * (V(in) - E_syn[in]) / (1 + exp(-V_old(j, tau[in][j]) / k_syn));
  447. //sum += 1 / (0.2 * Node_count_half) * A[in][j] * g_syn * (V(in) - E_syn[in]) / (1 + exp(-V(j) / k_syn)); // i up, j down
  448. //sum += 1 / (0.2 * Node_count_half) * A[in][j] * g_syn * (V(j) - E_syn[j]) / (1 + exp(-V(in) / k_syn)); // j up, i down
  449. I_syn += A_N[in][j] * g_syn * (E_syn[in] - V(in)) / (1 + exp(-(V(j) / k_syn)));
  450. //printf("in = %d\t Node_count = %d\t A[in][j] = %f\t V(in) = %f\t E_syn[in] = %f\t sum = %f\n", in, j, A[in][j], V(in), E_syn[in], sum);
  451. }*/
  452.  
  453. /*for (int j = 0; j < C[in]; j++)
  454. {
  455. sum += sigma[in][(int)B[in][j]] * (V((int)B[in][j]) - V(in));
  456. }*/
  457.  
  458. for (int j = 0; j < C_N[in]; j++)
  459. {
  460. if ((1 + g_astro * Ca(in)) > 0)
  461. {
  462. if (Ca(in) >= 0.3)
  463. {
  464. I_syn += g_syn * (1 + g_astro * Ca(in)) * (E_syn[(int)B_N[in][j]] - V(in)) / (1 + exp(-(V((int)B_N[in][j]) / k_syn))); // версия с V (без V_old)
  465. }
  466. else
  467. {
  468. I_syn += g_syn * (E_syn[(int)B_N[in][j]] - V(in)) / (1 + exp(-(V((int)B_N[in][j]) / k_syn))); // версия с V (без V_old)
  469. }
  470. }
  471. //I_syn += g_syn * (1 + g_astro * Ca(in)) * (E_syn[in] - V(in)) / (1 + exp(-(V_old((int)B_N[in][j], tau[in][(int)B_N[in][j]]) / k_syn)); // версия с V_old
  472. //I_syn += g_syn * (1 + g_astro * Ca(in)) * (E_syn[in] - V(in)) / (1 + exp(-(V(j) / k_syn))); // версия без с V (без V_old)
  473. //I_syn += g_syn * (E_syn[in] - V(in)) / (1 + exp(-(V(j) / k_syn))); // версия без с V (без V_old), упрощенная версия
  474. // sum_3 += g_syn * (1 + g_astro * Ca(in)) * (E_syn[i] - V(i)) / (1 + exp(-(V(j) / k_syn))); // образец из старой версии
  475. //I_syn += g_syn * (E_syn[in] - V(in)) / (1 + exp(-(V_old((int)B_N[in][j], tau[in][(int)B_N[in][j]])) / k_syn));*/
  476. //I_syn += g_syn * (E_syn[(int)B_N[in][j]] - V(in)) / (1 + exp(-(V(j) / k_syn))); // версия с V (без V_old)
  477. //I_syn += g_syn * (E_syn[(int)B_N[in][j]] - V(in)) / (1 + exp(-(V((int)B_N[in][j]) / k_syn))); // версия с V (без V_old), упрощенная версия !!!
  478. //I_syn += g_syn * (E_syn[(int)B_N[in][j]] - V(in)) / (1 + exp(-(V_old((int)B_N[in][j], tau[in][(int)B_N[in][j]]) / k_syn))); // версия с V (без V_old), упрощенная версия !!!
  479. //sum += g_syn * (V((int)B[in][j]) - V(in)); // устаревшая часть, нужна для проверки разностной схемы
  480. //sum += A[in][j] * g_syn * (V(in) - E_syn[in]) / (1 + exp(-V_old((int)B[in][j]) / k_syn)); // устаревшая часть
  481. //sum += A[in][(int)B[in][j]] * g_syn * (V(in) - E_syn[in]) / (1 + exp(-V_old((int)B[in][j], tau[in][(int)B[in][j]]) / k_syn));
  482. //sum += A[in][(int)B[in][j]] * g_syn * (V((int)B[in][j]) - E_syn[(int)B[in][j]]) / (1 + exp(-V_old(in, tau[in][(int)B[in][j]]) / k_syn));
  483. //sum += 1 / (0.2 * Node_count_half) * A[in][(int)B[in][j]] * g_syn * (V((int)B[in][j]) - E_syn[(int)B[in][j]]) / (1 + exp(-V(in) / k_syn)); // j up, i down
  484. //sum += 1 / (0.2 * Node_count) * /*(int)A_N[in][(int)B_N[in][j]] * */ g_syn * (1 + g_astro * Ca(in)) * (V(in) - E_syn[in]) / (1 + exp(-V((int)B_N[in][j]) / k_syn)); // i up, j down
  485. // i up, j down
  486. /*printf("i = %d\t j = %d\t A[i, j] = %d\n", in, (int)B_N[in][j], (int)A_N[in][(int)B_N[in][j]]);*/
  487. /*printf("i = %d\t V_old = %f\t exp = %f\n", in, Vold, ee);*/
  488. }
  489. /*printf("i = %d\t sum = %f\n", in, sum);*/
  490.  
  491. if ((1 + g_astro * Ca(in)) > 0)
  492. {
  493. if (Ca(in) >= 0.3)
  494. {
  495. I_syn_P += g_syn_P * (1 + g_astro * Ca(in)) * (E_syn_P[in] - V_P(in)) / (1 + exp(-(V_P(in) / k_syn_P))); // версия с V (без V_old)
  496. }
  497. else
  498. {
  499. I_syn_P += g_syn_P * (E_syn_P[in] - V_P(in)) / (1 + exp(-(V_P(in) / k_syn_P))); // версия с V (без V_old)
  500. }
  501. }
  502.  
  503. if (enable_I_syn_out)
  504. fprintf(fp_I_syn, i == Equations_count - 1 ? "%f" : "%f\t", I_syn);
  505.  
  506. return 1000 * ((g_Na * pow(m(in), 3) * h(in) * (E_Na - V(in)) + g_K * n(in) * (E_K - V(in)) + g_L * (E_L - V(in)) + I_app[in] + I_syn + I_syn_P) / C_m); // V
  507. }
  508.  
  509. case 5: // m
  510. {
  511. return 1000 * (alpha_m(f, in) * (1 - m(in)) - beta_m(f, in) * m(in)); // m
  512. }
  513.  
  514. case 6: // n
  515. {
  516. return 1000 * (alpha_n(f, in) * (1 - n(in)) - beta_n(f, in) * n(in)); // n
  517. }
  518.  
  519. case 7: // h
  520. {
  521. return 1000 * (alpha_h(f, in) * (1 - h(in)) - beta_h(f, in) * h(in)); // h
  522. }
  523.  
  524. case 8: // V_P
  525. {
  526. return 1000 * ((g_Na_P * pow(m_P(in), 3) * h_P(in) * (E_Na_P - V_P(in)) + g_K_P * n_P(in) * (E_K_P - V_P(in)) + g_L_P * (E_L_P - V_P(in)) + I_app_P[in] + I_stim(in, t)) / C_m_P); // V_P
  527. }
  528.  
  529. case 9: // m_P
  530. {
  531. return 1000 * (alpha_m_P(f, in) * (1 - m_P(in)) - beta_m_P(f, in) * m_P(in)); // m_P
  532. }
  533.  
  534. case 10: // n_P
  535. {
  536. return 1000 * (alpha_n_P(f, in) * (1 - n_P(in)) - beta_n_P(f, in) * n_P(in)); // n_P
  537. }
  538.  
  539. case 11: // h_P
  540. {
  541. return 1000 * (alpha_h_P(f, in) * (1 - h_P(in)) - beta_h_P(f, in) * h_P(in)); // h_P
  542. }
  543. }
  544.  
  545. return 0;
  546. }
  547.  
  548. void RungeKutta(double t, double dt, double* f, double* f_next)
  549. {
  550. // k1
  551. #pragma omp parallel for
  552. for (int i = 0; i < Equations_count; i++)
  553. {
  554. //if (!thread_count_printed)
  555. //{
  556. // thread_count_printed = true;
  557. // printf("Threads = %d\n", omp_get_num_threads());
  558. //}
  559.  
  560. k[i][0] = UllahJung_HodgkinHuxley(i, f, t) * dt;
  561. phi_k1[i] = f[i] + k[i][0] / 2;
  562. k[i][1] = UllahJung_HodgkinHuxley(i, phi_k1, t) * dt;
  563. phi_k2[i] = f[i] + k[i][1] / 2;
  564. k[i][2] = UllahJung_HodgkinHuxley(i, phi_k2, t) * dt;
  565. phi_k3[i] = f[i] + k[i][2] / 2;
  566. k[i][3] = UllahJung_HodgkinHuxley(i, phi_k3, t) * dt;
  567. f_next[i] = f[i] + (k[i][0] + 2 * k[i][1] + 2 * k[i][2] + k[i][3]) / 6;
  568. }
  569.  
  570. //for (int i = 0; i < Equations_count; i++)
  571. // phi_k1[i] = f[i] + k[i][0] / 2;
  572.  
  573. // k2
  574. //for (int i = 0; i < Equations_count; i++)
  575. // k[i][1] = UllahJung_HodgkinHuxley(i, phi_k1, t) * dt;
  576.  
  577.  
  578. //for (int i = 0; i < Equations_count; i++)
  579. // phi_k2[i] = f[i] + k[i][1] / 2;
  580.  
  581. // k3
  582. //for (int i = 0; i < Equations_count; i++)
  583. // k[i][2] = UllahJung_HodgkinHuxley(i, phi_k2, t) * dt;
  584.  
  585.  
  586. //for (int i = 0; i < Equations_count; i++)
  587. // phi_k3[i] = f[i] + k[i][2] / 2;
  588.  
  589. //enable_I_syn_out = true;
  590.  
  591. // k4
  592. //for (int i = 0; i < Equations_count; i++)
  593. // k[i][3] = UllahJung_HodgkinHuxley(i, phi_k3, t) * dt;
  594.  
  595. //enable_I_syn_out = false;
  596.  
  597. //for (int i = 0; i < Equations_count; i++)
  598. // f_next[i] = f[i] + (k[i][0] + 2 * k[i][1] + 2 * k[i][2] + k[i][3]) / 6;
  599. }
  600.  
  601. void CopyArray(double* source, double* target, int N)
  602. {
  603. for (int i = 0; i < N; i++)
  604. target[i] = source[i];
  605. }
  606.  
  607. bool Approximately(double a, double b)
  608. {
  609. if (a < 0)
  610. a = -a;
  611.  
  612. if (b < 0)
  613. b = -b;
  614.  
  615. return a - b <= 0.000001;
  616. }
  617.  
  618. //bool CheckSameLine(int i, int j)
  619. //{
  620. // return i / Node_wire_width == j / Node_wire_width;
  621. //}
  622. //
  623. //bool IsWireNeighbors(int i, int j)
  624. //{
  625. // if (CheckSameLine(i, j) && (i == j - 1 || i == j + 1))
  626. // return true;
  627. //
  628. // if (i == j - Node_wire_width || i == j + Node_wire_width)
  629. // return true;
  630. //
  631. // return false;
  632. //}
  633.  
  634. // http://preshing.com/20111007/how-to-generate-random-timings-for-a-poisson-process/
  635. double nextTime(double rateParameter)
  636. {
  637. return -log(1.0 - (double)rand() / (RAND_MAX)) / rateParameter;
  638. }
  639.  
  640. void GenerateRandomMeander(int i, double min_start_time)
  641. {
  642. double offset = nextTime(Poisson_Freq);
  643.  
  644. if (offset < 0)
  645. {
  646. int a = 0;
  647. }
  648.  
  649. Meander_start_from_zero[i] = min_start_time + offset;
  650. Meander_width[i] = Duration;
  651. //Meander_height[i] = RandomD(-Max_magnitude, Max_magnitude);
  652. //Meander_height[i] = RandomD(0, Max_magnitude);
  653. Meander_height[i] = Max_magnitude;
  654. }
  655.  
  656. void FillAMatrixZero()
  657. {
  658. for (int i = 0; i < Node_count; i++)
  659. {
  660. for (int j = 0; j < Node_count; j++)
  661. {
  662. A_A[i][j] = 0;
  663. A_N[i][j] = 0;
  664. A_N_P[i][j] = 0;
  665. }
  666. }
  667. }
  668.  
  669. void FillAstrociteMatrix()
  670. {
  671. for (int i = 0; i < Node_count; i++)
  672. {
  673. for (int j = 0; j < Node_count; j++)
  674. {
  675. if (i == j)
  676. {
  677. A_A[i][j] = 0;
  678. continue;
  679. }
  680.  
  681. if (i > j)
  682. {
  683. A_A[i][j] = A_A[j][i];
  684. continue;
  685. }
  686.  
  687. if (i == 0 && j == Node_count - 1)
  688. {
  689. A_A[i][j] = 1;
  690. continue;
  691. }
  692.  
  693. if (i == Node_count - 1 && j == 0)
  694. {
  695. A_A[i][j] = 1;
  696. continue;
  697. }
  698.  
  699. if (i == j - 1 || i == j + 1)
  700. {
  701. A_A[i][j] = 1;
  702. continue;
  703. }
  704. }
  705. }
  706. //A_A[0][1] = 0; // only for debug. diffusion Ca test
  707. //A_A[1][0] = 0; // only for debug. diffusion Ca test
  708. //A_A[1][3] = 0;
  709. //A_A[3][1] = 0;
  710. //A_A[0][2] = 0;
  711. //A_A[2][0] = 0;
  712. }
  713.  
  714. void FillBCMatrix_A()
  715. {
  716. for (int i = 0; i < Node_count; i++)
  717. {
  718. int bIndex = 0;
  719. C_A[i] = 0;
  720. for (int j = 0; j < Node_count; j++)
  721. {
  722. if (A_A[i][j] == 1)
  723. {
  724. B_A[i][bIndex] = j;
  725. bIndex++;
  726. C_A[i]++;
  727. }
  728. }
  729. }
  730. }
  731.  
  732. void FillBCMatrix_N()
  733. {
  734. for (int i = 0; i < Node_count; i++)
  735. {
  736. int bIndex = 0;
  737. C_N[i] = 0;
  738. for (int j = 0; j < Node_count; j++)
  739. {
  740. if (A_N[i][j] == 1)
  741. {
  742. B_N[i][bIndex] = j;
  743. bIndex++;
  744. C_N[i]++;
  745. }
  746. }
  747. }
  748. }
  749.  
  750. void FillBCMatrix_N_P()
  751. {
  752. for (int i = 0; i < Node_count; i++)
  753. {
  754. int bIndex = 0;
  755. C_N_P[i] = 0;
  756. for (int j = 0; j < Node_count; j++)
  757. {
  758. if (A_N_P[i][j] == 1)
  759. {
  760. B_N_P[i][bIndex] = j;
  761. bIndex++;
  762. C_N_P[i]++;
  763. }
  764. }
  765. }
  766. }
  767.  
  768. bool IsWireNeighbors(int i, int j, int deep)
  769. {
  770. int j_border_left = j - deep < 0 ? j + Node_count : j;
  771. int j_border_right = j + deep >= Node_count ? j - Node_count : j;
  772.  
  773. if (i == j_border_left - deep || i == j_border_right + deep)
  774. {
  775. return true;
  776. }
  777.  
  778. return false;
  779. }
  780.  
  781. void FillNeuronMatrix()
  782. {
  783. for (int i = 0; i < Node_count; i++)
  784. {
  785. for (int j = 0; j < Node_count; j++)
  786. {
  787. if (i == j)
  788. {
  789. A_N[i][j] = 0;
  790. continue;
  791. }
  792.  
  793. if (i > j)
  794. {
  795. A_N[i][j] = A_N[j][i];
  796. continue;
  797. }
  798.  
  799. for (int deep = 1; deep <= MaxDeep; deep++)
  800. {
  801. if (IsWireNeighbors(i, j, deep))
  802. A_N[i][j] = 1;
  803. }
  804. }
  805. }
  806. }
  807.  
  808. void RandomizeNeuronMatrix()
  809. {
  810. srand(time(NULL));
  811.  
  812. for (int i = 0; i < Node_count; i++)
  813. {
  814. //if (i == Node_count / 2)
  815. // srand(time(NULL));
  816.  
  817. for (int link = 0; link < MaxDeep * 2; link++)
  818. {
  819. double x = RandomD(0, 1);
  820.  
  821. if (x > p_rewir)
  822. continue;
  823.  
  824. int rndJ;
  825.  
  826. do
  827. {
  828. rndJ = RandomI(0, Node_count);
  829. } while (i == rndJ || A_N[i][rndJ] == 1);
  830.  
  831. int rndJ_last;
  832.  
  833. do
  834. {
  835. rndJ_last = RandomI(i - MaxDeep - 1, i + MaxDeep + 1);
  836.  
  837. if (rndJ_last < 0)
  838. rndJ_last += Node_count;
  839. else if (rndJ_last >= Node_count)
  840. rndJ_last -= Node_count;
  841.  
  842. } while (i == rndJ_last || A_N[i][rndJ_last] == 0);
  843.  
  844. A_N[i][rndJ_last] = 0;
  845.  
  846. A_N[i][rndJ] = 1;
  847. }
  848. }
  849. }
  850.  
  851. void FillNeuronPoissonMatrix()
  852. {
  853. for (int i = 0; i < Node_count; i++)
  854. {
  855. for (int j = 0; j < Node_count; j++)
  856. {
  857. A_N_P[i][j] = 0;
  858. }
  859. }
  860. }
  861.  
  862. void FillVOldFromCurrent()
  863. {
  864. for (int i = 0; i < Node_count; i++)
  865. for (int j = 0; j < Max_delay; j++)
  866. V_old_array[i][j] = V(i);
  867. }
  868.  
  869. void UpdateVOld()
  870. {
  871. for (int i = 0; i < Node_count; i++)
  872. {
  873. for (int j = 1; j < Max_delay; j++)
  874. V_old_array[i][j - 1] = V_old_array[i][j];
  875.  
  876. V_old_array[i][Max_delay - 1] = V(i);
  877. }
  878. }
  879.  
  880. //void FillFullTauMatrix()
  881. //{
  882. // for (int i = 0; i < Node_count; i++)
  883. // {
  884. // for (int j = 0; j < Node_count; j++)
  885. // {
  886. // if (i < Node_count || j < Node_count)
  887. // {
  888. // tau[i][j] = 0;
  889. // continue;
  890. // }
  891. //
  892. // int i_neuron = i - Node_count;
  893. // int j_neuron = j - Node_count;
  894. //
  895. // int i_wire_x = i_neuron / Node_wire_width;
  896. // int i_wire_y = i_neuron % Node_wire_width;
  897. //
  898. // int j_wire_x = j_neuron / Node_wire_width;
  899. // int j_wire_y = j_neuron % Node_wire_width;
  900. //
  901. // double distance_max = sqrt(2.) * (Node_wire_width - 1);
  902. // double distance = sqrt((i_wire_x - j_wire_x) * (i_wire_x - j_wire_x) + (i_wire_y - j_wire_y) * (i_wire_y - j_wire_y));
  903. //
  904. // tau[i][j] = (tau_min + distance / (distance_max) * (tau_max - tau_min)) * ms_to_step;
  905. // }
  906. // }
  907. //}
  908. //
  909. //void FillTauMatrix()
  910. //{
  911. // for (int i = 0; i < Node_count; i++)
  912. // {
  913. // for (int j = 0; j < Node_count; j++)
  914. // {
  915. // if (i == j || A_N[i][j] == 0)
  916. // {
  917. // tau[i][j] = 0;
  918. // continue;
  919. // }
  920. //
  921. // int i_neuron = i;
  922. // int j_neuron = j;
  923. //
  924. // int i_wire_x = i_neuron / Node_wire_width;
  925. // int i_wire_y = i_neuron % Node_wire_width;
  926. //
  927. // int j_wire_x = j_neuron / Node_wire_width;
  928. // int j_wire_y = j_neuron % Node_wire_width;
  929. //
  930. // double distance_max = sqrt(2.) * (Node_wire_width - 1);
  931. // double distance = sqrt((i_wire_x - j_wire_x) * (i_wire_x - j_wire_x) + (i_wire_y - j_wire_y) * (i_wire_y - j_wire_y));
  932. //
  933. // double t = (distance - 1) / (distance_max - 1);
  934. // tau[i][j] = (tau_min + t * (tau_max - tau_min)) * ms_to_step;
  935. // }
  936. // }
  937. //}
  938.  
  939. int main(int argc, char* argv[])
  940. {
  941. // run like: UJ_HH_Ring_acc.out 250 0.2 0.4 0.05 3.0 1.05 1.50 // (1) p_rewir (2) g_syn (3) g_astro (4) Max_magnitude (5) g_syn_P
  942. /*sscanf(argv[1], "%d", &Node_count);
  943. FILE* fp_Node_count;
  944. fp_Node_count = fopen("Node_count.txt", "w");
  945. fprintf(fp_Node_count, "%d\t", Node_count);
  946. fclose(fp_Node_count);
  947. printf("Node_count = %d\n", Node_count);*/
  948.  
  949. sscanf(argv[1], "%lf", &p_rewir);
  950. FILE* fp_p_rewir;
  951. fp_p_rewir = fopen("p_rewir.txt", "w");
  952. fprintf(fp_p_rewir, "%f\t", p_rewir);
  953. fclose(fp_p_rewir);
  954. printf("p_rewir = %f\n", p_rewir);
  955.  
  956. /*sscanf(argv[3], "%lf", &p_inhib);
  957. FILE* fp_p_inhib;
  958. fp_p_inhib = fopen("p_inhib.txt", "w");
  959. fprintf(fp_p_inhib, "%f\t", p_inhib);
  960. fclose(fp_p_inhib);
  961. printf("p_inhib = %f\n", p_inhib);*/
  962.  
  963. sscanf(argv[2], "%lf", &g_syn);
  964. FILE* fp_g_syn;
  965. fp_g_syn = fopen("g_syn.txt", "w");
  966. fprintf(fp_g_syn, "%f\t", g_syn);
  967. fclose(fp_g_syn);
  968. printf("g_syn = %f\n", g_syn);
  969.  
  970. sscanf(argv[3], "%lf", &g_astro);
  971. FILE* fp_g_astro;
  972. fp_g_astro = fopen("g_astro.txt", "w");
  973. fprintf(fp_g_astro, "%f\t", g_astro);
  974. fclose(fp_g_astro);
  975. printf("g_astro = %f\n", g_astro);
  976.  
  977. sscanf(argv[4], "%lf", &Max_magnitude);
  978. FILE* fp_Max_magnitude;
  979. fp_Max_magnitude = fopen("Max_magnitude.txt", "w");
  980. fprintf(fp_Max_magnitude, "%f\t", Max_magnitude);
  981. fclose(fp_Max_magnitude);
  982. printf("I_stim magnitude = %f\n", Max_magnitude);
  983.  
  984. sscanf(argv[5], "%lf", &g_syn_P);
  985. FILE* fp_g_syn_P;
  986. fp_g_syn_P = fopen("g_syn_P.txt", "w");
  987. fprintf(fp_g_syn_P, "%f\t", g_syn_P);
  988. fclose(fp_g_syn_P);
  989. printf("g_syn_P = %f\n", g_syn_P);
  990.  
  991. //sscanf(argv[6], "%lf", &I_app_min);
  992. //sscanf(argv[7], "%lf", &I_app_max);
  993.  
  994. f = new double[Equations_count];
  995. f_diff = new double[Equations_count];
  996. v_4 = new double[Node_count];
  997. E_syn = new double[Node_count];
  998. I_app = new double[Node_count];
  999. E_syn_P = new double[Node_count];
  1000. I_app_P = new double[Node_count];
  1001. V_spikes = new list<double>[Node_count];
  1002. V_spikes_Freq = new list<double>[Node_count];
  1003.  
  1004. Meander_start_from_zero = new double[Node_count];
  1005. Meander_width = new double[Node_count];
  1006. Meander_height = new double[Node_count];
  1007. Meander_interval = new double[Node_count];
  1008. last_meander_end = new double[Node_count];
  1009.  
  1010. tau = new double* [Node_count];
  1011. for (int i = 0; i < Node_count; i++)
  1012. tau[i] = new double[Node_count];
  1013.  
  1014. V_old_array = new double* [Node_count];
  1015. for (int i = 0; i < Node_count; i++)
  1016. V_old_array[i] = new double[Max_delay];
  1017.  
  1018. FILE* fp0;
  1019. FILE* fp_I_stim;
  1020. FILE* fp_Ca;
  1021. FILE* fp_IP3;
  1022. //FILE *fp_z;
  1023. //FILE* fp_G_P;
  1024. FILE* fp_V;
  1025. FILE* fp_V_P;
  1026. //FILE *fp_m;
  1027. //FILE *fp_n;
  1028. //FILE *fp_h;
  1029. FILE* fp_V_spikes;
  1030. FILE* fp_Esyn;
  1031. FILE* fp_Esyn_P;
  1032.  
  1033. //FILE* fp_res;
  1034. srand(time(NULL));
  1035.  
  1036. //for (int i = 0; i < Node_count; i++)
  1037. // V_old_length[i] = 0;
  1038.  
  1039. A_A = new double* [Node_count];
  1040. for (int i = 0; i < Node_count; i++)
  1041. A_A[i] = new double[Node_count];
  1042.  
  1043. B_A = new double* [Node_count];
  1044. for (int i = 0; i < Node_count; i++)
  1045. B_A[i] = new double[Node_count];
  1046.  
  1047. C_A = new double[Node_count];
  1048.  
  1049. A_N = new double* [Node_count];
  1050. for (int i = 0; i < Node_count; i++)
  1051. A_N[i] = new double[Node_count];
  1052.  
  1053. B_N = new double* [Node_count];
  1054. for (int i = 0; i < Node_count; i++)
  1055. B_N[i] = new double[Node_count];
  1056.  
  1057. C_N = new double[Node_count];
  1058.  
  1059. A_N_P = new double* [Node_count];
  1060. for (int i = 0; i < Node_count; i++)
  1061. A_N_P[i] = new double[Node_count];
  1062.  
  1063. B_N_P = new double* [Node_count];
  1064. for (int i = 0; i < Node_count; i++)
  1065. B_N_P[i] = new double[Node_count];
  1066.  
  1067. C_N_P = new double[Node_count];
  1068.  
  1069. FillAMatrixZero();
  1070. FillAstrociteMatrix();
  1071. FillNeuronMatrix();
  1072. RandomizeNeuronMatrix();
  1073. FillNeuronPoissonMatrix();
  1074. FillBCMatrix_A();
  1075. FillBCMatrix_N();
  1076. FillBCMatrix_N_P();
  1077. //FillTauMatrix();
  1078.  
  1079. fp0 = fopen("A_A.txt", "w+");
  1080. for (int i = 0; i < Node_count; i++)
  1081. {
  1082. for (int j = 0; j < Node_count; j++)
  1083. {
  1084. fprintf(fp0, "%d\t", (int)A_A[i][j]);
  1085. }
  1086. fprintf(fp0, "\n");
  1087. }
  1088. fclose(fp0);
  1089.  
  1090. fp0 = fopen("A_N.txt", "w+");
  1091. for (int i = 0; i < Node_count; i++)
  1092. {
  1093. for (int j = 0; j < Node_count; j++)
  1094. {
  1095. fprintf(fp0, "%d\t", (int)A_N[i][j]);
  1096. }
  1097. fprintf(fp0, "\n");
  1098. }
  1099. fclose(fp0);
  1100.  
  1101. fp0 = fopen("tau.txt", "w+");
  1102. for (int i = 0; i < Node_count; i++)
  1103. {
  1104. for (int j = 0; j < Node_count; j++)
  1105. {
  1106. fprintf(fp0, "%f\t", tau[i][j] / ms_to_step);
  1107. }
  1108. fprintf(fp0, "\n");
  1109. }
  1110. fclose(fp0);
  1111.  
  1112. // Write to file number of links for each neuron
  1113. fp0 = fopen("links.txt", "w+");
  1114. for (int i = 0; i < Node_count; i++)
  1115. {
  1116. int links_count = 0;
  1117. for (int j = 0; j < Node_count; j++)
  1118. {
  1119. if (A_N[i][j] == 1)
  1120. {
  1121. links_count++;
  1122. }
  1123. }
  1124. fprintf(fp0, "%d\n", (int)links_count);
  1125. }
  1126. fclose(fp0);
  1127.  
  1128. //setlocale(LC_NUMERIC, "French_Canada.1252");
  1129. fp0 = fopen("test_Poisson.txt", "w+");
  1130. for (int i = 0; i < 1000; i++)
  1131. fprintf(fp0, "%f\n", nextTime(Poisson_Freq));
  1132. fclose(fp0);
  1133.  
  1134. fp0 = fopen("B_A.txt", "w+");
  1135. for (int i = 0; i < Node_count; i++)
  1136. {
  1137. for (int j = 0; j < C_A[i]; j++)
  1138. {
  1139. fprintf(fp0, "%d\t", (int)B_A[i][j]);
  1140. }
  1141. fprintf(fp0, "\n");
  1142. }
  1143. fclose(fp0);
  1144.  
  1145. fp0 = fopen("B_N.txt", "w+");
  1146. for (int i = 0; i < Node_count; i++)
  1147. {
  1148. for (int j = 0; j < C_N[i]; j++)
  1149. {
  1150. fprintf(fp0, "%d\t", (int)B_N[i][j]);
  1151. }
  1152. fprintf(fp0, "\n");
  1153. }
  1154. fclose(fp0);
  1155.  
  1156. fp0 = fopen("C_A.txt", "w+");
  1157. for (int i = 0; i < Node_count; i++)
  1158. {
  1159. fprintf(fp0, "%d\n", (int)C_A[i]);
  1160. }
  1161. fclose(fp0);
  1162.  
  1163. fp0 = fopen("C_N.txt", "w+");
  1164. for (int i = 0; i < Node_count; i++)
  1165. {
  1166. fprintf(fp0, "%d\n", (int)C_N[i]);
  1167. }
  1168. fclose(fp0);
  1169.  
  1170. /*for (int i = 0; i < 6; i++)
  1171. {
  1172. v_4[i] = 0.6;
  1173. }*/
  1174. for (int i = 0; i < Node_count; i++)
  1175. {
  1176. v_4[i] = 0.4; // 0.4
  1177. }
  1178.  
  1179. // Initial values
  1180. /*for (int i = 0; i < Equations_count; i++)
  1181. {
  1182. f[i] = 0;
  1183. }*/
  1184.  
  1185. //I_app_min = 1.1;
  1186. //I_app_max = 1.5;
  1187.  
  1188. FILE* fp_I_app;
  1189. fp_I_app = fopen("I_app.txt", "w");
  1190. for (int i = 0; i < Node_count; i++)
  1191. {
  1192. I_app[i] = 0.7; //RandomD(I_app_min, I_app_max);
  1193. fprintf(fp_I_app, "%f\n", I_app[i]);
  1194. }
  1195. fclose(fp_I_app);
  1196.  
  1197. FILE* fp_I_app_P;
  1198. fp_I_app_P = fopen("I_app_P.txt", "w");
  1199. for (int i = 0; i < Node_count; i++)
  1200. {
  1201. I_app_P[i] = 0.7;
  1202. fprintf(fp_I_app_P, "%f\n", I_app_P[i]);
  1203. }
  1204. fclose(fp_I_app_P);
  1205.  
  1206. for (int i = 0; i < Node_count; i++) // init array for all nodes
  1207. {
  1208. SetG_P(i, 0); // G_P
  1209. }
  1210.  
  1211. double percent_stable_state = 0.50; // 0.40
  1212. double eps_persent = 0.05; //0.05
  1213.  
  1214. double Ca0 = 0.07;
  1215. double IP30 = 0.16;
  1216. double z0 = 0.67;
  1217.  
  1218. for (int i = 0; i < Node_count; i++)
  1219. {
  1220. /*SetCa(i, Ca0 + RandomD(-Ca0 * eps_persent, Ca0 * eps_persent)); // Ca
  1221. SetIP3(i, IP30 + RandomD(-IP30 * eps_persent, IP30 * eps_persent)); // IP3
  1222. Setz(i, z0 + RandomD(-z0 * eps_persent, z0 * eps_persent)); // z */
  1223. SetCa(i, Ca0); // Ca
  1224. SetIP3(i, IP30); // IP3
  1225. Setz(i, z0); // z
  1226. }
  1227.  
  1228. double V0 = -58.7085;
  1229. double m0 = 0.0953;
  1230. double n0 = 0.000913;
  1231. double h0 = 0.3662;
  1232.  
  1233. double V1 = 14.8409;
  1234. double m1 = 0.9174;
  1235. double n1 = 0.0140;
  1236. double h1 = 0.0539;
  1237.  
  1238. /*for (int i = 0; i < Node_count; i++) // init only for neurons
  1239. {
  1240. double random = RandomD(0, 1);
  1241.  
  1242. SetV(i, random < percent_stable_state ? V0 + RandomD(-V0 * eps_persent, V0 * eps_persent) : V1 + RandomD(-V1 * eps_persent, V1 * eps_persent)); // V
  1243. Setm(i, random < percent_stable_state ? m0 + RandomD(-m0 * eps_persent, m0 * eps_persent) : m1 + RandomD(-m1 * eps_persent, m1 * eps_persent)); // m
  1244. Setn(i, random < percent_stable_state ? n0 + RandomD(-n0 * eps_persent, n0 * eps_persent) : n1 + RandomD(-n1 * eps_persent, n1 * eps_persent)); // n
  1245. Seth(i, random < percent_stable_state ? h0 + RandomD(-h0 * eps_persent, h0 * eps_persent) : h1 + RandomD(-h1 * eps_persent, h1 * eps_persent)); // h
  1246. }*/
  1247.  
  1248. for (int i = 0; i < Node_count; i++) // init only for neurons
  1249. {
  1250. double random = RandomD(0, 1);
  1251.  
  1252. /*SetV(i, random < percent_stable_state ? V0 : V1); // V
  1253. Setm(i, random < percent_stable_state ? m0 : m1); // m
  1254. Setn(i, random < percent_stable_state ? n0 : n1); // n
  1255. Seth(i, random < percent_stable_state ? h0 : h1); // h*/
  1256.  
  1257. SetV(i, V0); // V
  1258. Setm(i, m0); // m
  1259. Setn(i, n0); // n
  1260. Seth(i, h0); // h
  1261.  
  1262. /*SetV_P(i, random < percent_stable_state ? V0 : V1); // V
  1263. Setm_P(i, random < percent_stable_state ? m0 : m1); // m
  1264. Setn_P(i, random < percent_stable_state ? n0 : n1); // n
  1265. Seth_P(i, random < percent_stable_state ? h0 : h1); // h*/
  1266.  
  1267. SetV_P(i, V0); // V
  1268. Setm_P(i, m0); // m
  1269. Setn_P(i, n0); // n
  1270. Seth_P(i, h0); // h
  1271. }
  1272.  
  1273. /*for (int i = 0; i < Node_count; i++) // init only for neurons
  1274. {*/
  1275. /*SetV(i, RandomD(-80, 20)); // V
  1276. Setm(i, RandomD(0, 1)); // m
  1277. Setn(i, RandomD(0, 1)); // n
  1278. Seth(i, RandomD(0, 1)); // h*/
  1279. /*SetV(i, V1); // V
  1280. Setm(i, m1); // m
  1281. Setn(i, n1); // n
  1282. Seth(i, h1); // h
  1283. }*/
  1284.  
  1285. double E_syn0 = 0; // Excitatory neuron
  1286. double E_syn1 = -90; // Inhibitory neuron
  1287.  
  1288. fp_Esyn = fopen("results_E_syn.txt", "w+");
  1289. for (int i = 0; i < Node_count; i++)
  1290. {
  1291. /*E_syn[i] = E_syn0;
  1292.  
  1293. double x = RandomD(0, 1);
  1294.  
  1295. if (x > p_inhib)
  1296. {
  1297. fprintf(fp_Esyn, "%f\n", E_syn[i]);
  1298. continue;
  1299. }*/
  1300.  
  1301. E_syn[i] = E_syn1;
  1302.  
  1303. fprintf(fp_Esyn, "%f\n", E_syn[i]);
  1304.  
  1305. E_syn_P[i] = E_syn0;
  1306. }
  1307. fclose(fp_Esyn);
  1308.  
  1309. for (int i = 0; i < Node_count; i++)
  1310. {
  1311. GenerateRandomMeander(i, 0);
  1312. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  1313. }
  1314.  
  1315. const double t_start = 0;
  1316. const double t_max = 4; // 100 msec = 0.1 sec // 240 // 270
  1317. const double dt = 0.00005; // 0.01 msec = 0.00001 sec; 0.1 msec = 0.0001 sec; 1 msec = 0.001 sec // 0.000025
  1318.  
  1319. double t = t_start;
  1320.  
  1321. //fp_res = fopen("matlab_res.txt", "a+");
  1322. //fprintf(fp_res, "%f\t%f\t", Max_magintude, g_syn);
  1323.  
  1324. //fp0 = fopen("results.txt", "w+");
  1325. //setlocale(LC_NUMERIC, "French_Canada.1252");
  1326.  
  1327. //double start_rk4, end_rk4;
  1328. clock_t start_rk4, end_rk4;
  1329. //start_rk4 = omp_get_wtime();
  1330. start_rk4 = clock();
  1331. int lastPercent = -1;
  1332.  
  1333. //FillVOldFromCurrent();
  1334.  
  1335. k = new double* [Equations_count];
  1336. for (int i = 0; i < Equations_count; i++)
  1337. k[i] = new double[4];
  1338.  
  1339. phi_k1 = new double[Equations_count];
  1340. phi_k2 = new double[Equations_count];
  1341. phi_k3 = new double[Equations_count];
  1342.  
  1343. fp_I_stim = fopen("results_I_stim.txt", "w+");
  1344. //fp_I_syn = fopen("results_I_syn.txt", "w+");
  1345. fp_Ca = fopen("results_Ca.txt", "w+");
  1346. //fp_IP3 = fopen("results_IP3.txt", "w+");
  1347. //fp_z = fopen("results_z.txt", "w+");
  1348. //fp_G_P = fopen("results_G_P.txt", "w+");
  1349. fp_V = fopen("results_V.txt", "w+");
  1350. fp_V_P = fopen("results_V_P.txt", "w+");
  1351. //fp_m = fopen("results_m.txt", "w+");
  1352. //fp_n = fopen("results_n.txt", "w+");
  1353. //fp_h = fopen("results_h.txt", "w+");
  1354. fp_V_spikes = fopen("results_V_spikes.txt", "w+");
  1355. //
  1356.  
  1357. double* f_next = new double[Equations_count];
  1358.  
  1359. while (t < t_max || Approximately(t, t_max))
  1360. {
  1361. fprintf(fp_I_stim, "%f\t", t);
  1362. fprintf(fp_Ca, "%f\t", t);
  1363. //fprintf(fp_IP3, "%f\t", t);
  1364. //fprintf(fp_z, "%f\t", t);
  1365. //fprintf(fp_G, "%f\t", t);
  1366. fprintf(fp_V, "%f\t", t);
  1367. fprintf(fp_V_P, "%f\t", t);
  1368. //fprintf(fp_m, "%f\t", t);
  1369. //fprintf(fp_n, "%f\t", t);
  1370. //fprintf(fp_h, "%f\t", t);
  1371. fprintf(fp_V_spikes, "%f\t", t);
  1372.  
  1373. for (int i = 0; i < Node_count; i++)
  1374. {
  1375. if (t > last_meander_end[i])
  1376. {
  1377. GenerateRandomMeander(i, t);
  1378. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  1379. }
  1380.  
  1381. fprintf(fp_I_stim, "%f\t", I_stim(i, t));
  1382. }
  1383. fprintf(fp_I_stim, "\n");
  1384.  
  1385. for (int i = 0; i < Equations_count; i += Equations_per_node)
  1386. fprintf(fp_Ca, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // Ca
  1387.  
  1388. //for (int i = 1; i < Equations_count; i += Equations_per_node)
  1389. // fprintf(fp_IP3, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // IP3
  1390.  
  1391. //for (int i = 2; i < Equations_count; i += Equations_per_node)
  1392. // fprintf(fp_z, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // z
  1393.  
  1394. //for (int i = 3; i < Equations_count; i += Equations_per_node)
  1395. // fprintf(fp_G_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // G
  1396.  
  1397. for (int i = 4; i < Equations_count; i += Equations_per_node)
  1398. fprintf(fp_V, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V
  1399.  
  1400. //for (int i = 5; i < Equations_count; i += Equations_per_node)
  1401. // fprintf(fp_m, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m
  1402.  
  1403. //for (int i = 6; i < Equations_count; i += Equations_per_node)
  1404. // fprintf(fp_n, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n
  1405.  
  1406. //for (int i = 7; i < Equations_count; i += Equations_per_node)
  1407. // fprintf(fp_h, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h
  1408.  
  1409. for (int i = 8; i < Equations_count; i += Equations_per_node)
  1410. fprintf(fp_V_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V_P
  1411.  
  1412. //for (int i = 9; i < Equations_count; i += Equations_per_node)
  1413. // fprintf(fp_m_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m_P
  1414.  
  1415. //for (int i = 10; i < Equations_count; i += Equations_per_node)
  1416. // fprintf(fp_n_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n_P
  1417.  
  1418. //for (int i = 11; i < Equations_count; i += Equations_per_node)
  1419. // fprintf(fp_h_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h_P
  1420.  
  1421. fprintf(fp_Ca, "\n");
  1422. //fprintf(fp_IP3, "\n");
  1423. //fprintf(fp_z, "\n");
  1424. //fprintf(fp_G, "\n");
  1425. fprintf(fp_V, "\n");
  1426. //fprintf(fp_m, "\n");
  1427. //fprintf(fp_n, "\n");
  1428. //fprintf(fp_h, "\n");
  1429.  
  1430. //fprintf(fp_G_P, "\n");
  1431. fprintf(fp_V_P, "\n");
  1432. //fprintf(fp_m_P, "\n");
  1433. //fprintf(fp_n_P, "\n");
  1434. //fprintf(fp_h_P, "\n");
  1435.  
  1436. RungeKutta(t, dt, f, f_next);
  1437.  
  1438. #pragma omp parallel for
  1439. for (int i = 0; i < Node_count; i++)
  1440. {
  1441. int index = Equations_per_node * i + 4;
  1442. double diff = f_next[index] - f[index];
  1443.  
  1444. fprintf(fp_V_spikes, i == Equations_count - 1 ? "%d" : "%d\t", diff < 0 && f_diff[index] > 0 && f[index] > -10 && (V_spikes[i].size() == 0 || t - V_spikes[i].back() > 0.001) ? 1 : 0);
  1445.  
  1446. if (diff < 0 && f_diff[index] > 0 && f[index] > -10 && (V_spikes[i].size() == 0 || t - V_spikes[i].back() > 0.001))
  1447. {
  1448. V_spikes[i].push_back(t);
  1449. }
  1450.  
  1451. f_diff[index] = diff;
  1452. }
  1453.  
  1454. fprintf(fp_V_spikes, "\n");
  1455.  
  1456. CopyArray(f_next, f, Equations_count);
  1457.  
  1458. t += dt;
  1459.  
  1460. int percent = (int)(100 * (t - t_start) / (t_max - t_start));
  1461. if (percent != lastPercent)
  1462. {
  1463. printf("Progress: %d%%\n", percent);
  1464. lastPercent = percent;
  1465. }
  1466.  
  1467. //printf("V(24) = %f\t V_old(24) = %f\n", f[24*4], V_old(24));
  1468. //UpdateVOld();
  1469.  
  1470. //fprintf(fp_I_syn, "\n");
  1471. }
  1472.  
  1473. delete[] f_next;
  1474.  
  1475. double* V_mean_freqs = new double[Node_count];
  1476. double* V_STD_freqs = new double[Node_count];
  1477. //list<double> V_mean_freqs;
  1478.  
  1479. #pragma omp parallel for
  1480. for (int i = 0; i < Node_count; i++)
  1481. {
  1482. list<double>::iterator it_V_spikes = V_spikes[i].begin();
  1483.  
  1484. while (it_V_spikes != V_spikes[i].end() && *it_V_spikes < 0.25 * t_max)
  1485. {
  1486. V_spikes[i].pop_front();
  1487. it_V_spikes = V_spikes[i].begin();
  1488. }
  1489.  
  1490. list<double> V_freqs;
  1491.  
  1492. it_V_spikes = V_spikes[i].begin();
  1493.  
  1494. V_mean_freqs[i] = 0;
  1495. V_STD_freqs[i] = 0;
  1496.  
  1497. if (V_spikes[i].size() <= 1)
  1498. {
  1499. continue;
  1500. }
  1501. else
  1502. {
  1503. for (int j = 1; j < V_spikes[i].size(); j++)
  1504. {
  1505. double first = *it_V_spikes;
  1506. advance(it_V_spikes, 1);
  1507. double next = *it_V_spikes;
  1508.  
  1509. double T = next - first;
  1510. V_freqs.push_back(1 / T);
  1511. }
  1512. }
  1513.  
  1514. list<double>::iterator it_Freq = V_freqs.begin();
  1515.  
  1516. for (int j = 0; j < V_freqs.size(); j++)
  1517. {
  1518. V_mean_freqs[i] += *it_Freq;
  1519. advance(it_Freq, 1);
  1520. }
  1521.  
  1522. V_mean_freqs[i] /= V_freqs.size();
  1523.  
  1524. it_Freq = V_freqs.begin();
  1525.  
  1526. for (int j = 0; j < V_freqs.size(); j++)
  1527. {
  1528. V_STD_freqs[i] += pow(*it_Freq - V_mean_freqs[i], 2);
  1529. advance(it_Freq, 1);
  1530. }
  1531.  
  1532. V_STD_freqs[i] /= V_freqs.size();
  1533. V_STD_freqs[i] = sqrt(V_STD_freqs[i]);
  1534. }
  1535.  
  1536. fp0 = fopen("V_STD_freqs.txt", "w+");
  1537. for (int i = 0; i < Node_count; i++)
  1538. {
  1539. fprintf(fp0, "%f\t", V_STD_freqs[i]);
  1540. }
  1541. fclose(fp0);
  1542.  
  1543. double V_STD_mean_Freq = 0;
  1544. double V_STD_mean_Freq_not_zero = 0;
  1545. double V_STD_mean_Freq_not_zero_count = 0;
  1546.  
  1547. for (int j = 0; j < Node_count; j++)
  1548. {
  1549. if (V_STD_freqs[j] != 0)
  1550. {
  1551. V_STD_mean_Freq_not_zero_count++;
  1552. V_STD_mean_Freq += V_STD_freqs[j];
  1553. }
  1554. }
  1555.  
  1556. V_STD_mean_Freq_not_zero = V_STD_mean_Freq / V_STD_mean_Freq_not_zero_count;
  1557. V_STD_mean_Freq /= Node_count;
  1558.  
  1559. fp0 = fopen("V_STD_mean_Freq.txt", "w+");
  1560. fprintf(fp0, "%f\n", V_STD_mean_Freq);
  1561. //fprintf(fp_res, "%f\t", V_STD_mean_Freq);
  1562. fclose(fp0);
  1563.  
  1564. fp0 = fopen("V_STD_mean_Freq_not_zero.txt", "w+");
  1565. fprintf(fp0, "%f\n", V_STD_mean_Freq_not_zero);
  1566. //fprintf(fp_res, "%f\t", V_STD_mean_Freq_not_zero);
  1567. fclose(fp0);
  1568.  
  1569. double V_mean_mean_Freq = 0;
  1570. double V_mean_mean_Freq_not_zero = 0;
  1571. double V_mean_mean_Freq_not_zero_count = 0;
  1572.  
  1573. for (int j = 0; j < Node_count; j++)
  1574. {
  1575. if (V_mean_freqs[j] != 0)
  1576. {
  1577. V_mean_mean_Freq_not_zero_count++;
  1578. V_mean_mean_Freq += V_mean_freqs[j];
  1579. }
  1580. }
  1581.  
  1582. delete[] V_mean_freqs;
  1583. delete[] V_STD_freqs;
  1584.  
  1585. V_mean_mean_Freq_not_zero = V_mean_mean_Freq / V_mean_mean_Freq_not_zero_count;
  1586. V_mean_mean_Freq /= Node_count;
  1587.  
  1588. fp0 = fopen("V_mean_mean_Freq.txt", "w+");
  1589. fprintf(fp0, "%f\n", V_mean_mean_Freq);
  1590. fclose(fp0);
  1591.  
  1592. fp0 = fopen("V_mean_mean_Freq_not_zero.txt", "w+");
  1593. fprintf(fp0, "%f\n", V_mean_mean_Freq_not_zero);
  1594. fclose(fp0);
  1595.  
  1596. // CHUNKS
  1597. double chunk_t_start = 0.25 * t_max;
  1598. double chunk_t_step = 0.5;
  1599. int chunk_step_count = (0.75 * t_max / chunk_t_step);
  1600.  
  1601. double dt_chunk = 0.1 / V_mean_mean_Freq_not_zero; // 0.25
  1602. int chunks_count = chunk_t_step / dt_chunk;
  1603.  
  1604. double corr_aver_mean = 0, corr_aver_mean_not_zero = 0;
  1605.  
  1606. FILE* fp_corr_not_zero = fopen("corr_not_zero.txt", "w+");
  1607. FILE* fp_V_spikes_chunks = fopen("V_spikes_chunks.txt", "w+");
  1608.  
  1609. for (int s = 0; s < chunk_step_count; s++)
  1610. {
  1611. int** V_spikes_chunks = new int* [Node_count];
  1612.  
  1613. //#pragma omp parallel for
  1614. for (int i = 0; i < Node_count; i++)
  1615. {
  1616. V_spikes_chunks[i] = new int[chunks_count];
  1617.  
  1618. if (V_spikes[i].size() == 0)
  1619. for (int ch = 0; ch < chunks_count; ch++)
  1620. V_spikes_chunks[i][ch] = 0;
  1621.  
  1622. double ch_start = chunk_t_start + chunk_t_step * s;
  1623. double ch_end = ch_start + dt_chunk;
  1624. list<double>::iterator currentSpike = V_spikes[i].begin();
  1625.  
  1626. for (int ch = 0; ch < chunks_count; ch++)
  1627. {
  1628. while (currentSpike != V_spikes[i].end() && *currentSpike < ch_start)
  1629. currentSpike++;
  1630.  
  1631. if (currentSpike == V_spikes[i].end())
  1632. V_spikes_chunks[i][ch] = 0;
  1633. else
  1634. V_spikes_chunks[i][ch] = *currentSpike >= ch_start && *currentSpike <= ch_end;
  1635.  
  1636. ch_start += dt_chunk;
  1637. ch_end += dt_chunk;
  1638. }
  1639. }
  1640.  
  1641. char buffer[50];
  1642. //sprintf(buffer, "V_spikes_chunks_%d.txt", s);
  1643. //fp0 = fopen(buffer, "w+");
  1644.  
  1645. for (int ch = 0; ch < chunks_count; ch++)
  1646. {
  1647. for (int i = 0; i < Node_count; i++)
  1648. fprintf(fp_V_spikes_chunks, "%d\t", V_spikes_chunks[i][ch]);
  1649.  
  1650. fprintf(fp_V_spikes_chunks, "\n");
  1651. }
  1652.  
  1653. //fclose(fp0);
  1654.  
  1655. double corr = 0;
  1656. double corr_not_zero = 0;
  1657. double counter = 0;
  1658. double counter_not_zero = 0;
  1659.  
  1660. for (int i = 0; i < Node_count; i++)
  1661. {
  1662. for (int j = 0; j < Node_count; j++)
  1663. {
  1664. if (i == j)
  1665. continue;
  1666.  
  1667. int k1 = 0;
  1668. int k2 = 0;
  1669. int k3 = 0;
  1670.  
  1671. for (int l = 0; l < chunks_count; l++)
  1672. {
  1673. if (V_spikes_chunks[i][l] == 1 && V_spikes_chunks[j][l] == 1)
  1674. k1++;
  1675.  
  1676. k2 += V_spikes_chunks[i][l];
  1677. k3 += V_spikes_chunks[j][l];
  1678. }
  1679.  
  1680. if (k2 != 0 && k3 != 0)
  1681. {
  1682. corr += (double)k1 / sqrt((double)k2 * (double)k3);
  1683. counter_not_zero++;
  1684. }
  1685.  
  1686. counter++;
  1687. }
  1688. }
  1689.  
  1690. double corr_aver = corr / counter;
  1691. double corr_aver_not_zero = corr / counter_not_zero;
  1692.  
  1693. corr_aver_mean += corr_aver;
  1694. corr_aver_mean_not_zero += corr_aver_not_zero;
  1695.  
  1696. //sprintf(buffer, "corr_aver_%d.txt", s);
  1697.  
  1698. //fp0 = fopen(buffer, "w+");
  1699. //fprintf(fp0, "%f\n", corr_aver);
  1700. //fclose(fp0);
  1701.  
  1702. double ch_start = chunk_t_start + chunk_t_step * s;
  1703. fprintf(fp_corr_not_zero, "%f\t%f\n", ch_start, corr_aver_not_zero);
  1704.  
  1705. for (int i = 0; i < Node_count; i++)
  1706. delete[] V_spikes_chunks[i];
  1707.  
  1708. delete[] V_spikes_chunks;
  1709. }
  1710.  
  1711. fclose(fp_corr_not_zero);
  1712. fclose(fp_V_spikes_chunks);
  1713.  
  1714. corr_aver_mean /= chunk_step_count;
  1715. corr_aver_mean_not_zero /= chunk_step_count;
  1716.  
  1717. //fp0 = fopen("corr_aver_mean.txt", "w+");
  1718. //fprintf(fp0, "%f\n", corr_aver_mean);
  1719. //fclose(fp0);
  1720.  
  1721. //fp0 = fopen("corr_aver_mean_not_zero.txt", "w+");
  1722. //fprintf(fp0, "%f\n", corr_aver_mean_not_zero);
  1723. //fclose(fp0);
  1724. ////// CHUNKS END
  1725.  
  1726. //2
  1727. double* V_freq_sync_time = new double[Node_count];
  1728. double* V_freq_sync_time_relative = new double[Node_count];
  1729.  
  1730. #pragma omp parallel for
  1731. for (int i = 0; i < Node_count; i++)
  1732. {
  1733. list<double>::iterator it_V_spikes = V_spikes[i].begin();
  1734.  
  1735. while (it_V_spikes != V_spikes[i].end() && *it_V_spikes < 0.25 * t_max)
  1736. {
  1737. V_spikes[i].pop_front();
  1738. it_V_spikes = V_spikes[i].begin();
  1739. }
  1740.  
  1741. list<double> V_freqs_normalized;
  1742. list<double> V_freqs_time;
  1743.  
  1744. it_V_spikes = V_spikes[i].begin();
  1745.  
  1746. if (V_spikes[i].size() <= 1)
  1747. {
  1748. continue;
  1749. }
  1750. else
  1751. {
  1752. for (int j = 1; j < V_spikes[i].size(); j++)
  1753. {
  1754. double first = *it_V_spikes;
  1755. advance(it_V_spikes, 1);
  1756. double next = *it_V_spikes;
  1757.  
  1758. double T = next - first;
  1759. V_freqs_normalized.push_back(1 / T - V_mean_mean_Freq);
  1760. V_freqs_time.push_back(next);
  1761. }
  1762. }
  1763.  
  1764. list<double>::iterator it_Freq_normalized = V_freqs_normalized.begin();
  1765. list<double>::iterator it_Freq_time = V_freqs_time.begin();
  1766.  
  1767. V_freq_sync_time[i] = 0;
  1768.  
  1769. for (int j = 1; j < V_freqs_normalized.size(); j++)
  1770. {
  1771. double Freq_normalized_last = *it_Freq_normalized;
  1772. advance(it_Freq_normalized, 1);
  1773. double Freq_normalized_next = *it_Freq_normalized;
  1774.  
  1775. double Freq_time_last = *it_Freq_time;
  1776. advance(it_Freq_time, 1);
  1777. double Freq_time_next = *it_Freq_time;
  1778.  
  1779. if (abs(Freq_normalized_last) <= 0.5 && abs(Freq_normalized_next) <= 0.5 && (Freq_time_next - Freq_time_last) <= 0.035)
  1780. V_freq_sync_time[i] += Freq_time_next - Freq_time_last;
  1781. }
  1782.  
  1783. V_freq_sync_time_relative[i] = V_freq_sync_time[i] / (t_max - (0.25 * t_max));
  1784. }
  1785.  
  1786. double V_mean_freq_sync_time_relative = 0;
  1787.  
  1788. for (int j = 0; j < Node_count; j++)
  1789. {
  1790. V_mean_freq_sync_time_relative += V_freq_sync_time_relative[j];
  1791. }
  1792.  
  1793. V_mean_freq_sync_time_relative /= Node_count;
  1794.  
  1795. fp0 = fopen("V_freq_sync_time_relative.txt", "w+");
  1796. for (int i = 0; i < Node_count; i++)
  1797. {
  1798. fprintf(fp0, "%f\t", V_freq_sync_time_relative[i]);
  1799. }
  1800. fclose(fp0);
  1801.  
  1802. fp0 = fopen("V_mean_freq_sync_time_relative.txt", "w+");
  1803. fprintf(fp0, "%f\n", V_mean_freq_sync_time_relative);
  1804. //fprintf(fp_res, "%f\n", V_mean_freq_sync_time_relative);
  1805. fclose(fp0);
  1806.  
  1807. //fclose(fp_res);
  1808. fclose(fp_Max_magnitude);
  1809. fclose(fp_I_stim);
  1810. ///fclose(fp_I_syn);
  1811. fclose(fp_Ca);
  1812. //fclose(fp_IP3);
  1813. //fclose(fp_z);
  1814. fclose(fp_V);
  1815. //fclose(fp_m);
  1816. //fclose(fp_n);
  1817. //fclose(fp_h);
  1818. //fclose(fp_G_P);
  1819. fclose(fp_V_P);
  1820. //fclose(fp_m_P);
  1821. //fclose(fp_n_P);
  1822. //fclose(fp_h_P);
  1823.  
  1824. fclose(fp_V_spikes);
  1825.  
  1826. //end_rk4 = omp_get_wtime();
  1827. end_rk4 = clock();
  1828. double extime_rk4 = (double)(end_rk4 - start_rk4);// / CLOCKS_PER_SEC;
  1829. int minutes = (int)extime_rk4 / 60;
  1830. int seconds = (int)extime_rk4 % 60;
  1831. printf("\nExecution time is: %d minutes %d seconds\n ", minutes, seconds);
  1832.  
  1833. /*int nth;
  1834. #pragma omp parallel
  1835. {
  1836. #pragma omp master
  1837. nth = omp_get_num_threads();
  1838. }*/
  1839.  
  1840. fp0 = fopen("time_exec.txt", "a");
  1841. //fprintf(fp0, "%d %lf\n", nth, extime_rk4);
  1842. fprintf(fp0, "%lf\n", extime_rk4);
  1843. fclose(fp0);
  1844.  
  1845. for (int i = 0; i < Node_count; i++)
  1846. delete[] A_A[i];
  1847.  
  1848. delete[] A_A;
  1849.  
  1850. for (int i = 0; i < Node_count; i++)
  1851. delete[] B_A[i];
  1852.  
  1853. delete[] B_A;
  1854.  
  1855. delete[] C_A;
  1856.  
  1857. for (int i = 0; i < Node_count; i++)
  1858. delete[] A_N[i];
  1859.  
  1860. delete[] A_N;
  1861.  
  1862. for (int i = 0; i < Node_count; i++)
  1863. delete[] B_N[i];
  1864.  
  1865. delete[] B_N;
  1866.  
  1867. delete[] C_N;
  1868.  
  1869. delete[] A_N_P;
  1870.  
  1871. for (int i = 0; i < Node_count; i++)
  1872. delete[] B_N_P[i];
  1873.  
  1874. delete[] B_N_P;
  1875.  
  1876. delete[] C_N_P;
  1877.  
  1878. delete[] f;
  1879. delete[] f_diff;
  1880. delete[] v_4;
  1881. delete[] E_syn;
  1882. delete[] I_app;
  1883. delete[] V_spikes;
  1884. delete[] V_spikes_Freq;
  1885.  
  1886. delete[] Meander_start_from_zero;
  1887. delete[] Meander_width;
  1888. delete[] Meander_height;
  1889. delete[] Meander_interval;
  1890. delete[] last_meander_end;
  1891. delete[] V_freq_sync_time;
  1892.  
  1893. for (int i = 0; i < Node_count; i++)
  1894. delete[] tau[i];
  1895.  
  1896. delete[] tau;
  1897.  
  1898. for (int i = 0; i < Node_count; i++)
  1899. delete[] V_old_array[i];
  1900.  
  1901. delete[] V_old_array;
  1902.  
  1903. for (int i = 0; i < Equations_count; i++)
  1904. delete[] k[i];
  1905.  
  1906. delete[] k;
  1907.  
  1908. delete[] phi_k1;
  1909. delete[] phi_k2;
  1910. delete[] phi_k3;
  1911. }
  1912.  
Add Comment
Please, Sign In to add comment