V3FIT
limiter_iso_T.f
Go to the documentation of this file.
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
9 !*******************************************************************************
11 
12  USE stel_kinds, only : rprec, cprec
13  USE v3_utilities
14  USE limiter
15 
16  IMPLICIT NONE
17 
18 !*******************************************************************************
19 ! DERIVED-TYPE DECLARATIONS
20 ! 1) extcurz base class
21 !
22 !*******************************************************************************
23 !-------------------------------------------------------------------------------
42 !-------------------------------------------------------------------------------
43  TYPE, EXTENDS(limiter_class) :: limiter_iso_class
45  REAL (rprec), DIMENSION(0:4,0:4) :: arz
47  REAL (rprec) :: rc
49  REAL (rprec) :: zc
51  INTEGER :: numin
52  CONTAINS
53  PROCEDURE :: &
54  & get_max_fval => limiter_iso_get_max_fval
55  PROCEDURE :: &
56  & get_type => limiter_iso_get_type
57  PROCEDURE :: &
58  & get_value => limiter_iso_get_value
59  final :: limiter_iso_destruct
60  END TYPE
61 
62 !*******************************************************************************
63 ! INTERFACE BLOCKS
64 !*******************************************************************************
65 !-------------------------------------------------------------------------------
67 !-------------------------------------------------------------------------------
68  INTERFACE limiter_iso_class
69  MODULE PROCEDURE limiter_iso_construct
70  END INTERFACE
71 
72  CONTAINS
73 !*******************************************************************************
74 ! CONSTRUCTION SUBROUTINES
75 !*******************************************************************************
76 !-------------------------------------------------------------------------------
91 !-------------------------------------------------------------------------------
92  FUNCTION limiter_iso_construct(arz, rc, zc, numin, vgrid, on_edge)
93 
94  IMPLICIT NONE
95 
96 ! Declare Arguments
97  class(limiter_iso_class), POINTER :: limiter_iso_construct
98  REAL (rprec), DIMENSION(0:4,0:4), INTENT(in) :: arz
99  REAL (rprec), INTENT(in) :: rc
100  REAL (rprec), INTENT(in) :: zc
101  INTEGER, INTENT(in) :: numin
102  REAL (rprec), DIMENSION(:), INTENT(in) :: vgrid
103  LOGICAL, INTENT(in) :: on_edge
104 
105 ! local variables
106  REAL (rprec) :: start_time
107 
108 ! Start of executable code
109  start_time = profiler_get_start_time()
110 
111 ! First, destroy this
112  ALLOCATE(limiter_iso_construct)
113 
114  limiter_iso_construct%arz = arz
115  limiter_iso_construct%rc = rc
116  limiter_iso_construct%zc = zc
117  limiter_iso_construct%numin = numin
118  limiter_iso_construct%on_edge = on_edge
119 
120  ALLOCATE(limiter_iso_construct%phi(SIZE(vgrid)))
121  limiter_iso_construct%phi = vgrid
122 
123  CALL profiler_set_stop_time('limiter_iso_construct', start_time)
124 
125  END FUNCTION
126 
127 !*******************************************************************************
128 ! DESTRUCTION SUBROUTINES
129 !*******************************************************************************
130 !-------------------------------------------------------------------------------
136 !-------------------------------------------------------------------------------
137  SUBROUTINE limiter_iso_destruct(this)
138 
139  IMPLICIT NONE
140 
141 ! Declare Arguments
142  TYPE (limiter_iso_class), INTENT(inout) :: this
143 
144 ! Start of executable code
145 
146 ! Get rid of all components
147  CALL limiter_destruct(this)
148 
149  this%arz = 0.0
150  this%rc = 0.0
151  this%zc = 0.0
152  this%numin = 0
153 
154  END SUBROUTINE
155 
156 !*******************************************************************************
157 ! GETTER SUBROUTINES
158 !*******************************************************************************
159 !-------------------------------------------------------------------------------
169 !-------------------------------------------------------------------------------
170  FUNCTION limiter_iso_get_max_fval(this, num_theta, phi_index, &
171  & r, z, rphiz_at_max)
172 
173  IMPLICIT NONE
174 
175 ! Declare Arguments
176  REAL (rprec) :: limiter_iso_get_max_fval
177  class(limiter_iso_class), INTENT(in) :: this
178  INTEGER, INTENT(in) :: num_theta
179  INTEGER, INTENT(in) :: phi_index
180  REAL (rprec), DIMENSION(:), INTENT(in) :: r
181  REAL (rprec), DIMENSION(:), INTENT(in) :: z
182  REAL (rprec), DIMENSION(3), INTENT(out) :: rphiz_at_max
183 
184 ! local variables
185  INTEGER :: theta_index
186  REAL (rprec) :: fval
187  REAL (rprec) :: start_time
188 
189 ! Start of executable code
190  start_time = profiler_get_start_time()
191 
192  limiter_iso_get_max_fval = -1.0e10
193  rphiz_at_max = 0.0
194 
195  DO theta_index = 1, num_theta
196  fval = this%get_value(r(theta_index), z(theta_index))
197 
198  IF (fval .gt. limiter_iso_get_max_fval) THEN
200  rphiz_at_max = (/ r(theta_index), this%phi(phi_index), &
201  & z(theta_index) /)
202  END IF
203  END DO
204 
205  CALL profiler_set_stop_time('limiter_iso_get_max_fval', &
206  & start_time)
207 
208  END FUNCTION
209 
210 !-------------------------------------------------------------------------------
223 !-------------------------------------------------------------------------------
224  FUNCTION limiter_iso_get_value(this, r, z)
225 
226  IMPLICIT NONE
227 
228 ! Declare Arguments
229  REAL (rprec) :: limiter_iso_get_value
230  class(limiter_iso_class), INTENT(in) :: this
231  REAL (rprec), INTENT(in) :: r
232  REAL (rprec), INTENT(in) :: z
233 
234 ! local variables
235  REAL (rprec) :: e
236  REAL (rprec) :: er
237  REAL (rprec) :: ez
238  REAL (rprec) :: grad_e
239  INTEGER :: i
240  INTEGER :: j
241  REAL (rprec) :: start_time
242 
243 ! Start of executable code
244  start_time = profiler_get_start_time()
245 
246 ! Compute function
247  e = 0.0
248  DO i = 0, 4
249  DO j = 0, 4
250  e = e &
251  & + this%arz(i,j)*((r - this%rc)**i)*((z - this%zc)**j)
252  END DO
253  END DO
254 
255 ! Compute de/dr
256  er = 0.0
257  DO i = 1, 4
258  DO j = 0, 4
259  er = er &
260  & + this%arz(i,j)*i*((r - this%rc)**(i-1)) * &
261  & ((z - this%zc)**j)
262  END DO
263  END DO
264 
265 ! Compute de/dz
266  ez = 0.0
267  DO i = 0, 4
268  DO j = 1, 4
269  ez = ez &
270  & + this%arz(i,j)*j*((r - this%rc)**i) * &
271  & ((z - this%zc)**(j - 1))
272  END DO
273  END DO
274 
275 ! Avoid divide by zero errors.
276  grad_e = max(1.e-12, sqrt(er*er + ez*ez))
277 
278  limiter_iso_get_value = e/grad_e
279 
280  CALL profiler_set_stop_time('limiter_iso_get_value', start_time)
281 
282  END FUNCTION
283 
284 !-------------------------------------------------------------------------------
291 !-------------------------------------------------------------------------------
292  FUNCTION limiter_iso_get_type(this)
294 
295  IMPLICIT NONE
296 
297 ! Declare Arguments
298  CHARACTER (len=data_name_length) :: limiter_iso_get_type
299  class(limiter_iso_class), INTENT(in) :: this
300 
301 ! local variables
302  REAL (rprec) :: start_time
303 
304 ! Start of executable code
305  start_time = profiler_get_start_time()
306 
308  & trim(this%limiter_class%get_type()) // 'iso'
309 
310  CALL profiler_set_stop_time('limiter_iso_get_type', start_time)
311 
312  END FUNCTION
313 
314  END MODULE
limiter_iso_t::limiter_iso_get_type
character(len=data_name_length) function limiter_iso_get_type(this)
Gets a discription of the limiter iso type.
Definition: limiter_iso_T.f:293
limiter_iso_t::limiter_iso_get_value
real(rprec) function limiter_iso_get_value(this, r, z)
Computes the iso value at an r, phi, z position.
Definition: limiter_iso_T.f:225
limiter::limiter_class
Base class representing a limiter signal.
Definition: limiter.f:35
limiter_iso_t::limiter_iso_construct
class(limiter_iso_class) function, pointer limiter_iso_construct(arz, rc, zc, numin, vgrid, on_edge)
Construct a limiter iso function.
Definition: limiter_iso_T.f:93
limiter::limiter_destruct
subroutine limiter_destruct(this)
Deconstruct a limiter_class object.
Definition: limiter.f:69
limiter_iso_t::limiter_iso_get_max_fval
real(rprec) function limiter_iso_get_max_fval(this, num_theta, phi_index, r, z, rphiz_at_max)
Calculates the maximum value of the iso function.
Definition: limiter_iso_T.f:172
data_parameters
This modules contains parameters used by equilibrium models.
Definition: data_parameters.f:10
limiter
Defines the base class of the type limiter_class.
Definition: limiter.f:15
limiter_iso_t::limiter_iso_destruct
subroutine limiter_iso_destruct(this)
Deconstruct a limiter_iso object.
Definition: limiter_iso_T.f:138
limiter_iso_t::limiter_iso_class
Base class representing a limiter_iso function.
Definition: limiter_iso_T.f:43
limiter_iso_t
Defines the base class of the type limiter_iso.
Definition: limiter_iso_T.f:10