Skip to content

Commit

Permalink
Merge pull request #71 from mnlevy1981/feature/BryanLewis_low
Browse files Browse the repository at this point in the history
Provide low-level interface for BL initialization
  • Loading branch information
mnlevy1981 authored Apr 12, 2018
2 parents 59edff7 + 36b29dd commit 04136cf
Showing 1 changed file with 54 additions and 20 deletions.
74 changes: 54 additions & 20 deletions src/shared/cvmix_background.F90
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ module cvmix_background
module procedure cvmix_init_bkgnd_scalar
module procedure cvmix_init_bkgnd_1D
module procedure cvmix_init_bkgnd_2D
module procedure cvmix_init_bkgnd_BryanLewis
module procedure cvmix_init_bkgnd_BryanLewis_wrap
module procedure cvmix_init_bkgnd_BryanLewis_low
end interface cvmix_init_bkgnd

interface cvmix_coeffs_bkgnd
Expand Down Expand Up @@ -360,12 +361,51 @@ end subroutine cvmix_init_bkgnd_2D

!BOP

! !IROUTINE: cvmix_init_bkgnd_BryanLewis
! !IROUTINE: cvmix_init_bkgnd_BryanLewis_wrap
! !INTERFACE:

subroutine cvmix_init_bkgnd_BryanLewis(CVmix_vars, bl1, bl2, bl3, bl4, &
CVmix_params_in, old_vals, &
CVmix_bkgnd_params_user)
subroutine cvmix_init_bkgnd_BryanLewis_wrap(CVmix_vars, bl1, bl2, bl3, bl4, &
CVmix_params_in, old_vals, &
CVmix_bkgnd_params_user)

! !DESCRIPTION:
! Calls cvmix_init_bkgnd_BryanLewis_low
!
! !USES:
! Only those used by entire module.

! !INPUT PARAMETERS:
! Contains depth and nlev
type(cvmix_data_type), intent(in) :: CVmix_vars
! Units are first column if CVmix_data%depth is m, second if cm
real(cvmix_r8), intent(in) :: bl1, &! m^2/s or cm^2/s
bl2, &! m^2/s or cm^2/s
bl3, &! 1/m or 1/cm
bl4 ! m or cm
character(len=cvmix_strlen), optional, intent(in) :: old_vals
type(cvmix_global_params_type), intent(in) :: CVmix_params_in

! !OUTPUT PARAMETERS:
type(cvmix_bkgnd_params_type), target, optional, intent(inout) :: &
CVmix_bkgnd_params_user
!EOP
!BOC

call cvmix_init_bkgnd(CVmix_params_in%max_nlev,-CVMix_vars%zw_iface, bl1, &
bl2, bl3, bl4, CVmix_params_in%prandtl, &
old_vals, CVmix_bkgnd_params_user)

!EOC

end subroutine cvmix_init_bkgnd_BryanLewis_wrap

!BOP

! !IROUTINE: cvmix_coeffs_bkgnd_low
! !INTERFACE:

subroutine cvmix_init_bkgnd_BryanLewis_low(max_nlev, zw, bl1, bl2, bl3, bl4, &
prandtl, old_vals, CVmix_bkgnd_params_user)

! !DESCRIPTION:
! Initialization routine for Bryan-Lewis diffusivity/viscosity calculation.
Expand Down Expand Up @@ -401,15 +441,15 @@ subroutine cvmix_init_bkgnd_BryanLewis(CVmix_vars, bl1, bl2, bl3, bl4, &
! Only those used by entire module.

! !INPUT PARAMETERS:
! Contains depth and nlev
type(cvmix_data_type), intent(in) :: CVmix_vars
integer, intent(in) :: max_nlev
real(cvmix_r8), dimension(max_nlev+1), intent(in) :: zw
! Units are first column if CVmix_data%depth is m, second if cm
real(cvmix_r8), intent(in) :: bl1, &! m^2/s or cm^2/s
bl2, &! m^2/s or cm^2/s
bl3, &! 1/m or 1/cm
bl4 ! m or cm
bl4, &! m or cm
prandtl ! nondim
character(len=cvmix_strlen), optional, intent(in) :: old_vals
type(cvmix_global_params_type), intent(in) :: CVmix_params_in

! !OUTPUT PARAMETERS:
type(cvmix_bkgnd_params_type), target, optional, intent(inout) :: &
Expand All @@ -420,34 +460,28 @@ subroutine cvmix_init_bkgnd_BryanLewis(CVmix_vars, bl1, bl2, bl3, bl4, &
! Pointers to parameter data type
type(cvmix_bkgnd_params_type), pointer :: CVmix_bkgnd_params_out

! Local index
integer :: nlev ! max number of levels

! Local copies to make code easier to read
real(cvmix_r8), dimension(CVmix_params_in%max_nlev+1) :: Mdiff, Tdiff, zw
real(cvmix_r8), dimension(max_nlev+1) :: Mdiff, Tdiff

CVmix_bkgnd_params_out => CVmix_bkgnd_params_saved
if (present(CVmix_bkgnd_params_user)) then
CVmix_bkgnd_params_out => CVmix_bkgnd_params_user
end if

nlev = CVmix_params_in%max_nlev

! Clean up memory in bkgnd_params_type (will be re-allocated in put call)
if (allocated(CVmix_bkgnd_params_out%static_Mdiff)) &
deallocate(CVmix_bkgnd_params_out%static_Mdiff)
if (allocated(CVmix_bkgnd_params_out%static_Tdiff)) &
deallocate(CVmix_bkgnd_params_out%static_Tdiff)

! Set static_[MT]diff in background_input_type
zw = -CVmix_vars%zw_iface
Tdiff = bl1 + (bl2/cvmix_PI)*atan(bl3*(zw-bl4))
Mdiff = CVmix_params_in%prandtl*Tdiff
Mdiff = prandtl*Tdiff

call cvmix_put_bkgnd("static_Mdiff", Mdiff, CVmix_bkgnd_params_user, &
nlev=nlev)
nlev=max_nlev)
call cvmix_put_bkgnd("static_Tdiff", Tdiff, CVmix_bkgnd_params_user, &
nlev=nlev)
nlev=max_nlev)

if (present(old_vals)) then
select case (trim(old_vals))
Expand All @@ -472,7 +506,7 @@ subroutine cvmix_init_bkgnd_BryanLewis(CVmix_vars, bl1, bl2, bl3, bl4, &

!EOC

end subroutine cvmix_init_bkgnd_BryanLewis
end subroutine cvmix_init_bkgnd_BryanLewis_low

!BOP

Expand Down

0 comments on commit 04136cf

Please sign in to comment.