V3FIT
siesta_pressure.f90
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 
12  USE v3_utilities, ONLY: assert
13  USE stel_kinds
14  USE stel_constants
15  USE quantities
16  USE nscalingtools, ONLY: startglobrow, endglobrow
17  USE utilities, ONLY: gradienthalf, to_half_mesh
18 
19  IMPLICIT NONE
20 
21  CONTAINS
22 
23 !-------------------------------------------------------------------------------
57 !-------------------------------------------------------------------------------
58  SUBROUTINE update_pres
59  USE timer_mod, ONLY: time_update_pres
60  USE fourier, ONLY: f_cos, f_sin, f_sum, f_du, f_dv
61  USE quantities, ONLY: gvsupumnsf => fsupumnsf, gvsupvmnsf => fsupvmnsf, &
62  gvsupumncf => fsupumncf, gvsupvmncf => fsupvmncf
63  USE utilities, ONLY: set_bndy_fouier_m0, m0
64  USE shared_data, ONLY: delta_t
66 
67  IMPLICIT NONE
68 
69 ! local variables
70  INTEGER :: istat
71  REAL (dp) :: ton
72  REAL (dp) :: toff
73  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: jvsupuijh
74  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: jvsupvijh
75  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: workij1
76  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: workij2
77  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: workij3
78  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: workmn4
79  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: workmn5
80  REAL (dp), DIMENSION(:,:,:), ALLOCATABLE :: vgradph
81  INTEGER :: nsmin
82  INTEGER :: nsmax
83 
84 ! local parameters
85 ! Does not work well, keep it off.
86  LOGICAL, PARAMETER :: l_upwind = .false.
87 
88 ! Start of executable code
89  CALL second0(ton)
90  nsmin = max(1, startglobrow - 1)
91  nsmax = min(ns, endglobrow + 1)
92 
93 ! Compute first term ~(gamma-1)V * grad(p) on r.h.s. of pressure equation the
94 ! u,v derivatives should be consistent with div(pv) term and combine to cancel
95 ! if div(V) = 0
96  ALLOCATE(workij1(ntheta,nzeta,nsmin:nsmax), &
97  workij2(ntheta,nzeta,nsmin:nsmax), &
98  workij3(ntheta,nzeta,nsmin:nsmax), &
99  vgradph(ntheta,nzeta,nsmin:nsmax), stat=istat)
100  CALL assert_eq(0, istat, 'Allocation1 failed in update_pres')
101 
102  ALLOCATE(workmn4(0:mpol,-ntor:ntor,nsmin:nsmax), &
103  workmn5(0:mpol,-ntor:ntor,nsmin:nsmax))
104  CALL assert_eq(0, istat, 'Allocation2 failed in update_pres')
105 
106  ALLOCATE (jvsupuijh(ntheta,nzeta,nsmin:nsmax), &
107  jvsupvijh(ntheta,nzeta,nsmin:nsmax), stat=istat)
108  CALL assert_eq(0, istat, 'Allocation3 failed in update_pres')
109 
110 ! On exit, jsupXh valid on [nsmin+1:nsmax]
111  CALL to_half_mesh(jvsupuijf, jvsupuijh)
112  CALL to_half_mesh(jvsupvijf, jvsupvijh)
113 
114 ! On exit, vgradph is valid on [nsmin+1:nsmax]. Mixed half/full form: Diagonal
115 ! in angular derivatives. Exactly cancel Div(pV) term when div(V) = 0.
116  workij1 = pijf0_ds(:,:,nsmin:nsmax)*jvsupsijf(:,:,nsmin:nsmax)
117  CALL to_half_mesh(workij1, vgradph)
118  vgradph = vgradph &
119  + jvsupuijh(:,:,nsmin:nsmax)*pijh0_du(:,:,nsmin:nsmax) &
120  + jvsupvijh(:,:,nsmin:nsmax)*pijh0_dv(:,:,nsmin:nsmax)
121 
122 ! d/ds Jv^s
123  workij2(:,:,nsmin:nsmax) = jvsupsijf(:,:,nsmin:nsmax)
124 
125  IF (nsmin .EQ. 1) THEN
126 ! Enforce bc at origin in Div(pv) term.
127  workij2(:,:,1) = 0
128  END IF
129 
130  CALL gradienthalf(workij1, workij2)
131 
132 ! Get djvsupudu and djvsupvdv. d/du Jv^u and d/dv Jv^v
133  CALL to_half_mesh(gvsupumnsf, workmn4)
134  CALL to_half_mesh(gvsupvmnsf, workmn5)
135 
136  CALL set_bndy_fouier_m0(workmn4, f_sin)
137  CALL set_bndy_fouier_m0(workmn5, f_sin)
138 
139  CALL fourier_context%toijsp(workmn4(:,:,nsmin:nsmax), &
140  workij2(:,:,nsmin:nsmax), f_du, f_sin)
141  CALL fourier_context%toijsp(workmn5(:,:,nsmin:nsmax), &
142  workij3(:,:,nsmin:nsmax), f_dv, f_sin)
143  IF (lasym) THEN
144  CALL to_half_mesh(gvsupumncf, workmn4)
145  CALL to_half_mesh(gvsupvmncf, workmn5)
146 
147  CALL set_bndy_fouier_m0(workmn4, f_cos)
148  CALL set_bndy_fouier_m0(workmn5, f_cos)
149 
150  CALL fourier_context%toijsp(workmn4(:,:,nsmin:nsmax), &
151  workij2(:,:,nsmin:nsmax), &
152  ior(f_du, f_sum), f_cos)
153  CALL fourier_context%toijsp(workmn5(:,:,nsmin:nsmax), &
154  workij3(:,:,nsmin:nsmax), &
155  ior(f_dv, f_sum), f_cos)
156  END IF
157 
158  nsmin = max(2, startglobrow)
159 
160 ! First half of the pressure variation.
161 ! gamma*p*d/ds Jv^s + gamma*p*d/du Jv^u + gamma*p*d/dv Jv^v
162  workij1(:,:,nsmin:nsmax) = gamma*pijh0(:,:,nsmin:nsmax) &
163  * (workij1(:,:,nsmin:nsmax) + &
164  workij2(:,:,nsmin:nsmax) + &
165  workij3(:,:,nsmin:nsmax))
166 
167 ! Second half the the pressure variation.
168 ! J dp/dt = -Jv^s d/ds p - Jv^u d/du -Jv^v d/dv
169 ! - gamma*p*d/ds Jv^s + gamma*p*d/du Jv^u + gamma*p*d/dv Jv^v
170  workij1(:,:,nsmin:nsmax) = -vgradph(:,:,nsmin:nsmax) &
171  - workij1(:,:,nsmin:nsmax)
172 
173 ! Convert to Fourier space.
174  CALL fourier_context%tomnsp(workij1(:,:,nsmin:nsmax), &
175  djpmnch(:,:,nsmin:nsmax), f_cos)
176  djpmnch(:,:,nsmin:nsmax) = delta_t*djpmnch(:,:,nsmin:nsmax)
177  IF (lasym) THEN
178  CALL fourier_context%tomnsp(workij1(:,:,nsmin:nsmax), &
179  djpmnsh(:,:,nsmin:nsmax), f_sin)
180  djpmnsh(:,:,nsmin:nsmax) = delta_t*djpmnsh(:,:,nsmin:nsmax)
181  END IF
182 
183  IF (startglobrow .eq. 1) THEN
184  djpmnch(:,:,1) = 0
185  djpmnch(m0,:,1) = djpmnch(m0,:,2)
186 
187  IF (lasym) THEN
188  djpmnsh(:,:,1) = 0
189  djpmnsh(m0,:,1) = djpmnsh(m0,:,2)
190  END IF
191  END IF
192 
193  DEALLOCATE(workij1, workij2, workij3, vgradph)
194  DEALLOCATE(workmn4, workmn5)
195 
196  CALL second0(toff)
197  time_update_pres = time_update_pres + (toff - ton)
198 
199  END SUBROUTINE update_pres
200 
201  END MODULE
shared_data::delta_t
real(dp) delta_t
Time step.
Definition: shared_data.f90:125
quantities
This file contains subroutines for allocating and initializing curvilinear magnetic covariant and pre...
Definition: quantities.f90:11
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
v3_utilities::assert
Definition: v3_utilities.f:55
fourier::f_sin
integer, parameter f_sin
Sine parity.
Definition: fourier.f90:27
island_params
This file contains fix parameters related to the computational grids.
Definition: island_params.f90:10
fourier::f_du
integer, parameter f_du
Poloidal derivative flag.
Definition: fourier.f90:36
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::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
siesta_pressure
Updates pressure.
Definition: siesta_pressure.f90:11
fourier::f_dv
integer, parameter f_dv
Toroidal derivative flag.
Definition: fourier.f90:38