Skip to content

Commit b19bd91

Browse files
authored
Merge pull request xcompact3d#26 from semi-h/feature
Add divergence and gradient
2 parents 29677ec + 3790085 commit b19bd91

File tree

5 files changed

+370
-11
lines changed

5 files changed

+370
-11
lines changed

src/backend.f90

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ module m_base_backend
3030
procedure(tds_solve), deferred :: tds_solve
3131
procedure(transposer), deferred :: trans_x2y
3232
procedure(transposer), deferred :: trans_x2z
33+
procedure(trans_d2d), deferred :: trans_y2z
34+
procedure(trans_d2d), deferred :: trans_z2y
35+
procedure(trans_d2d), deferred :: trans_y2x
3336
procedure(sum9into3), deferred :: sum_yzintox
37+
procedure(vecadd), deferred :: vecadd
3438
procedure(get_fields), deferred :: get_fields
3539
procedure(set_fields), deferred :: set_fields
3640
procedure(alloc_tdsops), deferred :: alloc_tdsops
@@ -90,6 +94,20 @@ subroutine transposer(self, u_, v_, w_, u, v, w)
9094
class(field_t), intent(inout) :: u_, v_, w_
9195
class(field_t), intent(in) :: u, v, w
9296
end subroutine transposer
97+
98+
subroutine trans_d2d(self, u_, u)
99+
!! transposer subroutines are straightforward, they rearrange
100+
!! data into our specialist data structure so that regardless
101+
!! of the direction tridiagonal systems are solved efficiently
102+
!! and fast.
103+
import :: base_backend_t
104+
import :: field_t
105+
implicit none
106+
107+
class(base_backend_t) :: self
108+
class(field_t), intent(inout) :: u_
109+
class(field_t), intent(in) :: u
110+
end subroutine trans_d2d
93111
end interface
94112

95113
abstract interface
@@ -106,6 +124,22 @@ subroutine sum9into3(self, du, dv, dw, du_y, dv_y, dw_y, du_z, dv_z, dw_z)
106124
end subroutine sum9into3
107125
end interface
108126

127+
abstract interface
128+
subroutine vecadd(self, a, x, b, y)
129+
!! adds two vectors together: y = a*x + b*y
130+
import :: base_backend_t
131+
import :: dp
132+
import :: field_t
133+
implicit none
134+
135+
class(base_backend_t) :: self
136+
real(dp), intent(in) :: a
137+
class(field_t), intent(in) :: x
138+
real(dp), intent(in) :: b
139+
class(field_t), intent(inout) :: y
140+
end subroutine vecadd
141+
end interface
142+
109143
abstract interface
110144
subroutine get_fields(self, u_out, v_out, w_out, u, v, w)
111145
!! copy the specialist data structure from device or host back
@@ -136,7 +170,8 @@ end subroutine set_fields
136170
end interface
137171

138172
abstract interface
139-
subroutine alloc_tdsops(self, tdsops, n, dx, operation, scheme)
173+
subroutine alloc_tdsops(self, tdsops, n, dx, operation, scheme, n_halo, &
174+
from_to, bc_start, bc_end, sym, c_nu, nu0_nu)
140175
import :: base_backend_t
141176
import :: dp
142177
import :: tdsops_t
@@ -147,6 +182,10 @@ subroutine alloc_tdsops(self, tdsops, n, dx, operation, scheme)
147182
integer, intent(in) :: n
148183
real(dp), intent(in) :: dx
149184
character(*), intent(in) :: operation, scheme
185+
integer, optional, intent(in) :: n_halo
186+
character(*), optional, intent(in) :: from_to, bc_start, bc_end
187+
logical, optional, intent(in) :: sym
188+
real(dp), optional, intent(in) :: c_nu, nu0_nu
150189
end subroutine alloc_tdsops
151190
end interface
152191

src/cuda/backend.f90

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ module m_cuda_backend
3434
procedure :: tds_solve => tds_solve_cuda
3535
procedure :: trans_x2y => trans_x2y_cuda
3636
procedure :: trans_x2z => trans_x2z_cuda
37+
procedure :: trans_y2z => trans_y2z_cuda
38+
procedure :: trans_z2y => trans_z2y_cuda
39+
procedure :: trans_y2x => trans_y2x_cuda
3740
procedure :: sum_yzintox => sum_yzintox_cuda
41+
procedure :: vecadd => vecadd_cuda
3842
procedure :: set_fields => set_fields_cuda
3943
procedure :: get_fields => get_fields_cuda
4044
procedure :: transeq_cuda_dist
@@ -101,20 +105,28 @@ function init(globs, allocator) result(backend)
101105

102106
end function init
103107

104-
subroutine alloc_cuda_tdsops(self, tdsops, n, dx, operation, scheme)
108+
subroutine alloc_cuda_tdsops( &
109+
self, tdsops, n, dx, operation, scheme, &
110+
n_halo, from_to, bc_start, bc_end, sym, c_nu, nu0_nu &
111+
)
105112
implicit none
106113

107114
class(cuda_backend_t) :: self
108115
class(tdsops_t), allocatable, intent(inout) :: tdsops
109116
integer, intent(in) :: n
110117
real(dp), intent(in) :: dx
111118
character(*), intent(in) :: operation, scheme
119+
integer, optional, intent(in) :: n_halo
120+
character(*), optional, intent(in) :: from_to, bc_start, bc_end
121+
logical, optional, intent(in) :: sym
122+
real(dp), optional, intent(in) :: c_nu, nu0_nu
112123

113124
allocate(cuda_tdsops_t :: tdsops)
114125

115126
select type (tdsops)
116127
type is (cuda_tdsops_t)
117-
tdsops = cuda_tdsops_t(n, dx, operation, scheme)
128+
tdsops = cuda_tdsops_t(n, dx, operation, scheme, n_halo, from_to, &
129+
bc_start, bc_end, sym, c_nu, nu0_nu)
118130
end select
119131

120132
end subroutine alloc_cuda_tdsops
@@ -421,6 +433,33 @@ subroutine trans_x2z_cuda(self, u_z, v_z, w_z, u, v, w)
421433

422434
end subroutine trans_x2z_cuda
423435

436+
subroutine trans_y2z_cuda(self, u_z, u_y)
437+
implicit none
438+
439+
class(cuda_backend_t) :: self
440+
class(field_t), intent(inout) :: u_z
441+
class(field_t), intent(in) :: u_y
442+
443+
end subroutine trans_y2z_cuda
444+
445+
subroutine trans_z2y_cuda(self, u_y, u_z)
446+
implicit none
447+
448+
class(cuda_backend_t) :: self
449+
class(field_t), intent(inout) :: u_y
450+
class(field_t), intent(in) :: u_z
451+
452+
end subroutine trans_z2y_cuda
453+
454+
subroutine trans_y2x_cuda(self, u_x, u_y)
455+
implicit none
456+
457+
class(cuda_backend_t) :: self
458+
class(field_t), intent(inout) :: u_x
459+
class(field_t), intent(in) :: u_y
460+
461+
end subroutine trans_y2x_cuda
462+
424463
subroutine sum_yzintox_cuda(self, du, dv, dw, &
425464
du_y, dv_y, dw_y, du_z, dv_z, dw_z)
426465
implicit none
@@ -431,6 +470,17 @@ subroutine sum_yzintox_cuda(self, du, dv, dw, &
431470

432471
end subroutine sum_yzintox_cuda
433472

473+
subroutine vecadd_cuda(self, a, x, b, y)
474+
implicit none
475+
476+
class(cuda_backend_t) :: self
477+
real(dp), intent(in) :: a
478+
class(field_t), intent(in) :: x
479+
real(dp), intent(in) :: b
480+
class(field_t), intent(inout) :: y
481+
482+
end subroutine vecadd_cuda
483+
434484
subroutine copy_into_buffers(u_send_s_dev, u_send_e_dev, u_dev, n)
435485
implicit none
436486

src/omp/backend.f90

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ module m_omp_backend
2626
procedure :: tds_solve => tds_solve_omp
2727
procedure :: trans_x2y => trans_x2y_omp
2828
procedure :: trans_x2z => trans_x2z_omp
29+
procedure :: trans_y2z => trans_y2z_omp
30+
procedure :: trans_z2y => trans_z2y_omp
31+
procedure :: trans_y2x => trans_y2x_omp
2932
procedure :: sum_yzintox => sum_yzintox_omp
33+
procedure :: vecadd => vecadd_omp
3034
procedure :: set_fields => set_fields_omp
3135
procedure :: get_fields => get_fields_omp
3236
end type omp_backend_t
@@ -83,20 +87,28 @@ function init(globs, allocator) result(backend)
8387

8488
end function init
8589

86-
subroutine alloc_omp_tdsops(self, tdsops, n, dx, operation, scheme)
90+
subroutine alloc_omp_tdsops( &
91+
self, tdsops, n, dx, operation, scheme, &
92+
n_halo, from_to, bc_start, bc_end, sym, c_nu, nu0_nu &
93+
)
8794
implicit none
8895

8996
class(omp_backend_t) :: self
9097
class(tdsops_t), allocatable, intent(inout) :: tdsops
9198
integer, intent(in) :: n
9299
real(dp), intent(in) :: dx
93100
character(*), intent(in) :: operation, scheme
101+
integer, optional, intent(in) :: n_halo
102+
character(*), optional, intent(in) :: from_to, bc_start, bc_end
103+
logical, optional, intent(in) :: sym
104+
real(dp), optional, intent(in) :: c_nu, nu0_nu
94105

95106
allocate(tdsops_t :: tdsops)
96107

97108
select type (tdsops)
98109
type is (tdsops_t)
99-
tdsops = tdsops_t(n, dx, operation, scheme)
110+
tdsops = tdsops_t(n, dx, operation, scheme, n_halo, from_to, &
111+
bc_start, bc_end, sym, c_nu, nu0_nu)
100112
end select
101113

102114
end subroutine alloc_omp_tdsops
@@ -170,6 +182,33 @@ subroutine trans_x2z_omp(self, u_, v_, w_, u, v, w)
170182

171183
end subroutine trans_x2z_omp
172184

185+
subroutine trans_y2z_omp(self, u_, u)
186+
implicit none
187+
188+
class(omp_backend_t) :: self
189+
class(field_t), intent(inout) :: u_
190+
class(field_t), intent(in) :: u
191+
192+
end subroutine trans_y2z_omp
193+
194+
subroutine trans_z2y_omp(self, u_, u)
195+
implicit none
196+
197+
class(omp_backend_t) :: self
198+
class(field_t), intent(inout) :: u_
199+
class(field_t), intent(in) :: u
200+
201+
end subroutine trans_z2y_omp
202+
203+
subroutine trans_y2x_omp(self, u_, u)
204+
implicit none
205+
206+
class(omp_backend_t) :: self
207+
class(field_t), intent(inout) :: u_
208+
class(field_t), intent(in) :: u
209+
210+
end subroutine trans_y2x_omp
211+
173212
subroutine sum_yzintox_omp(self, du, dv, dw, &
174213
du_y, dv_y, dw_y, du_z, dv_z, dw_z)
175214
implicit none
@@ -180,6 +219,17 @@ subroutine sum_yzintox_omp(self, du, dv, dw, &
180219

181220
end subroutine sum_yzintox_omp
182221

222+
subroutine vecadd_omp(self, a, x, b, y)
223+
implicit none
224+
225+
class(omp_backend_t) :: self
226+
real(dp), intent(in) :: a
227+
class(field_t), intent(in) :: x
228+
real(dp), intent(in) :: b
229+
class(field_t), intent(inout) :: y
230+
231+
end subroutine vecadd_omp
232+
183233
subroutine copy_into_buffers(u_send_s, u_send_e, u, n)
184234
implicit none
185235

0 commit comments

Comments
 (0)