V3FIT
math_utilities.f
1 !============================================================================
2  MODULE math_utilities
3 !--------------------------------------------------------------------------
4 !
5 ! FUNCTION: Module containing routines necessary to compute the line-integrated
6 ! Faraday rotation angle and the line-integrated polarization phase shift.
7 !
8 !------------------------------------------------------------------------------
9  USE stel_kinds
10  USE stel_constants
11  IMPLICIT NONE
12 
13 
14  CONTAINS
15 !=============================================================================
16  REAL(KIND=rprec) FUNCTION magnitude(vec)
17 !--------------------------------------------------------------------------
18 ! FUNCTION: calculates the magnitude of 3D input vector.
19 !
20 !---------------------------------------------------------------------------
21  USE stel_kinds
22  IMPLICIT NONE
23 
24 
25  REAL(rprec), DIMENSION(3), INTENT(IN) :: &
26  & vec ! 3D vector
27 
28  magnitude = sqrt( vec(1)*vec(1) + vec(2)*vec(2) + vec(3)*vec(3) )
29 
30  RETURN
31  END FUNCTION magnitude
32 
33 !=============================================================================
34  SUBROUTINE unit_vector(v1, v1_unit)
35 !--------------------------------------------------------------------------
36 ! FUNCTION: calculates the magnitude of 3D input vector.
37 !
38 !---------------------------------------------------------------------------
39  USE stel_kinds
40  IMPLICIT NONE
41 
42  REAL(rprec), DIMENSION(3), INTENT(IN) :: &
43  & v1 ! 3D vector
44 
45  REAL(rprec), DIMENSION(3), INTENT(OUT) :: &
46  & v1_unit ! 3D vector
47 
48  v1_unit = v1 / magnitude(v1)
49 
50  RETURN
51  END SUBROUTINE unit_vector
52 
53 
54 !=============================================================================
55  REAL(KIND=rprec) FUNCTION dist(v1, v2)
56 !--------------------------------------------------------------------------
57 ! FUNCTION: calculates the absolute distance between 2 input vectors.
58 !
59 !---------------------------------------------------------------------------
60  USE stel_kinds
61  IMPLICIT NONE
62 
63  REAL(rprec), DIMENSION(3), INTENT(IN) :: &
64  & v1, v2 ! 3D vectors
65 
66  REAL(rprec), DIMENSION(3) :: &
67  & v3 ! difference vector btwn v1 & v2
68 
69  v3 = abs( v2 - v1 )
70  dist = sqrt( v3(1)*v3(1) + v3(2)*v3(2) + v3(3)*v3(3) )
71 
72  RETURN
73  END FUNCTION dist
74 
75 !==================================================================================
76  SUBROUTINE cross_product(A, B, C)
77 !----------------------------------------------------------------------------------
78 ! FUNCTION: computes the cross product (C) for input CARTESIAN vectors A and B.
79 !
80 ! LOGIC: C = A .cross. B
81 !
82 ! created by J. Shields 2/15/06
83 !
84 !--------------------------------------------------------------------------------------
85  USE stel_kinds
86  IMPLICIT NONE
87 
88 !........passed variables....................................................!
89  REAL(rprec), DIMENSION(3), INTENT(IN) :: A ! input Cartesian vector
90 
91  REAL(rprec), DIMENSION(3), INTENT(IN) :: B ! input Cartesian vector
92 
93  REAL(rprec), DIMENSION(3), INTENT(OUT) :: C ! Cross product: A .cross. B
94 
95 
96 !.................local variables...................................!
97  INTEGER(iprec) :: i
98  character(len=*), PARAMETER :: subname = 'CROSS_PRODUCT'
99 
100 
101 !..................X component.....................................!
102  c(1) = a(2) * b(3) - a(3) * b(2)
103 
104 !...................Y component.....................................!
105  c(2) = a(3) * b(1) - a(1) * b(3)
106 
107 !...................Z component.....................................!
108  c(3) = a(1) * b(2) - a(2) * b(1)
109 
110  RETURN
111  END SUBROUTINE cross_product
112 
113 
114  END MODULE math_utilities