tem_polygon_material_test_value Subroutine

public subroutine tem_polygon_material_test_value(success)

A subroutine to test the tem_polygon_material_value 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_value~~CallsGraph proc~tem_polygon_material_test_value tem_polygon_material_test_value proc~tem_polygon_material_value tem_polygon_material_value proc~tem_polygon_material_test_value->proc~tem_polygon_material_value proc~angle_between angle_between proc~tem_polygon_material_value->proc~angle_between

Source Code

  subroutine tem_polygon_material_test_value(success)
    ! ----------------------------------------------------------------------
    !> Indicator if all tests were computed correctly.
    logical, intent(out) :: success
    ! ----------------------------------------------------------------------
    type(tem_polygon_material_type) :: polygon
    type(tem_polygon_vertex_type) :: me
    real(kind=rk) :: matval(1)
    ! ----------------------------------------------------------------------

    ! Use simple polygon with 5 vertices to check the containment function.
    ! It has roughly this shape:
    !
    !  x-------x
    !   \      |
    !    \     |
    !     x    |
    !    /     |
    !   /      |
    !  x-------x
    !
    ! With the 'x' indicating the 5 vertices.
    me%nVertices = 5
    allocate(me%Vertex(me%nVertices,2))

    me%Vertex(1,:) = [ 0.0_rk,  0.0_rk]
    me%Vertex(2,:) = [-1.0_rk, -1.0_rk]
    me%Vertex(3,:) = [ 1.0_rk, -1.0_rk]
    me%Vertex(4,:) = [ 1.0_rk,  1.0_rk]
    me%Vertex(5,:) = [-1.0_rk,  1.0_rk]

    ! Defining returned values for inside and outside the polygon:
    polygon%nComponents = 1
    allocate(polygon%inval(polygon%nComponents))
    allocate(polygon%outval(polygon%nComponents))

    polygon%inval = 1.0_rk
    polygon%outval = 0.0_rk

    success = .true.
    ! (If any subsequent test fails, we set this to false.)

    write(*,*) 'Checking point containment for this 5 point polygon:'
    write(*,*)
    write(*,*) '(-1,1)---(1,1)'
    write(*,*) '    \      |'
    write(*,*) '     \     |'
    write(*,*) '    (0,0)  |'
    write(*,*) '     /     |'
    write(*,*) '    /      |'
    write(*,*) '(-1,-1)--(1,-1)'
    write(*,*)

    ! Check a point inside the polygon:
    matval = tem_polygon_material_value( me          = me,                 &
      &                                  point       = [0.5_rk, 0.5_rk],   &
      &                                  inval       = polygon%inval,      &
      &                                  outval      = polygon%outval,     &
      &                                  nComponents = polygon%nComponents )

    if (matval(1) < 1.0_rk) success = .false.
    write(*,*) 'Point (0.5, 0.5) has value:', matval

    ! Check a point outside the polygon:
    matval = tem_polygon_material_value( me          = me,                 &
      &                                  point       = [-1.0_rk, 0.0_rk],  &
      &                                  inval       = polygon%inval,      &
      &                                  outval      = polygon%outval,     &
      &                                  nComponents = polygon%nComponents )

    if (matval(1) > epsilon(1.0_rk)) success = .false.
    write(*,*) 'Point (-1.0, 0.0) has value:', matval

    ! Check a point on a side of the polygon (should be considered inside):
    matval = tem_polygon_material_value( me          = me,                 &
      &                                  point       = [-0.5_rk, -0.5_rk], &
      &                                  inval       = polygon%inval,      &
      &                                  outval      = polygon%outval,     &
      &                                  nComponents = polygon%nComponents )

    if (matval(1) < 1.0_rk) success = .false.
    write(*,*) 'Point (-0.5, -0.5) has value:', matval

    ! Check an outward pointing corner (should be outside):
    matval = tem_polygon_material_value( me          = me,                 &
      &                                  point       = [1.0_rk, 1.0_rk],   &
      &                                  inval       = polygon%inval,      &
      &                                  outval      = polygon%outval,     &
      &                                  nComponents = polygon%nComponents )

    if (matval(1) > epsilon(1.0_rk)) success = .false.
    write(*,*) 'Point (1.0, 1.0) has value:', matval

    ! Check an inward pointing corner (should be inside):
    matval = tem_polygon_material_value( me          = me,                 &
      &                                  point       = [0.0_rk, 0.0_rk],   &
      &                                  inval       = polygon%inval,      &
      &                                  outval      = polygon%outval,     &
      &                                  nComponents = polygon%nComponents )

    if (matval(1) < 1.0_rk) success = .false.
    write(*,*) 'Point (0.0, 0.0) has value:', matval

  end subroutine tem_polygon_material_test_value