16 USE descriptor_mod,
ONLY: iam, siesta_comm
20 USE timer_mod,
ONLY: time_update_state
22 USE nscalingtools,
ONLY: startglobrow, endglobrow, mpi_err, &
33 LOGICAL,
PUBLIC :: lfirst = .true.
50 SUBROUTINE update_state(lprint, fsq_total, ftol)
55 LOGICAL,
INTENT(in) :: lprint
56 REAL (dp),
INTENT(in) :: fsq_total
57 REAL (dp),
INTENT(in) :: ftol
68 CALL updatefields(jbsupsmnsh, jbsupumnch, jbsupvmnch, jpmnch,
69 djbsupsmnsh, djbsupumnch, djbsupvmnch, djpmnch)
71 CALL updatefields(jbsupsmnch, jbsupumnsh, jbsupvmnsh, jpmnsh
72 djbsupsmnch, djbsupumnsh, djbsupvmnsh, djpmnsh
81 time_update_state = time_update_state + (toff - ton)
84 CALL clear_field_perts
87 time_update_state = time_update_state + (toff - ton)
95 CALL update_diagnostics(jbsupsmnsh, jbsupumnch, jbsupumnch, jpmnch
99 CALL update_diagnostics(jbsupsmnch, jbsupumnsh, jbsupvmnsh, jpmnsh
105 nsmin = max(1, startglobrow)
106 nsmax = min(endglobrow, ns)
113 CALL divb(nsmin, nsmax)
114 CALL divj(nsmin, nsmax)
115 CALL bgradp(nsmin, nsmax)
120 toroidal_flux = toroidal_flux - toroidal_flux0
123 WRITE (*,1000)
ste(1),
ste(2),
ste(3),
ste(4), divb_rms,
124 toroidal_flux, wp/wb, bgradp_rms, max_bgradp,
125 min_bgradp, bdotj_rms, bdotj2_rms, divj_rms
128 toroidal_flux, wp/wb, bgradp_rms, max_bgradp
129 min_bgradp, bdotj_rms, bdotj2_rms, divj_rms
133 time_update_state = time_update_state + (toff - ton)
135 1000
FORMAT(
' SPECTRAL TRUNC ERROR - p: ',1pe11.3,
' B_s: ',1pe11.3,
136 ' B_u: ',1pe11.3,
' B_v: ',1pe11.3,/,
137 ' DIV-B (rms): ',1pe11.3,
' DEL_TFLUX: ',1pe11.3,/,
138 ' <BETA>: ', 1pe11.3,
' B.GRAD-P (rms): ',1pe11.3,
139 ' B.GRAD-P (max): ',1pe11.3,
' B.GRAD-P (min): ',1pe11.3,/,
140 ' (J*B)/|JxB| (rms): ', 1pe11.3,
' (J_par)/|J_tot| (rms): ',
141 1pe11.3,
' DIV-J (rms): ',1pe11.3)
160 SUBROUTINE updatefields(jbsupsmnh, jbsupumnh, jbsupvmnh, jpmnh, &
161 djbsupsmnh, djbsupumnh, djbsupvmnh, djpmnh)
166 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: jbsupsmnh
167 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: jbsupumnh
168 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: jbsupvmnh
169 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: jpmnh
170 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: djbsupsmnh
171 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: djbsupumnh
172 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: djbsupvmnh
173 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: djpmnh
183 jbsupsmnh(:,:,n1:n2) = jbsupsmnh(:,:,n1:n2) + djbsupsmnh(:,:,n1:n2
184 jbsupumnh(:,:,n1:n2) = jbsupumnh(:,:,n1:n2) + djbsupumnh(:,:,n1:n2
185 jbsupvmnh(:,:,n1:n2) = jbsupvmnh(:,:,n1:n2) + djbsupvmnh(:,:,n1:n2
186 jpmnh(:,:,n1:n2) = jpmnh(:,:,n1:n2) + djpmnh(:,:,n1:n2)
203 SUBROUTINE update_diagnostics(jbsupsmnh, jbsupumnh, jbsupvmnh, &
204 jpmnh, bs, bu, bsbu_ratio, &
212 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(IN) :: jbsupsmnh
213 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(IN) :: jbsupumnh
214 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(IN) :: jbsupvmnh
215 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(IN) :: jpmnh
216 REAL (dp),
DIMENSION(6),
INTENT(out) :: bs
217 REAL (dp),
DIMENSION(6),
INTENT(out) :: bu
218 REAL (dp),
INTENT(out) :: bsbu_ratio
219 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns,4),
INTENT(inout) :: pwr_spec
220 INTEGER,
INTENT(in) :: iparity
226 REAL (dp),
DIMENSION(12) :: d1
233 CHARACTER (len=4),
DIMENSION(2),
PARAMETER ::
240 IF (iparity .eq. f_sin)
THEN
250 #if defined(_TEST_STATE)
252 WRITE (*,1000) def(itype)
254 WRITE (*,1001) js, jbsupsmnh(
m1,js,2), r12*jbsupumnh(
m1,js,2
259 bs(1) = sqrt(sum((jbsupsmnh(
m1,:,2) - r12*jbsupumnh(
m1,:,2))**2))/r12
260 bu(1) = sqrt(sum((jbsupsmnh(
m1,:,2) + r12*jbsupumnh(
m1,:,2))**2))/r12
266 CALL mpi_bcast(d1, 2, mpi_real8, 0, siesta_comm, mpi_err)
271 IF (abs(bu(1)) .GT. 1.e-10_dp)
THEN
272 bsbu_ratio = bs(1)/bu(1)
275 d1(js) = sqrt(sum(jbsupsmnh(
m1,:,js)**2))/abs(r12)
276 d1(js+6) = sqrt(sum(jbsupumnh(
m1,:,js)**2))
280 CALL mpi_allreduce(mpi_in_place, d1, 12, mpi_real8, mpi_sum,
281 siesta_comm, mpi_err)
292 #if defined(DUMP_STATE)
294 pwr_spec(:,:,n1:n2,1) = jbsupsmnh(:,:,n1:n2)
295 pwr_spec(:,:,n1:n2,2) = jbsupumnh(:,:,n1:n2)
296 pwr_spec(:,:,n1:n2,3) = jbsupvmnh(:,:,n1:n2)
297 pwr_spec(:,:,n1:n2,4) = jpmnh(:,:,n1:n2)
299 d1(1) = sum((jbsupsmnh(:,:,n1:n2) - pwr_spec(:,:,n1:n2,1))**2 +
300 (jbsupumnh(:,:,n1:n2) - pwr_spec(:,:,n1:n2,2))**2 +
301 (jbsupvmnh(:,:,n1:n2) - pwr_spec(:,:,n1:n2,3))**2)
302 d1(2) = sum((jpmnh(:,:,n1:n2) - pwr_spec(:,:,n1:n2,4))**2)
305 CALL mpi_allreduce(mpi_in_place, d1, 2, mpi_real8, mpi_sum,
306 siesta_comm, mpi_err)
313 IF (.NOT.lverbose .AND. js.EQ.6) cycle
314 WRITE(js, 1002) def(itype), diag_b, diag_p
319 1000
FORMAT(
'ipar: ',a,/,
' n B^s r12*B^u')
320 1001
FORMAT(i4,1p,2e14.4)
321 1002
FORMAT(1x,
'POWER SPECTRA(',a,
') -- dB: ',1p,e10.3,
' dP: ',1p,e10.3
328 SUBROUTINE clear_field_perts