40 use num_types,
only: rp
41 use field_list,
only: field_list_t
42 use json_module,
only: json_file
43 use json_utils,
only: json_get, json_get_or_default
44 use source_term,
only: source_term_t
45 use coefs,
only: coef_t
46 use neko_config,
only: neko_bcknd_device
47 use utils,
only: neko_error
48 use field,
only: field_t
49 use field_math,
only: field_subcol3, field_add2, field_add2s2, field_rzero
50 use json_module,
only: json_file
51 use time_state,
only: time_state_t
53 use simcomp_executor,
only: neko_simcomps
54 use user_source_term,
only: user_source_term_t
55 use num_types,
only: rp
56 use field,
only: field_t
57 use field_registry,
only: neko_field_registry
58 use math,
only: rzero, copy, chsign, cfill, invcol2
59 use device_math,
only: device_copy, device_cmult, device_cfill, device_invcol2
60 use neko_config,
only: neko_bcknd_device
61 use scratch_registry,
only: neko_scratch_registry
63 use point_zone,
only: point_zone_t
64 use ax_product,
only : ax_t, ax_helm_factory
71 type,
public,
extends(source_term_t) :: &
74 type(field_t),
pointer :: u => null()
76 type(field_t),
pointer :: v => null()
78 type(field_t),
pointer :: w => null()
80 real(kind=rp) :: obj_scale
82 class(point_zone_t),
pointer :: mask => null()
86 class(ax_t),
allocatable :: ax
88 real(kind=rp) :: volume
92 procedure, pass(this) :: init => &
93 adjoint_minimum_dissipation_source_term_init_from_json
95 procedure, pass(this) :: init_from_components => &
96 adjoint_minimum_dissipation_source_term_init_from_components
98 procedure, pass(this) :: free => &
99 adjoint_minimum_dissipation_source_term_free
101 procedure, pass(this) :: compute_ => &
102 adjoint_minimum_dissipation_source_term_compute
112 subroutine adjoint_minimum_dissipation_source_term_init_from_json(this, &
113 json, fields, coef, variable_name)
115 type(json_file),
intent(inout) :: json
116 type(field_list_t),
intent(in),
target :: fields
117 type(coef_t),
intent(in),
target :: coef
118 character(len=*),
intent(in) :: variable_name
124 end subroutine adjoint_minimum_dissipation_source_term_init_from_json
135 subroutine adjoint_minimum_dissipation_source_term_init_from_components(this,&
137 u, v, w, obj_scale, &
141 type(field_t),
pointer,
intent(in) :: f_x, f_y, f_z
142 type(field_list_t) :: fields
144 real(kind=rp) :: start_time
145 real(kind=rp) :: end_time
146 real(kind=rp) :: obj_scale
147 type(field_t),
intent(in),
target :: u, v, w
148 class(point_zone_t),
intent(in),
target :: mask
149 real(kind=rp),
intent(in) :: volume
155 end_time = 100000000.0_rp
162 call fields%assign(1, f_x)
163 call fields%assign(2, f_y)
164 call fields%assign(3, f_z)
166 call this%init_base(fields, coef, start_time, end_time)
173 this%obj_scale = obj_scale
176 this%if_mask = if_mask
177 if (this%if_mask)
then
182 call ax_helm_factory(this%Ax, full_formulation = .false.)
184 end subroutine adjoint_minimum_dissipation_source_term_init_from_components
187 subroutine adjoint_minimum_dissipation_source_term_free(this)
190 call this%free_base()
195 if (
allocated(this%Ax))
then
199 end subroutine adjoint_minimum_dissipation_source_term_free
204 subroutine adjoint_minimum_dissipation_source_term_compute(this, time)
206 type(time_state_t),
intent(in) :: time
207 type(field_t),
pointer :: u, v, w
208 type(field_t),
pointer :: fu, fv, fw
209 type(field_t),
pointer :: work
210 integer :: temp_indices(1)
213 fu => this%fields%get_by_index(1)
214 fv => this%fields%get_by_index(2)
215 fw => this%fields%get_by_index(3)
223 call neko_scratch_registry%request_field(work, temp_indices(1))
225 associate(coef => this%coef)
229 if (neko_bcknd_device .eq. 1)
then
230 call device_cfill(coef%h1_d, 1.0_rp, n)
231 call device_cfill(coef%h2_d, 0.0_rp, n)
233 call cfill(coef%h1, 1.0_rp, n)
234 call cfill(coef%h2, 0.0_rp, n)
241 call this%Ax%compute(work%x, u%x, coef, coef%msh, coef%xh)
244 if (neko_bcknd_device .eq. 1)
then
245 call device_invcol2(work%x_d, coef%B_d, work%size())
247 call invcol2(work%x, coef%B, work%size())
251 if (this%if_mask)
then
256 call field_add2s2(fu, work, this%obj_scale / this%volume)
261 call this%Ax%compute(work%x, v%x, coef, coef%msh, coef%xh)
264 if (neko_bcknd_device .eq. 1)
then
265 call device_invcol2(work%x_d, coef%B_d, work%size())
267 call invcol2(work%x, coef%B, work%size())
271 if (this%if_mask)
then
276 call field_add2s2(fv, work, this%obj_scale / this%volume)
281 call this%Ax%compute(work%x, w%x, coef, coef%msh, coef%xh)
284 if (neko_bcknd_device .eq. 1)
then
285 call device_invcol2(work%x_d, coef%B_d, work%size())
287 call invcol2(work%x, coef%B, work%size())
291 if (this%if_mask)
then
296 call field_add2s2(fw, work, this%obj_scale / this%volume)
298 call neko_scratch_registry%relinquish_field(temp_indices)
302 end subroutine adjoint_minimum_dissipation_source_term_compute
Implements the adjoint_minimum_dissipation_source_term_t type.
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...