diff --git a/sequential.cpp b/sequential.cpp index 78e0fe9..d13eed3 100644 --- a/sequential.cpp +++ b/sequential.cpp @@ -43,8 +43,8 @@ int main() std::cout << "--------------------------------------------------" << std::endl; // Stores the approximated values for each step - double Q[kmax][dt]; - double P[kmax][dt]; + double Q[dt][kmax]; + double P[dt][kmax]; // Prepare initial condition for (int i = 0; i < dt; i++) @@ -55,12 +55,12 @@ int main() // Boundary condition for the last spatial step if (k == kmax - 1) { - Q[k][i] = 0; - P[k][i] = -202.0; // P = -202 when Q = 10 + Q[i][k] = 0; + P[i][k] = -202.0; // P = -202 when Q = 10 } else { - Q[k][i] = 0; - P[k][i] = 0; + Q[i][k] = 0; + P[i][k] = 0; } } } @@ -74,11 +74,11 @@ int main() { // Loop over spatial steps for flow for (int k = 1; k < kmax; k++) { - Q[k][i + 1] = Q[k][i] + h * (alpha * (P[k - 1][i] - P[k][i]) - beta * Q[k][i] * abs(Q[k][i])); + Q[i + 1][k] = Q[i][k] + h * (alpha * (P[i][k - 1] - P[i][k]) - beta * Q[i][k] * abs(Q[i][k])); } // Loop over steps for pressure, DO NOT calculate pressure for the last element as it is given as a boundary condition for (int k = 1; k < kmax - 1; k++) { - P[k][i + 1] = P[k][i - 2] + h * (gamma * (Q[k][i] - Q[k + 1][i])); + P[i + 1][k] = P[k][i - 2] + h * (gamma * (Q[i][k] - Q[i][k + 1])); } } @@ -91,7 +91,7 @@ int main() std::cout << i << ": "; for(int k = 0; k < 10; k++) - std::cout << std::setw(10) << Q[i][k]; + std::cout << std::setw(10) << Q[k][i]; std::cout << std::endl; } @@ -104,7 +104,7 @@ int main() std::cout << i << ": "; for(int k = 0; k < 10; k++) - std::cout << std::setw(10) << Q[i][dt - 10 + k]; + std::cout << std::setw(10) << Q[dt - 10 + k][i]; std::cout << std::endl; }