66 use num_types,
only: rp
67 use field,
only: field_t
68 use field_math,
only: field_col3, field_addcol3, field_cmult, field_add2s2, &
70 use operators,
only: grad
72 use scratch_registry,
only: neko_scratch_registry
78 use coefs,
only: coef_t
79 use registry,
only: neko_registry
80 use neko_config,
only: neko_bcknd_device
81 use math,
only: glsc2, copy
82 use device_math,
only: device_copy, device_glsc2
85 use point_zone,
only: point_zone_t
87 use math_ext,
only: glsc2_mask
88 use utils,
only: neko_error
89 use json_module,
only: json_file
90 use json_utils,
only: json_get_or_default
100 type(field_t),
pointer :: u => null()
102 type(field_t),
pointer :: v => null()
104 type(field_t),
pointer :: w => null()
106 type(coef_t),
pointer :: c_xh => null()
108 type(field_t),
pointer :: adjoint_u => null()
110 type(field_t),
pointer :: adjoint_v => null()
112 type(field_t),
pointer :: adjoint_w => null()
114 real(kind=rp) :: volume
118 procedure,
public, pass(this) :: init_json_sim => &
121 procedure,
public, pass(this) :: init_from_attributes => &
122 minimum_dissipation_init_attributes
124 procedure,
public, pass(this) :: free => minimum_dissipation_free
126 procedure,
public, pass(this) :: update_value => &
127 minimum_dissipation_update_value
129 procedure,
public, pass(this) :: update_sensitivity => &
130 minimum_dissipation_update_sensitivity
143 type(json_file),
intent(inout) :: json
144 class(
design_t),
intent(in) :: design
147 character(len=:),
allocatable :: name
148 character(len=:),
allocatable :: mask_name
149 real(kind=rp) :: weight
151 call json_get_or_default(json,
"weight", weight, 1.0_rp)
152 call json_get_or_default(json,
"mask_name", mask_name,
"")
153 call json_get_or_default(json,
"name", name,
"Dissipation")
155 call this%init_from_attributes(
design, simulation, weight, name, mask_name)
165 subroutine minimum_dissipation_init_attributes(this, design, simulation, &
166 weight, name, mask_name)
168 class(
design_t),
intent(in) :: design
170 real(kind=rp),
intent(in) :: weight
171 character(len=*),
intent(in) :: name
172 character(len=*),
intent(in) :: mask_name
175 call this%init_base(name,
design%size(), weight, mask_name)
178 this%u => neko_registry%get_field(
'u')
179 this%v => neko_registry%get_field(
'v')
180 this%w => neko_registry%get_field(
'w')
181 this%c_Xh => simulation%fluid%c_Xh
182 this%adjoint_u => neko_registry%get_field(
'u_adj')
183 this%adjoint_v => neko_registry%get_field(
'v_adj')
184 this%adjoint_w => neko_registry%get_field(
'w_adj')
187 if (this%has_mask)
then
190 this%volume = this%c_Xh%volume
196 call adjoint_forcing%init_from_components( &
197 simulation%adjoint_fluid%f_adj_x, &
198 simulation%adjoint_fluid%f_adj_y, &
199 simulation%adjoint_fluid%f_adj_z, &
200 this%u, this%v, this%w, this%weight, &
201 this%mask, this%has_mask, &
202 this%c_Xh, this%volume)
205 select type (f => simulation%adjoint_fluid)
207 call f%source_term%add_source_term(adjoint_forcing)
210 end subroutine minimum_dissipation_init_attributes
213 subroutine minimum_dissipation_free(this)
215 call this%free_base()
217 if (
associated(this%u))
nullify(this%u)
218 if (
associated(this%v))
nullify(this%v)
219 if (
associated(this%w))
nullify(this%w)
220 if (
associated(this%c_Xh))
nullify(this%c_Xh)
222 if (
associated(this%adjoint_u))
nullify(this%adjoint_u)
223 if (
associated(this%adjoint_v))
nullify(this%adjoint_v)
224 if (
associated(this%adjoint_w))
nullify(this%adjoint_w)
226 end subroutine minimum_dissipation_free
231 subroutine minimum_dissipation_update_value(this, design)
233 class(
design_t),
intent(in) :: design
234 type(field_t),
pointer :: wo1, wo2, wo3, work
235 type(field_t),
pointer :: objective_field
236 integer :: temp_indices(5)
239 call neko_scratch_registry%request_field(wo1, temp_indices(1), .false.)
240 call neko_scratch_registry%request_field(wo2, temp_indices(2), .false.)
241 call neko_scratch_registry%request_field(wo3, temp_indices(3), .false.)
242 call neko_scratch_registry%request_field(objective_field, temp_indices(4), &
244 call neko_scratch_registry%request_field(work, temp_indices(5), .false.)
247 call grad(wo1%x, wo2%x, wo3%x, this%u%x, this%c_Xh)
248 call field_col3(objective_field, wo1, wo1)
249 call field_addcol3(objective_field, wo2, wo2)
250 call field_addcol3(objective_field, wo3, wo3)
252 call grad(wo1%x, wo2%x, wo3%x, this%v%x, this%c_Xh)
253 call field_addcol3(objective_field, wo1, wo1)
254 call field_addcol3(objective_field, wo2, wo2)
255 call field_addcol3(objective_field, wo3, wo3)
257 call grad(wo1%x, wo2%x, wo3%x, this%w%x, this%c_Xh)
258 call field_addcol3(objective_field, wo1, wo1)
259 call field_addcol3(objective_field, wo2, wo2)
260 call field_addcol3(objective_field, wo3, wo3)
264 if (this%has_mask)
then
265 if (neko_bcknd_device .eq. 1)
then
268 call field_copy(work, objective_field)
270 this%value = device_glsc2(work%x_d, this%c_xh%B_d, n)
272 this%value = glsc2_mask(objective_field%x, this%c_Xh%b, &
273 n, this%mask%mask%get(), this%mask%size)
276 if (neko_bcknd_device .eq. 1)
then
277 this%value = device_glsc2(objective_field%x_d, &
280 this%value = glsc2(objective_field%x, this%c_Xh%b, n)
284 this%value = this%value * 0.5_rp / this%volume
286 call neko_scratch_registry%relinquish_field(temp_indices)
288 end subroutine minimum_dissipation_update_value
293 subroutine minimum_dissipation_update_sensitivity(this, design)
295 class(
design_t),
intent(in) :: design
297 end subroutine minimum_dissipation_update_sensitivity
Adjoint Pn/Pn formulation.
Implements the adjoint_minimum_dissipation_source_term_t type.
Some common Masking operations we may need.
real(kind=rp) function, public compute_masked_volume(mask, coef)
Compute the volume of the domain contained within the mask.
Implements the minimum_dissipation_objective_t type.
subroutine minimum_dissipation_init_json_sim(this, json, design, simulation)
The common constructor using a JSON object.
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.