zoo.F90 4.39 KB
Newer Older
1
#include "fabm_driver.h"
Jorn Bruggeman's avatar
Jorn Bruggeman committed
2 3 4

! Fennel & Neumann 1996 NPZD model - zooplankton component

Jorn Bruggeman's avatar
Jorn Bruggeman committed
5
module examples_npzd_zoo
6
   use fabm_types
7

8
   implicit none
9 10

   private
11

Jorn Bruggeman's avatar
Jorn Bruggeman committed
12 13 14 15
   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
16

Jorn Bruggeman's avatar
Jorn Bruggeman committed
17 18 19
      ! Model parameters
      real(rk) :: z0, gmax, iv, rzn, rzd
   contains
20 21 22
      procedure :: initialize
      procedure :: do
      procedure :: do_ppdd
23 24
   end type

Jorn Bruggeman's avatar
Jorn Bruggeman committed
25
contains
26

Jorn Bruggeman's avatar
Jorn Bruggeman committed
27
   subroutine initialize(self, configunit)
Jorn Bruggeman's avatar
Jorn Bruggeman committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
      class (type_examples_npzd_zoo), intent(inout), target :: self
      integer,                        intent(in)            :: configunit

      real(rk), parameter :: d_per_s = 1.0_rk/86400.0_rk

      ! 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)
      call self%get_parameter(self%gmax, 'gmax', 'd-1',       'maximum specific grazing rate', default=0.5_rk,  scale_factor=d_per_s)
      call self%get_parameter(self%iv,   'iv',   'm3 mmol-1', 'Ivlev grazing constant',        default=1.1_rk)
      call self%get_parameter(self%rzn,  'rzn',  'd-1',       'excretion rate',                default=0.01_rk, scale_factor=d_per_s)
      call self%get_parameter(self%rzd,  'rzd',  'd-1',       'mortality',                     default=0.02_rk, scale_factor=d_per_s)

      ! Register state variables
      call self%register_state_variable(self%id_z, 'c', 'mmol m-3', 'concentration', 0.0_rk, minimum=0.0_rk)
43

Jorn Bruggeman's avatar
Jorn Bruggeman committed
44 45 46 47 48 49 50
      ! Register contribution of state to global aggregate variables.
      call self%add_to_aggregate_variable(standard_variables%total_nitrogen, self%id_z)

      ! Register dependencies on external state variables.
      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')
51
   end subroutine initialize
52

Jorn Bruggeman's avatar
Jorn Bruggeman committed
53
   subroutine do(self, _ARGUMENTS_DO_)
Jorn Bruggeman's avatar
Jorn Bruggeman committed
54 55
      class (type_examples_npzd_zoo), intent(in) :: self
      _DECLARE_ARGUMENTS_DO_
56

Jorn Bruggeman's avatar
Jorn Bruggeman committed
57
      real(rk) :: p, z, g
58

Jorn Bruggeman's avatar
Jorn Bruggeman committed
59 60
      ! Enter spatial loops (if any)
      _LOOP_BEGIN_
61

Jorn Bruggeman's avatar
Jorn Bruggeman committed
62 63 64
         ! Retrieve current (local) state variable values.
         _GET_(self%id_z, z)         ! zooplankton
         _GET_(self%id_grztarget, p) ! prey
65

Jorn Bruggeman's avatar
Jorn Bruggeman committed
66 67
         ! Grazing rate
         g = fpz(self%gmax, self%iv, p, z + self%z0)
68

Jorn Bruggeman's avatar
Jorn Bruggeman committed
69
         ! Set temporal derivatives
70 71 72 73
         _ADD_SOURCE_(self%id_z, g - self%rzn*z - self%rzd*z)
         _ADD_SOURCE_(self%id_grztarget, -g)
         _ADD_SOURCE_(self%id_morttarget, self%rzd*z)
         _ADD_SOURCE_(self%id_exctarget, self%rzn*z)
Jorn Bruggeman's avatar
Jorn Bruggeman committed
74 75 76

      ! Leave spatial loops (if any)
      _LOOP_END_
77
   end subroutine do
78

Jorn Bruggeman's avatar
Jorn Bruggeman committed
79
   subroutine do_ppdd(self, _ARGUMENTS_DO_PPDD_)
Jorn Bruggeman's avatar
Jorn Bruggeman committed
80 81 82 83
      class (type_examples_npzd_zoo), intent(in) :: self
      _DECLARE_ARGUMENTS_DO_PPDD_

      real(rk) :: p, z
84

Jorn Bruggeman's avatar
Jorn Bruggeman committed
85 86
      ! Enter spatial loops (if any)
      _LOOP_BEGIN_
87

Jorn Bruggeman's avatar
Jorn Bruggeman committed
88 89 90
         ! Retrieve current (local) state variable values.
         _GET_(self%id_z,z)         ! zooplankton
         _GET_(self%id_grztarget,p) ! prey
91

Jorn Bruggeman's avatar
Jorn Bruggeman committed
92 93 94 95 96 97
         ! 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)
         ! are automatically assigned to pp(j,i) as well.
          _SET_DD_SYM_(self%id_grztarget,self%id_z,fpz(self%gmax,self%iv,p,z+self%z0))
          _SET_DD_SYM_(self%id_z,self%id_exctarget,self%rzn*z)
          _SET_DD_SYM_(self%id_z,self%id_morttarget,self%rzd*z)
98

Jorn Bruggeman's avatar
Jorn Bruggeman committed
99 100
      ! Leave spatial loops (if any)
      _LOOP_END_
101
   end subroutine do_ppdd
102

Jorn Bruggeman's avatar
Jorn Bruggeman committed
103 104 105
   ! Ivlev formulation for zooplankton grazing on phytoplankton
   elemental real(rk) function fpz(gmax, iv, p, z)
      real(rk), intent(in) :: gmax, iv, p, z
106

Jorn Bruggeman's avatar
Jorn Bruggeman committed
107
      fpz = gmax * (1.0_rk - exp(-iv * iv * p * p)) * z
108 109
   end function fpz

Jorn Bruggeman's avatar
Jorn Bruggeman committed
110
end module examples_npzd_zoo
111 112

!-----------------------------------------------------------------------
113
! Copyright Bolding & Bruggeman ApS - GNU Public License - www.gnu.org
114
!-----------------------------------------------------------------------