72 use num_types,
only: rp
73 use field,
only: field_t
74 use scratch_registry,
only: neko_scratch_registry, scratch_registry_t
75 use neko_config,
only: neko_bcknd_device
77 use utils,
only: neko_error
78 use json_module,
only: json_file
79 use json_utils,
only: json_get_or_default
80 use registry,
only: neko_registry
81 use interpolation,
only: interpolator_t
82 use space,
only: space_t, gl
83 use coefs,
only: coef_t
84 use math,
only: glsc2, copy, col2, invcol2
85 use device_math,
only: device_copy, device_glsc2, device_col2, device_invcol2
86 use math_ext,
only: glsc2_mask
87 use field_math,
only: field_col3, field_addcol3, field_cmult, field_col2
97 type(field_t),
pointer :: u => null()
99 type(field_t),
pointer :: v => null()
101 type(field_t),
pointer :: w => null()
103 type(field_t),
pointer :: brinkman_amplitude => null()
105 logical :: dealias_sensitivity
107 logical :: dealias_forcing
109 real(kind=rp) :: volume
113 type(coef_t),
pointer :: c_xh_gll
115 type(space_t),
pointer :: xh_gll
119 type(space_t),
pointer :: xh_gl
121 type(coef_t),
pointer :: c_xh_gl
123 type(interpolator_t),
pointer :: gll_to_gl
125 type(scratch_registry_t),
pointer :: scratch_gl
132 procedure,
public, pass(this) :: init_from_attributes => &
133 lube_term_init_attributes
135 procedure,
public, pass(this) :: free => lube_term_free
137 procedure,
public, pass(this) :: update_value => &
138 lube_term_update_value
140 procedure,
public, pass(this) :: update_sensitivity => &
141 lube_term_update_sensitivity
154 type(json_file),
intent(inout) :: json
155 class(
design_t),
intent(in) :: design
158 character(len=:),
allocatable :: mask_name
159 character(len=:),
allocatable :: name
160 real(kind=rp) :: weight
161 logical :: dealias_sensitivity, dealias_forcing
163 call json_get_or_default(json,
"weight", weight, 1.0_rp)
164 call json_get_or_default(json,
"mask_name", mask_name,
"")
165 call json_get_or_default(json,
"name", name,
"Out of plane stresses")
166 call json_get_or_default(json,
"dealias_sensitivity", &
167 dealias_sensitivity, .true.)
168 call json_get_or_default(json,
"dealias_forcing", &
169 dealias_forcing, .true.)
171 call this%init_from_attributes(
design, simulation, weight, name, &
172 mask_name, dealias_sensitivity, dealias_forcing)
184 subroutine lube_term_init_attributes(this, design, simulation, weight, &
185 name, mask_name, dealias_sensitivity, dealias_forcing)
187 class(
design_t),
intent(in) :: design
189 real(kind=rp),
intent(in) :: weight
190 character(len=*),
intent(in) :: mask_name
191 character(len=*),
intent(in) :: name
192 logical,
intent(in) :: dealias_sensitivity
193 logical,
intent(in) :: dealias_forcing
197 call this%init_base(name,
design%size(), weight, mask_name)
199 this%dealias_forcing = dealias_forcing
200 this%dealias_sensitivity = dealias_sensitivity
205 this%brinkman_amplitude => &
206 neko_registry%get_field(
"brinkman_amplitude")
210 call neko_error(
'Minimum dissipation only works with brinkman_design')
213 this%u => neko_registry%get_field(
'u')
214 this%v => neko_registry%get_field(
'v')
215 this%w => neko_registry%get_field(
'w')
218 this%c_Xh_GLL => simulation%neko_case%fluid%c_Xh
219 this%Xh_GLL => simulation%neko_case%fluid%c_Xh%Xh
222 this%c_Xh_GL => simulation%adjoint_case%fluid_adj%c_Xh_GL
223 this%Xh_GL => this%c_Xh_GL%Xh
226 this%GLL_to_GL => simulation%adjoint_case%fluid_adj%GLL_to_GL
228 this%scratch_GL => simulation%adjoint_case%fluid_adj%scratch_GL
231 if (this%has_mask)
then
234 this%volume = this%c_Xh_GLL%volume
239 associate(f_adj_x => simulation%adjoint_fluid%f_adj_x, &
240 f_adj_y => simulation%adjoint_fluid%f_adj_y, &
241 f_adj_z => simulation%adjoint_fluid%f_adj_z)
243 call lube_term%init_from_components(f_adj_x, f_adj_y, f_adj_z,
design, &
244 this%weight, this%u, this%v, this%w, this%mask, &
245 this%has_mask, this%c_Xh_GLL, this%c_Xh_GL, this%GLL_to_GL, &
246 this%dealias_forcing, this%volume, &
252 select type (f => simulation%adjoint_fluid)
254 call f%source_term%add_source_term(lube_term)
257 end subroutine lube_term_init_attributes
260 subroutine lube_term_free(this)
262 call this%free_base()
267 this%c_Xh_GLL => null()
268 this%brinkman_amplitude => null()
269 nullify(this%c_Xh_GL)
272 nullify(this%GLL_to_GL)
273 nullify(this%scratch_GL)
275 end subroutine lube_term_free
280 subroutine lube_term_update_value(this, design)
282 class(design_t),
intent(in) :: design
283 type(field_t),
pointer :: work
284 integer :: temp_indices(1)
286 call neko_scratch_registry%request_field(work, temp_indices(1), .false.)
288 call field_col3(work, this%u, this%u)
289 call field_addcol3(work, this%v, this%v)
290 call field_addcol3(work, this%w, this%w)
291 call field_col2(work, this%brinkman_amplitude)
293 if (this%has_mask)
then
294 if (neko_bcknd_device .eq. 1)
then
297 call mask_exterior_const(work, this%mask, 0.0_rp)
298 this%value = device_glsc2(work%x_d, this%c_Xh_GLL%B_d,
design%size())
300 this%value = glsc2_mask(work%x, this%c_Xh_GLL%B,
design%size(), &
301 this%mask%mask%get(), this%mask%size)
304 if (neko_bcknd_device .eq. 1)
then
305 this%value = device_glsc2(work%x_d, this%c_Xh_GLL%B_d,
design%size())
307 this%value = glsc2(work%x, this%c_Xh_GLL%B,
design%size())
310 this%value = 0.5_rp * this%value / this%volume
312 call neko_scratch_registry%relinquish_field(temp_indices)
314 end subroutine lube_term_update_value
320 subroutine lube_term_update_sensitivity(this, design)
322 class(design_t),
intent(in) :: design
323 type(field_t),
pointer :: work
324 integer :: temp_indices(1)
326 type(field_t),
pointer :: accumulate, fld_GL
327 integer :: temp_indices_GL(2)
331 call neko_scratch_registry%request_field(work, temp_indices(1), .false.)
333 if(this%dealias_sensitivity)
then
334 nel = this%c_Xh_GLL%msh%nelv
335 n_gl = nel * this%Xh_GL%lxyz
336 call this%scratch_GL%request_field(accumulate, temp_indices_gl(1), &
338 call this%scratch_GL%request_field(fld_gl, temp_indices_gl(2), .false.)
340 call this%GLL_to_GL%map(fld_gl%x, this%u%x, nel, this%Xh_GL)
341 call field_col3(accumulate, fld_gl, fld_gl)
342 call this%GLL_to_GL%map(fld_gl%x, this%v%x, nel, this%Xh_GL)
343 call field_addcol3(accumulate, fld_gl, fld_gl)
344 call this%GLL_to_GL%map(fld_gl%x, this%w%x, nel, this%Xh_GL)
345 call field_addcol3(accumulate, fld_gl, fld_gl)
347 call field_cmult(accumulate, this%weight * 0.5_rp / this%volume)
350 if (neko_bcknd_device .eq. 1)
then
351 call device_col2(accumulate%x_d, this%c_Xh_GL%B_d, n_gl)
352 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
353 call device_invcol2(work%x_d, this%c_Xh_GLL%B_d, work%size())
355 call col2(accumulate%x, this%c_Xh_GL%B, n_gl)
356 call this%GLL_to_GL%map(work%x, accumulate%x, nel, this%Xh_GLL)
357 call invcol2(work%x, this%c_Xh_GLL%B, work%size())
360 call this%scratch_GL%relinquish_field(temp_indices_gl)
363 call field_col3(work, this%u, this%u)
364 call field_addcol3(work, this%v, this%v)
365 call field_addcol3(work, this%w, this%w)
367 call field_cmult(work, this%weight * 0.5_rp / this%volume)
370 if (neko_bcknd_device .eq. 1)
then
371 call device_copy(this%sensitivity%x_d, work%x_d, this%sensitivity%size())
373 call copy(this%sensitivity%x, work%x, this%sensitivity%size())
376 call neko_scratch_registry%relinquish_field(temp_indices)
378 end subroutine lube_term_update_sensitivity
Adjoint Pn/Pn formulation.
Implements the adjoint_lube_source_term_t type.
Implements the lube_term_objective_t type.
subroutine lube_term_init_json_sim(this, json, design, simulation)
The common constructor using a JSON object.
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.
A adjoint source term corresponding to an objective of.
A topology optimization design variable.
An objective function corresponding to out of plane stresses .
The abstract objective type.