Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
adjoint_pnpn_res_cpu.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 math, only : cfill, col3, cmult, col2, chsign, add2
50 use, intrinsic :: iso_c_binding, only : c_ptr
51 implicit none
52 private
53
55 contains
56 procedure, nopass :: compute => adjoint_pnpn_prs_res_cpu_compute
58
60 contains
61 procedure, nopass :: compute => adjoint_pnpn_vel_res_cpu_compute
63
64contains
65
85 subroutine adjoint_pnpn_prs_res_cpu_compute(p, p_res, u, v, w, &
86 f_x, f_y, f_z, c_Xh, gs_Xh, bc_prs_surface, bc_sym_surface, &
87 Ax, bd, dt, mu, rho, event)
88 type(field_t), intent(inout) :: p, u, v, w
89 type(field_t), intent(inout) :: p_res
90 type(field_t), intent(in) :: f_x, f_y, f_z
91 type(coef_t), intent(inout) :: c_Xh
92 type(gs_t), intent(inout) :: gs_Xh
93 type(facet_normal_t), intent(in) :: bc_prs_surface
94 type(facet_normal_t), intent(in) :: bc_sym_surface
95 class(ax_t), intent(inout) :: Ax
96 real(kind=rp), intent(in) :: bd
97 real(kind=rp), intent(in) :: dt
98 type(field_t), intent(in) :: mu
99 type(field_t), intent(in) :: rho
100 type(c_ptr), intent(inout) :: event
101 real(kind=rp) :: rho_val
102 integer :: n
103 type(field_t), pointer :: ta1, ta2, ta3, wa1, wa2, wa3
104 integer :: temp_indices(6)
105
106 call neko_scratch_registry%request_field(ta1, temp_indices(1), .false.)
107 call neko_scratch_registry%request_field(ta2, temp_indices(2), .false.)
108 call neko_scratch_registry%request_field(ta3, temp_indices(3), .false.)
109 call neko_scratch_registry%request_field(wa1, temp_indices(4), .false.)
110 call neko_scratch_registry%request_field(wa2, temp_indices(5), .false.)
111 call neko_scratch_registry%request_field(wa3, temp_indices(6), .false.)
112
113 n = c_xh%dof%size()
114
115 ! We assume the material properties are constant
116 rho_val = rho%x(1,1,1,1)
117 call cfill(c_xh%h1, 1.0_rp / rho_val, n)
118 call cfill(c_xh%h2, 0.0_rp, n)
119 c_xh%ifh2 = .false.
120
121 call col3(ta1%x, f_x%x, c_xh%B, n)
122 call col3(ta2%x, f_y%x, c_xh%B, n)
123 call col3(ta3%x, f_z%x, c_xh%B, n)
124 call cmult(ta1%x, 1.0_rp / rho_val, n)
125 call cmult(ta2%x, 1.0_rp / rho_val, n)
126 call cmult(ta3%x, 1.0_rp / rho_val, n)
127
128 call gs_xh%op(ta1, gs_op_add)
129 call gs_xh%op(ta2, gs_op_add)
130 call gs_xh%op(ta3, gs_op_add)
131
132 call col2(ta1%x, c_xh%Binv, n)
133 call col2(ta2%x, c_xh%Binv, n)
134 call col2(ta3%x, c_xh%Binv, n)
135
136 call cdtp(wa1%x, ta1%x, c_xh%drdx, c_xh%dsdx, c_xh%dtdx, c_xh)
137 call cdtp(wa2%x, ta2%x, c_xh%drdy, c_xh%dsdy, c_xh%dtdy, c_xh)
138 call cdtp(wa3%x, ta3%x, c_xh%drdz, c_xh%dsdz, c_xh%dtdz, c_xh)
139
140 ! maybe I'm missing a mu??
141
142 call ax%compute(p_res%x, p%x, c_xh, p%msh, p%Xh)
143
144 call chsign(p_res%x, n)
145 call add2(p_res%x, wa1%x, n)
146 call add2(p_res%x, wa2%x, n)
147 call add2(p_res%x, wa3%x, n)
148
149 ! This is commented out because I don't think it applies any more... but
150 ! sym BCs haven't been tested thoroughly.
151 ! !
152 ! ! Surface velocity terms
153 ! !
154 ! do concurrent (i = 1:n)
155 ! wa1%x(i,1,1,1) = 0.0_rp
156 ! wa2%x(i,1,1,1) = 0.0_rp
157 ! wa3%x(i,1,1,1) = 0.0_rp
158 ! end do
159
160 ! call bc_sym_surface%apply_surfvec(wa1%x, wa2%x, wa3%x, ta1%x, ta2%x, &
161 ! ta3%x,&
162 ! n)
163
164 ! dtbd = bd / dt
165 ! do concurrent (i = 1:n)
166 ! ta1%x(i,1,1,1) = 0.0_rp
167 ! ta2%x(i,1,1,1) = 0.0_rp
168 ! ta3%x(i,1,1,1) = 0.0_rp
169 ! end do
170
171 ! call bc_prs_surface%apply_surfvec(ta1%x, ta2%x, ta3%x, u%x, v%x, w%x, n)
172
173 ! do concurrent (i = 1:n)
174 ! p_res%x(i,1,1,1) = p_res%x(i,1,1,1) &
175 ! - (dtbd * (ta1%x(i,1,1,1) + ta2%x(i,1,1,1) + ta3%x(i,1,1,1))) &
176 ! - (wa1%x(i,1,1,1) + wa2%x(i,1,1,1) + wa3%x(i,1,1,1))
177 ! end do
178
179 call neko_scratch_registry%relinquish_field(temp_indices)
180
182
203 subroutine adjoint_pnpn_vel_res_cpu_compute(Ax, u, v, w, u_res, &
204 v_res, w_res, p, f_x, f_y, f_z, c_Xh, msh, Xh, mu, rho, bd, dt, n)
205 class(ax_t), intent(in) :: Ax
206 type(mesh_t), intent(inout) :: msh
207 type(space_t), intent(inout) :: Xh
208 type(field_t), intent(inout) :: p, u, v, w
209 type(field_t), intent(inout) :: u_res, v_res, w_res
210 type(field_t), intent(in) :: f_x, f_y, f_z
211 type(coef_t), intent(inout) :: c_Xh
212 type(field_t), intent(in) :: mu
213 type(field_t), intent(in) :: rho
214 real(kind=rp), intent(in) :: bd
215 real(kind=rp), intent(in) :: dt
216 integer, intent(in) :: n
217 real(kind=rp) :: rho_val, mu_val
218 ! We assume the material properties are constant
219 rho_val = rho%x(1,1,1,1)
220 mu_val = mu%x(1,1,1,1)
221
222 call cfill(c_xh%h1, mu_val, n)
223 call cfill(c_xh%h2, rho_val * bd / dt, n)
224 c_xh%ifh2 = .true.
225
226 call ax%compute(u_res%x, u%x, c_xh, msh, xh)
227 call ax%compute(v_res%x, v%x, c_xh, msh, xh)
228 call ax%compute(w_res%x, w%x, c_xh, msh, xh)
229
230 call chsign(u_res%x, n)
231 call chsign(v_res%x, n)
232 call chsign(w_res%x, n)
233 call add2(u_res%x, f_x%x, n)
234 call add2(v_res%x, f_y%x, n)
235 call add2(w_res%x, f_z%x, n)
236
237 end subroutine adjoint_pnpn_vel_res_cpu_compute
238
239end module adjoint_pnpn_res_cpu
Residuals in the Pn-Pn formulation (CPU version)
subroutine adjoint_pnpn_prs_res_cpu_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 (CPU backend).
Abstract type to compute pressure residual.
Abstract type to compute velocity residual.