Change element order in data structure to allow vectorization

Signed-off-by: Christoph Niethammer <niethammer@hlrs.de>
This commit is contained in:
Christoph Niethammer 2024-03-13 13:49:45 +01:00
parent d6a0d64176
commit c07070ae31

View file

@ -43,8 +43,8 @@ int main()
std::cout << "--------------------------------------------------" << std::endl; std::cout << "--------------------------------------------------" << std::endl;
// Stores the approximated values for each step // Stores the approximated values for each step
double Q[kmax][dt]; double Q[dt][kmax];
double P[kmax][dt]; double P[dt][kmax];
// Prepare initial condition // Prepare initial condition
for (int i = 0; i < dt; i++) for (int i = 0; i < dt; i++)
@ -55,12 +55,12 @@ int main()
// Boundary condition for the last spatial step // Boundary condition for the last spatial step
if (k == kmax - 1) if (k == kmax - 1)
{ {
Q[k][i] = 0; Q[i][k] = 0;
P[k][i] = -202.0; // P = -202 when Q = 10 P[i][k] = -202.0; // P = -202 when Q = 10
} else } else
{ {
Q[k][i] = 0; Q[i][k] = 0;
P[k][i] = 0; P[i][k] = 0;
} }
} }
} }
@ -74,11 +74,11 @@ int main()
{ {
// Loop over spatial steps for flow // Loop over spatial steps for flow
for (int k = 1; k < kmax; k++) { 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 // 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++) { 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 << ": "; std::cout << i << ": ";
for(int k = 0; k < 10; k++) 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; std::cout << std::endl;
} }
@ -104,7 +104,7 @@ int main()
std::cout << i << ": "; std::cout << i << ": ";
for(int k = 0; k < 10; k++) 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; std::cout << std::endl;
} }