70 use num_types,
only: rp
71 use field,
only: field_t
72 use scratch_registry,
only: neko_scratch_registry
73 use neko_config,
only: neko_bcknd_device
75 use utils,
only: neko_error
76 use json_module,
only: json_file
77 use json_utils,
only: json_get_or_default
78 use field_registry,
only: neko_field_registry
79 use coefs,
only: coef_t
80 use math,
only: glsc2, copy
81 use device_math,
only: device_copy, device_glsc2
82 use math_ext,
only: glsc2_mask
83 use field_math,
only: field_col3, field_addcol3, field_cmult
84 use,
intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr
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()
106 type(field_t),
pointer :: brinkman_amplitude => null()
111 procedure,
public, pass(this) :: init_json_sim => lube_term_init_json_sim
113 procedure,
public, pass(this) :: init_from_attributes => &
114 lube_term_init_attributes
116 procedure,
public, pass(this) :: free => lube_term_free
118 procedure,
public, pass(this) :: update_value => &
119 lube_term_update_value
121 procedure,
public, pass(this) :: update_sensitivity => &
122 lube_term_update_sensitivity
133 subroutine lube_term_init_json_sim(this, json, design, simulation)
135 type(json_file),
intent(inout) :: json
136 class(
design_t),
intent(in) :: design
139 character(len=:),
allocatable :: mask_name
140 character(len=:),
allocatable :: name
141 real(kind=rp) :: weight, k
143 call json_get_or_default(json,
"weight", weight, 1.0_rp)
144 call json_get_or_default(json,
"mask_name", mask_name,
"")
145 call json_get_or_default(json,
"name", name,
"Out of plane stresses")
146 call json_get_or_default(json,
"K", k, 1.0_rp)
148 call this%init_from_attributes(
design, simulation, weight, name, &
150 end subroutine lube_term_init_json_sim
160 subroutine lube_term_init_attributes(this, design, simulation, weight, &
163 class(
design_t),
intent(in) :: design
165 real(kind=rp),
intent(in) :: weight
166 character(len=*),
intent(in) :: mask_name
167 character(len=*),
intent(in) :: name
168 real(kind=rp),
intent(in) :: k
172 call this%init_base(name,
design%size(), weight, mask_name)
180 this%brinkman_amplitude => &
181 neko_field_registry%get_field(
"brinkman_amplitude")
185 call neko_error(
'Minimum dissipation only works with brinkman_design')
188 this%u => neko_field_registry%get_field(
'u')
189 this%v => neko_field_registry%get_field(
'v')
190 this%w => neko_field_registry%get_field(
'w')
191 this%c_Xh => simulation%neko_case%fluid%c_Xh
195 associate(f_adj_x => simulation%adjoint_fluid%f_adj_x, &
196 f_adj_y => simulation%adjoint_fluid%f_adj_y, &
197 f_adj_z => simulation%adjoint_fluid%f_adj_z, &
198 c_xh => simulation%adjoint_fluid%c_Xh)
200 call lube_term%init_from_components(f_adj_x, f_adj_y, f_adj_z,
design, &
201 this%k * this%weight, this%u, this%v, this%w, this%mask, &
207 call simulation%adjoint_fluid%source_term%add_source_term(lube_term)
209 end subroutine lube_term_init_attributes
212 subroutine lube_term_free(this)
214 call this%free_base()
220 this%brinkman_amplitude => null()
222 end subroutine lube_term_free
227 subroutine lube_term_update_value(this, design)
229 class(design_t),
intent(in) :: design
230 type(field_t),
pointer :: work
231 integer :: temp_indices(1)
233 call neko_scratch_registry%request_field(work, temp_indices(1))
240 call field_col3(work, this%u, this%brinkman_amplitude)
241 call field_addcol3(work, this%v, this%brinkman_amplitude)
242 call field_addcol3(work, this%w, this%brinkman_amplitude)
244 if (this%has_mask)
then
245 if (neko_bcknd_device .eq. 1)
then
248 call mask_exterior_const(work, this%mask, 0.0_rp)
249 this%value = device_glsc2(work%x_d, this%c_Xh%B_d,
design%size())
251 this%value = glsc2_mask(work%x, this%c_Xh%B,
design%size(), &
252 this%mask%mask, this%mask%size)
255 if (neko_bcknd_device .eq. 1)
then
256 this%value = device_glsc2(work%x_d, this%c_Xh%B_d,
design%size())
258 this%value = glsc2(work%x, this%c_Xh%B,
design%size())
261 this%value = 0.5 * this%K * this%value
263 call neko_scratch_registry%relinquish_field(temp_indices)
265 end subroutine lube_term_update_value
270 subroutine lube_term_update_sensitivity(this, design)
272 class(design_t),
intent(in) :: design
273 type(field_t),
pointer :: work
274 integer :: temp_indices(1)
283 call neko_scratch_registry%request_field(work, temp_indices(1))
285 call field_col3(work, this%u, this%u)
286 call field_addcol3(work, this%v, this%v)
287 call field_addcol3(work, this%w, this%w)
288 call field_cmult(work, this%K)
290 if (neko_bcknd_device .eq. 1)
then
291 call device_copy(this%sensitivity%x_d, work%x_d, this%sensitivity%size())
293 call copy(this%sensitivity%x, work%x, this%sensitivity%size())
296 call neko_scratch_registry%relinquish_field(temp_indices)
298 end subroutine lube_term_update_sensitivity
Implements the adjoint_lube_source_term_t type.
Implements the lube_term_objective_t type.
Some common Masking operations we may need.
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 minimum dissipation .
The abstract objective type.