LCOV - code coverage report
Current view: top level - mHM - mo_startup.f90 (source / functions) Hit Total Coverage
Test: mHM coverage Lines: 26 30 86.7 %
Date: 2024-04-15 17:48:09 Functions: 2 2 100.0 %

          Line data    Source code
       1             : !> \file mo_startup.f90
       2             : !> \brief \copybrief mo_startup
       3             : !> \details \copydetails mo_startup
       4             : 
       5             : !> \brief Startup procedures for mHM.
       6             : !> \details This module initializes all variables required to run mHM. This
       7             : !> module needs to be run only one time at the beginning of a simulation if
       8             : !> re-starting files do not exist.
       9             : !> \authors Luis Samaniego, Rohini Kumar
      10             : !> \date Dec 2012
      11             : !> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
      12             : !! mHM is released under the LGPLv3+ license \license_note
      13             : !> \ingroup f_mhm
      14             : MODULE mo_startup
      15             : 
      16             :   USE mo_kind, ONLY : i4, dp
      17             :   use mo_message, only: message, error_message
      18             : 
      19             :   IMPLICIT NONE
      20             : 
      21             :   PRIVATE
      22             : 
      23             :   PUBLIC :: mhm_initialize        ! initialization sequence
      24             : 
      25             : CONTAINS
      26             : 
      27             : 
      28             :   !> \brief Initialize main mHM variables
      29             :   !> \details Initialize main mHM variables for a given domain.
      30             :   !! Calls the following procedures in this order:
      31             :   !! - Constant initialization.
      32             :   !! - Generate soil database.
      33             :   !! - Checking inconsistencies input fields.
      34             :   !! - Variable initialization at level-0.
      35             :   !! - Variable initialization at level-1.
      36             :   !! - Variable initialization at level-11.
      37             :   !! - Space allocation of remaining variable/parameters.
      38             :   !! Global variables will be used at this stage.
      39             :   !> \changelog
      40             :   !! - Luis Samaniego Mar 2008
      41             :   !!   - fully distributed multilayer
      42             :   !! - Rohini Kumar   Oct 2010
      43             :   !!   - matrix to vector version
      44             :   !!   - openmp parallelization
      45             :   !!   - routing level 11
      46             :   !! - Luis Samaniego Jul 2012
      47             :   !!   - removal of IMSL dependencies
      48             :   !! - Luis Samaniego Dec 2012
      49             :   !!   - modular version
      50             :   !! - Rohini Kumar   May 2013
      51             :   !!   - code cleaned and error checks
      52             :   !! - Rohini Kumar   Nov 2013
      53             :   !!   - updated documentation
      54             :   !! - Stephan Thober Jun 2014
      55             :   !!   - copied L2 initialization from mo_meteo_forcings
      56             :   !! - Stephan Thober Jun 2014
      57             :   !!   - updated flag for read_restart
      58             :   !! - Stephan Thober Aug 2015
      59             :   !!   - removed initialisation of routing
      60             :   !! - Rohini Kumar   Mar 2016
      61             :   !!   - changes for handling multiple soil database options
      62             :   !! - Robert Schweppe Jun 2018
      63             :   !!   - refactoring and reformatting
      64             :   !! - Sebastian Müller Mar 2023
      65             :   !!   - added separate read_nLAI_and_check_dims to correctly read nLAI from restart
      66             :   !> \authors Luis Samaniego, Rohini Kumar
      67             :   !> \date Dec 2012
      68          28 :   subroutine mhm_initialize
      69             : 
      70             :     use mo_common_mHM_mRM_variables, only : mhmFileRestartIn, read_restart
      71             :     use mo_common_restart, only : read_grid_info, read_nLAI_and_check_dims
      72             :     use mo_common_variables, only : level0, level1, domainMeta
      73             :     use mo_grid, only : set_domain_indices
      74             :     use mo_init_states, only : variables_alloc
      75             :     use mo_mpr_startup, only : init_eff_params, mpr_initialize
      76             :     use mo_mpr_global_variables, only: nLAI
      77             : 
      78             :     implicit none
      79             : 
      80             :     integer(i4) :: iDomain
      81             : 
      82             :     ! constants initialization
      83          14 :     call constants_init()
      84             : 
      85          14 :     if (read_restart) then
      86           4 :       allocate(level1(domainMeta%nDomains))
      87           4 :       allocate(level0(domainMeta%nDomains))
      88             :       ! read nLAI from restart files (-1 indicates first reading)
      89           1 :       nLAI = -1_i4
      90             :     else
      91          13 :       call mpr_initialize()
      92             :     end if
      93             : 
      94          40 :     do iDomain = 1, domainMeta%nDomains
      95             : 
      96          26 :       if (read_restart) then
      97             :         ! this reads only the domain properties
      98           1 :         if (domainMeta%L0DataFrom(iDomain) == iDomain) then
      99             :           ! only read level0 data if it is new
     100             :           ! similar to mo_common_read_data::read_dem
     101           1 :           call read_grid_info(mhmFileRestartIn(iDomain), "0", level0(iDomain))
     102             :         endif
     103           1 :         call read_grid_info(mhmFileRestartIn(iDomain), "1", level1(iDomain))
     104             :         ! read nLAI from restart
     105           1 :         call read_nLAI_and_check_dims(iDomain, mhmFileRestartIn(iDomain))
     106             :         ! Parameter fields have to be allocated in any case
     107           1 :         call init_eff_params(level1(iDomain)%nCells)
     108             :       end if
     109             : 
     110             :       ! State variables and fluxes
     111             :       ! have to be allocated and initialised in any case
     112          40 :       call variables_alloc(level1(iDomain)%nCells)
     113             : 
     114             :     end do
     115             : 
     116             :     ! if no restart, this is done already in MPR
     117          14 :     if (read_restart) then
     118             :       call set_domain_indices(level0, indices=domainMeta%L0DataFrom)
     119             :       call set_domain_indices(level1)
     120             :     end if
     121             : 
     122          14 :   end subroutine mhm_initialize
     123             : 
     124             : 
     125             :   !> \brief Initialize mHM constants
     126             :   !> \details transformation of time units & initialize constants
     127             :   !> \changelog
     128             :   !! - Rohini Kumar                 Jan 2013
     129             :   !! - Juliane Mai & Matthias Cuntz Nov 2013
     130             :   !!   - check timeStep
     131             :   !! - Robert Schweppe Jun 2018
     132             :   !!   - refactoring and reformatting
     133             :   !> \authors Luis Samaniego
     134             :   !> \date Dec 2012
     135          14 :   subroutine constants_init
     136          14 :     use mo_common_mHM_mRM_variables, only : timestep, c2TSTu, read_restart
     137             :     use mo_common_variables, only : processMatrix
     138             :     use mo_file, only : file_namelist_mhm_param
     139             :     use mo_global_variables, only : neutron_integral_AFast
     140             :     use mo_mpr_file, only : file_hydrogeoclass
     141             :     use mo_mpr_global_variables, only : GeoUnitList
     142             :     use mo_neutrons, only : TabularIntegralAFast
     143             :     use mo_string_utils, only : num2str
     144             : 
     145             :     implicit none
     146             : 
     147             :     !Fill Tabular for neutron flux integral
     148          14 :     if (processMatrix(10, 1) .eq. 2) then
     149           0 :       allocate(neutron_integral_AFast(10000 + 2))
     150           0 :       call TabularIntegralAFast(neutron_integral_AFast, 20.0_dp)
     151             :     else
     152          14 :       allocate(neutron_integral_AFast(1))
     153          28 :       neutron_integral_AFast(:) = 0.0_dp
     154             :     endif
     155             : 
     156             :     ! if reading restart, we don't need GeoUnitList
     157          14 :     if (.not. read_restart) then
     158             :       ! check if enough geoparameter are defined in mhm_parameter.nml
     159             :       ! this was formerly done after reading of data, but mHM and MPR are now seperate processes
     160          13 :       if ((processMatrix(9, 2)) .NE.  size(GeoUnitList, 1)) then
     161             :         call error_message('***ERROR: Mismatch: Number of geological units in ', trim(adjustl(file_hydrogeoclass)), &
     162           0 :                 ' is ', trim(adjustl(num2str(size(GeoUnitList, 1)))), raise=.false.)
     163             :         call error_message('          while it is ', trim(num2str(processMatrix(9, 2))), &
     164           0 :                 ' in ', trim(file_namelist_mhm_param), '!')
     165             :       end if
     166             :     end if
     167             : 
     168          14 :     c2TSTu = real(timeStep, dp) / 24.0_dp   ! from per timeStep to per day
     169             : 
     170          14 :   end subroutine constants_init
     171             : 
     172             : END MODULE mo_startup

Generated by: LCOV version 1.16