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

Last change on this file since 4243 was 4242, checked in by suehring, 5 years ago

Bugfixes in indoor model and in chemical emissions

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