38 use num_types,
only: rp
39 use field_list,
only: field_list_t
40 use field,
only: field_t
41 use json_module,
only: json_file
42 use time_state,
only: time_state_t
43 use source_term,
only: source_term_t
44 use interpolation,
only: interpolator_t
45 use space,
only: space_t, gl
46 use coefs,
only: coef_t
47 use field_math,
only: field_subcol3, field_sub2, field_col3
48 use operators,
only: grad, dudxyz
49 use utils,
only: neko_error
50 use gather_scatter,
only: gs_op_add
51 use scratch_registry,
only: neko_scratch_registry, scratch_registry_t
52 use neko_config,
only: neko_bcknd_device
54 use device_math,
only: device_col2
68 type,
public,
extends(source_term_t) :: &
71 type(field_t),
pointer :: s_adj => null()
73 type(field_t),
pointer :: s => null()
76 type(space_t),
pointer :: xh_gll
78 type(space_t),
pointer :: xh_gl
80 type(coef_t),
pointer :: c_xh_gl
82 type(interpolator_t),
pointer :: gll_to_gl
86 type(scratch_registry_t),
pointer :: scratch_gl
90 procedure, pass(this) :: init => &
91 adjoint_scalar_convection_source_term_init_from_json
93 procedure, pass(this) :: init_from_components => &
94 adjoint_scalar_convection_source_term_init_from_components
96 procedure, pass(this) :: free => adjoint_scalar_convection_source_term_free
98 procedure, pass(this) :: compute_ => &
99 adjoint_scalar_convection_source_term_compute
106 class(source_term_t),
allocatable,
intent(inout) :: obj
116 subroutine adjoint_scalar_convection_source_term_init_from_json(this, &
117 json, fields, coef, variable_name)
119 type(json_file),
intent(inout) :: json
120 type(field_list_t),
intent(in),
target :: fields
121 type(coef_t),
intent(in),
target :: coef
122 character(len=*),
intent(in) :: variable_name
132 end subroutine adjoint_scalar_convection_source_term_init_from_json
144 subroutine adjoint_scalar_convection_source_term_init_from_components(this,&
145 f_x, f_y, f_z, s, s_adj, coef, c_Xh_GL, GLL_to_GL, dealias, scratch_GL)
147 type(field_t),
pointer,
intent(in) :: f_x, f_y, f_z
148 type(field_t),
intent(in),
target :: s, s_adj
149 type(coef_t),
intent(in),
target :: coef
150 type(coef_t),
intent(in),
target :: c_xh_gl
151 type(interpolator_t),
intent(in),
target :: gll_to_gl
152 logical,
intent(in) :: dealias
153 type(scratch_registry_t),
intent(in),
target :: scratch_gl
155 type(field_list_t) :: fields
156 real(kind=rp) :: start_time
157 real(kind=rp) :: end_time
162 end_time = 100000000.0_rp
169 call fields%assign(1, f_x)
170 call fields%assign(2, f_y)
171 call fields%assign(3, f_z)
173 call this%init_base(fields, coef, start_time, end_time)
181 this%dealias = dealias
182 this%c_Xh_GL => c_xh_gl
183 this%Xh_GL => this%c_Xh_GL%Xh
184 this%Xh_GLL => this%coef%Xh
185 this%GLL_to_GL => gll_to_gl
186 this%scratch_GL => scratch_gl
188 end subroutine adjoint_scalar_convection_source_term_init_from_components
191 subroutine adjoint_scalar_convection_source_term_free(this)
194 call this%free_base()
197 nullify(this%c_Xh_GL)
200 nullify(this%GLL_to_GL)
201 nullify(this%scratch_GL)
203 end subroutine adjoint_scalar_convection_source_term_free
208 subroutine adjoint_scalar_convection_source_term_compute(this, time)
210 type(time_state_t),
intent(in) :: time
211 type(field_t),
pointer :: fu, fv, fw
212 integer :: temp_indices(4)
213 type(field_t),
pointer :: dsdx, dsdy, dsdz, work
214 type(field_t),
pointer :: accumulate, fld_gl, s_gl, s_adj_gl
215 integer :: temp_indices_gl(4)
219 call neko_scratch_registry%request_field(dsdx, temp_indices(1), .false.)
220 call neko_scratch_registry%request_field(dsdy, temp_indices(2), .false.)
221 call neko_scratch_registry%request_field(dsdz, temp_indices(3), .false.)
222 call neko_scratch_registry%request_field(work, temp_indices(4), .false.)
224 fu => this%fields%get(1)
225 fv => this%fields%get(2)
226 fw => this%fields%get(3)
229 if (this%dealias)
then
230 nel = this%coef%msh%nelv
231 n_gl = nel * this%Xh_GL%lxyz
232 call this%scratch_GL%request_field(accumulate, temp_indices_gl(1), .false.)
233 call this%scratch_GL%request_field(fld_gl, temp_indices_gl(2), .false.)
234 call this%scratch_GL%request_field(s_gl, temp_indices_gl(3), .false.)
235 call this%scratch_GL%request_field(s_adj_gl, temp_indices_gl(4), .false.)
237 call this%GLL_to_GL%map(s_gl%x, this%s%x, nel, this%Xh_GL)
238 call this%GLL_to_GL%map(s_adj_gl%x, this%s_adj%x, nel, this%Xh_GL)
241 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdx, &
242 this%c_Xh_GL%dsdx, this%c_Xh_GL%dtdx, this%c_Xh_GL)
243 call field_col3(accumulate, s_adj_gl, fld_gl)
245 if (neko_bcknd_device .eq. 1)
then
246 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
247 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
250 call this%coef%gs_h%op(work, gs_op_add)
251 call device_col2(work%x_d, this%coef%Binv_d, work%size())
253 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
254 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
256 call this%coef%gs_h%op(work, gs_op_add)
257 call col2(work%x, this%coef%Binv, work%size())
259 call field_sub2(fu, work)
262 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdy, &
263 this%c_Xh_GL%dsdy, this%c_Xh_GL%dtdy, this%c_Xh_GL)
264 call field_col3(accumulate, s_adj_gl, fld_gl)
266 if (neko_bcknd_device .eq. 1)
then
267 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
268 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
271 call this%coef%gs_h%op(work, gs_op_add)
272 call device_col2(work%x_d, this%coef%Binv_d, work%size())
274 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
275 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
277 call this%coef%gs_h%op(work, gs_op_add)
278 call col2(work%x, this%coef%Binv, work%size())
280 call field_sub2(fv, work)
283 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdz, &
284 this%c_Xh_GL%dsdz, this%c_Xh_GL%dtdz, this%c_Xh_GL)
285 call field_col3(accumulate, s_adj_gl, fld_gl)
287 if (neko_bcknd_device .eq. 1)
then
288 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
289 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
292 call this%coef%gs_h%op(work, gs_op_add)
293 call device_col2(work%x_d, this%coef%Binv_d, work%size())
295 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
296 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
298 call this%coef%gs_h%op(work, gs_op_add)
299 call col2(work%x, this%coef%Binv, work%size())
301 call field_sub2(fw, work)
303 call this%scratch_GL%relinquish_field(temp_indices_gl)
306 call grad(dsdx%x, dsdy%x, dsdz%x, this%s%x, this%coef)
307 call field_subcol3(fu, this%s_adj, dsdx)
308 call field_subcol3(fv, this%s_adj, dsdy)
309 call field_subcol3(fw, this%s_adj, dsdz)
313 call neko_scratch_registry%relinquish_field(temp_indices)
314 end subroutine adjoint_scalar_convection_source_term_compute
Implements the adjoint_scalar_convection_source_term type.
subroutine, public adjoint_scalar_convection_source_term_allocate(obj)
Allocator for the adjoint scalar convection source term.