Browse code

Избавился от iostream, добавил цель rebuild

Dmitrii Kashin authored on 11/09/2014 09:16:52
Showing 10 changed files
... ...
@@ -2,7 +2,8 @@ CXX=g++
2 2
 CFLAGS=-Wall -g -ggdb
3 3
 LDFLAGS=-lm
4 4
 SOURCES=main.cxx variables.cxx cell.cxx grid.cxx solver.cxx timestep_constant.cxx march.cxx
5
-OBJECTS=$(SOURCES:.cxx=.o) grid-init.o
5
+STASH=grid-init.o
6
+OBJECTS=$(SOURCES:.cxx=.o) $(STASH)
6 7
 DEPENDS=$(OBJECTS:.o=.deps)
7 8
 EXECUTABLE=frolov
8 9
 
... ...
@@ -12,6 +13,14 @@ all:
12 12
 
13 13
 build: $(EXECUTABLE)
14 14
 
15
+rebuild: $(STASH) stash clean unstash build
16
+
17
+stash: $(STASH)
18
+	mv $(STASH) stashed/
19
+
20
+unstash: 
21
+	cd stashed && mv $(STASH) .. && cd -
22
+
15 23
 # tests
16 24
 test-mono: 
17 25
 	make grid-init-monotonous.o
... ...
@@ -28,6 +28,13 @@
28 28
 
29 29
 
30 30
 * Developement Log
31
+** 2014-09-11
32
+   Избавился от ofstream в пользу stdio.h
33
+   Добавил в Makefile действие rebuild
34
+** 2014-09-10
35
+   Сегодня я развернул на своём сервере web-интерфейс для просмотра
36
+   изменений git-репозитория. Он называется GitList, и меня в принципе
37
+   устраивает.
31 38
 ** 2014-09-04
32 39
    Добил тесты Власенко для скачков без источниковых членов. К сожалению, я ловлю segfault
33 40
    где-то в районе 22760 шага. Я посмотрел backtrace в gdb и мне кажется, что стоит
... ...
@@ -1,13 +1,14 @@
1 1
 #include "cell.h"
2
+#include <stdio.h>
2 3
 
3 4
 // output possibilities
4
-std::ostream&
5
-operator<< (std::ostream& outputStream, Cell1D const& cell)
5
+int
6
+sprintf_Cell1D (char* str, Cell1D cell)
6 7
 {
7
-  //return outputStream << "Cell1D " <<
8
-  return outputStream << 
9
-    cell.x << "\t" << conserv2primitive(cell.vars) << "\t" << cell.convergence;
10
-};
8
+  char var_str[1000];
9
+  sprintf_PrimitiveVars(var_str, conserv2primitive(cell.vars));
10
+  return sprintf(str, "%8.6E\t%s\t%8.6E", cell.x, var_str, cell.convergence);
11
+}
11 12
 
12 13
 // Cell1D operator overloading
13 14
 const ConservVars
... ...
@@ -1,5 +1,4 @@
1 1
 #include "variables.h"
2
-#include <ostream>
3 2
 
4 3
 #ifndef CELL_1D
5 4
 #define CELL_1D
... ...
@@ -11,7 +10,7 @@ typedef struct {
11 11
 } Cell1D;
12 12
 
13 13
 // output possibilities
14
-std::ostream& operator<< (std::ostream& outputStream, Cell1D const& cell);
14
+int sprintf_Cell1D (char* str, Cell1D cell);
15 15
 
16 16
 // Cell1D operator overloading
17 17
 const ConservVars operator+ (Cell1D c1, Cell1D c2);
... ...
@@ -1,7 +1,5 @@
1 1
 #include "grid.h"
2 2
 #include <stdio.h>
3
-#include <iostream>
4
-#include <fstream>
5 3
 
6 4
 Grid1D 
7 5
 grid_cons (unsigned int N, double x0, double x1, boundary_condition_types lbt, boundary_condition_types rbt)
... ...
@@ -31,7 +29,6 @@ Cell1D*
31 31
 allocate_memory_for_grid(unsigned int amount)
32 32
 {
33 33
   Cell1D* cells = (Cell1D*) malloc(amount*sizeof(Cell1D));
34
-  std::cout << "!!! " << cells << std::endl;
35 34
   if (cells == NULL)
36 35
     {
37 36
       perror("Cannot allocate memory for grid\n");
... ...
@@ -55,30 +52,52 @@ grid_skel (Grid1D grid)
55 55
 int
56 56
 printGrid(Grid1D const& grid)
57 57
 {
58
-  std::cout << "x" << "\t" << "phi" << "\t" << "rho_g" << "\t" << "Ug" << "\t" << "Ul" << "\t" << "convergence" << std::endl;
58
+  char cell_str[1000];
59
+  printf("x\tphi\trho_g\tUg\tUl\tconvergence\n");
59 60
   int N = grid.N;
60 61
   Cell1D* cells = grid.cells;
61
-  std::cout << grid.lbc << std::endl;
62
+  
63
+  sprintf_Cell1D(cell_str, grid.lbc);
64
+  printf("%s\n", cell_str);
65
+  
62 66
   for (int i=0; i<N; i++)
63
-    std::cout << cells[i] << std::endl;
64
-  std::cout << grid.rbc << std::endl;
67
+    {
68
+      sprintf_Cell1D(cell_str, cells[i]);
69
+      printf("%s\n", cell_str);
70
+    }
71
+
72
+  sprintf_Cell1D(cell_str, grid.rbc);
73
+  printf("%s\n", cell_str);
74
+
65 75
   return 0;
66 76
 };
67 77
 
68 78
 int
69 79
 printGridToFile(Grid1D const& grid)
70 80
 {
71
-  char filename[30];
72
-  sprintf(filename, "grid%05d", grid.iter);
73
-  std::ofstream file;
74
-  file.open(filename);
75
-  file << "x" << "\t" << "phi" << "\t" << "rho_g" << "\t" << "Ug" << "\t" << "Ul" << "\t" << "convergence" << std::endl;
81
+  char filename[20];
82
+  sprintf(filename, "grid%06d", grid.iter);
83
+
84
+  FILE* fh = fopen(filename, "w");
85
+
86
+  char cell_str[1000];
87
+  fprintf(fh, "x\tphi\trho_g\tUg\tUl\tconvergence\n");
76 88
   int N = grid.N;
77 89
   Cell1D* cells = grid.cells;
78
-  file << grid.lbc << std::endl;
90
+  
91
+  sprintf_Cell1D(cell_str, grid.lbc);
92
+  fprintf(fh, "%s\n", cell_str);
93
+  
79 94
   for (int i=0; i<N; i++)
80
-    file << cells[i] << std::endl;
81
-  file << grid.rbc << std::endl;
82
-  file.close();
95
+    {
96
+      sprintf_Cell1D(cell_str, cells[i]);
97
+      fprintf(fh, "%s\n", cell_str);
98
+    }
99
+
100
+  sprintf_Cell1D(cell_str, grid.rbc);
101
+  fprintf(fh, "%s\n", cell_str);
102
+
103
+  fclose(fh);
104
+
83 105
   return 0;
84
-}
106
+};
... ...
@@ -1,4 +1,3 @@
1
-#include <iostream>
2 1
 #include <stdio.h>
3 2
 
4 3
 #include "grid.h"
... ...
@@ -1,4 +1,4 @@
1
-#include <iostream>
1
+#include <stdio.h>
2 2
 #include <math.h>
3 3
 #include "timestep.h"
4 4
 #include "solver.h"
... ...
@@ -62,8 +62,7 @@ march (Grid1D grid)
62 62
   // шаг
63 63
   if (!finFlag)
64 64
     {
65
-      std::cout << "Making iteration " << grid.iter+1 << ", "
66
-		<< "Passed time: " << grid.time << std::endl;
65
+      printf("Making iteration %06d; Passed time: %f\n", grid.iter+1, grid.time);
67 66
       Grid1D newgrid = make_step(grid, tau);
68 67
       march(newgrid);
69 68
     };
... ...
@@ -4,7 +4,6 @@
4 4
 #include "exit-codes.h"
5 5
 #include <stdio.h>
6 6
 #include <math.h>
7
-#include <iostream>
8 7
 
9 8
 #ifndef SOLVER
10 9
 #define SOLVER
... ...
@@ -35,20 +34,15 @@ count_left_flux(Grid1D grid, unsigned int i, double tau)
35 35
   ConservVars right_shot;
36 36
   
37 37
   if (i == 0) {
38
-    //std::cout << "!!! i=0" << std::endl;
39 38
     left_shot = grid.lbc.vars;
40 39
     right_shot = grid.cells[i].vars;
41 40
   } else if ((signed)i == (signed)grid.N-1) {
42
-    //std::cout << "!!! i=N" << std::endl;
43 41
     left_shot = grid.cells[i-1].vars;
44 42
     right_shot = grid.rbc.vars;
45 43
   } else {
46
-    //std::cout << "!!! i=?!" << std::endl;
47 44
     left_shot = grid.cells[i-1].vars;
48 45
     right_shot = grid.cells[i].vars;
49 46
   };
50
-  //std::cout << "DEBUG1 " << left_shot << std::endl
51
-  //	    << "DEBUG2 " << right_shot << std::endl << std::endl;
52 47
     
53 48
   return 0.5*(cell_flux(left_shot)+cell_flux(right_shot)) - 0.5*grid.h*(right_shot-left_shot)/tau;
54 49
  };
... ...
@@ -63,13 +57,10 @@ make_step(Grid1D grid, double tau)
63 63
   double h = grid.h;
64 64
   double N = grid.N;
65 65
 
66
-  //std::cout << "??? "<< N << std::endl;
67
-
68 66
   ConservVars lf;
69 67
   ConservVars rf = count_left_flux(grid,0,tau);
70 68
   for (unsigned int i=0; i<N; i++)
71 69
     {
72
-      //std::cout << "i=" << i << std::endl;
73 70
       lf = rf;
74 71
       if (i != N-1)
75 72
 	rf = count_left_flux(grid,i+1,tau);
... ...
@@ -49,26 +49,16 @@ num2conserv (double num)
49 49
 };
50 50
 
51 51
 // output
52
-std::ostream&
53
-operator<< (std::ostream& outputStream, PrimitiveVars const& vars)
52
+int
53
+sprintf_PrimitiveVars (char* str, PrimitiveVars vars)
54 54
 {
55
-  //return outputStream << "PrimitiveVars " <<
56
-  return outputStream << 
57
-    vars.p1 << "\t" <<
58
-    vars.p2 << "\t" <<
59
-    vars.p3 << "\t" <<
60
-    vars.p4;
61
-};
55
+  return sprintf(str, "%8.6E\t%8.6E\t%8.6E\t%8.6E", vars.p1, vars.p2, vars.p3, vars.p4);
56
+}
62 57
 
63
-std::ostream&
64
-operator<< (std::ostream& outputStream, ConservVars const& vars)
58
+int
59
+sprintf_ConservVars (char* str, ConservVars vars)
65 60
 {
66
-  //return outputStream << "ConservVars " <<
67
-  return outputStream << 
68
-    vars.u1 << "\t" <<
69
-    vars.u2 << "\t" <<
70
-    vars.u3 << "\t" <<
71
-    vars.u4;
61
+  return sprintf(str, "%8.6E\t%8.6E\t%8.6E\t%8.6E", vars.u1, vars.u2, vars.u3, vars.u4);
72 62
 }
73 63
 
74 64
 // PrimiriveVars operator overloading
... ...
@@ -3,7 +3,6 @@
3 3
 
4 4
 #include "initials.h"
5 5
 #include "exit-codes.h"
6
-#include <ostream>
7 6
 
8 7
 // phi, rho_g, Ug, Ul
9 8
 typedef struct {
... ...
@@ -22,8 +21,8 @@ PrimitiveVars num2primitive (double num);
22 22
 ConservVars num2conserv (double num);
23 23
 
24 24
 // output
25
-std::ostream& operator<< (std::ostream& outputStream, PrimitiveVars const& vars);
26
-std::ostream& operator<< (std::ostream& outputStream, ConservVars const& vars);
25
+int sprintf_PrimitiveVars (char* str, PrimitiveVars vars);
26
+int sprintf_ConservVars (char* str, ConservVars vars);
27 27
 
28 28
 // PrimiriveVars operator overloading
29 29
 const PrimitiveVars operator+ (PrimitiveVars v1, PrimitiveVars v2);