5.13.3-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_coupling_type.f90
Go to the documentation of this file.
1!> \dir coupling
2!> \brief \copybrief f_coupling
3!> \details \copydetails f_coupling
4
5!> \defgroup f_coupling coupling - Fortran modules
6!> \brief Core modules to couple mHM.
7!> \details These modules provide the core components to couple mHM.
8
9!> \file mo_coupling_type.f90
10!> \brief \copybrief mo_coupling_type
11!> \details \copydetails mo_coupling_type
12
13!> \brief Types to specify the coupling configuration of mHM.
14!> \version 0.1
15!> \authors Sebastian Mueller
16!> \date Apr 2023
17!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
18!! mHM is released under the LGPLv3+ license \license_note
19!> \ingroup f_coupling
21
22 use mo_kind, only: i4, dp
23
24 implicit none
25
26 private
27
28 !> \class couple_cfg_type
29 !> \brief This is a container to hold all coupling configurations for mHM.
30 type, public :: couple_cfg_type
31 character(256) :: nml_name = 'coupling' !< namelist name in mhm namelist
32 logical :: read_nml = .true. !< whether to read the namelist (or set via routine)
33 integer(i4) :: case !< coupling case (0: no coupling, 1: single domain coupling)
34 integer(i4) :: meteo_timestep !< timestep for meteo-data from coupling
35 logical :: meteo_time_ref_endpoint !< expect meteo has time reference point at end of associated time interval
36 logical :: meteo_expect_pre !< expect meteo from coupling: [mm] Precipitation
37 logical :: meteo_expect_temp !< expect meteo from coupling: [degC] Air temperature
38 logical :: meteo_expect_pet !< expect meteo from coupling: [mm TS-1] Potential evapotranspiration
39 logical :: meteo_expect_tmin !< expect meteo from coupling: [degC] minimum daily air temperature
40 logical :: meteo_expect_tmax !< expect meteo from coupling: [degC] maximum daily air temperature
41 logical :: meteo_expect_netrad !< expect meteo from coupling: [W m2] net radiation
42 logical :: meteo_expect_absvappress !< expect meteo from coupling: [Pa] absolute vapour pressure
43 logical :: meteo_expect_windspeed !< expect meteo from coupling: [m s-1] windspeed
44 ! riv-temp related
45 logical :: meteo_expect_ssrd !< expect meteo from coupling: [W m2] short wave radiation
46 logical :: meteo_expect_strd !< expect meteo from coupling: [W m2] long wave radiation
47 logical :: meteo_expect_tann !< expect meteo from coupling: [degC] annual mean air temperature
48
49 contains
50 !> \copydoc mo_coupling_type::read_config
51 procedure :: read_config !< \see mo_coupling_type::read_config
52 !> \copydoc mo_coupling_type::set_config
53 procedure :: set_config !< \see mo_coupling_type::set_config
54 !> \copydoc mo_coupling_type::any_meteo_expected
55 procedure :: any_meteo_expected !< \see mo_coupling_type::any_meteo_expected
56 !> \copydoc mo_coupling_type::clean_up
57 procedure :: clean_up !< \see mo_coupling_type::clean_up
58 !> \copydoc mo_coupling_type::check
59 procedure :: check !< \see mo_coupling_type::check
60 !> \copydoc mo_coupling_type::active
61 procedure :: active !< \see mo_coupling_type::active
62 end type couple_cfg_type
63
64contains
65
66 !> \brief clean up
67 subroutine clean_up(self)
68 implicit none
69
70 class(couple_cfg_type), intent(inout) :: self
71
72 ! restore defaults
73 call self%set_config(read_nml=.true.)
74
75 end subroutine clean_up
76
77 !> \brief read configuration for the \ref couple_cfg_type class from the mhm namelist
78 subroutine read_config(self, file_namelist)
79 use mo_namelists, only: nml_coupling
80 implicit none
81
82 class(couple_cfg_type), intent(inout) :: self
83 character(*), intent(in) :: file_namelist !< mhm namelist file
84
85 ! set defaults of namelist should be read
86 if (self%read_nml) then
87 call self%set_config(read_nml=.true.)
88 else
89 return ! config already set via set_config
90 end if
91
92 call nml_coupling%read(file_namelist)
93
94 self%case = nml_coupling%case
95 self%meteo_timestep = nml_coupling%meteo_timestep
96 self%meteo_time_ref_endpoint = nml_coupling%meteo_time_ref_endpoint
97 self%meteo_expect_pre = nml_coupling%meteo_expect_pre
98 self%meteo_expect_temp = nml_coupling%meteo_expect_temp
99 self%meteo_expect_pet = nml_coupling%meteo_expect_pet
100 self%meteo_expect_tmin = nml_coupling%meteo_expect_tmin
101 self%meteo_expect_tmax = nml_coupling%meteo_expect_tmax
102 self%meteo_expect_netrad = nml_coupling%meteo_expect_netrad
103 self%meteo_expect_absvappress = nml_coupling%meteo_expect_absvappress
104 self%meteo_expect_windspeed = nml_coupling%meteo_expect_windspeed
105 self%meteo_expect_ssrd = nml_coupling%meteo_expect_ssrd
106 self%meteo_expect_strd = nml_coupling%meteo_expect_strd
107 self%meteo_expect_tann = nml_coupling%meteo_expect_tann
108
109 end subroutine read_config
110
111 !> \brief set configuration for the \ref couple_cfg_type class
112 subroutine set_config( &
113 self, &
114 case, &
115 meteo_timestep, &
116 meteo_time_ref_endpoint, &
117 meteo_expect_pre, &
118 meteo_expect_temp, &
119 meteo_expect_pet, &
120 meteo_expect_tmin, &
121 meteo_expect_tmax, &
122 meteo_expect_netrad, &
123 meteo_expect_absvappress, &
124 meteo_expect_windspeed, &
125 meteo_expect_ssrd, &
126 meteo_expect_strd, &
127 meteo_expect_tann, &
128 read_nml &
129 )
130 implicit none
131
132 class(couple_cfg_type), intent(inout) :: self
133 integer(i4), intent(in), optional :: case !< coupling case
134 integer(i4), intent(in), optional :: meteo_timestep !< timestep for meteo-data from coupling
135 logical, intent(in), optional :: meteo_time_ref_endpoint !< expect meteo has time reference point at end of time interval
136 logical, intent(in), optional :: meteo_expect_pre !< expect meteo from coupling: [mm] Precipitation
137 logical, intent(in), optional :: meteo_expect_temp !< expect meteo from coupling: [degC] Air temperature
138 logical, intent(in), optional :: meteo_expect_pet !< expect meteo from coupling: [mm TS-1] Potential evapotranspiration
139 logical, intent(in), optional :: meteo_expect_tmin !< expect meteo from coupling: [degC] minimum daily air temperature
140 logical, intent(in), optional :: meteo_expect_tmax !< expect meteo from coupling: [degC] maximum daily air temperature
141 logical, intent(in), optional :: meteo_expect_netrad !< expect meteo from coupling: [W m2] net radiation
142 logical, intent(in), optional :: meteo_expect_absvappress !< expect meteo from coupling: [Pa] absolute vapour pressure
143 logical, intent(in), optional :: meteo_expect_windspeed !< expect meteo from coupling: [m s-1] windspeed
144 logical, intent(in), optional :: meteo_expect_ssrd !< expect meteo from coupling: [W m2] short wave radiation
145 logical, intent(in), optional :: meteo_expect_strd !< expect meteo from coupling: [W m2] long wave radiation
146 logical, intent(in), optional :: meteo_expect_tann !< expect meteo from coupling: [degC] annual mean air temperature
147 logical, intent(in), optional :: read_nml !< whether to read the namelist (or set via routine)
148
149 ! defaults
150 self%case = 0_i4 ! no coupling by default
151 self%meteo_timestep = 0_i4 ! only valid if no meteo expected
152 self%meteo_time_ref_endpoint = .false. ! meteo data usually given at begin of time interval (i.e. 00:00 for current day)
153 self%meteo_expect_pre = .false.
154 self%meteo_expect_temp = .false.
155 self%meteo_expect_pet = .false.
156 self%meteo_expect_tmin = .false.
157 self%meteo_expect_tmax = .false.
158 self%meteo_expect_netrad = .false.
159 self%meteo_expect_absvappress = .false.
160 self%meteo_expect_windspeed = .false.
161 self%meteo_expect_ssrd = .false.
162 self%meteo_expect_strd = .false.
163 self%meteo_expect_tann = .false.
164 ! don't read namelist if configured via this routine (by default)
165 ! if set_config is only used to set defaults, set this to true
166 self%read_nml = .false.
167
168 if (present(case)) self%case = case
169 if (present(meteo_timestep)) self%meteo_timestep = meteo_timestep
170 if (present(meteo_time_ref_endpoint)) self%meteo_time_ref_endpoint = meteo_time_ref_endpoint
171 if (present(meteo_expect_pre)) self%meteo_expect_pre = meteo_expect_pre
172 if (present(meteo_expect_temp)) self%meteo_expect_temp = meteo_expect_temp
173 if (present(meteo_expect_pet)) self%meteo_expect_pet = meteo_expect_pet
174 if (present(meteo_expect_tmin)) self%meteo_expect_tmin = meteo_expect_tmin
175 if (present(meteo_expect_tmax)) self%meteo_expect_tmax = meteo_expect_tmax
176 if (present(meteo_expect_netrad)) self%meteo_expect_netrad = meteo_expect_netrad
177 if (present(meteo_expect_absvappress)) self%meteo_expect_absvappress = meteo_expect_absvappress
178 if (present(meteo_expect_windspeed)) self%meteo_expect_windspeed = meteo_expect_windspeed
179 if (present(meteo_expect_ssrd)) self%meteo_expect_ssrd = meteo_expect_ssrd
180 if (present(meteo_expect_strd)) self%meteo_expect_strd = meteo_expect_strd
181 if (present(meteo_expect_tann)) self%meteo_expect_tann = meteo_expect_tann
182 if (present(read_nml)) self%read_nml = read_nml
183
184 end subroutine set_config
185
186 !> \brief whether any meteo data is expected
187 !> \return True if any meteo data expected, else False
188 logical function any_meteo_expected(self)
189 implicit none
190
191 class(couple_cfg_type), intent(in) :: self
192
194 self%meteo_expect_pre .or. &
195 self%meteo_expect_temp .or. &
196 self%meteo_expect_pet .or. &
197 self%meteo_expect_tmin .or. &
198 self%meteo_expect_tmax .or. &
199 self%meteo_expect_netrad .or. &
200 self%meteo_expect_absvappress .or. &
201 self%meteo_expect_windspeed .or. &
202 self%meteo_expect_ssrd .or. &
203 self%meteo_expect_strd .or. &
204 self%meteo_expect_tann
205
206 end function any_meteo_expected
207
208 !> \brief check configuration
209 subroutine check(self, domainMeta, optimize)
210 use mo_message, only : error_message
211 use mo_string_utils, only : num2str
212 use mo_common_types, only : domain_meta
213 implicit none
214
215 class(couple_cfg_type), intent(inout) :: self
216 type(domain_meta), intent(in) :: domainMeta !< domain general description
217 logical, intent(in) :: optimize !< Optimization (.true. ) or Evaluation run (.false.)
218
219 if (.not. any(self%case == [0, 1])) &
220 call error_message("Coupling: case needs to be 0 or 1. Got: ", num2str(self%case))
221
222 ! coupling case 1 for single domain coupling
223 if (self%case == 1 .and. domainmeta%nDomains > 1) &
224 call error_message("Coupling: Only one domain allowed when coupling.")
225
226 ! coupling only without internal optimization
227 if (self%case /= 0 .and. optimize) &
228 call error_message("Coupling: no internal optimization allowed when coupling.")
229
230 ! if meteo data is expected, an associated time-step (1 or 24) needs to be given
231 if (self%case /= 0 .and. self%any_meteo_expected() .and. .not. any(self%meteo_timestep == [1, 24])) &
232 call error_message("Coupling: meteo data expected but no valid time-step (1 or 24) given for it.")
233
234 end subroutine check
235
236 !> \brief whether coupling is actived
237 !> \return True if any case > 0, else False
238 logical function active(self)
239 implicit none
240 class(couple_cfg_type), intent(in) :: self
241 active = self%case > 0_i4
242 end function active
243
244end module mo_coupling_type
Provides common types needed by mHM, mRM and/or mpr.
Types to specify the coupling configuration of mHM.
subroutine set_config(self, case, meteo_timestep, meteo_time_ref_endpoint, meteo_expect_pre, meteo_expect_temp, meteo_expect_pet, meteo_expect_tmin, meteo_expect_tmax, meteo_expect_netrad, meteo_expect_absvappress, meteo_expect_windspeed, meteo_expect_ssrd, meteo_expect_strd, meteo_expect_tann, read_nml)
set configuration for the couple_cfg_type class
logical function active(self)
whether coupling is actived
logical function any_meteo_expected(self)
whether any meteo data is expected
subroutine clean_up(self)
clean up
subroutine check(self, domainmeta, optimize)
check configuration
subroutine read_config(self, file_namelist)
read configuration for the couple_cfg_type class from the mhm namelist
Module containing all namelists representations.
type(nml_coupling_t), public nml_coupling
'coupling' namelist content
DOMAIN general description.
This is a container to hold all coupling configurations for mHM.