13 USE v3_utilities,
ONLY:
assert
16 USE descriptor_mod,
ONLY: siesta_comm
20 USE nscalingtools,
ONLY: nranks, startglobrow, endglobrow, mpi_err
61 SUBROUTINE cv_currents(bsupsijh, bsupuijh, bsupvijh, &
62 ksupsijf, ksupuijf, ksupvijf, &
65 USE hessian,
ONLY: mupar_norm
66 USE descriptor_mod,
ONLY: iam
70 USE descriptor_mod,
ONLY: siesta_comm
76 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: bsupsijh
77 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: bsupuijh
78 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: bsupvijh
79 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupsijf
80 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupuijf
81 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupvijf
82 LOGICAL,
INTENT(in) :: lmagen
83 LOGICAL,
INTENT(in) :: lcurr
90 REAL (dp),
DIMENSION(6) :: temp(6)
96 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubsijh
97 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubuijh
98 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubvijh
99 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bs_filter
100 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bu_filter
101 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bv_filter
102 REAL (dp) :: edge_cur
107 nmin = max(1, startglobrow)
108 nmax = min(ns, endglobrow)
109 nsmin = lbound(bsupsijh,3)
110 nsmax = ubound(bsupsijh,3)
113 ALLOCATE(bsubsijh(ntheta,nzeta,nsmin:nsmax),
114 bsubuijh(ntheta,nzeta,nsmin:nsmax),
115 bsubvijh(ntheta,nzeta,nsmin:nsmax), stat=istat)
116 CALL assert_eq(0, istat,
'Allocation1 failed in cv_currents')
118 CALL tolowerh(bsupsijh, bsupuijh, bsupvijh,
119 bsubsijh, bsubuijh, bsubvijh, nsmin, nsmax)
122 IF (.not.
ALLOCATED(mupar_norm))
THEN
123 ALLOCATE(mupar_norm(nsmin:nsmax), stat=istat)
124 CALL assert_eq(0, istat,
'mupar_norm allocation failed!')
125 beta = max(1.e-5_dp, wp_i/wb_i)
127 IF (iam .eq. 0 .and. lverbose)
THEN
133 bsq(:,:,nmin:nmax) = bsupsijh(:,:,nmin:nmax)*bsubsijh(:,:,nmin:nmax
134 + bsupuijh(:,:,nmin:nmax)*bsubuijh(:,:,nmin:nmax
135 + bsupvijh(:,:,nmin:nmax)*bsubvijh(:,:,nmin:nmax
136 IF (nmin .EQ. 1)
THEN
140 CALL assert(nmin .eq. 1 .or.
141 all(bsq(:,:,nmin:nmax) .gt. zero),
142 'BSQ <= 0 in cv_currents!')
144 wb = sum(bsq(:,:,nmin:nmax)*jacobh(:,:,nmin:nmax)*wint(:,:,nmin
149 CALL mpi_allreduce(mpi_in_place, wb, 1, mpi_real8, mpi_sum,
150 siesta_comm, mpi_err)
153 wb = signjac*(twopi*pi*hs_i)*wb
157 IF (l_update_state)
THEN
158 ALLOCATE(bs_filter(ntheta,nzeta,nsmin:nsmax),
159 bu_filter(ntheta,nzeta,nsmin:nsmax),
160 bv_filter(ntheta,nzeta,nsmin:nsmax), stat=istat)
161 CALL assert_eq(0, istat,
'Allocation2 failed in CURLB')
165 CALL curlb(ksupsmnsf, ksupumncf, ksupvmncf,
166 bsubsijh, bsubuijh, bsubvijh,
167 bs_filter, bu_filter, bv_filter, edge_cur,
170 CALL curlb(ksupsmncf, ksupumnsf, ksupvmnsf,
171 bsubsijh, bsubuijh, bsubvijh,
172 bs_filter, bu_filter, bv_filter, edge_cur,
173 jsju_ratio_a,
f_cos, lcurr, nsmax, nsmin,
177 IF (nsmax .eq. ns)
THEN
183 nsmax = min(ns, endglobrow + 1)
185 nsmax = min(ns, endglobrow)
190 CALL getcv(ksupsmnsf, ksupumncf, ksupvmncf,
191 ksupsijf, ksupuijf, ksupvijf,
f_sin, nsmin, nsmax)
193 CALL getcv(ksupsmncf, ksupumnsf, ksupvmnsf,
194 ksupsijf, ksupuijf, ksupvijf,
f_cos, nsmin, nsmax)
200 CALL tolowerf(ksupsijf, ksupuijf, ksupvijf,
201 ksubsijf, ksubuijf, ksubvijf, nsmin, nsmax)
202 IF (nsmin .eq. 1)
THEN
208 diagno:
IF (l_update_state)
THEN
212 IF (nsmax .eq. ns)
THEN
213 tmp = sum(wint(:,:,ns)*(bsubvijh(:,:,ns)*bsubvijh(:,:,ns) +
214 bsubuijh(:,:,ns)*bsubuijh(:,:,ns)))
215 IF (tmp .ne. zero)
THEN
216 tmp = sqrt(edge_cur/tmp)
221 CALL mpi_bcast(tmp, 1, mpi_real8, nranks - 1, siesta_comm, mpi_err
232 temp(1) = sum(wint(:,:,nmin:nmax) *
233 (bs_filter - bsubsijh(:,:,nmin:nmax))**2)
234 temp(2) = sum(wint(:,:,nmin:nmax) *
235 (bs_filter + bsubsijh(:,:,nmin:nmax))**2)
236 temp(3) = sum(wint(:,:,nmin:nmax) *
237 (bu_filter - bsubuijh(:,:,nmin:nmax))**2)
238 temp(4) = sum(wint(:,:,nmin:nmax) *
239 (bu_filter + bsubuijh(:,:,nmin:nmax))**2)
240 temp(5) = sum(wint(:,:,nmin:nmax) *
241 (bv_filter - bsubvijh(:,:,nmin:nmax))**2)
242 temp(6) = sum(wint(:,:,nmin:nmax) *
243 (bv_filter + bsubvijh(:,:,nmin:nmax))**2)
246 CALL mpi_allreduce(mpi_in_place, temp, 6, mpi_real8, mpi_sum
247 siesta_comm, mpi_err)
250 IF (temp(2) .ne. zero)
THEN
251 ste(2) = sqrt(temp(1)/temp(2))
253 IF (temp(4) .ne. zero)
THEN
254 ste(3) = sqrt(temp(3)/temp(4))
256 IF (temp(6) .ne. zero)
THEN
257 ste(4) = sqrt(temp(5)/temp(6))
259 DEALLOCATE (bs_filter, bu_filter, bv_filter)
262 DEALLOCATE (bsubsijh, bsubuijh, bsubvijh)
265 cv_current_time = cv_current_time + (toff - ton)
266 time_current = time_current + (toff - ton)
268 1000
FORMAT(
' Rmajor_i = ',1p,e12.3)
269 1001
FORMAT(
' RMS EDGE CURRENT ||KSUPS(NS)|| = ',1p,e10.3)
297 SUBROUTINE curlb(ksupsmnf, ksupumnf, ksupvmnf, &
298 bsubsijh, bsubuijh, bsubvijh, &
299 bs_filter, bu_filter, bv_filter, edge_cur, &
300 jsju_ratio, iparity, lcurr, nsmax, nsmin, curtor)
301 USE utilities,
ONLY: curl_htof
307 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: ksupsmnf
308 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: ksupumnf
309 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: ksupvmnf
310 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: bsubsijh
311 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: bsubuijh
312 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: bsubvijh
313 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: bs_filter
314 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: bu_filter
315 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: bv_filter
316 REAL (dp),
INTENT(inout) :: edge_cur
317 REAL (dp),
INTENT(out) :: jsju_ratio
318 INTEGER,
INTENT(in) :: iparity
319 LOGICAL,
INTENT(in) :: lcurr
320 INTEGER,
INTENT(in) :: nsmax
321 INTEGER,
INTENT(in) :: nsmin
322 REAL (dp),
INTENT(inout) :: curtor
332 REAL (dp),
DIMENSION(-ntor:ntor) :: temp
333 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubsmnh
334 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubumnh
335 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: bsubvmnh
338 nmin = max(1, startglobrow)
339 nmax = min(ns, endglobrow)
341 IF (iparity .EQ.
f_sin)
THEN
353 ALLOCATE(bsubsmnh(0:mpol,-ntor:ntor,nsmin:nsmax),
354 bsubumnh(0:mpol,-ntor:ntor,nsmin:nsmax),
355 bsubvmnh(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
356 CALL assert_eq(0, istat,
'Allocation1 failed in CURLB')
363 CALL curl_htof(bsubsmnh, bsubumnh, bsubvmnh,
364 ksupsmnf, ksupumnf, ksupvmnf,
365 iparity, nsmin, nsmax, lcurr, curtor)
369 IF (nmax .eq. ns)
THEN
370 edge_cur = edge_cur + sum(ksupsmnf(:,:,ns)*ksupsmnf(:,:,ns))
379 IF (nmin .eq. 1)
THEN
380 bv_filter(:,:,1) = bv_filter(:,:,2)
381 bsubvijh(:,:,1) = bsubvijh(:,:,2)
385 IF (nsmin .eq. 1)
THEN
386 temp = ksupsmnf(
m1,:,1) + r12*ksupumnf(
m1,:,1)
387 jsju_ratio = sum(temp*temp)
388 IF (jsju_ratio .gt. zero)
THEN
389 temp = ksupsmnf(
m1,:,1) - r12*ksupumnf(
m1,:,1)
390 jsju_ratio = sum(temp*temp)/jsju_ratio
391 jsju_ratio = sqrt(jsju_ratio)
396 DEALLOCATE (bsubsmnh, bsubumnh, bsubvmnh, stat=istat)
397 CALL assert_eq(0, istat,
'Deallocation failed in CURLB')
414 SUBROUTINE getcv(ksupsmnf, ksupumnf, ksupvmnf, &
415 ksupsijf, ksupuijf, ksupvijf, parity, nsmin, nsmax)
421 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: ksupsmnf
422 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: ksupumnf
423 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: ksupvmnf
424 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupsijf
425 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupuijf
426 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: ksupvijf
427 INTEGER,
INTENT(in) :: parity
428 INTEGER,
INTENT(in) :: nsmin
429 INTEGER,
INTENT(in) :: nsmax
437 IF (parity .eq.
f_sin)
THEN