build_thermo_Y Subroutine

private subroutine build_thermo_Y(params, ncells, Y_local, species_Y)

Build a cellwise thermodynamic composition array for Cantera calls.

If transported species are available, they are used directly and clipped to non-negative values. If their sum is positive, the local composition is normalized before passing to Cantera. If no transported species are available, use the single-species/default mixture prepared during Cantera initialization, usually thermo_default_species.

Arguments

Type IntentOptional Attributes Name
type(case_params_t), intent(in) :: params
integer, intent(in) :: ncells
real(kind=rk), intent(out), allocatable :: Y_local(:,:)
real(kind=rk), intent(in), optional :: species_Y(:,:)

Source Code

   subroutine build_thermo_Y(params, ncells, Y_local, species_Y)
      type(case_params_t), intent(in) :: params
      integer, intent(in) :: ncells
      real(rk), allocatable, intent(out) :: Y_local(:,:)
      real(rk), intent(in), optional :: species_Y(:,:)

      integer :: c, k, nsp
      real(rk) :: sum_Y

      nsp = max(1, params%nspecies)
      allocate(Y_local(nsp, ncells))
      Y_local = zero

      if (present(species_Y) .and. params%enable_species .and. params%nspecies > 0) then
         if (size(species_Y, 1) < params%nspecies .or. size(species_Y, 2) < ncells) then
            call fatal_error('energy', 'species_Y has incompatible shape for Cantera thermo update')
         end if

         do c = 1, ncells
            sum_Y = zero
            do k = 1, params%nspecies
               Y_local(k, c) = max(zero, species_Y(k, c))
               sum_Y = sum_Y + Y_local(k, c)
            end do

            if (sum_Y > tiny_safe) then
               Y_local(1:params%nspecies, c) = Y_local(1:params%nspecies, c) / sum_Y
            else
               Y_local(1, c) = 1.0_rk
            end if
         end do
      else
         Y_local(1, :) = 1.0_rk
      end if
   end subroutine build_thermo_Y