Skip to content

Commit

Permalink
Merge pull request #45 from CVMix/feature/allow_inactive_levels
Browse files Browse the repository at this point in the history
Feature/allow inactive levels

Still need to generate a stand-alone test that allocates more memory than it needs
  • Loading branch information
mnlevy1981 committed Oct 10, 2014
2 parents de44154 + 01d35fa commit 004a6c5
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 128 deletions.
2 changes: 1 addition & 1 deletion bld/CompileFlags.mak
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ifeq ($(FC_TMP),pgf90)
endif

ifeq ($(FC_TMP),ifort)
FCFLAGS = -O2 -free -module $(OBJ_DIR) -cpp -warn all -diag-error warn,remark -nogen-interface
FCFLAGS = -O2 -free -module $(OBJ_DIR) -cpp -warn all -diag-error warn,remark -nogen-interface -fp-model precise
endif

ifeq ($(FC_TMP),xlf90)
Expand Down
44 changes: 24 additions & 20 deletions src/shared/cvmix_background.F90
Original file line number Diff line number Diff line change
Expand Up @@ -507,23 +507,26 @@ subroutine cvmix_coeffs_bkgnd_wrap(CVmix_vars, colid, &
!EOP
!BOC

real(cvmix_r8), dimension(CVmix_vars%nlev+1) :: new_Mdiff, new_Tdiff
type(cvmix_bkgnd_params_type), pointer :: CVmix_bkgnd_params_in
real(cvmix_r8), dimension(CVmix_vars%max_nlev+1) :: new_Mdiff, new_Tdiff
type(cvmix_bkgnd_params_type), pointer :: CVmix_bkgnd_params_in
integer :: nlev, max_nlev

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

nlev = CVmix_vars%nlev
max_nlev = CVmix_vars%max_nlev

if (.not.associated(CVmix_vars%Mdiff_iface)) &
call cvmix_put(CVmix_vars, "Mdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Mdiff", cvmix_zero, max_nlev)
if (.not.associated(CVmix_vars%Tdiff_iface)) &
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero, max_nlev)

call cvmix_coeffs_bkgnd(new_Mdiff, new_Tdiff, colid, &
call cvmix_coeffs_bkgnd(new_Mdiff, new_Tdiff, nlev, max_nlev, colid, &
CVmix_bkgnd_params_user)
call cvmix_update_wrap(CVmix_bkgnd_params_in%handle_old_vals, &
CVmix_vars%nlev, &
call cvmix_update_wrap(CVmix_bkgnd_params_in%handle_old_vals, max_nlev, &
Mdiff_out = CVmix_vars%Mdiff_iface, &
new_Mdiff = new_Mdiff, &
Tdiff_out = CVmix_vars%Tdiff_iface, &
Expand All @@ -538,8 +541,8 @@ end subroutine cvmix_coeffs_bkgnd_wrap
! !IROUTINE: cvmix_coeffs_bkgnd_low
! !INTERFACE:

subroutine cvmix_coeffs_bkgnd_low(Mdiff_out, Tdiff_out, colid, &
CVmix_bkgnd_params_user)
subroutine cvmix_coeffs_bkgnd_low(Mdiff_out, Tdiff_out, nlev, max_nlev, &
colid, CVmix_bkgnd_params_user)

! !DESCRIPTION:
! Computes vertical tracer and velocity mixing coefficients for static
Expand All @@ -554,13 +557,16 @@ subroutine cvmix_coeffs_bkgnd_low(Mdiff_out, Tdiff_out, colid, &
! !INPUT PARAMETERS:

! Need to know column for pulling data from static_visc and _diff
integer, intent(in) :: nlev, &
max_nlev
integer, optional, intent(in) :: colid
type(cvmix_bkgnd_params_type), target, optional, intent(in) :: &
CVmix_bkgnd_params_user

! !OUTPUT PARAMETERS:
! Using intent(inout) because memory should already be allocated
real(cvmix_r8), dimension(:), intent(inout) :: Mdiff_out, Tdiff_out
real(cvmix_r8), dimension(max_nlev+1), intent(inout) :: Mdiff_out, &
Tdiff_out

!EOP
!BOC
Expand All @@ -571,14 +577,12 @@ subroutine cvmix_coeffs_bkgnd_low(Mdiff_out, Tdiff_out, colid, &
!
!-----------------------------------------------------------------------

integer :: nlev
type(cvmix_bkgnd_params_type), pointer :: CVmix_bkgnd_params_in

CVmix_bkgnd_params_in => CVmix_bkgnd_params_saved
if (present(CVmix_bkgnd_params_user)) then
CVmix_bkgnd_params_in => CVmix_bkgnd_params_user
end if
nlev = size(Mdiff_out)-1

if (CVmix_bkgnd_params_in%lvary_horizontal.and.(.not.present(colid))) then
print*, "ERROR: background parameters vary in horizontal so you must ", &
Expand All @@ -588,19 +592,19 @@ subroutine cvmix_coeffs_bkgnd_low(Mdiff_out, Tdiff_out, colid, &

if (CVmix_bkgnd_params_in%lvary_horizontal) then
if (CVmix_bkgnd_params_in%lvary_vertical) then
Mdiff_out = CVmix_bkgnd_params_in%static_visc(colid,1:nlev+1)
Tdiff_out = CVmix_bkgnd_params_in%static_diff(colid,1:nlev+1)
Mdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_visc(colid,1:nlev+1)
Tdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_diff(colid,1:nlev+1)
else
Mdiff_out = CVmix_bkgnd_params_in%static_visc(colid,1)
Tdiff_out = CVmix_bkgnd_params_in%static_diff(colid,1)
Mdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_visc(colid,1)
Tdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_diff(colid,1)
end if
else
if (CVmix_bkgnd_params_in%lvary_vertical) then
Mdiff_out = CVmix_bkgnd_params_in%static_visc(1,1:nlev+1)
Tdiff_out = CVmix_bkgnd_params_in%static_diff(1,1:nlev+1)
Mdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_visc(1,1:nlev+1)
Tdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_diff(1,1:nlev+1)
else
Mdiff_out = CVmix_bkgnd_params_in%static_visc(1,1)
Tdiff_out = CVmix_bkgnd_params_in%static_diff(1,1)
Mdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_visc(1,1)
Tdiff_out(1:nlev+1) = CVmix_bkgnd_params_in%static_diff(1,1)
end if
end if

Expand Down
36 changes: 21 additions & 15 deletions src/shared/cvmix_convection.F90
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,30 @@ subroutine cvmix_coeffs_conv_wrap(CVmix_vars, CVmix_conv_params_user)
!
!-----------------------------------------------------------------------

real(cvmix_r8), dimension(CVmix_vars%nlev+1) :: new_Mdiff, new_Tdiff
real(cvmix_r8), dimension(CVmix_vars%max_nlev+1) :: new_Mdiff, new_Tdiff
type (cvmix_conv_params_type), pointer :: CVmix_conv_params_in
integer :: nlev, max_nlev

if (present(CVmix_conv_params_user)) then
CVmix_conv_params_in => CVmix_conv_params_user
else
CVmix_conv_params_in => CVmix_conv_params_saved
end if

nlev = CVmix_vars%nlev
max_nlev = CVmix_vars%max_nlev

if (.not.associated(CVmix_vars%Mdiff_iface)) &
call cvmix_put(CVmix_vars, "Mdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Mdiff", cvmix_zero, max_nlev)
if (.not.associated(CVmix_vars%Tdiff_iface)) &
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero, max_nlev)

call cvmix_coeffs_conv(new_Mdiff, new_Tdiff, &
CVmix_vars%SqrBuoyancyFreq_iface, &
CVmix_vars%WaterDensity_cntr, &
CVmix_vars%AdiabWaterDensity_cntr, &
CVmix_conv_params_user)
call cvmix_update_wrap(CVmix_conv_params_in%handle_old_vals, &
CVmix_vars%nlev, &
nlev, max_nlev, CVmix_conv_params_user)
call cvmix_update_wrap(CVmix_conv_params_in%handle_old_vals, max_nlev, &
Mdiff_out = CVmix_vars%Mdiff_iface, &
new_Mdiff = new_Mdiff, &
Tdiff_out = CVmix_vars%Tdiff_iface, &
Expand All @@ -215,13 +219,14 @@ subroutine cvmix_coeffs_conv_wrap(CVmix_vars, CVmix_conv_params_user)
!EOC

end subroutine cvmix_coeffs_conv_wrap

!BOP

! !IROUTINE: cvmix_coeffs_conv_low
! !INTERFACE:

subroutine cvmix_coeffs_conv_low(Mdiff_out, Tdiff_out, Nsqr, dens, &
dens_lwr, CVmix_conv_params_user)
subroutine cvmix_coeffs_conv_low(Mdiff_out, Tdiff_out, Nsqr, dens, dens_lwr,&
nlev, max_nlev, CVmix_conv_params_user)

! !DESCRIPTION:
! Computes vertical diffusion coefficients for convective mixing.
Expand All @@ -233,16 +238,18 @@ subroutine cvmix_coeffs_conv_low(Mdiff_out, Tdiff_out, Nsqr, dens, &

! !INPUT PARAMETERS:

! nlev+1
real(cvmix_r8), dimension(:), intent(in) :: Nsqr
! nlev
real(cvmix_r8), dimension(:), intent(in) :: dens, dens_lwr
integer, intent(in) :: nlev, max_nlev
! max_nlev+1
real(cvmix_r8), dimension(max_nlev+1), intent(in) :: Nsqr
! max_nlev
real(cvmix_r8), dimension(max_nlev), intent(in) :: dens, dens_lwr
type (cvmix_conv_params_type), optional, target, intent(in) :: &
CVmix_conv_params_user

! !INPUT/OUTPUT PARAMETERS:
! nlev+1
real(cvmix_r8), dimension(:), intent(inout) :: Mdiff_out, Tdiff_out
real(cvmix_r8), dimension(max_nlev+1), intent(inout) :: Mdiff_out, &
Tdiff_out

!EOP
!BOC
Expand All @@ -254,15 +261,14 @@ subroutine cvmix_coeffs_conv_low(Mdiff_out, Tdiff_out, Nsqr, dens, &
!-----------------------------------------------------------------------

real(cvmix_r8) :: vvconv, wgt
integer :: nlev, kw
integer :: kw
type (cvmix_conv_params_type), pointer :: CVmix_conv_params_in

if (present(CVmix_conv_params_user)) then
CVmix_conv_params_in => CVmix_conv_params_user
else
CVmix_conv_params_in => CVmix_conv_params_saved
end if
nlev = size(dens)

!-----------------------------------------------------------------------
!
Expand Down
28 changes: 16 additions & 12 deletions src/shared/cvmix_ddiff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -303,25 +303,27 @@ subroutine cvmix_coeffs_ddiff_wrap(CVmix_vars, CVmix_ddiff_params_user)
!EOP
!BOC

real(cvmix_r8), dimension(CVmix_vars%nlev+1) :: new_Tdiff, new_Sdiff
real(cvmix_r8), dimension(CVmix_vars%max_nlev+1) :: new_Tdiff, new_Sdiff
integer :: nlev, max_nlev
type(cvmix_ddiff_params_type), pointer :: CVmix_ddiff_params_in

if (present(CVmix_ddiff_params_user)) then
CVmix_ddiff_params_in => CVmix_ddiff_params_user
else
CVmix_ddiff_params_in => CVmix_ddiff_params_saved
end if
nlev = CVmix_vars%nlev
max_nlev = CVmix_vars%max_nlev

if (.not.associated(CVmix_vars%Tdiff_iface)) &
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Tdiff", cvmix_zero, max_nlev)
if (.not.associated(CVmix_vars%Sdiff_iface)) &
call cvmix_put(CVmix_vars, "Sdiff", cvmix_zero)
call cvmix_put(CVmix_vars, "Sdiff", cvmix_zero, max_nlev)

call cvmix_coeffs_ddiff(new_Tdiff, new_Sdiff, CVmix_vars%strat_param_num, &
CVmix_vars%strat_param_denom, &
CVmix_vars%strat_param_denom, nlev, max_nlev, &
CVmix_ddiff_params_user)
call cvmix_update_wrap(CVmix_ddiff_params_in%handle_old_vals, &
CVmix_vars%nlev, &
call cvmix_update_wrap(CVmix_ddiff_params_in%handle_old_vals, max_nlev, &
Tdiff_out = CVmix_vars%Tdiff_iface, &
new_Tdiff = new_Tdiff, &
Sdiff_out = CVmix_vars%Sdiff_iface, &
Expand All @@ -337,7 +339,8 @@ end subroutine cvmix_coeffs_ddiff_wrap
! !INTERFACE:

subroutine cvmix_coeffs_ddiff_low(Tdiff_out, Sdiff_out, strat_param_num, &
strat_param_denom, CVmix_ddiff_params_user)
strat_param_denom, nlev, max_nlev, &
CVmix_ddiff_params_user)

! !DESCRIPTION:
! Computes vertical diffusion coefficients for the double diffusion mixing
Expand All @@ -351,14 +354,16 @@ subroutine cvmix_coeffs_ddiff_low(Tdiff_out, Sdiff_out, strat_param_num, &
! !INPUT PARAMETERS:
type(cvmix_ddiff_params_type), optional, target, intent(in) :: &
CVmix_ddiff_params_user
real(cvmix_r8), dimension(:), intent(in) :: strat_param_num, &
strat_param_denom
integer, intent(in) :: nlev, max_nlev
real(cvmix_r8), dimension(max_nlev), intent(in) :: strat_param_num, &
strat_param_denom

! !INPUT/OUTPUT PARAMETERS:
real(cvmix_r8), dimension(:), intent(inout) :: Tdiff_out, Sdiff_out
real(cvmix_r8), dimension(max_nlev+1), intent(inout) :: Tdiff_out, &
Sdiff_out

! !LOCAL VARIABLES:
integer :: k, nlev
integer :: k
real(cvmix_r8) :: ddiff, Rrho

!EOP
Expand All @@ -371,7 +376,6 @@ subroutine cvmix_coeffs_ddiff_low(Tdiff_out, Sdiff_out, strat_param_num, &
else
CVmix_ddiff_params_in => CVmix_ddiff_params_saved
end if
nlev = size(strat_param_num)

! Determine coefficients
Tdiff_out=cvmix_zero
Expand Down
5 changes: 3 additions & 2 deletions src/shared/cvmix_kinds_and_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ module cvmix_kinds_and_types
! cvmix_global_params_type and *-mixing specific parameters should be
! stored in cvmix_*_params_type (found in the cvmix_* module).
type, public :: cvmix_data_type
integer :: nlev = -1 ! Number of levels in column
! Setting default to -1 might be F95...
integer :: nlev = -1 ! Number of active levels in column
integer :: max_nlev = -1 ! Number of levels in column
! Setting defaults to -1 might be F95...

! Scalar quantities
! -----------------
Expand Down
Loading

0 comments on commit 004a6c5

Please sign in to comment.