Skip to content

Commit 68ca9de

Browse files
author
Milan K
authored
Merge pull request #127 from milankl/Tcomm
Ghost points type stable with Tcomm
2 parents 629992d + e601308 commit 68ca9de

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

src/GhostPoints.jl

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,22 @@ function ghost_points_u_nonperiodic!(C::Constants,u::AbstractMatrix)
5656
end
5757

5858
""" Copy ghost points for u from inside to the halo in the periodic case. """
59-
function ghost_points_u_periodic!(C::Constants,u::AbstractMatrix)
59+
function ghost_points_u_periodic!(::Type{Tcomm},u::Array{T,2},C::Constants) where {Tcomm,T}
6060

6161
@unpack one_minus_α = C
6262

63-
# periodic bc
64-
@views @inbounds u[1,:] .= u[end-3,:]
65-
@views @inbounds u[2,:] .= u[end-2,:]
66-
@views @inbounds u[end-1,:] .= u[3,:]
67-
@views @inbounds u[end,:] .= u[4,:]
63+
# periodic bc - mimic MPI communication with (reduced precision) type Tcomm
64+
@views @inbounds u[1,:] .= T.(Tcomm.(u[end-3,:]))
65+
@views @inbounds u[2,:] .= T.(Tcomm.(u[end-2,:]))
66+
@views @inbounds u[end-1,:] .= T.(Tcomm.(u[3,:]))
67+
@views @inbounds u[end,:] .= T.(Tcomm.(u[4,:]))
6868

6969
# tangential bc
7070
@views @inbounds u[:,1] .= one_minus_α*u[:,4]
7171
@views @inbounds u[:,2] .= one_minus_α*u[:,3]
7272
@views @inbounds u[:,end-1] .= one_minus_α*u[:,end-2]
7373
@views @inbounds u[:,end] .= one_minus_α*u[:,end-3]
7474

75-
# # periodic bc
76-
# @views copyto!(u[1,:],u[end-3,:])
77-
# @views copyto!(u[2,:],u[end-2,:])
78-
# @views copyto!(u[end-1,:],u[3,:])
79-
# @views copyto!(u[end,:],u[4,:])
80-
#
81-
# # tangential bc
82-
# @views copyto!(u[:,1],one_minus_α.*u[:,4])
83-
# @views copyto!(u[:,2],one_minus_α.*u[:,3])
84-
# @views copyto!(u[:,end-1],one_minus_α.*u[:,end-2])
85-
# @views copyto!(u[:,end],one_minus_α.*u[:,end-3])
8675
end
8776

8877
""" Copy ghost points for v from inside to the halo in the nonperiodic case. """
@@ -98,13 +87,13 @@ function ghost_points_v_nonperiodic!(C::Constants,v::AbstractMatrix)
9887
end
9988

10089
""" Copy ghost points for v from inside to the halo in the periodic case. """
101-
function ghost_points_v_periodic!(v::AbstractMatrix)
90+
function ghost_points_v_periodic!(::Type{Tcomm},v::Array{T,2}) where {Tcomm,T}
10291

103-
# tangential boundary condition
104-
@views @inbounds v[1,:] .= v[end-3,:]
105-
@views @inbounds v[2,:] .= v[end-2,:]
106-
@views @inbounds v[end-1,:] .= v[3,:]
107-
@views @inbounds v[end,:] .= v[4,:]
92+
# tangential boundary condition - mimic MPI communication with (reduced precision) type Tcomm
93+
@views @inbounds v[1,:] .= T.(Tcomm.(v[end-3,:]))
94+
@views @inbounds v[2,:] .= T.(Tcomm.(v[end-2,:]))
95+
@views @inbounds v[end-1,:] .= T.(Tcomm.(v[3,:]))
96+
@views @inbounds v[end,:] .= T.(Tcomm.(v[4,:]))
10897
end
10998

11099
""" Copy ghost points for η from inside to the halo in the nonperiodic case. """
@@ -120,14 +109,15 @@ function ghost_points_η_nonperiodic!(η::AbstractMatrix)
120109
end
121110

122111
""" Copy ghost points for η from inside to the halo in the periodic case. """
123-
function ghost_points_η_periodic!::AbstractMatrix)
112+
function ghost_points_η_periodic!(::Type{Tcomm},η::Array{T,2}) where {Tcomm,T}
124113

125114
# corner points are copied twice, but it's faster!
126-
@views @inbounds η[1,:] .= η[end-1,:]
127-
@views @inbounds η[end,:] .= η[2,:]
115+
# mimic MPI communication with (reduced precision) type Tcomm
116+
@views @inbounds η[1,:] .= T.(Tcomm.(η[end-1,:]))
117+
@views @inbounds η[end,:] .= T.(Tcomm.(η[2,:]))
128118

129-
@views @inbounds η[:,1] .= η[:,2]
130-
@views @inbounds η[:,end] .= η[:,end-1]
119+
@views @inbounds η[:,1] .= T.(Tcomm.(η[:,2]))
120+
@views @inbounds η[:,end] .= T.(Tcomm.(η[:,end-1]))
131121
end
132122

133123
""" Copy ghost points for η from inside to the halo in the nonperiodic case. """
@@ -149,14 +139,14 @@ function ghost_points_sst_nonperiodic!(G::Grid,sst::AbstractMatrix)
149139
end
150140

151141
""" Copy ghost points for η from inside to the halo in the periodic case. """
152-
function ghost_points_sst_periodic!(G::Grid,sst::AbstractMatrix)
142+
function ghost_points_sst_periodic!(::Type{Tcomm},sst::Array{T,2},G::Grid) where {Tcomm,T}
153143

154144
@unpack halosstx,halossty = G
155145

156146
# corner points are copied twice, but it's faster!
157147
for i 1:halosstx
158-
@views @inbounds sst[i,:] .= sst[end-2*halosstx+i,:]
159-
@views @inbounds sst[end-halosstx+i,:] .= sst[halosstx+i,:]
148+
@views @inbounds sst[i,:] .= T.(Tcomm.(sst[end-2*halosstx+i,:]))
149+
@views @inbounds sst[end-halosstx+i,:] .= T.(Tcomm.(sst[halosstx+i,:]))
160150
end
161151

162152
for j 1:halossty
@@ -175,9 +165,10 @@ function ghost_points!( u::AbstractMatrix,
175165
C = S.constants
176166

177167
if bc == "periodic"
178-
ghost_points_u_periodic!(C,u)
179-
ghost_points_v_periodic!(v)
180-
ghost_points_η_periodic!(η)
168+
@unpack Tcomm = S.parameters
169+
ghost_points_u_periodic!(Tcomm,u,C)
170+
ghost_points_v_periodic!(Tcomm,v)
171+
ghost_points_η_periodic!(Tcomm,η)
181172
else
182173
ghost_points_u_nonperiodic!(C,u)
183174
ghost_points_v_nonperiodic!(C,v)
@@ -192,7 +183,8 @@ function ghost_points_sst!(sst::AbstractMatrix,S::ModelSetup)
192183
G = S.grid
193184

194185
if bc == "periodic"
195-
ghost_points_sst_periodic!(G,sst)
186+
@unpack Tcomm = S.parameters
187+
ghost_points_sst_periodic!(Tcomm,sst,G)
196188
else
197189
ghost_points_sst_nonperiodic!(G,sst)
198190
end

0 commit comments

Comments
 (0)