SpaceQuester

Untitled

Dec 4th, 2017
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.73 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include "math.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <locale.h>
  6. #include <time.h>
  7. #include <stdbool.h>
  8.  
  9. #define Node_count 5*5*2 // должно быть таким, что бы из этого числа, разделенного на два, извлекался корень
  10. #define Node_count_half Node_count / 2
  11. #define Node_wire_width (int)sqrt(Node_count_half)
  12.  
  13. #define Equations_per_node 4
  14. #define Equations_count Node_count * Equations_per_node
  15.  
  16. double f[Equations_count];
  17.  
  18. double C_m = 1;
  19. double g_K = 36;
  20. double g_Na = 120;
  21. double g_L = 0.3;
  22. double E_K = -77;
  23. double E_Na = 55;
  24. double E_L = -54.4;
  25.  
  26. double g_syn = 0.04; // 0.1
  27. double k_syn = 0.2; // 0.2
  28. double E_syn[Node_count];
  29.  
  30. double I_app[Node_count];
  31.  
  32. const double sigma_G = 0.0;
  33. const double sigma_GN = 0.0;
  34. const double sigma_N = 1.0;
  35.  
  36. double** A;
  37. double** B;
  38. double* C;
  39. double** sigma;
  40. double tau[Node_count][Node_count];
  41.  
  42. #define tau_min 2
  43. #define tau_max 12
  44.  
  45. #define ms_to_step 100
  46.  
  47. #define Max_delay tau_max * ms_to_step
  48. double V_old_array[Node_count][Max_delay];
  49.  
  50. const double Freq = 500; // Hz
  51. const double Min_magintude = -1.35;
  52. const double Max_magintude = 1.35;
  53. const double Duration = 0.001;
  54.  
  55. double Meander_start_from_zero[Node_count];
  56. double Meander_width[Node_count];
  57. double Meander_height[Node_count];
  58. double Meander_interval[Node_count];
  59. double last_meander_end[Node_count];
  60.  
  61. double I_stim(int i, double t)
  62. {
  63. if (t < Meander_start_from_zero[i])
  64. return 0;
  65.  
  66. t -= Meander_start_from_zero[i];
  67. t = fmod(t, Meander_width[i] + Meander_interval[i]);
  68.  
  69. return t < Meander_width[i] ? Meander_height[i] : 0;
  70. }
  71.  
  72. double V(int i)
  73. {
  74. return f[i * 4];
  75. }
  76.  
  77. void SetV(int i, double value)
  78. {
  79. f[i * 4] = value;
  80. }
  81.  
  82. double m(int i)
  83. {
  84. return f[i * 4 + 1];
  85. }
  86.  
  87. void Setm(int i, double value)
  88. {
  89. f[i * 4 + 1] = value;
  90. }
  91.  
  92. double n(int i)
  93. {
  94. return f[i * 4 + 2];
  95. }
  96.  
  97. void Setn(int i, double value)
  98. {
  99. f[i * 4 + 2] = value;
  100. }
  101.  
  102. double h(int i)
  103. {
  104. return f[i * 4 + 3];
  105. }
  106.  
  107. void Seth(int i, double value)
  108. {
  109. f[i * 4 + 3] = value;
  110. }
  111.  
  112. double V_old(int i, int delay)
  113. {
  114. return V_old_array[i][Max_delay - 1 - delay];
  115. }
  116.  
  117. int RandomI(int min, int max)
  118. {
  119. return ((double)rand() / (RAND_MAX - 1)) * (max - min) + min;
  120. }
  121.  
  122. double RandomD(double min, double max)
  123. {
  124. return ((double)rand() / RAND_MAX) * (max - min) + min;
  125. }
  126.  
  127. double alpha_m(double* f, int i)
  128. {
  129. return 0.1 * (V(i) + 40) / (1 - exp(-(V(i) + 40) / 10));
  130. }
  131.  
  132. double beta_m(double* f, int i)
  133. {
  134. return 4 * exp(-(V(i) + 65) / 18);
  135. }
  136.  
  137. double alpha_n(double* f, int i)
  138. {
  139. return 0.01 * (V(i) + 55) / (1 - exp(-(V(i) + 55) / 10));
  140. }
  141.  
  142. double beta_n(double* f, int i)
  143. {
  144. return 0.125 * exp(-(V(i) + 65) / 80);
  145. }
  146.  
  147. double alpha_h(double* f, int i)
  148. {
  149. return 0.07 * exp(-(V(i) + 65) / 20);
  150. }
  151.  
  152. double beta_h(double* f, int i)
  153. {
  154. return 1 / (exp(-(V(i) + 35) / 10) + 1);
  155. }
  156.  
  157. double HodgkinHuxley(int i, double* f, double t)
  158. {
  159. int in = i / 4;
  160. int il = i % 4;
  161.  
  162. switch (il)
  163. {
  164. case 0:
  165. {
  166. double sum = 0;
  167.  
  168. for (int j = 0; j < Node_count; j++)
  169. {
  170. //sum += A[in][j] * g_syn * (V(in) - V(j));
  171. sum += A[in][j] * g_syn * (V(in) - E_syn[in]) / (1 + exp(-V_old(j, tau[in][j]) / k_syn));
  172. }
  173.  
  174. /*for (int j = 0; j < C[in]; j++)
  175. {
  176. sum += sigma[in][(int)B[in][j]] * (V((int)B[in][j]) - V(in));
  177. }*/
  178.  
  179. //for (int j = 0; j < C[in]; j++)
  180. //{
  181. // // только тут подставил V_old
  182.  
  183. // sum += /*sigma[in][(int)B[in][j]] * */ g_syn * (V(in) - E_syn[in]) / (1 + exp(-V_old((int)B[in][j]) / k_syn));
  184. // //sum += g_syn * (V((int)B[in][j]) - V(in));
  185. //}
  186. //printf("i = %d\t sum = %f\n", in, sum);
  187.  
  188. return 1000 * ((g_Na * pow(m(in), 3) * h(in) * (E_Na - V(in)) + g_K * pow(n(in), 4) * (E_K - V(in)) + g_L * (E_L - V(in)) + I_app[in] + I_stim(in, t) + sum) / C_m); // V
  189. }
  190.  
  191. case 1:
  192. {
  193. return 1000 * (alpha_m(f, in) * (1 - m(in)) - beta_m(f, in) * m(in));
  194. }
  195.  
  196. case 2:
  197. {
  198. return 1000 * (alpha_n(f, in) * (1 - n(in)) - beta_n(f, in) * n(in));
  199. }
  200.  
  201. case 3:
  202. {
  203. return 1000 * (alpha_h(f, in) * (1 - h(in)) - beta_h(f, in) * h(in));
  204. }
  205. }
  206.  
  207. return 0;
  208. }
  209.  
  210. void RungeKutta(double t, double dt, double* f, double* f_next)
  211. {
  212. double k[Equations_count][4];
  213.  
  214. // k1
  215. for (int i = 0; i < Equations_count; i++)
  216. k[i][0] = HodgkinHuxley(i, f, t) * dt;
  217.  
  218. double phi_k1[Equations_count];
  219. for (int i = 0; i < Equations_count; i++)
  220. phi_k1[i] = f[i] + k[i][0] / 2;
  221.  
  222. // k2
  223. for (int i = 0; i < Equations_count; i++)
  224. k[i][1] = HodgkinHuxley(i, phi_k1, t) * dt;
  225.  
  226. double phi_k2[Equations_count];
  227. for (int i = 0; i < Equations_count; i++)
  228. phi_k2[i] = f[i] + k[i][1] / 2;
  229.  
  230. // k3
  231. for (int i = 0; i < Equations_count; i++)
  232. k[i][2] = HodgkinHuxley(i, phi_k2, t) * dt;
  233.  
  234. double phi_k3[Equations_count];
  235. for (int i = 0; i < Equations_count; i++)
  236. phi_k3[i] = f[i] + k[i][2] / 2;
  237.  
  238. // k4
  239. for (int i = 0; i < Equations_count; i++)
  240. k[i][3] = HodgkinHuxley(i, phi_k3, t) * dt;
  241.  
  242. for (int i = 0; i < Equations_count; i++)
  243. f_next[i] = f[i] + (k[i][0] + 2 * k[i][1] + 2 * k[i][2] + k[i][3]) / 6;
  244. }
  245.  
  246. void CopyArray(double* source, double* target, int N)
  247. {
  248. for (int i = 0; i < N; i++)
  249. target[i] = source[i];
  250. }
  251.  
  252. bool Approximately(double a, double b)
  253. {
  254. if (a < 0)
  255. a = -a;
  256.  
  257. if (b < 0)
  258. b = -b;
  259.  
  260. return a - b <= 0.000001;
  261. }
  262.  
  263. // http://preshing.com/20111007/how-to-generate-random-timings-for-a-poisson-process/
  264. double nextTime(double rateParameter)
  265. {
  266. return -log(1.0 - (double)rand() / (RAND_MAX)) / rateParameter;
  267. }
  268.  
  269. void GenerateRandomMeander(int i, double min_start_time)
  270. {
  271. double offset = nextTime(Freq);
  272.  
  273. if (offset < 0)
  274. {
  275. int a = 0;
  276. }
  277.  
  278. Meander_start_from_zero[i] = min_start_time + offset;
  279. Meander_width[i] = Duration;
  280. Meander_height[i] = RandomD(Min_magintude, Max_magintude);
  281. }
  282.  
  283. void FillAMatrixZero()
  284. {
  285. for (int i = 0; i < Node_count; i++)
  286. {
  287. for (int j = 0; j < Node_count; j++)
  288. {
  289. A[i][j] = 0;
  290. }
  291. }
  292. }
  293.  
  294. void FillBCMatrix()
  295. {
  296. for (int i = 0; i < Node_count; i++)
  297. {
  298. int bIndex = 0;
  299. C[i] = 0;
  300. for (int j = 0; j < Node_count; j++)
  301. {
  302. if (A[i][j] == 1)
  303. {
  304. B[i][bIndex] = j;
  305. bIndex++;
  306. C[i]++;
  307. }
  308. }
  309. }
  310. }
  311.  
  312. void FillSigmaMatrix()
  313. {
  314. for (int i = 0; i < Node_count; i++)
  315. {
  316. for (int j = 0; j < Node_count; j++)
  317. {
  318. if ((i >= 0 && i < Node_count_half) && (j >= 0 || j < Node_count_half))
  319. {
  320. sigma[i][j] = sigma_G;
  321. }
  322. if ((((i >= Node_count_half && i < Node_count) && (j >= 0 && j < Node_count_half)) || ((i >= 0 && i < Node_count_half) && (j >= Node_count_half && j < Node_count))))
  323. {
  324. sigma[i][j] = sigma_GN;
  325. }
  326. if ((i >= Node_count_half && i < Node_count) && (j >= Node_count_half && j < Node_count))
  327. {
  328. sigma[i][j] = sigma_N;
  329. }
  330. }
  331. }
  332. }
  333.  
  334. void FillRandomMatrix()
  335. {
  336. double p_links = 1.0;
  337. //for (int k = 0; k < 2 * Node_count_half; k++)
  338. for (int k = 0; k < p_links * 0.5 * Node_count_half * (Node_count_half - 1); k++)
  339. {
  340. int i, j;
  341.  
  342. do
  343. {
  344. i = RandomI(Node_count_half, Node_count);
  345. j = RandomI(Node_count_half, Node_count);
  346. } while ((i == j) || (A[i][j] == 1));
  347.  
  348. A[i][j] = 1;
  349. A[j][i] = 1;
  350. }
  351. }
  352.  
  353. void FillVOldFromCurrent()
  354. {
  355. for (int i = 0; i < Node_count; i++)
  356. for (int j = 0; j < Max_delay; j++)
  357. V_old_array[i][j] = V(i);
  358. }
  359.  
  360. void UpdateVOld()
  361. {
  362. for (int i = 0; i < Node_count; i++)
  363. {
  364. for (int j = 1; j < Max_delay; j++)
  365. V_old_array[i][j - 1] = V_old_array[i][j];
  366.  
  367. V_old_array[i][Max_delay - 1] = V(i);
  368. }
  369. }
  370.  
  371. /*void FillFullTauMatrix()
  372. {
  373. for (int i = 0; i < Node_count; i++)
  374. {
  375. for (int j = 0; j < Node_count; j++)
  376. {
  377. if (i < Node_count_half || j < Node_count_half)
  378. {
  379. tau[i][j] = 0;
  380. continue;
  381. }
  382.  
  383. int i_neuron = i - Node_count_half;
  384. int j_neuron = j - Node_count_half;
  385.  
  386. int i_wire_x = i_neuron / Node_wire_width;
  387. int i_wire_y = i_neuron % Node_wire_width;
  388.  
  389. int j_wire_x = j_neuron / Node_wire_width;
  390. int j_wire_y = j_neuron % Node_wire_width;
  391.  
  392. double distance_max = sqrt(2.) * (Node_wire_width - 1);
  393. 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));
  394.  
  395. tau[i][j] = (tau_min + distance / (distance_max) * (tau_max - tau_min)) * ms_to_step;
  396. }
  397. }
  398. }*/
  399.  
  400. void FillTauMatrix()
  401. {
  402. for (int i = 0; i < Node_count; i++)
  403. {
  404. for (int j = 0; j < Node_count; j++)
  405. {
  406. if (i < Node_count_half || j < Node_count_half || i == j || A[i][j] == 0)
  407. {
  408. tau[i][j] = 0;
  409. continue;
  410. }
  411.  
  412. int i_neuron = i - Node_count_half;
  413. int j_neuron = j - Node_count_half;
  414.  
  415. int i_wire_x = i_neuron / Node_wire_width;
  416. int i_wire_y = i_neuron % Node_wire_width;
  417.  
  418. int j_wire_x = j_neuron / Node_wire_width;
  419. int j_wire_y = j_neuron % Node_wire_width;
  420.  
  421. double distance_max = sqrt(2.) * (Node_wire_width - 1);
  422. 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));
  423.  
  424. tau[i][j] = (tau_min + distance / (distance_max) * (tau_max - tau_min)) * ms_to_step;
  425. }
  426. }
  427. }
  428.  
  429. int main(int argc, char *argv[])
  430. {
  431. FILE *fp0;
  432. //FILE *fp_Ca;
  433. //FILE *fp_IP3;
  434. //FILE *fp_z;
  435. //FILE *fp_G;
  436. FILE *fp_I_stim;
  437. FILE *fp_V;
  438. FILE *fp_m;
  439. FILE *fp_n;
  440. FILE *fp_h;
  441. srand(time(NULL));
  442.  
  443. //for (int i = 0; i < Node_count; i++)
  444. // V_old_length[i] = 0;
  445.  
  446. A = malloc(Node_count * sizeof(double));
  447. for (int i = 0; i < Node_count; i++)
  448. A[i] = malloc(Node_count * sizeof(double));
  449.  
  450. B = malloc(Node_count * sizeof(double));
  451. for (int i = 0; i < Node_count; i++)
  452. B[i] = malloc(Node_count * sizeof(double));
  453.  
  454. C = malloc(Node_count * sizeof(double));
  455.  
  456. sigma = malloc(Node_count * sizeof(double));
  457. for (int i = 0; i < Node_count; i++)
  458. sigma[i] = malloc(Node_count * sizeof(double));
  459.  
  460. FillAMatrixZero();
  461. FillRandomMatrix();
  462. FillBCMatrix();
  463. FillSigmaMatrix();
  464. FillTauMatrix();
  465.  
  466. fp0 = fopen("A.txt", "w+");
  467. for (int i = 0; i < Node_count; i++)
  468. {
  469. for (int j = 0; j < Node_count; j++)
  470. {
  471. fprintf(fp0, "%d\t", (int)A[i][j]);
  472. }
  473. fprintf(fp0, "\n");
  474. }
  475. fclose(fp0);
  476.  
  477. fp0 = fopen("tau.txt", "w+");
  478. for (int i = 0; i < Node_count; i++)
  479. {
  480. for (int j = 0; j < Node_count; j++)
  481. {
  482. fprintf(fp0, "%f\t", tau[i][j] / ms_to_step);
  483. }
  484. fprintf(fp0, "\n");
  485. }
  486. fclose(fp0);
  487.  
  488. //Пишем в файл число связей у каждого осциллятора в четвертом квадранте
  489. fp0 = fopen("links.txt", "w+");
  490. for (int i = Node_count_half; i < Node_count; i++)
  491. {
  492. int links_count = 0;
  493. for (int j = Node_count_half; j < Node_count; j++)
  494. {
  495. if (A[i][j] == 1)
  496. {
  497. links_count++;
  498. }
  499. }
  500. fprintf(fp0, "%d\n", (int)links_count);
  501.  
  502. }
  503. fclose(fp0);
  504.  
  505. //setlocale(LC_NUMERIC, "French_Canada.1252");
  506. fp0 = fopen("test_Poisson.txt", "w+");
  507. for (int i = 0; i < 5500; i++)
  508. fprintf(fp0, "%f\n", nextTime(Freq));
  509. fclose(fp0);
  510.  
  511. fp0 = fopen("B.txt", "w+");
  512. for (int i = 0; i < Node_count; i++)
  513. {
  514. for (int j = 0; j < C[i]; j++)
  515. {
  516. fprintf(fp0, "%d\t", (int)B[i][j]);
  517. }
  518. fprintf(fp0, "\n");
  519. }
  520. fclose(fp0);
  521.  
  522. fp0 = fopen("C.txt", "w+");
  523. for (int i = 0; i < Node_count; i++)
  524. {
  525. fprintf(fp0, "%d\n", (int)C[i]);
  526. }
  527. fclose(fp0);
  528.  
  529. fp0 = fopen("sigma.txt", "w+");
  530. for (int i = 0; i < Node_count; i++)
  531. {
  532. for (int j = 0; j < Node_count; j++)
  533. {
  534. fprintf(fp0, "%f\t", sigma[i][j]);
  535. }
  536. fprintf(fp0, "\n");
  537. }
  538. fclose(fp0);
  539.  
  540. // Initial values
  541. /*for (int i = 0; i < Equations_count; i++)
  542. {
  543. f[i] = 0;
  544. }
  545.  
  546. for (int i = 0; i < Equations_count; i++)
  547. {
  548. I_app[i] = RandomD(9, 40);
  549. }*/
  550.  
  551. double percent_stable_state = 0.40;
  552.  
  553. double V0 = -61.5364;
  554. double m0 = 0.0789;
  555. double n0 = 0.3718;
  556. double h0 = 0.4723;
  557.  
  558. double V1 = 34.3334;
  559. double m1 = 0.9165;
  560. double n1 = 0.5626;
  561. double h1 = 0.2440;
  562.  
  563. for (int i = 0; i < Node_count; i++) // init array for all neurons
  564. {
  565. SetV(i, 0); // V
  566. Setm(i, 0); // m
  567. Setn(i, 0); // n
  568. Seth(i, 0); // h
  569. }
  570. for (int i = Node_count_half; i < Node_count; i++) // init only neuron nodes
  571. {
  572. double random = RandomD(0, 1);
  573.  
  574. SetV(i, random < percent_stable_state ? V0 : V1); // V
  575. Setm(i, random < percent_stable_state ? m0 : m1); // m
  576. Setn(i, random < percent_stable_state ? n0 : n1); // n
  577. Seth(i, random < percent_stable_state ? h0 : h1); // h
  578. }
  579.  
  580. for (int i = 0; i < Node_count; i++)
  581. {
  582. I_app[i] = 0; // init for neurons all array
  583. }
  584.  
  585. for (int i = Node_count_half; i < Node_count; i++)
  586. {
  587. I_app[i] = 5.27; //RandomD(5.20, 5.34); // init for neurons; Bifurcation point: I_app = 5.27
  588. }
  589.  
  590. double percent_excitable = 0.8; // 0.8
  591. double E_syn0 = 0;
  592. double E_syn1 = -90;
  593.  
  594. for (int i = 0; i < Node_count; i++)
  595. {
  596. E_syn[i] = 0; // init for neurons all array
  597. }
  598.  
  599. for (int i = Node_count_half; i < Node_count; i++)
  600. {
  601. double random = RandomD(0, 1);
  602. E_syn[i] = random < percent_excitable ? E_syn0 : E_syn1;
  603. //printf("i = %d\t E_syn = %f\n", i, E_syn[i]);
  604. }
  605.  
  606. for (int i = 0; i < Node_count; i++)
  607. {
  608. GenerateRandomMeander(i, 0);
  609. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  610. }
  611.  
  612. const double t_start = 0;
  613. const double t_max = 60; // 100 msec = 0.1 sec
  614. const double dt = 0.00001; // 0.01 msec = 0.00001 sec; 1 msec = 0.001 sec
  615.  
  616. double t = t_start;
  617.  
  618. //fp0 = fopen("results.txt", "w+");
  619. //setlocale(LC_NUMERIC, "French_Canada.1252");
  620.  
  621. clock_t start_rk4, end_rk4;
  622. start_rk4 = clock();
  623. int lastPercent = -1;
  624.  
  625. FillVOldFromCurrent();
  626.  
  627. //fp_Ca = fopen("results_Ca.txt", "w+");
  628. //fp_IP3 = fopen("results_IP3.txt", "w+");
  629. //fp_z = fopen("results_z.txt", "w+");
  630. //fp_G = fopen("results_G.txt", "w+");
  631. fp_I_stim = fopen("results_I_stim.txt", "w+");
  632. fp_V = fopen("results_V.txt", "w+");
  633. fp_m = fopen("results_m.txt", "w+");
  634. fp_n = fopen("results_n.txt", "w+");
  635. fp_h = fopen("results_h.txt", "w+");
  636.  
  637. while (t < t_max || Approximately(t, t_max))
  638. {
  639. //fprintf(fp_Ca, "%f\t", t);
  640. //fprintf(fp_IP3, "%f\t", t);
  641. //fprintf(fp_z, "%f\t", t);
  642. //fprintf(fp_G, "%f\t", t);
  643. fprintf(fp_I_stim, "%f\t", t);
  644. fprintf(fp_V, "%f\t", t);
  645. fprintf(fp_m, "%f\t", t);
  646. fprintf(fp_n, "%f\t", t);
  647. fprintf(fp_h, "%f\t", t);
  648.  
  649. for (int i = 0; i < Node_count; i++)
  650. {
  651. if (t > last_meander_end[i])
  652. {
  653. GenerateRandomMeander(i, t);
  654. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  655. }
  656.  
  657. fprintf(fp_I_stim, "%f\t", I_stim(i, t));
  658. }
  659. fprintf(fp_I_stim, "\n");
  660.  
  661. //for (int i = 0; i < Equations_count; i += 8)
  662. // fprintf(fp_Ca, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // Ca
  663.  
  664. //for (int i = 1; i < Equations_count; i += 8)
  665. // fprintf(fp_IP3, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // IP3
  666.  
  667. //for (int i = 2; i < Equations_count; i += 8)
  668. // fprintf(fp_z, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // z
  669.  
  670. //for (int i = 3; i < Equations_count; i += 8)
  671. // fprintf(fp_G, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // G
  672.  
  673. for (int i = 0; i < Equations_count; i += 4)
  674. fprintf(fp_V, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V
  675.  
  676. for (int i = 1; i < Equations_count; i += 4)
  677. fprintf(fp_m, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m
  678.  
  679. for (int i = 2; i < Equations_count; i += 4)
  680. fprintf(fp_n, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n
  681.  
  682. for (int i = 3; i < Equations_count; i += 4)
  683. fprintf(fp_h, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h
  684.  
  685. //fprintf(fp_Ca, "\n");
  686. //fprintf(fp_IP3, "\n");
  687. //fprintf(fp_z, "\n");
  688. //fprintf(fp_G, "\n");
  689. fprintf(fp_V, "\n");
  690. fprintf(fp_m, "\n");
  691. fprintf(fp_n, "\n");
  692. fprintf(fp_h, "\n");
  693.  
  694. double f_next[Equations_count];
  695.  
  696. RungeKutta(t, dt, f, f_next);
  697. CopyArray(f_next, f, Equations_count);
  698.  
  699. t += dt;
  700.  
  701. int percent = (int)(100 * (t - t_start) / (t_max - t_start));
  702. if (percent != lastPercent)
  703. {
  704. printf("Progress: %d%%\n", percent);
  705. lastPercent = percent;
  706. }
  707.  
  708. //printf("V(24) = %f\t V_old(24) = %f\n", f[24*4], V_old(24));
  709. UpdateVOld();
  710. }
  711.  
  712. //fclose(fp_Ca);
  713. //fclose(fp_IP3);
  714. //fclose(fp_z);
  715. //fclose(fp_G);
  716. fclose(fp_I_stim);
  717. fclose(fp_V);
  718. fclose(fp_m);
  719. fclose(fp_n);
  720. fclose(fp_h);
  721.  
  722. end_rk4 = clock();
  723. double extime_rk4 = (double)(end_rk4 - start_rk4) / CLOCKS_PER_SEC;
  724. int minutes = (int)extime_rk4 / 60;
  725. int seconds = (int)extime_rk4 % 60;
  726. printf("\nExecution time is: %d minutes %d seconds\n ", minutes, seconds);
  727.  
  728. fp0 = fopen("time_exec.txt", "w+");
  729. fprintf(fp0, "%f\n", extime_rk4);
  730. fclose(fp0);
  731.  
  732. for (int i = 0; i < Node_count; i++)
  733. free(A[i]);
  734. free(A);
  735.  
  736. for (int i = 0; i < Node_count; i++)
  737. free(B[i]);
  738. free(B);
  739.  
  740. for (int i = 0; i < Node_count; i++)
  741. free(sigma[i]);
  742. free(sigma);
  743.  
  744. free(C);
  745. }
Advertisement
Add Comment
Please, Sign In to add comment