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

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
            params%dt = min(params%max_cfl / max_cfl_rate, &
                            params%dt * params%dt_growth_limit, &
                            params%max_dt)
         else
            params%dt = min(params%dt * params%dt_growth_limit, params%max_dt)
         end if
         params%dt = max(params%min_dt, min(params%dt, params%max_dt))
      end if

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