295 subroutine adjoint_fluid_scheme_init_base(this, msh, lx, params, scheme, &
297 class(adjoint_fluid_scheme_t),
target,
intent(inout) :: this
298 type(mesh_t),
target,
intent(inout) :: msh
299 integer,
intent(in) :: lx
300 character(len=*),
intent(in) :: scheme
301 type(json_file),
target,
intent(inout) :: params
302 type(user_t),
target,
intent(in) :: user
303 logical,
intent(in) :: kspv_init
304 character(len=LOG_SIZE) :: log_buf
305 real(kind=rp) :: real_val
306 logical :: logical_val
307 integer :: integer_val
308 character(len=:),
allocatable :: string_val1, string_val2
309 real(kind=rp) :: gjp_param_a, gjp_param_b
310 character(len=:),
allocatable :: json_key
318 if (msh%gdim .eq. 2)
then
319 call this%Xh%init(gll, lx, lx)
321 call this%Xh%init(gll, lx, lx, lx)
324 call this%dm_Xh%init(msh, this%Xh)
326 call this%gs_Xh%init(this%dm_Xh)
328 call this%c_Xh%init(this%gs_Xh)
331 this%scratch = scratch_registry_t(this%dm_Xh, 10, 2)
337 call neko_log%section(
'Adjoint fluid')
338 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
339 call neko_log%message(log_buf)
344 call this%set_material_properties(params,
user)
349 if (params%valid_path(
'case.fluid.nut_field'))
then
350 call neko_error(
'Variable material properties not yet implemented')
351 call json_get(params,
'case.fluid.nut_field', this%nut_field_name)
352 this%variable_material_properties = .true.
354 this%nut_field_name =
""
359 call this%mu_field%init(this%dm_Xh,
"mu")
360 call this%rho_field%init(this%dm_Xh,
"mu")
361 call field_cfill(this%mu_field, this%mu, this%mu_field%size())
362 call field_cfill(this%rho_field, this%rho, this%mu_field%size())
367 if (neko_bcknd_device .eq. 1)
then
368 call cfill(this%mu_field%x, this%mu, this%mu_field%size())
369 call cfill(this%rho_field%x, this%rho, this%rho_field%size())
375 'case.adjoint_fluid.velocity_solver.projection_space_size', &
376 'case.fluid.velocity_solver.projection_space_size')
377 call json_get_or_default(params, json_key, this%vel_projection_dim, 20)
379 'case.adjoint_fluid.pressure_solver.projection_space_size', &
380 'case.fluid.pressure_solver.projection_space_size')
381 call json_get_or_default(params, json_key, this%pr_projection_dim, 20)
384 'case.adjoint_fluid.velocity_solver.projection_hold_steps', &
385 'case.fluid.velocity_solver.projection_hold_steps')
386 call json_get_or_default(params, json_key, &
387 this%vel_projection_activ_step, 5)
389 'case.adjoint_fluid.pressure_solver.projection_hold_steps', &
390 'case.fluid.pressure_solver.projection_hold_steps')
391 call json_get_or_default(params, json_key, &
392 this%pr_projection_activ_step, 5)
396 call json_get_or_default(params, json_key, this%freeze, .false.)
405 if (params%valid_path(
"case.fluid.flow_rate_force"))
then
406 call neko_error(
'Flow rate forcing not yet implemented')
407 this%forced_flow_rate = .true.
412 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
413 else if (lx .ge. 10)
then
414 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
416 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
418 call neko_log%message(log_buf)
419 this%glb_n_points = int(this%msh%glb_nelv, i8)*int(this%Xh%lxyz, i8)
420 this%glb_unique_points = int(glsum(this%c_Xh%mult, this%dm_Xh%size()), i8)
422 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
423 call neko_log%message(log_buf)
424 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
425 call neko_log%message(log_buf)
427 write(log_buf,
'(A,ES13.6)')
'rho :', this%rho
428 call neko_log%message(log_buf)
429 write(log_buf,
'(A,ES13.6)')
'mu :', this%mu
430 call neko_log%message(log_buf)
432 call json_get(params,
'case.numerics.dealias', logical_val)
433 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
434 call neko_log%message(log_buf)
436 write(log_buf,
'(A, L1)')
'LES : ', this%variable_material_properties
437 call neko_log%message(log_buf)
439 call json_get_or_default(params,
'case.output_boundary', logical_val, &
441 write(log_buf,
'(A, L1)')
'Save bdry : ', logical_val
442 call neko_log%message(log_buf)
447 allocate(this%f_adj_x)
448 allocate(this%f_adj_y)
449 allocate(this%f_adj_z)
450 call this%f_adj_x%init(this%dm_Xh, fld_name =
"adjoint_rhs_x")
451 call this%f_adj_y%init(this%dm_Xh, fld_name =
"adjoint_rhs_y")
452 call this%f_adj_z%init(this%dm_Xh, fld_name =
"adjoint_rhs_z")
474 call this%source_term%init(this%f_adj_x, this%f_adj_y, this%f_adj_z, &
476 call this%source_term%add(params,
'case.adjoint_fluid.source_term')
496 call neko_log%section(
"Adjoint Velocity solver")
499 'case.adjoint_fluid.velocity_solver.max_iterations', &
500 'case.fluid.velocity_solver.max_iterations')
501 call json_get_or_default(params, json_key, integer_val, ksp_max_iter)
504 'case.adjoint_fluid.velocity_solver.type', &
505 'case.fluid.velocity_solver.type')
506 call json_get(params, json_key, string_val1)
509 'case.adjoint_fluid.velocity_solver.preconditioner', &
510 'case.fluid.velocity_solver.preconditioner')
511 call json_get(params, json_key, string_val2)
514 'case.adjoint_fluid.velocity_solver.absolute_tolerance', &
515 'case.fluid.velocity_solver.absolute_tolerance')
516 call json_get(params, json_key, real_val)
519 'case.adjoint_fluid.velocity_solver.monitor', &
520 'case.fluid.velocity_solver.monitor')
521 call json_get_or_default(params, json_key, logical_val, .false.)
523 call neko_log%message(
'Type : ('// trim(string_val1) // &
524 ', ' // trim(string_val2) //
')')
526 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
527 call neko_log%message(log_buf)
528 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
529 string_val1, integer_val, real_val, logical_val)
530 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
531 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs_vel, string_val2)
532 call neko_log%end_section()
536 call json_get_or_default(params,
'case.fluid.strict_convergence', &
537 this%strict_convergence, .false.)
540 call neko_field_registry%add_field(this%dm_Xh,
'u_adj')
541 call neko_field_registry%add_field(this%dm_Xh,
'v_adj')
542 call neko_field_registry%add_field(this%dm_Xh,
'w_adj')
543 this%u_adj => neko_field_registry%get_field(
'u_adj')
544 this%v_adj => neko_field_registry%get_field(
'v_adj')
545 this%w_adj => neko_field_registry%get_field(
'w_adj')
548 call this%ulag%init(this%u_adj, 2)
549 call this%vlag%init(this%v_adj, 2)
550 call this%wlag%init(this%w_adj, 2)
553 call json_get_or_default(params, &
554 'case.fluid.gradient_jump_penalty.enabled',&
555 this%if_gradient_jump_penalty, .false.)
557 if (this%if_gradient_jump_penalty .eqv. .true.)
then
558 call neko_error(
'Gradient jump penalty not implemented for adjoint')
560 if ((this%dm_Xh%xh%lx - 1) .eq. 1)
then
561 call json_get_or_default(params, &
562 'case.fluid.gradient_jump_penalty.tau',&
563 gjp_param_a, 0.02_rp)
566 call json_get_or_default(params, &
567 'case.fluid.gradient_jump_penalty.scaling_factor',&
569 call json_get_or_default(params, &
570 'case.fluid.gradient_jump_penalty.scaling_exponent',&
573 call this%gradient_jump_penalty_u_adj%init(params, this%dm_Xh, &
574 this%c_Xh, gjp_param_a, gjp_param_b)
575 call this%gradient_jump_penalty_v_adj%init(params, this%dm_Xh, &
576 this%c_Xh, gjp_param_a, gjp_param_b)
577 call this%gradient_jump_penalty_w_adj%init(params, this%dm_Xh, &
578 this%c_Xh, gjp_param_a, gjp_param_b)
581 call neko_log%end_section()