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    select type (f => simulation%adjoint_fluid)
 
  209       call f%source_term%add_source_term(lube_term)
 
  212  end subroutine lube_term_init_attributes
 
  215  subroutine lube_term_free(this)
 
  217    call this%free_base()
 
  223    this%brinkman_amplitude => null()
 
  225  end subroutine lube_term_free
 
  230  subroutine lube_term_update_value(this, design)
 
  232    class(design_t), 
intent(in) :: design
 
  233    type(field_t), 
pointer :: work
 
  234    integer :: temp_indices(1)
 
  236    call neko_scratch_registry%request_field(work, temp_indices(1))
 
  243    call field_col3(work, this%u, this%brinkman_amplitude)
 
  244    call field_addcol3(work, this%v, this%brinkman_amplitude)
 
  245    call field_addcol3(work, this%w, this%brinkman_amplitude)
 
  247    if (this%has_mask) 
then 
  248       if (neko_bcknd_device .eq. 1) 
then 
  251          call mask_exterior_const(work, this%mask, 0.0_rp)
 
  252          this%value = device_glsc2(work%x_d, this%c_Xh%B_d, 
design%size())
 
  254          this%value = glsc2_mask(work%x, this%c_Xh%B, 
design%size(), &
 
  255               this%mask%mask%get(), this%mask%size)
 
  258       if (neko_bcknd_device .eq. 1) 
then 
  259          this%value = device_glsc2(work%x_d, this%c_Xh%B_d, 
design%size())
 
  261          this%value = glsc2(work%x, this%c_Xh%B, 
design%size())
 
  264    this%value = 0.5_rp * this%K * this%value
 
  266    call neko_scratch_registry%relinquish_field(temp_indices)
 
  268  end subroutine lube_term_update_value
 
  273  subroutine lube_term_update_sensitivity(this, design)
 
  275    class(design_t), 
intent(in) :: design
 
  276    type(field_t), 
pointer :: work
 
  277    integer :: temp_indices(1)
 
  286    call neko_scratch_registry%request_field(work, temp_indices(1))
 
  288    call field_col3(work, this%u, this%u)
 
  289    call field_addcol3(work, this%v, this%v)
 
  290    call field_addcol3(work, this%w, this%w)
 
  291    call field_cmult(work, this%K)
 
  293    if (neko_bcknd_device .eq. 1) 
then 
  294       call device_copy(this%sensitivity%x_d, work%x_d, this%sensitivity%size())
 
  296       call copy(this%sensitivity%x, work%x, this%sensitivity%size())
 
  299    call neko_scratch_registry%relinquish_field(temp_indices)
 
  301  end subroutine lube_term_update_sensitivity
 
Adjoint Pn/Pn formulation.
 
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.