Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
adjoint_pnpn_res_device.F90
Go to the documentation of this file.
1
34!
37 use gather_scatter, only : gs_t, gs_op_add
38 use operators, only : cdtp
39 use field, only : field_t
40 use ax_product, only : ax_t
41 use coefs, only : coef_t
42 use facet_normal, only : facet_normal_t
43 use adjoint_pnpn_residual, only : adjoint_pnpn_prs_res_t, &
45 use scratch_registry, only: neko_scratch_registry
46 use mesh, only : mesh_t
47 use num_types, only : rp
48 use space, only : space_t
49 use device_math, only : device_cfill, device_cmult, device_cmult2, &
50 device_col2, device_add2
51 use device, only : device_event_sync
52 use, intrinsic :: iso_c_binding, only : c_ptr
53 implicit none
54 private
55
57 contains
58 procedure, nopass :: compute => adjoint_pnpn_prs_res_device_compute
60
62 contains
63 procedure, nopass :: compute => adjoint_pnpn_vel_res_device_compute
65
66contains
67
87 subroutine adjoint_pnpn_prs_res_device_compute(p, p_res, u, v, w, &
88 f_x, f_y, f_z, c_Xh, gs_Xh, bc_prs_surface, bc_sym_surface, &
89 Ax, bd, dt, mu, rho, event)
90 type(field_t), intent(inout) :: p, u, v, w
91 type(field_t), intent(inout) :: p_res
92 type(field_t), intent(in) :: f_x, f_y, f_z
93 type(coef_t), intent(inout) :: c_Xh
94 type(gs_t), intent(inout) :: gs_Xh
95 type(facet_normal_t), intent(in) :: bc_prs_surface
96 type(facet_normal_t), intent(in) :: bc_sym_surface
97 class(ax_t), intent(inout) :: Ax
98 real(kind=rp), intent(in) :: bd
99 real(kind=rp), intent(in) :: dt
100 type(field_t), intent(in) :: mu
101 type(field_t), intent(in) :: rho
102 type(c_ptr), intent(inout) :: event
103 real(kind=rp) :: rho_val, inv_rho
104 integer :: n
105 type(field_t), pointer :: ta1, ta2, ta3, wa1, wa2, wa3
106 integer :: temp_indices(6)
107
108 call neko_scratch_registry%request_field(ta1, temp_indices(1), .false.)
109 call neko_scratch_registry%request_field(ta2, temp_indices(2), .false.)
110 call neko_scratch_registry%request_field(ta3, temp_indices(3), .false.)
111 call neko_scratch_registry%request_field(wa1, temp_indices(4), .false.)
112 call neko_scratch_registry%request_field(wa2, temp_indices(5), .false.)
113 call neko_scratch_registry%request_field(wa3, temp_indices(6), .false.)
114
115 n = u%dof%size()
116
117 ! We assume the material properties are constant
118 rho_val = rho%x(1,1,1,1)
119 inv_rho = 1.0_rp / rho_val
120
121 c_xh%ifh2 = .false.
122 call device_cfill(c_xh%h1_d, inv_rho, n)
123 call device_cfill(c_xh%h2_d, 0.0_rp, n)
124
125 call device_cmult2(ta1%x_d, f_x%x_d, inv_rho, n)
126 call device_cmult2(ta2%x_d, f_y%x_d, inv_rho, n)
127 call device_cmult2(ta3%x_d, f_z%x_d, inv_rho, n)
128
129 call device_col2(ta1%x_d, c_xh%B_d, n)
130 call device_col2(ta2%x_d, c_xh%B_d, n)
131 call device_col2(ta3%x_d, c_xh%B_d, n)
132
133 call gs_xh%op(ta1, gs_op_add, event)
134 call gs_xh%op(ta2, gs_op_add, event)
135 call gs_xh%op(ta3, gs_op_add, event)
136 call device_event_sync(event)
137
138 call device_col2(ta1%x_d, c_xh%Binv_d, n)
139 call device_col2(ta2%x_d, c_xh%Binv_d, n)
140 call device_col2(ta3%x_d, c_xh%Binv_d, n)
141
142 call cdtp(wa1%x, ta1%x, c_xh%drdx, c_xh%dsdx, c_xh%dtdx, c_xh)
143 call cdtp(wa2%x, ta2%x, c_xh%drdy, c_xh%dsdy, c_xh%dtdy, c_xh)
144 call cdtp(wa3%x, ta3%x, c_xh%drdz, c_xh%dsdz, c_xh%dtdz, c_xh)
145
146 call ax%compute(p_res%x, p%x, c_xh, p%msh, p%Xh)
147
148 call device_cmult(p_res%x_d, -1.0_rp, n)
149 call device_add2(p_res%x_d, wa1%x_d, n)
150 call device_add2(p_res%x_d, wa2%x_d, n)
151 call device_add2(p_res%x_d, wa3%x_d, n)
152
153 call neko_scratch_registry%relinquish_field(temp_indices)
155
176 subroutine adjoint_pnpn_vel_res_device_compute(Ax, u, v, w, u_res, &
177 v_res, w_res, p, f_x, f_y, f_z, c_Xh, msh, Xh, mu, rho, bd, dt, n)
178 class(ax_t), intent(in) :: Ax
179 type(mesh_t), intent(inout) :: msh
180 type(space_t), intent(inout) :: Xh
181 type(field_t), intent(inout) :: p, u, v, w
182 type(field_t), intent(inout) :: u_res, v_res, w_res
183 type(field_t), intent(in) :: f_x, f_y, f_z
184 type(coef_t), intent(inout) :: c_Xh
185 type(field_t), intent(in) :: mu
186 type(field_t), intent(in) :: rho
187 real(kind=rp), intent(in) :: bd
188 real(kind=rp), intent(in) :: dt
189 integer, intent(in) :: n
190 real(kind=rp) :: mu_val, rho_val
191
192 ! We assume the material properties are constant
193 mu_val = mu%x(1,1,1,1)
194 rho_val = rho%x(1,1,1,1)
195
196 call device_cfill(c_xh%h1_d, mu_val, n)
197 call device_cfill(c_xh%h2_d, rho_val * (bd / dt), n)
198 c_xh%ifh2 = .true.
199
200 call ax%compute_vector(u_res%x, v_res%x, w_res%x, u%x, v%x, w%x, c_xh, &
201 msh, xh)
202
203 call device_cmult(u_res%x_d, -1.0_rp, n)
204 call device_add2(u_res%x_d, f_x%x_d, n)
205
206 call device_cmult(v_res%x_d, -1.0_rp, n)
207 call device_add2(v_res%x_d, f_y%x_d, n)
208
209 call device_cmult(w_res%x_d, -1.0_rp, n)
210 call device_add2(w_res%x_d, f_z%x_d, n)
211 end subroutine adjoint_pnpn_vel_res_device_compute
212
Residuals in the Pn-Pn formulation (device backend)
subroutine adjoint_pnpn_prs_res_device_compute(p, p_res, u, v, w, f_x, f_y, f_z, c_xh, gs_xh, bc_prs_surface, bc_sym_surface, ax, bd, dt, mu, rho, event)
Compute adjoint pressure residual (device backend).
Abstract type to compute pressure residual.
Abstract type to compute velocity residual.