-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtransportSweepLinearSource.H
146 lines (125 loc) · 4.29 KB
/
transportSweepLinearSource.H
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//Transport Sweep Algorithm with a linear source
int sweeps=0;
do{
//Reinitialise values
err2=0.0;
forAll(flux, energyI)
{
flux[energyI]*=0.0;
fluxX[energyI]*=0.0;
fluxY[energyI]*=0.0;
}
for(int lines=0; lines<klines; lines++)
{
wa=wgta[lines]; //width and weight of line in azimuthal direction
List<label> indList=cellIndices[lines]; //list of indices of cells intersected
segNum=raySegments[lines]; //number of segments of ray
List<scalar> yIn; //set list of local y-entry co-ords
List<scalar> xIn; //set list of local x-entry co-ords
List<scalar> yC=yCCell[lines];
List<scalar> xC=xCCell[lines];
List<scalar> lengthList=segLengths[lines]; //list of azimuthal ray lengths
label i0=angleInd[lines]; //index of azimuthal angle
//Set trigonometric functions of azimuthal angle
//Should these be strictly positive? (if so make sure to remove *-1 in the direction loop)
sina=sinInd[i0];
cosa=cosInd[i0];
//Info<<sina<<endl;
//List of areas approximated by lines at given angle
List<scalar> approxAreaList=approxArea[angleInd[lines]];
forAll(flux, energyI)
{
for(int j=0; j<npo; j++)
{
wt = wa*wsintheta[j]; //combined polar weight and sintheta with azimuthal
sinT=sintheta[j];
List<scalar> f1 = F1[energyI][lines][j];
List<scalar> hFac=H[energyI][lines][j];
for(int d=0; d<2; d++)
{
yIn=yInCell[lines][d];
xIn=xInCell[lines][d];
if (d==0)
{
c1=0;
c2=segNum-1;
m=+1;
}else if (d==1)
{
c1=segNum-1;
c2=0;
m=-1;
//Should these functions be *-1?
sina*=-1;
cosa*=-1;
}
//Take boundary flux for first cell
afluxIn=aflux[energyI][j][lines][d];
for(int k=c1; k!=c2+m; k+=m)
{
label ind=indList[k];
A=area[ind];
sigT=sigmaT[energyI][ind];
scalar w_ASigT=wt/(A*sigT);
scalar s=lengthList[k];
scalar normFac=A/approxAreaList[ind];
tau=sigT*s*normFac/sinT;
//Confirmed that commenting fluxX,Y and relevant terms yields FS
//Error in hFac, qh, qX, qY, fluxX, fluxY, Cx, Cy, Cxy, Mxx, Mxy, Myy
//Calculate expansion coefficients
qb=one_over_4_PI*(Q[energyI][ind]+ xC[k]*qX[energyI][ind]
+ yC[k]*qY[energyI][ind]);
qh=one_over_4_PI*(sinT*cosa*qX[energyI][ind]
+ sinT*sina*qY[energyI][ind])*normFac;
//Calculate change in angular flux
delta=(afluxIn - qb/sigT) * f1[k]
-qh*(2*(tau-f1[k])-tau*f1[k])/(2*sigT*sigT);
//Increment scalar flux and flux moments
flux[energyI][ind] += delta*w_ASigT;
fluxX[energyI][ind] += w_ASigT*(cosa*s*afluxIn*hFac[k]+xIn[k]*delta);
fluxY[energyI][ind] += w_ASigT*(sina*s*afluxIn*hFac[k]+yIn[k]*delta);
//Calculate outgoing angular flux
afluxIn -= delta;
//Apply boundary conditions if exiting boundary cell
if (k==c2)
{
albedo=alpha[d][lines];
refRay=compRay[lines][d];
refDir=compDir[lines][d];
aflux[energyI][j][refRay][refDir]=albedo*afluxIn;
}
}
}
}
}
}
forAll(flux, energyI)
{
//Increment flux moments by source moments
fluxX[energyI].internalField()+=(qX[energyI].internalField()*Cxx[energyI].internalField()
+ qY[energyI].internalField()*Cxy[energyI].internalField())/sigmaT[energyI].internalField();
fluxY[energyI].internalField()+=(qY[energyI].internalField()*Cyy[energyI].internalField()
+ qX[energyI].internalField()*Cxy[energyI].internalField())/sigmaT[energyI].internalField();
flux[energyI].internalField() += Q[energyI].internalField()/sigmaT[energyI].internalField();
if(min(mag(flux[energyI])).value()<1e-6)
{e1 = max(mag(flux[energyI]-prevFlux[energyI])).value();}
else{e1 = max(mag(flux[energyI]-prevFlux[energyI])/flux[energyI]).value();}
if( e1>err2 ) {err2=e1;}
prevFlux[energyI]=flux[energyI];
//Check error in angular flux
forAll(aflux[energyI], j)
{
forAll(aflux[energyI][j], lines)
{
forAll(aflux[energyI][j][lines], d)
{
e1=mag(aflux[energyI][j][lines][d]-oldAflux[energyI][j][lines][d]);
if(e1>err2) {err2=e1;}
oldAflux[energyI][j][lines][d]=aflux[energyI][j][lines][d];
}
}
}
}
sweeps++;
}while( err2>1e-7);
Info<<"Transport sweep converged after "<<sweeps<<" iterations"<<endl;