Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
minimum_dissipation_objective.f90
Go to the documentation of this file.
1
34!
36!
37! I promise I'll write this document properly in the future...
38!
39! But the Borval Peterson (I think) paper had an objective function
40! that had 2 terms, dissipation and this term they claimed represented
41! out of plane stresses.
42! I never really understood that extra term, I also don't think it
43! applies to 3D cases, but everyone includes it anyway.
44!
45! It appears to me to be basically a heuristic penality that targets
46! non-binary designs
47!
48! so let's call
49!
50! F = \int |\nabla u|^2 + K \int \chi \u^2
51!
52! | dissipation | |"lube term"|
53!
54! I say "lube term" because they said it came from lubrication theory...
55! Anyway, we can change all this later (especially the names!)
56
57! If the objective function \int |\nabla u|^2,
58! the corresponding adjoint forcing is \int \nabla v \cdot \nabla u
59!
60! for the lube term, the adjoint forcing is \chi u
61!
62! This has always annoyed me...
63! because now I see one objective and one constraint
64!
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, &
69 field_copy
70 use operators, only: grad
72 use scratch_registry, only: neko_scratch_registry
75 use objective, only: objective_t
76 use simulation_m, only: simulation_t
77 use adjoint_fluid_scheme, only: adjoint_fluid_scheme_t
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
83 use design, only: design_t
84 use brinkman_design, only: brinkman_design_t
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
91 implicit none
92 private
93
97 private
98
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
115
116 contains
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
131
133
134contains
135
141 subroutine minimum_dissipation_init_json_sim(this, json, design, simulation)
142 class(minimum_dissipation_objective_t), intent(inout) :: this
143 type(json_file), intent(inout) :: json
144 class(design_t), intent(in) :: design
145 type(simulation_t), target, intent(inout) :: simulation
146
147 character(len=:), allocatable :: name
148 character(len=:), allocatable :: mask_name
149 real(kind=rp) :: weight
150
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")
154
155 call this%init_from_attributes(design, simulation, weight, name, mask_name)
157
165 subroutine minimum_dissipation_init_attributes(this, design, simulation, &
166 weight, name, mask_name)
167 class(minimum_dissipation_objective_t), intent(inout) :: this
168 class(design_t), intent(in) :: design
169 type(simulation_t), target, intent(inout) :: simulation
170 real(kind=rp), intent(in) :: weight
171 character(len=*), intent(in) :: name
172 character(len=*), intent(in) :: mask_name
173 type(adjoint_minimum_dissipation_source_term_t) :: adjoint_forcing
174
175 call this%init_base(name, design%size(), weight, mask_name)
176
177 ! Save the simulation and design
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')
185
186 ! compute the volume of the objective domain
187 if (this%has_mask) then
188 this%volume = compute_masked_volume(this%mask, this%c_Xh)
189 else
190 this%volume = this%c_Xh%volume
191 end if
192
193 ! you will need to init this!
194 ! append a source term based on the minimum dissipation
195 ! init the adjoint forcing term for the adjoint
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)
203
204 ! append adjoint forcing term based on objective function
205 select type (f => simulation%adjoint_fluid)
206 type is (adjoint_fluid_pnpn_t)
207 call f%source_term%add_source_term(adjoint_forcing)
208 end select
209
210 end subroutine minimum_dissipation_init_attributes
211
213 subroutine minimum_dissipation_free(this)
214 class(minimum_dissipation_objective_t), intent(inout) :: this
215 call this%free_base()
216
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)
221
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)
225
226 end subroutine minimum_dissipation_free
227
231 subroutine minimum_dissipation_update_value(this, design)
232 class(minimum_dissipation_objective_t), intent(inout) :: this
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)
237 integer n
238
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), &
243 .false.)
244 call neko_scratch_registry%request_field(work, temp_indices(5), .false.)
245
246 ! update_value the objective function.
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)
251
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)
256
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)
261
262 ! integrate the field
263 n = wo1%size()
264 if (this%has_mask) then
265 if (neko_bcknd_device .eq. 1) then
266 ! note, this could be done more elagantly by writing
267 ! device_glsc2_mask
268 call field_copy(work, objective_field)
269 call mask_exterior_const(work, this%mask, 0.0_rp)
270 this%value = device_glsc2(work%x_d, this%c_xh%B_d, n)
271 else
272 this%value = glsc2_mask(objective_field%x, this%c_Xh%b, &
273 n, this%mask%mask%get(), this%mask%size)
274 end if
275 else
276 if (neko_bcknd_device .eq. 1) then
277 this%value = device_glsc2(objective_field%x_d, &
278 this%c_Xh%b_d, n)
279 else
280 this%value = glsc2(objective_field%x, this%c_Xh%b, n)
281 end if
282 end if
283
284 this%value = this%value * 0.5_rp / this%volume
285
286 call neko_scratch_registry%relinquish_field(temp_indices)
287
288 end subroutine minimum_dissipation_update_value
289
293 subroutine minimum_dissipation_update_sensitivity(this, design)
294 class(minimum_dissipation_objective_t), intent(inout) :: this
295 class(design_t), intent(in) :: design
296
297 end subroutine minimum_dissipation_update_sensitivity
298
Adjoint Pn/Pn formulation.
Implements the adjoint_minimum_dissipation_source_term_t type.
Implements the design_t.
Definition design.f90:36
Some common Masking operations we may need.
Definition mask_ops.f90:36
real(kind=rp) function, public compute_masked_volume(mask, coef)
Compute the volume of the domain contained within the mask.
Definition mask_ops.f90:182
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.
Definition objective.f90:36
Implements the steady_problem_t type.
A topology optimization design variable.
An abstract design type.
Definition design.f90:54
An objective function corresponding to minimum dissipation .
The abstract objective type.
Definition objective.f90:52