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
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()
113 procedure,
public, pass(this) :: init_from_attributes => &
118 procedure,
public, pass(this) :: update_value => &
121 procedure,
public, pass(this) :: update_sensitivity => &
134 type(json_file),
intent(inout) :: json
135 class(
design_t),
intent(in) :: design
137 character(len=:),
allocatable :: mask_name
138 character(len=:),
allocatable :: name
139 real(kind=rp) :: weight, k
141 call json_get_or_default(json,
"weight", weight, 1.0_rp)
142 call json_get_or_default(json,
"mask_name", mask_name,
"")
143 call json_get_or_default(json,
"name", name,
"Out of plane stresses")
144 call json_get_or_default(json,
"K", k, 1.0_rp)
159 class(
design_t),
intent(in) :: design
161 real(kind=rp),
intent(in) :: weight
162 character(len=*),
intent(in) :: mask_name
163 character(len=*),
intent(in) :: name
164 real(kind=rp),
intent(in) :: k
168 call this%init_base(name,
design%size(), weight, mask_name)
176 this%brinkman_amplitude => &
177 neko_field_registry%get_field(
"brinkman_amplitude")
181 call neko_error(
'Minimum dissipation only works with brinkman_design')
184 this%u => neko_field_registry%get_field(
'u')
185 this%v => neko_field_registry%get_field(
'v')
186 this%w => neko_field_registry%get_field(
'w')
191 associate(f_adj_x =>
simulation%adjoint_case%scheme%f_adj_x, &
192 f_adj_y =>
simulation%adjoint_case%scheme%f_adj_y, &
193 f_adj_z =>
simulation%adjoint_case%scheme%f_adj_z, &
196 call lube_term%init_from_components(f_adj_x, f_adj_y, f_adj_z,
design, &
197 this%k * this%weight, &
198 this%u, this%v, this%w, &
199 this%mask, this%has_mask, c_xh)
204 call simulation%adjoint_case%scheme%source_term%add_source_term(lube_term)
211 call this%free_base()
217 this%brinkman_amplitude => null()
227 class(design_t),
intent(in) :: design
228 type(field_t),
pointer :: work
229 integer :: temp_indices(1)
231 call neko_scratch_registry%request_field(work, temp_indices(1))
238 call field_col3(work, this%u, this%brinkman_amplitude)
239 call field_addcol3(work, this%v, this%brinkman_amplitude)
240 call field_addcol3(work, this%w, this%brinkman_amplitude)
242 if (this%has_mask)
then
243 if (neko_bcknd_device .eq. 1)
then
246 call mask_exterior_const(work, this%mask, 0.0_rp)
247 this%value = device_glsc2(work%x_d, this%c_Xh%B_d,
design%size())
249 this%value = glsc2_mask(work%x, this%c_Xh%B,
design%size(), &
250 this%mask%mask, this%mask%size)
253 if (neko_bcknd_device .eq. 1)
then
254 this%value = device_glsc2(work%x_d, this%c_Xh%B_d,
design%size())
256 this%value = glsc2(work%x, this%c_Xh%B,
design%size())
259 this%value = 0.5 * this%K * this%value
261 call neko_scratch_registry%relinquish_field(temp_indices)
269 class(design_t),
intent(in) :: design
270 type(field_t),
pointer :: work
271 integer :: temp_indices(1)
280 call neko_scratch_registry%request_field(work, temp_indices(1))
282 call field_col3(work, this%u, this%u)
283 call field_addcol3(work, this%v, this%v)
284 call field_addcol3(work, this%w, this%w)
285 call field_cmult(work, this%K)
287 if (neko_bcknd_device .eq. 1)
then
288 call device_copy(this%sensitivity%x_d, work%x_d, this%sensitivity%size())
290 call copy(this%sensitivity%x, work%x, this%sensitivity%size())
293 call neko_scratch_registry%relinquish_field(temp_indices)
Implements the adjoint_lube_source_term_t type.
Implements the lube_term_objective_t type.
subroutine lube_term_init_json(this, json, design, simulation)
The common constructor using a JSON object.
subroutine lube_term_update_value(this, design)
Compute the objective function.
subroutine lube_term_init_attributes(this, design, simulation, weight, name, mask_name, k)
The actual constructor.
subroutine lube_term_free(this)
Destructor.
subroutine lube_term_update_sensitivity(this, design)
update_value the sensitivity of the objective function with respect to $\chi$
Some common Masking operations we may need.
real(kind=rp) function glsc2_mask(a, b, size, mask, mask_size)
Weighted inner product for indices in 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 minimum dissipation $ F = \int_\Omega |\nabla u|^2 d \Omega + ...
The abstract objective type.