67 use num_types,
only: rp
68 use field,
only: field_t
69 use field_math,
only: field_col3, field_addcol3, field_cmult, field_add2s2, &
71 use operators,
only: grad
73 use scratch_registry,
only: neko_scratch_registry
79 use coefs,
only: coef_t
80 use registry,
only: neko_registry
81 use neko_config,
only: neko_bcknd_device
82 use math,
only: glsc2, copy
83 use device_math,
only: device_copy, device_glsc2
86 use point_zone,
only: point_zone_t
88 use math_ext,
only: glsc2_mask
89 use utils,
only: neko_error
90 use json_module,
only: json_file
91 use json_utils,
only: json_get_or_default
102 type(field_t),
pointer :: u => null()
104 type(field_t),
pointer :: v => null()
106 type(field_t),
pointer :: w => null()
108 type(coef_t),
pointer :: c_xh => null()
110 type(field_t),
pointer :: adjoint_u => null()
112 type(field_t),
pointer :: adjoint_v => null()
114 type(field_t),
pointer :: adjoint_w => null()
116 real(kind=rp) :: volume
118 real(kind=rp) :: viscosity
122 procedure,
public, pass(this) :: init_json_sim => &
125 procedure,
public, pass(this) :: init_from_attributes => &
126 viscous_dissipation_init_attributes
128 procedure,
public, pass(this) :: free => viscous_dissipation_free
130 procedure,
public, pass(this) :: update_value => &
131 viscous_dissipation_update_value
133 procedure,
public, pass(this) :: update_sensitivity => &
134 viscous_dissipation_update_sensitivity
147 type(json_file),
intent(inout) :: json
148 class(
design_t),
intent(in) :: design
151 character(len=:),
allocatable :: name
152 character(len=:),
allocatable :: mask_name
153 real(kind=rp) :: weight
156 call nekotop_continuation%json_get_or_register(json,
'weight', &
158 call json_get_or_default(json,
"mask_name", mask_name,
"")
159 call json_get_or_default(json,
"name", name,
"Dissipation")
161 call this%init_from_attributes(
design, simulation, weight, name, mask_name)
171 subroutine viscous_dissipation_init_attributes(this, design, simulation, &
172 weight, name, mask_name)
174 class(
design_t),
intent(in) :: design
176 real(kind=rp),
intent(in) :: weight
177 character(len=*),
intent(in) :: name
178 character(len=*),
intent(in) :: mask_name
181 call this%init_base(name,
design%size(), weight, mask_name)
184 this%u => neko_registry%get_field(
'u')
185 this%v => neko_registry%get_field(
'v')
186 this%w => neko_registry%get_field(
'w')
187 this%c_Xh => simulation%fluid%c_Xh
188 this%adjoint_u => neko_registry%get_field(
'u_adj')
189 this%adjoint_v => neko_registry%get_field(
'v_adj')
190 this%adjoint_w => neko_registry%get_field(
'w_adj')
191 this%viscosity = simulation%fluid%mu%x(1,1,1,1)
194 if (this%has_mask)
then
197 this%volume = this%c_Xh%volume
203 call adjoint_forcing%init_from_components( &
204 simulation%adjoint_fluid%f_adj_x, &
205 simulation%adjoint_fluid%f_adj_y, &
206 simulation%adjoint_fluid%f_adj_z, &
207 this%u, this%v, this%w, this%weight * this%viscosity, &
208 this%mask, this%has_mask, &
209 this%c_Xh, this%volume)
212 select type (f => simulation%adjoint_fluid)
214 call f%source_term%add_source_term(adjoint_forcing)
217 end subroutine viscous_dissipation_init_attributes
220 subroutine viscous_dissipation_free(this)
222 call this%free_base()
224 if (
associated(this%u))
nullify(this%u)
225 if (
associated(this%v))
nullify(this%v)
226 if (
associated(this%w))
nullify(this%w)
227 if (
associated(this%c_Xh))
nullify(this%c_Xh)
229 if (
associated(this%adjoint_u))
nullify(this%adjoint_u)
230 if (
associated(this%adjoint_v))
nullify(this%adjoint_v)
231 if (
associated(this%adjoint_w))
nullify(this%adjoint_w)
233 end subroutine viscous_dissipation_free
238 subroutine viscous_dissipation_update_value(this, design)
240 class(
design_t),
intent(in) :: design
241 type(field_t),
pointer :: wo1, wo2, wo3, work
242 type(field_t),
pointer :: objective_field
243 integer :: temp_indices(5)
246 call neko_scratch_registry%request_field(wo1, temp_indices(1), .false.)
247 call neko_scratch_registry%request_field(wo2, temp_indices(2), .false.)
248 call neko_scratch_registry%request_field(wo3, temp_indices(3), .false.)
249 call neko_scratch_registry%request_field(objective_field, temp_indices(4), &
251 call neko_scratch_registry%request_field(work, temp_indices(5), .false.)
254 call grad(wo1%x, wo2%x, wo3%x, this%u%x, this%c_Xh)
255 call field_col3(objective_field, wo1, wo1)
256 call field_addcol3(objective_field, wo2, wo2)
257 call field_addcol3(objective_field, wo3, wo3)
259 call grad(wo1%x, wo2%x, wo3%x, this%v%x, this%c_Xh)
260 call field_addcol3(objective_field, wo1, wo1)
261 call field_addcol3(objective_field, wo2, wo2)
262 call field_addcol3(objective_field, wo3, wo3)
264 call grad(wo1%x, wo2%x, wo3%x, this%w%x, this%c_Xh)
265 call field_addcol3(objective_field, wo1, wo1)
266 call field_addcol3(objective_field, wo2, wo2)
267 call field_addcol3(objective_field, wo3, wo3)
271 if (this%has_mask)
then
272 if (neko_bcknd_device .eq. 1)
then
275 call field_copy(work, objective_field)
277 this%value = device_glsc2(work%x_d, this%c_xh%B_d, n)
279 this%value = glsc2_mask(objective_field%x, this%c_Xh%b, &
280 n, this%mask%mask%get(), this%mask%size)
283 if (neko_bcknd_device .eq. 1)
then
284 this%value = device_glsc2(objective_field%x_d, &
287 this%value = glsc2(objective_field%x, this%c_Xh%b, n)
291 this%value = this%value * 0.5_rp * this%viscosity / this%volume
293 call neko_scratch_registry%relinquish_field(temp_indices)
295 end subroutine viscous_dissipation_update_value
300 subroutine viscous_dissipation_update_sensitivity(this, design)
302 class(
design_t),
intent(in) :: design
304 end subroutine viscous_dissipation_update_sensitivity
Adjoint Pn/Pn formulation.
Implements the adjoint_viscous_dissipation_source_term_t type.
Continuation scheduler for the optimization loop.
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 objective_t type.
Implements the steady_problem_t type.
Implements the viscous_dissipation_objective_t type.
subroutine viscous_dissipation_init_json_sim(this, json, design, simulation)
The common constructor using a JSON object.
Base type of all fluid formulations.
An adjoint source term for objectives of viscous dissipation.
A topology optimization design variable.
The abstract objective type.
An objective function corresponding to viscous dissipation .