Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
adjoint_scalar_convection_source_term.f90
Go to the documentation of this file.
1
34!
36! this is a such a dumb name
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 scratch_registry, only: neko_scratch_registry, scratch_registry_t
51 use neko_config, only: neko_bcknd_device
52 use math, only: col2, invcol2
53 use device_math, only: device_col2, device_invcol2
54 implicit none
55 private
57
58 ! I don't know how to name this term, but when you have a passive
59 ! scalar you get an extra term in the adjoint velocity equation, which comes
60 ! from the convective term in the passive scalar equation.
61 ! Maybe this should be called just `adjoint_scalar_convection`?
62 ! but it does come in a source term...
63
64 ! In any case,
65 ! it's a source term acting on the adjoint velocity equations, of the form:
66 ! \f$\nabla s s_adj\f$
67 type, public, extends(source_term_t) :: &
70 type(field_t), pointer :: s_adj => null()
72 type(field_t), pointer :: s => null()
73 ! --- for over-integration
75 type(space_t), pointer :: xh_gll
77 type(space_t), pointer :: xh_gl
79 type(coef_t), pointer :: c_xh_gl
81 type(interpolator_t), pointer :: gll_to_gl
83 logical :: dealias
85 type(scratch_registry_t), pointer :: scratch_gl
86
87 contains
89 procedure, pass(this) :: init => &
90 adjoint_scalar_convection_source_term_init_from_json
92 procedure, pass(this) :: init_from_components => &
93 adjoint_scalar_convection_source_term_init_from_components
95 procedure, pass(this) :: free => adjoint_scalar_convection_source_term_free
97 procedure, pass(this) :: compute_ => &
98 adjoint_scalar_convection_source_term_compute
100
101contains
102
105 class(source_term_t), allocatable, intent(inout) :: obj
108
115 subroutine adjoint_scalar_convection_source_term_init_from_json(this, &
116 json, fields, coef, variable_name)
117 class(adjoint_scalar_convection_source_term_t), intent(inout) :: this
118 type(json_file), intent(inout) :: json
119 type(field_list_t), intent(in), target :: fields
120 type(coef_t), intent(in), target :: coef
121 character(len=*), intent(in) :: variable_name
122
123 ! this is a bit weird... because I don't think this should come from the
124 ! JSON.
125 ! Maybe we should think of all these source terms as only "appendable"
126 !
127 ! Because we'll never have the whole case here, so we'll never be able
128 ! init from components anyway...
129
130
131 end subroutine adjoint_scalar_convection_source_term_init_from_json
132
143 subroutine adjoint_scalar_convection_source_term_init_from_components(this,&
144 f_x, f_y, f_z, s, s_adj, coef, c_Xh_GL, GLL_to_GL, dealias, scratch_GL)
145 class(adjoint_scalar_convection_source_term_t), intent(inout) :: this
146 type(field_t), pointer, intent(in) :: f_x, f_y, f_z
147 type(field_t), intent(in), target :: s, s_adj
148 type(coef_t), intent(in), target :: coef
149 type(coef_t), intent(in), target :: c_xh_gl
150 type(interpolator_t), intent(in), target :: gll_to_gl
151 logical, intent(in) :: dealias
152 type(scratch_registry_t), intent(in), target :: scratch_gl
153
154 type(field_list_t) :: fields
155 real(kind=rp) :: start_time
156 real(kind=rp) :: end_time
157
158 ! I wish you didn't need a start time and end time...
159 ! but I'm just going to set a super big number...
160 start_time = 0.0_rp
161 end_time = 100000000.0_rp
162
163 call this%free()
164
165 ! this is copying the fluid source term init
166 ! We package the fields for the source term to operate on in a field list.
167 call fields%init(3)
168 call fields%assign(1, f_x)
169 call fields%assign(2, f_y)
170 call fields%assign(3, f_z)
171
172 call this%init_base(fields, coef, start_time, end_time)
173 call fields%free()
174
175 ! point everything in the correct places
176 this%s_adj => s_adj
177 this%s => s
178
179 ! for over integration
180 this%dealias = dealias
181 this%c_Xh_GL => c_xh_gl
182 this%Xh_GL => this%c_Xh_GL%Xh
183 this%Xh_GLL => this%coef%Xh
184 this%GLL_to_GL => gll_to_gl
185 this%scratch_GL => scratch_gl
186
187 end subroutine adjoint_scalar_convection_source_term_init_from_components
188
190 subroutine adjoint_scalar_convection_source_term_free(this)
191 class(adjoint_scalar_convection_source_term_t), intent(inout) :: this
192
193 call this%free_base()
194 nullify(this%s_adj)
195 nullify(this%s)
196 nullify(this%c_Xh_GL)
197 nullify(this%Xh_GL)
198 nullify(this%Xh_GLL)
199 nullify(this%GLL_to_GL)
200 nullify(this%scratch_GL)
201
202 end subroutine adjoint_scalar_convection_source_term_free
203
207 subroutine adjoint_scalar_convection_source_term_compute(this, time)
208 class(adjoint_scalar_convection_source_term_t), intent(inout) :: this
209 type(time_state_t), intent(in) :: time
210 type(field_t), pointer :: fu, fv, fw
211 integer :: temp_indices(4)
212 type(field_t), pointer :: dsdx, dsdy, dsdz, work
213 type(field_t), pointer :: accumulate, fld_gl, s_gl, s_adj_gl
214 integer :: temp_indices_gl(4)
215 integer :: n_gl, nel
216
217
218 call neko_scratch_registry%request_field(dsdx, temp_indices(1), .false.)
219 call neko_scratch_registry%request_field(dsdy, temp_indices(2), .false.)
220 call neko_scratch_registry%request_field(dsdz, temp_indices(3), .false.)
221 call neko_scratch_registry%request_field(work, temp_indices(4), .false.)
222
223 fu => this%fields%get(1)
224 fv => this%fields%get(2)
225 fw => this%fields%get(3)
226
227 ! we need the term \f$\nabla s s_adj\f$
228 if (this%dealias) then
229 nel = this%coef%msh%nelv
230 n_gl = nel * this%Xh_GL%lxyz
231 call this%scratch_GL%request_field(accumulate, temp_indices_gl(1), .false.)
232 call this%scratch_GL%request_field(fld_gl, temp_indices_gl(2), .false.)
233 call this%scratch_GL%request_field(s_gl, temp_indices_gl(3), .false.)
234 call this%scratch_GL%request_field(s_adj_gl, temp_indices_gl(4), .false.)
235
236 call this%GLL_to_GL%map(s_gl%x, this%s%x, nel, this%Xh_GL)
237 call this%GLL_to_GL%map(s_adj_gl%x, this%s_adj%x, nel, this%Xh_GL)
238
239 ! u
240 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdx, &
241 this%c_Xh_GL%dsdx, this%c_Xh_GL%dtdx, this%c_Xh_GL)
242 call field_col3(accumulate, s_adj_gl, fld_gl)
243 ! Evaluate term on GL and preempt the GLL premultiplication
244 if (neko_bcknd_device .eq. 1) then
245 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
246 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
247 call device_invcol2(work%x_d, this%coef%B_d, work%size())
248 else
249 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
250 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
251 call invcol2(work%x, this%coef%B, work%size())
252 end if
253 call field_sub2(fu, work)
254
255 ! v
256 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdy, &
257 this%c_Xh_GL%dsdy, this%c_Xh_GL%dtdy, this%c_Xh_GL)
258 call field_col3(accumulate, s_adj_gl, fld_gl)
259 ! Evaluate term on GL and preempt the GLL premultiplication
260 if (neko_bcknd_device .eq. 1) then
261 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
262 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
263 call device_invcol2(work%x_d, this%coef%B_d, work%size())
264 else
265 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
266 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
267 call invcol2(work%x, this%coef%B, work%size())
268 end if
269 call field_sub2(fv, work)
270
271 ! w
272 call dudxyz(fld_gl%x, s_gl%x, this%c_Xh_GL%drdz, &
273 this%c_Xh_GL%dsdz, this%c_Xh_GL%dtdz, this%c_Xh_GL)
274 call field_col3(accumulate, s_adj_gl, fld_gl)
275 ! Evaluate term on GL and preempt the GLL premultiplication
276 if (neko_bcknd_device .eq. 1) then
277 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
278 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
279 call device_invcol2(work%x_d, this%coef%B_d, work%size())
280 else
281 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
282 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
283 call invcol2(work%x, this%coef%B, work%size())
284 end if
285 call field_sub2(fw, work)
286
287 call this%scratch_GL%relinquish_field(temp_indices_gl)
288
289 else
290 call grad(dsdx%x, dsdy%x, dsdz%x, this%s%x, this%coef)
291 call field_subcol3(fu, this%s_adj, dsdx)
292 call field_subcol3(fv, this%s_adj, dsdy)
293 call field_subcol3(fw, this%s_adj, dsdz)
294 end if
295
296 ! free the scratch
297 call neko_scratch_registry%relinquish_field(temp_indices)
298 end subroutine adjoint_scalar_convection_source_term_compute
299
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.