Commit 7cd90438 authored by Jorn Bruggeman's avatar Jorn Bruggeman
Browse files

test case clean-up

parent f9b2abdf
#include "fabm_driver.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: examples_npzd_det - Fennel & Neumann 1996 NPZD model - detritus component
!
! !INTERFACE:
module examples_npzd_det
!
! !DESCRIPTION:
! Fennel & Neumann 1996 NPZD model - detritus component
! This model features a single detritus variable, characterized by a rate of decay (rdn)
! and a sinking rate. Mineralized detritus feeds into a dissolved mineral pool that must
! be provided by an external model (e.g., examples_npzd_nut).
!
! !USES:
module examples_npzd_det
use fabm_types
implicit none
private
!
! !PUBLIC DERIVED TYPES:
type,extends(type_base_model),public :: type_examples_npzd_det
! Variable identifiers
type, extends(type_base_model),public :: type_examples_npzd_det
! Variable identifiers
type (type_state_variable_id) :: id_d
type (type_state_variable_id) :: id_mintarget
! Model parameters
! Model parameters
real(rk) :: rdn
contains
procedure :: initialize
procedure :: do
procedure :: do_ppdd
end type
!EOP
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the Detritus model
!
! !INTERFACE:
subroutine initialize(self,configunit)
!
! !DESCRIPTION:
! Here, parameter values are read and variables exported
! by the model are registered with FABM.
!
! !INPUT PARAMETERS:
subroutine initialize(self, configunit)
class (type_examples_npzd_det), intent(inout), target :: self
integer, intent(in) :: configunit
!
! !LOCAL VARIABLES:
real(rk), parameter :: d_per_s = 1.0_rk/86400.0_rk
real(rk) :: w_d, kc
!EOP
!-----------------------------------------------------------------------
!BOC
! Store parameter values in our own derived type
! NB: all rates must be provided in values per day and are converted here to values per second.
call self%get_parameter(w_d, 'w_d', 'm d-1', 'vertical velocity (<0 for sinking)', default=-5.0_rk, scale_factor=d_per_s)
......@@ -76,25 +51,13 @@ contains
call self%register_state_dependency(self%id_mintarget, 'mineralisation_target', 'mmol m-3', 'sink for remineralized matter')
end subroutine initialize
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of Detritus model
!
! !INTERFACE:
subroutine do(self, _ARGUMENTS_DO_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_det), intent(in) :: self
_DECLARE_ARGUMENTS_DO_
!
! !LOCAL VARIABLES:
real(rk) :: d
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
......@@ -109,25 +72,13 @@ contains
_LOOP_END_
end subroutine do
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of Detritus model exporting production/destruction matrices
!
! !INTERFACE:
subroutine do_ppdd(self, _ARGUMENTS_DO_PPDD_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_det), intent(in) :: self
_DECLARE_ARGUMENTS_DO_PPDD_
!
! !LOCAL VARIABLES:
real(rk) :: d
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
......@@ -143,9 +94,6 @@ contains
_LOOP_END_
end subroutine do_ppdd
!EOC
!-----------------------------------------------------------------------
end module examples_npzd_det
......
#include "fabm_driver.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: examples_npzd_nut - Fennel & Neumann 1996 NPZD model - nutrient component
!
! !INTERFACE:
module examples_npzd_nut
!
! !DESCRIPTION:
! Fennel & Neumann 1996 NPZD model - nutrient component
! This is a general nutrient (passive non-sinking, non-floating tracer), characterized by
! an initial concentration only.
!
! !USES:
module examples_npzd_nut
use fabm_types
implicit none
! default: all is private.
private
!
! !PUBLIC DERIVED TYPES:
type,extends(type_base_model),public :: type_examples_npzd_nut
! Variable identifiers
type, extends(type_base_model),public :: type_examples_npzd_nut
! Variable identifiers
type (type_state_variable_id) :: id_n
contains
procedure :: initialize
end type
!EOP
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the nutrient component
!
! !INTERFACE:
subroutine initialize(self, configunit)
!
! !DESCRIPTION:
! Here, parameter values are read and variables exported
! by the model are registered with FABM.
!
! !INPUT PARAMETERS:
class (type_examples_npzd_nut), intent(inout), target :: self
integer, intent(in) :: configunit
!EOP
!-----------------------------------------------------------------------
!BOC
! Register state variables
call self%register_state_variable(self%id_n, 'c', 'mmol m-3', 'concentration', 1.0_rk, minimum=0.0_rk, no_river_dilution=.true.)
! Register contribution of state to global aggregate variables.
call self%add_to_aggregate_variable(standard_variables%total_nitrogen, self%id_n)
end subroutine initialize
!EOC
!-----------------------------------------------------------------------
end module examples_npzd_nut
......
#include "fabm_driver.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: examples_npzd_phy - Fennel & Neumann 1996 NPZD model - phytoplankton component
!
! !INTERFACE:
! Fennel & Neumann 1996 NPZD model - phytoplankton component
module examples_npzd_phy
!
! !DESCRIPTION:
!
! !USES:
use fabm_types
implicit none
! default: all is private.
private
!
! !PUBLIC DERIVED TYPES:
type,extends(type_base_model),public :: type_examples_npzd_phy
! Variable identifiers
type, extends(type_base_model), public :: type_examples_npzd_phy
! Variable identifiers
type (type_state_variable_id) :: id_p
type (type_state_variable_id) :: id_exctarget,id_morttarget,id_upttarget
type (type_dependency_id) :: id_par
type (type_horizontal_dependency_id) :: id_I_0
type (type_surface_dependency_id) :: id_I_0
type (type_diagnostic_variable_id) :: id_GPP,id_NCP,id_PPR,id_NPR,id_dPAR
! Model parameters
! Model parameters
real(rk) :: p0,z0,kc,i_min,rmax,gmax,iv,alpha,rpn,rpdu,rpdl
real(rk) :: dic_per_n
contains
procedure :: initialize
procedure :: do
procedure :: do_ppdd
procedure :: get_light_extinction
end type
!EOP
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the NPZD model
!
! !INTERFACE:
subroutine initialize(self, configunit)
!
! !DESCRIPTION:
! Here, parameter values are read and variables exported
! by the model are registered with FABM.
!
! !INPUT PARAMETERS:
class (type_examples_npzd_phy), intent(inout), target :: self
integer, intent(in) :: configunit
!
! !LOCAL VARIABLES:
real(rk), parameter :: d_per_s = 1.0_rk/86400.0_rk
real(rk) :: w_p
!EOP
!-----------------------------------------------------------------------
!BOC
! Store parameter values in our own derived type
! NB: all rates must be provided in values per day and are converted here to values per second.
call self%get_parameter(self%p0, 'p0', 'mmol m-3', 'background concentration ', default=0.0225_rk)
......@@ -99,28 +69,19 @@ contains
call self%register_dependency(self%id_par, standard_variables%downwelling_photosynthetic_radiative_flux)
call self%register_dependency(self%id_I_0, standard_variables%surface_downwelling_photosynthetic_radiative_flux)
! Contribute to light attentuation
call self%add_to_aggregate_variable(standard_variables%attenuation_coefficient_of_photosynthetic_radiative_flux, self%id_p, scale_factor=self%kc)
call self%add_to_aggregate_variable(standard_variables%attenuation_coefficient_of_photosynthetic_radiative_flux, self%p0 * self%kc)
end subroutine initialize
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of NPZD model
!
! !INTERFACE:
subroutine do(self, _ARGUMENTS_DO_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_phy), intent(in) :: self
_DECLARE_ARGUMENTS_DO_
!
! !LOCAL VARIABLES:
real(rk) :: n, p, par, I_0
real(rk) :: iopt, rpd, primprod
real(rk), parameter :: secs_pr_day = 86400.0_rk
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
......@@ -130,7 +91,7 @@ contains
! Retrieve current environmental conditions.
_GET_(self%id_par,par) ! local photosynthetically active radiation
_GET_HORIZONTAL_(self%id_I_0,I_0) ! surface short wave radiation
_GET_SURFACE_(self%id_I_0,I_0) ! surface photosynthetically active radiation
! Light acclimation formulation based on surface light intensity.
iopt = max(0.25*I_0,self%I_min)
......@@ -143,7 +104,7 @@ contains
end if
! Define some intermediate quantities that will be reused multiple times.
primprod = fnp(self,n,p,par,iopt)
primprod = fnp(self%rmax, self%alpha, n, p + self%p0, par, iopt)
! Set temporal derivatives
_SET_ODE_(self%id_p,primprod - self%rpn*p - rpd*p)
......@@ -162,66 +123,16 @@ contains
! Leave spatial loops (if any)
_LOOP_END_
end subroutine do
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Get the light extinction coefficient due to biogeochemical
! variables
!
! !INTERFACE:
subroutine get_light_extinction(self, _ARGUMENTS_GET_EXTINCTION_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_phy), intent(in) :: self
_DECLARE_ARGUMENTS_GET_EXTINCTION_
!
! !LOCAL VARIABLES:
real(rk) :: p
!
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
! Retrieve current (local) state variable values.
_GET_(self%id_p,p) ! phytoplankton
! Self-shading with explicit contribution from background phytoplankton concentration.
_SET_EXTINCTION_(self%kc*(self%p0+p))
! Leave spatial loops (if any)
_LOOP_END_
end subroutine get_light_extinction
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of NPZD model exporting production/destruction matrices
!
! !INTERFACE:
subroutine do_ppdd(self, _ARGUMENTS_DO_PPDD_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_phy), intent(in) :: self
_DECLARE_ARGUMENTS_DO_PPDD_
!
! !REVISION HISTORY:
! Original author(s): Hans Burchard, Karsten Bolding
!
! !LOCAL VARIABLES:
real(rk) :: n, p, par, I_0
real(rk) :: iopt, rpd, primprod
real(rk), parameter :: secs_pr_day = 86400.
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
......@@ -231,7 +142,7 @@ contains
! Retrieve current environmental conditions.
_GET_(self%id_par,par) ! local photosynthetically active radiation
_GET_HORIZONTAL_(self%id_I_0,I_0) ! surface short wave radiation
_GET_SURFACE_(self%id_I_0,I_0) ! surface photosynthetically active radiation
! Light acclimation formulation based on surface light intensity.
iopt = max(0.25*I_0,self%I_min)
......@@ -244,7 +155,7 @@ contains
end if
! Rate of primary production will be reused multiple times - calculate it once.
primprod = fnp(self,n,p,par,iopt)
primprod = fnp(self%rmax, self%alpha, n, p + self%p0, par, iopt)
! Assign destruction rates to different elements of the destruction matrix.
! By assigning with _SET_DD_SYM_ [as opposed to _SET_DD_], assignments to dd(i,j)
......@@ -262,40 +173,16 @@ contains
! Leave spatial loops (if any)
_LOOP_END_
end subroutine do_ppdd
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Michaelis-Menten formulation for nutrient uptake
!
! !INTERFACE:
pure real(rk) function fnp(self,n,p,par,iopt)
!
! !DESCRIPTION:
! Here, the classical Michaelis-Menten formulation for nutrient uptake
! is formulated.
!
! !INPUT PARAMETERS:
class (type_examples_npzd_phy), intent(in) :: self
real(rk), intent(in) :: n,p,par,iopt
!
! !REVISION HISTORY:
! Original author(s): Hans Burchard, Karsten Bolding
!
!EOP
!-----------------------------------------------------------------------
!BOC
fnp = self%rmax*par/iopt*exp(1.0_rk-par/iopt)*n/(self%alpha+n)*(p+self%p0)
! Phytoplankton growth limited by light and nutrient availability
elemental real(rk) function fnp(rmax, alpha, n, p, par, iopt)
real(rk), intent(in) :: rmax, alpha, n, p, par, iopt
fnp = rmax * par / iopt * exp(1.0_rk - par / iopt) * n / (alpha + n) * p
end function fnp
!EOC
!-----------------------------------------------------------------------
end module examples_npzd_phy
end module examples_npzd_phy
!-----------------------------------------------------------------------
! Copyright Bolding & Bruggeman ApS - GNU Public License - www.gnu.org
......
#include "fabm_driver.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: examples_npzd_zoo - Fennel & Neumann 1996 NPZD model - zooplankton component
!
! !INTERFACE:
! Fennel & Neumann 1996 NPZD model - zooplankton component
module examples_npzd_zoo
!
! !DESCRIPTION:
!
! !USES:
use fabm_types
implicit none
private
!
! !PUBLIC DERIVED TYPES:
type,extends(type_base_model),public :: type_examples_npzd_zoo
! Variable identifiers
type (type_state_variable_id) :: id_z
type (type_state_variable_id) :: id_exctarget,id_morttarget,id_grztarget
! Model parameters
real(rk) :: z0,gmax,iv,rzn,rzd
type, extends(type_base_model), public :: type_examples_npzd_zoo
! Variable identifiers
type (type_state_variable_id) :: id_z
type (type_state_variable_id) :: id_exctarget, id_morttarget, id_grztarget
! Model parameters
real(rk) :: z0, gmax, iv, rzn, rzd
contains
procedure :: initialize
procedure :: do
procedure :: do_ppdd
end type
!EOP
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the NPZD model
!
! !INTERFACE:
subroutine initialize(self, configunit)
!
! !DESCRIPTION:
! Here, parameter values are read and variables exported
! by the model are registered with FABM.
!
! !INPUT PARAMETERS:
class (type_examples_npzd_zoo), intent(inout), target :: self
integer, intent(in) :: configunit
!
! !LOCAL VARIABLES:
real(rk), parameter :: d_per_s = 1.0_rk/86400.0_rk
!EOP
!-----------------------------------------------------------------------
!BOC
! Store parameter values in our own derived type
! NB: all rates must be provided in values per day and are converted here to values per second.
call self%get_parameter(self%z0, 'z0', 'mmol m-3', 'background concentration', default=0.0225_rk)
......@@ -76,27 +48,14 @@ contains
call self%register_state_dependency(self%id_grztarget, 'grazing_target', 'mmol m-3', 'prey source')
call self%register_state_dependency(self%id_exctarget, 'excretion_target', 'mmol m-3', 'sink for excreted matter')
call self%register_state_dependency(self%id_morttarget, 'mortality_target', 'mmol m-3', 'sink for dead matter')
end subroutine initialize
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of NPZD model
!
! !INTERFACE:
subroutine do(self, _ARGUMENTS_DO_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_zoo), intent(in) :: self
_DECLARE_ARGUMENTS_DO_
!
! !LOCAL VARIABLES:
real(rk) :: p, z, g
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_
......@@ -105,7 +64,7 @@ contains
_GET_(self%id_grztarget, p) ! prey
! Grazing rate
g = fpz(self, p, z)
g = fpz(self%gmax, self%iv, p, z + self%z0)
! Set temporal derivatives
_SET_ODE_(self%id_z, g - self%rzn*z - self%rzd*z)
......@@ -115,27 +74,14 @@ contains
! Leave spatial loops (if any)
_LOOP_END_
end subroutine do
!EOC
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of NPZD model exporting production/destruction matrices
!
! !INTERFACE:
subroutine do_ppdd(self, _ARGUMENTS_DO_PPDD_)
!
! !INPUT PARAMETERS:
class (type_examples_npzd_zoo), intent(in) :: self
_DECLARE_ARGUMENTS_DO_PPDD_
!
! !LOCAL VARIABLES:
real(rk) :: p, z
!EOP
!-----------------------------------------------------------------------
!BOC
! Enter spatial loops (if any)
_LOOP_BEGIN_