VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
functions.f
Go to the documentation of this file.
1!> \file
2!> This module containes functions used by the profiles.
3
4 MODULE functions
5
6 USE stel_kinds
7
8 implicit none
9
10 PUBLIC :: two_power, two_power_gs
11 PRIVATE :: check
12
13 CONTAINS
14
15!> \brief Profile function for the \c two\_power profile.
16!> \f$b(0) * (1 - x^{b(1)})^{b(2)}\f$
17!>
18!> @param x evaluation location
19!> @param b parameter vector
20 REAL(rprec) function two_power(x, b)
21
22 REAL(rprec), INTENT(in) :: x
23 REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
24
25 two_power = b(0)*((1 - x**b(1))**b(2))
26
27 END FUNCTION
28
29!> \brief Profile function for the \c two\_power\_gs profile.
30!> \f$\texttt{two\_power}(x)*(1 + \sum\left[b(i)*\exp(-(x - b(i+1))/b(i+2))^2\right])\f$
31!>
32!> @param x evaluation location
33!> @param b parameter vector
34 REAL(rprec) function two_power_gs(x, b)
35
36 REAL(rprec), INTENT(in) :: x
37 REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
38
39 INTEGER :: i
40
41 two_power_gs = 1.0
42 DO i = 3, 18, 3
44 & b(i)*exp(-((x - b(i+1))/b(i+2))**2.0_dp)
45 END DO
47
48 END FUNCTION
49
50!> \brief Main test function
51 FUNCTION function_test()
52
53 LOGICAL :: function_test
54 REAL(rprec) :: result
55 REAL(rprec), DIMENSION(0:20) :: b(0:20) = 0
56
57!> Test \c two\_power function for x = 0, b = {1,10,2} is 1
58 b(0:2) = (/ 1.0d+0, 10.0d+0, 2.0d+0 /)
59 result = two_power(0.0d+0, b)
60 function_test = check(1.0d+0,result,1,"two_power()")
61 IF (.not.function_test) RETURN
62
63!> Test \c two\_power function for x = 1, b = {1,10,2} is 0
64 result = two_power(1.0d+0, b)
65 function_test = check(0.0d+0,result,2,"two_power()")
66 IF (.not.function_test) RETURN
67
68!> Test \c two\_power function for x = 0.5, b = {1,1,1} is 0.5
69 b(0:2) = (/ 1.0d+0, 1.0d+0, 1.0d+0 /)
70 result = two_power(0.5d+0, b)
71 function_test = check(0.5d+0,result,3,"two_power()")
72 IF (.not.function_test) RETURN
73
74!> Test \c two\_power function for x = 0.5, b = {1,1,2} is 0.25
75 b(0:2) = (/ 1.0d+0, 1.0d+0, 2.0d+0 /)
76 result = two_power(0.5d+0, b)
77 function_test = check(0.25d+0,result,4,"two_power()")
78 IF (.not.function_test) RETURN
79
80!> Test \c two\_power_gs function for x = 0.4, b = {1,1,1,0,0,1} is two\_power(x,b)
81 b(0:5) = (/ 1.0d+0, 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0, 1.0d+0 /)
82 result = two_power_gs(0.4d+0, b)
83 function_test = check(two_power(0.4d+0, b), &
84 & result,1,"two_power_gs")
85 IF (.not.function_test) RETURN
86
87!> Test \c two\_power\_gs function for x = 0.8, b = {1,1,0,1,0.8,0.1} is 2
88 b(0:5) = (/ 1.0d+0, 1.0d+0, 0.0d+0, 1.0d+0, 0.8d+0, 0.1d+0 /)
89 result = two_power_gs(0.8d+0, b)
90 function_test = check(2.0d+0,result,1,"two_power_gs")
91 IF (.not.function_test) RETURN
92
93 END FUNCTION
94
95!> \brief Check Test result
96 FUNCTION check(expected, recieved, testNum, name)
97
98 LOGICAL :: check
99 REAL(rprec), INTENT(in) :: expected, recieved
100 INTEGER, INTENT(in) :: testnum
101 CHARACTER (LEN=*), INTENT(in) :: name
102
103 check = expected .eq. recieved
104 IF (.not.check) THEN
105 write(*,*) "functions.f: ", name, " test", testnum, &
106 & "failed."
107 write(*,*) "Expected", expected, "Recieved", recieved
108 END IF
109
110 END FUNCTION
111
112 END MODULE
real(rprec) function, public two_power(x, b)
Profile function for the two_power profile. .
Definition functions.f:21
real(rprec) function, public two_power_gs(x, b)
Profile function for the two_power_gs profile. .
Definition functions.f:35
logical function function_test()
Main test function.
Definition functions.f:52
integer, parameter rprec