compute_and_update_cfl Subroutine

public subroutine compute_and_update_cfl(mesh, flow, params, fields, stats)

Calculates domain-wide CFL and optionally scales the timestep size.

For stability in reacting flows, the timestep growth is capped to 2% per step when use_dynamic_dt is active.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(in) :: flow
type(case_params_t), intent(inout) :: params
type(flow_fields_t), intent(in) :: fields
type(solver_stats_t), intent(inout) :: stats

Calls

proc~~compute_and_update_cfl~~CallsGraph proc~compute_and_update_cfl mod_flow_projection::compute_and_update_cfl mpi_allreduce mpi_allreduce proc~compute_and_update_cfl->mpi_allreduce proc~check_mpi mod_flow_projection::check_mpi proc~compute_and_update_cfl->proc~check_mpi proc~fatal_error mod_kinds::fatal_error proc~check_mpi->proc~fatal_error

Called by

proc~~compute_and_update_cfl~~CalledByGraph proc~compute_and_update_cfl mod_flow_projection::compute_and_update_cfl program~lowmach_react_hex lowmach_react_hex program~lowmach_react_hex->proc~compute_and_update_cfl

Source Code

   subroutine compute_and_update_cfl(mesh, flow, params, fields, stats)
      type(mesh_t), intent(in) :: mesh
      type(flow_mpi_t), intent(in) :: flow
      type(case_params_t), intent(inout) :: params
      type(flow_fields_t), intent(in) :: fields
      type(solver_stats_t), intent(inout) :: stats

      integer :: c, lf, f
      real(rk) :: local_cfl_rate, max_cfl_rate
      real(rk) :: cell_outward_flux
      integer :: ierr

      local_cfl_rate = zero

      do c = flow%first_cell, flow%last_cell
         cell_outward_flux = zero
         do lf = 1, mesh%ncell_faces(c)
            f = mesh%cell_faces(lf, c)
            cell_outward_flux = cell_outward_flux + abs(fields%face_flux(f))
         end do
         cell_outward_flux = half * cell_outward_flux / mesh%cells(c)%volume
         if (cell_outward_flux > local_cfl_rate) then
            local_cfl_rate = cell_outward_flux
         end if
      end do

      call MPI_Allreduce(local_cfl_rate, max_cfl_rate, 1, MPI_DOUBLE_PRECISION, MPI_MAX, flow%comm, ierr)
      call check_mpi(ierr, 'cfl max rate')

      if (params%use_dynamic_dt) then
         if (max_cfl_rate > tiny_safe) then
            ! Tighten dt growth cap to 1.02x per step for stability starting from rest
            params%dt = min(params%max_cfl / max_cfl_rate, params%dt * 1.02_rk)
         end if
      end if

      stats%cfl = max_cfl_rate * params%dt
   end subroutine compute_and_update_cfl