SpaceQuester

Untitled

Aug 6th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.57 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 200
  16.  
  17. #define Equations_per_node 12 // !!! 12 - Don't change !!!
  18. #define Equations_count Node_count * Equations_per_node
  19.  
  20. int MaxDeep = 50;
  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. double Poisson_Freq; // 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)) * (V(in) - E_syn[(int)B_N[in][j]]) / (1 + exp(-(V((int)B_N[in][j]) / k_syn))); // версия с V (без V_old)
  465. }
  466. else
  467. {
  468. I_syn += g_syn * (V(in) - E_syn[(int)B_N[in][j]]) / (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)) * (V_P(in) - E_syn_P[in]) / (1 + exp(-(V_P(in) / k_syn_P))); // версия с V (без V_old)
  496. }
  497. else
  498. {
  499. I_syn_P += g_syn_P * (V_P(in) - E_syn_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 (6) Poisson_Freq
  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", &Poisson_Freq);
  992. FILE* fp_Poisson_Freq;
  993. fp_Poisson_Freq = fopen("Poisson_Freq.txt", "w");
  994. fprintf(fp_Poisson_Freq, "%f\t", Poisson_Freq);
  995. fclose(fp_Poisson_Freq);
  996. printf("Poisson_Freq = %f\n", Poisson_Freq);
  997.  
  998. //sscanf(argv[6], "%lf", &I_app_min);
  999. //sscanf(argv[7], "%lf", &I_app_max);
  1000.  
  1001. f = new double[Equations_count];
  1002. f_diff = new double[Equations_count];
  1003. v_4 = new double[Node_count];
  1004. E_syn = new double[Node_count];
  1005. I_app = new double[Node_count];
  1006. E_syn_P = new double[Node_count];
  1007. I_app_P = new double[Node_count];
  1008. V_spikes = new list<double>[Node_count];
  1009. V_spikes_Freq = new list<double>[Node_count];
  1010.  
  1011. Meander_start_from_zero = new double[Node_count];
  1012. Meander_width = new double[Node_count];
  1013. Meander_height = new double[Node_count];
  1014. Meander_interval = new double[Node_count];
  1015. last_meander_end = new double[Node_count];
  1016.  
  1017. tau = new double* [Node_count];
  1018. for (int i = 0; i < Node_count; i++)
  1019. tau[i] = new double[Node_count];
  1020.  
  1021. V_old_array = new double* [Node_count];
  1022. for (int i = 0; i < Node_count; i++)
  1023. V_old_array[i] = new double[Max_delay];
  1024.  
  1025. FILE* fp0;
  1026. FILE* fp_I_stim;
  1027. FILE* fp_Ca;
  1028. FILE* fp_IP3;
  1029. //FILE *fp_z;
  1030. //FILE* fp_G_P;
  1031. FILE* fp_V;
  1032. FILE* fp_V_P;
  1033. //FILE *fp_m;
  1034. //FILE *fp_n;
  1035. //FILE *fp_h;
  1036. FILE* fp_V_spikes;
  1037. FILE* fp_Esyn;
  1038. FILE* fp_Esyn_P;
  1039.  
  1040. //FILE* fp_res;
  1041. srand(time(NULL));
  1042.  
  1043. //for (int i = 0; i < Node_count; i++)
  1044. // V_old_length[i] = 0;
  1045.  
  1046. A_A = new double* [Node_count];
  1047. for (int i = 0; i < Node_count; i++)
  1048. A_A[i] = new double[Node_count];
  1049.  
  1050. B_A = new double* [Node_count];
  1051. for (int i = 0; i < Node_count; i++)
  1052. B_A[i] = new double[Node_count];
  1053.  
  1054. C_A = new double[Node_count];
  1055.  
  1056. A_N = new double* [Node_count];
  1057. for (int i = 0; i < Node_count; i++)
  1058. A_N[i] = new double[Node_count];
  1059.  
  1060. B_N = new double* [Node_count];
  1061. for (int i = 0; i < Node_count; i++)
  1062. B_N[i] = new double[Node_count];
  1063.  
  1064. C_N = new double[Node_count];
  1065.  
  1066. A_N_P = new double* [Node_count];
  1067. for (int i = 0; i < Node_count; i++)
  1068. A_N_P[i] = new double[Node_count];
  1069.  
  1070. B_N_P = new double* [Node_count];
  1071. for (int i = 0; i < Node_count; i++)
  1072. B_N_P[i] = new double[Node_count];
  1073.  
  1074. C_N_P = new double[Node_count];
  1075.  
  1076. FillAMatrixZero();
  1077. FillAstrociteMatrix();
  1078. FillNeuronMatrix();
  1079. RandomizeNeuronMatrix();
  1080. FillNeuronPoissonMatrix();
  1081. FillBCMatrix_A();
  1082. FillBCMatrix_N();
  1083. FillBCMatrix_N_P();
  1084. //FillTauMatrix();
  1085.  
  1086. fp0 = fopen("A_A.txt", "w+");
  1087. for (int i = 0; i < Node_count; i++)
  1088. {
  1089. for (int j = 0; j < Node_count; j++)
  1090. {
  1091. fprintf(fp0, "%d\t", (int)A_A[i][j]);
  1092. }
  1093. fprintf(fp0, "\n");
  1094. }
  1095. fclose(fp0);
  1096.  
  1097. fp0 = fopen("A_N.txt", "w+");
  1098. for (int i = 0; i < Node_count; i++)
  1099. {
  1100. for (int j = 0; j < Node_count; j++)
  1101. {
  1102. fprintf(fp0, "%d\t", (int)A_N[i][j]);
  1103. }
  1104. fprintf(fp0, "\n");
  1105. }
  1106. fclose(fp0);
  1107.  
  1108. fp0 = fopen("tau.txt", "w+");
  1109. for (int i = 0; i < Node_count; i++)
  1110. {
  1111. for (int j = 0; j < Node_count; j++)
  1112. {
  1113. fprintf(fp0, "%f\t", tau[i][j] / ms_to_step);
  1114. }
  1115. fprintf(fp0, "\n");
  1116. }
  1117. fclose(fp0);
  1118.  
  1119. // Write to file number of links for each neuron
  1120. fp0 = fopen("links.txt", "w+");
  1121. for (int i = 0; i < Node_count; i++)
  1122. {
  1123. int links_count = 0;
  1124. for (int j = 0; j < Node_count; j++)
  1125. {
  1126. if (A_N[i][j] == 1)
  1127. {
  1128. links_count++;
  1129. }
  1130. }
  1131. fprintf(fp0, "%d\n", (int)links_count);
  1132. }
  1133. fclose(fp0);
  1134.  
  1135. //setlocale(LC_NUMERIC, "French_Canada.1252");
  1136. fp0 = fopen("test_Poisson.txt", "w+");
  1137. for (int i = 0; i < 1000; i++)
  1138. fprintf(fp0, "%f\n", nextTime(Poisson_Freq));
  1139. fclose(fp0);
  1140.  
  1141. fp0 = fopen("B_A.txt", "w+");
  1142. for (int i = 0; i < Node_count; i++)
  1143. {
  1144. for (int j = 0; j < C_A[i]; j++)
  1145. {
  1146. fprintf(fp0, "%d\t", (int)B_A[i][j]);
  1147. }
  1148. fprintf(fp0, "\n");
  1149. }
  1150. fclose(fp0);
  1151.  
  1152. fp0 = fopen("B_N.txt", "w+");
  1153. for (int i = 0; i < Node_count; i++)
  1154. {
  1155. for (int j = 0; j < C_N[i]; j++)
  1156. {
  1157. fprintf(fp0, "%d\t", (int)B_N[i][j]);
  1158. }
  1159. fprintf(fp0, "\n");
  1160. }
  1161. fclose(fp0);
  1162.  
  1163. fp0 = fopen("C_A.txt", "w+");
  1164. for (int i = 0; i < Node_count; i++)
  1165. {
  1166. fprintf(fp0, "%d\n", (int)C_A[i]);
  1167. }
  1168. fclose(fp0);
  1169.  
  1170. fp0 = fopen("C_N.txt", "w+");
  1171. for (int i = 0; i < Node_count; i++)
  1172. {
  1173. fprintf(fp0, "%d\n", (int)C_N[i]);
  1174. }
  1175. fclose(fp0);
  1176.  
  1177. /*for (int i = 0; i < 6; i++)
  1178. {
  1179. v_4[i] = 0.6;
  1180. }*/
  1181. for (int i = 0; i < Node_count; i++)
  1182. {
  1183. v_4[i] = 0.4; // 0.4
  1184. }
  1185.  
  1186. // Initial values
  1187. /*for (int i = 0; i < Equations_count; i++)
  1188. {
  1189. f[i] = 0;
  1190. }*/
  1191.  
  1192. //I_app_min = 1.1;
  1193. //I_app_max = 1.5;
  1194.  
  1195. FILE* fp_I_app;
  1196. fp_I_app = fopen("I_app.txt", "w");
  1197. for (int i = 0; i < Node_count; i++)
  1198. {
  1199. I_app[i] = 0.7; //RandomD(I_app_min, I_app_max);
  1200. fprintf(fp_I_app, "%f\n", I_app[i]);
  1201. }
  1202. fclose(fp_I_app);
  1203.  
  1204. FILE* fp_I_app_P;
  1205. fp_I_app_P = fopen("I_app_P.txt", "w");
  1206. for (int i = 0; i < Node_count; i++)
  1207. {
  1208. I_app_P[i] = 0.7;
  1209. fprintf(fp_I_app_P, "%f\n", I_app_P[i]);
  1210. }
  1211. fclose(fp_I_app_P);
  1212.  
  1213. for (int i = 0; i < Node_count; i++) // init array for all nodes
  1214. {
  1215. SetG_P(i, 0); // G_P
  1216. }
  1217.  
  1218. double percent_stable_state = 0.50; // 0.40
  1219. double eps_persent = 0.05; //0.05
  1220.  
  1221. double Ca0 = 0.07;
  1222. double IP30 = 0.16;
  1223. double z0 = 0.67;
  1224.  
  1225. for (int i = 0; i < Node_count; i++)
  1226. {
  1227. /*SetCa(i, Ca0 + RandomD(-Ca0 * eps_persent, Ca0 * eps_persent)); // Ca
  1228. SetIP3(i, IP30 + RandomD(-IP30 * eps_persent, IP30 * eps_persent)); // IP3
  1229. Setz(i, z0 + RandomD(-z0 * eps_persent, z0 * eps_persent)); // z */
  1230. SetCa(i, Ca0); // Ca
  1231. SetIP3(i, IP30); // IP3
  1232. Setz(i, z0); // z
  1233. }
  1234.  
  1235. double V0 = -58.7085;
  1236. double m0 = 0.0953;
  1237. double n0 = 0.000913;
  1238. double h0 = 0.3662;
  1239.  
  1240. double V1 = 14.8409;
  1241. double m1 = 0.9174;
  1242. double n1 = 0.0140;
  1243. double h1 = 0.0539;
  1244.  
  1245. /*for (int i = 0; i < Node_count; i++) // init only for neurons
  1246. {
  1247. double random = RandomD(0, 1);
  1248.  
  1249. SetV(i, random < percent_stable_state ? V0 + RandomD(-V0 * eps_persent, V0 * eps_persent) : V1 + RandomD(-V1 * eps_persent, V1 * eps_persent)); // V
  1250. Setm(i, random < percent_stable_state ? m0 + RandomD(-m0 * eps_persent, m0 * eps_persent) : m1 + RandomD(-m1 * eps_persent, m1 * eps_persent)); // m
  1251. Setn(i, random < percent_stable_state ? n0 + RandomD(-n0 * eps_persent, n0 * eps_persent) : n1 + RandomD(-n1 * eps_persent, n1 * eps_persent)); // n
  1252. Seth(i, random < percent_stable_state ? h0 + RandomD(-h0 * eps_persent, h0 * eps_persent) : h1 + RandomD(-h1 * eps_persent, h1 * eps_persent)); // h
  1253. }*/
  1254.  
  1255. for (int i = 0; i < Node_count; i++) // init only for neurons
  1256. {
  1257. double random = RandomD(0, 1);
  1258.  
  1259. /*SetV(i, random < percent_stable_state ? V0 : V1); // V
  1260. Setm(i, random < percent_stable_state ? m0 : m1); // m
  1261. Setn(i, random < percent_stable_state ? n0 : n1); // n
  1262. Seth(i, random < percent_stable_state ? h0 : h1); // h*/
  1263.  
  1264. SetV(i, V0); // V
  1265. Setm(i, m0); // m
  1266. Setn(i, n0); // n
  1267. Seth(i, h0); // h
  1268.  
  1269. /*SetV_P(i, random < percent_stable_state ? V0 : V1); // V
  1270. Setm_P(i, random < percent_stable_state ? m0 : m1); // m
  1271. Setn_P(i, random < percent_stable_state ? n0 : n1); // n
  1272. Seth_P(i, random < percent_stable_state ? h0 : h1); // h*/
  1273.  
  1274. SetV_P(i, V0); // V
  1275. Setm_P(i, m0); // m
  1276. Setn_P(i, n0); // n
  1277. Seth_P(i, h0); // h
  1278. }
  1279.  
  1280. /*for (int i = 0; i < Node_count; i++) // init only for neurons
  1281. {*/
  1282. /*SetV(i, RandomD(-80, 20)); // V
  1283. Setm(i, RandomD(0, 1)); // m
  1284. Setn(i, RandomD(0, 1)); // n
  1285. Seth(i, RandomD(0, 1)); // h*/
  1286. /*SetV(i, V1); // V
  1287. Setm(i, m1); // m
  1288. Setn(i, n1); // n
  1289. Seth(i, h1); // h
  1290. }*/
  1291.  
  1292. double E_syn0 = 0; // Excitatory neuron
  1293. double E_syn1 = -90; // Inhibitory neuron
  1294.  
  1295. fp_Esyn = fopen("results_E_syn.txt", "w+");
  1296. for (int i = 0; i < Node_count; i++)
  1297. {
  1298. /*E_syn[i] = E_syn0;
  1299.  
  1300. double x = RandomD(0, 1);
  1301.  
  1302. if (x > p_inhib)
  1303. {
  1304. fprintf(fp_Esyn, "%f\n", E_syn[i]);
  1305. continue;
  1306. }*/
  1307.  
  1308. E_syn[i] = E_syn1;
  1309.  
  1310. fprintf(fp_Esyn, "%f\n", E_syn[i]);
  1311.  
  1312. E_syn_P[i] = E_syn0;
  1313. }
  1314. fclose(fp_Esyn);
  1315.  
  1316. for (int i = 0; i < Node_count; i++)
  1317. {
  1318. GenerateRandomMeander(i, 0);
  1319. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  1320. }
  1321.  
  1322. const double t_start = 0;
  1323. const double t_max = 40; // 100 msec = 0.1 sec // 240 // 270
  1324. const double dt = 0.00002; // 0.01 msec = 0.00001 sec; 0.1 msec = 0.0001 sec; 1 msec = 0.001 sec // 0.000025
  1325.  
  1326. double t = t_start;
  1327.  
  1328. //fp_res = fopen("matlab_res.txt", "a+");
  1329. //fprintf(fp_res, "%f\t%f\t", Max_magintude, g_syn);
  1330.  
  1331. //fp0 = fopen("results.txt", "w+");
  1332. //setlocale(LC_NUMERIC, "French_Canada.1252");
  1333.  
  1334. //double start_rk4, end_rk4;
  1335. clock_t start_rk4, end_rk4;
  1336. //start_rk4 = omp_get_wtime();
  1337. start_rk4 = clock();
  1338. int lastPercent = -1;
  1339.  
  1340. //FillVOldFromCurrent();
  1341.  
  1342. k = new double* [Equations_count];
  1343. for (int i = 0; i < Equations_count; i++)
  1344. k[i] = new double[4];
  1345.  
  1346. phi_k1 = new double[Equations_count];
  1347. phi_k2 = new double[Equations_count];
  1348. phi_k3 = new double[Equations_count];
  1349.  
  1350. fp_I_stim = fopen("results_I_stim.txt", "w+");
  1351. //fp_I_syn = fopen("results_I_syn.txt", "w+");
  1352. fp_Ca = fopen("results_Ca.txt", "w+");
  1353. //fp_IP3 = fopen("results_IP3.txt", "w+");
  1354. //fp_z = fopen("results_z.txt", "w+");
  1355. //fp_G_P = fopen("results_G_P.txt", "w+");
  1356. fp_V = fopen("results_V.txt", "w+");
  1357. fp_V_P = fopen("results_V_P.txt", "w+");
  1358. //fp_m = fopen("results_m.txt", "w+");
  1359. //fp_n = fopen("results_n.txt", "w+");
  1360. //fp_h = fopen("results_h.txt", "w+");
  1361. fp_V_spikes = fopen("results_V_spikes.txt", "w+");
  1362. //
  1363.  
  1364. double* f_next = new double[Equations_count];
  1365.  
  1366. while (t < t_max || Approximately(t, t_max))
  1367. {
  1368. fprintf(fp_I_stim, "%f\t", t);
  1369. fprintf(fp_Ca, "%f\t", t);
  1370. //fprintf(fp_IP3, "%f\t", t);
  1371. //fprintf(fp_z, "%f\t", t);
  1372. //fprintf(fp_G, "%f\t", t);
  1373. fprintf(fp_V, "%f\t", t);
  1374. fprintf(fp_V_P, "%f\t", t);
  1375. //fprintf(fp_m, "%f\t", t);
  1376. //fprintf(fp_n, "%f\t", t);
  1377. //fprintf(fp_h, "%f\t", t);
  1378. fprintf(fp_V_spikes, "%f\t", t);
  1379.  
  1380. for (int i = 0; i < Node_count; i++)
  1381. {
  1382. if (t > last_meander_end[i])
  1383. {
  1384. GenerateRandomMeander(i, t);
  1385. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  1386. }
  1387.  
  1388. fprintf(fp_I_stim, "%f\t", I_stim(i, t));
  1389. }
  1390. fprintf(fp_I_stim, "\n");
  1391.  
  1392. for (int i = 0; i < Equations_count; i += Equations_per_node)
  1393. fprintf(fp_Ca, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // Ca
  1394.  
  1395. //for (int i = 1; i < Equations_count; i += Equations_per_node)
  1396. // fprintf(fp_IP3, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // IP3
  1397.  
  1398. //for (int i = 2; i < Equations_count; i += Equations_per_node)
  1399. // fprintf(fp_z, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // z
  1400.  
  1401. //for (int i = 3; i < Equations_count; i += Equations_per_node)
  1402. // fprintf(fp_G_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // G
  1403.  
  1404. for (int i = 4; i < Equations_count; i += Equations_per_node)
  1405. fprintf(fp_V, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V
  1406.  
  1407. //for (int i = 5; i < Equations_count; i += Equations_per_node)
  1408. // fprintf(fp_m, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m
  1409.  
  1410. //for (int i = 6; i < Equations_count; i += Equations_per_node)
  1411. // fprintf(fp_n, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n
  1412.  
  1413. //for (int i = 7; i < Equations_count; i += Equations_per_node)
  1414. // fprintf(fp_h, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h
  1415.  
  1416. for (int i = 8; i < Equations_count; i += Equations_per_node)
  1417. fprintf(fp_V_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V_P
  1418.  
  1419. //for (int i = 9; i < Equations_count; i += Equations_per_node)
  1420. // fprintf(fp_m_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m_P
  1421.  
  1422. //for (int i = 10; i < Equations_count; i += Equations_per_node)
  1423. // fprintf(fp_n_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n_P
  1424.  
  1425. //for (int i = 11; i < Equations_count; i += Equations_per_node)
  1426. // fprintf(fp_h_P, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h_P
  1427.  
  1428. fprintf(fp_Ca, "\n");
  1429. //fprintf(fp_IP3, "\n");
  1430. //fprintf(fp_z, "\n");
  1431. //fprintf(fp_G, "\n");
  1432. fprintf(fp_V, "\n");
  1433. //fprintf(fp_m, "\n");
  1434. //fprintf(fp_n, "\n");
  1435. //fprintf(fp_h, "\n");
  1436.  
  1437. //fprintf(fp_G_P, "\n");
  1438. fprintf(fp_V_P, "\n");
  1439. //fprintf(fp_m_P, "\n");
  1440. //fprintf(fp_n_P, "\n");
  1441. //fprintf(fp_h_P, "\n");
  1442.  
  1443. RungeKutta(t, dt, f, f_next);
  1444.  
  1445. #pragma omp parallel for
  1446. for (int i = 0; i < Node_count; i++)
  1447. {
  1448. int index = Equations_per_node * i + 4;
  1449. double diff = f_next[index] - f[index];
  1450.  
  1451. 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);
  1452.  
  1453. if (diff < 0 && f_diff[index] > 0 && f[index] > -10 && (V_spikes[i].size() == 0 || t - V_spikes[i].back() > 0.001))
  1454. {
  1455. V_spikes[i].push_back(t);
  1456. }
  1457.  
  1458. f_diff[index] = diff;
  1459. }
  1460.  
  1461. fprintf(fp_V_spikes, "\n");
  1462.  
  1463. CopyArray(f_next, f, Equations_count);
  1464.  
  1465. t += dt;
  1466.  
  1467. int percent = (int)(100 * (t - t_start) / (t_max - t_start));
  1468. if (percent != lastPercent)
  1469. {
  1470. printf("Progress: %d%%\n", percent);
  1471. lastPercent = percent;
  1472. }
  1473.  
  1474. //printf("V(24) = %f\t V_old(24) = %f\n", f[24*4], V_old(24));
  1475. //UpdateVOld();
  1476.  
  1477. //fprintf(fp_I_syn, "\n");
  1478. }
  1479.  
  1480. delete[] f_next;
  1481.  
  1482. double* V_mean_freqs = new double[Node_count];
  1483. double* V_STD_freqs = new double[Node_count];
  1484. //list<double> V_mean_freqs;
  1485.  
  1486. #pragma omp parallel for
  1487. for (int i = 0; i < Node_count; i++)
  1488. {
  1489. list<double>::iterator it_V_spikes = V_spikes[i].begin();
  1490.  
  1491. while (it_V_spikes != V_spikes[i].end() && *it_V_spikes < 0.25 * t_max)
  1492. {
  1493. V_spikes[i].pop_front();
  1494. it_V_spikes = V_spikes[i].begin();
  1495. }
  1496.  
  1497. list<double> V_freqs;
  1498.  
  1499. it_V_spikes = V_spikes[i].begin();
  1500.  
  1501. V_mean_freqs[i] = 0;
  1502. V_STD_freqs[i] = 0;
  1503.  
  1504. if (V_spikes[i].size() <= 1)
  1505. {
  1506. continue;
  1507. }
  1508. else
  1509. {
  1510. for (int j = 1; j < V_spikes[i].size(); j++)
  1511. {
  1512. double first = *it_V_spikes;
  1513. advance(it_V_spikes, 1);
  1514. double next = *it_V_spikes;
  1515.  
  1516. double T = next - first;
  1517. V_freqs.push_back(1 / T);
  1518. }
  1519. }
  1520.  
  1521. list<double>::iterator it_Freq = V_freqs.begin();
  1522.  
  1523. for (int j = 0; j < V_freqs.size(); j++)
  1524. {
  1525. V_mean_freqs[i] += *it_Freq;
  1526. advance(it_Freq, 1);
  1527. }
  1528.  
  1529. V_mean_freqs[i] /= V_freqs.size();
  1530.  
  1531. it_Freq = V_freqs.begin();
  1532.  
  1533. for (int j = 0; j < V_freqs.size(); j++)
  1534. {
  1535. V_STD_freqs[i] += pow(*it_Freq - V_mean_freqs[i], 2);
  1536. advance(it_Freq, 1);
  1537. }
  1538.  
  1539. V_STD_freqs[i] /= V_freqs.size();
  1540. V_STD_freqs[i] = sqrt(V_STD_freqs[i]);
  1541. }
  1542.  
  1543. fp0 = fopen("V_STD_freqs.txt", "w+");
  1544. for (int i = 0; i < Node_count; i++)
  1545. {
  1546. fprintf(fp0, "%f\t", V_STD_freqs[i]);
  1547. }
  1548. fclose(fp0);
  1549.  
  1550. double V_STD_mean_Freq = 0;
  1551. double V_STD_mean_Freq_not_zero = 0;
  1552. double V_STD_mean_Freq_not_zero_count = 0;
  1553.  
  1554. for (int j = 0; j < Node_count; j++)
  1555. {
  1556. if (V_STD_freqs[j] != 0)
  1557. {
  1558. V_STD_mean_Freq_not_zero_count++;
  1559. V_STD_mean_Freq += V_STD_freqs[j];
  1560. }
  1561. }
  1562.  
  1563. V_STD_mean_Freq_not_zero = V_STD_mean_Freq / V_STD_mean_Freq_not_zero_count;
  1564. V_STD_mean_Freq /= Node_count;
  1565.  
  1566. fp0 = fopen("V_STD_mean_Freq.txt", "w+");
  1567. fprintf(fp0, "%f\n", V_STD_mean_Freq);
  1568. //fprintf(fp_res, "%f\t", V_STD_mean_Freq);
  1569. fclose(fp0);
  1570.  
  1571. fp0 = fopen("V_STD_mean_Freq_not_zero.txt", "w+");
  1572. fprintf(fp0, "%f\n", V_STD_mean_Freq_not_zero);
  1573. //fprintf(fp_res, "%f\t", V_STD_mean_Freq_not_zero);
  1574. fclose(fp0);
  1575.  
  1576. double V_mean_mean_Freq = 0;
  1577. double V_mean_mean_Freq_not_zero = 0;
  1578. double V_mean_mean_Freq_not_zero_count = 0;
  1579.  
  1580. for (int j = 0; j < Node_count; j++)
  1581. {
  1582. if (V_mean_freqs[j] != 0)
  1583. {
  1584. V_mean_mean_Freq_not_zero_count++;
  1585. V_mean_mean_Freq += V_mean_freqs[j];
  1586. }
  1587. }
  1588.  
  1589. delete[] V_mean_freqs;
  1590. delete[] V_STD_freqs;
  1591.  
  1592. V_mean_mean_Freq_not_zero = V_mean_mean_Freq / V_mean_mean_Freq_not_zero_count;
  1593. V_mean_mean_Freq /= Node_count;
  1594.  
  1595. fp0 = fopen("V_mean_mean_Freq.txt", "w+");
  1596. fprintf(fp0, "%f\n", V_mean_mean_Freq);
  1597. fclose(fp0);
  1598.  
  1599. fp0 = fopen("V_mean_mean_Freq_not_zero.txt", "w+");
  1600. fprintf(fp0, "%f\n", V_mean_mean_Freq_not_zero);
  1601. fclose(fp0);
  1602.  
  1603. // CHUNKS
  1604. double chunk_t_start = 0.25 * t_max;
  1605. double chunk_t_step = 0.5;
  1606. int chunk_step_count = (0.75 * t_max / chunk_t_step);
  1607.  
  1608. double dt_chunk = 0.1 / V_mean_mean_Freq_not_zero; // 0.25
  1609. int chunks_count = chunk_t_step / dt_chunk;
  1610.  
  1611. double corr_aver_mean = 0, corr_aver_mean_not_zero = 0;
  1612.  
  1613. FILE* fp_corr_not_zero = fopen("corr_not_zero.txt", "w+");
  1614. FILE* fp_V_spikes_chunks = fopen("V_spikes_chunks.txt", "w+");
  1615.  
  1616. for (int s = 0; s < chunk_step_count; s++)
  1617. {
  1618. int** V_spikes_chunks = new int* [Node_count];
  1619.  
  1620. //#pragma omp parallel for
  1621. for (int i = 0; i < Node_count; i++)
  1622. {
  1623. V_spikes_chunks[i] = new int[chunks_count];
  1624.  
  1625. if (V_spikes[i].size() == 0)
  1626. for (int ch = 0; ch < chunks_count; ch++)
  1627. V_spikes_chunks[i][ch] = 0;
  1628.  
  1629. double ch_start = chunk_t_start + chunk_t_step * s;
  1630. double ch_end = ch_start + dt_chunk;
  1631. list<double>::iterator currentSpike = V_spikes[i].begin();
  1632.  
  1633. for (int ch = 0; ch < chunks_count; ch++)
  1634. {
  1635. while (currentSpike != V_spikes[i].end() && *currentSpike < ch_start)
  1636. currentSpike++;
  1637.  
  1638. if (currentSpike == V_spikes[i].end())
  1639. V_spikes_chunks[i][ch] = 0;
  1640. else
  1641. V_spikes_chunks[i][ch] = *currentSpike >= ch_start && *currentSpike <= ch_end;
  1642.  
  1643. ch_start += dt_chunk;
  1644. ch_end += dt_chunk;
  1645. }
  1646. }
  1647.  
  1648. char buffer[50];
  1649. //sprintf(buffer, "V_spikes_chunks_%d.txt", s);
  1650. //fp0 = fopen(buffer, "w+");
  1651.  
  1652. for (int ch = 0; ch < chunks_count; ch++)
  1653. {
  1654. for (int i = 0; i < Node_count; i++)
  1655. fprintf(fp_V_spikes_chunks, "%d\t", V_spikes_chunks[i][ch]);
  1656.  
  1657. fprintf(fp_V_spikes_chunks, "\n");
  1658. }
  1659.  
  1660. //fclose(fp0);
  1661.  
  1662. double corr = 0;
  1663. double corr_not_zero = 0;
  1664. double counter = 0;
  1665. double counter_not_zero = 0;
  1666.  
  1667. for (int i = 0; i < Node_count; i++)
  1668. {
  1669. for (int j = 0; j < Node_count; j++)
  1670. {
  1671. if (i == j)
  1672. continue;
  1673.  
  1674. int k1 = 0;
  1675. int k2 = 0;
  1676. int k3 = 0;
  1677.  
  1678. for (int l = 0; l < chunks_count; l++)
  1679. {
  1680. if (V_spikes_chunks[i][l] == 1 && V_spikes_chunks[j][l] == 1)
  1681. k1++;
  1682.  
  1683. k2 += V_spikes_chunks[i][l];
  1684. k3 += V_spikes_chunks[j][l];
  1685. }
  1686.  
  1687. if (k2 != 0 && k3 != 0)
  1688. {
  1689. corr += (double)k1 / sqrt((double)k2 * (double)k3);
  1690. counter_not_zero++;
  1691. }
  1692.  
  1693. counter++;
  1694. }
  1695. }
  1696.  
  1697. double corr_aver = corr / counter;
  1698. double corr_aver_not_zero = corr / counter_not_zero;
  1699.  
  1700. corr_aver_mean += corr_aver;
  1701. corr_aver_mean_not_zero += corr_aver_not_zero;
  1702.  
  1703. //sprintf(buffer, "corr_aver_%d.txt", s);
  1704.  
  1705. //fp0 = fopen(buffer, "w+");
  1706. //fprintf(fp0, "%f\n", corr_aver);
  1707. //fclose(fp0);
  1708.  
  1709. double ch_start = chunk_t_start + chunk_t_step * s;
  1710. fprintf(fp_corr_not_zero, "%f\t%f\n", ch_start, corr_aver_not_zero);
  1711.  
  1712. for (int i = 0; i < Node_count; i++)
  1713. delete[] V_spikes_chunks[i];
  1714.  
  1715. delete[] V_spikes_chunks;
  1716. }
  1717.  
  1718. fclose(fp_corr_not_zero);
  1719. fclose(fp_V_spikes_chunks);
  1720.  
  1721. corr_aver_mean /= chunk_step_count;
  1722. corr_aver_mean_not_zero /= chunk_step_count;
  1723.  
  1724. //fp0 = fopen("corr_aver_mean.txt", "w+");
  1725. //fprintf(fp0, "%f\n", corr_aver_mean);
  1726. //fclose(fp0);
  1727.  
  1728. //fp0 = fopen("corr_aver_mean_not_zero.txt", "w+");
  1729. //fprintf(fp0, "%f\n", corr_aver_mean_not_zero);
  1730. //fclose(fp0);
  1731. ////// CHUNKS END
  1732.  
  1733. //2
  1734. double* V_freq_sync_time = new double[Node_count];
  1735. double* V_freq_sync_time_relative = new double[Node_count];
  1736.  
  1737. #pragma omp parallel for
  1738. for (int i = 0; i < Node_count; i++)
  1739. {
  1740. list<double>::iterator it_V_spikes = V_spikes[i].begin();
  1741.  
  1742. while (it_V_spikes != V_spikes[i].end() && *it_V_spikes < 0.25 * t_max)
  1743. {
  1744. V_spikes[i].pop_front();
  1745. it_V_spikes = V_spikes[i].begin();
  1746. }
  1747.  
  1748. list<double> V_freqs_normalized;
  1749. list<double> V_freqs_time;
  1750.  
  1751. it_V_spikes = V_spikes[i].begin();
  1752.  
  1753. if (V_spikes[i].size() <= 1)
  1754. {
  1755. continue;
  1756. }
  1757. else
  1758. {
  1759. for (int j = 1; j < V_spikes[i].size(); j++)
  1760. {
  1761. double first = *it_V_spikes;
  1762. advance(it_V_spikes, 1);
  1763. double next = *it_V_spikes;
  1764.  
  1765. double T = next - first;
  1766. V_freqs_normalized.push_back(1 / T - V_mean_mean_Freq);
  1767. V_freqs_time.push_back(next);
  1768. }
  1769. }
  1770.  
  1771. list<double>::iterator it_Freq_normalized = V_freqs_normalized.begin();
  1772. list<double>::iterator it_Freq_time = V_freqs_time.begin();
  1773.  
  1774. V_freq_sync_time[i] = 0;
  1775.  
  1776. for (int j = 1; j < V_freqs_normalized.size(); j++)
  1777. {
  1778. double Freq_normalized_last = *it_Freq_normalized;
  1779. advance(it_Freq_normalized, 1);
  1780. double Freq_normalized_next = *it_Freq_normalized;
  1781.  
  1782. double Freq_time_last = *it_Freq_time;
  1783. advance(it_Freq_time, 1);
  1784. double Freq_time_next = *it_Freq_time;
  1785.  
  1786. if (abs(Freq_normalized_last) <= 0.5 && abs(Freq_normalized_next) <= 0.5 && (Freq_time_next - Freq_time_last) <= 0.035)
  1787. V_freq_sync_time[i] += Freq_time_next - Freq_time_last;
  1788. }
  1789.  
  1790. V_freq_sync_time_relative[i] = V_freq_sync_time[i] / (t_max - (0.25 * t_max));
  1791. }
  1792.  
  1793. double V_mean_freq_sync_time_relative = 0;
  1794.  
  1795. for (int j = 0; j < Node_count; j++)
  1796. {
  1797. V_mean_freq_sync_time_relative += V_freq_sync_time_relative[j];
  1798. }
  1799.  
  1800. V_mean_freq_sync_time_relative /= Node_count;
  1801.  
  1802. fp0 = fopen("V_freq_sync_time_relative.txt", "w+");
  1803. for (int i = 0; i < Node_count; i++)
  1804. {
  1805. fprintf(fp0, "%f\t", V_freq_sync_time_relative[i]);
  1806. }
  1807. fclose(fp0);
  1808.  
  1809. fp0 = fopen("V_mean_freq_sync_time_relative.txt", "w+");
  1810. fprintf(fp0, "%f\n", V_mean_freq_sync_time_relative);
  1811. //fprintf(fp_res, "%f\n", V_mean_freq_sync_time_relative);
  1812. fclose(fp0);
  1813.  
  1814. //fclose(fp_res);
  1815. fclose(fp_Max_magnitude);
  1816. fclose(fp_I_stim);
  1817. ///fclose(fp_I_syn);
  1818. fclose(fp_Ca);
  1819. //fclose(fp_IP3);
  1820. //fclose(fp_z);
  1821. fclose(fp_V);
  1822. //fclose(fp_m);
  1823. //fclose(fp_n);
  1824. //fclose(fp_h);
  1825. //fclose(fp_G_P);
  1826. fclose(fp_V_P);
  1827. //fclose(fp_m_P);
  1828. //fclose(fp_n_P);
  1829. //fclose(fp_h_P);
  1830.  
  1831. fclose(fp_V_spikes);
  1832.  
  1833. //end_rk4 = omp_get_wtime();
  1834. end_rk4 = clock();
  1835. double extime_rk4 = (double)(end_rk4 - start_rk4);// / CLOCKS_PER_SEC;
  1836. int minutes = (int)extime_rk4 / 60;
  1837. int seconds = (int)extime_rk4 % 60;
  1838. printf("\nExecution time is: %d minutes %d seconds\n ", minutes, seconds);
  1839.  
  1840. /*int nth;
  1841. #pragma omp parallel
  1842. {
  1843. #pragma omp master
  1844. nth = omp_get_num_threads();
  1845. }*/
  1846.  
  1847. fp0 = fopen("time_exec.txt", "a");
  1848. //fprintf(fp0, "%d %lf\n", nth, extime_rk4);
  1849. fprintf(fp0, "%lf\n", extime_rk4);
  1850. fclose(fp0);
  1851.  
  1852. for (int i = 0; i < Node_count; i++)
  1853. delete[] A_A[i];
  1854.  
  1855. delete[] A_A;
  1856.  
  1857. for (int i = 0; i < Node_count; i++)
  1858. delete[] B_A[i];
  1859.  
  1860. delete[] B_A;
  1861.  
  1862. delete[] C_A;
  1863.  
  1864. for (int i = 0; i < Node_count; i++)
  1865. delete[] A_N[i];
  1866.  
  1867. delete[] A_N;
  1868.  
  1869. for (int i = 0; i < Node_count; i++)
  1870. delete[] B_N[i];
  1871.  
  1872. delete[] B_N;
  1873.  
  1874. delete[] C_N;
  1875.  
  1876. delete[] A_N_P;
  1877.  
  1878. for (int i = 0; i < Node_count; i++)
  1879. delete[] B_N_P[i];
  1880.  
  1881. delete[] B_N_P;
  1882.  
  1883. delete[] C_N_P;
  1884.  
  1885. delete[] f;
  1886. delete[] f_diff;
  1887. delete[] v_4;
  1888. delete[] E_syn;
  1889. delete[] I_app;
  1890. delete[] V_spikes;
  1891. delete[] V_spikes_Freq;
  1892.  
  1893. delete[] Meander_start_from_zero;
  1894. delete[] Meander_width;
  1895. delete[] Meander_height;
  1896. delete[] Meander_interval;
  1897. delete[] last_meander_end;
  1898. delete[] V_freq_sync_time;
  1899.  
  1900. for (int i = 0; i < Node_count; i++)
  1901. delete[] tau[i];
  1902.  
  1903. delete[] tau;
  1904.  
  1905. for (int i = 0; i < Node_count; i++)
  1906. delete[] V_old_array[i];
  1907.  
  1908. delete[] V_old_array;
  1909.  
  1910. for (int i = 0; i < Equations_count; i++)
  1911. delete[] k[i];
  1912.  
  1913. delete[] k;
  1914.  
  1915. delete[] phi_k1;
  1916. delete[] phi_k2;
  1917. delete[] phi_k3;
  1918. }
  1919.  
Add Comment
Please, Sign In to add comment