V3FIT
ece.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 !
11 !*******************************************************************************
12 
13  MODULE ece
14 
15  USE stel_kinds, only: rprec
17  USE signal
18 
19  IMPLICIT NONE
20 
21 !*******************************************************************************
22 ! DERIVED-TYPE DECLARATIONS
23 ! 1) ece base class
24 ! 2) ece context
25 !
26 !*******************************************************************************
27 !-------------------------------------------------------------------------------
31 !-------------------------------------------------------------------------------
32  TYPE, EXTENDS(signal_class) :: ece_class
34  TYPE (vertex), POINTER :: chord_path => null()
36  REAL (rprec) :: resonance
37  CONTAINS
38  PROCEDURE :: &
39  & get_modeled_signal_last => ece_get_modeled_signal
40  PROCEDURE :: get_cart => ece_get_cart
41  PROCEDURE :: &
42  & get_type => ece_get_type
43  PROCEDURE :: get_header => ece_get_header
44  PROCEDURE :: get_gp_i => ece_get_gp_i
45  PROCEDURE :: get_gp_s => ece_get_gp_s
46  PROCEDURE :: get_gp_x => ece_get_gp_x
47  final :: ece_destruct
48  END TYPE ece_class
49 
50 !-------------------------------------------------------------------------------
52 !-------------------------------------------------------------------------------
55  REAL (rprec) :: resonance
57  TYPE (model_class), POINTER :: model => null()
58  END TYPE
59 
60 !*******************************************************************************
61 ! INTERFACE BLOCKS
62 !*******************************************************************************
63 !-------------------------------------------------------------------------------
65 !-------------------------------------------------------------------------------
66  INTERFACE ece_class
67  MODULE PROCEDURE ece_construct
68  END INTERFACE
69 
70  PRIVATE :: ece_function, is_in_range
71 
72  CONTAINS
73 !*******************************************************************************
74 ! CONSTRUCTION SUBROUTINES
75 !*******************************************************************************
76 !-------------------------------------------------------------------------------
85 !-------------------------------------------------------------------------------
86  FUNCTION ece_construct(start_path, end_path, resonance)
87 
88  IMPLICIT NONE
89 
90 ! Declare Arguments
91  class(ece_class), POINTER :: ece_construct
92  REAL (rprec), DIMENSION(3), INTENT(in) :: start_path
93  REAL (rprec), DIMENSION(3), INTENT(in) :: end_path
94  REAL (rprec), INTENT(in) :: resonance
95 
96 ! local variables
97  REAL (rprec) :: start_time
98 
99 ! Start of executable code
100  start_time = profiler_get_start_time()
101 
102  ALLOCATE(ece_construct)
103 
104  CALL path_append_vertex(ece_construct%chord_path, start_path)
105  CALL path_append_vertex(ece_construct%chord_path, end_path)
106 
107  ece_construct%resonance = resonance
108 
109  CALL profiler_set_stop_time('ece_construct', start_time)
110 
111  END FUNCTION
112 
113 !*******************************************************************************
114 ! DESTRUCTION SUBROUTINES
115 !*******************************************************************************
116 !-------------------------------------------------------------------------------
122 !-------------------------------------------------------------------------------
123  SUBROUTINE ece_destruct(this)
124 
125  IMPLICIT NONE
126 
127 ! Declare Arguments
128  TYPE (ece_class), INTENT(inout) :: this
129 
130 ! Start of executable code
131  IF (ASSOCIATED(this%chord_path)) THEN
132  CALL path_destruct(this%chord_path)
133  this%chord_path => null()
134  END IF
135 
136  END SUBROUTINE
137 
138 !*******************************************************************************
139 ! GETTER SUBROUTINES
140 !*******************************************************************************
141 !-------------------------------------------------------------------------------
152 !-------------------------------------------------------------------------------
153  FUNCTION ece_get_modeled_signal(this, a_model, sigma, last_value)
154 
155  IMPLICIT NONE
156 
157 ! Declare Arguments
158  REAL (rprec), DIMENSION(4) :: ece_get_modeled_signal
159  class(ece_class), INTENT(inout) :: this
160  TYPE (model_class), POINTER :: a_model
161  REAL (rprec), DIMENSION(4), INTENT(out) :: sigma
162  REAL (rprec), DIMENSION(4), INTENT(in) :: last_value
163 
164 ! local variables
165  LOGICAL :: found
166  REAL (rprec) :: start_time
167 
168 ! Start of executable code
169  start_time = profiler_get_start_time()
170 
171  sigma = 0.0
172 
173  IF (btest(a_model%state_flags, model_state_vmec_flag) .or. &
174  & btest(a_model%state_flags, model_state_siesta_flag) .or. &
175  & btest(a_model%state_flags, model_state_te_flag) .or. &
176  & btest(a_model%state_flags, model_state_shift_flag) .or. &
177  & btest(a_model%state_flags, model_state_signal_flag)) THEN
178 
179  ece_get_modeled_signal(2:4) = this%get_cart(a_model, found)
180 
181  IF (found) THEN
183  & model_get_te(a_model, ece_get_modeled_signal(2:4))
184  ELSE
185  ece_get_modeled_signal(1) = 0.0
186  END IF
187 
188  CALL this%scale_and_offset(a_model, ece_get_modeled_signal(1))
189  ELSE
190  ece_get_modeled_signal = last_value
191  END IF
192 
193  CALL profiler_set_stop_time('ece_get_modeled_signal', start_time)
194 
195  END FUNCTION
196 
197 !-------------------------------------------------------------------------------
207 !-------------------------------------------------------------------------------
208  FUNCTION ece_get_cart(this, a_model, found)
209 
210  IMPLICIT NONE
211 
212 ! Declare Arguments
213  REAL (rprec), DIMENSION(3) :: ece_get_cart
214  class(ece_class), INTENT(in) :: this
215  TYPE (model_class), POINTER :: a_model
216  LOGICAL, INTENT(out) :: found
217 
218 ! local variables
219  CHARACTER(len=1), ALLOCATABLE :: context(:)
220  INTEGER :: context_length
221  TYPE (ece_context) :: temp_context
222  REAL (rprec) :: start_time
223 
224 ! Start of executable code
225  start_time = profiler_get_start_time()
226 
227 ! The relevant data for the ece context.
228  temp_context%resonance = this%resonance
229  temp_context%model => a_model
230 
231 ! Cast model into a data to a context. This is the equivalent to casting to a
232 ! void pointer in C.
233  context_length = SIZE(transfer(temp_context, context))
234  ALLOCATE(context(context_length))
235  context = transfer(temp_context, context)
236 
237  ece_get_cart = path_search(this%chord_path, ece_function, context, &
238  & found)
239 
240  DEALLOCATE(context)
241 
242  CALL profiler_set_stop_time('ece_get_cart', start_time)
243 
244  END FUNCTION
245 
246 !-------------------------------------------------------------------------------
253 !-------------------------------------------------------------------------------
254  FUNCTION ece_get_type(this)
256 
257  IMPLICIT NONE
258 
259 ! Declare Arguments
260  CHARACTER (len=data_name_length) :: ece_get_type
261  class(ece_class), INTENT(in) :: this
262 
263 ! local variables
264  REAL (rprec) :: start_time
265 
266 ! Start of executable code
267  start_time = profiler_get_start_time()
268 
269  ece_get_type = 'ece'
270 
271  CALL profiler_set_stop_time('ece_get_type', start_time)
272 
273  END FUNCTION
274 
275 !-------------------------------------------------------------------------------
284 !-------------------------------------------------------------------------------
285  SUBROUTINE ece_get_header(this, header)
287 
288  IMPLICIT NONE
289 
290 ! Declare Arguments
291  class(ece_class), INTENT(in) :: this
292  CHARACTER (len=data_name_length), DIMENSION(7), INTENT(inout) :: &
293  & header
294 
295 ! local variables
296  REAL (rprec) :: start_time
297 
298 ! Start of executable code
299  start_time = profiler_get_start_time()
300 
301  header(1) = 'x (m)'
302  header(2) = 'y (m)'
303  header(3) = 'z (m)'
304 
305  header(4) = 'model_sig(1)'
306  header(5) = 'model_sig(2)'
307  header(6) = 'model_sig(3)'
308  header(7) = 'model_sig(4)'
309 
310  CALL profiler_set_stop_time('ece_get_header', start_time)
311 
312  END SUBROUTINE
313 
314 !-------------------------------------------------------------------------------
325 !-------------------------------------------------------------------------------
326  FUNCTION ece_get_gp_i(this, a_model, i, flags)
327 
328  IMPLICIT NONE
329 
330 ! Declare Arguments
331  REAL (rprec) :: ece_get_gp_i
332  class(ece_class), INTENT(in) :: this
333  TYPE (model_class), POINTER :: a_model
334  INTEGER, INTENT(in) :: i
335  INTEGER, INTENT(in) :: flags
336 
337 ! local variables
338  REAL (rprec), DIMENSION(3) :: x_cart
339  LOGICAL :: found
340  REAL (rprec) :: start_time
341 
342 ! Start of executable code
343  start_time = profiler_get_start_time()
344 
345  x_cart = this%get_cart(a_model, found)
346  IF (found) THEN
347  ece_get_gp_i = model_get_gp_te(a_model, x_cart, i)
348  ELSE
349  ece_get_gp_i = 0.0
350  END IF
351 
352  CALL this%scale_and_offset(a_model, ece_get_gp_i)
353 
354  CALL profiler_set_stop_time('ece_get_gp_i', start_time)
355 
356  END FUNCTION
357 
358 !-------------------------------------------------------------------------------
369 !-------------------------------------------------------------------------------
370  FUNCTION ece_get_gp_s(this, a_model, signal, flags)
371 
372  IMPLICIT NONE
373 
374 ! Declare Arguments
375  REAL (rprec) :: ece_get_gp_s
376  class(ece_class), INTENT(in) :: this
377  TYPE (model_class), POINTER :: a_model
378  class(signal_class), POINTER :: signal
379  INTEGER, INTENT(in) :: flags
380 
381 ! local variables
382  REAL (rprec), DIMENSION(3) :: x_cart
383  LOGICAL :: found
384  REAL (rprec) :: start_time
385 
386 ! Start of executable code
387  start_time = profiler_get_start_time()
388 
389  x_cart = this%get_cart(a_model, found)
390  IF (found) THEN
391  ece_get_gp_s = signal%get_gp(a_model, x_cart, flags)
392  ELSE
393  ece_get_gp_s = 0.0
394  END IF
395 
396  CALL this%scale_and_offset(a_model, ece_get_gp_s)
397 
398  CALL profiler_set_stop_time('ece_get_gp_s', start_time)
399 
400  END FUNCTION
401 
402 !-------------------------------------------------------------------------------
416 !-------------------------------------------------------------------------------
417  FUNCTION ece_get_gp_x(this, a_model, x_cart, flags)
418 
419  IMPLICIT NONE
420 
421 ! Declare Arguments
422  REAL (rprec) :: ece_get_gp_x
423  class(ece_class), INTENT(in) :: this
424  TYPE (model_class), POINTER :: a_model
425  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
426  INTEGER, INTENT(in) :: flags
427 
428 ! local variables
429  REAL (rprec), DIMENSION(3) :: y_cart
430  LOGICAL :: found
431  REAL (rprec) :: start_time
432 
433 ! Start of executable code
434  start_time = profiler_get_start_time()
435 
436  y_cart = this%get_cart(a_model, found)
437  IF (found) THEN
438  ece_get_gp_x = model_get_gp_te(a_model, y_cart, x_cart)
439  ELSE
440  ece_get_gp_x = 0.0
441  END IF
442 
443  CALL this%scale_and_offset(a_model, ece_get_gp_x)
444 
445  CALL profiler_set_stop_time('ece_get_gp_x', start_time)
446 
447  END FUNCTION
448 
449 !*******************************************************************************
450 ! PRIVATE
451 !*******************************************************************************
452 !-------------------------------------------------------------------------------
464 !-------------------------------------------------------------------------------
465  FUNCTION ece_function(context, xcart1, xcart2)
467 
468  IMPLICIT NONE
469 
470 ! Declare Arguments
471  CHARACTER (len=1), INTENT(in) :: context(:)
472  REAL (rprec), DIMENSION(3), INTENT(in) :: xcart1
473  REAL (rprec), DIMENSION(3), INTENT(in) :: xcart2
474  LOGICAL :: ece_function
475 
476 ! local variables
477  TYPE (ece_context) :: temp_context
478  REAL (rprec), DIMENSION(3) :: bcart1
479  REAL (rprec), DIMENSION(3) :: bcart2
480  REAL (rprec) :: bmod1
481  REAL (rprec) :: bmod2
482  REAL (rprec) :: start_time
483 
484 ! Start of executable code
485  start_time = profiler_get_start_time()
486 
487  ece_function = .false.
488 
489  temp_context = transfer(context, temp_context)
490 
491  bcart1 = equilibrium_get_b_vec(temp_context%model%equilibrium, &
492  & xcart1, .false.)
493  bcart2 = equilibrium_get_b_vec(temp_context%model%equilibrium, &
494  & xcart2, .false.)
495 
496  bmod1 = sqrt(dot_product(bcart1, bcart1))
497  bmod2 = sqrt(dot_product(bcart2, bcart2))
498 
499  IF (abs(bmod1 - bmod2) .lt. &
500  & temp_context%model%resonace_range) THEN
501  ece_function = is_in_range(temp_context%resonance, &
502  & bmod1, bmod2)
503  END IF
504 
505  CALL profiler_set_stop_time('ece_function', start_time)
506 
507  END FUNCTION
508 
509 !-------------------------------------------------------------------------------
518 !-------------------------------------------------------------------------------
519  PURE FUNCTION is_in_range(xp, x1, x2)
520 
521  IMPLICIT NONE
522 
523 ! Declare Arguments
524  LOGICAL :: is_in_range
525  REAL(rprec), INTENT(in) :: xp
526  REAL(rprec), INTENT(in) :: x1
527  REAL(rprec), INTENT(in) :: x2
528 
529 ! Start of executable code
530  IF (x1 .gt. x2) THEN
531  is_in_range = xp .ge. x2 .and. xp .le. x1
532  ELSE
533  is_in_range = xp .ge. x1 .and. xp .le. x2
534  END IF
535 
536  END FUNCTION
537 
538  END MODULE
coordinate_utilities
Module is part of the LIBSTELL. This modules containes code to convert from different coordinate syst...
Definition: coordinate_utilities.f:12
ece::ece_get_modeled_signal
real(rprec) function, dimension(4) ece_get_modeled_signal(this, a_model, sigma, last_value)
Calculates the modeled signal.
Definition: ece.f:154
ece::ece_get_gp_x
real(rprec) function ece_get_gp_x(this, a_model, x_cart, flags)
Gets the guassian process kernel for an ece signal and a cartesian position.
Definition: ece.f:418
ece::ece_class
Base class representing an ECE signal.
Definition: ece.f:32
model
Defines the base class of the type model_class. The model contains information not specific to the eq...
Definition: model.f:59
ece::ece_context
Structure to hold all memory needed to be sent to the callback function.
Definition: ece.f:53
vertex
A vertex.
Definition: vertex.hpp:21
ece::ece_destruct
subroutine ece_destruct(this)
Deconstruct a ece_class object.
Definition: ece.f:124
ece::ece_get_gp_s
real(rprec) function ece_get_gp_s(this, a_model, signal, flags)
Gets the guassian process kernel for a ece signal and a signal.
Definition: ece.f:371
integration_path
Module is part of the LIBSTELL. This modules contains code to define and integrate along an arbitray ...
Definition: integration_path.f:12
ece::ece_construct
class(ece_class) function, pointer ece_construct(start_path, end_path, resonance)
Construct a ece_class object.
Definition: ece.f:87
integration_path::path_append_vertex
recursive subroutine path_append_vertex(this, position)
Append a vertex to a path.
Definition: integration_path.f:253
integration_path::path_search
recursive real(rprec) function, dimension(3) path_search(path, search_function, context, found)
Search along the path.
Definition: integration_path.f:344
ece::ece_function
logical function, private ece_function(context, xcart1, xcart2)
ECE callback function.
Definition: ece.f:466
ece::ece_get_gp_i
real(rprec) function ece_get_gp_i(this, a_model, i, flags)
Gets the guassian process kernel for an ece signal and a position.
Definition: ece.f:327
ece::ece_get_header
subroutine ece_get_header(this, header)
Gets a discription of the model and model sigma array indices.
Definition: ece.f:286
data_parameters
This modules contains parameters used by equilibrium models.
Definition: data_parameters.f:10
ece::ece_get_type
character(len=data_name_length) function ece_get_type(this)
Gets a discription of the ece type.
Definition: ece.f:255
ece
Defines the base class of the type ece_class.
Definition: ece.f:13
ece::ece_get_cart
real(rprec) function, dimension(3) ece_get_cart(this, a_model, found)
Calculates the signal measurement point.
Definition: ece.f:209
signal::signal_class
Base class representing a signal.
Definition: signal.f:33
integration_path::path_destruct
Destruct interface using either path_destruct_int or path_destruct_vertex.
Definition: integration_path.f:84
signal
Defines the base class of the type signal_class.
Definition: signal.f:14
ece::is_in_range
pure logical function, private is_in_range(xp, x1, x2)
Check if values is in range.
Definition: ece.f:520