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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(case_params_t), | intent(inout) | :: | params |
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