TABLE OF CONTENTS


ABINIT/m_outvars [ Modules ]

[ Top ] [ Modules ]

NAME

  m_outvars

FUNCTION

COPYRIGHT

  Copyright (C) 1998-2024 ABINIT group (DCA, XG, GMR)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

SOURCE

16 #if defined HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 
20 #include "abi_common.h"
21 
22 module m_outvars
23 
24  use defs_basis
25  use m_results_out
26  use m_dtset
27  use m_abicore
28  use m_errors
29  use m_xomp
30  use m_xmpi
31 #if defined HAVE_NETCDF
32  use netcdf
33 #endif
34  use m_outvar_a_h
35  use m_outvar_i_n
36  use m_outvar_o_z
37 
38  use m_parser,    only : ab_dimensions
39  use m_nctk,      only : create_nc_file
40 
41  implicit none
42 
43  private

ABINIT/outvars [ Functions ]

[ Top ] [ Functions ]

NAME

 outvars

FUNCTION

 Echo variables for the ABINIT code.

INPUTS

  choice= 1 if echo of preprocessed variables, 2 if echo after call driver
  dmatpuflag=flag controlling the use of an initial density matrix in PAW+U (max. value over datasets)
  dtsets(0:ndtset_alloc)=<type datafiles_type>contains all input variables
  iout=unit number for echoed output
  mxvals=maximum size of some arrays along all datasets, including:
         ga_n_rules =maximal value of input ga_n_rules for all the datasets
         gw_nqlwl   =maximal value of input gw_nqlwl for all the datasets
         lpawu      =maximal value of input lpawu for all the datasets
         mband      =maximum number of bands
         natom      =maximal value of input natom for all the datasets
         natpawu    =maximal value of number of atoms on which +U is applied for all the datasets
         natsph     =maximal value of input natsph for all the datasets
         natvshift  =maximal value of input natvshift for all the datasets
         nconeq     =maximal value of input nconeq for all the datasets
         nimage     =maximal value of input nimage for all the datasets
         nimfrqs    =maximal value of input cd_customnimfrqs for all the datasets
         nkpt       =maximal value of input nkpt for all the datasets
         nkptgw     =maximal value of input nkptgw for all the datasets
         nkpthf     =maximal value of input nkpthf for all the datasets
         nnos       =maximal value of input nnos for all the datasets
         nqptdm     =maximal value of input nqptdm for all the datasets
         nspinor    =maximal value of input nspinor for all the datasets
         nsppol     =maximal value of input nsppol for all the datasets
         nsym       =maximum number of symmetries
         ntypat     =maximum number of type of atoms
         nzchempot  =maximal value of input nzchempot for all the datasets
  ndtset=number of datasets
  ndtset_alloc=number of datasets, corrected for allocation of at least
   one data set. Use for most dimensioned arrays.
  npsp=number of pseudopotentials
  results_out(0:ndtset_alloc)=<type results_out_type>contains the results
   needed for outvars, including evolving variables
  timopt=input variable to modulate the timing

OUTPUT

  Only writing

NOTES

 Note that this routine is called only by the processor me==0 .
 In consequence, no use of message and wrtout routine.
 The lines of code needed to output the defaults are preserved
 (see last section of the routine, but are presently disabled)

SOURCE

105 subroutine outvars(choice,dmatpuflag,dtsets,filnam4,iout,&
106 &  mxvals,ndtset,ndtset_alloc,npsp,results_out,timopt)
107 
108 !Arguments ------------------------------------
109 !scalars
110  integer,intent(in) :: choice,dmatpuflag,iout
111  integer,intent(in) :: ndtset,ndtset_alloc,npsp,timopt
112  type(ab_dimensions),intent(in) :: mxvals
113  character(len=*),intent(in) :: filnam4
114 !arrays
115  type(dataset_type),intent(in) :: dtsets(0:ndtset_alloc)
116  type(results_out_type),intent(in) :: results_out(0:ndtset_alloc)
117 
118 !Local variables-------------------------------
119 !scalars
120  integer,parameter :: nkpt_max=50
121  integer :: first,idtset,iimage,kptopt
122  integer :: marr,mu,ncerr
123  integer :: nshiftk
124  integer :: prtvol_glob,max_nthreads
125  integer :: rfddk,rfelfd,rfphon,rfstrs,rfuser,rfmagn,rf2_dkdk,rf2_dkde
126  integer :: ncid=0 ! Variables for NetCDF output
127  character(len=500) :: message
128  character(len=4) :: stringimage
129  type(ab_dimensions) :: multivals
130 !arrays
131  integer,allocatable :: jdtset_(:),response_(:)
132  character(len=8),allocatable :: strimg(:)
133 
134 ! *************************************************************************
135 
136 !Set up a 'global' prtvol value
137  prtvol_glob=1
138  if(sum((dtsets(:)%prtvol)**2)==0)prtvol_glob=0
139 
140 !###########################################################
141 !### 00. Echo of selected default values
142 
143  if(choice==1)then
144 
145    max_nthreads = xomp_get_max_threads()
146 #ifndef HAVE_OPENMP
147    max_nthreads = 0 ! this value signals that OMP is not enabled in ABINIT.
148 #endif
149 
150    write(iout, '(10a)' )&
151 &   '--------------------------------------------------------------------------------',ch10,&
152 &   '------------- Echo of variables that govern the present computation ------------',ch10,&
153 &   '--------------------------------------------------------------------------------',ch10,&
154 &   '-',ch10,&
155 &   '- outvars: echo of selected default values                                      '
156    write(iout, '(3(a,i3),2a)' )&
157 &   '-   iomode0 =',dtsets(0)%iomode,' , fftalg0 =',dtsets(0)%ngfft(7),' , wfoptalg0 =',dtsets(0)%wfoptalg,ch10,&
158 &   '-'
159    write(iout, '(3a,(a,i5),2a)' )&
160 &   '- outvars: echo of global parameters not present in the input file              ',ch10,&
161 &   '- ',' max_nthreads =',max_nthreads,ch10,&
162 &   '-'
163  end if
164 
165 !write(std_out,*) 'outvar 01'
166 !###########################################################
167 !### 01. First line indicating outvars
168 
169  if(choice==1)then
170    write(iout, '(a)' )&
171 &   ' -outvars: echo values of preprocessed input variables --------'
172  else
173    write(iout, '(a)' )&
174 &   ' -outvars: echo values of variables after computation  --------'
175  end if
176 
177 !###########################################################
178 !### 02. Open NetCDF file for export variables
179 
180 !Wrap the netcdf OUT.nc into conditional for flexible output writing
181  if ( dtsets(1)%ncout == 1 ) then
182 
183 #ifdef HAVE_NETCDF
184  ! Enable netcdf output only if the number of datasets is small.
185  ! otherwise v6[34] crashes with errmess:
186  !    nf90_def_dim - NetCDF library returned:   NetCDF: NC_MAX_DIMS exceeded
187  ! because we keep on creating dimensions in write_var_netcdf.
188  ! one should use groups for this kind of operations!!
189 
190  ncid = 0
191    if (ndtset_alloc  < 10) then
192      if (iout==std_out)then
193        write(iout,*) ch10,' These variables are accessible in NetCDF format (',trim(filnam4)//'_OUT.nc',')',ch10
194      end if
195      call create_nc_file(trim(filnam4)//"_OUT.nc",ncid)
196 
197      if (dtsets(1)%prtvol==-2) then
198        if (ncid>0)then
199         ncid=-ncid
200        else
201         ncid=-1
202        end if
203      end if
204    else
205      ABI_COMMENT("output of OUT.nc has been disabled. Too many datasets")
206    end if
207 #endif
208  !ncid = 0
209  
210   else if ( dtsets(1)%ncout == 0 ) then
211    ABI_COMMENT("ncout set to 0. No OUT.nc will be printed.")
212   else
213    ABI_COMMENT("ncout value unregonized. OUT.nc will proceed will default settings.")
214  end if !ncout condition
215 
216 !###########################################################
217 !##1 03. Set up dimensions : determine whether these are different for different datasets.
218 
219  multivals%ga_n_rules=0
220  multivals%gw_nqlwl=0
221  multivals%mband=0
222  multivals%natom=0
223  multivals%natpawu=0
224  multivals%natsph=0
225  multivals%natvshift=0
226  multivals%nberry=0
227  multivals%nbandhf=0
228  multivals%nconeq=0
229  multivals%nfreqsp=0
230  multivals%nimage=0
231  multivals%nimfrqs=0
232  multivals%nkpt=0
233  multivals%nkptgw=0
234  multivals%nkpthf=0
235  multivals%nnos=0
236  multivals%nqptdm=0
237  multivals%nshiftk=0
238  multivals%nsp=0
239  multivals%nspinor=0
240  multivals%nsppol=0
241  multivals%nsym=0
242  multivals%ntypat=0
243  multivals%ntypalch=0
244  multivals%nzchempot=0
245 
246  if(ndtset_alloc>1)then
247    do idtset=1,ndtset_alloc
248      if(dtsets(1)%ga_n_rules/=dtsets(idtset)%ga_n_rules) multivals%ga_n_rules =1
249      if(dtsets(1)%gw_nqlwl /=dtsets(idtset)%gw_nqlwl ) multivals%gw_nqlwl =1
250      if(dtsets(1)%mband    /=dtsets(idtset)%mband    ) multivals%mband    =1
251      if(dtsets(1)%natom    /=dtsets(idtset)%natom    ) multivals%natom    =1
252      if(dtsets(1)%natpawu  /=dtsets(idtset)%natpawu  ) multivals%natpawu  =1
253      if(dtsets(1)%natsph   /=dtsets(idtset)%natsph   ) multivals%natsph   =1
254      if(dtsets(1)%natvshift/=dtsets(idtset)%natvshift) multivals%natvshift=1
255      if(dtsets(1)%nberry   /=dtsets(idtset)%nberry   ) multivals%nberry   =1
256      if(dtsets(1)%nbandhf  /=dtsets(idtset)%nbandhf  ) multivals%nbandhf  =1
257      if(dtsets(1)%nconeq   /=dtsets(idtset)%nconeq   ) multivals%nconeq   =1
258      if(dtsets(1)%nfreqsp  /=dtsets(idtset)%nfreqsp  ) multivals%nfreqsp  =1
259      if(dtsets(1)%nimage   /=dtsets(idtset)%nimage   ) multivals%nimage   =1
260      if(dtsets(1)%cd_customnimfrqs  /=dtsets(idtset)%cd_customnimfrqs  ) multivals%nimfrqs  =1
261      if(dtsets(1)%nkpt     /=dtsets(idtset)%nkpt     ) multivals%nkpt     =1
262      if(dtsets(1)%nkptgw   /=dtsets(idtset)%nkptgw   ) multivals%nkptgw   =1
263      if(dtsets(1)%nkpthf*dtsets(1)%usefock /=dtsets(idtset)%nkpthf*dtsets(idtset)%usefock) multivals%nkpthf=1
264      if(dtsets(1)%nnos     /=dtsets(idtset)%nnos     ) multivals%nnos     =1
265      if(dtsets(1)%nqptdm   /=dtsets(idtset)%nqptdm   ) multivals%nqptdm   =1
266      if(dtsets(1)%nsppol*dtsets(1)%nspinor/=dtsets(idtset)%nsppol*dtsets(idtset)%nspinor) multivals%nsp=1
267      if(dtsets(1)%nsppol   /=dtsets(idtset)%nsppol   ) multivals%nsppol   =1
268      if(dtsets(1)%nspinor  /=dtsets(idtset)%nspinor  ) multivals%nspinor  =1
269      if(dtsets(1)%nsym     /=dtsets(idtset)%nsym     ) multivals%nsym     =1
270      if(dtsets(1)%ntypat   /=dtsets(idtset)%ntypat   ) multivals%ntypat   =1
271      if(dtsets(1)%ntypalch /=dtsets(idtset)%ntypalch ) multivals%ntypalch =1
272      if(dtsets(1)%nzchempot/=dtsets(idtset)%nzchempot) multivals%nzchempot=1
273    end do
274  end if
275 
276 !DEBUG
277 ! write(std_out,*)' outvars : multivals%nkpthf =',multivals%nkpthf
278 ! write(std_out,*)' outvars : dtsets(1:ndtset_alloc)%nkpthf =',dtsets(1:ndtset_alloc)%nkpthf
279 !ENDDEBUG
280 
281  nshiftk=1
282  if(sum((dtsets(1:ndtset_alloc)%kptopt)**2)/=0)then
283    first=0
284    do idtset=1,ndtset_alloc
285      kptopt=dtsets(idtset)%kptopt
286      if(kptopt>=1)then
287        if(first==0)then
288          first=1
289          nshiftk=dtsets(idtset)%nshiftk
290        else
291          if(nshiftk/=dtsets(idtset)%nshiftk)multivals%nshiftk=1
292        end if
293      end if
294    end do
295  end if
296 
297 !###########################################################
298 !### 04. Determine whether each dataset is (or not) a response calculation
299 !## (should use optdriver, isn't it ?)
300 
301  ABI_MALLOC(response_,(ndtset_alloc))
302  response_(:)=0
303  do idtset=1,ndtset_alloc
304    rfddk=dtsets(idtset)%rfddk
305    rfelfd=dtsets(idtset)%rfelfd
306    rfphon=dtsets(idtset)%rfphon
307    rfstrs=dtsets(idtset)%rfstrs
308    rfuser=dtsets(idtset)%rfuser
309    rfmagn=dtsets(idtset)%rfmagn
310    rf2_dkdk=dtsets(idtset)%rf2_dkdk
311    rf2_dkde=dtsets(idtset)%rf2_dkde
312    if(rfddk/=0 .or. rfelfd/=0 .or. rfphon/=0 .or. rfstrs/=0 .or. &
313 &   rfuser/=0 .or. rf2_dkdk/=0 .or. rf2_dkde/=0 .or. rfmagn/=0)then
314      response_(idtset)=1
315    end if
316  end do
317 
318 !###########################################################
319 !### 05. Determine size of work arrays
320 
321  marr=max(3*mxvals%natom,&
322 & mxvals%natsph,&
323 & mxvals%natvshift*mxvals%nsppol*mxvals%natom,&
324 & 3*mxvals%nberry,&
325 & mxvals%nimage,&
326 & 3*mxvals%nkptgw,&
327 & 3*mxvals%nkpthf,&
328 & mxvals%nkpt*mxvals%nsppol*mxvals%mband,&
329 & 3*mxvals%nkpt,npsp,&
330 & 3*mxvals%nqptdm,&
331 & mxvals%ntypat,&
332 & 9*mxvals%nsym,3*8,&
333 & 3*mxvals%natom*mxvals%nconeq,&
334 & mxvals%nnos,&
335 & 3*mxvals%nqptdm,&
336 & 3*mxvals%nzchempot*mxvals%ntypat,&
337 & 3*mxvals%gw_nqlwl,&
338 & (2*mxvals%lpawu+1)**2*max(mxvals%nsppol,mxvals%nspinor)*mxvals%natpawu*dmatpuflag,&
339 & 30 ) ! used by ga_rules TODO : replace with mxvals% ga_n_rules
340 
341 !###########################################################
342 !### 06. Initialize strimg
343 
344  ABI_MALLOC(strimg,(mxvals%nimage))
345  do iimage=1,mxvals%nimage
346    if(iimage<10)then
347      write(stringimage,'(i1)')iimage
348    else if(iimage<100)then
349      write(stringimage,'(i2)')iimage
350    else if(iimage<1000)then
351      write(stringimage,'(i3)')iimage
352    else if(iimage<10000)then
353      write(stringimage,'(i4)')iimage
354    end if
355    strimg(iimage)='_'//trim(stringimage)//'img'
356  end do
357  strimg(1)=''
358 
359 !###########################################################
360 !### 07. Initialize jdtset_
361 
362  ABI_MALLOC(jdtset_,(0:ndtset_alloc))
363  jdtset_(0:ndtset_alloc)=dtsets(0:ndtset_alloc)%jdtset
364 
365 
366 !###########################################################
367 !### 08. Print variables, for different ranges of names
368 
369  call outvar_a_h(choice,dmatpuflag,dtsets,iout,jdtset_,marr,multivals,mxvals,&
370 & ncid,ndtset,ndtset_alloc,results_out,strimg)
371 
372  call outvar_i_n(dtsets,iout,jdtset_,marr,multivals,mxvals,&
373 & ncid,ndtset,ndtset_alloc,npsp,prtvol_glob,response_,results_out,strimg)
374 
375  call outvar_o_z(choice,dtsets,iout,&
376 & jdtset_,marr,multivals,mxvals,ncid,ndtset,ndtset_alloc,npsp,prtvol_glob,&
377 & results_out,strimg,timopt)
378 
379 
380 !###########################################################
381 !## Deallocations and cleaning
382 
383  ABI_FREE(jdtset_)
384  ABI_FREE(response_)
385  ABI_FREE(strimg)
386 
387  write(message,'(a,80a)')ch10,('=',mu=1,80)
388  call wrtout(iout,message,'COLL')
389 
390 #ifdef HAVE_NETCDF
391  if (ncid /= 0 .and. dtsets(1)%ncout == 1) then
392    ncerr=nf90_close(abs(ncid))
393    if (ncerr/=nf90_NoErr) then
394      message='Netcdf Error while closing the OUT.nc file: '//trim(nf90_strerror(ncerr))
395      ABI_ERROR(message)
396    end if
397  end if
398 #endif
399  if (.false.) write(std_out,*) ncerr
400 
401 !**************************************************************************
402 
403 end subroutine outvars