V3FIT
functions.f
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
9 !*******************************************************************************
10  MODULE functions
11  USE stel_kinds
12 
13 !*******************************************************************************
14 ! INTERFACE BLOCKS
15 !*******************************************************************************
16  PUBLIC :: two_power, two_power_gs, function_test
17  PRIVATE :: check
18 
19  CONTAINS
20 
21 !*******************************************************************************
22 ! PUBLIC FUNCTIONS AND SUBROUTINES
23 !*******************************************************************************
24 !*******************************************************************************
38 !*******************************************************************************
39  REAL(rprec) PURE FUNCTION two_power(x, b)
40 
41  IMPLICIT NONE
42 
43 ! Declare Arguments
44  REAL(rprec), INTENT(in) :: x
45  REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
46 
47 ! Start of executable code
48  two_power = b(0)*((1.0 - x**b(1))**b(2))
49 
50  END FUNCTION
51 
52 !*******************************************************************************
68 !*******************************************************************************
69  REAL(rprec) PURE function two_power_gs(x, b)
70 
71  IMPLICIT NONE
72 
73 ! Declare Arguments
74  REAL(rprec), INTENT(in) :: x
75  REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
76 
77 ! local variables
78  INTEGER :: i
79 
80 ! Start of executable code
81  two_power_gs = 1.0
82  DO i = 3, 18, 3
83  two_power_gs = two_power_gs &
84  & + b(i)*exp(-((x - b(i+1))/b(i+2))**2.0)
85  END DO
86  two_power_gs = two_power_gs*two_power(x,b)
87 
88  END FUNCTION
89 
90 !*******************************************************************************
104 !*******************************************************************************
105  REAL(rprec) PURE function guassian(x, b)
106 
107  IMPLICIT NONE
108 
109 ! Declare Arguments
110  REAL(rprec), INTENT(in) :: x
111  REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
112 
113 ! Start of executable code
114  guassian = b(0)*exp(-((x - b(1))/b(2))**2.0)
115 
116  END FUNCTION
117 
118 !*******************************************************************************
135 !*******************************************************************************
136  REAL(rprec) PURE function guassian_int(x, b)
137  USE stel_constants, only : pi
138 
139  IMPLICIT NONE
140 
141 ! Declare Arguments
142  REAL(rprec), INTENT(in) :: x
143  REAL(rprec), DIMENSION(0:20), INTENT(in) :: b
144 
145 ! local parameters
146  REAL(rprec), PARAMETER :: sqrpi = 0.5*sqrt(pi)
147 
148 ! Start of executable code
149 
150  guassian_int = sqrpi*b(0)*b(1)*(erf(b(1)/b(2)) - &
151  & erf((b(1) - x)/b(2)))
152 
153  END FUNCTION
154 
155 !*******************************************************************************
156 ! UNIT TESTS
157 !*******************************************************************************
158 !-------------------------------------------------------------------------------
164 !-------------------------------------------------------------------------------
165  FUNCTION function_test()
166 
167  IMPLICIT NONE
168 
169 ! Declare Arguments
170  LOGICAL :: function_test
171 
172 ! local variables
173  REAL(rprec) :: result
174  REAL(rprec), DIMENSION(0:20) :: b(0:20) = 0
175 
176 ! Start of executable code
177 ! Test two_power function for x = 0, b = {1,10,2} is 1
178  b(0:2) = (/ 1.0d+0, 10.0d+0, 2.0d+0 /)
179  result = two_power(0.0d+0, b)
180  function_test = check(1.0d+0,result,1,"two_power()")
181  IF (.not.function_test) RETURN
182 
183 ! Test two_power function for x = 1, b = {1,10,2} is 0
184  result = two_power(1.0d+0, b)
185  function_test = check(0.0d+0,result,2,"two_power()")
186  IF (.not.function_test) RETURN
187 
188 ! Test two_power function for x = 0.5, b = {1,1,1} is 0.5
189  b(0:2) = (/ 1.0d+0, 1.0d+0, 1.0d+0 /)
190  result = two_power(0.5d+0, b)
191  function_test = check(0.5d+0,result,3,"two_power()")
192  IF (.not.function_test) RETURN
193 
194 ! Test two_power function for x = 0.5, b = {1,1,2} is 0.25
195  b(0:2) = (/ 1.0d+0, 1.0d+0, 2.0d+0 /)
196  result = two_power(0.5d+0, b)
197  function_test = check(0.25d+0,result,4,"two_power()")
198  IF (.not.function_test) RETURN
199 
200 ! Test two_power_gs function for x = 0.4, b = {1,1,1,0,0,1} is twopower(x,b)
201  b(0:5) = (/ 1.0d+0, 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0, 1.0d+0 /)
202  result = two_power_gs(0.4d+0, b)
203  function_test = check(two_power(0.4d+0, b), &
204  & result,1,"two_power_gs")
205  IF (.not.function_test) RETURN
206 
207 ! Test two_power_gs function for x = 0.8, b = {1,1,0,1,0.8,0.1} is 2
208  b(0:5) = (/ 1.0d+0, 1.0d+0, 0.0d+0, 1.0d+0, 0.8d+0, 0.1d+0 /)
209  result = two_power_gs(0.8d+0, b)
210  function_test = check(2.0d+0,result,1,"two_power_gs")
211  IF (.not.function_test) RETURN
212 
213  END FUNCTION
214 
215 !*******************************************************************************
216 ! CHECK FUNCTIONS
217 !*******************************************************************************
218 !-------------------------------------------------------------------------------
229 !-------------------------------------------------------------------------------
230  FUNCTION check(expected, received, testNum, name)
231 
232  IMPLICIT NONE
233 
234 ! Declare Arguments
235  LOGICAL :: check
236  REAL(rprec), INTENT(in) :: expected, received
237  INTEGER, INTENT(in) :: testnum
238  CHARACTER (LEN=*), INTENT(in) :: name
239 
240 ! Start of executable code
241  check = expected .eq. received
242  IF (.not.check) THEN
243  write(*,*) "functions.f: ", name, " test", testnum, &
244  & "failed."
245  write(*,*) "Expected", expected, "Received", received
246  END IF
247 
248  END FUNCTION
249 
250  END MODULE
functions
This module containes functions used by the profiles.
Definition: functions.f:10