leapfrog Subroutine

public subroutine leapfrog(func, x, v, a, t, m, dt, n)

速度比位移、加速度快半步长,本例程仅用作力学求解,求解一段时间内的力学变化,并更新时间

Arguments

Type IntentOptional Attributes Name
real :: func
real(kind=rk), intent(inout), dimension(*) :: x
real(kind=rk), intent(inout), dimension(*) :: v
real(kind=rk), intent(inout), dimension(*) :: a
real(kind=rk), intent(inout) :: t
integer, intent(in) :: m
real(kind=rk), intent(in) :: dt
integer, intent(in) :: n

Contents

Source Code


Source Code

    subroutine leapfrog(func, x, v, a, t, m, dt, n)
        external :: func
        real(kind=rk), intent(inout), dimension(*) :: x, v, a
        real(kind=rk), intent(inout) :: t
        integer, intent(in) :: m
        real(kind=rk), intent(in) :: dt
        integer, intent(in) :: n

        real(kind=rk) :: t0, vtmp(n)
        integer :: i

        do i = 1, m
            t0 = t + dt*i
            x(:n) = x(:n) + v(:n)*dt
            vtmp = v(:n) + a(:n)*dt/2
            call func(t, x, vtmp, a)
            v(:n) = v(:n) + a(:n)*dt
        end do

        if (m > 0) t = t0

    end subroutine leapfrog