V3FIT
siesta_displacement.f90
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
18 !*******************************************************************************
19  MODULE siesta_displacement
20  USE island_params, ONLY: hs_i, ns=>ns_i
21  USE stel_kinds
22  USE stel_constants
23  USE nscalingtools, ONLY: startglobrow, endglobrow
24  USE timer_mod, ONLY: time_update_upperv
25 
26  IMPLICIT NONE
27 
28  CONTAINS
29 
30 !*******************************************************************************
31 ! UTILITY SUBROUTINES
32 !*******************************************************************************
33 !-------------------------------------------------------------------------------
43 !-------------------------------------------------------------------------------
44  SUBROUTINE update_upperv
45  USE shared_data, ONLY: lasym, gc_sup, xc, col_scale
46  USE siesta_state, ONLY: clear_field_perts
47  USE quantities, ONLY: gvsupsmncf => fsupsmncf, gvsupumnsf => fsupumnsf, &
48  gvsupvmnsf => fsupvmnsf, gvsupsmnsf => fsupsmnsf, &
49  gvsupumncf => fsupumncf, gvsupvmncf => fsupvmncf
50  USE fourier, ONLY: f_sin, f_cos
51 
52  IMPLICIT NONE
53 
54 ! local variables
55  INTEGER :: istat
56  REAL (dp) :: ton
57  REAL (dp) :: toff
58 
59 ! Start of executable code
60  CALL second0(ton)
61 
62  CALL clear_field_perts
63 
64 ! Use components of gc_sup as scratch array. gvsup*mn*f componets point to
65 ! fsup*mn*f values which in turn point to parts of the gc_sup array.
66 ! @ref ScaleDisplacement sets gc_sup to the xc array then applies the column
67 ! factors so the gc_sup array is treated as the xc here.
68  CALL scaledisplacement(gc_sup, xc, col_scale)
69 
70  CALL initdisplacement(gvsupsmncf, gvsupumnsf, gvsupvmnsf, f_cos)
71  IF (lasym) THEN
72  CALL initdisplacement(gvsupsmnsf, gvsupumncf, gvsupvmncf, f_sin)
73  END IF
74 
75  CALL second0(toff)
76  time_update_upperv = time_update_upperv + (toff - ton)
77 
78  END SUBROUTINE update_upperv
79 
80 !-------------------------------------------------------------------------------
89 !-------------------------------------------------------------------------------
90  SUBROUTINE initdisplacement(gvsupsmnf, gvsupumnf, gvsupvmnf, iparity)
91  USE fourier, ONLY: f_cos, f_sin, f_none, f_sum, m0, m1, m2
92  USE quantities, ONLY: jvsupsijf, jvsupuijf, jvsupvijf, mpol, ntor
95  USE v3_utilities, ONLY: assert_eq
97  USE utilities, ONLY: set_bndy_fouier_m0, set_bndy_full_origin
98 
99  IMPLICIT NONE
100 
101 ! Declare Arguments
102  REAL (dp), DIMENSION(0:mpol,-ntor:ntor,ns), INTENT(inout) :: gvsupsmnf
103  REAL (dp), DIMENSION(0:mpol,-ntor:ntor,ns), INTENT(inout) :: gvsupumnf
104  REAL (dp), DIMENSION(0:mpol,-ntor:ntor,ns), INTENT(inout) :: gvsupvmnf
105  INTEGER, INTENT(in) :: iparity
106 
107 ! local variables
108  INTEGER :: fours
109  INTEGER :: fouruv
110  INTEGER :: fcomb
111  INTEGER :: nsmin
112  INTEGER :: nsmax
113 
114 ! Start of executable code
115  nsmin = max(1, startglobrow - 1)
116  nsmax = min(endglobrow + 1, ns)
117 
118  IF (iparity .eq. f_cos) THEN
119  fours = f_cos
120  fouruv = f_sin
121  fcomb = f_none
122  ELSE
123  fours = f_sin
124  fouruv = f_cos
125  fcomb = f_sum
126  END IF
127 
128  CALL assert_eq(1, lbound(gvsupsmnf,3), 'LBOUND WRONG IN InitDisplacement')
129  CALL assert_eq(ns, ubound(gvsupsmnf,3), &
130  'UBOUND WRONG IN InitDisplacement')
131 
132  CALL set_bndy_fouier_m0(gvsupsmnf, gvsupumnf, gvsupvmnf, fours)
133 
134 ! Origin boundary conditions (evolve m = 1 F_u, F_s, m = 0 F_v)
135  IF (nsmin .eq. 1) THEN
136 ! FIXME: Check if this should be here. Seems to converge faster if this is
137 ! commented out.
138  CALL set_bndy_full_origin(gvsupsmnf, gvsupumnf, gvsupvmnf)
139 
140  IF (.not.l_push_s) THEN
141  gvsupsmnf(m1,:,1) = 0
142  END IF
143  IF (.not.l_push_u) THEN
144  gvsupumnf(m1,:,1) = 0
145  END IF
146  IF (.not.l_push_v) THEN
147  gvsupvmnf(m0,:,1) = 0
148  END IF
149  END IF
150 
151 ! Edge boundary conditions (B_tangential = 0 => vsups = 0; J^s = 0 => F_v = 0)
152 ! Note that F_v and F_u are both ~J^s at edge, so only one can be varied to
153 ! prevent a dependent row in the Hessian matrix
154  IF (nsmax .eq. ns) THEN
155  gvsupsmnf(:,:,ns) = 0
156  IF (l_pedge) THEN
157  gvsupumnf(:,:,ns) = 0
158  END IF
159  IF (.not.l_push_edge) THEN
160  gvsupumnf(:,:,ns) = 0
161  gvsupvmnf(:,:,ns) = 0
162  END IF
163  END IF
164 
165 ! Calculate contravariant (SUP) velocities in real space on full mesh
166  CALL fourier_context%toijsp(gvsupsmnf(:,:,nsmin:nsmax), &
167  jvsupsijf(:,:,nsmin:nsmax), fcomb, fours)
168  CALL fourier_context%toijsp(gvsupumnf(:,:,nsmin:nsmax), &
169  jvsupuijf(:,:,nsmin:nsmax), fcomb, fouruv)
170  CALL fourier_context%toijsp(gvsupvmnf(:,:,nsmin:nsmax), &
171  jvsupvijf(:,:,nsmin:nsmax), fcomb, fouruv)
172 
173  END SUBROUTINE
174 
175 !-------------------------------------------------------------------------------
184 !-------------------------------------------------------------------------------
185  SUBROUTINE scaledisplacement(xc_scratch, xc, colscale)
186  USE hessian, ONLY: apply_colscale
187  USE shared_data, ONLY: mblk_size
188 
189  IMPLICIT NONE
190 
191 ! Declare Arguments
192  REAL (dp), DIMENSION(mblk_size,ns), INTENT(out) :: xc_scratch
193  REAL (dp), DIMENSION(mblk_size,ns), INTENT(in) :: xc
194  REAL (dp), DIMENSION(mblk_size,ns), INTENT(in) :: colscale
195 
196 ! local variables
197  INTEGER :: nsmin
198  INTEGER :: nsmax
199 
200 ! Start of executable code
201  nsmin = max(1, startglobrow - 1)
202  nsmax = min(endglobrow + 1, ns)
203 
204  xc_scratch(:,nsmin:nsmax) = xc(:,nsmin:nsmax)
205  CALL apply_colscale(xc_scratch, colscale, nsmin, nsmax)
206 
207  END SUBROUTINE
208 
209  END MODULE
shared_data::l_push_edge
logical l_push_edge
Solve u,v components at s=1.
Definition: shared_data.f90:202
shared_data::xc
real(dp), dimension(:), allocatable xc
1D array of Fourier mode displacement components.
Definition: shared_data.f90:97
shared_data::l_push_u
logical l_push_u
Solve for u component at origin.
Definition: shared_data.f90:206
shared_data::l_pedge
logical, parameter l_pedge
Preserve s=1 as iso-pressure surface.
Definition: shared_data.f90:43
shared_data::gc_sup
real(dp), dimension(:), allocatable, target gc_sup
1D Array of Fourier mode MHD force components, FIXME Check if this is really needed.
Definition: shared_data.f90:102
quantities
This file contains subroutines for allocating and initializing curvilinear magnetic covariant and pre...
Definition: quantities.f90:11
shared_data::l_push_s
logical l_push_s
Solve for s component at origin.
Definition: shared_data.f90:204
siesta_state
This file contains subroutines for aupdating from t to t + delta_t the magnetic field and pressure as...
Definition: siesta_state.f90:12
v3_utilities::assert_eq
Definition: v3_utilities.f:62
island_params::fourier_context
type(fourier_class), pointer fourier_context
Fourier transform object.
Definition: island_params.f90:76
fourier
Module contains subroutines for computing FFT on parallel radial intervals. Converts quantities betwe...
Definition: fourier.f90:13
fourier::m0
integer, parameter m0
m = 0 mode.
Definition: fourier.f90:58
fourier::f_sin
integer, parameter f_sin
Sine parity.
Definition: fourier.f90:27
shared_data::col_scale
real(dp), dimension(:,:,:,:), allocatable col_scale
Column scaling factors.
Definition: shared_data.f90:110
island_params
This file contains fix parameters related to the computational grids.
Definition: island_params.f90:10
shared_data::lasym
logical lasym
Use non-stellarator symmetry.
Definition: shared_data.f90:230
island_params::hs_i
real(dp) hs_i
Radial grid spacing. hs = s_i+1 - s_i.
Definition: island_params.f90:47
fourier::m2
integer, parameter m2
m = 2 mode.
Definition: fourier.f90:62
fourier::f_sum
integer, parameter f_sum
Sum fouier real space transformed quantity. This is used when a non-stellarator symmetric parity is b...
Definition: fourier.f90:43
fourier::m1
integer, parameter m1
m = 1 mode.
Definition: fourier.f90:60
shared_data::mblk_size
integer mblk_size
Block size. (mpol + 1)*(2*ntor + 1)*ndims.
Definition: shared_data.f90:62
fourier::f_cos
integer, parameter f_cos
Cosine parity.
Definition: fourier.f90:25
shared_data
This file contains variables and parameters used by many modules in SIESTA.
Definition: shared_data.f90:10
fourier::f_none
integer, parameter f_none
Do not sum fouier real space transformed quantity. This is used when a stellarator symmetric parity i...
Definition: fourier.f90:32
shared_data::l_push_v
logical l_push_v
Solve for v component at origin.
Definition: shared_data.f90:208