64 use num_types,
only: rp
65 use field,
only: field_t
66 use field_math,
only: field_col3, field_addcol3, field_cmult, field_add2s2, &
68 use operators,
only: grad
69 use scratch_registry,
only: neko_scratch_registry
75 use coefs,
only: coef_t
76 use field_registry,
only: neko_field_registry
77 use neko_config,
only: neko_bcknd_device
78 use math,
only: glsc2, copy
79 use device_math,
only: device_copy, device_glsc2
82 use point_zone,
only: point_zone_t
84 use math_ext,
only: glsc2_mask
85 use utils,
only: neko_error
86 use json_module,
only: json_file
87 use json_utils,
only: json_get_or_default
98 type(field_t),
pointer :: u => null()
100 type(field_t),
pointer :: v => null()
102 type(field_t),
pointer :: w => null()
104 type(coef_t),
pointer :: c_xh => null()
107 type(field_t),
pointer :: adjoint_u => null()
109 type(field_t),
pointer :: adjoint_v => null()
111 type(field_t),
pointer :: adjoint_w => null()
115 procedure,
public, pass(this) :: init_json_sim => &
116 minimum_dissipation_init_json_sim
118 procedure,
public, pass(this) :: init_from_attributes => &
119 minimum_dissipation_init_attributes
121 procedure,
public, pass(this) :: free => minimum_dissipation_free
123 procedure,
public, pass(this) :: update_value => &
124 minimum_dissipation_update_value
126 procedure,
public, pass(this) :: update_sensitivity => &
127 minimum_dissipation_update_sensitivity
138 subroutine minimum_dissipation_init_json_sim(this, json, design, simulation)
140 type(json_file),
intent(inout) :: json
141 class(
design_t),
intent(in) :: design
144 character(len=:),
allocatable :: name
145 character(len=:),
allocatable :: mask_name
146 real(kind=rp) :: weight
148 call json_get_or_default(json,
"weight", weight, 1.0_rp)
149 call json_get_or_default(json,
"mask_name", mask_name,
"")
150 call json_get_or_default(json,
"name", name,
"Dissipation")
152 call this%init_from_attributes(
design, simulation, weight, name, mask_name)
153 end subroutine minimum_dissipation_init_json_sim
162 subroutine minimum_dissipation_init_attributes(this, design, simulation, &
163 weight, name, mask_name)
165 class(
design_t),
intent(in) :: design
167 real(kind=rp),
intent(in) :: weight
168 character(len=*),
intent(in) :: name
169 character(len=*),
intent(in) :: mask_name
173 call this%init_base(name,
design%size(), weight, mask_name)
176 this%u => neko_field_registry%get_field(
'u')
177 this%v => neko_field_registry%get_field(
'v')
178 this%w => neko_field_registry%get_field(
'w')
179 this%c_Xh => simulation%fluid%c_Xh
180 this%adjoint_u => neko_field_registry%get_field(
'u_adj')
181 this%adjoint_v => neko_field_registry%get_field(
'v_adj')
182 this%adjoint_w => neko_field_registry%get_field(
'w_adj')
187 call adjoint_forcing%init_from_components( &
188 simulation%adjoint_fluid%f_adj_x, &
189 simulation%adjoint_fluid%f_adj_y, &
190 simulation%adjoint_fluid%f_adj_z, &
191 this%u, this%v, this%w, this%weight, &
192 this%mask, this%has_mask, &
196 call simulation%adjoint_fluid%source_term%add_source_term(adjoint_forcing)
198 end subroutine minimum_dissipation_init_attributes
201 subroutine minimum_dissipation_free(this)
203 call this%free_base()
205 if (
associated(this%u))
nullify(this%u)
206 if (
associated(this%v))
nullify(this%v)
207 if (
associated(this%w))
nullify(this%w)
208 if (
associated(this%c_Xh))
nullify(this%c_Xh)
210 if (
associated(this%adjoint_u))
nullify(this%adjoint_u)
211 if (
associated(this%adjoint_v))
nullify(this%adjoint_v)
212 if (
associated(this%adjoint_w))
nullify(this%adjoint_w)
214 end subroutine minimum_dissipation_free
219 subroutine minimum_dissipation_update_value(this, design)
221 class(
design_t),
intent(in) :: design
222 type(field_t),
pointer :: wo1, wo2, wo3, work
223 type(field_t),
pointer :: objective_field
224 integer :: temp_indices(5)
227 call neko_scratch_registry%request_field(wo1, temp_indices(1))
228 call neko_scratch_registry%request_field(wo2, temp_indices(2))
229 call neko_scratch_registry%request_field(wo3, temp_indices(3))
230 call neko_scratch_registry%request_field(objective_field, temp_indices(4))
231 call neko_scratch_registry%request_field(work, temp_indices(5))
234 call grad(wo1%x, wo2%x, wo3%x, this%u%x, this%c_Xh)
235 call field_col3(objective_field, wo1, wo1)
236 call field_addcol3(objective_field, wo2, wo2)
237 call field_addcol3(objective_field, wo3, wo3)
239 call grad(wo1%x, wo2%x, wo3%x, this%v%x, this%c_Xh)
240 call field_addcol3(objective_field, wo1, wo1)
241 call field_addcol3(objective_field, wo2, wo2)
242 call field_addcol3(objective_field, wo3, wo3)
244 call grad(wo1%x, wo2%x, wo3%x, this%w%x, this%c_Xh)
245 call field_addcol3(objective_field, wo1, wo1)
246 call field_addcol3(objective_field, wo2, wo2)
247 call field_addcol3(objective_field, wo3, wo3)
251 if (this%has_mask)
then
252 if (neko_bcknd_device .eq. 1)
then
255 call field_copy(work, objective_field)
257 this%value = device_glsc2(work%x_d, this%c_xh%B_d, n)
259 this%value = glsc2_mask(objective_field%x, this%C_Xh%b, &
260 n, this%mask%mask, this%mask%size)
263 if (neko_bcknd_device .eq. 1)
then
264 this%value = device_glsc2(objective_field%x_d, &
267 this%value = glsc2(objective_field%x, this%C_Xh%b, n)
271 call neko_scratch_registry%relinquish_field(temp_indices)
273 end subroutine minimum_dissipation_update_value
278 subroutine minimum_dissipation_update_sensitivity(this, design)
280 class(
design_t),
intent(in) :: design
281 type(field_t),
pointer :: work
282 integer :: temp_indices(1)
284 call neko_scratch_registry%request_field(work, temp_indices(1))
287 call field_col3(work, this%u, this%adjoint_u)
288 call field_addcol3(work, this%v, this%adjoint_v)
289 call field_addcol3(work, this%w, this%adjoint_w)
291 call field_cmult(work, -1.0_rp)
293 if (neko_bcknd_device .eq. 1)
then
294 call device_copy(this%sensitivity%x_d, work%x_d, this%sensitivity%size())
296 call copy(this%sensitivity%x, work%x, this%sensitivity%size())
299 call neko_scratch_registry%relinquish_field(temp_indices)
301 end subroutine minimum_dissipation_update_sensitivity
Implements the adjoint_minimum_dissipation_source_term_t type.
Some common Masking operations we may need.
Implements the minimum_dissipation_objective_t type.
Implements the objective_t type.
Implements the steady_problem_t type.
Base type of all fluid formulations.
An adjoint source term for objectives of minimum dissipation.
A topology optimization design variable.
An objective function corresponding to minimum dissipation .
The abstract objective type.