resolve_chemistry_active_species Subroutine

private subroutine resolve_chemistry_active_species(params, nactive_species, active_species_indices)

Resolve optional named chemistry active-species screening names to current species indices.

This is intentionally done at chemistry-update time rather than during namelist validation because Cantera mechanism discovery may replace the user-specified species list after the namelist has been read.

Arguments

Type IntentOptional Attributes Name
type(case_params_t), intent(in) :: params
integer, intent(out) :: nactive_species
integer, intent(out) :: active_species_indices(:)

Source Code

   subroutine resolve_chemistry_active_species(params, nactive_species, active_species_indices)
      type(case_params_t), intent(in) :: params
      integer, intent(out) :: nactive_species
      integer, intent(out) :: active_species_indices(:)

      integer :: requested, i, k, found, nslots
      character(len=name_len) :: requested_name, mechanism_name
      logical :: duplicate

      nactive_species = 0
      active_species_indices = 0

      if (params%chemistry_active_species_threshold <= zero) return

      requested = params%chemistry_n_active_species
      if (requested <= 0) then
         do i = 1, max_species
            if (len_trim(params%chemistry_active_species_name(i)) > 0) requested = i
         end do
      end if
      if (requested <= 0) return

      nslots = min(size(active_species_indices), requested)
      do i = 1, nslots
         if (len_trim(params%chemistry_active_species_name(i)) <= 0) cycle

         requested_name = lowercase(trim(params%chemistry_active_species_name(i)))
         found = 0
         do k = 1, params%nspecies
            mechanism_name = lowercase(trim(params%species_name(k)))
            if (trim(mechanism_name) == trim(requested_name)) then
               found = k
               exit
            end if
         end do

         if (found <= 0) then
            call fatal_error('chemistry', 'chemistry_active_species_name not found in active mechanism: '// &
                             trim(params%chemistry_active_species_name(i)))
         end if

         duplicate = .false.
         do k = 1, nactive_species
            if (active_species_indices(k) == found) then
               duplicate = .true.
               exit
            end if
         end do
         if (.not. duplicate) then
            nactive_species = nactive_species + 1
            active_species_indices(nactive_species) = found
         end if
      end do
   end subroutine resolve_chemistry_active_species