V3FIT
vacuum_equilibrium.f
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! The @header, @table_section, @table_subsection, @item and @end_table commands
3 ! are custom defined commands in Doxygen.in. They are defined under ALIASES.
4 ! For the page created here, the 80 column limit is exceeded. Arguments of
5 ! aliases are separated by ','. If you intended ',' to be a string you must use
6 ! an escaped comma '\,'.
7 !
21 !*******************************************************************************
24 !
25 ! Note separating the Doxygen comment block here so detailed decription is
26 ! found in the Module not the file.
27 !
32 !*******************************************************************************
33 
35  USE stel_kinds
36  USE data_parameters
37  USE biotsavart
38  USE mpi_inc
39  USE profiler
40 
41  IMPLICIT NONE
42 
43 !*******************************************************************************
44 ! vacuum equilibrium module parameters
45 !*******************************************************************************
46 ! Define id's only for values that can change. All others shouldn't be needed
47 ! outside of the vacuum interface. Parameter id's start at 14 since 0-13 are
48 ! reserved for non equilibrium model parameters. These numbers will need to be
49 ! updated if any new model parameters are added.
50 
51 ! Variable Parameters
53  INTEGER, PARAMETER :: vacuum_extcur_id = 15
54 
55 !*******************************************************************************
56 ! DERIVED-TYPE DECLARATIONS
57 ! 1) vacuum base class
58 !
59 !*******************************************************************************
60 !-------------------------------------------------------------------------------
64 !-------------------------------------------------------------------------------
67  CHARACTER (len=path_length) :: vacuum_file_name
69  REAL (rprec), DIMENSION(:), POINTER :: extcur => null()
70  END TYPE
71 
72  CONTAINS
73 !*******************************************************************************
74 ! CONSTRUCTION SUBROUTINES
75 !*******************************************************************************
76 !-------------------------------------------------------------------------------
83 !-------------------------------------------------------------------------------
84  FUNCTION vacuum_construct(file_name, iou)
86 
87  IMPLICIT NONE
88 
89 ! Declare Arguments
90  TYPE (vacuum_class), POINTER :: vacuum_construct
91  CHARACTER (len=*), INTENT(in) :: file_name
92  INTEGER, INTENT(in) :: iou
93 
94 ! local variables
95  TYPE (bsc_rs) :: bsc_rs_object
96  REAL (rprec), DIMENSION(3) :: center, mean_r
97  REAL (rprec) :: total_current
98  INTEGER :: i, j
99  REAL (rprec) :: start_time
100 
101 ! Start of executable code
102  start_time = profiler_get_start_time()
103 
104  WRITE (*,*) ' *** Initializing vacuum equilibrium from file ' // &
105  & trim(file_name)
106  WRITE (iou,*) ' *** Initializing vacuum equilibrium from file ' // &
107  & trim(file_name)
108 
109  ALLOCATE(vacuum_construct)
110 
111  vacuum_construct%vacuum_file_name = file_name
112  CALL vacuum_input_read_namelist(file_name)
113 
114  ALLOCATE(vacuum_construct%extcur(n_extcur))
115  vacuum_construct%extcur = extcur(1:n_extcur)
116 
117  CALL parse_coils_file(coils_dot_file)
118 
119  DO i = 1, SIZE(vacuum_construct%extcur)
120 
121 ! Compute the current averaged center of the coil group.
122  center = 0.0
123  total_current = 0.0
124  IF (l_rot_coil_center(i)) THEN
125  center = cg_rot_xcent(i,:)
126  ELSE
127  DO j = 1, coil_group(i)%ncoil
128  total_current = total_current &
129  & + coil_group(i)%coils(j)%current
130  CALL bsc_mean_r(coil_group(i)%coils(j), mean_r)
131  center = center + mean_r*coil_group(i)%coils(j)%current
132  END DO
133  IF (total_current .ne. 0.0) THEN
134  center = center/total_current
135  END IF
136  END IF
137 
138 ! Generate bsc_rs for first shift, and apply it.
139  CALL bsc_construct_rs(bsc_rs_object, 0.0_dp, 0.0_dp, 0.0_dp, &
140  & (/ 0.0_dp, 0.0_dp, 0.0_dp /), &
141  & cg_shift_1(i,:))
142  CALL bsc_rot_shift(coil_group(i), bsc_rs_object)
143 
144 ! Generate bsc_rs for second shift, and apply it.
145  CALL bsc_construct_rs(bsc_rs_object, cg_rot_theta(i), &
146  & cg_rot_phi(i), cg_rot_angle(i), &
147  & center, cg_shift_2(i,:))
148  CALL bsc_rot_shift(coil_group(i), bsc_rs_object)
149  END DO
150 
151  CALL profiler_set_stop_time('vacuum_construct', start_time)
152 
153  END FUNCTION
154 
155 !*******************************************************************************
156 ! DESTRUCTION SUBROUTINES
157 !*******************************************************************************
158 !-------------------------------------------------------------------------------
164 !-------------------------------------------------------------------------------
165  SUBROUTINE vacuum_destruct(this)
166 
167  IMPLICIT NONE
168 
169 ! Declare Arguments
170  TYPE (vacuum_class), POINTER :: this
171 
172 ! Start of executable code
173  IF (ASSOCIATED(this%extcur)) THEN
174  DEALLOCATE(this%extcur)
175  this%extcur => null()
176  END IF
177 
178  DEALLOCATE(this)
179 
180  END SUBROUTINE
181 
182 !*******************************************************************************
183 ! SETTER SUBROUTINES
184 !*******************************************************************************
185 !-------------------------------------------------------------------------------
196 !-------------------------------------------------------------------------------
197  SUBROUTINE vacuum_set_param(this, id, i_index, value)
198 
199  IMPLICIT NONE
200 
201 ! Declare Arguments
202  TYPE (vacuum_class), INTENT(inout) :: this
203  INTEGER, INTENT(in) :: id
204  INTEGER, INTENT(in) :: i_index
205  REAL (rprec), INTENT(in) :: value
206 
207 ! local variables
208  REAL (rprec) :: start_time
209 
210 ! Start of executable code
211  start_time = profiler_get_start_time()
212 
213  SELECT CASE (id)
214 
215  CASE (vacuum_extcur_id)
216  this%extcur(i_index) = value
217 
218  END SELECT
219 
220  CALL profiler_set_stop_time('vacuum_set_param', start_time)
221 
222  END SUBROUTINE
223 
224 !*******************************************************************************
225 ! GETTER SUBROUTINES
226 !*******************************************************************************
227 !-------------------------------------------------------------------------------
235 !-------------------------------------------------------------------------------
236  FUNCTION vacuum_get_param_id(this, param_name)
237 
238  IMPLICIT NONE
239 
240 ! Declare Arguments
241  INTEGER :: vacuum_get_param_id
242  TYPE (vacuum_class), INTENT(in) :: this
243  CHARACTER (len=*), INTENT(in) :: param_name
244 
245 ! local variables
246  REAL (rprec) :: start_time
247 
248 ! Start of executable code
249  start_time = profiler_get_start_time()
250 
251  SELECT CASE (trim(param_name))
252 
253  CASE ('extcur')
255 
256  CASE DEFAULT
257  WRITE (*,1000) trim(param_name)
258  CALL exit(1)
259 
260  END SELECT
261 
262  CALL profiler_set_stop_time('vacuum_get_param_id', start_time)
263 
264 1000 FORMAT('ERROR: ',a,' is not a valid parameter.')
265 
266  END FUNCTION
267 
268 !-------------------------------------------------------------------------------
277 !-------------------------------------------------------------------------------
278  FUNCTION vacuum_get_param_value(this, id, i_index)
279 
280  IMPLICIT NONE
281 
282 ! Declare Arguments
283  REAL (rprec) :: vacuum_get_param_value
284  TYPE (vacuum_class), INTENT(in) :: this
285  INTEGER, INTENT(in) :: id
286  INTEGER, INTENT(in) :: i_index
287 
288 ! local variables
289  REAL (rprec) :: start_time
290 
291 ! Start of executable code
292  start_time = profiler_get_start_time()
293 
294  SELECT CASE (id)
295 
296  CASE (vacuum_extcur_id)
297  vacuum_get_param_value = this%extcur(i_index)
298 
299  CASE DEFAULT
301 
302  END SELECT
303 
304  CALL profiler_set_stop_time('vacuum_get_param_value', start_time)
305 
306  END FUNCTION
307 
308 !-------------------------------------------------------------------------------
316 !-------------------------------------------------------------------------------
317  FUNCTION vacuum_get_param_name(this, id)
318 
319  IMPLICIT NONE
320 
321 ! Declare Arguments
322  CHARACTER(len=data_name_length) :: vacuum_get_param_name
323  TYPE (vacuum_class), INTENT(in) :: this
324  INTEGER, INTENT(in) :: id
325 
326 ! local variables
327  REAL (rprec) :: start_time
328 
329 ! Start of executable code
330  start_time = profiler_get_start_time()
331 
332  SELECT CASE (id)
333 
334  CASE (vacuum_extcur_id)
335  vacuum_get_param_name = 'extcur'
336 
337  CASE DEFAULT
338  stop 'Invalid vacuum parameter id.'
339 
340  END SELECT
341 
342  CALL profiler_set_stop_time('vacuum_get_param_name', start_time)
343 
344  END FUNCTION
345 
346 !-------------------------------------------------------------------------------
356 !-------------------------------------------------------------------------------
357  FUNCTION vacuum_get_b_vec(this, x_cart, cyl)
359 
360  IMPLICIT NONE
361 
362 ! Declare Arguments
363  REAL (rprec), DIMENSION(3) :: vacuum_get_b_vec
364  TYPE (vacuum_class), INTENT(in) :: this
365  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
366  LOGICAL, INTENT(in) :: cyl
367 
368 ! local variables
369  INTEGER :: i
370  REAL (rprec), DIMENSION(3) :: b_vec
371  REAL (rprec) :: start_time
372 
373 ! Start of executable code
374  start_time = profiler_get_start_time()
375 
376  vacuum_get_b_vec = 0.0
377  DO i = 1, SIZE(this%extcur)
378  CALL bsc_b(coil_group(i), x_cart, b_vec, this%extcur(i))
380  END DO
381 
382  IF (cyl) THEN
384  END IF
385 
386  CALL profiler_set_stop_time('vacuum_get_B_vec', start_time)
387 
388  END FUNCTION
389 
390 !-------------------------------------------------------------------------------
402 !-------------------------------------------------------------------------------
403  FUNCTION vacuum_get_int_b_dphi(this, r, theta)
404  USE stel_constants, only: twopi
406 
407  IMPLICIT NONE
408 
409 ! Declare Arguments
410  REAL (rprec) :: vacuum_get_int_b_dphi
411  TYPE (vacuum_class), INTENT(in) :: this
412  REAL (rprec), INTENT(in) :: r
413  REAL (rprec), INTENT(in) :: theta
414 
415 ! local variables
416  REAL (rprec), DIMENSION(3) :: b_cart
417  REAL (rprec), DIMENSION(3) :: r_cyl
418  REAL (rprec), DIMENSION(3) :: dl
419  REAL (rprec) :: dphi
420  REAL (rprec) :: start_time
421 
422 ! Start of executable code
423  start_time = profiler_get_start_time()
424 
426 
427  r_cyl(1) = r*cos(theta)
428  r_cyl(2) = 0.0
429  r_cyl(3) = r*sin(theta)
430 
431  dphi = 0.001/r_cyl(1)
432  DO WHILE (r_cyl(2) .lt. twopi)
433  dl = cyl_to_cart_vec(r_cyl, (/ 0.0_dp, dphi, 0.0_dp /))
434  b_cart = vacuum_get_b_vec(this, cyl_to_cart(r_cyl), .false.)
436  & + dot_product(b_cart, dl)
437  r_cyl(2) = r_cyl(2) + dphi
438  END DO
439 
440  CALL profiler_set_stop_time('vacuum_get_Int_B_dphi', start_time)
441 
442  END FUNCTION
443 
444 !-------------------------------------------------------------------------------
455 !-------------------------------------------------------------------------------
456  FUNCTION vacuum_get_ext_currents(this, scale_currents)
457 
458  IMPLICIT NONE
459 
460 ! Declare Arguments
461  REAL (rprec), DIMENSION(:), POINTER :: vacuum_get_ext_currents
462  TYPE (vacuum_class), INTENT(in) :: this
463  LOGICAL, INTENT(out) :: scale_currents
464 
465 ! local variables
466  REAL (rprec) :: start_time
467 
468 ! Start of executable code
469  start_time = profiler_get_start_time()
470 
471  vacuum_get_ext_currents => this%extcur
472  scale_currents = .false.
473 
474  CALL profiler_set_stop_time('vacuum_get_ext_currents', start_time)
475 
476  END FUNCTION
477 
478 !*******************************************************************************
479 ! QUERY SUBROUTINES
480 !*******************************************************************************
481 !-------------------------------------------------------------------------------
489 !-------------------------------------------------------------------------------
490  FUNCTION vacuum_is_1d_array(this, id)
491 
492  IMPLICIT NONE
493 
494 ! Declare Arguments
495  LOGICAL :: vacuum_is_1d_array
496  TYPE (vacuum_class), INTENT(in) :: this
497  INTEGER, INTENT(in) :: id
498 
499 ! local variables
500  REAL (rprec) :: start_time
501 
502 ! Start of executable code
503  start_time = profiler_get_start_time()
504 
505  SELECT CASE (id)
506 
507  CASE (vacuum_extcur_id)
508  vacuum_is_1d_array = .true.
509 
510  CASE DEFAULT
511  vacuum_is_1d_array = .false.
512 
513  END SELECT
514 
515  CALL profiler_set_stop_time('vacuum_is_1d_array', start_time)
516 
517  END FUNCTION
518 
519 !-------------------------------------------------------------------------------
528 !-------------------------------------------------------------------------------
529  FUNCTION vacuum_is_recon_param(this, id)
530 
531  IMPLICIT NONE
532 
533 ! Declare Arguments
534  LOGICAL :: vacuum_is_recon_param
535  TYPE (vacuum_class), INTENT(in) :: this
536  INTEGER, INTENT(in) :: id
537 
538 ! local variables
539  REAL (rprec) :: start_time
540 
541 ! Start of executable code
542  start_time = profiler_get_start_time()
543 
544  SELECT CASE (id)
545 
546  CASE (vacuum_extcur_id)
547  vacuum_is_recon_param = .true.
548 
549  CASE DEFAULT
550  vacuum_is_recon_param = .false.
551 
552  END SELECT
553 
554  CALL profiler_set_stop_time('vacuum_is_recon_param', start_time)
555 
556  END FUNCTION
557 
558 !*******************************************************************************
559 ! UTILITY SUBROUTINES
560 !*******************************************************************************
561 !-------------------------------------------------------------------------------
568 !-------------------------------------------------------------------------------
569  SUBROUTINE vacuum_write(this, iou)
570 
571  IMPLICIT NONE
572 
573 ! Declare Arguments
574  TYPE (vacuum_class), INTENT(in) :: this
575  INTEGER, INTENT(in) :: iou
576 
577 ! local variables
578  REAL (rprec) :: start_time
579 
580 ! Start of executable code
581  start_time = profiler_get_start_time()
582 
583  WRITE (iou,*)
584  WRITE (iou,*) 'Equilibrium Type : vacuum'
585 
586  CALL profiler_set_stop_time('vacuum_write', start_time)
587 
588  END SUBROUTINE
589 
590 !-------------------------------------------------------------------------------
599 !-------------------------------------------------------------------------------
600  SUBROUTINE vacuum_write_input(this, current_step)
602 
603  IMPLICIT NONE
604 
605 ! Declare Arguments
606  TYPE (vacuum_class), INTENT(in) :: this
607  INTEGER, INTENT(in) :: current_step
608 
609 ! local variables
610  CHARACTER (len=path_length) :: filename
611  REAL (rprec) :: start_time
612 
613 ! Start of executable code
614  start_time = profiler_get_start_time()
615 
616  WRITE (filename,1000) trim(this%vacuum_file_name), current_step
617  CALL vacuum_input_write_namelist(trim(filename))
618 
619  CALL profiler_set_stop_time('vacuum_write_input', start_time)
620 
621 1000 FORMAT(a,'_',i0.3)
622 
623  END SUBROUTINE
624 
625  END MODULE
vacuum_equilibrium::vacuum_is_recon_param
logical function vacuum_is_recon_param(this, id)
Checks if a parameter id is a reconstruction parameter.
Definition: vacuum_equilibrium.f:530
profiler
Defines functions for measuring an tabulating performance of function and subroutine calls....
Definition: profiler.f:13
coordinate_utilities
Module is part of the LIBSTELL. This modules containes code to convert from different coordinate syst...
Definition: coordinate_utilities.f:12
vacuum_equilibrium::vacuum_get_b_vec
real(rprec) function, dimension(3) vacuum_get_b_vec(this, x_cart, cyl)
Gets the magnetic field vector at a position.
Definition: vacuum_equilibrium.f:358
vacuum_equilibrium::vacuum_extcur_id
integer, parameter vacuum_extcur_id
1D Array of external currents.
Definition: vacuum_equilibrium.f:53
vacuum_input::cg_rot_angle
real(rprec), dimension(vacuum_max_currents) cg_rot_angle
Angle to rotate about axis of rotation. NB - LEFT HAND convention. Put left thumb along axis of rotat...
Definition: vacuum_input.f:117
coordinate_utilities::cart_to_cyl_vec
pure real(rprec) function, dimension(3) cart_to_cyl_vec(cart, vec)
Convert vector from cartesian coordinates to cylindical coordinates.
Definition: coordinate_utilities.f:126
vacuum_equilibrium::vacuum_get_ext_currents
real(rprec) function, dimension(:), pointer vacuum_get_ext_currents(this, scale_currents)
Get external current.
Definition: vacuum_equilibrium.f:457
vacuum_equilibrium::vacuum_get_int_b_dphi
real(rprec) function vacuum_get_int_b_dphi(this, r, theta)
Gets the loop integrated magnetic field at a position.
Definition: vacuum_equilibrium.f:404
vacuum_equilibrium::vacuum_destruct
subroutine vacuum_destruct(this)
Deconstruct a vacuum_class object.
Definition: vacuum_equilibrium.f:166
vacuum_input::cg_shift_1
real(rprec), dimension(vacuum_max_currents, 3) cg_shift_1
Vector to shift all the coils. (Before rotation)
Definition: vacuum_input.f:106
vacuum_input::cg_rot_theta
real(rprec), dimension(vacuum_max_currents) cg_rot_theta
Spherical polar angle to specify axis of rotation.
Definition: vacuum_input.f:109
coordinate_utilities::cyl_to_cart_vec
pure real(rprec) function, dimension(3), public cyl_to_cart_vec(cyl, vec)
Convert vector from cylindical coordinates to cartesian coordinates.
Definition: coordinate_utilities.f:95
mpi_inc
Umbrella module avoid multiple inlcudes of the mpif.h header.
Definition: mpi_inc.f:11
vacuum_input::extcur
real(rprec), dimension(vacuum_max_currents) extcur
External currents.
Definition: vacuum_input.f:102
vacuum_input::cg_shift_2
real(rprec), dimension(vacuum_max_currents, 3) cg_shift_2
Vector to shift all the coils. (After rotation)
Definition: vacuum_input.f:127
vacuum_input::coils_dot_file
character(len=path_length) coils_dot_file
File name for vacuum namelist input.
Definition: vacuum_input.f:97
vacuum_input::cg_rot_xcent
real(rprec), dimension(vacuum_max_currents, 3) cg_rot_xcent
Position of center of rotation.
Definition: vacuum_input.f:120
vacuum_equilibrium::vacuum_get_param_value
real(rprec) function vacuum_get_param_value(this, id, i_index)
Get the value of a reconstruction vacuum parameter.
Definition: vacuum_equilibrium.f:279
profiler::profiler_get_start_time
real(rprec) function profiler_get_start_time()
Gets the start time of profiled function.
Definition: profiler.f:194
vacuum_input::l_rot_coil_center
logical, dimension(vacuum_max_currents) l_rot_coil_center
Definition: vacuum_input.f:124
vacuum_input::cg_rot_phi
real(rprec), dimension(vacuum_max_currents) cg_rot_phi
Spherical azimuthal angle to specify axis of rotation.
Definition: vacuum_input.f:112
vacuum_equilibrium::vacuum_write
subroutine vacuum_write(this, iou)
Write out the equilibrium to an output file.
Definition: vacuum_equilibrium.f:570
coordinate_utilities::cyl_to_cart
pure real(rprec) function, dimension(3), public cyl_to_cart(cyl)
Convert a point from cylindical coordinates to cartesian coordinates.
Definition: coordinate_utilities.f:67
vacuum_equilibrium::vacuum_get_param_name
character(len=data_name_length) function vacuum_get_param_name(this, id)
Get the name of a reconstruction vacuum parameter.
Definition: vacuum_equilibrium.f:318
vacuum_input::vacuum_input_write_namelist
subroutine vacuum_input_write_namelist(namelist_file)
Writes the namelist input file.
Definition: vacuum_input.f:194
vacuum_input
This file contains all the variables and maximum sizes of the inputs for a vacuum namelist input file...
Definition: vacuum_input.f:78
vacuum_equilibrium::vacuum_construct
type(vacuum_class) function, pointer vacuum_construct(file_name, iou)
Construct a vacuum_class object.
Definition: vacuum_equilibrium.f:85
vacuum_input::vacuum_input_read_namelist
subroutine vacuum_input_read_namelist(namelist_file)
Reads the namelist input file.
Definition: vacuum_input.f:152
vacuum_equilibrium::vacuum_get_param_id
integer function vacuum_get_param_id(this, param_name)
Get the id for a reconstruction parameter.
Definition: vacuum_equilibrium.f:237
data_parameters
This modules contains parameters used by equilibrium models.
Definition: data_parameters.f:10
profiler::profiler_set_stop_time
subroutine profiler_set_stop_time(symbol_name, start_time)
Gets the end time of profiled function.
Definition: profiler.f:121
vacuum_equilibrium::vacuum_is_1d_array
logical function vacuum_is_1d_array(this, id)
Checks if a parameter id is a 1d array.
Definition: vacuum_equilibrium.f:491
vacuum_equilibrium::vacuum_write_input
subroutine vacuum_write_input(this, current_step)
Write the current valid input.
Definition: vacuum_equilibrium.f:601
vacuum_equilibrium::vacuum_set_param
subroutine vacuum_set_param(this, id, i_index, value)
Sets the value of a reconstruction equilibrium parameter.
Definition: vacuum_equilibrium.f:198
vacuum_input::n_extcur
integer n_extcur
Number of external currents.
Definition: vacuum_input.f:100
vacuum_equilibrium::vacuum_class
Base class representing a vacuum_equilibrium.
Definition: vacuum_equilibrium.f:65
vacuum_equilibrium
Defines the base class of the type vacuum_class. This module contains all the code necessary to inter...
Definition: vacuum_equilibrium.f:34