42 use num_types,
only: rp
43 use field_list,
only: field_list_t
44 use json_module,
only: json_file
45 use json_utils,
only: json_get, json_get_or_default
46 use source_term,
only: source_term_t
47 use coefs,
only: coef_t
48 use neko_config,
only: neko_bcknd_device
49 use utils,
only: neko_error
50 use field,
only: field_t
51 use field_math,
only: field_subcol3, field_add2, field_add2s2, field_rzero
52 use json_module,
only: json_file
53 use time_state,
only: time_state_t
55 use simcomp_executor,
only: neko_simcomps
56 use user_source_term,
only: user_source_term_t
57 use num_types,
only: rp
58 use field,
only: field_t
59 use registry,
only: neko_registry
60 use math,
only: rzero, copy, chsign, cfill, invcol2
61 use device_math,
only: device_copy, device_cmult, device_cfill, device_invcol2
62 use neko_config,
only: neko_bcknd_device
63 use scratch_registry,
only: neko_scratch_registry
65 use point_zone,
only: point_zone_t
66 use ax_product,
only : ax_t, ax_helm_factory
74 type,
public,
extends(source_term_t) :: &
77 type(field_t),
pointer :: u => null()
79 type(field_t),
pointer :: v => null()
81 type(field_t),
pointer :: w => null()
83 real(kind=rp) :: obj_scale
85 class(point_zone_t),
pointer :: mask => null()
89 class(ax_t),
allocatable :: ax
91 real(kind=rp) :: volume
95 procedure, pass(this) :: init => &
96 adjoint_minimum_dissipation_source_term_init_from_json
98 procedure, pass(this) :: init_from_components => &
99 adjoint_minimum_dissipation_source_term_init_from_components
101 procedure, pass(this) :: free => &
102 adjoint_minimum_dissipation_source_term_free
104 procedure, pass(this) :: compute_ => &
105 adjoint_minimum_dissipation_source_term_compute
112 class(source_term_t),
allocatable,
intent(inout) :: obj
122 subroutine adjoint_minimum_dissipation_source_term_init_from_json(this, &
123 json, fields, coef, variable_name)
125 type(json_file),
intent(inout) :: json
126 type(field_list_t),
intent(in),
target :: fields
127 type(coef_t),
intent(in),
target :: coef
128 character(len=*),
intent(in) :: variable_name
134 end subroutine adjoint_minimum_dissipation_source_term_init_from_json
145 subroutine adjoint_minimum_dissipation_source_term_init_from_components(this,&
147 u, v, w, obj_scale, &
151 type(field_t),
pointer,
intent(in) :: f_x, f_y, f_z
152 type(field_list_t) :: fields
154 real(kind=rp) :: start_time
155 real(kind=rp) :: end_time
156 real(kind=rp) :: obj_scale
157 type(field_t),
intent(in),
target :: u, v, w
158 class(point_zone_t),
intent(in),
target :: mask
159 real(kind=rp),
intent(in) :: volume
165 end_time = 100000000.0_rp
172 call fields%assign(1, f_x)
173 call fields%assign(2, f_y)
174 call fields%assign(3, f_z)
176 call this%init_base(fields, coef, start_time, end_time)
183 this%obj_scale = obj_scale
186 this%if_mask = if_mask
187 if (this%if_mask)
then
192 call ax_helm_factory(this%Ax, full_formulation = .false.)
194 end subroutine adjoint_minimum_dissipation_source_term_init_from_components
197 subroutine adjoint_minimum_dissipation_source_term_free(this)
200 call this%free_base()
205 if (
allocated(this%Ax))
then
209 end subroutine adjoint_minimum_dissipation_source_term_free
214 subroutine adjoint_minimum_dissipation_source_term_compute(this, time)
216 type(time_state_t),
intent(in) :: time
217 type(field_t),
pointer :: u, v, w
218 type(field_t),
pointer :: fu, fv, fw
219 type(field_t),
pointer :: work
220 integer :: temp_indices(1)
223 fu => this%fields%get_by_index(1)
224 fv => this%fields%get_by_index(2)
225 fw => this%fields%get_by_index(3)
233 call neko_scratch_registry%request_field(work, temp_indices(1), .false.)
235 associate(coef => this%coef)
239 if (neko_bcknd_device .eq. 1)
then
240 call device_cfill(coef%h1_d, 1.0_rp, n)
241 call device_cfill(coef%h2_d, 0.0_rp, n)
243 call cfill(coef%h1, 1.0_rp, n)
244 call cfill(coef%h2, 0.0_rp, n)
251 call this%Ax%compute(work%x, u%x, coef, coef%msh, coef%xh)
254 if (neko_bcknd_device .eq. 1)
then
255 call device_invcol2(work%x_d, coef%B_d, work%size())
257 call invcol2(work%x, coef%B, work%size())
261 if (this%if_mask)
then
266 call field_add2s2(fu, work, this%obj_scale / this%volume)
271 call this%Ax%compute(work%x, v%x, coef, coef%msh, coef%xh)
274 if (neko_bcknd_device .eq. 1)
then
275 call device_invcol2(work%x_d, coef%B_d, work%size())
277 call invcol2(work%x, coef%B, work%size())
281 if (this%if_mask)
then
286 call field_add2s2(fv, work, this%obj_scale / this%volume)
291 call this%Ax%compute(work%x, w%x, coef, coef%msh, coef%xh)
294 if (neko_bcknd_device .eq. 1)
then
295 call device_invcol2(work%x_d, coef%B_d, work%size())
297 call invcol2(work%x, coef%B, work%size())
301 if (this%if_mask)
then
306 call field_add2s2(fw, work, this%obj_scale / this%volume)
308 call neko_scratch_registry%relinquish_field(temp_indices)
312 end subroutine adjoint_minimum_dissipation_source_term_compute
Implements the adjoint_minimum_dissipation_source_term_t type.
subroutine, public adjoint_minimum_dissipation_source_term_allocate(obj)
Allocator for the adjoint minimum dissipation source term.
Some common Masking operations we may need.
Implements the steady_simcomp_t type.
An adjoint source term for objectives of minimum dissipation.
The steady_simcomp_t type is a simulation component that terminates a simulation when the normed diff...