Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
adjoint_fluid_scheme.f90
1! Copyright (c) 2020-2024, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33module adjoint_fluid_scheme
34 use bc, only: bc_t
35 use gather_scatter, only: gs_t
36 use mean_sqr_flow, only: mean_sqr_flow_t
37 use neko_config, only: neko_bcknd_device
38 use checkpoint, only: chkp_t
39 use mean_flow, only: mean_flow_t
40 use num_types, only: rp, i8
41 use comm, only: neko_comm
43 use field, only: field_t
44 use space, only: space_t, gll
45 use dofmap, only: dofmap_t
46 use zero_dirichlet, only: zero_dirichlet_t
47 use krylov, only: ksp_t, krylov_solver_factory, ksp_max_iter
48 use coefs, only: coef_t
49 use usr_inflow, only: usr_inflow_t, usr_inflow_eval
50 use dirichlet, only: dirichlet_t
51 use field_dirichlet, only: field_dirichlet_t
52 use field_dirichlet_vector, only: field_dirichlet_vector_t
53 use jacobi, only: jacobi_t
54 use sx_jacobi, only: sx_jacobi_t
55 use device_jacobi, only: device_jacobi_t
56 use hsmg, only: hsmg_t
57 use phmg, only: phmg_t
58 use precon, only: pc_t, precon_factory, precon_destroy
59 use fluid_stats, only: fluid_stats_t
60 use bc_list, only: bc_list_t
61 use mesh, only: mesh_t, neko_msh_max_zlbls, neko_msh_max_zlbl_len
62 use math, only: cfill, add2s2, glsum
63 use device_math, only: device_cfill, device_add2s2
64 use time_scheme_controller, only: time_scheme_controller_t
65 use operators, only: cfl
66 use logger, only: neko_log, log_size, neko_log_verbose
67 use field_registry, only: neko_field_registry
68 use json_utils, only: json_get, json_get_or_default, json_extract_object, &
69 json_extract_item
70 use json_module, only: json_file, json_core, json_value
71 use scratch_registry, only: scratch_registry_t
72 use user_intf, only: user_t, dummy_user_material_properties, &
73 user_material_properties
74 use utils, only: neko_error, neko_warning
75 use field_series, only: field_series_t
76 use time_step_controller, only: time_step_controller_t
77 use field_math, only: field_cfill, field_add2s2
78 use wall_model_bc, only: wall_model_bc_t
79 use shear_stress, only: shear_stress_t
80 use field_list, only : field_list_t
81 use time_state, only: time_state_t
82 use field_math, only: field_addcol3
83
84 use mpi_f08, only: mpi_integer, mpi_sum, mpi_allreduce
85 use json_utils_ext, only: json_key_fallback
86 use device, only : device_event_sync, glb_cmd_event, device_to_host, &
87 device_memcpy
88 implicit none
89 private
90 public :: adjoint_fluid_scheme_t, adjoint_fluid_scheme_factory
91
93 type, abstract :: adjoint_fluid_scheme_t
95 character(len=:), allocatable :: name
96
97 type(space_t) :: xh
98 type(dofmap_t) :: dm_xh
99 type(gs_t) :: gs_xh
100 type(coef_t) :: c_xh
101
102 type(time_scheme_controller_t), allocatable :: ext_bdf
103
105 type(field_t), pointer :: u_adj => null()
106 type(field_t), pointer :: v_adj => null()
107 type(field_t), pointer :: w_adj => null()
108 type(field_t), pointer :: p_adj => null()
109 type(field_series_t) :: ulag, vlag, wlag
110
112 type(chkp_t), pointer :: chkp => null()
113
115 type(field_t), pointer :: f_adj_x => null()
117 type(field_t), pointer :: f_adj_y => null()
119 type(field_t), pointer :: f_adj_z => null()
120
122 ! List of boundary conditions for pressure
123 type(bc_list_t) :: bcs_prs
124 ! List of boundary conditions for velocity
125 type(bc_list_t) :: bcs_vel
126
127 type(json_file), pointer :: params
128 type(mesh_t), pointer :: msh => null()
129
131 character(len=NEKO_MSH_MAX_ZLBL_LEN), allocatable :: bc_labels(:)
132
134 type(field_t) :: rho
135
137 type(field_t) :: mu
138
140 type(field_list_t) :: material_properties
141
143 logical :: freeze = .false.
144
146 procedure(user_material_properties), nopass, pointer :: &
147 user_material_properties => null()
148
149 contains
151 procedure(adjoint_fluid_scheme_init_intrf), pass(this), deferred :: init
153 procedure(adjoint_fluid_scheme_free_intrf), pass(this), deferred :: free
155 procedure(adjoint_fluid_scheme_step_intrf), pass(this), deferred :: step
157 procedure(adjoint_fluid_scheme_restart_intrf), &
158 pass(this), deferred :: restart
160 procedure(adjoint_fluid_scheme_setup_bcs_intrf), pass(this), deferred :: &
161 setup_bcs
162
164 procedure(validate_intrf), pass(this), deferred :: validate
166 procedure(fluid_scheme_base_compute_cfl_intrf), pass(this), deferred :: compute_cfl
168 procedure(update_material_properties), pass(this), deferred :: update_material_properties
170
172 abstract interface
173 subroutine adjoint_fluid_init_all_intrf(this, msh, lx, params, kspv_init, &
174 kspp_init, scheme, user)
176 import mesh_t
177 import json_file
178 import user_t
179 import rp
180 import log_size
181 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
182 type(mesh_t), target, intent(inout) :: msh
183 integer, intent(inout) :: lx
184 type(json_file), target, intent(inout) :: params
185 type(user_t), target, intent(in) :: user
186 logical :: kspv_init
187 logical :: kspp_init
188 character(len=*), intent(in) :: scheme
189 real(kind=rp) :: abs_tol
190 integer :: integer_val, ierr
191 logical :: logical_val
192 character(len=:), allocatable :: solver_type, precon_type
193 character(len=LOG_SIZE) :: log_buf
194 real(kind=rp) :: gjp_param_a, gjp_param_b
195 end subroutine adjoint_fluid_init_all_intrf
196 end interface
197
199 abstract interface
200 subroutine adjoint_fluid_init_common_intrf(this, msh, lx, params, scheme, &
201 user, kspv_init)
203 import mesh_t
204 import json_file
205 import user_t
206 import dirichlet_t
207 import log_size
208 import rp
209 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
210 type(mesh_t), target, intent(inout) :: msh
211 integer, intent(inout) :: lx
212 character(len=*), intent(in) :: scheme
213 type(json_file), target, intent(inout) :: params
214 type(user_t), target, intent(in) :: user
215 logical, intent(in) :: kspv_init
216 type(dirichlet_t) :: bdry_mask
217 character(len=LOG_SIZE) :: log_buf
218 real(kind=rp), allocatable :: real_vec(:)
219 real(kind=rp) :: real_val, kappa, b, z0
220 logical :: logical_val
221 integer :: integer_val, ierr
222 type(json_file) :: wm_json
223 character(len=:), allocatable :: string_val1, string_val2
224 end subroutine adjoint_fluid_init_common_intrf
225 end interface
226
228 abstract interface
229 subroutine adjoint_fluid_free_intrf(this)
231 class(adjoint_fluid_scheme_t), intent(inout) :: this
232 end subroutine adjoint_fluid_free_intrf
233 end interface
234
236 abstract interface
237 subroutine adjoint_fluid_scheme_init_intrf(this, msh, lx, params, user, &
238 chkp)
240 import json_file
241 import mesh_t
242 import user_t
243 import chkp_t
244 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
245 type(mesh_t), target, intent(inout) :: msh
246 integer, intent(in) :: lx
247 type(json_file), target, intent(inout) :: params
248 type(user_t), target, intent(in) :: user
249 type(chkp_t), target, intent(inout) :: chkp
250 end subroutine adjoint_fluid_scheme_init_intrf
251 end interface
252
254 abstract interface
255 subroutine adjoint_fluid_scheme_free_intrf(this)
257 class(adjoint_fluid_scheme_t), intent(inout) :: this
258 end subroutine adjoint_fluid_scheme_free_intrf
259 end interface
260
262 abstract interface
263 subroutine adjoint_fluid_scheme_step_intrf(this, time, dt_controller)
264 import time_state_t
266 import time_step_controller_t
267 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
268 type(time_state_t), intent(in) :: time
269 type(time_step_controller_t), intent(in) :: dt_controller
270 end subroutine adjoint_fluid_scheme_step_intrf
271 end interface
272
274 abstract interface
275 subroutine adjoint_fluid_scheme_restart_intrf(this, chkp)
277 import chkp_t
278 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
279 type(chkp_t), intent(inout) :: chkp
280 end subroutine adjoint_fluid_scheme_restart_intrf
281 end interface
282
284 abstract interface
285 subroutine adjoint_fluid_scheme_setup_bcs_intrf(this, user, params)
286 import adjoint_fluid_scheme_t, user_t, json_file
287 class(adjoint_fluid_scheme_t), intent(inout) :: this
288 type(user_t), target, intent(in) :: user
289 type(json_file), intent(inout) :: params
290 end subroutine adjoint_fluid_scheme_setup_bcs_intrf
291 end interface
292
294 abstract interface
295 subroutine validate_intrf(this)
297 class(adjoint_fluid_scheme_t), target, intent(inout) :: this
298 end subroutine validate_intrf
299 end interface
300
302 abstract interface
303 subroutine update_material_properties(this, t, tstep)
304 import adjoint_fluid_scheme_t, rp
305 class(adjoint_fluid_scheme_t), intent(inout) :: this
306 real(kind=rp),intent(in) :: t
307 integer, intent(in) :: tstep
308 end subroutine update_material_properties
309 end interface
310
312 abstract interface
313 function fluid_scheme_base_compute_cfl_intrf(this, dt) result(c)
315 import rp
316 class(adjoint_fluid_scheme_t), intent(in) :: this
317 real(kind=rp), intent(in) :: dt
318 real(kind=rp) :: c
319 end function fluid_scheme_base_compute_cfl_intrf
320 end interface
321
322 interface
323
324 module subroutine adjoint_fluid_scheme_factory(object, type_name)
325 class(adjoint_fluid_scheme_t), intent(inout), allocatable :: object
326 character(len=*) :: type_name
327 end subroutine adjoint_fluid_scheme_factory
328 end interface
329end module adjoint_fluid_scheme
Implements the adjoint_source_term_t type.
Wrapper contaning and executing the adjoint source terms.