source: palm/trunk/SOURCE/indoor_model_mod.f90 @ 4725

Last change on this file since 4725 was 4709, checked in by maronga, 4 years ago

reactivated release of waste heat and additional fix in indoor model

  • Property svn:keywords set to Id
File size: 106.6 KB
Line 
1!> @file indoor_model_mod.f90
2!--------------------------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
6! Public License as published by the Free Software Foundation, either version 3 of the License, or
7! (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11! Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with PALM. If not, see
14! <http://www.gnu.org/licenses/>.
15!
16! Copyright 2018-2020 Leibniz Universitaet Hannover
17! Copyright 2018-2020 Hochschule Offenburg
18!--------------------------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: indoor_model_mod.f90 4709 2020-09-28 19:20:00Z suehring $
27! Bugfix: avoid division by zero in case of zero window fraction (now also for vertical walls).
28! Reactivated waste heat.
29!
30! 4704 2020-09-28 10:13:03Z maronga
31! Bugfix: avoid division by zero in case of zero window fraction
32!
33! 4702 2020-09-27 18:39:00Z maronga
34! Removed unused variable indoor_wall_window_temperature
35!
36! 4701 2020-09-27 11:02:15Z maronga
37! Heat transfer for wall and windows back to USM separated into q_wall and q_win (instead q_wall_win).
38! Heat flow direction revised (heat flow positive from outside to inside).
39! New variable indoor_wall_temperature (for q_wall).
40! Removed unused quantity q_trans.
41!
42! 4698 2020-09-25 08:37:55Z maronga
43! Fixed faulty characters
44!
45! 4687 2020-09-21 19:40:16Z maronga
46! Bugfix: values of theta_m_t_prev were not stored for individual surfaces and thus re-used by all
47! surfaces and buildings, which led to excessive indoor temperatures
48!
49! 4681 2020-09-16 10:23:06Z pavelkrc
50! Bugfix for implementation of downward surfaces
51!
52! 4671 2020-09-09 20:27:58Z pavelkrc
53! Implementation of downward facing USM and LSM surfaces
54!
55! 4646 2020-08-24 16:02:40Z raasch
56! file re-formatted to follow the PALM coding standard
57!
58! 4481 2020-03-31 18:55:54Z maronga
59! Change order of dimension in surface array %frac to allow for better vectorization.
60!
61! 4441 2020-03-04 19:20:35Z suehring
62! Major bugfix in calculation of energy demand - floor-area-per-facade was wrongly calculated
63! leading to unrealistically high energy demands and thus to unreallistically high waste-heat
64! fluxes.
65!
66! 4346 2019-12-18 11:55:56Z motisi
67! Introduction of wall_flags_total_0, which currently sets bits based on static topography
68! information used in wall_flags_static_0
69!
70! 4329 2019-12-10 15:46:36Z motisi
71! Renamed wall_flags_0 to wall_flags_static_0
72!
73! 4310 2019-11-26 19:01:28Z suehring
74! Remove dt_indoor from namelist input. The indoor model is an hourly-based model, calling it
75! more/less often lead to inaccurate results.
76!
77! 4299 2019-11-22 10:13:38Z suehring
78! Output of indoor temperature revised (to avoid non-defined values within buildings)
79!
80! 4267 2019-10-16 18:58:49Z suehring
81! Bugfix in initialization, some indices to access building_pars where wrong.
82! Introduction of seasonal parameters.
83!
84! 4246 2019-09-30 09:27:52Z pavelkrc
85!
86!
87! 4242 2019-09-27 12:59:10Z suehring
88! Bugfix in array index
89!
90! 4238 2019-09-25 16:06:01Z suehring
91! - Bugfix in determination of minimum facade height and in location message
92! - Bugfix, avoid division by zero
93! - Some optimization
94!
95! 4227 2019-09-10 18:04:34Z gronemeier
96! implement new palm_date_time_mod
97!
98! 4217 2019-09-04 09:47:05Z scharf
99! Corrected "Former revisions" section
100!
101! 4209 2019-09-02 12:00:03Z suehring
102! - Bugfix in initialization of indoor temperature
103! - Prescibe default indoor temperature in case it is not given in the namelist input
104!
105! 4182 2019-08-21 14:37:54Z scharf
106! Corrected "Former revisions" section
107!
108! 4148 2019-08-08 11:26:00Z suehring
109! Bugfix in case of non grid-resolved buildings. Further, vertical grid spacing is now considered at
110! the correct level.
111! - change calculation of a_m and c_m
112! - change calculation of u-values (use h_es in building array)
113! - rename h_tr_... to  h_t_...
114!          h_tr_em  to  h_t_wm
115!          h_tr_op  to  h_t_wall
116!          h_tr_w   to  h_t_es
117! - rename h_ve     to  h_v
118! - rename h_is     to  h_ms
119! - inserted net_floor_area
120! - inserted params_waste_heat_h, params_waste_heat_c from building database
121!   in building array
122! - change calculation of q_waste_heat
123! - bugfix in averaging mean indoor temperature
124!
125! 3759 2019-02-21 15:53:45Z suehring
126! - Calculation of total building volume
127! - Several bugfixes
128! - Calculation of building height revised
129!
130! 3745 2019-02-15 18:57:56Z suehring
131! - remove building_type from module
132! - initialize parameters for each building individually instead of a bulk initializaion with
133!   identical building type for all
134! - output revised
135! - add missing _wp
136! - some restructuring of variables in building data structure
137!
138! 3744 2019-02-15 18:38:58Z suehring
139! Some interface calls moved to module_interface + cleanup
140!
141! 3469 2018-10-30 20:05:07Z kanani
142! Initial revision (tlang, suehring, kanani, srissman)!
143!
144! Authors:
145! --------
146! @author Tobias Lang
147! @author Jens Pfafferott
148! @author Farah Kanani-Suehring
149! @author Matthias Suehring
150! @author Sascha Rissmann
151! @author Bjoern Maronga
152!
153!
154! Description:
155! ------------
156!> Module for Indoor Climate Model (ICM)
157!> The module is based on the DIN EN ISO 13790 with simplified hour-based procedure.
158!> This model is a equivalent circuit diagram of a three-point RC-model (5R1C).
159!> This module differs between indoor-air temperature an average temperature of indoor surfaces which make it prossible to determine
160!> thermal comfort
161!> the heat transfer between indoor and outdoor is simplified
162
163!> @todo Many statement comments that are given as doxygen comments need to be changed to normal comments
164!> @todo Replace window_area_per_facade by %frac(1,m) for window
165!> @todo emissivity change for window blinds if solar_protection_on=1
166
167!> @note Do we allow use of integer flags, or only logical flags? (concerns e.g. cooling_on, heating_on)
168!> @note How to write indoor temperature output to pt array?
169!>
170!> @bug  Calculation of iwghf_eb and iwghf_eb_window is faulty
171!--------------------------------------------------------------------------------------------------!
172 MODULE indoor_model_mod
173
174    USE arrays_3d,                                                                                 &
175        ONLY:  ddzw,                                                                               &
176               dzw,                                                                                &
177               pt
178
179    USE control_parameters,                                                                        &
180        ONLY:  initializing_actions
181
182    USE kinds
183
184    USE netcdf_data_input_mod,                                                                     &
185        ONLY:  building_id_f, building_type_f
186
187    USE palm_date_time_mod,                                                                        &
188        ONLY:  get_date_time, northward_equinox, seconds_per_hour, southward_equinox
189
190    USE surface_mod,                                                                               &
191        ONLY:  surf_usm_h, surf_usm_v
192
193
194    IMPLICIT NONE
195
196!
197!-- Define data structure for buidlings.
198    TYPE build
199
200       INTEGER(iwp) ::  id                                !< building ID
201       INTEGER(iwp) ::  kb_max                            !< highest vertical index of a building
202       INTEGER(iwp) ::  kb_min                            !< lowest vertical index of a building
203       INTEGER(iwp) ::  num_facades_per_building_h = 0    !< total number of horizontal facades elements
204       INTEGER(iwp) ::  num_facades_per_building_h_l = 0  !< number of horizontal facade elements on local subdomain
205       INTEGER(iwp) ::  num_facades_per_building_v = 0    !< total number of vertical facades elements
206       INTEGER(iwp) ::  num_facades_per_building_v_l = 0  !< number of vertical facade elements on local subdomain
207       INTEGER(iwp) ::  ventilation_int_loads             !< [-] allocation of activity in the building
208
209       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  l_h            !< index array linking surface-element orientation index
210                                                                  !< for horizontal surfaces with building
211       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  l_v            !< index array linking surface-element orientation index
212                                                                  !< for vertical surfaces with building
213       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_h            !< index array linking surface-element index for
214                                                                  !< horizontal surfaces with building
215       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_v            !< index array linking surface-element index for
216                                                                  !< vertical surfaces with building
217       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_h   !< number of horizontal facade elements per buidling
218                                                                  !< and height level
219       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_v   !< number of vertical facades elements per buidling
220                                                                  !< and height level
221
222
223       LOGICAL ::  on_pe = .FALSE.   !< flag indicating whether a building with certain ID is on local subdomain
224
225       REAL(wp) ::  air_change_high       !< [1/h] air changes per time_utc_hour
226       REAL(wp) ::  air_change_low        !< [1/h] air changes per time_utc_hour
227       REAL(wp) ::  area_facade           !< [m2] area of total facade
228       REAL(wp) ::  building_height       !< building height
229       REAL(wp) ::  eta_ve                !< [-] heat recovery efficiency
230       REAL(wp) ::  factor_a              !< [-] Dynamic parameters specific effective surface according to Table 12; 2.5
231                                          !< (very light, light and medium), 3.0 (heavy), 3.5 (very heavy)
232       REAL(wp) ::  factor_c              !< [J/(m2 K)] Dynamic parameters inner heatstorage according to Table 12; 80000
233                                          !< (very light), 110000 (light), 165000 (medium), 260000 (heavy), 370000 (very heavy)
234       REAL(wp) ::  f_c_win               !< [-] shading factor
235       REAL(wp) ::  fapf                  !< [m2/m2] floor area per facade
236       REAL(wp) ::  g_value_win           !< [-] SHGC factor
237       REAL(wp) ::  h_es                  !< [W/(m2 K)] surface-related heat transfer coefficient between extern and surface
238       REAL(wp) ::  height_cei_con        !< [m] ceiling construction heigth
239       REAL(wp) ::  height_storey         !< [m] storey heigth
240       REAL(wp) ::  params_waste_heat_c   !< [-] anthropogenic heat outputs for cooling e.g. 1.33 for KKM with COP = 3
241       REAL(wp) ::  params_waste_heat_h   !< [-] anthropogenic heat outputs for heating e.g. 1 - 0.9 = 0.1 for combustion with
242                                          !< eta = 0.9 or -2 for WP with COP = 3
243       REAL(wp) ::  phi_c_max             !< [W] Max. Cooling capacity (negative)
244       REAL(wp) ::  phi_h_max             !< [W] Max. Heating capacity (positive)
245       REAL(wp) ::  q_c_max               !< [W/m2] Max. Cooling heat flux per netto floor area (negative)
246       REAL(wp) ::  q_h_max               !< [W/m2] Max. Heating heat flux per netto floor area (positive)
247       REAL(wp) ::  qint_high             !< [W/m2] internal heat gains, option Database qint_0-23
248       REAL(wp) ::  qint_low              !< [W/m2] internal heat gains, option Database qint_0-23
249       REAL(wp) ::  lambda_at             !< [-] ratio internal surface/floor area chap. 7.2.2.2.
250       REAL(wp) ::  lambda_layer3         !< [W/(m*K)] Thermal conductivity of the inner layer
251       REAL(wp) ::  net_floor_area        !< [m2] netto ground area
252       REAL(wp) ::  s_layer3              !< [m] half thickness of the inner layer (layer_3)
253       REAL(wp) ::  theta_int_c_set       !< [degree_C] Max. Setpoint temperature (summer)
254       REAL(wp) ::  theta_int_h_set       !< [degree_C] Max. Setpoint temperature (winter)
255       REAL(wp) ::  u_value_win           !< [W/(m2*K)] transmittance
256       REAL(wp) ::  vol_tot               !< [m3] total building volume
257
258       REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in       !< mean building indoor temperature, height dependent
259       REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_l     !< mean building indoor temperature on local subdomain, height dependent
260       REAL(wp), DIMENSION(:), ALLOCATABLE ::  theta_m_t_prev_h !< [degree_C] value of theta_m_t from previous time step (horizontal)
261       REAL(wp), DIMENSION(:), ALLOCATABLE ::  theta_m_t_prev_v !< [degree_C] value of theta_m_t from previous time step (vertical)
262       REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume     !< total building volume, height dependent
263       REAL(wp), DIMENSION(:), ALLOCATABLE ::  vol_frac   !< fraction of local on total building volume, height dependent
264       REAL(wp), DIMENSION(:), ALLOCATABLE ::  vpf        !< building volume volume per facade element, height dependent
265
266    END TYPE build
267
268    TYPE(build), DIMENSION(:), ALLOCATABLE ::  buildings   !< building array
269
270    INTEGER(iwp) ::  num_build   !< total number of buildings in domain
271!
272!-- Declare all global variables within the module
273
274    REAL(wp), PARAMETER ::  dt_indoor = 3600.0_wp                  !< [s] time interval for indoor-model application, fixed to
275                                                                   !< 3600.0 due to model requirements
276    REAL(wp), PARAMETER ::  h_is                     = 3.45_wp     !< [W/(m2 K)] surface-related heat transfer coefficient between
277                                                                   !< surface and air (chap. 7.2.2.2)
278    REAL(wp), PARAMETER ::  h_ms                     = 9.1_wp      !< [W/(m2 K)] surface-related heat transfer coefficient between
279                                                                   !< component and surface (chap. 12.2.2)
280    REAL(wp), PARAMETER ::  params_f_f               = 0.3_wp      !< [-] frame ratio chap. 8.3.2.1.1 for buildings with mostly
281                                                                   !< cooling 2.0_wp
282    REAL(wp), PARAMETER ::  params_f_w               = 0.9_wp      !< [-] correction factor (fuer nicht senkrechten Stahlungseinfall
283                                                                   !< DIN 4108-2 chap.8, (hier konstant, keine WinkelabhÀngigkeit)
284    REAL(wp), PARAMETER ::  params_f_win             = 0.5_wp      !< [-] proportion of window area, Database A_win aus
285                                                                   !< Datenbank 27 window_area_per_facade_percent
286    REAL(wp), PARAMETER ::  params_solar_protection  = 300.0_wp    !< [W/m2] chap. G.5.3.1 sun protection closed, if the radiation
287                                                                   !< on facade exceeds this value
288
289    INTEGER(iwp) ::  cooling_on              !< Indoor cooling flag (0=off, 1=on)
290    INTEGER(iwp) ::  heating_on              !< Indoor heating flag (0=off, 1=on)
291    INTEGER(iwp) ::  solar_protection_off    !< Solar protection off
292    INTEGER(iwp) ::  solar_protection_on     !< Solar protection on
293
294
295    REAL(wp) ::  a_m                                 !< [m2] the effective mass-related area
296    REAL(wp) ::  air_change                          !< [1/h] Airflow
297    REAL(wp) ::  c_m                                 !< [J/K] internal heat storage capacity
298    REAL(wp) ::  facade_element_area                 !< [m2_facade] building surface facade
299    REAL(wp) ::  floor_area_per_facade               !< [m2/m2] floor area per facade area
300    REAL(wp) ::  h_t_1                               !< [W/K] Heat transfer coefficient auxiliary variable 1
301    REAL(wp) ::  h_t_2                               !< [W/K] Heat transfer coefficient auxiliary variable 2
302    REAL(wp) ::  h_t_3                               !< [W/K] Heat transfer coefficient auxiliary variable 3
303    REAL(wp) ::  h_t_es                              !< [W/K] heat transfer coefficient of doors, windows, curtain walls and
304                                                     !< glazed walls (assumption: thermal mass=0)
305    REAL(wp) ::  h_t_is                              !< [W/K] thermal coupling conductance (Thermischer Kopplungsleitwert)
306    REAL(wp) ::  h_t_ms                              !< [W/K] Heat transfer conductance term (got with h_t_wm the thermal mass)
307    REAL(wp) ::  h_t_wall                            !< [W/K] heat transfer coefficient of opaque components (assumption: got all
308                                                     !< thermal mass) contains of h_t_wm and h_t_ms
309    REAL(wp) ::  h_t_wm                              !< [W/K] Heat transfer coefficient of the emmision (got with h_t_ms the
310                                                     !< thermal mass)
311    REAL(wp) ::  h_v                                 !< [W/K] heat transfer of ventilation
312    REAL(wp) ::  indoor_volume_per_facade            !< [m3] indoor air volume per facade element
313    REAL(wp) ::  initial_indoor_temperature = 293.15 !< [K] initial indoor temperature (namelist parameter)
314    REAL(wp) ::  net_sw_in                           !< [W/m2] net short-wave radiation
315    REAL(wp) ::  phi_hc_nd                           !< [W] heating demand and/or cooling demand
316    REAL(wp) ::  phi_hc_nd_10                        !< [W] heating demand and/or cooling demand for heating or cooling
317    REAL(wp) ::  phi_hc_nd_ac                        !< [W] actual heating demand and/or cooling demand
318    REAL(wp) ::  phi_hc_nd_un                        !< [W] unlimited heating demand and/or cooling demand which is necessary to
319                                                     !< reach the demanded required temperature (heating is positive,
320                                                     !< cooling is negative)
321    REAL(wp) ::  phi_ia                              !< [W] internal air load = internal loads * 0.5, Eq. (C.1)
322    REAL(wp) ::  phi_m                               !< [W] mass specific thermal load (internal and external)
323    REAL(wp) ::  phi_mtot                            !< [W] total mass specific thermal load (internal and external)
324    REAL(wp) ::  phi_sol                             !< [W] solar loads
325    REAL(wp) ::  phi_st                              !< [W] mass specific thermal load implied non thermal mass
326    REAL(wp) ::  q_wall                              !< [W/m2]heat flux from indoor into wall
327    REAL(wp) ::  q_win                               !< [W/m2]heat flux from indoor into window
328    REAL(wp) ::  q_waste_heat                        !< [W/m2]waste heat, sum of waste heat over the roof to Palm
329
330    REAL(wp) ::  q_c_m                               !< [W] Energy of thermal storage mass specific thermal load for internal
331                                                     !< and external heatsources (for energy bilanz)
332    REAL(wp) ::  q_c_st                              !< [W] Energy of thermal storage mass specific thermal load implied non
333                                                     !< thermal mass (for energy bilanz)
334    REAL(wp) ::  q_int                               !< [W] Energy of internal air load (for energy bilanz)
335    REAL(wp) ::  q_sol                               !< [W] Energy of solar (for energy bilanz)
336    REAL(wp) ::  q_vent                              !< [W] Energy of ventilation (for energy bilanz)
337
338    REAL(wp) ::  schedule_d                          !< [-] activation for internal loads (low or high + low)
339    REAL(wp) ::  skip_time_do_indoor = 0.0_wp        !< [s] Indoor model is not called before this time
340    REAL(wp) ::  theta_air                           !< [degree_C] air temperature of the RC-node
341    REAL(wp) ::  theta_air_0                         !< [degree_C] air temperature of the RC-node in equilibrium
342    REAL(wp) ::  theta_air_10                        !< [degree_C] air temperature of the RC-node from a heating capacity
343                                                     !< of 10 W/m2
344    REAL(wp) ::  theta_air_ac                        !< [degree_C] actual room temperature after heating/cooling
345    REAL(wp) ::  theta_air_set                       !< [degree_C] Setpoint_temperature for the room
346    REAL(wp) ::  theta_m                             !< [degree_C} inner temperature of the RC-node
347    REAL(wp) ::  theta_m_t                           !< [degree_C] (Fictive) component temperature during timestep
348    REAL(wp) ::  theta_op                            !< [degree_C] operative temperature
349    REAL(wp) ::  theta_s                             !< [degree_C] surface temperature of the RC-node
350    REAL(wp) ::  time_indoor = 0.0_wp                !< [s] time since last call of indoor model
351    REAL(wp) ::  total_area                          !< [m2] area of all surfaces pointing to zone
352    REAL(wp) ::  window_area_per_facade              !< [m2] window area per facade element
353
354!
355!-- Definition of seasonal parameters, summer and winter, for different building types
356    REAL(wp), DIMENSION(0:1,1:7) ::  summer_pars = RESHAPE( (/                & ! building_type 1
357                                          0.5_wp,                             & ! basical airflow without occupancy of the room
358                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
359                                          0.5_wp,                             & ! building_type 2: basical airflow without occupancy
360                                                                                ! of the room
361                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
362                                          0.8_wp,                             & ! building_type 3: basical airflow without occupancy
363                                                                                ! of the room
364                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
365                                          0.1_wp,                             & ! building_type 4: basical airflow without occupancy
366                                                                                ! of the room
367                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
368                                          0.1_wp,                             & ! building_type 5: basical airflow without occupancy
369                                                                                ! of the room
370                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
371                                          0.1_wp,                             & ! building_type 6: basical airflow without occupancy
372                                                                                ! of the room
373                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
374                                          0.1_wp,                             & ! building_type 7: basical airflow without occupancy
375                                                                                ! of the room
376                                          1.5_wp                              & ! additional airflow depend of occupancy of the room
377                                                           /), (/ 2, 7 /) )
378
379    REAL(wp), DIMENSION(0:1,1:7) ::  winter_pars = RESHAPE( (/                & ! building_type 1
380                                          0.1_wp,                             & ! basical airflow without occupancy of the room
381                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
382                                          0.1_wp,                             & ! building_type 2: basical airflow without occupancy
383                                                                                ! of the room
384                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
385                                          0.1_wp,                             & ! building_type 3: basical airflow without occupancy
386                                                                                ! of the room
387                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
388                                          0.1_wp,                             & ! building_type 4: basical airflow without occupancy
389                                                                                ! of the room
390                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
391                                          0.1_wp,                             & ! building_type 5: basical airflow without occupancy
392                                                                                ! of the room
393                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
394                                          0.1_wp,                             & ! building_type 6: basical airflow without occupancy
395                                                                                ! of the room
396                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
397                                          0.1_wp,                             & ! building_type 7: basical airflow without occupancy
398                                                                                ! of the room
399                                          1.5_wp                              & ! additional airflow depend of occupancy of the room
400                                                           /), (/ 2, 7 /) )
401
402    SAVE
403
404
405    PRIVATE
406
407!
408!-- Add INTERFACES that must be available to other modules
409    PUBLIC im_init, im_main_heatcool, im_parin, im_define_netcdf_grid, im_check_data_output,       &
410           im_data_output_3d, im_check_parameters
411
412
413!
414!-- Add VARIABLES that must be available to other modules
415    PUBLIC dt_indoor, skip_time_do_indoor, time_indoor
416
417!
418!-- PALM interfaces:
419!-- Data output checks for 2D/3D data to be done in check_parameters
420     INTERFACE im_check_data_output
421        MODULE PROCEDURE im_check_data_output
422     END INTERFACE im_check_data_output
423!
424!-- Input parameter checks to be done in check_parameters
425     INTERFACE im_check_parameters
426        MODULE PROCEDURE im_check_parameters
427     END INTERFACE im_check_parameters
428!
429!-- Data output of 3D data
430     INTERFACE im_data_output_3d
431        MODULE PROCEDURE im_data_output_3d
432     END INTERFACE im_data_output_3d
433
434!
435!-- Definition of data output quantities
436     INTERFACE im_define_netcdf_grid
437        MODULE PROCEDURE im_define_netcdf_grid
438     END INTERFACE im_define_netcdf_grid
439!
440! !
441! !-- Output of information to the header file
442!     INTERFACE im_header
443!        MODULE PROCEDURE im_header
444!     END INTERFACE im_header
445!
446!-- Calculations for indoor temperatures
447    INTERFACE im_calc_temperatures
448       MODULE PROCEDURE im_calc_temperatures
449    END INTERFACE im_calc_temperatures
450!
451!-- Initialization actions
452    INTERFACE im_init
453       MODULE PROCEDURE im_init
454    END INTERFACE im_init
455!
456!-- Main part of indoor model
457    INTERFACE im_main_heatcool
458       MODULE PROCEDURE im_main_heatcool
459    END INTERFACE im_main_heatcool
460!
461!-- Reading of NAMELIST parameters
462    INTERFACE im_parin
463       MODULE PROCEDURE im_parin
464    END INTERFACE im_parin
465
466 CONTAINS
467
468!--------------------------------------------------------------------------------------------------!
469! Description:
470! ------------
471!< Calculation of the air temperatures and mean radiation temperature.
472!< This is basis for the operative temperature.
473!< Based on a Crank-Nicholson scheme with a timestep of a hour.
474!--------------------------------------------------------------------------------------------------!
475 SUBROUTINE im_calc_temperatures ( i, j, k, indoor_wall_temperature,  &
476                                   near_facade_temperature, phi_hc_nd_dummy, theta_m_t_prev )
477
478    INTEGER(iwp) ::  i
479    INTEGER(iwp) ::  j
480    INTEGER(iwp) ::  k
481
482    REAL(wp) ::  indoor_wall_temperature   !< temperature of innermost wall layer evtl in im_calc_temperatures einfÃŒgen
483    REAL(wp) ::  near_facade_temperature
484    REAL(wp) ::  phi_hc_nd_dummy
485    REAL(wp), INTENT(IN) :: theta_m_t_prev
486!
487!-- Calculation of total mass specific thermal load (internal and external)
488    phi_mtot = ( phi_m + h_t_wm * indoor_wall_temperature                                   &
489                       + h_t_3  * ( phi_st + h_t_es * pt(k,j,i)                                    &
490                                            + h_t_1 *                                              &
491                                    ( ( ( phi_ia + phi_hc_nd_dummy ) / h_v )                       &
492                                                 + near_facade_temperature )                       &
493                                  ) / h_t_2                                                        &
494               )                                                                !< [degree_C] Eq. (C.5)
495!
496!-- Calculation of component temperature at current timestep
497    theta_m_t = ( ( theta_m_t_prev                                                                 &
498                    * ( ( c_m / 3600.0_wp ) - 0.5_wp * ( h_t_3 + h_t_wm ) )                        &
499                     + phi_mtot                                                                    &
500                  )                                                                                &
501                  /   ( ( c_m / 3600.0_wp ) + 0.5_wp * ( h_t_3 + h_t_wm ) )                        &
502                )                                                               !< [degree_C] Eq. (C.4)
503!
504!-- Calculation of mean inner temperature for the RC-node in current timestep
505    theta_m = ( theta_m_t + theta_m_t_prev ) * 0.5_wp                           !< [degree_C] Eq. (C.9)
506
507!
508!-- Calculation of mean surface temperature of the RC-node in current timestep
509    theta_s = ( (   h_t_ms * theta_m + phi_st + h_t_es * pt(k,j,i)                                 &
510                  + h_t_1  * ( near_facade_temperature                                             &
511                           + ( phi_ia + phi_hc_nd_dummy ) / h_v )                                  &
512                )                                                                                  &
513                / ( h_t_ms + h_t_es + h_t_1 )                                                      &
514              )                                                                 !< [degree_C] Eq. (C.10)
515
516!
517!-- Calculation of the air temperature of the RC-node
518
519
520    theta_air = ( h_t_is * theta_s + h_v * near_facade_temperature + phi_ia + phi_hc_nd_dummy ) /  &
521                ( h_t_is + h_v )                                                !< [degree_C] Eq. (C.11)
522
523
524 END SUBROUTINE im_calc_temperatures
525
526
527!--------------------------------------------------------------------------------------------------!
528! Description:
529! ------------
530!> Initialization of the indoor model.
531!> Static information are calculated here, e.g. building parameters and geometrical information,
532!> anything that doesn't change in time.
533!
534!-- Input values
535!-- Input datas from Palm, M4
536!     i_global             -->  net_sw_in                         !< global radiation [W/m2]
537!     theta_e              -->  pt(k,j,i)                         !< undisturbed outside temperature, 1. PALM volume, for windows
538!     theta_sup = theta_f  -->  surf_usm_h%pt_10cm(m)
539!                               surf_usm_v(l)%pt_10cm(m)          !< Air temperature, facade near (10cm) air temperature from
540                                                                  !< 1. Palm volume
541!     theta_node           -->  t_wall_h(nzt_wall,m)
542!                               t_wall_v(l)%t(nzt_wall,m)         !< Temperature of innermost wall layer, for opaque wall
543!--------------------------------------------------------------------------------------------------!
544 SUBROUTINE im_init
545
546    USE control_parameters,                                                                        &
547        ONLY:  message_string, time_since_reference_point
548
549    USE indices,                                                                                   &
550        ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_total_0
551
552    USE grid_variables,                                                                            &
553        ONLY:  dx, dy
554
555    USE pegrid
556
557    USE surface_mod,                                                                               &
558        ONLY:  surf_usm_h, surf_usm_v
559
560    USE urban_surface_mod,                                                                         &
561        ONLY:  building_pars, building_type
562
563    INTEGER(iwp) ::  bt          !< local building type
564    INTEGER(iwp) ::  day_of_year !< day of the year
565    INTEGER(iwp) ::  i           !< running index along x-direction
566    INTEGER(iwp) ::  j           !< running index along y-direction
567    INTEGER(iwp) ::  k           !< running index along z-direction
568    INTEGER(iwp) ::  l           !< running index for surface-element orientation
569    INTEGER(iwp) ::  m           !< running index surface elements
570    INTEGER(iwp) ::  n           !< building index
571    INTEGER(iwp) ::  nb          !< building index
572
573    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids           !< building IDs on entire model domain
574    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain,
575                                                                    !< multiple occurences are sorted out
576    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final_tmp !< temporary array used for resizing
577    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l         !< building IDs on local subdomain
578    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l_tmp     !< temporary array used to resize array of building IDs
579    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  displace_dum        !< displacements of start addresses, used for MPI_ALLGATHERV
580    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_max_l             !< highest vertical index of a building on subdomain
581    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_min_l             !< lowest vertical index of a building on subdomain
582    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  n_fa                !< counting array
583    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_h       !< dummy array used for summing-up total number of
584                                                                    !< horizontal facade elements
585    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_v       !< dummy array used for summing-up total number of
586                                                                    !< vertical facade elements
587    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_h       !< dummy array used for MPI_ALLREDUCE
588    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_v       !< dummy array used for MPI_ALLREDUCE
589
590    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings         !< number of buildings with different ID on entire model domain
591    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings_l       !< number of buildings with different ID on local subdomain
592
593    REAL(wp) ::  u_tmp                                     !< dummy for temporary calculation of u-value without h_is
594    REAL(wp) ::  du_tmp                                    !< 1/u_tmp
595    REAL(wp) ::  du_win_tmp                                !< 1/building(nb)%u_value_win
596    REAL(wp) ::  facade_area_v                             !< dummy to compute the total facade area from vertical walls
597
598    REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume         !< total building volume at each discrete height level
599    REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume_l       !< total building volume at each discrete height level,
600                                                           !< on local subdomain
601
602    CALL location_message( 'initializing indoor model', 'start' )
603!
604!-- Initializing of indoor model is only possible if buildings can be distinguished by their IDs.
605    IF ( .NOT. building_id_f%from_file )  THEN
606       message_string = 'Indoor model requires information about building_id'
607       CALL message( 'im_init', 'PA0999', 1, 2, 0, 6, 0  )
608    ENDIF
609!
610!-- Determine number of different building IDs on local subdomain.
611    num_buildings_l = 0
612    num_buildings   = 0
613    ALLOCATE( build_ids_l(1) )
614    DO  i = nxl, nxr
615       DO  j = nys, nyn
616          IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
617             IF ( num_buildings_l(myid) > 0 )  THEN
618                IF ( ANY( building_id_f%var(j,i) == build_ids_l ) )  THEN
619                   CYCLE
620                ELSE
621                   num_buildings_l(myid) = num_buildings_l(myid) + 1
622!
623!--                Resize array with different local building ids
624                   ALLOCATE( build_ids_l_tmp(1:SIZE(build_ids_l)) )
625                   build_ids_l_tmp = build_ids_l
626                   DEALLOCATE( build_ids_l )
627                   ALLOCATE( build_ids_l(1:num_buildings_l(myid)) )
628                   build_ids_l(1:num_buildings_l(myid)-1) =                                        &
629                                                          build_ids_l_tmp(1:num_buildings_l(myid)-1)
630                   build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i)
631                   DEALLOCATE( build_ids_l_tmp )
632                ENDIF
633!
634!--          First occuring building id on PE
635             ELSE
636                num_buildings_l(myid) = num_buildings_l(myid) + 1
637                build_ids_l(1) = building_id_f%var(j,i)
638             ENDIF
639          ENDIF
640       ENDDO
641    ENDDO
642!
643!-- Determine number of building IDs for the entire domain. (Note, building IDs can appear multiple
644!-- times as buildings might be distributed over several PEs.)
645#if defined( __parallel )
646    CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs, MPI_INTEGER, MPI_SUM, comm2d,    &
647                        ierr )
648#else
649    num_buildings = num_buildings_l
650#endif
651    ALLOCATE( build_ids(1:SUM(num_buildings)) )
652!
653!-- Gather building IDs. Therefore, first, determine displacements used required for MPI_GATHERV
654!-- call.
655    ALLOCATE( displace_dum(0:numprocs-1) )
656    displace_dum(0) = 0
657    DO i = 1, numprocs-1
658       displace_dum(i) = displace_dum(i-1) + num_buildings(i-1)
659    ENDDO
660
661#if defined( __parallel )
662    CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)),                                     &
663                         num_buildings(myid),                                                      &
664                         MPI_INTEGER,                                                              &
665                         build_ids,                                                                &
666                         num_buildings,                                                            &
667                         displace_dum,                                                             &
668                         MPI_INTEGER,                                                              &
669                         comm2d, ierr )
670
671    DEALLOCATE( displace_dum )
672
673#else
674    build_ids = build_ids_l
675#endif
676!
677!-- Note: in parallel mode, building IDs can occur mutliple times, as each PE has send its own ids.
678!-- Therefore, sort out building IDs which appear multiple times.
679    num_build = 0
680    DO  n = 1, SIZE(build_ids)
681
682       IF ( ALLOCATED(build_ids_final) )  THEN
683          IF ( ANY( build_ids(n) == build_ids_final ) )  THEN
684             CYCLE
685          ELSE
686             num_build = num_build + 1
687!
688!--          Resize
689             ALLOCATE( build_ids_final_tmp(1:num_build) )
690             build_ids_final_tmp(1:num_build-1) = build_ids_final(1:num_build-1)
691             DEALLOCATE( build_ids_final )
692             ALLOCATE( build_ids_final(1:num_build) )
693             build_ids_final(1:num_build-1) = build_ids_final_tmp(1:num_build-1)
694             build_ids_final(num_build) = build_ids(n)
695             DEALLOCATE( build_ids_final_tmp )
696          ENDIF
697       ELSE
698          num_build = num_build + 1
699          ALLOCATE( build_ids_final(1:num_build) )
700          build_ids_final(num_build) = build_ids(n)
701       ENDIF
702    ENDDO
703
704!
705!-- Allocate building-data structure array. Note, this is a global array and all building IDs on
706!-- domain are known by each PE. Further attributes, e.g. height-dependent arrays, however, are only
707!-- allocated on PEs where  the respective building is present (in order to reduce memory demands).
708    ALLOCATE( buildings(1:num_build) )
709
710!
711!-- Store building IDs and check if building with certain ID is present on subdomain.
712    DO  nb = 1, num_build
713       buildings(nb)%id = build_ids_final(nb)
714
715       IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) )                        &
716          buildings(nb)%on_pe = .TRUE.
717    ENDDO
718!
719!-- Determine the maximum vertical dimension occupied by each building.
720    ALLOCATE( k_min_l(1:num_build) )
721    ALLOCATE( k_max_l(1:num_build) )
722    k_min_l = nzt + 1
723    k_max_l = 0
724
725    DO  i = nxl, nxr
726       DO  j = nys, nyn
727          IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
728             nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
729             DO  k = nzb, nzt+1
730!
731!--             Check if grid point belongs to a building.
732                IF ( BTEST( wall_flags_total_0(k,j,i), 6 ) )  THEN
733                   k_min_l(nb) = MIN( k_min_l(nb), k )
734                   k_max_l(nb) = MAX( k_max_l(nb), k )
735                ENDIF
736
737             ENDDO
738          ENDIF
739       ENDDO
740    ENDDO
741
742#if defined( __parallel )
743    CALL MPI_ALLREDUCE( k_min_l(:), buildings(:)%kb_min, num_build, MPI_INTEGER, MPI_MIN, comm2d,  &
744                        ierr )
745    CALL MPI_ALLREDUCE( k_max_l(:), buildings(:)%kb_max, num_build, MPI_INTEGER, MPI_MAX, comm2d,  &
746                        ierr )
747#else
748    buildings(:)%kb_min = k_min_l(:)
749    buildings(:)%kb_max = k_max_l(:)
750#endif
751
752    DEALLOCATE( k_min_l )
753    DEALLOCATE( k_max_l )
754!
755!-- Calculate building height.
756    DO  nb = 1, num_build
757       buildings(nb)%building_height = 0.0_wp
758       DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
759          buildings(nb)%building_height = buildings(nb)%building_height + dzw(k+1)
760       ENDDO
761    ENDDO
762!
763!-- Calculate building volume
764    DO  nb = 1, num_build
765!
766!--    Allocate temporary array for summing-up building volume
767       ALLOCATE( volume(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
768       ALLOCATE( volume_l(buildings(nb)%kb_min:buildings(nb)%kb_max) )
769       volume   = 0.0_wp
770       volume_l = 0.0_wp
771!
772!--    Calculate building volume per height level on each PE where these building is present.
773       IF ( buildings(nb)%on_pe )  THEN
774
775          ALLOCATE( buildings(nb)%volume(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
776          ALLOCATE( buildings(nb)%vol_frac(buildings(nb)%kb_min:buildings(nb)%kb_max) )
777          buildings(nb)%volume   = 0.0_wp
778          buildings(nb)%vol_frac = 0.0_wp
779
780          IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) )  THEN
781             DO  i = nxl, nxr
782                DO  j = nys, nyn
783                   DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
784                      IF ( building_id_f%var(j,i) /= building_id_f%fill )                          &
785                         volume_l(k) = volume_l(k) + dx * dy * dzw(k+1)
786                   ENDDO
787                ENDDO
788             ENDDO
789          ENDIF
790       ENDIF
791!
792!--    Sum-up building volume from all subdomains
793#if defined( __parallel )
794       CALL MPI_ALLREDUCE( volume_l, volume, SIZE(volume), MPI_REAL, MPI_SUM, comm2d, ierr )
795#else
796       volume = volume_l
797#endif
798!
799!--    Save total building volume as well as local fraction on volume on building data structure.
800       IF ( ALLOCATED( buildings(nb)%volume ) )  buildings(nb)%volume = volume
801!
802!--    Determine fraction of local on total building volume
803       IF ( buildings(nb)%on_pe )  buildings(nb)%vol_frac = volume_l / volume
804!
805!--    Calculate total building volume
806       IF ( ALLOCATED( buildings(nb)%volume ) )  buildings(nb)%vol_tot = SUM( buildings(nb)%volume )
807
808       DEALLOCATE( volume   )
809       DEALLOCATE( volume_l )
810
811    ENDDO
812!
813!-- Allocate arrays for indoor temperature.
814    DO  nb = 1, num_build
815       IF ( buildings(nb)%on_pe )  THEN
816          ALLOCATE( buildings(nb)%t_in(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
817          ALLOCATE( buildings(nb)%t_in_l(buildings(nb)%kb_min:buildings(nb)%kb_max) )
818          buildings(nb)%t_in   = 0.0_wp
819          buildings(nb)%t_in_l = 0.0_wp
820       ENDIF
821    ENDDO
822!
823!-- Allocate arrays for number of facades per height level. Distinguish between horizontal and
824!-- vertical facades.
825    DO  nb = 1, num_build
826       IF ( buildings(nb)%on_pe )  THEN
827          ALLOCATE( buildings(nb)%num_facade_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
828          ALLOCATE( buildings(nb)%num_facade_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
829
830          buildings(nb)%num_facade_h = 0
831          buildings(nb)%num_facade_v = 0
832       ENDIF
833    ENDDO
834!
835!-- Determine number of facade elements per building on local subdomain.
836!-- Distinguish between horizontal and vertical facade elements.
837!
838!-- Horizontal facades
839    buildings(:)%num_facades_per_building_h_l = 0
840    DO  l = 0, 1
841       DO  m = 1, surf_usm_h(l)%ns
842!
843!--       For the current facade element determine corresponding building index.
844!--       First, obtain j,j,k indices of the building. Please note the offset between facade/surface
845!--       element and building location (for horizontal surface elements the horizontal offsets are
846!--       zero).
847          i = surf_usm_h(l)%i(m) + surf_usm_h(l)%ioff
848          j = surf_usm_h(l)%j(m) + surf_usm_h(l)%joff
849          k = surf_usm_h(l)%k(m) + surf_usm_h(l)%koff
850!
851!--       Determine building index and check whether building is on PE.
852          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
853
854          IF ( buildings(nb)%on_pe )  THEN
855!
856!--          Count number of facade elements at each height level.
857             buildings(nb)%num_facade_h(k) = buildings(nb)%num_facade_h(k) + 1
858!
859!--          Moreover, sum up number of local facade elements per building.
860             buildings(nb)%num_facades_per_building_h_l =                                             &
861                                                      buildings(nb)%num_facades_per_building_h_l + 1
862          ENDIF
863       ENDDO
864    ENDDO
865!
866!-- Vertical facades
867    buildings(:)%num_facades_per_building_v_l = 0
868    DO  l = 0, 3
869       DO  m = 1, surf_usm_v(l)%ns
870!
871!--       For the current facade element determine corresponding building index.
872!--       First, obtain j,j,k indices of the building. Please note the offset between facade/surface
873!--       element and building location (for vertical surface elements the vertical offsets are
874!--       zero).
875          i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
876          j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
877          k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
878
879          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
880          IF ( buildings(nb)%on_pe )  THEN
881             buildings(nb)%num_facade_v(k) = buildings(nb)%num_facade_v(k) + 1
882             buildings(nb)%num_facades_per_building_v_l =                                          &
883                                                      buildings(nb)%num_facades_per_building_v_l + 1
884          ENDIF
885       ENDDO
886    ENDDO
887!
888!-- Determine total number of facade elements per building and assign number to building data type.
889    DO  nb = 1, num_build
890!
891!--    Allocate dummy array used for summing-up facade elements.
892!--    Please note, dummy arguments are necessary as building-date type arrays are not necessarily
893!--    allocated on all PEs.
894       ALLOCATE( num_facades_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
895       ALLOCATE( num_facades_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
896       ALLOCATE( receive_dum_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
897       ALLOCATE( receive_dum_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
898       num_facades_h = 0
899       num_facades_v = 0
900       receive_dum_h = 0
901       receive_dum_v = 0
902
903       IF ( buildings(nb)%on_pe )  THEN
904          num_facades_h = buildings(nb)%num_facade_h
905          num_facades_v = buildings(nb)%num_facade_v
906       ENDIF
907
908#if defined( __parallel )
909       CALL MPI_ALLREDUCE( num_facades_h,                                                          &
910                           receive_dum_h,                                                          &
911                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
912                           MPI_INTEGER,                                                            &
913                           MPI_SUM,                                                                &
914                           comm2d,                                                                 &
915                           ierr )
916
917       CALL MPI_ALLREDUCE( num_facades_v,                                                          &
918                           receive_dum_v,                                                          &
919                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
920                           MPI_INTEGER,                                                            &
921                           MPI_SUM,                                                                &
922                           comm2d,                                                                 &
923                           ierr )
924       IF ( ALLOCATED( buildings(nb)%num_facade_h ) )  buildings(nb)%num_facade_h = receive_dum_h
925       IF ( ALLOCATED( buildings(nb)%num_facade_v ) )  buildings(nb)%num_facade_v = receive_dum_v
926#else
927       buildings(nb)%num_facade_h = num_facades_h
928       buildings(nb)%num_facade_v = num_facades_v
929#endif
930
931!
932!--    Deallocate dummy arrays
933       DEALLOCATE( num_facades_h )
934       DEALLOCATE( num_facades_v )
935       DEALLOCATE( receive_dum_h )
936       DEALLOCATE( receive_dum_v )
937!
938!--    Allocate index arrays which link facade elements with surface-data type.
939!--    Please note, no height levels are considered here (information is stored in surface-data type
940!--    itself).
941       IF ( buildings(nb)%on_pe )  THEN
942!
943!--       Determine number of facade elements per building.
944          buildings(nb)%num_facades_per_building_h = SUM( buildings(nb)%num_facade_h )
945          buildings(nb)%num_facades_per_building_v = SUM( buildings(nb)%num_facade_v )
946!
947!--       Allocate arrays which link the building with the horizontal and vertical urban-type
948!--       surfaces. Please note, linking arrays are allocated over all facade elements, which is
949!--       required in case a building is located at the subdomain boundaries, where the building and
950!--       the corresponding surface elements are located on different subdomains.
951          ALLOCATE( buildings(nb)%l_h(1:buildings(nb)%num_facades_per_building_h_l) )
952          ALLOCATE( buildings(nb)%m_h(1:buildings(nb)%num_facades_per_building_h_l) )
953
954          ALLOCATE( buildings(nb)%l_v(1:buildings(nb)%num_facades_per_building_v_l) )
955          ALLOCATE( buildings(nb)%m_v(1:buildings(nb)%num_facades_per_building_v_l) )
956
957          ALLOCATE( buildings(nb)%theta_m_t_prev_h(1:buildings(nb)%num_facades_per_building_h_l) )
958          ALLOCATE( buildings(nb)%theta_m_t_prev_v(1:buildings(nb)%num_facades_per_building_v_l) )
959       ENDIF
960
961       IF ( buildings(nb)%on_pe )  THEN
962          ALLOCATE( buildings(nb)%vpf(buildings(nb)%kb_min:buildings(nb)%kb_max) )
963          buildings(nb)%vpf = 0.0_wp
964
965          facade_area_v = 0.0_wp
966          DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
967             facade_area_v = facade_area_v + buildings(nb)%num_facade_v(k) * dzw(k+1) * dx
968          ENDDO
969!
970!--       Determine volume per total facade area (vpf). For the horizontal facade area
971!--       num_facades_per_building_h can be taken, multiplied with dx*dy.
972!--       However, due to grid stretching, vertical facade elements must be summed-up vertically.
973!--       Please note, if dx /= dy, an error is made!
974          buildings(nb)%vpf = buildings(nb)%vol_tot /                                              &
975                              ( buildings(nb)%num_facades_per_building_h * dx * dy + facade_area_v )
976!
977!--       Determine floor-area-per-facade.
978          buildings(nb)%fapf = buildings(nb)%num_facades_per_building_h     * dx * dy              &
979                               / ( buildings(nb)%num_facades_per_building_h * dx * dy              &
980                                   + facade_area_v )
981       ENDIF
982    ENDDO
983!
984!-- Link facade elements with surface data type.
985!-- Allocate array for counting.
986    ALLOCATE( n_fa(1:num_build) )
987    n_fa = 1
988
989    DO  l = 0, 1
990       DO  m = 1, surf_usm_h(l)%ns
991          i = surf_usm_h(l)%i(m) + surf_usm_h(l)%ioff
992          j = surf_usm_h(l)%j(m) + surf_usm_h(l)%joff
993
994          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
995
996          IF ( buildings(nb)%on_pe )  THEN
997             buildings(nb)%l_h(n_fa(nb)) = l
998             buildings(nb)%m_h(n_fa(nb)) = m
999             n_fa(nb) = n_fa(nb) + 1
1000          ENDIF
1001       ENDDO
1002    ENDDO
1003
1004    n_fa = 1
1005    DO  l = 0, 3
1006       DO  m = 1, surf_usm_v(l)%ns
1007          i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
1008          j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
1009
1010          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
1011
1012          IF ( buildings(nb)%on_pe )  THEN
1013             buildings(nb)%l_v(n_fa(nb)) = l
1014             buildings(nb)%m_v(n_fa(nb)) = m
1015             n_fa(nb) = n_fa(nb) + 1
1016          ENDIF
1017       ENDDO
1018    ENDDO
1019    DEALLOCATE( n_fa )
1020!
1021!-- Initialize building parameters, first by mean building type. Note, in this case all buildings
1022!-- have the same type.
1023!-- In a second step initialize with building tpyes from static input file, where building types can
1024!-- be individual for each building.
1025    buildings(:)%lambda_layer3       = building_pars(31,building_type)
1026    buildings(:)%s_layer3            = building_pars(44,building_type)
1027    buildings(:)%f_c_win             = building_pars(119,building_type)
1028    buildings(:)%g_value_win         = building_pars(120,building_type)
1029    buildings(:)%u_value_win         = building_pars(121,building_type)
1030    buildings(:)%eta_ve              = building_pars(124,building_type)
1031    buildings(:)%factor_a            = building_pars(125,building_type)
1032    buildings(:)%factor_c            = building_pars(126,building_type)
1033    buildings(:)%lambda_at           = building_pars(127,building_type)
1034    buildings(:)%theta_int_h_set     = building_pars(13,building_type)
1035    buildings(:)%theta_int_c_set     = building_pars(12,building_type)
1036    buildings(:)%q_h_max             = building_pars(128,building_type)
1037    buildings(:)%q_c_max             = building_pars(129,building_type)
1038    buildings(:)%qint_high           = building_pars(130,building_type)
1039    buildings(:)%qint_low            = building_pars(131,building_type)
1040    buildings(:)%height_storey       = building_pars(132,building_type)
1041    buildings(:)%height_cei_con      = building_pars(133,building_type)
1042    buildings(:)%params_waste_heat_h = building_pars(134,building_type)
1043    buildings(:)%params_waste_heat_c = building_pars(135,building_type)
1044!
1045!-- Initialize seasonal dependent parameters, depending on day of the year.
1046!-- First, calculated day of the year.
1047    CALL get_date_time( time_since_reference_point, day_of_year = day_of_year )
1048!
1049!-- Summer is defined in between northward- and southward equinox.
1050    IF ( day_of_year >= northward_equinox  .AND.  day_of_year <= southward_equinox )  THEN
1051       buildings(:)%air_change_low      = summer_pars(0,building_type)
1052       buildings(:)%air_change_high     = summer_pars(1,building_type)
1053    ELSE
1054       buildings(:)%air_change_low      = winter_pars(0,building_type)
1055       buildings(:)%air_change_high     = winter_pars(1,building_type)
1056    ENDIF
1057!
1058!-- Initialize ventilation load. Please note, building types > 7 are actually not allowed (check
1059!-- already in urban_surface_mod and netcdf_data_input_mod.
1060!-- However, the building data base may be later extended.
1061    IF ( building_type ==  1  .OR.  building_type ==  2  .OR.                                      &
1062         building_type ==  3  .OR.  building_type == 10  .OR.                                      &
1063         building_type == 11  .OR.  building_type == 12 )  THEN
1064       buildings(:)%ventilation_int_loads = 1
1065!
1066!-- Office, building with large windows
1067    ELSEIF ( building_type ==  4  .OR.  building_type ==  5  .OR.                                  &
1068             building_type ==  6  .OR.  building_type ==  7  .OR.                                  &
1069             building_type ==  8  .OR.  building_type ==  9)  THEN
1070       buildings(:)%ventilation_int_loads = 2
1071!
1072!-- Industry, hospitals
1073    ELSEIF ( building_type == 13  .OR.  building_type == 14  .OR.                                  &
1074             building_type == 15  .OR.  building_type == 16  .OR.                                  &
1075             building_type == 17  .OR.  building_type == 18 )  THEN
1076       buildings(:)%ventilation_int_loads = 3
1077    ENDIF
1078!
1079!-- Initialization of building parameters - level 2
1080    IF ( building_type_f%from_file )  THEN
1081       DO  i = nxl, nxr
1082          DO  j = nys, nyn
1083              IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
1084                 nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
1085                 bt = building_type_f%var(j,i)
1086
1087                 buildings(nb)%lambda_layer3       = building_pars(31,bt)
1088                 buildings(nb)%s_layer3            = building_pars(44,bt)
1089                 buildings(nb)%f_c_win             = building_pars(119,bt)
1090                 buildings(nb)%g_value_win         = building_pars(120,bt)
1091                 buildings(nb)%u_value_win         = building_pars(121,bt)
1092                 buildings(nb)%eta_ve              = building_pars(124,bt)
1093                 buildings(nb)%factor_a            = building_pars(125,bt)
1094                 buildings(nb)%factor_c            = building_pars(126,bt)
1095                 buildings(nb)%lambda_at           = building_pars(127,bt)
1096                 buildings(nb)%theta_int_h_set     = building_pars(13,bt)
1097                 buildings(nb)%theta_int_c_set     = building_pars(12,bt)
1098                 buildings(nb)%q_h_max             = building_pars(128,bt)
1099                 buildings(nb)%q_c_max             = building_pars(129,bt)
1100                 buildings(nb)%qint_high           = building_pars(130,bt)
1101                 buildings(nb)%qint_low            = building_pars(131,bt)
1102                 buildings(nb)%height_storey       = building_pars(132,bt)
1103                 buildings(nb)%height_cei_con      = building_pars(133,bt)
1104                 buildings(nb)%params_waste_heat_h = building_pars(134,bt)
1105                 buildings(nb)%params_waste_heat_c = building_pars(135,bt)
1106
1107              IF ( day_of_year >= northward_equinox  .AND.  day_of_year <= southward_equinox )  THEN
1108                 buildings(nb)%air_change_low      = summer_pars(0,bt)
1109                 buildings(nb)%air_change_high     = summer_pars(1,bt)
1110              ELSE
1111                 buildings(nb)%air_change_low      = winter_pars(0,bt)
1112                 buildings(nb)%air_change_high     = winter_pars(1,bt)
1113              ENDIF
1114
1115!
1116!--              Initialize ventilaation load. Please note, building types > 7
1117!--              are actually not allowed (check already in urban_surface_mod
1118!--              and netcdf_data_input_mod. However, the building data base may
1119!--              be later extended.
1120                 IF ( bt ==  1  .OR.  bt ==  2  .OR.                                               &
1121                      bt ==  3  .OR.  bt == 10  .OR.                                               &
1122                      bt == 11  .OR.  bt == 12 )  THEN
1123                    buildings(nb)%ventilation_int_loads = 1
1124!
1125!--              Office, building with large windows
1126                 ELSEIF ( bt ==  4  .OR.  bt ==  5  .OR.                                           &
1127                          bt ==  6  .OR.  bt ==  7  .OR.                                           &
1128                          bt ==  8  .OR.  bt ==  9)  THEN
1129                    buildings(nb)%ventilation_int_loads = 2
1130!
1131!--              Industry, hospitals
1132                 ELSEIF ( bt == 13  .OR.  bt == 14  .OR.                                           &
1133                          bt == 15  .OR.  bt == 16  .OR.                                           &
1134                          bt == 17  .OR.  bt == 18 )  THEN
1135                    buildings(nb)%ventilation_int_loads = 3
1136                 ENDIF
1137              ENDIF
1138           ENDDO
1139        ENDDO
1140    ENDIF
1141!
1142!-- Calculation of surface-related heat transfer coeffiecient out of standard u-values from building
1143!-- database.
1144!-- Only amount of extern and surface is used.
1145!-- Otherwise amount between air and surface taken account twice.
1146    DO nb = 1, num_build
1147       IF ( buildings(nb)%on_pe ) THEN
1148          du_win_tmp = 1.0_wp / buildings(nb)%u_value_win
1149          u_tmp = buildings(nb)%u_value_win * ( du_win_tmp / ( du_win_tmp -                        &
1150                  0.125_wp + ( 1.0_wp / h_is ) ) )
1151
1152          du_tmp = 1.0_wp / u_tmp
1153
1154          buildings(nb)%h_es = 1.0_wp / ( du_tmp - ( 1.0_wp / h_is ) )
1155
1156       ENDIF
1157    ENDDO
1158!
1159!-- Initialize indoor temperature. Actually only for output at initial state.
1160    DO  nb = 1, num_build
1161       IF ( buildings(nb)%on_pe )  THEN
1162          buildings(nb)%t_in(:) = initial_indoor_temperature
1163
1164!
1165!--       (after first loop, use theta_m_t as theta_m_t_prev)
1166          buildings(nb)%theta_m_t_prev_h(:) = initial_indoor_temperature
1167          buildings(nb)%theta_m_t_prev_v(:) = initial_indoor_temperature
1168
1169       ENDIF
1170    ENDDO
1171
1172    CALL location_message( 'initializing indoor model', 'finished' )
1173
1174 END SUBROUTINE im_init
1175
1176
1177!--------------------------------------------------------------------------------------------------!
1178! Description:
1179! ------------
1180!> Main part of the indoor model.
1181!> Calculation of .... (kanani: Please describe)
1182!--------------------------------------------------------------------------------------------------!
1183 SUBROUTINE im_main_heatcool
1184
1185!     USE basic_constants_and_equations_mod,                                     &
1186!         ONLY:  c_p
1187
1188    USE control_parameters,                                                                        &
1189        ONLY:  time_since_reference_point
1190
1191    USE grid_variables,                                                                            &
1192        ONLY:  dx, dy
1193
1194    USE pegrid
1195
1196    USE surface_mod,                                                                               &
1197        ONLY:  ind_veg_wall, ind_wat_win, surf_usm_h, surf_usm_v
1198
1199    USE urban_surface_mod,                                                                         &
1200        ONLY:  building_type, nzt_wall, t_wall_h, t_wall_v, t_window_h, t_window_v
1201
1202
1203    INTEGER(iwp) ::  fa   !< running index for facade elements of each building
1204    INTEGER(iwp) ::  i    !< index of facade-adjacent atmosphere grid point in x-direction
1205    INTEGER(iwp) ::  j    !< index of facade-adjacent atmosphere grid point in y-direction
1206    INTEGER(iwp) ::  k    !< index of facade-adjacent atmosphere grid point in z-direction
1207    INTEGER(iwp) ::  kk   !< vertical index of indoor grid point adjacent to facade
1208    INTEGER(iwp) ::  l    !< running index for surface-element orientation
1209    INTEGER(iwp) ::  m    !< running index surface elements
1210    INTEGER(iwp) ::  nb   !< running index for buildings
1211
1212    REAL(wp) ::  indoor_wall_window_temperature   !< weighted temperature of innermost wall/window layer
1213   
1214    REAL(wp) ::  indoor_wall_temperature   !< temperature of innermost wall layer evtl in im_calc_temperatures einfÃŒgen
1215   
1216    REAL(wp) ::  near_facade_temperature          !< outside air temperature 10cm away from facade
1217    REAL(wp) ::  second_of_day                    !< second of the current day
1218    REAL(wp) ::  time_utc_hour                    !< time of day (hour UTC)
1219
1220    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_l_send   !< dummy send buffer used for summing-up indoor temperature per kk-level
1221    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_recv     !< dummy recv buffer used for summing-up indoor temperature per kk-level
1222!
1223!-- Determine time of day in hours.
1224    CALL get_date_time( time_since_reference_point, second_of_day=second_of_day )
1225    time_utc_hour = second_of_day / seconds_per_hour
1226!
1227!-- Following calculations must be done for each facade element.
1228    DO  nb = 1, num_build
1229!
1230!--    First, check whether building is present on local subdomain.
1231       IF ( buildings(nb)%on_pe )  THEN
1232!
1233!--       Determine daily schedule. 08:00-18:00 = 1, other hours = 0.
1234!--       Residental Building, panel WBS 70
1235          IF ( buildings(nb)%ventilation_int_loads == 1 )  THEN
1236             IF ( time_utc_hour >= 8.0_wp  .AND.  time_utc_hour <= 18.0_wp )  THEN
1237                schedule_d = 0
1238             ELSE
1239                schedule_d = 1
1240             ENDIF
1241          ENDIF
1242!
1243!--       Office, building with large windows
1244          IF ( buildings(nb)%ventilation_int_loads == 2 )  THEN
1245             IF ( time_utc_hour >= 8.0_wp  .AND.  time_utc_hour <= 18.0_wp )  THEN
1246                schedule_d = 1
1247             ELSE
1248                schedule_d = 0
1249             ENDIF
1250          ENDIF
1251!
1252!--       Industry, hospitals
1253          IF ( buildings(nb)%ventilation_int_loads == 3 )  THEN
1254             IF ( time_utc_hour >= 6.0_wp  .AND.  time_utc_hour <= 22.0_wp )  THEN
1255                schedule_d = 1
1256             ELSE
1257                schedule_d = 0
1258             ENDIF
1259          ENDIF
1260!
1261!--       Initialize/reset indoor temperature
1262          buildings(nb)%t_in_l = 0.0_wp
1263!
1264!--       Horizontal surfaces
1265          DO  fa = 1, buildings(nb)%num_facades_per_building_h_l
1266!
1267!--          Determine indices where corresponding surface-type information is stored.
1268             l = buildings(nb)%l_h(fa)
1269             m = buildings(nb)%m_h(fa)
1270!
1271!--          Determine building height level index.
1272             kk = surf_usm_h(l)%k(m) + surf_usm_h(l)%koff
1273!
1274!--          Building geometries --> not time-dependent
1275             facade_element_area          = dx * dy                               !< [m2] surface area per facade element
1276             floor_area_per_facade        = buildings(nb)%fapf                    !< [m2/m2] floor area per facade area
1277             indoor_volume_per_facade     = buildings(nb)%vpf(kk)                 !< [m3/m2] indoor air volume per facade area
1278             buildings(nb)%area_facade    = facade_element_area *                                  &
1279                                            ( buildings(nb)%num_facades_per_building_h +           &
1280                                              buildings(nb)%num_facades_per_building_v )              !< [m2] area of total facade
1281             window_area_per_facade       = surf_usm_h(l)%frac(m,ind_wat_win)  * facade_element_area  !< [m2] window area per facade
1282                                                                                                      !< element
1283
1284             buildings(nb)%net_floor_area = buildings(nb)%vol_tot / ( buildings(nb)%height_storey )
1285             total_area                   = buildings(nb)%net_floor_area                            !< [m2] area of all surfaces
1286                                                                                                    !< pointing to zone  Eq. (9) according to section 7.2.2.2
1287             a_m                          = buildings(nb)%factor_a * total_area *                  &
1288                                            ( facade_element_area / buildings(nb)%area_facade ) *  &
1289                                            buildings(nb)%lambda_at                                 !< [m2] standard values
1290                                                                                                    !< according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
1291             c_m                          = buildings(nb)%factor_c * total_area *                  &
1292                                            ( facade_element_area / buildings(nb)%area_facade )     !< [J/K] standard values
1293                                                                                                    !< according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
1294!
1295!--          Calculation of heat transfer coefficient for transmission --> not time-dependent
1296             h_t_es   = window_area_per_facade * buildings(nb)%h_es                                   !< [W/K] only for windows
1297
1298             h_t_is  = buildings(nb)%area_facade * h_is                                               !< [W/K] with h_is = 3.45 W /
1299                                                                                                      !< (m2 K) between surface and air, Eq. (9)
1300             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W /
1301                                                                                                      !< (m2 K) between component and surface, Eq. (64)
1302             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )    &  !< [W/K]
1303                                    * buildings(nb)%lambda_layer3 / buildings(nb)%s_layer3 * 0.5_wp &
1304                                             ) + 1.0_wp / h_t_ms )                                    !< [W/K] opaque components
1305             h_t_wm  = 1.0_wp / ( 1.0_wp / h_t_wall - 1.0_wp / h_t_ms )                               !< [W/K] emmision Eq. (63),
1306                                                                                                      !< Section 12.2.2
1307!
1308!--          Internal air loads dependent on the occupacy of the room.
1309!--          Basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int).
1310             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low ) &
1311                              * floor_area_per_facade )
1312             q_int = phi_ia / total_area
1313!
1314!--          Airflow dependent on the occupacy of the room.
1315!--          Basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
1316             air_change = ( buildings(nb)%air_change_high * schedule_d + buildings(nb)%air_change_low )  !< [1/h]?
1317!
1318!--          Heat transfer of ventilation.
1319!--          Not less than 0.01 W/K to avoid division by 0 in further calculations with heat
1320!--          capacity of air 0.33 Wh/m2K.
1321             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *                      &
1322                                      0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )    !< [W/K] from ISO 13789 Eq.(10)
1323
1324!--          Heat transfer coefficient auxiliary variables
1325             h_t_1 = 1.0_wp / ( ( 1.0_wp / h_v )   + ( 1.0_wp / h_t_is ) )  !< [W/K] Eq. (C.6)
1326             h_t_2 = h_t_1 + h_t_es                                         !< [W/K] Eq. (C.7)
1327             h_t_3 = 1.0_wp / ( ( 1.0_wp / h_t_2 ) + ( 1.0_wp / h_t_ms ) )  !< [W/K] Eq. (C.8)
1328!
1329!--          Net short-wave radiation through window area (was i_global)
1330             net_sw_in = surf_usm_h(l)%rad_sw_in(m) - surf_usm_h(l)%rad_sw_out(m)
1331!
1332!--          Quantities needed for im_calc_temperatures
1333             i = surf_usm_h(l)%i(m)
1334             j = surf_usm_h(l)%j(m)
1335             k = surf_usm_h(l)%k(m)
1336             near_facade_temperature = surf_usm_h(l)%pt_10cm(m)
1337             indoor_wall_window_temperature =                                                             &
1338                                            surf_usm_h(l)%frac(m,ind_veg_wall) * t_wall_h(l)%val(nzt_wall,m) &
1339                                          + surf_usm_h(l)%frac(m,ind_wat_win)  * t_window_h(l)%val(nzt_wall,m)
1340             indoor_wall_temperature = surf_usm_h(l)%frac(m,ind_veg_wall) * t_wall_h(l)%val(nzt_wall,m)
1341!
1342!--          Solar thermal gains. If net_sw_in larger than sun-protection threshold parameter
1343!--          (params_solar_protection), sun protection will be activated.
1344             IF ( net_sw_in <= params_solar_protection )  THEN
1345                solar_protection_off = 1
1346                solar_protection_on  = 0
1347             ELSE
1348                solar_protection_off = 0
1349                solar_protection_on  = 1
1350             ENDIF
1351!
1352!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on
1353!--          automatic sun protection.
1354!--          DIN 4108 - 2 chap.8
1355             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
1356                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win *            &
1357                           solar_protection_on )                                                   &
1358                       * buildings(nb)%g_value_win * ( 1.0_wp - params_f_f ) * params_f_w
1359             q_sol = phi_sol
1360!
1361!--          Calculation of the mass specific thermal load for internal and external heatsources of
1362!--          the inner node.
1363             phi_m   = (a_m / total_area) * ( phi_ia + phi_sol )                                    !< [W] Eq. (C.2) with
1364                                                                                                    !< phi_ia=0,5*phi_int
1365             q_c_m = phi_m
1366!
1367!--          Calculation mass specific thermal load implied non thermal mass
1368             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) )  &
1369                       * ( phi_ia + phi_sol )                                                       !< [W] Eq. (C.3) with
1370                                                                                                    !< phi_ia=0,5*phi_int
1371             q_c_st = phi_st
1372!
1373!--          Calculations for deriving indoor temperature and heat flux into the wall
1374!--          Step 1: indoor temperature without heating and cooling
1375!--          section C.4.1 Picture C.2 zone 3)
1376             phi_hc_nd = 0.0_wp
1377
1378             CALL  im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1379                                          near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_h(fa) )
1380!
1381!--          If air temperature between border temperatures of heating and cooling, assign output
1382!--          variable, then ready.
1383             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.                                &
1384                  theta_air <= buildings(nb)%theta_int_c_set )  THEN
1385                phi_hc_nd_ac = 0.0_wp
1386                phi_hc_nd    = phi_hc_nd_ac
1387                theta_air_ac = theta_air
1388!
1389!--          Step 2: Else, apply 10 W/m2 heating/cooling power and calculate indoor temperature
1390!--          again.
1391             ELSE
1392!
1393!--             Temperature not correct, calculation method according to section C4.2
1394                theta_air_0 = theta_air                                                  !< temperature without heating/cooling
1395!
1396!--             Heating or cooling?
1397                IF ( theta_air_0 > buildings(nb)%theta_int_c_set )  THEN
1398                   theta_air_set = buildings(nb)%theta_int_c_set
1399                ELSE
1400                   theta_air_set = buildings(nb)%theta_int_h_set
1401                ENDIF
1402!
1403!--             Calculate the temperature with phi_hc_nd_10
1404                phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
1405                phi_hc_nd    = phi_hc_nd_10
1406
1407                CALL  im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1408                                             near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_h(fa) )
1409                theta_air_10 = theta_air                                                !< temperature with 10 W/m2 of heating
1410                phi_hc_nd_un = phi_hc_nd_10 * (theta_air_set - theta_air_0)                        &
1411                                            / (theta_air_10  - theta_air_0)             !< Eq. (C.13)
1412!
1413!--             Step 3: with temperature ratio to determine the heating or cooling capacity.
1414!--             If necessary, limit the power to maximum power.
1415!--             section C.4.1 Picture C.2 zone 2) and 4)
1416                buildings(nb)%phi_c_max = buildings(nb)%q_c_max * floor_area_per_facade
1417                buildings(nb)%phi_h_max = buildings(nb)%q_h_max * floor_area_per_facade
1418                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.                                 &
1419                     phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
1420                   phi_hc_nd_ac = phi_hc_nd_un
1421                   phi_hc_nd = phi_hc_nd_un
1422                ELSE
1423!
1424!--             Step 4: inner temperature with maximum heating (phi_hc_nd_un positive) or cooling
1425!--                     (phi_hc_nd_un negative)
1426!--             section C.4.1 Picture C.2 zone 1) and 5)
1427                   IF ( phi_hc_nd_un > 0.0_wp )  THEN
1428                      phi_hc_nd_ac = buildings(nb)%phi_h_max                            !< Limit heating
1429                   ELSE
1430                      phi_hc_nd_ac = buildings(nb)%phi_c_max                            !< Limit cooling
1431                   ENDIF
1432                ENDIF
1433                phi_hc_nd = phi_hc_nd_ac
1434!
1435!--             Calculate the temperature with phi_hc_nd_ac (new)
1436                CALL  im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1437                                             near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_h(fa) )
1438                theta_air_ac = theta_air
1439             ENDIF
1440!
1441!--          Update theta_m_t_prev
1442             buildings(nb)%theta_m_t_prev_h(fa) = theta_m_t
1443
1444
1445             q_vent = h_v * ( theta_air - near_facade_temperature )
1446!
1447!--          Calculate the operating temperature with weighted mean temperature of air and mean
1448!--          solar temperature.
1449!--          Will be used for thermal comfort calculations.
1450             theta_op     = 0.3_wp * theta_air_ac + 0.7_wp * theta_s          !< [degree_C] operative Temperature Eq. (C.12)
1451
1452!              surf_usm_h(l)%t_indoor(m) = theta_op                               !< not integrated now
1453!
1454!--          Heat flux into the wall. Value needed in urban_surface_mod to
1455!--          calculate heat transfer through wall layers towards the facade
1456!--          (use c_p * rho_surface to convert [W/m2] into [K m/s])
1457             IF ( (facade_element_area - window_area_per_facade) > 0.0_wp )  THEN
1458                q_wall = h_t_wm * ( indoor_wall_temperature - theta_m )                 &
1459                                    / ( facade_element_area - window_area_per_facade )
1460             ELSE
1461                q_wall = 0.0_wp
1462             ENDIF
1463
1464             IF ( window_area_per_facade > 0.0_wp )  THEN
1465                q_win = h_t_es * ( pt(k,j,i) - theta_s ) / ( window_area_per_facade )
1466             ELSE
1467                q_win = 0.0_wp
1468             ENDIF
1469!
1470!--          Transfer q_wall & q_win back to USM (innermost wall/window layer)
1471             surf_usm_h(l)%iwghf_eb(m)        = - q_wall
1472             surf_usm_h(l)%iwghf_eb_window(m) = - q_win
1473!
1474!--          Sum up operational indoor temperature per kk-level. Further below, this temperature is
1475!--          reduced by MPI to one temperature per kk-level and building (processor overlapping).
1476             buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
1477!
1478!--          Calculation of waste heat.
1479!--          Anthropogenic heat output.
1480             IF ( phi_hc_nd_ac > 0.0_wp )  THEN
1481                heating_on = 1
1482                cooling_on = 0
1483             ELSE
1484                heating_on = 0
1485                cooling_on = -1
1486             ENDIF
1487
1488             q_waste_heat = ( phi_hc_nd * (                                                        &
1489                              buildings(nb)%params_waste_heat_h * heating_on +                     &
1490                              buildings(nb)%params_waste_heat_c * cooling_on )                     &
1491                            ) / facade_element_area                                             !< [W/m2] , observe the directional
1492                                                                                                !< convention in PALM!
1493             surf_usm_h(l)%waste_heat(m) = q_waste_heat
1494          ENDDO !< Horizontal surfaces loop
1495!
1496!--       Vertical surfaces
1497          DO  fa = 1, buildings(nb)%num_facades_per_building_v_l
1498!
1499!--          Determine indices where corresponding surface-type information is stored.
1500             l = buildings(nb)%l_v(fa)
1501             m = buildings(nb)%m_v(fa)
1502!
1503!--          Determine building height level index.
1504             kk = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
1505!
1506!--          (SOME OF THE FOLLOWING (not time-dependent) COULD PROBABLY GO INTO A FUNCTION
1507!--          EXCEPT facade_element_area, EVERYTHING IS CALCULATED EQUALLY)
1508!--          Building geometries  --> not time-dependent
1509             IF ( l == 0  .OR. l == 1 ) facade_element_area = dx * dzw(kk+1)    !< [m2] surface area per facade element
1510             IF ( l == 2  .OR. l == 3 ) facade_element_area = dy * dzw(kk+1)    !< [m2] surface area per facade element
1511
1512             floor_area_per_facade        = buildings(nb)%fapf                  !< [m2/m2] floor area per facade area
1513             indoor_volume_per_facade     = buildings(nb)%vpf(kk)               !< [m3/m2] indoor air volume per facade area
1514             buildings(nb)%area_facade    = facade_element_area *                                  &
1515                                            ( buildings(nb)%num_facades_per_building_h +           &
1516                                              buildings(nb)%num_facades_per_building_v )              !< [m2] area of total facade
1517             window_area_per_facade       = surf_usm_v(l)%frac(m,ind_wat_win) * facade_element_area   !< [m2] window area per
1518                                                                                                      !< facade element
1519
1520             buildings(nb)%net_floor_area = buildings(nb)%vol_tot / ( buildings(nb)%height_storey )
1521             total_area                   = buildings(nb)%net_floor_area                              !< [m2] area of all surfaces
1522                                                                                                      !< pointing to zone  Eq. (9) according to section 7.2.2.2
1523             a_m                          = buildings(nb)%factor_a * total_area *                  &
1524                                            ( facade_element_area / buildings(nb)%area_facade ) *  &
1525                                              buildings(nb)%lambda_at                                 !< [m2] standard values
1526                                                                                                      !< according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
1527             c_m                          = buildings(nb)%factor_c * total_area *                   &
1528                                            ( facade_element_area / buildings(nb)%area_facade )       !< [J/K] standard values
1529                                                                                                      !< according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
1530!
1531!--          Calculation of heat transfer coefficient for transmission --> not time-dependent
1532             h_t_es   = window_area_per_facade * buildings(nb)%h_es                                   !< [W/K] only for windows
1533
1534             h_t_is  = buildings(nb)%area_facade  * h_is                                              !< [W/K] with h_is = 3.45 W /
1535                                                                                                      !< (m2 K) between surface and air, Eq. (9)
1536             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W /
1537                                                                                                      !< (m2 K) between component and surface, Eq. (64)
1538             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )    &  !< [W/K]
1539                                    * buildings(nb)%lambda_layer3 / buildings(nb)%s_layer3 * 0.5_wp &
1540                                             ) + 1.0_wp / h_t_ms )                                    !< [W/K] opaque components
1541             h_t_wm  = 1.0_wp / ( 1.0_wp / h_t_wall - 1.0_wp / h_t_ms )                               !< [W/K] emmision Eq. (63), Section 12.2.2
1542!
1543!--          Internal air loads dependent on the occupacy of the room.
1544!--          Basical internal heat gains (qint_low) with additional internal heat gains by occupancy
1545!--          (qint_high) (0,5*phi_int)
1546             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low ) &
1547                             * floor_area_per_facade )
1548             q_int = phi_ia
1549
1550!
1551!--          Airflow dependent on the occupacy of the room.
1552!--          Basical airflow (air_change_low) with additional airflow gains by occupancy
1553!--          (air_change_high)
1554             air_change = ( buildings(nb)%air_change_high * schedule_d +                           &
1555                          buildings(nb)%air_change_low )
1556!
1557!--          Heat transfer of ventilation.
1558!--          Not less than 0.01 W/K to avoid division by 0 in further calculations with heat
1559!--          capacity of air 0.33 Wh/m2K
1560             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *                      &
1561                                    0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )                    !< [W/K] from ISO 13789
1562                                                                                                      !< Eq.(10)
1563
1564!--          Heat transfer coefficient auxiliary variables
1565             h_t_1 = 1.0_wp / ( ( 1.0_wp / h_v )   + ( 1.0_wp / h_t_is ) )                            !< [W/K] Eq. (C.6)
1566             h_t_2 = h_t_1 + h_t_es                                                                   !< [W/K] Eq. (C.7)
1567             h_t_3 = 1.0_wp / ( ( 1.0_wp / h_t_2 ) + ( 1.0_wp / h_t_ms ) )                            !< [W/K] Eq. (C.8)
1568!
1569!--          Net short-wave radiation through window area (was i_global)
1570             net_sw_in = surf_usm_v(l)%rad_sw_in(m) - surf_usm_v(l)%rad_sw_out(m)
1571!
1572!--          Quantities needed for im_calc_temperatures
1573             i = surf_usm_v(l)%i(m)
1574             j = surf_usm_v(l)%j(m)
1575             k = surf_usm_v(l)%k(m)
1576             near_facade_temperature = surf_usm_v(l)%pt_10cm(m)
1577             indoor_wall_window_temperature =                                                          &
1578                                    surf_usm_v(l)%frac(m,ind_veg_wall) * t_wall_v(l)%val(nzt_wall,m)   &
1579                                  + surf_usm_v(l)%frac(m,ind_wat_win)  * t_window_v(l)%val(nzt_wall,m)
1580             indoor_wall_temperature = surf_usm_v(l)%frac(m,ind_veg_wall) * t_wall_v(l)%val(nzt_wall,m) 
1581
1582!
1583!--          Solar thermal gains. If net_sw_in larger than sun-protection
1584!--          threshold parameter (params_solar_protection), sun protection will
1585!--          be activated
1586             IF ( net_sw_in <= params_solar_protection )  THEN
1587                solar_protection_off = 1
1588                solar_protection_on  = 0
1589             ELSE
1590                solar_protection_off = 0
1591                solar_protection_on  = 1
1592             ENDIF
1593!
1594!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on
1595!--          automatic sun protection.
1596!--          DIN 4108 - 2 chap.8
1597             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
1598                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win *            &
1599                           solar_protection_on )                                                   &
1600                       * buildings(nb)%g_value_win * ( 1.0_wp - params_f_f ) * params_f_w
1601             q_sol = phi_sol
1602!
1603!--          Calculation of the mass specific thermal load for internal and external heatsources.
1604             phi_m   = (a_m / total_area) * ( phi_ia + phi_sol )          !< [W] Eq. (C.2) with phi_ia=0,5*phi_int
1605             q_c_m = phi_m
1606!
1607!--          Calculation mass specific thermal load implied non thermal mass.
1608             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) )  &
1609                       * ( phi_ia + phi_sol )                                                       !< [W] Eq. (C.3) with
1610                                                                                                    !< phi_ia=0,5*phi_int
1611             q_c_st = phi_st
1612!
1613!--          Calculations for deriving indoor temperature and heat flux into the wall.
1614!--          Step 1: indoor temperature without heating and cooling.
1615!--          section C.4.1 Picture C.2 zone 3)
1616             phi_hc_nd = 0.0_wp
1617             CALL im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1618                                         near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_v(fa) )
1619!
1620!--          If air temperature between border temperatures of heating and cooling, assign output
1621!--          variable, then ready.
1622             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.                                &
1623                  theta_air <= buildings(nb)%theta_int_c_set )  THEN
1624                phi_hc_nd_ac = 0.0_wp
1625                phi_hc_nd    = phi_hc_nd_ac
1626                theta_air_ac = theta_air
1627!
1628!--          Step 2: Else, apply 10 W/m2 heating/cooling power and calculate indoor temperature
1629!--          again.
1630             ELSE
1631!
1632!--             Temperature not correct, calculation method according to section C4.2
1633                theta_air_0 = theta_air !< Note temperature without heating/cooling
1634!
1635!--             Heating or cooling?
1636                IF ( theta_air_0 > buildings(nb)%theta_int_c_set )  THEN
1637                   theta_air_set = buildings(nb)%theta_int_c_set
1638                ELSE
1639                   theta_air_set = buildings(nb)%theta_int_h_set
1640                ENDIF
1641
1642!--             Calculate the temperature with phi_hc_nd_10
1643                phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
1644                phi_hc_nd    = phi_hc_nd_10
1645
1646                CALL  im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1647                                             near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_v(fa) )
1648
1649                theta_air_10 = theta_air !< Note the temperature with 10 W/m2 of heating
1650
1651                phi_hc_nd_un = phi_hc_nd_10 * ( theta_air_set - theta_air_0 )                      &
1652                                            / ( theta_air_10  - theta_air_0 )            !< Eq. (C.13)
1653!
1654!--             Step 3: with temperature ratio to determine the heating or cooling capacity
1655!--             If necessary, limit the power to maximum power.
1656!--             section C.4.1 Picture C.2 zone 2) and 4)
1657                buildings(nb)%phi_c_max = buildings(nb)%q_c_max * floor_area_per_facade
1658                buildings(nb)%phi_h_max = buildings(nb)%q_h_max * floor_area_per_facade
1659                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.                                 &
1660                     phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
1661                   phi_hc_nd_ac = phi_hc_nd_un
1662                   phi_hc_nd = phi_hc_nd_un
1663                ELSE
1664!
1665!--             Step 4: inner temperature with maximum heating (phi_hc_nd_un positive) or cooling
1666!--                     (phi_hc_nd_un negative)
1667!--             section C.4.1 Picture C.2 zone 1) and 5)
1668                   IF ( phi_hc_nd_un > 0.0_wp )  THEN
1669                      phi_hc_nd_ac = buildings(nb)%phi_h_max                                         !< Limit heating
1670                   ELSE
1671                      phi_hc_nd_ac = buildings(nb)%phi_c_max                                         !< Limit cooling
1672                   ENDIF
1673                ENDIF
1674                phi_hc_nd = phi_hc_nd_ac
1675!
1676!--             Calculate the temperature with phi_hc_nd_ac (new)
1677                CALL  im_calc_temperatures ( i, j, k, indoor_wall_temperature, &
1678                                             near_facade_temperature, phi_hc_nd, buildings(nb)%theta_m_t_prev_v(fa) )
1679                theta_air_ac = theta_air
1680             ENDIF
1681!
1682!--          Update theta_m_t_prev
1683             buildings(nb)%theta_m_t_prev_v(fa) = theta_m_t
1684
1685
1686             q_vent = h_v * ( theta_air - near_facade_temperature )
1687!
1688!--          Calculate the operating temperature with weighted mean of temperature of air and mean.
1689!--          Will be used for thermal comfort calculations.
1690             theta_op     = 0.3_wp * theta_air_ac + 0.7_wp * theta_s
1691
1692!              surf_usm_v(l)%t_indoor(m) = theta_op                  !< not integrated yet
1693!
1694!--          Heat flux into the wall. Value needed in urban_surface_mod to
1695!--          calculate heat transfer through wall layers towards the facade
1696             IF ( (facade_element_area - window_area_per_facade) > 0.0_wp )  THEN
1697                q_wall = h_t_wm * ( indoor_wall_temperature - theta_m )                 &
1698                                    / ( facade_element_area - window_area_per_facade )
1699             ELSE
1700                q_wall = 0.0_wp
1701             ENDIF
1702
1703             IF ( window_area_per_facade > 0.0_wp )  THEN
1704                q_win = h_t_es * ( pt(k,j,i) - theta_s ) / ( window_area_per_facade )
1705             ELSE
1706                q_win = 0.0_wp
1707             ENDIF
1708
1709!
1710!--          Transfer q_wall & q_win back to USM (innermost wall/window layer)
1711             surf_usm_v(l)%iwghf_eb(m)        = - q_wall
1712             surf_usm_v(l)%iwghf_eb_window(m) = - q_win
1713!
1714!--          Sum up operational indoor temperature per kk-level. Further below, this temperature is
1715!--          reduced by MPI to one temperature per kk-level and building (processor overlapping).
1716             buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
1717!
1718!--          Calculation of waste heat.
1719!--          Anthropogenic heat output.
1720             IF ( phi_hc_nd_ac > 0.0_wp )  THEN
1721                heating_on = 1
1722                cooling_on = 0
1723             ELSE
1724                heating_on = 0
1725                cooling_on = -1
1726             ENDIF
1727
1728             q_waste_heat = ( phi_hc_nd * ( buildings(nb)%params_waste_heat_h * heating_on +       &
1729                                            buildings(nb)%params_waste_heat_c * cooling_on )       &
1730                                                    ) / facade_element_area  !< [W/m2] , observe the directional convention in
1731                                                                             !< PALM!
1732             surf_usm_v(l)%waste_heat(m) = q_waste_heat
1733          ENDDO !< Vertical surfaces loop
1734       ENDIF !< buildings(nb)%on_pe
1735    ENDDO !< buildings loop
1736
1737!
1738!-- Determine the mean building temperature.
1739    DO  nb = 1, num_build
1740!
1741!--    Allocate dummy array used for summing-up facade elements.
1742!--    Please note, dummy arguments are necessary as building-date type arrays are not necessarily
1743!--    allocated on all PEs.
1744       ALLOCATE( t_in_l_send(buildings(nb)%kb_min:buildings(nb)%kb_max) )
1745       ALLOCATE( t_in_recv(buildings(nb)%kb_min:buildings(nb)%kb_max) )
1746       t_in_l_send = 0.0_wp
1747       t_in_recv   = 0.0_wp
1748
1749       IF ( buildings(nb)%on_pe )  THEN
1750          t_in_l_send = buildings(nb)%t_in_l
1751       ENDIF
1752
1753
1754#if defined( __parallel )
1755       CALL MPI_ALLREDUCE( t_in_l_send,                                                            &
1756                           t_in_recv,                                                              &
1757                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
1758                           MPI_REAL,                                                               &
1759                           MPI_SUM,                                                                &
1760                           comm2d,                                                                 &
1761                           ierr )
1762
1763       IF ( ALLOCATED( buildings(nb)%t_in ) )  buildings(nb)%t_in = t_in_recv
1764#else
1765       IF ( ALLOCATED( buildings(nb)%t_in ) )  buildings(nb)%t_in = buildings(nb)%t_in_l
1766#endif
1767
1768       IF ( ALLOCATED( buildings(nb)%t_in ) )  THEN
1769!
1770!--       Average indoor temperature. Note, in case a building is completely surrounded by higher
1771!--       buildings, it may have no facade elements at some height levels, which will lead to a
1772!--       division by zero.
1773          DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
1774             IF ( buildings(nb)%num_facade_h(k) + buildings(nb)%num_facade_v(k) > 0 )  THEN
1775                buildings(nb)%t_in(k) = buildings(nb)%t_in(k) /                                    &
1776                                        REAL( buildings(nb)%num_facade_h(k) +                      &
1777                                              buildings(nb)%num_facade_v(k), KIND = wp )
1778             ENDIF
1779          ENDDO
1780!
1781!--       If indoor temperature is not defined because of missing facade elements, the values from
1782!--       the above-lying level will be taken.
1783!--       At least at the top of the buildings facades are defined, so that at least there an indoor
1784!--       temperature is defined. This information will propagate downwards the building.
1785          DO  k = buildings(nb)%kb_max-1, buildings(nb)%kb_min, -1
1786             IF ( buildings(nb)%num_facade_h(k) + buildings(nb)%num_facade_v(k) <= 0 )  THEN
1787                buildings(nb)%t_in(k) = buildings(nb)%t_in(k+1)
1788             ENDIF
1789          ENDDO
1790       ENDIF
1791
1792
1793!
1794!--    Deallocate dummy arrays
1795       DEALLOCATE( t_in_l_send )
1796       DEALLOCATE( t_in_recv )
1797
1798    ENDDO
1799
1800 END SUBROUTINE im_main_heatcool
1801
1802
1803!--------------------------------------------------------------------------------------------------!
1804! Description:
1805!-------------
1806!> Check data output for plant canopy model
1807!--------------------------------------------------------------------------------------------------!
1808 SUBROUTINE im_check_data_output( var, unit )
1809
1810    CHARACTER (LEN=*) ::  unit   !<
1811    CHARACTER (LEN=*) ::  var    !<
1812
1813    SELECT CASE ( TRIM( var ) )
1814
1815
1816        CASE ( 'im_hf_roof')
1817           unit = 'W m-2'
1818
1819        CASE ( 'im_hf_wall_win' )
1820           unit = 'W m-2'
1821
1822        CASE ( 'im_hf_wall_win_waste' )
1823           unit = 'W m-2'
1824
1825        CASE ( 'im_hf_roof_waste' )
1826           unit = 'W m-2'
1827
1828        CASE ( 'im_t_indoor_mean' )
1829           unit = 'K'
1830
1831        CASE ( 'im_t_indoor_roof' )
1832           unit = 'K'
1833
1834        CASE ( 'im_t_indoor_wall_win' )
1835           unit = 'K'
1836           
1837        CASE ( 'im_t_indoor_wall' )
1838           unit = 'K'
1839
1840        CASE DEFAULT
1841           unit = 'illegal'
1842
1843    END SELECT
1844
1845 END SUBROUTINE
1846
1847
1848!--------------------------------------------------------------------------------------------------!
1849! Description:
1850!-------------
1851!> Check parameters routine for plant canopy model
1852!--------------------------------------------------------------------------------------------------!
1853 SUBROUTINE im_check_parameters
1854
1855!   USE control_parameters,
1856!       ONLY: message_string
1857
1858 END SUBROUTINE im_check_parameters
1859
1860
1861!--------------------------------------------------------------------------------------------------!
1862! Description:
1863!-------------
1864!> Subroutine defining appropriate grid for netcdf variables.
1865!> It is called from subroutine netcdf.
1866!--------------------------------------------------------------------------------------------------!
1867 SUBROUTINE im_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
1868
1869    CHARACTER (LEN=*), INTENT(OUT) ::  grid_x
1870    CHARACTER (LEN=*), INTENT(OUT) ::  grid_y
1871    CHARACTER (LEN=*), INTENT(OUT) ::  grid_z
1872    CHARACTER (LEN=*), INTENT(IN)  ::  var
1873
1874    LOGICAL, INTENT(OUT)           ::  found
1875
1876
1877    found   = .TRUE.
1878!
1879!-- Check for the grid
1880    SELECT CASE ( TRIM( var ) )
1881
1882       CASE ( 'im_hf_roof', 'im_hf_roof_waste' )
1883          grid_x = 'x'
1884          grid_y = 'y'
1885          grid_z = 'zw'
1886!
1887!--    Heat fluxes at vertical walls are actually defined on stagged grid, i.e. xu, yv.
1888       CASE ( 'im_hf_wall_win', 'im_hf_wall_win_waste' )
1889          grid_x = 'x'
1890          grid_y = 'y'
1891          grid_z = 'zu'
1892
1893       CASE ( 'im_t_indoor_mean', 'im_t_indoor_roof', 'im_t_indoor_wall_win', 'indoor_wall' )
1894          grid_x = 'x'
1895          grid_y = 'y'
1896          grid_z = 'zw'
1897
1898       CASE DEFAULT
1899          found  = .FALSE.
1900          grid_x = 'none'
1901          grid_y = 'none'
1902          grid_z = 'none'
1903    END SELECT
1904
1905 END SUBROUTINE im_define_netcdf_grid
1906
1907
1908!--------------------------------------------------------------------------------------------------!
1909! Description:
1910! ------------
1911!> Subroutine defining 3D output variables
1912!--------------------------------------------------------------------------------------------------!
1913 SUBROUTINE im_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
1914
1915    USE indices
1916
1917    USE kinds
1918
1919    CHARACTER (LEN=*) ::  variable !<
1920
1921    INTEGER(iwp) ::  av    !<
1922    INTEGER(iwp) ::  i     !<
1923    INTEGER(iwp) ::  j     !<
1924    INTEGER(iwp) ::  k     !<
1925    INTEGER(iwp) ::  l     !<
1926    INTEGER(iwp) ::  m     !<
1927    INTEGER(iwp) ::  nb    !< index of the building in the building data structure
1928    INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
1929    INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
1930
1931    LOGICAL      ::  found !<
1932
1933    REAL(wp), INTENT(IN) ::  fill_value !< value for the _FillValue attribute
1934
1935    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
1936
1937    local_pf = fill_value
1938
1939    found = .TRUE.
1940
1941    SELECT CASE ( TRIM( variable ) )
1942!
1943!--     Output of indoor temperature. All grid points within the building are filled with values,
1944!--     while atmospheric grid points are set to _FillValues.
1945        CASE ( 'im_t_indoor_mean' )
1946           IF ( av == 0 ) THEN
1947              DO  i = nxl, nxr
1948                 DO  j = nys, nyn
1949                    IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
1950!
1951!--                    Determine index of the building within the building data structure.
1952                       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
1953                       IF ( buildings(nb)%on_pe )  THEN
1954!
1955!--                       Write mean building temperature onto output array. Please note, in
1956!--                       contrast to many other loops in the output, the vertical bounds are
1957!--                       determined by the lowest and hightest vertical index occupied by the
1958!--                       building.
1959                          DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
1960                             local_pf(i,j,k) = buildings(nb)%t_in(k)
1961                          ENDDO
1962                       ENDIF
1963                    ENDIF
1964                 ENDDO
1965              ENDDO
1966           ENDIF
1967
1968        CASE ( 'im_hf_roof' )
1969           IF ( av == 0 )  THEN
1970              DO  m = 1, surf_usm_h(0)%ns
1971                 i = surf_usm_h(0)%i(m) !+ surf_usm_h%ioff
1972                 j = surf_usm_h(0)%j(m) !+ surf_usm_h%joff
1973                 k = surf_usm_h(0)%k(m) !+ surf_usm_h%koff
1974                 local_pf(i,j,k) = surf_usm_h(0)%iwghf_eb(m)
1975              ENDDO
1976           ENDIF
1977
1978        CASE ( 'im_hf_roof_waste' )
1979           IF ( av == 0 )  THEN
1980              DO m = 1, surf_usm_h(0)%ns
1981                 i = surf_usm_h(0)%i(m) !+ surf_usm_h%ioff
1982                 j = surf_usm_h(0)%j(m) !+ surf_usm_h%joff
1983                 k = surf_usm_h(0)%k(m) !+ surf_usm_h%koff
1984                 local_pf(i,j,k) = surf_usm_h(0)%waste_heat(m)
1985              ENDDO
1986           ENDIF
1987
1988       CASE ( 'im_hf_wall_win' )
1989           IF ( av == 0 )  THEN
1990              DO l = 0, 3
1991                 DO m = 1, surf_usm_v(l)%ns
1992                    i = surf_usm_v(l)%i(m) !+ surf_usm_v(l)%ioff
1993                    j = surf_usm_v(l)%j(m) !+ surf_usm_v(l)%joff
1994                    k = surf_usm_v(l)%k(m) !+ surf_usm_v(l)%koff
1995                    local_pf(i,j,k) = surf_usm_v(l)%iwghf_eb(m)
1996                 ENDDO
1997              ENDDO
1998           ENDIF
1999
2000        CASE ( 'im_hf_wall_win_waste' )
2001           IF ( av == 0 )  THEN
2002              DO l = 0, 3
2003                 DO m = 1, surf_usm_v(l)%ns
2004                    i = surf_usm_v(l)%i(m) !+ surf_usm_v(l)%ioff
2005                    j = surf_usm_v(l)%j(m) !+ surf_usm_v(l)%joff
2006                    k = surf_usm_v(l)%k(m) !+ surf_usm_v(l)%koff
2007                    local_pf(i,j,k) =  surf_usm_v(l)%waste_heat(m)
2008                 ENDDO
2009              ENDDO
2010           ENDIF
2011
2012!
2013!< NOTE im_t_indoor_roof and im_t_indoor_wall_win not work yet
2014
2015!         CASE ( 'im_t_indoor_roof' )
2016!            IF ( av == 0 )  THEN
2017!               DO  m = 1, surf_usm_h%ns
2018!                   i = surf_usm_h%i(m) !+ surf_usm_h%ioff
2019!                   j = surf_usm_h%j(m) !+ surf_usm_h%joff
2020!                   k = surf_usm_h%k(m) !+ surf_usm_h%koff
2021!                   local_pf(i,j,k) = surf_usm_h%t_indoor(m)
2022!               ENDDO
2023!            ENDIF
2024!
2025!         CASE ( 'im_t_indoor_wall_win' )
2026!            IF ( av == 0 )  THEN
2027!               DO l = 0, 3
2028!                  DO m = 1, surf_usm_v(l)%ns
2029!                     i = surf_usm_v(l)%i(m) !+ surf_usm_v(l)%ioff
2030!                     j = surf_usm_v(l)%j(m) !+ surf_usm_v(l)%joff
2031!                     k = surf_usm_v(l)%k(m) !+ surf_usm_v(l)%koff
2032!                     local_pf(i,j,k) = surf_usm_v(l)%t_indoor(m)
2033!                  ENDDO
2034!               ENDDO
2035!            ENDIF
2036
2037        CASE DEFAULT
2038           found = .FALSE.
2039
2040    END SELECT
2041
2042 END SUBROUTINE im_data_output_3d
2043
2044
2045!--------------------------------------------------------------------------------------------------!
2046! Description:
2047! ------------
2048!> Parin for &indoor_parameters for indoor model
2049!--------------------------------------------------------------------------------------------------!
2050 SUBROUTINE im_parin
2051
2052    USE control_parameters,                                                                        &
2053        ONLY:  indoor_model
2054
2055
2056    CHARACTER (LEN=80) ::  line  !< string containing current line of file PARIN
2057
2058    NAMELIST /indoor_parameters/  initial_indoor_temperature
2059
2060
2061!
2062!-- Try to find indoor model package
2063    REWIND ( 11 )
2064    line = ' '
2065    DO  WHILE ( INDEX( line, '&indoor_parameters' ) == 0 )
2066       READ ( 11, '(A)', END=10 )  line
2067    ENDDO
2068    BACKSPACE ( 11 )
2069
2070!
2071!-- Read user-defined namelist
2072    READ ( 11, indoor_parameters )
2073!
2074!-- Set flag that indicates that the indoor model is switched on
2075    indoor_model = .TRUE.
2076
2077!
2078!--    Activate spinup (maybe later
2079!        IF ( spinup_time > 0.0_wp )  THEN
2080!           coupling_start_time = spinup_time
2081!           end_time = end_time + spinup_time
2082!           IF ( spinup_pt_mean == 9999999.9_wp )  THEN
2083!              spinup_pt_mean = pt_surface
2084!           ENDIF
2085!           spinup = .TRUE.
2086!        ENDIF
2087
2088 10 CONTINUE
2089
2090 END SUBROUTINE im_parin
2091
2092
2093END MODULE indoor_model_mod
Note: See TracBrowser for help on using the repository browser.