FindSpan Function

private pure elemental function FindSpan(me, u) result(span)

This procedure is an elemental function and does a binary search and return the integer :: span value, where lies on. Note that, indexing starts with zero. If , the index is , i.e., , where "nb " is number of control points of the univariate spline basis object.

By a binary search, returns the index of the knot span where lies on.

Implementation Details of Algorithm A2.1

In any given knot span, , at most of the are nonzero, namely the functions . On the only nonzero zeroth-degree function is . Hence, the only cubic functions not zero on are . This property is illustrated here

Properties 2.2

So, we can decrease the computation time by focusing only non-zero functions and their derivatives.


Arguments

Type IntentOptional AttributesName
class(basis), intent(in) :: me
real(kind=wp), intent(in) :: u

Given value

Return Value integer

Knot span index of value


Calls

proc~~findspan~~CallsGraph proc~findspan FindSpan ui ui proc~findspan->ui

Contents

Source Code


Source Code

        pure elemental function FindSpan(me,u) result (span)
            class(basis), intent(in)    :: me
            real(wp), intent(in)        :: u        !< Given \( u \) value
            integer                     :: span     !< Knot span index of \( u \) value
            !locals
            integer :: low, high    !< indices for binary search
            
            associate( p => me%p, Ui => me%kv, n => me%n ) !get rid of % signs
            !/* Special cases */
            if (u >= Ui(n+1)) then
                span = me%n
                return
            end if
            if (u <= Ui(p)) then
            span = p
            return
            end if
            !/* Do binary search */
            low = p; high = n+1
            span = (low + high) / 2
            do while (u < Ui(span) .or. u >= Ui(span+1))
                if (u < Ui(span)) then
                    high = span
                else
                    low  = span
                end if
                span = (low + high) / 2
            end do
            end associate
            
        end function FindSpan