Time derivative of advection field, the residuals function.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(integrand_ladvection), | intent(in) | :: | self | Advection field. |
||
real(kind=R_P), | intent(in), | optional | :: | t | Time. |
Advection field time derivative.
function dU_dt(self, t) result(dState_dt)
!< Time derivative of advection field, the residuals function.
class(integrand_ladvection), intent(in) :: self !< Advection field.
real(R_P), intent(in), optional :: t !< Time.
real(R_P), allocatable :: dState_dt(:) !< Advection field time derivative.
real(R_P) :: u(1-self%Ng:self%Ni+self%Ng) !< Conservative variable.
real(R_P) :: ur(1:2,0:self%Ni+1) !< Reconstructed conservative variable.
real(R_P) :: f(0:self%Ni) !< Flux of conservative variable.
integer(I_P) :: i !< Counter.
do i=1, self%Ni
u(i) = self%u(i)
enddo
call self%impose_boundary_conditions(u=u)
call self%reconstruct_interfaces(conservative=u, r_conservative=ur)
do i=0, self%Ni
call solve_riemann_problem(state_left=ur(2, i), state_right=ur(1, i+1), flux=f(i))
enddo
allocate(dState_dt(1:self%Ni))
do i=1, self%Ni
dState_dt(i) = (f(i - 1) - f(i)) / self%Dx
enddo
contains
subroutine solve_riemann_problem(state_left, state_right, flux)
!< Solver Riemann problem of linear advection by upwinding.
real(R_P), intent(in) :: state_left !< Left state.
real(R_P), intent(in) :: state_right !< right state.
real(R_P), intent(out) :: flux !< Flux of conservative variable.
if (self%a > 0._R_P) then
flux = self%a * state_left
else
flux = self%a * state_right
endif
endsubroutine solve_riemann_problem
endfunction dU_dt