Skip to content

Commit

Permalink
refactored seagrass:
Browse files Browse the repository at this point in the history
default is ON

handled vi gotm.yaml and not namelist

SEAGRASS -> _SEAGRASS_

output is handled by register_all_variables()

split init_seagrass() in init_seagrass() and post_init_seagrass()
  • Loading branch information
bolding committed Jun 27, 2024
1 parent b8df7cf commit 3e888d4
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 70 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ else(MSVC)
option(GOTM_EMBED_VERSION "Embed GOTM version information" ON)
endif(MSVC)

option(GOTM_USE_SEAGRASS "Enable seagrass module" OFF)
option(GOTM_USE_SEAGRASS "Enable seagrass module" ON)

option(GOTM_EXTRA_OUTPUT "Include additional turbulence diagnostics in output" OFF)
mark_as_advanced(GOTM_EXTRA_OUTPUT)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(GOTM_USE_STIM)
add_definitions(-D_ICE_)
endif()
if(GOTM_USE_SEAGRASS)
add_definitions(-DSEAGRASS)
add_definitions(-D_SEAGRASS_)
endif()
if(GOTM_EXTRA_OUTPUT)
add_definitions(-DEXTRA_OUTPUT)
Expand Down
2 changes: 1 addition & 1 deletion src/extras/seagrass/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(seagrass
seagrass.F90
)
target_link_libraries(seagrass PUBLIC field_manager PRIVATE meanflow)
set_property(TARGET seagrass PROPERTY FOLDER gotm)
target_link_libraries(seagrass PUBLIC field_manager PRIVATE meanflow gotm::config)
115 changes: 58 additions & 57 deletions src/extras/seagrass/seagrass.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef SEAGRASS
#ifdef _SEAGRASS_

#include"cppdefs.h"
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -27,24 +27,19 @@ module seagrass
private
!
! !PUBLIC MEMBER FUNCTIONS:
public init_seagrass, do_seagrass, end_seagrass
logical, public :: seagrass_calc
public init_seagrass, post_init_seagrass, do_seagrass, end_seagrass
logical, public :: seagrass_calc = .false.
REALTYPE, public, dimension(:), allocatable :: xx,yy
!
! !REVISION HISTORY:!
! Original author(s): Hans Burchard & Karsten Bolding
!
REALTYPE, dimension(:), allocatable :: xx,yy
REALTYPE, dimension(:), allocatable :: exc,vfric,grassz,xxP
logical :: init_output
! from a namelist
character(len=PATH_MAX) :: grassfile='seagrass.dat'
REALTYPE :: XP_rat
REALTYPE :: alpha
integer :: grassind
integer :: grassn
integer :: out_unit
integer :: maxn

REALTYPE, parameter :: miss_val = -999.0
!EOP
!-----------------------------------------------------------------------

Expand All @@ -56,54 +51,75 @@ module seagrass
! !IROUTINE: Initialise the sea grass module
!
! !INTERFACE:
subroutine init_seagrass(namlst,fname,unit,nlev,h,fm)
subroutine init_seagrass()
!
! !DESCRIPTION:
! Here, the seagrass namelist {\tt seagrass.nml} is read
! and memory is allocated
! for some relevant vectors. Afterwards, excursion limits and friction
! coefficients are read from a file. The uppermost grid related index
! for the seagrass canopy is then calculated.
! Reading seagrass configuration from YAML-file
!
! !USES:
use field_manager
use settings
IMPLICIT NONE
!
! !INPUT PARAMETERS:
integer, intent(in) :: namlst
character(len=*), intent(in) :: fname
integer, intent(in) :: unit
integer, intent(in) :: nlev
REALTYPE, intent(in) :: h(0:nlev)
type (type_field_manager), intent(inout) :: fm
!
! !REVISION HISTORY:
! Original author(s): Karsten Bolding & Hans Burchard
!
! !LOCAL VARIABLES:
integer :: i,rc
REALTYPE :: z
namelist /canopy/ seagrass_calc,grassfile,XP_rat
class (type_gotm_settings), pointer :: branch
!! GOTM settings variable
integer :: i
!EOP
!-----------------------------------------------------------------------
!BOC
LEVEL1 'init_seagrass'

init_output = .true.
seagrass_calc = .false.

maxn=nlev
branch => settings_store%get_typed_child('seagrass','calculate seagrass effect on turbulence')
call branch%get(i, 'method', '', options=(/option(0, 'off'), option(1, 'from file')/), default=0)
call branch%get(grassfile, 'file', 'path to file with grass specifications', default='seagrass.dat')
call branch%get(alpha, 'alpha', 'efficiency of leafes turbulence production', '',default=0._rk)

! Open and read the namelist
open(namlst,file=fname,action='read',status='old',err=98)
read(namlst,nml=canopy,err=99)
close(namlst)
if (i .ne. 0) seagrass_calc = .true.

if (seagrass_calc) then
out_unit=unit
if (seagrass_calc) LEVEL2 'seagrass initialise ...'
end subroutine init_seagrass
!EOC

open(unit,status='unknown',file=grassfile)
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the sea grass module
!
! !INTERFACE:
subroutine post_init_seagrass(nlev)
!
! !DESCRIPTION:
! Seagrass memory is allocated and initialized from file
!
! !USES:
use meanflow, only: h
IMPLICIT NONE
!
! !INPUT PARAMETERS:
integer, intent(in) :: nlev
!
! !REVISION HISTORY:
! Original author(s): Karsten Bolding & Hans Burchard
!
! !LOCAL VARIABLES:
integer :: i,rc
integer :: iu
REALTYPE :: z
REALTYPE, parameter :: miss_val = -999.0
!EOP
!-----------------------------------------------------------------------
!BOC

read(unit,*) grassn
if (seagrass_calc) then
LEVEL2 'post seagrass initialise ...'
open(newunit=iu,status='unknown',file=grassfile)

read(iu,*) grassn

allocate(xx(0:nlev),stat=rc)
if (rc /= 0) STOP 'init_seagrass: Error allocating (xx)'
Expand All @@ -130,7 +146,7 @@ subroutine init_seagrass(namlst,fname,unit,nlev,h,fm)
grassz = _ZERO_

do i=1,grassn
read(unit,*) grassz(i),exc(i),vfric(i)
read(iu,*) grassz(i),exc(i),vfric(i)
end do

z=0.5*h(1)
Expand All @@ -139,28 +155,13 @@ subroutine init_seagrass(namlst,fname,unit,nlev,h,fm)
if (grassz(grassn).gt.z) grassind=i
end do

close(unit)
close(iu)

xx(grassind+1:nlev) = miss_val
yy(grassind+1:nlev) = miss_val

call fm%register('x_excur', 'm', 'seagrass excursion(x)', dimensions=(/id_dim_z/), data1d=xx(1:nlev), fill_value=miss_val, category='seagrass')
call fm%register('y_excur', 'm', 'seagrass excursion(y)', dimensions=(/id_dim_z/), data1d=yy(1:nlev), fill_value=miss_val, category='seagrass')

LEVEL2 'seagrass initialised ...'

end if
return

98 LEVEL2 'I could not open seagrass.nml'
LEVEL2 'Ill continue but set seagrass_calc to false.'
LEVEL2 'If thats not what you want you have to supply seagrass.nml'
LEVEL2 'See the Seagrass example on www.gotm.net for a working seagrass.nml'
seagrass_calc = .false.
return
99 FATAL 'I could not read seagrass.nml'
stop 'init_seagrass'
end subroutine init_seagrass
end subroutine post_init_seagrass
!EOC

!-----------------------------------------------------------------------
Expand Down Expand Up @@ -265,7 +266,7 @@ subroutine do_seagrass(nlev,dt)
drag(i)=drag(i)+grassfric(i)

! Extra turbulence production by seagrass friction
xxP(i)=xP_rat*grassfric(i)*(sqrt(u(i)**2+v(i)**2))**3
xxP(i)=alpha*grassfric(i)*(sqrt(u(i)**2+v(i)**2))**3
else
xxP(i)=_ZERO_
end if
Expand Down
21 changes: 13 additions & 8 deletions src/gotm/gotm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module gotm
use gotm_cvmix, only: zsbl, sbl_langmuir_method
#endif

#ifdef SEAGRASS
#ifdef _SEAGRASS_
use seagrass
#endif
#ifdef SPM
Expand All @@ -93,7 +93,7 @@ module gotm
!
! !DEFINED PARAMETERS:
integer, parameter :: namlst=10
#ifdef SEAGRASS
#ifdef _SEAGRASS_
integer, parameter :: unit_seagrass=62
#endif
#ifdef SPM
Expand Down Expand Up @@ -391,6 +391,10 @@ subroutine initialize_gotm()
call configure_gotm_fabm_input()
#endif

#ifdef _SEAGRASS_
call init_seagrass()
#endif

! Initialize field manager
! This is needed for the output manager to be able to read its configuration [output_manager_init]
call fm%register_dimension('lon',1,id=id_dim_lon)
Expand Down Expand Up @@ -489,9 +493,6 @@ subroutine initialize_gotm()
call init_tridiagonal(nlev)
call updategrid(nlev,dt,zeta)

#ifdef SEAGRASS
call init_seagrass(namlst,'seagrass.nml',unit_seagrass,nlev,h,fm)
#endif
#ifdef SPM
call init_spm(namlst,'spm.nml',unit_spm,nlev)
#endif
Expand Down Expand Up @@ -578,6 +579,10 @@ subroutine initialize_gotm()
#endif
call init_diagnostics(nlev)

#ifdef _SEAGRASS_
call post_init_seagrass(nlev)
#endif

call do_register_all_variables(latitude,longitude,nlev)

! initialize FABM module
Expand Down Expand Up @@ -803,7 +808,7 @@ subroutine integrate_gotm()
call internal_pressure(nlev)
call friction(nlev,kappa,avmolu,tx,ty,plume_type)

#ifdef SEAGRASS
#ifdef _SEAGRASS_
if(seagrass_calc) call do_seagrass(nlev,dt)
#endif

Expand Down Expand Up @@ -892,7 +897,7 @@ subroutine integrate_gotm()

case default
! update one-point models
# ifdef SEAGRASS
# ifdef _SEAGRASS_
call do_turbulence(nlev,dt,depth,u_taus,u_taub,z0s,z0b,h, &
NN,SS,xP, SSCSTK=SSCSTK, SSSTK=SSSTK)
# else
Expand Down Expand Up @@ -958,7 +963,7 @@ subroutine finalize_gotm()

call clean_tridiagonal()

#ifdef SEAGRASS
#ifdef _SEAGRASS_
call end_seagrass
#endif

Expand Down
35 changes: 35 additions & 0 deletions src/gotm/register_all_variables.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ subroutine do_register_all_variables(lat,lon,nlev)
call register_coordinate_variables(lat,lon)
call register_density_variables(nlev)
call register_meanflow_variables(nlev)
#ifdef _SEAGRASS_
call register_seagrass_variables(nlev)
#endif
call register_airsea_variables(nlev)
#ifdef _ICE_
call register_stim_variables(nlev)
Expand Down Expand Up @@ -488,6 +491,38 @@ subroutine register_meanflow_variables(nlev)
end subroutine register_meanflow_variables
!EOC

#ifdef _SEAGRASS_
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: seagrass variable registration
!
! !INTERFACE:
subroutine register_seagrass_variables(nlev)
!
! !DESCRIPTION:
!
! !USES:
use seagrass, only: seagrass_calc, xx, yy
IMPLICIT NONE
!
! !INPUT PARAMETERS:
integer, intent(in) :: nlev
!
! !LOCAL VARIABLES:
REALTYPE, parameter :: miss_val = -999.0
!EOP
!-----------------------------------------------------------------------
!BOC
if (seagrass_calc) then
LEVEL2 'register_seagrass_variables()'
call fm%register('x_excur', 'm', 'seagrass excursion(x)', dimensions=(/id_dim_z/), data1d=xx(1:nlev), fill_value=miss_val, category='seagrass')
call fm%register('y_excur', 'm', 'seagrass excursion(y)', dimensions=(/id_dim_z/), data1d=yy(1:nlev), fill_value=miss_val, category='seagrass')
end if
end subroutine register_seagrass_variables
!EOC
#endif

!-----------------------------------------------------------------------
!BOP
! !IROUTINE: turbulence variable registration
Expand Down
2 changes: 1 addition & 1 deletion src/meanflow/uequation.F90
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ subroutine uequation(nlev,dt,cnpar,tx,num, nucl, gamu,ext_method)
! add external and internal pressure gradients
Qsour(i) = Qsour(i) - gravity*dzetadx + idpdx(i)

#ifdef SEAGRASS
#ifdef _SEAGRASS_
Lsour(i) = -drag(i)/h(i)*sqrt(u(i)*u(i)+v(i)*v(i))
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/meanflow/vequation.F90
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ subroutine vequation(nlev,dt,cnpar,ty,num, nucl, gamv,ext_method)
! add external and internal pressure gradients
Qsour(i) = Qsour(i) - gravity*dzetady + idpdy(i)

#ifdef SEAGRASS
#ifdef _SEAGRASS_
Lsour(i) = -drag(i)/h(i)*sqrt(u(i)*u(i)+v(i)*v(i))
#endif

Expand Down

0 comments on commit 3e888d4

Please sign in to comment.