13 USE descriptor_mod,
ONLY: siesta_comm, iam
16 USE nscalingtools,
ONLY: startglobrow, endglobrow, mpi_err
30 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: pfilter
46 USE utilities,
ONLY: gradientfull
50 USE hessian,
ONLY: mupar
57 LOGICAL,
INTENT(IN) :: lcurrent_only
58 LOGICAL,
INTENT(IN),
OPTIONAL :: lpar_in
77 IF (
PRESENT(lpar_in))
THEN
89 nsmin = max(1, startglobrow - 1)
90 nsmax = min(ns, endglobrow + 2)
94 IF (.not.ladd_pert0)
THEN
107 CALL bhalftobfull(bsupsijh0, bsupuijh0, bsupvijh0,
108 bsupsijf0, bsupuijf0, bsupvijf0,
114 ksupsijf0, ksupuijf0, ksupvijf0,
117 IF (lcurrent_only)
THEN
123 IF (ladd_pert0 .or. mupar .ne. zero)
THEN
124 nmax = min(endglobrow + 1, ns)
126 CALL tolowerf(bsupsijf0,bsupuijf0,bsupvijf0,
127 bsubsijf, bsubuijf, bsubvijf,
131 ksubsijf(:,:,nsmin:nmax) = bsubsijf(:,:,nsmin:nmax)
132 ksubuijf(:,:,nsmin:nmax) = bsubuijf(:,:,nsmin:nmax)
133 ksubvijf(:,:,nsmin:nmax) = bsubvijf(:,:,nsmin:nmax)
140 ALLOCATE(pfilter(ntheta, nzeta, nsmin:nsmax))
142 CALL filterpressure(
f_cos)
144 CALL filterpressure(
f_sin)
149 CALL gradientfull(pijf0_ds, pijh0)
153 IF (nsmin .EQ. 1)
THEN
154 pijf0_ds(:,:,1) = 2.0*(pijh0(:,:,2) - pijh0(:,:,1))*ohs
158 IF (nsmax .eq. ns .and. l_pedge)
THEN
159 pijf0(:,:,ns) = pedge
169 n1 = max(1, startglobrow)
170 n2 = min(ns, endglobrow)
174 temp(1) = sum((pijh0(:,:,n1:n2) - pfilter(:,:,n1:n2))**2)
175 temp(2) = sum((pijh0(:,:,n1:n2) + pfilter(:,:,n1:n2))**2)
177 CALL mpi_allreduce(mpi_in_place, temp, 2, mpi_real8, mpi_sum,
178 siesta_comm, mpi_err)
180 IF (temp(2) .ne. zero)
THEN
181 ste(1) = sqrt(temp(1)/temp(2))
185 CALL checkfft(jbsupsmnsh, jbsupumnch, jbsupvmnch, jpmnch,
f_sin)
187 CALL checkfft(jbsupsmnch, jbsupumnsh, jbsupvmnsh, jpmnsh,
f_cos
191 startglobrow = startr
203 LOGICAL,
INTENT(in) :: lpar
207 LOGICAL :: lrealloc, lalloc
208 INTEGER :: istat, n1, n2, n3, nsmin, nsmax, &
211 lalloc =
ALLOCATED(jvsupsijf)
214 nsmin =max(1,startglobrow); nsmax =min(endglobrow+1,ns)
215 nsmin1=max(1,startglobrow-1); nsmax1=min(endglobrow+2,ns)
216 n1 = ntheta; n2 = nzeta
227 IF (
SIZE(bsupsijh0,3) .EQ. n3) lrealloc=.false.
229 DEALLOCATE (jvsupsijf, jvsupuijf, jvsupvijf,
230 bsupsijf0, bsupuijf0, bsupvijf0,
231 bsupsijf, bsupuijf, bsupvijf,
232 bsupsijh0, bsupuijh0, bsupvijh0,
233 bsubsijf, bsubuijf, bsubvijf,
234 ksupsijf0, ksupuijf0, ksupvijf0,
235 ksupsijf, ksupuijf, ksupvijf,
236 ksubsijf, ksubuijf, ksubvijf,
237 pijf0, pijh0, pijf0_ds,
238 pijh0_du, pijh0_dv, stat=istat)
240 'Deallocation error #1 in INIT_ALLOCATE_ARRAYS'
246 ALLOCATE (jvsupsijf(n1,n2,n3), jvsupuijf(n1,n2,n3),
249 ALLOCATE (bsupsijh0(n1,n2,nsmin1:nsmax1),
250 bsupuijh0(n1,n2,nsmin1:nsmax1),
251 bsupvijh0(n1,n2,nsmin1:nsmax1),
252 bsupsijf0(n1,n2,nsmin1:nsmax1),
253 bsupuijf0(n1,n2,nsmin1:nsmax1),
254 bsupvijf0(n1,n2,nsmin1:nsmax1),
255 ksupsijf0(n1,n2,nsmin1:nsmax),
256 ksupuijf0(n1,n2,nsmin1:nsmax),
257 ksupvijf0(n1,n2,nsmin1:nsmax),
258 ksubsijf(n1,n2,nsmin1:nsmax),
259 ksubuijf(n1,n2,nsmin1:nsmax),
260 ksubvijf(n1,n2,nsmin1:nsmax),
261 bsubsijf(n1,n2,nsmin1:nsmax),
262 bsubuijf(n1,n2,nsmin1:nsmax),
263 bsubvijf(n1,n2,nsmin1:nsmax),
264 ksupsijf(n1,n2,nsmin:nsmax),
265 ksupuijf(n1,n2,nsmin:nsmax),
266 ksupvijf(n1,n2,nsmin:nsmax),
267 bsupsijf(n1,n2,nsmin:nsmax),
268 bsupuijf(n1,n2,nsmin:nsmax),
269 bsupvijf(n1,n2,nsmin:nsmax),
270 pijh0(n1,n2,nsmin1:nsmax1),
271 pijh0_du(n1,n2,nsmin1:nsmax),
272 pijh0_dv(n1,n2,nsmin1:nsmax),
273 pijf0(n1,n2,nsmin1:nsmax1),
274 pijf0_ds(n1,n2,nsmin1:nsmax), stat=istat)
276 ALLOCATE (ksupsijf0(n1,n2,n3), ksupuijf0(n1,n2,n3),
277 ksupvijf0(n1,n2,n3), ksupsijf(n1,n2,n3),
278 ksupuijf(n1,n2,n3), ksupvijf(n1,n2,n3),
285 pijf0(n1,n2,n3), pijh0(n1,n2,n3),
286 pijh0_du(n1,n2,n3), pijh0_dv(n1,n2,n3),
287 pijf0_ds(n1,n2,n3), bsupsijf0(n1,n2,n3),
288 bsupuijf0(n1,n2,n3),bsupvijf0(n1,n2,n3),
289 bsupsijf(n1,n2,n3), bsupuijf(n1,n2,n3),
290 bsupvijf(n1,n2,n3), bsupsijh0(n1,n2,n3),
291 bsupuijh0(n1,n2,n3),bsupvijh0(n1,n2,n3),
295 'Allocation error #1 in Init_Allocate_Arrays')
296 jvsupsijf = 0; jvsupuijf = 0; jvsupvijf = 0
300 lalloc =
ALLOCATED(ksupsmnsf)
304 n1 = mpol+1; n2 = 2*ntor+1; n3 = nsmax-nsmin1+1
306 n1 = mpol+1; n2 = 2*ntor+1; n3 = ns
310 IF (
SIZE(ksupsmnsf,3) .EQ. n3)
THEN
314 DEALLOCATE(ksupsmnsf, ksupumncf, ksupvmncf,
315 djpmnch, djbsupsmnsh, djbsupumnch, djbsupvmnch,
318 'Deallocation error #2 in Init_Allocate_Arrays'
320 DEALLOCATE(ksupsmncf, ksupumnsf, ksupvmnsf,
321 djpmnsh, djbsupsmnch, djbsupumnsh, djbsupvmnsh
324 'Deallocation error #3 in Init_Allocate_Arrays'
331 ALLOCATE(ksupsmnsf(0:mpol,-ntor:ntor,nsmin1:nsmax),
332 ksupumncf(0:mpol,-ntor:ntor,nsmin1:nsmax),
333 ksupvmncf(0:mpol,-ntor:ntor,nsmin1:nsmax),
334 djpmnch(0:mpol,-ntor:ntor,nsmin:nsmax),
335 djbsupsmnsh(0:mpol,-ntor:ntor,nsmin:nsmax),
336 djbsupumnch(0:mpol,-ntor:ntor,nsmin:nsmax),
337 djbsupvmnch(0:mpol,-ntor:ntor,nsmin:nsmax),
340 ALLOCATE(ksupsmncf(0:mpol,-ntor:ntor,nsmin1:nsmax),
341 ksupumnsf(0:mpol,-ntor:ntor,nsmin1:nsmax),
342 ksupvmnsf(0:mpol,-ntor:ntor,nsmin1:nsmax),
343 djpmnsh(0:mpol,-ntor:ntor,nsmin:nsmax),
344 djbsupsmnch(0:mpol,-ntor:ntor,nsmin:nsmax),
345 djbsupumnsh(0:mpol,-ntor:ntor,nsmin:nsmax),
346 djbsupvmnsh(0:mpol,-ntor:ntor,nsmin:nsmax),
350 ALLOCATE(ksupsmnsf(0:mpol,-ntor:ntor,n3),
351 ksupumncf(0:mpol,-ntor:ntor,n3),
352 ksupvmncf(0:mpol,-ntor:ntor,n3),
353 djpmnch(0:mpol,-ntor:ntor,n3),
354 djbsupsmnsh(0:mpol,-ntor:ntor,n3),
355 djbsupumnch(0:mpol,-ntor:ntor,n3),
356 djbsupvmnch(0:mpol,-ntor:ntor,n3),
359 ALLOCATE(ksupsmncf(0:mpol,-ntor:ntor,n3),
360 ksupumnsf(0:mpol,-ntor:ntor,n3),
361 ksupvmnsf(0:mpol,-ntor:ntor,n3),
362 djpmnsh(0:mpol,-ntor:ntor,n3),
363 djbsupsmnch(0:mpol,-ntor:ntor,n3),
364 djbsupumnsh(0:mpol,-ntor:ntor,n3),
365 djbsupvmnsh(0:mpol,-ntor:ntor,n3),
370 'Allocation error #2 in Init_Allocate_Arrays')
396 SUBROUTINE getfields(jbsupsmnh, jbsupumnh, jbsupvmnh, jpmnh, iparity)
401 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupsmnh
402 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupumnh
403 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupvmnh
404 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jpmnh
405 INTEGER,
INTENT(in) :: iparity
414 IF (nsmin .EQ. 1)
THEN
415 CALL assert(all(jbsupsmnh(
m1,:,1) .eq. jbsupsmnh(
m1,:,2)),
416 'bmnsh(1) != bmnsh(2)')
417 CALL assert(all(jbsupsmnh(
m0,:,1) .eq. zero),
'bmnsh(m0:,1) != 0'
418 CALL assert(all(jbsupsmnh(
m1+1:,:,1) .eq. zero),
'bmnsh(m2:,1) != 0'
420 'bmnuh(1) != bmnuh(2)')
421 CALL assert(all(jbsupumnh(
m1+1:,:,1) .eq. zero),
'bmnuh(m2:,1) != 0'
422 CALL assert(all(jbsupvmnh(
m0,:,1) .eq. jbsupvmnh(
m0,:,2)),
423 'bmnvh(m0,1) != bmnvh(m0,2)')
424 CALL assert(all(jbsupvmnh(
m1:,:,1) .eq. zero),
'bmnvh(m1:,1) != 0'
425 CALL assert(all(jpmnh(
m0,:,1) .eq. jpmnh(
m0,:,2)),
426 'pmnh(m0,1) != pmnh(m0,2)')
427 CALL assert(all(jpmnh(
m1:,:,1) .eq. zero),
'pmnh(m1:,1) != 0'
430 IF (iparity .EQ.
f_sin)
THEN
446 CALL fourier_context%toijsp(jpmnh(:,:,nsmin:nsmax), pijh0, fcomb, fouruvp
458 SUBROUTINE filterpressure(parity)
464 INTEGER,
INTENT(in) :: parity
469 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: pmnh
472 IF (parity .eq.
f_cos)
THEN
480 ALLOCATE(pmnh(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
481 CALL assert_eq(0, istat,
'Allocation error in FilterPressure')
485 IF (parity .eq.
f_cos .and. nsmax .eq. ns)
THEN
510 SUBROUTINE checkfft(jbsupsmnh, jbsupumnh, jbsupvmnh, jpmnh, iparity)
515 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupsmnh
516 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupumnh
517 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jbsupvmnh
518 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: jpmnh
519 INTEGER,
INTENT(in) :: iparity
530 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: FFT_TEST
531 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: pmnh
532 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: temp
536 REAL (dp),
PARAMETER :: rtol = 1.e
541 #if defined(_TEST_INIT)
542 IF (iparity .EQ.
f_sin)
THEN
553 ALLOCATE (fft_test(0:mpol,-ntor:ntor,nsmin:nsmax),
554 temp(ntheta,nzeta,nsmin:nsmax),
555 pmnh(0:mpol,-ntor:ntor,nsmin:nsmax), stat=m)
556 CALL assert(m.EQ.0,
' Allocation failed in CheckFFT')
557 temp = bsupsijh0*jacobh(:,:,nsmin:nsmax)
558 CALL tomnsp(temp, fft_test, fours)
559 rtest = maxval(abs(fft_test - jbsupsmnh(:,:,nsmin:nsmax)))
560 CALL assert(rtest.LT.rtol,
' jbsupsmnh FFT error in siesta_init')
561 temp = bsupuijh0*jacobh(:,:,nsmin:nsmax)
562 CALL tomnsp(temp, fft_test, fouruv)
563 rtest = maxval(abs(fft_test - jbsupumnh(:,:,nsmin:nsmax)))
564 CALL assert(rtest.LT.rtol,
' jbsupumnh FFT error in siesta_init')
565 temp = bsupvijh0*jacobh(:,:,nsmin:nsmax)
566 CALL tomnsp(temp, fft_test, fouruv)
567 rtest = maxval(abs(fft_test - jbsupvmnh(:,:,nsmin:nsmax)))
568 CALL assert(rtest.LT.rtol,
' jbsupvmnh FFT error in siesta_init')
569 temp = pijh0*jacobh(:,:,nsmin:nsmax)
570 CALL tomnsp(temp, fft_test, fouruv)
571 rtest = maxval(abs(fft_test - jpmnh(:,:,nsmin:nsmax)))
572 CALL assert(rtest.LT.rtol,
' jpmnh FFT error in siesta_init')
575 CALL tomnsp(pijh0, pmnh, fouruv)
576 CALL tomnsp(pijh0_du, fft_test, fouruv)
579 CALL assert(maxval(abs(fft_test(m,:,:) - mp*pmnh(m,:,:))) .LE.
580 ' pijh0_du FFT error in siesta_init')
583 CALL tomnsp(pijh0_dv, fft_test, fouruv)
586 CALL assert(maxval(abs(fft_test(:,n,:) - np*pmnh(:,n,:))) .LE.
587 ' pijh0_dv FFT error in siesta_init')
590 DEALLOCATE(fft_test, pmnh, temp)
598 SUBROUTINE checkpressure
603 IF (lverbose .and. minval(pijh0) .lt. zero)
THEN
608 WHERE (pijh0 .LT. zero)
612 1000
FORMAT(
' pijh < 0 in init_state. ===> Recommend lowering f2 exponent'