LCOV - code coverage report
Current view: top level - physics/carma/base - prestep.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 22 100.0 %
Date: 2025-03-14 01:33:33 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "carma_globaer.h"
       2             : 
       3             : !! This routine handles all preliminary setup at the beginning
       4             : !! of every timestep.  Things that would appropriately be done
       5             : !! here include:
       6             : !!  Input or otherwise define interface quantities from other submodels.
       7             : !!  Save any model state that is needed to compute tendencies.
       8             : !!  Save any model state that might be needed for comparison at end of step.
       9             : !!  Update timestep counter and simulation time.
      10             : !!
      11             : !! @author Bill McKie
      12             : !! @version Oct-1995
      13     1050624 : subroutine prestep(carma, cstate, rc)
      14             : 
      15             :   ! types
      16             :   use carma_precision_mod
      17             :   use carma_enums_mod
      18             :   use carma_constants_mod
      19             :   use carma_types_mod
      20             :   use carmastate_mod
      21             :   use carma_mod
      22             : 
      23             :   implicit none
      24             : 
      25             :   type(carma_type), intent(in)         :: carma   !! the carma object
      26             :   type(carmastate_type), intent(inout) :: cstate  !! the carma state object
      27             :   integer, intent(inout)               :: rc      !! return code, negative indicates failure
      28             : 
      29             :   integer                        :: iz      ! z index
      30             :   integer                        :: igrp    ! group index
      31             :   integer                        :: igas    ! gas index
      32             :   integer                        :: ibin    ! bin index
      33             :   integer                        :: ielem   ! element index
      34             :   integer                        :: iep
      35             :   real(kind=f)                   :: tmp_gc(NZ, NGAS)
      36             :   real(kind=f)                   :: tmp_t(NZ)
      37             : 
      38             : 
      39             :   ! If substepping is enabled, then determine how much the
      40             :   ! gas concentration and temperature changed during this time step.
      41     1050624 :   if (do_substep) then
      42     1050624 :     if (NGAS > 0) then
      43   150239232 :       d_gc(:,:) = gc(:,:) - gcl(:,:)
      44             : 
      45     3151872 :       do igas = 1, NGAS
      46   150239232 :         do iz = 1, NZ
      47             : 
      48             :           ! NOTE: When d_gc is negative, you can get into problems with overshoot
      49             :           ! to negative gas concentrations. To prevent that, when gc is negative
      50             :           ! apply it all in the first step. Only substep gc when gc is increasing.
      51             :           !
      52             :           ! NOTE: Perhaps there should be a limit, so that small changes happen
      53             :           ! over the course of the timestep, but large changes get applied on the
      54             :           ! first step. For now, doing it all on the first step should be the most
      55             :           ! stable.
      56             :           !
      57             :           ! NOTE: The case that is problematic is when the particle is growing
      58             :           ! (i.e. supersaturated) and d_gc is negative. For better performance,
      59             :           ! substep the gas unless both of these are true. This might run into
      60             :           ! trouble if d_t is large and negative.
      61   149188608 :           if (d_gc(iz, igas) < 0._f) then
      62             : 
      63             :             ! Start from the new state and don't step the gas.
      64    57909183 :             d_gc(iz, igas) = 0._f
      65    57909183 :             gcl(iz, igas) = gc(iz, igas)
      66             :           else
      67             : 
      68             :             ! Start the step from the old state and step the gas.
      69    89178177 :             gc(iz, igas) = gcl(iz, igas)
      70             :           end if
      71             :         end do
      72             :       end do
      73             :     end if
      74             : 
      75             :     ! Start the temperature from the old state.
      76    74594304 :     d_t(:) = t(:) - told(:)
      77    74594304 :     t(:) = told(:)
      78             :   endif
      79             : 
      80             : 
      81             :   ! Don't allow particle concentrations to get too small.
      82    74594304 :   do iz = 1, NZ
      83  1545467904 :     do ibin = 1, NBIN
      84 11840532480 :       do ielem = 1, NELEM
      85 11766988800 :         call smallconc(carma, cstate, iz, ibin, ielem, rc)
      86             :       end do
      87             :     end do
      88             :   end do
      89             : 
      90             :   ! Set <pcl> to <pc> from previous time step. This is needed by coagulation
      91             :   ! as well as substepping.
      92     1050624 :   if (do_substep .or. do_coag) then
      93 10451607552 :     pcl(:,:,:) = pc(:,:,:)
      94             :   endif
      95             : 
      96             :   ! Find maximum particle concentrations.
      97    74594304 :   do iz = 1, NZ
      98    74594304 :     call maxconc(carma, cstate, iz, rc)
      99             :   end do
     100             : 
     101             :   ! Return to caller with preliminary timestep things completed.
     102     1050624 :   return
     103     1050624 : end

Generated by: LCOV version 1.14