initialize_cantera_wrapper Subroutine

private subroutine initialize_cantera_wrapper(params)

Uses

  • proc~~initialize_cantera_wrapper~~UsesGraph proc~initialize_cantera_wrapper mod_transport_properties::initialize_cantera_wrapper iso_c_binding iso_c_binding proc~initialize_cantera_wrapper->iso_c_binding

Higher-level wrapper to coordinate Cantera initialization.

Handles string conversion between Fortran and C, and manages the automatic discovery of species counts and names from the mechanism file.

Arguments

Type IntentOptional Attributes Name
type(case_params_t), intent(inout) :: params

Calls

proc~~initialize_cantera_wrapper~~CallsGraph proc~initialize_cantera_wrapper mod_transport_properties::initialize_cantera_wrapper interface~cantera_get_species_count_c mod_transport_properties::cantera_get_species_count_c proc~initialize_cantera_wrapper->interface~cantera_get_species_count_c interface~cantera_get_species_name_c mod_transport_properties::cantera_get_species_name_c proc~initialize_cantera_wrapper->interface~cantera_get_species_name_c interface~cantera_init_c mod_transport_properties::cantera_init_c proc~initialize_cantera_wrapper->interface~cantera_init_c

Called by

proc~~initialize_cantera_wrapper~~CalledByGraph proc~initialize_cantera_wrapper mod_transport_properties::initialize_cantera_wrapper proc~initialize_transport mod_transport_properties::initialize_transport proc~initialize_transport->proc~initialize_cantera_wrapper program~lowmach_react_hex lowmach_react_hex program~lowmach_react_hex->proc~initialize_transport

Source Code

   subroutine initialize_cantera_wrapper(params)
      use iso_c_binding, only : c_char, c_null_char
      type(case_params_t), intent(inout) :: params
      character(kind=c_char, len=len(params%cantera_mech_file)+1) :: c_mech_file
      character(kind=c_char), allocatable :: c_names_flat(:)
      integer :: k, n_len, c_nsp

      c_mech_file = trim(params%cantera_mech_file) // c_null_char
      
      ! Initial dummy call to setup mechanism and query species
      call cantera_init_c(c_mech_file, 0, "", 0)

      if (params%enable_reactions) then
         ! Automatic Discovery Mode: Inherit all species from the mechanism
         c_nsp = cantera_get_species_count_c()
         params%nspecies = c_nsp
         n_len = len(params%species_name(1))
         do k = 1, params%nspecies
            call cantera_get_species_name_c(k-1, params%species_name(k), n_len)
         end do
      else if (params%enable_cantera_thermo .and. params%nspecies == 0) then
         ! No-species thermo mode: use user-selected inert/default species.
         params%nspecies = 1
         params%species_name(1) = trim(params%thermo_default_species)
      else if (params%enable_cantera_fluid .and. params%nspecies == 0) then
         ! Single Species Fluid Mode: default to N2 when no species list is provided.
         params%nspecies = 1
         params%species_name(1) = 'N2'
      end if

      ! Re-initialize with the finalized species list for future transport updates
      n_len = len(params%species_name(1))
      allocate(c_names_flat(n_len * params%nspecies))
      c_names_flat = " "
      do k = 1, params%nspecies
         do c_nsp = 1, n_len
            c_names_flat((k-1)*n_len + c_nsp) = char(ichar(params%species_name(k)(c_nsp:c_nsp)))
         end do
      end do

      call cantera_init_c(c_mech_file, params%nspecies, c_names_flat, n_len)
      deallocate(c_names_flat)
   end subroutine initialize_cantera_wrapper