tem_polygon_material_test_angle Subroutine

public subroutine tem_polygon_material_test_angle(success)

A subroutine to test the angle_between function in tem_polygon_material_test.

The only argument will be true, if all calculations result in the expected values.

Arguments

Type IntentOptional Attributes Name
logical, intent(out) :: success

Indicator if all tests were computed correctly.


Calls

proc~~tem_polygon_material_test_angle~~CallsGraph proc~tem_polygon_material_test_angle tem_polygon_material_test_angle proc~angle_between angle_between proc~tem_polygon_material_test_angle->proc~angle_between

Source Code

  subroutine tem_polygon_material_test_angle(success)
    ! ----------------------------------------------------------------------
    !> Indicator if all tests were computed correctly.
    logical, intent(out) :: success
    ! ----------------------------------------------------------------------
    real(kind=rk) :: res
    ! ----------------------------------------------------------------------

    success = .true.

    write(*,*) 'Checking angle computation between two 2D Vectors:'
    ! 90 degree
    res = angle_between( va_x = 1.0_rk, va_y = 0.0_rk, &
      &                  vb_x = 0.0_rk, vb_y = 1.0_rk  )

    if (res < 0.5_rk*tolm*PI .or. res > 0.5_rk*tolp*PI) success = .false.
    write(*,*) '  90 deg:', res


    ! 45 degree
    res = angle_between( va_x = 10.0_rk, va_y = 0.0_rk, &
      &                  vb_x =  2.0_rk, vb_y = 2.0_rk  )

    if (res < 0.25_rk*tolm*PI .or. res > 0.25_rk*tolp*PI) success = .false.
    write(*,*) '  45 deg:', res


    ! -90 degree
    res = angle_between( va_x = 10.0_rk, va_y =  0.0_rk, &
      &                  vb_x =  0.0_rk, vb_y = -3.0_rk  )

    if (res < -0.5_rk*tolp*PI .or. res > -0.5_rk*tolm*PI) success = .false.
    write(*,*) ' -90 deg:', res


    ! -135 degree
    res = angle_between( va_x = 10.0_rk, va_y =  0.0_rk, &
      &                  vb_x = -3.0_rk, vb_y = -3.0_rk  )

    if (res < -0.75_rk*tolp*PI .or. res > -0.75_rk*tolm*PI) success = .false.
    write(*,*) '-135 deg:', res


    ! 120 degree
    res = angle_between( va_x =  0.0_rk,       va_y =  4.5_rk, &
      &                  vb_x = -sqrt(3.0_rk), vb_y = -1.0_rk  )

    if ( res < 2.0_rk/3.0_rk*tolm*PI &
      &  .or. res > 2.0_rk/3.0_rk*tolp*PI) success = .false.
    write(*,*) ' 120 deg:', res

    ! 0 degree
    res = angle_between( va_x = 3.0_rk, va_y = -1.0_rk, &
      &                  vb_x = 3.0_rk, vb_y = -1.0_rk  )

    if (res > epsilon(1.0_rk)) success = .false.
    write(*,*) '   0 deg:', res

    ! 180 degree
    res = angle_between( va_x = -1.0_rk, va_y = -1.0_rk, &
      &                  vb_x =  1.0_rk, vb_y =  1.0_rk  )

    if (res > epsilon(1.0_rk)) success = .false.
    write(*,*) ' 180 deg:', res

    ! 0 Vector
    res = angle_between( va_x = 1.0_rk, va_y = -1.0_rk, &
      &                  vb_x = 0.0_rk, vb_y =  0.0_rk  )

    if (res > epsilon(1.0_rk)) success = .false.
    write(*,*) 'Zero vec:', res

  end subroutine tem_polygon_material_test_angle