Skip to content
Stefano Zaghi edited this page Nov 6, 2015 · 2 revisions

VecFor allows a very simple, high-level implementation of vectorial calculus algebra.

Import VecFor

use vecfor ! load vector type and all helpers

Define some vector variables

type(vector) :: point1
type(vector) :: point2
type(vector) :: distance

Initialize vectors by high-level math-like syntax

point1 = 1 * ex ! ex is the versor along x direction exposed by VecFor
point2 = 1 * ex + 2 * ey ! ey is the versor along y direction exposed by VecFor

Note that ex, ey and ez are the Cartesian versors exposed by VecFor.

Perform vectorial calculus algebra

distance = point2 - ponint1

Use helper methods to simplify your life

print "(A)", " Vectorial distance"
call distance%print
print "(A)", " Distance module"
print*, distance%normL2()
! expected output
!   Vectorial distance
!   Component x  0.000000000000000E+000
!   Component y +0.200000000000000E+001
!   Component z  0.000000000000000E+000
!   Distance module
!   +0.200000000000000E+001

As you can see from the above example, defining and using a vector become very close to the mathematical formulation. Note that, using the dynamic dispatching resolved at compile time, there is no performance penalty on using a type(vector) variable instead of an hard-coded real, dimension(3) array variable (or even more verbose and less clear real :: x, y, z variables for each vector...).

Clone this wiki locally