SpaceQuester

Untitled

Nov 30th, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.97 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.20;
  52. const double Max_magintude = 1.20;
  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. for (int k = 0; k < 2 * Node_count_half; k++)
  337. {
  338. int i, j;
  339.  
  340. do
  341. {
  342. i = RandomI(Node_count_half, Node_count);
  343. j = RandomI(Node_count_half, Node_count);
  344. } while ((i == j) || (A[i][j] == 1));
  345.  
  346. A[i][j] = 1;
  347. A[j][i] = 1;
  348. }
  349. }
  350.  
  351. void FillVOldFromCurrent()
  352. {
  353. for (int i = 0; i < Node_count; i++)
  354. for (int j = 0; j < Max_delay; j++)
  355. V_old_array[i][j] = V(i);
  356. }
  357.  
  358. void UpdateVOld()
  359. {
  360. for (int i = 0; i < Node_count; i++)
  361. {
  362. for (int j = 1; j < Max_delay; j++)
  363. V_old_array[i][j - 1] = V_old_array[i][j];
  364.  
  365. V_old_array[i][Max_delay - 1] = V(i);
  366. }
  367. }
  368.  
  369. void FillTauMatrix()
  370. {
  371. for (int i = 0; i < Node_count; i++)
  372. {
  373. for (int j = 0; j < Node_count; j++)
  374. {
  375. if (i < Node_count_half || j < Node_count_half || i == j || A[i][j] == 0)
  376. {
  377. tau[i][j] = 0;
  378. continue;
  379. }
  380.  
  381. int i_neuron = i - Node_count_half;
  382. int j_neuron = j - Node_count_half;
  383.  
  384. int i_wire_x = i_neuron / Node_wire_width;
  385. int i_wire_y = i_neuron % Node_wire_width;
  386.  
  387. int j_wire_x = j_neuron / Node_wire_width;
  388. int j_wire_y = j_neuron % Node_wire_width;
  389.  
  390. double distance_max = sqrt(2.) * (Node_wire_width - 1);
  391. 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));
  392.  
  393. tau[i][j] = (tau_min + distance / (distance_max) * (tau_max - tau_min)) * ms_to_step;
  394. }
  395. }
  396. }
  397.  
  398. int main(int argc, char *argv[])
  399. {
  400. FILE *fp0;
  401. //FILE *fp_Ca;
  402. //FILE *fp_IP3;
  403. //FILE *fp_z;
  404. //FILE *fp_G;
  405. FILE *fp_I_stim;
  406. FILE *fp_V;
  407. FILE *fp_m;
  408. FILE *fp_n;
  409. FILE *fp_h;
  410. srand(time(NULL));
  411.  
  412. //for (int i = 0; i < Node_count; i++)
  413. // V_old_length[i] = 0;
  414.  
  415. A = malloc(Node_count * sizeof(double));
  416. for (int i = 0; i < Node_count; i++)
  417. A[i] = malloc(Node_count * sizeof(double));
  418.  
  419. B = malloc(Node_count * sizeof(double));
  420. for (int i = 0; i < Node_count; i++)
  421. B[i] = malloc(Node_count * sizeof(double));
  422.  
  423. C = malloc(Node_count * sizeof(double));
  424.  
  425. sigma = malloc(Node_count * sizeof(double));
  426. for (int i = 0; i < Node_count; i++)
  427. sigma[i] = malloc(Node_count * sizeof(double));
  428.  
  429. FillAMatrixZero();
  430. FillRandomMatrix();
  431. FillBCMatrix();
  432. FillSigmaMatrix();
  433. FillTauMatrix();
  434.  
  435. fp0 = fopen("A.txt", "w+");
  436. for (int i = 0; i < Node_count; i++)
  437. {
  438. for (int j = 0; j < Node_count; j++)
  439. {
  440. fprintf(fp0, "%d\t", (int)A[i][j]);
  441. }
  442. fprintf(fp0, "\n");
  443. }
  444. fclose(fp0);
  445.  
  446. fp0 = fopen("tau.txt", "w+");
  447. for (int i = 0; i < Node_count; i++)
  448. {
  449. for (int j = 0; j < Node_count; j++)
  450. {
  451. fprintf(fp0, "%f\t", tau[i][j] / ms_to_step);
  452. }
  453. fprintf(fp0, "\n");
  454. }
  455. fclose(fp0);
  456.  
  457. //Пишем в файл число связей у каждого осциллятора в четвертом квадранте
  458. fp0 = fopen("links.txt", "w+");
  459. for (int i = Node_count_half; i < Node_count; i++)
  460. {
  461. int links_count = 0;
  462. for (int j = Node_count_half; j < Node_count; j++)
  463. {
  464. if (A[i][j] == 1)
  465. {
  466. links_count++;
  467. }
  468. }
  469. fprintf(fp0, "%d\n", (int)links_count);
  470.  
  471. }
  472. fclose(fp0);
  473.  
  474. setlocale(LC_NUMERIC, "French_Canada.1252");
  475. fp0 = fopen("pu.txt", "w+");
  476.  
  477. for (int i = 0; i < 500; i++)
  478. fprintf(fp0, "%f\n", nextTime(500));
  479.  
  480. fclose(fp0);
  481.  
  482. fp0 = fopen("B.txt", "w+");
  483. for (int i = 0; i < Node_count; i++)
  484. {
  485. for (int j = 0; j < C[i]; j++)
  486. {
  487. fprintf(fp0, "%d\t", (int)B[i][j]);
  488. }
  489. fprintf(fp0, "\n");
  490. }
  491. fclose(fp0);
  492.  
  493. fp0 = fopen("C.txt", "w+");
  494. for (int i = 0; i < Node_count; i++)
  495. {
  496. fprintf(fp0, "%d\n", (int)C[i]);
  497. }
  498. fclose(fp0);
  499.  
  500. fp0 = fopen("sigma.txt", "w+");
  501. for (int i = 0; i < Node_count; i++)
  502. {
  503. for (int j = 0; j < Node_count; j++)
  504. {
  505. fprintf(fp0, "%f\t", sigma[i][j]);
  506. }
  507. fprintf(fp0, "\n");
  508. }
  509. fclose(fp0);
  510.  
  511. // Initial values
  512. /*for (int i = 0; i < Equations_count; i++)
  513. {
  514. f[i] = 0;
  515. }
  516.  
  517. for (int i = 0; i < Equations_count; i++)
  518. {
  519. I_app[i] = RandomD(9, 40);
  520. }*/
  521.  
  522. double percent_stable_state = 0.40;
  523.  
  524. double V0 = -61.5364;
  525. double m0 = 0.0789;
  526. double n0 = 0.3718;
  527. double h0 = 0.4723;
  528.  
  529. double V1 = 34.3334;
  530. double m1 = 0.9165;
  531. double n1 = 0.5626;
  532. double h1 = 0.2440;
  533.  
  534. for (int i = 0; i < Node_count; i++) // init array for all neurons
  535. {
  536. SetV(i, 0); // V
  537. Setm(i, 0); // m
  538. Setn(i, 0); // n
  539. Seth(i, 0); // h
  540. }
  541. for (int i = Node_count_half; i < Node_count; i++) // init only neuron nodes
  542. {
  543. double random = RandomD(0, 1);
  544.  
  545. SetV(i, random < percent_stable_state ? V0 : V1); // V
  546. Setm(i, random < percent_stable_state ? m0 : m1); // m
  547. Setn(i, random < percent_stable_state ? n0 : n1); // n
  548. Seth(i, random < percent_stable_state ? h0 : h1); // h
  549. }
  550.  
  551. for (int i = 0; i < Node_count; i++)
  552. {
  553. I_app[i] = 0; // init for neurons all array
  554. }
  555.  
  556. for (int i = Node_count_half; i < Node_count; i++)
  557. {
  558. I_app[i] = 5.27; //RandomD(5.20, 5.34); // init for neurons; Bifurcation point: I_app = 5.27
  559. }
  560.  
  561. double percent_excitable = 0.8; // 0.8
  562. double E_syn0 = 0;
  563. double E_syn1 = -90;
  564.  
  565. for (int i = 0; i < Node_count; i++)
  566. {
  567. E_syn[i] = 0; // init for neurons all array
  568. }
  569.  
  570. for (int i = Node_count_half; i < Node_count; i++)
  571. {
  572. double random = RandomD(0, 1);
  573. E_syn[i] = random < percent_excitable ? E_syn0 : E_syn1;
  574. //printf("i = %d\t E_syn = %f\n", i, E_syn[i]);
  575. }
  576.  
  577. for (int i = 0; i < Node_count; i++)
  578. {
  579. GenerateRandomMeander(i, 0);
  580. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  581. }
  582.  
  583. const double t_start = 0;
  584. const double t_max = 50; // 100 msec = 0.1 sec
  585. const double dt = 0.00001; // 0.01 msec = 0.00001 sec; 1 msec = 0.001 sec
  586.  
  587. double t = t_start;
  588.  
  589. //fp0 = fopen("results.txt", "w+");
  590. //setlocale(LC_NUMERIC, "French_Canada.1252");
  591.  
  592. clock_t start_rk4, end_rk4;
  593. start_rk4 = clock();
  594. int lastPercent = -1;
  595.  
  596. FillVOldFromCurrent();
  597.  
  598. //fp_Ca = fopen("results_Ca.txt", "w+");
  599. //fp_IP3 = fopen("results_IP3.txt", "w+");
  600. //fp_z = fopen("results_z.txt", "w+");
  601. //fp_G = fopen("results_G.txt", "w+");
  602. fp_I_stim = fopen("results_I_stim.txt", "w+");
  603. fp_V = fopen("results_V.txt", "w+");
  604. fp_m = fopen("results_m.txt", "w+");
  605. fp_n = fopen("results_n.txt", "w+");
  606. fp_h = fopen("results_h.txt", "w+");
  607.  
  608. while (t < t_max || Approximately(t, t_max))
  609. {
  610. //fprintf(fp_Ca, "%f\t", t);
  611. //fprintf(fp_IP3, "%f\t", t);
  612. //fprintf(fp_z, "%f\t", t);
  613. //fprintf(fp_G, "%f\t", t);
  614. fprintf(fp_I_stim, "%f\t", t);
  615. fprintf(fp_V, "%f\t", t);
  616. fprintf(fp_m, "%f\t", t);
  617. fprintf(fp_n, "%f\t", t);
  618. fprintf(fp_h, "%f\t", t);
  619.  
  620. for (int i = 0; i < Node_count; i++)
  621. {
  622. if (t > last_meander_end[i])
  623. {
  624. GenerateRandomMeander(i, t);
  625. last_meander_end[i] = Meander_start_from_zero[i] + Duration;
  626. }
  627.  
  628. fprintf(fp_I_stim, "%f\t", I_stim(i, t));
  629. }
  630. fprintf(fp_I_stim, "\n");
  631.  
  632. //for (int i = 0; i < Equations_count; i += 8)
  633. // fprintf(fp_Ca, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // Ca
  634.  
  635. //for (int i = 1; i < Equations_count; i += 8)
  636. // fprintf(fp_IP3, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // IP3
  637.  
  638. //for (int i = 2; i < Equations_count; i += 8)
  639. // fprintf(fp_z, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // z
  640.  
  641. //for (int i = 3; i < Equations_count; i += 8)
  642. // fprintf(fp_G, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // G
  643.  
  644. for (int i = 0; i < Equations_count; i += 4)
  645. fprintf(fp_V, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // V
  646.  
  647. for (int i = 1; i < Equations_count; i += 4)
  648. fprintf(fp_m, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // m
  649.  
  650. for (int i = 2; i < Equations_count; i += 4)
  651. fprintf(fp_n, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // n
  652.  
  653. for (int i = 3; i < Equations_count; i += 4)
  654. fprintf(fp_h, i == Equations_count - 1 ? "%f" : "%f\t", f[i]); // h
  655.  
  656. //fprintf(fp_Ca, "\n");
  657. //fprintf(fp_IP3, "\n");
  658. //fprintf(fp_z, "\n");
  659. //fprintf(fp_G, "\n");
  660. fprintf(fp_V, "\n");
  661. fprintf(fp_m, "\n");
  662. fprintf(fp_n, "\n");
  663. fprintf(fp_h, "\n");
  664.  
  665. double f_next[Equations_count];
  666.  
  667. RungeKutta(t, dt, f, f_next);
  668. CopyArray(f_next, f, Equations_count);
  669.  
  670. t += dt;
  671.  
  672. int percent = (int)(100 * (t - t_start) / (t_max - t_start));
  673. if (percent != lastPercent)
  674. {
  675. printf("Progress: %d%%\n", percent);
  676. lastPercent = percent;
  677. }
  678.  
  679. //printf("V(24) = %f\t V_old(24) = %f\n", f[24*4], V_old(24));
  680. UpdateVOld();
  681. }
  682.  
  683. //fclose(fp_Ca);
  684. //fclose(fp_IP3);
  685. //fclose(fp_z);
  686. //fclose(fp_G);
  687. fclose(fp_I_stim);
  688. fclose(fp_V);
  689. fclose(fp_m);
  690. fclose(fp_n);
  691. fclose(fp_h);
  692.  
  693. end_rk4 = clock();
  694. double extime_rk4 = (double)(end_rk4 - start_rk4) / CLOCKS_PER_SEC;
  695. int minutes = (int)extime_rk4 / 60;
  696. int seconds = (int)extime_rk4 % 60;
  697. printf("\nExecution time is: %d minutes %d seconds\n ", minutes, seconds);
  698.  
  699. fp0 = fopen("time_exec.txt", "w+");
  700. fprintf(fp0, "%f\n", extime_rk4);
  701. fclose(fp0);
  702.  
  703. for (int i = 0; i < Node_count; i++)
  704. free(V_old_array[i]);
  705. free(V_old_array);
  706.  
  707. for (int i = 0; i < Node_count; i++)
  708. free(A[i]);
  709. free(A);
  710.  
  711. for (int i = 0; i < Node_count; i++)
  712. free(B[i]);
  713. free(B);
  714.  
  715. for (int i = 0; i < Node_count; i++)
  716. free(sigma[i]);
  717. free(sigma);
  718.  
  719. for (int i = 0; i < Node_count; i++)
  720. free(tau[i]);
  721. free(tau);
  722.  
  723. free(C);
  724. }
Advertisement
Add Comment
Please, Sign In to add comment