perf: added threading
[skip ci]
This commit is contained in:
parent
fe7f5c9b4a
commit
97e318ff5d
@ -157,10 +157,10 @@ end
|
||||
|
||||
function FTCS_1D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T}
|
||||
colMax = getCols(grid)
|
||||
sx = timestep / getDeltaCol(grid) * getDeltaCol(grid)
|
||||
sx = timestep / (getDeltaCol(grid)^2)
|
||||
|
||||
# matrix for concentrations at time t+1
|
||||
concentrations_t1 = zeros(1, colMax)
|
||||
concentrations = getConcentrations(grid)
|
||||
concentrations_t1 = copy(concentrations)
|
||||
|
||||
# only one row in 1D case -> row constant at index 1
|
||||
row = 1
|
||||
@ -168,17 +168,14 @@ function FTCS_1D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T}
|
||||
# inner cells
|
||||
# independent of boundary condition type
|
||||
for col = 2:colMax-1
|
||||
concentrations_t1[row, col] = getConcentrations(grid)[row, col] +
|
||||
sx * calcHorizontalChange(grid, row, col)
|
||||
concentrations_t1[row, col] += sx * calcHorizontalChange(grid, row, col)
|
||||
end
|
||||
|
||||
# left boundary; hold column constant at index 1
|
||||
concentrations_t1[row, 1] = getConcentrations(grid)[row, 1] +
|
||||
sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1)
|
||||
concentrations_t1[row, 1] += sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1)
|
||||
|
||||
# right boundary; hold column constant at max index
|
||||
concentrations_t1[row, colMax] = getConcentrations(grid)[row, colMax] +
|
||||
sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax)
|
||||
concentrations_t1[row, colMax] += sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax)
|
||||
|
||||
# overwrite obsolete concentrations
|
||||
setConcentrations!(grid, concentrations_t1)
|
||||
@ -193,9 +190,7 @@ function FTCS_2D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T}
|
||||
concentrations = getConcentrations(grid)
|
||||
concentrations_t1 = copy(concentrations)
|
||||
|
||||
# inner cells
|
||||
# these are independent of the boundary condition type
|
||||
for row = 2:rowMax-1
|
||||
Threads.@threads for row = 2:rowMax-1
|
||||
# inner cells
|
||||
for col = 2:colMax-1
|
||||
concentrations_t1[row, col] += sy * calcVerticalChange(grid, row, col) +
|
||||
@ -205,16 +200,18 @@ function FTCS_2D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T}
|
||||
# left boundary without corners
|
||||
concentrations_t1[row, 1] += sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1) +
|
||||
sy * calcVerticalChange(grid, row, 1)
|
||||
|
||||
# right boundary without corners
|
||||
concentrations_t1[row, colMax] += sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax) +
|
||||
sy * calcVerticalChange(grid, row, colMax)
|
||||
end
|
||||
|
||||
# top / bottom without corners / looping over columns
|
||||
for col = 2:colMax-1
|
||||
Threads.@threads for col = 2:colMax-1
|
||||
# top
|
||||
concentrations_t1[1, col] += sy * calcVerticalChangeTopBoundary(grid, bc, 1, col) +
|
||||
sx * calcHorizontalChange(grid, 1, col)
|
||||
|
||||
# bottom
|
||||
concentrations_t1[rowMax, col] += sy * calcVerticalChangeBottomBoundary(grid, bc, rowMax, col) +
|
||||
sx * calcHorizontalChange(grid, rowMax, col)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user