forked from FSIS-IBM/pitch-plunge-omp-noisyinflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolverPGaussSeidelSOR.cpp
109 lines (95 loc) · 2.99 KB
/
solverPGaussSeidelSOR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "solverPGaussSeidelSOR.h"
#include "evalMaxError.h"
void solverPGaussSeidelSOR(int m, int n, float* a_p, float* b_p, float* c_p, float* d_p, float* e_p, float* f_p, float* p_c, float* pA_old, float* p_c_red, float* p_c_black, float* p_c_red_old, float* p_c_black_old, float* max_error3)
{
// Gauss Seidel iterations with red-black SOR for pressure correction equation
for (int p=0; p<GSite2; p++)
{
#pragma omp parallel for collapse(2)
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
*(pA_old +i*m +j) = *(p_c+i*m+j);
*(p_c_red_old +m*i+j) = *(p_c_red +m*i+j);
*(p_c_black_old +m*i+j) = *(p_c_black +m*i+j);
}
}
// For red and black pressure correction points
#pragma omp parallel for default(shared) schedule(dynamic)
for(int i=0; i<n; i++)
{
int j1;
j1 = (i%2==0) ? 0 : 1;
for (int j=j1; j<m; j+=2)
{
if (i==0)//bottom row
{
*(p_c_red+m*i+j) = *(p_c_black+m*(i+1)+j);
}
else if (i>0 && i<n-1 && j==0)//left column
{
*(p_c_red+m*i+j) = *(p_c_black+m*i+j+1);
}
else if (i>0 && i<n-1 && j==m-1)//right column
{
*(p_c_red+m*i+j) = *(p_c_black+m*i+j-1);
}
else if (i==n-1)//top row
{
*(p_c_red+m*i+j) = *(p_c_black+m*(i-1)+j);
}
else
{
*(p_c_red+m*i+j) = alpha_SOR*((*(b_p+i*m+j)*(*(p_c_black+m*(i+1)+j)) + *(c_p+i*m+j)*(*(p_c_black+m*(i-1)+j)) + *(d_p+i*m+j)*(*(p_c_black+m*i+j+1)) + *(e_p+i*m+j)*(*(p_c_black+m*i+j-1)) + *(f_p+i*m+j)) / (*(a_p+i*m+j))) + (1.0-alpha_SOR)*(*(p_c_red_old +m*i+j));
}
}
}
#pragma omp parallel for default(shared) schedule(dynamic)
for(int i=0; i<n; i++)
{
int j1;
j1 = (i%2==0) ? 1 : 0;
for (int j=j1; j<m; j+=2)
{
if (i==0)//bottom row
{
*(p_c_black+m*i+j) = *(p_c_red+m*(i+1)+j);
}
else if (i>0 && i<n-1 && j==0)//left column
{
*(p_c_black+m*i+j) = *(p_c_red+m*i+j+1);
}
else if (i>0 && i<n-1 && j==m-1)//right column
{
*(p_c_black+m*i+j) = *(p_c_red+m*i+j-1);
}
else if (i==n-1)//top row
{
*(p_c_black+m*i+j) = *(p_c_red+m*(i-1)+j);
}
else
{
*(p_c_black+m*i+j) = alpha_SOR*((*(b_p+i*m+j)*(*(p_c_red+m*(i+1)+j))+ *(c_p+i*m+j)*(*(p_c_red+m*(i-1)+j)) + *(d_p+i*m+j)*(*(p_c_red+m*i+j+1)) + *(e_p+i*m+j)*(*(p_c_red+m*i+j-1)) + *(f_p+i*m+j)) / (*(a_p+i*m+j))) + (1.0-alpha_SOR)*(*(p_c_black_old +m*i+j));
}
}
}
// generating the actual pressure correction matrix
#pragma omp parallel for default(shared) schedule(dynamic)
for(int i=0;i<n;i++)
{
int j1;
j1 = (i%2==0) ? 0 : 1;
for (int j=j1; j<m; j+=2)
*(p_c+i*m+j)=*(p_c_red+m*i+j);
j1 = (i%2==0) ? 1 : 0;
for (int j=j1; j<m; j+=2)
*(p_c+i*m+j)=*(p_c_black +m*i+j);
}
// Calculate error
*(max_error3+p) = evalMaxError(m, n, (float*)p_c, (float*)pA_old);
// Checking if the error is below tolerance
if (*(max_error3+p) <= tol)
break;
}
}