shift_mesh Subroutine

private subroutine shift_mesh(me)

Shift the vertex coordinates so that there are no non-positive components.

Type Bound

stl_file

Arguments

Type IntentOptional Attributes Name
class(stl_file), intent(inout) :: me

Source Code

    subroutine shift_mesh(me)

    implicit none

    class(stl_file),intent(inout) :: me

    integer :: i !! counter
    integer :: j !! counter
    real(wp),dimension(3) :: offset !! offset vector for vertext coordinates [x,y,z]
    real(wp),dimension(3) :: mins   !! min values of vertex coordinates [x,y,z]

    real(wp),parameter :: tiny = 1.0e-4_wp !! small value to avoid zero

    ! first find the min value of each coordinate:
    mins = huge(one)
    do i = 1, size(me%plates)
        do concurrent (j = 1:3)
            mins(j) = min(mins(j), &
                            me%plates(i)%v1(j), &
                            me%plates(i)%v2(j), &
                            me%plates(i)%v3(j) )
        end do
    end do

    ! compute the offset vector:
    offset = zero
    do concurrent (j = 1:3)
        if (mins(j) <= zero) offset(j) = abs(mins(j)) + tiny
    end do

    if (any(offset/=zero)) then
        ! now add offset vector to each
        do i = 1, size(me%plates)
            me%plates(i)%v1 = me%plates(i)%v1 + offset
            me%plates(i)%v2 = me%plates(i)%v2 + offset
            me%plates(i)%v3 = me%plates(i)%v3 + offset
        end do
    end if

    end subroutine shift_mesh