-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.cpp
More file actions
34 lines (34 loc) · 854 Bytes
/
utils.cpp
File metadata and controls
34 lines (34 loc) · 854 Bytes
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
/*
* @Author: smasky
* @Date: 2021-06-16 21:43:52
* @LastEditTime: 2021-06-17 22:16:35
* @LastEditors: smasky
* @Description: utils for 1d_rivers
* @FilePath: \Rivers_1d\utils.cpp
* You will never know unless you try
*/
#include "utils.h"
#include <iostream>
void solve_SOR(double *A, double *b, int *Dr, int *Ri, double *all_Z,const int length_A, const int length_Ri){
double w=0.8;
double temp_Ze=0.0,temp_aii=0.0,sum_error=0.0;
int k=0;
while(k<100){
for(int j=0;j<length_Ri;j++){
temp_Ze=temp_Ze+b[j];
///////////////
for(int i=Ri[j];i<Ri[j+1];i++){
if(Dr[j]==i) temp_aii=A[i];
temp_Ze=temp_Ze-A[i]*all_Z[Dr[i]];
}
//////////////
temp_Ze=w*temp_Ze/temp_aii;
all_Z[j]=all_Z[j]+temp_Ze;
sum_error+=temp_Ze;
temp_Ze=0;
}
if((sum_error<1e-10) & (sum_error>-1e-10)) break;
k+=1;
sum_error=0;
};
}