-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweep.cpp
87 lines (78 loc) · 2.21 KB
/
sweep.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
#include <iostream>
#include <fstream>
#include <string>
#include "ddsolve.h"
int sweep(int I, int J, double *dx, double *dy,
int K, double *mu, double *eta, double *w,
int M, double *SigmaT, double *SigmaS, double *BC,
int *materialMatrix, double *distrSource,
double *topBC, double *bottomBC, double *phi) {
double leftBC, rightBC;
double solution[3];
for(int p = 0; p < I*J; p++) {
phi[p] = 0;
}
for(int k = 0; k < K; k++) {
// set bottom BC
for(int i = 0; i < I; i++) {
bottomBC[i] = BC[2];
}
// first quadrant calculation
for(int j = 0; j < J; j++) {
// set left BC
leftBC = BC[0];
for(int i = 0; i < I; i++) {
ddsolve(solution, dx[i], dy[j], mu[k], eta[k], SigmaT[materialMatrix[j*I + i] - 1], leftBC, bottomBC[i], distrSource[j*I + i]);
phi[j*I + i] += w[k] * solution[0];
leftBC = solution[1];
bottomBC[i] = solution[2];
}
}
// set bottom BC
for(int i = 0; i < I; i++) {
bottomBC[i] = BC[2];
}
// second quadrant calculation
for(int j = 0; j < J; j++) {
// set right BC
rightBC = BC[1];
for(int i = I-1; i > -1; i--) {
ddsolve(solution, dx[i], dy[j], mu[k], eta[k], SigmaT[materialMatrix[j*I + i] - 1], rightBC, bottomBC[i], distrSource[j*I + i]);
phi[j*I + i] += w[k] * solution[0];
rightBC = solution[1];
bottomBC[i] = solution[2];
}
}
// set top BC
for(int i = 0; i < I; i++) {
topBC[i] = BC[3];
}
// third quadrant calculation
for(int j = J-1; j > -1; j--) {
// set right BC
rightBC = BC[1];
for(int i = I-1; i > -1; i--) {
ddsolve(solution, dx[i], dy[j], mu[k], eta[k], SigmaT[materialMatrix[j*I + i] - 1], rightBC, topBC[i], distrSource[j*I + i]);
phi[j*I + i] += w[k] * solution[0];
rightBC = solution[1];
topBC[i] = solution[2];
}
}
// set top BC
for(int i = 0; i < I; i++) {
topBC[i] = BC[3];
}
// fourth quadrant calculation
for(int j = J-1; j > -1; j--) {
// set left BC
leftBC = BC[1];
for(int i = 0; i < I; i++) {
ddsolve(solution, dx[i], dy[j], mu[k], eta[k], SigmaT[materialMatrix[j*I + i] - 1], leftBC, topBC[i], distrSource[j*I + i]);
phi[j*I + i] += w[k] * solution[0];
leftBC = solution[1];
topBC[i] = solution[2];
}
}
}
return 0;
}