fork(16) download
  1. #include <vector>
  2. #include <cmath>
  3. #include <iostream>
  4.  
  5.  
  6.  
  7. class FloodIsolation {
  8. public:
  9. FloodIsolation() :
  10. numberOfCells(20000),
  11. h(numberOfCells, 0),
  12. floodedCells(numberOfCells, 0),
  13. floodedCellsTimeInterval(numberOfCells, 0),
  14. qInflow(numberOfCells, 0),
  15. qStartTime(numberOfCells, 0),
  16. qEndTime(numberOfCells, 0),
  17. lowerFloorCells(numberOfCells, 0),
  18. cellLocationX(numberOfCells, 0),
  19. cellLocationY(numberOfCells, 0),
  20. cellLocationZ(numberOfCells, 0),
  21. levelOfCell(numberOfCells, 0),
  22. valueOfCellIds(numberOfCells, 0),
  23. h0(numberOfCells, 0),
  24. vU(numberOfCells, 0),
  25. vV(numberOfCells, 0),
  26. vUh(numberOfCells, 0),
  27. vVh(numberOfCells, 0),
  28. vUh0(numberOfCells, 0),
  29. vVh0(numberOfCells, 0),
  30. ghh(numberOfCells, 0),
  31. sfx(numberOfCells, 0),
  32. sfy(numberOfCells, 0),
  33. qIn(numberOfCells, 0),
  34. typeInterface(numberOfCells * nEdges, 0),
  35. neighborIds(numberOfCells * nEdges, 0)
  36. {
  37. }
  38. ~FloodIsolation(){
  39. }
  40.  
  41. void isUpdateNeeded() {
  42. for (int i = 0; i < numberOfCells; ++i) {
  43. h[i] = h[i] + 1;
  44. floodedCells[i] = !floodedCells[i];
  45. floodedCellsTimeInterval[i] = !floodedCellsTimeInterval[i];
  46. qInflow[i] = qInflow[i] + 1;
  47. qStartTime[i] = qStartTime[i] + 1;
  48. qEndTime[i] = qEndTime[i] + 1;
  49. lowerFloorCells[i] = lowerFloorCells[i] + 1;
  50. cellLocationX[i] = cellLocationX[i] + 1;
  51. cellLocationY[i] = cellLocationY[i] + 1;
  52. cellLocationZ[i] = cellLocationZ[i] + 1;
  53. levelOfCell[i] = levelOfCell[i] + 1;
  54. valueOfCellIds[i] = valueOfCellIds[i] + 1;
  55. h0[i] = h0[i] + 1;
  56. vU[i] = vU[i] + 1;
  57. vV[i] = vV[i] + 1;
  58. vUh[i] = vUh[i] + 1;
  59. vVh[i] = vVh[i] + 1;
  60. vUh0[i] = vUh0[i] + 1;
  61. vVh0[i] = vVh0[i] + 1;
  62. ghh[i] = ghh[i] + 1;
  63. sfx[i] = sfx[i] + 1;
  64. sfy[i] = sfy[i] + 1;
  65. qIn[i] = qIn[i] + 1;
  66. for(int j = 0; j < nEdges; ++j) {
  67. typeInterface[i * nEdges + j] = typeInterface[i * nEdges + j] + 1;
  68. neighborIds[i * nEdges + j] = neighborIds[i * nEdges + j] + 1;
  69. }
  70. }
  71.  
  72. }
  73.  
  74. private:
  75.  
  76. const int numberOfCells;
  77. const int nEdges = 6;
  78. std::vector<bool> floodedCells;
  79. std::vector<bool> floodedCellsTimeInterval;
  80.  
  81. std::vector<int> neighborIds;
  82. std::vector<double> valueOfCellIds;
  83. std::vector<double> h;
  84.  
  85. std::vector<double> h0;
  86. std::vector<double> vU;
  87. std::vector<double> vV;
  88. std::vector<double> vUh;
  89. std::vector<double> vVh;
  90. std::vector<double> vUh0;
  91. std::vector<double> vVh0;
  92. std::vector<double> ghh;
  93. std::vector<double> sfx;
  94. std::vector<double> sfy;
  95. std::vector<double> qInflow;
  96. std::vector<double> qStartTime;
  97. std::vector<double> qEndTime;
  98. std::vector<double> qIn;
  99. std::vector<double> nx;
  100. std::vector<double> ny;
  101. std::vector<double> floorLevels;
  102. std::vector<int> lowerFloorCells;
  103. std::vector<bool> flagInterface;
  104. std::vector<int> typeInterface;
  105. std::vector<bool> floorCompleteleyFilled;
  106. std::vector<double> cellLocationX;
  107. std::vector<double> cellLocationY;
  108. std::vector<double> cellLocationZ;
  109. std::vector<int> levelOfCell;
  110. };
  111.  
  112. int main() {
  113. FloodIsolation isolation;
  114. clock_t start = clock();
  115. for (int i = 0; i < 400; ++i) {
  116. if(i % 100 == 0) {
  117. std::cout << i << "\n";
  118. }
  119. isolation.isUpdateNeeded();
  120. }
  121. clock_t stop = clock();
  122. std::cout << "Time: " << difftime(stop, start) / 1000 << "\n";
  123. }
  124.  
Success #stdin #stdout 4.79s 3360KB
stdin
Standard input is empty
stdout
0
100
200
300
Time: 4774.72