vector Derived Type

type, public :: vector

Vector class


Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: x

vector components

real(kind=wp), public :: y

vector components

real(kind=wp), public :: z

vector components


Type-Bound Procedures

procedure, public :: length

Returns the length of the vector

  • public pure elemental function length(this)

    Returns the length of a vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: this

    Return Value real(kind=wp)

procedure, public :: magnitude

Returns the magnitude of the vector

  • public pure elemental function magnitude(this)

    Returns the magnitude of a vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: this

    Return Value type(vector)

generic, public :: operator(*) => vec_mult_vec, vec_mult_scal, scal_mult_vec

Overloads the Multiplication operator for vec3

  • private pure elemental function vec_mult_vec(a, b)

    vec3 * vec3 elementwise

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    type(vector), intent(in) :: b

    vec3 to multiply by

    Return Value type(vector)

  • private pure elemental function vec_mult_scal(a, b)

    vec3 * scalar elementwise

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=wp), intent(in) :: b

    Scalar to multiply by

    Return Value type(vector)

  • private pure elemental function scal_mult_vec(a, b)

    Scalar * vec3 elementwise

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to multiply by

    class(vector), intent(in) :: b

    input vec3

    Return Value type(vector)

generic, public :: operator(**) => vec_mult_exp_scal_int, vec_mult_exp_scal_r4, vec_mult_exp_scal_r8

Overloads the exponential operator for vec3

  • private pure elemental function vec_mult_exp_scal_int(a, b)

    vec3**scalar for integer scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    integer, intent(in) :: b

    Input scalar

    Return Value type(vector)

  • private pure elemental function vec_mult_exp_scal_r4(a, b)

    vec3**scalar for 32-bit float scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    real(kind=sp), intent(in) :: b

    Input scalar

    Return Value type(vector)

  • private pure elemental function vec_mult_exp_scal_r8(a, b)

    vec3**scalar for 64-bit float scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    real(kind=dp), intent(in) :: b

    Input scalar

    Return Value type(vector)

generic, public :: operator(+) => vec_add_vec, vec_add_scal, scal_add_vec

Overloads the Addition operator for vec3

  • private pure elemental function vec_add_vec(a, b)

    vec3 + vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    Vec3 to add

    Return Value type(vector)

  • private pure elemental function vec_add_scal(a, b)

    vec3 + scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    real(kind=wp), intent(in) :: b

    Scalar to add

    Return Value type(vector)

  • private pure elemental function scal_add_vec(a, b)

    vec3 + scalar

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to add

    class(vector), intent(in) :: b

    Input vector

    Return Value type(vector)

generic, public :: operator(-) => vec_minus_vec, vec_minus_scal, scal_minus_vec

Overloads the Subtraction operator for vec3

  • private pure elemental function vec_minus_vec(a, b)

    vec3 - vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    vec3 to subtract

    Return Value type(vector)

  • private pure elemental function vec_minus_scal(a, b)

    vec3 - scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    real(kind=wp), intent(in) :: b

    Scalar to subtract

    Return Value type(vector)

  • private pure elemental function scal_minus_vec(a, b)

    scalar - vec3

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to subtract from

    class(vector), intent(in) :: b

    Input vector

    Return Value type(vector)

generic, public :: operator(.cross.) => vec_cross_vec

.cross. operator. Cross product

  • private pure elemental function vec_cross_vec(a, b) result(cross)

    vec3 x vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    vec3 to cross with

    Return Value type(vector)

generic, public :: operator(.dot.) => vec_dot_vec, vec_dot_mat

.dot. operator. Dot product

  • private pure elemental function vec_dot_vec(a, b) result(dot)

    vec3 . vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3

    type(vector), intent(in) :: b

    vec3 to dot

    Return Value real(kind=wp)

  • private pure function vec_dot_mat(a, b) result(dot)

    vec3 . matrix

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3

    real(kind=wp), intent(in) :: b(4,4)

    Matrix to dot with

    Return Value type(vector)

generic, public :: operator(/) => vec_div_scal_r4, vec_div_scal_r8, vec_div_scal_int

Overloads the Division operator for vec3

  • private pure elemental function vec_div_scal_r4(a, b)

    vec3 / scalar elementwise. Scalar is a 32-bit float

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=sp), intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

  • private pure elemental function vec_div_scal_r8(a, b)

    vec3 / scalar elementwise. Scalar is a 64-bit float

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=dp), intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

  • private pure elemental function vec_div_scal_int(a, b)

    vec3 / scalar elementwise. Scalar is an integer

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    integer, intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

generic, public :: operator(==) => vec_equal_vec

Overloads the equal operator for vec3

  • private pure elemental function vec_equal_vec(a, b)

    vec3 == vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3s

    class(vector), intent(in) :: b

    Input vec3s

    Return Value logical

procedure, private, pass(b) :: scal_add_vec

  • private pure elemental function scal_add_vec(a, b)

    vec3 + scalar

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to add

    class(vector), intent(in) :: b

    Input vector

    Return Value type(vector)

procedure, private, pass(b) :: scal_minus_vec

  • private pure elemental function scal_minus_vec(a, b)

    scalar - vec3

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to subtract from

    class(vector), intent(in) :: b

    Input vector

    Return Value type(vector)

procedure, private, pass(b) :: scal_mult_vec

  • private pure elemental function scal_mult_vec(a, b)

    Scalar * vec3 elementwise

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: a

    Scalar to multiply by

    class(vector), intent(in) :: b

    input vec3

    Return Value type(vector)

procedure, private, pass(a) :: vec_add_scal

  • private pure elemental function vec_add_scal(a, b)

    vec3 + scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    real(kind=wp), intent(in) :: b

    Scalar to add

    Return Value type(vector)

procedure, private, pass(a) :: vec_add_vec

  • private pure elemental function vec_add_vec(a, b)

    vec3 + vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    Vec3 to add

    Return Value type(vector)

procedure, private, pass(a) :: vec_cross_vec

  • private pure elemental function vec_cross_vec(a, b) result(cross)

    vec3 x vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    vec3 to cross with

    Return Value type(vector)

procedure, private, pass(a) :: vec_div_scal_int

  • private pure elemental function vec_div_scal_int(a, b)

    vec3 / scalar elementwise. Scalar is an integer

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    integer, intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

procedure, private, pass(a) :: vec_div_scal_r4

  • private pure elemental function vec_div_scal_r4(a, b)

    vec3 / scalar elementwise. Scalar is a 32-bit float

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=sp), intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

procedure, private, pass(a) :: vec_div_scal_r8

  • private pure elemental function vec_div_scal_r8(a, b)

    vec3 / scalar elementwise. Scalar is a 64-bit float

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=dp), intent(in) :: b

    Scalar to divide by

    Return Value type(vector)

procedure, private, pass(a) :: vec_dot_mat

  • private pure function vec_dot_mat(a, b) result(dot)

    vec3 . matrix

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3

    real(kind=wp), intent(in) :: b(4,4)

    Matrix to dot with

    Return Value type(vector)

procedure, private, pass(a) :: vec_dot_vec

  • private pure elemental function vec_dot_vec(a, b) result(dot)

    vec3 . vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3

    type(vector), intent(in) :: b

    vec3 to dot

    Return Value real(kind=wp)

procedure, private, pass(a) :: vec_equal_vec

  • private pure elemental function vec_equal_vec(a, b)

    vec3 == vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vec3s

    class(vector), intent(in) :: b

    Input vec3s

    Return Value logical

procedure, private, pass(a) :: vec_minus_scal

  • private pure elemental function vec_minus_scal(a, b)

    vec3 - scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    real(kind=wp), intent(in) :: b

    Scalar to subtract

    Return Value type(vector)

procedure, private, pass(a) :: vec_minus_vec

  • private pure elemental function vec_minus_vec(a, b)

    vec3 - vec3

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input vector

    type(vector), intent(in) :: b

    vec3 to subtract

    Return Value type(vector)

procedure, private, pass(a) :: vec_mult_exp_scal_int

  • private pure elemental function vec_mult_exp_scal_int(a, b)

    vec3**scalar for integer scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    integer, intent(in) :: b

    Input scalar

    Return Value type(vector)

procedure, private, pass(a) :: vec_mult_exp_scal_r4

  • private pure elemental function vec_mult_exp_scal_r4(a, b)

    vec3**scalar for 32-bit float scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    real(kind=sp), intent(in) :: b

    Input scalar

    Return Value type(vector)

procedure, private, pass(a) :: vec_mult_exp_scal_r8

  • private pure elemental function vec_mult_exp_scal_r8(a, b)

    vec3**scalar for 64-bit float scalar

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    Input Vector

    real(kind=dp), intent(in) :: b

    Input scalar

    Return Value type(vector)

procedure, private, pass(a) :: vec_mult_scal

  • private pure elemental function vec_mult_scal(a, b)

    vec3 * scalar elementwise

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    real(kind=wp), intent(in) :: b

    Scalar to multiply by

    Return Value type(vector)

procedure, private, pass(a) :: vec_mult_vec

  • private pure elemental function vec_mult_vec(a, b)

    vec3 * vec3 elementwise

    Arguments

    Type IntentOptional Attributes Name
    class(vector), intent(in) :: a

    input vec3

    type(vector), intent(in) :: b

    vec3 to multiply by

    Return Value type(vector)

Source Code

    type :: vector
        !> vector components
        real(kind=wp)  :: x, y, z
        contains

        !> Returns the magnitude of the vector
        procedure :: magnitude         => magnitude
        !> Returns the length of the vector
        procedure :: length            => length
        !> .dot. operator. Dot product
        generic   :: operator(.dot.)   => vec_dot_vec, vec_dot_mat
        !> .cross. operator. Cross product
        generic   :: operator(.cross.) => vec_cross_vec
        !> Overloads the Division operator for vec3
        generic   :: operator(/)       => vec_div_scal_r4, vec_div_scal_r8, vec_div_scal_int
        !> Overloads the Multiplication operator for vec3
        generic   :: operator(*)       => vec_mult_vec, vec_mult_scal, scal_mult_vec
        !> Overloads the exponential operator for vec3
        generic   :: operator(**)      => vec_mult_exp_scal_int, vec_mult_exp_scal_r4, vec_mult_exp_scal_r8
        !> Overloads the Addition operator for vec3
        generic   :: operator(+)       => vec_add_vec, vec_add_scal, scal_add_vec
        !> Overloads the Subtraction operator for vec3
        generic   :: operator(-)       => vec_minus_vec, vec_minus_scal, scal_minus_vec
        !> Overloads the equal operator for vec3
        generic   :: operator(==)      => vec_equal_vec

        procedure, pass(a), private :: vec_dot_vec
        procedure, pass(a), private :: vec_dot_mat

        procedure, pass(a), private :: vec_cross_vec

        procedure, pass(a), private :: vec_div_scal_r4
        procedure, pass(a), private :: vec_div_scal_r8
        procedure, pass(a), private :: vec_div_scal_int

        procedure, pass(a), private :: vec_mult_vec
        procedure, pass(a), private :: vec_mult_scal
        procedure, pass(b), private :: scal_mult_vec
        
        procedure, pass(a), private :: vec_mult_exp_scal_int
        procedure, pass(a), private :: vec_mult_exp_scal_r4
        procedure, pass(a), private :: vec_mult_exp_scal_r8

        procedure, pass(a), private :: vec_add_vec
        procedure, pass(a), private :: vec_add_scal
        procedure, pass(b), private :: scal_add_vec

        procedure, pass(a), private :: vec_minus_vec
        procedure, pass(a), private :: vec_minus_scal
        procedure, pass(b), private :: scal_minus_vec

        procedure, pass(a), private :: vec_equal_vec

    end type vector