Dice Fortran Backend Documentation
input_parser.f90
Go to the documentation of this file.
1 ! ---------------------------------------------------------------------------------------
2 ! Dice Quantum Monte Carlo
3 ! ---------------------------------------------------------------------------------------
4 ! MODULE: input parser
5 !
6 ! DESCRIPTION:
9 !
14 ! ---------------------------------------------------------------------------------------
15 
17 
18  use shared_data
19  use restart_fns
20 
21  implicit none
22 
23 contains
24 
25 
26 ! ---------------------------------------------------------------------------------------
27 ! SECTION: Namelist Parsers
28 ! ---------------------------------------------------------------------------------------
29 
30 
31  ! -----------------------------------------------------------------------------------
32  ! ROUTINE: read_control
33  !
34  ! DESCRIPTION:
38  !
39  ! PARAMETERS:
47  ! -----------------------------------------------------------------------------------
48  subroutine read_control(p_system, run_equil, run_restart, write_restart, restart_num, write_chains, write_log)
49 
50  ! Local variables
51  character(len=10), intent(out) :: p_system
52  logical, intent(out) :: run_equil, run_restart, write_restart, write_chains, write_log
53  integer(int32), intent(out) :: restart_num
54 
55  ! Define the namelist
56  namelist /control/ p_system, run_equil, run_restart, write_restart, restart_num, write_chains, write_log
57 
58  ! Read the namelist
59  read(nml=control, iostat=rc, unit=fu)
60  if (rc /= 0) then
61  error stop 'Error: Invalid CONTROL namelist format in file "params.txt".'
62  end if
63 
64  end subroutine read_control
65 
66  ! -----------------------------------------------------------------------------------
67  ! ROUTINE: read_QHO
68  !
69  ! DESCRIPTION:
73  !
74  ! PARAMETERS:
76  ! -----------------------------------------------------------------------------------
77  subroutine read_qho(QHO)
78 
79  ! Local variables
80  type(qho_type), intent(out) :: QHO
81 
82  ! Define the namelist
83  namelist /parameters/ qho
84 
85  ! Read the namelist
86  read(nml=parameters, iostat=rc, unit=fu)
87  if (rc /= 0) then
88  error stop 'Error: Invalid PARAMETERS namelist for QHO p_system in file "params.txt".'
89  end if
90 
91  end subroutine read_qho
92 
93  ! -----------------------------------------------------------------------------------
94  ! ROUTINE: read_H2plus
95  !
96  ! DESCRIPTION:
100  !
101  ! PARAMETERS:
103  ! -----------------------------------------------------------------------------------
104  subroutine read_h2plus(H2plus)
105 
106  ! Local variables
107  type(h2plus_type), intent(out) :: H2plus
108 
109  ! Define the namelist
110  namelist /parameters/ h2plus
111 
112  ! Read the namelist
113  read(nml=parameters, iostat=rc, unit=fu)
114  if (rc /= 0) then
115  error stop 'Error: Invalid PARAMETERS namelist for H2plus p_system in file "params.txt".'
116  end if
117 
118  end subroutine read_h2plus
119 
120  ! -----------------------------------------------------------------------------------
121  ! ROUTINE: read_H2
122  !
123  ! DESCRIPTION:
127  !
128  ! PARAMETERS:
130  ! -----------------------------------------------------------------------------------
131  subroutine read_h2(H2)
132 
133  ! Local variables
134  type(h2_type), intent(out) :: H2
135 
136  ! Define the namelist
137  namelist /parameters/ h2
138 
139  ! Read the namelist
140  read(nml=parameters, iostat=rc, unit=fu)
141  if (rc /= 0) then
142  error stop 'Error: Invalid PARAMETERS namelist for H2 p_system in file "params.txt".'
143  end if
144 
145  end subroutine read_h2
146 
147 
148 ! ---------------------------------------------------------------------------------------
149 ! SECTION: Input Main
150 ! ---------------------------------------------------------------------------------------
151 
152 
153  ! -----------------------------------------------------------------------------------
154  ! ROUTINE: read_inputs
155  !
156  ! DESCRIPTION:
160  !
163  ! -----------------------------------------------------------------------------------
164  subroutine read_inputs()
165 
166  ! Check if file 'params.txt' exists
167  inquire(file='params.txt', iostat=rc)
168  if (rc /= 0) then
169  error stop 'Error: Input file "params.txt" does not exist.'
170  end if
171 
172  ! Open the params.txt file
173  open(action='read', file='params.txt', iostat=rc, newunit=fu)
174 
175  ! Read CONTROL namelist
177 
178  ! If p_system='test', return to main
179  if (trim(p_system)=='test') then
180  return
181  endif
182 
183  ! For equilibration runs, modify the default steps
184  if (run_equil) then
185  select case (trim(p_system))
186  case ('QHO')
187  qho%steps = d_eqsteps_qho
188  case ('H2plus')
189  h2plus%steps = d_eqsteps_h2plus
190  case ('H2')
191  h2%steps = d_eqsteps_h2
192  case default
193  error stop 'Error: Invalid system definition.'
194  end select
195  endif
196 
197  ! Read PARAMETERS namelist of the defined problem
198  select case (trim(p_system))
199  case ('QHO')
200  call read_qho(qho)
201  case ('H2plus')
202  call read_h2plus(h2plus)
203  case ('H2')
204  call read_h2(h2)
205  case default
206  error stop 'Error: Invalid system definition.'
207  end select
208 
209  ! Close the params.txt file
210  close(fu)
211 
212  ! For equilibration runs, ensure burn_step=0 & thin_step=1
213  if (run_equil) then
214  select case (trim(p_system))
215  case ('QHO')
216  qho%burn_step = 0
217  qho%thin_step = 1
218  case ('H2plus')
219  h2plus%burn_step = 0
220  h2plus%thin_step = 1
221  case ('H2')
222  h2%burn_step = 0
223  h2%thin_step = 1
224  case default
225  error stop 'Error: Invalid system definition.'
226  end select
227  endif
228 
229  ! Find run steps and thin step for checks
230  select case (trim(p_system))
231  case ('QHO')
232  run_steps = qho%steps - qho%burn_step
233  tstep = qho%thin_step
234  case ('H2plus')
235  run_steps = h2plus%steps - h2plus%burn_step
236  tstep = h2plus%thin_step
237  case ('H2')
238  run_steps = h2%steps - h2%burn_step
239  tstep = h2%thin_step
240  case default
241  error stop 'Error: Invalid system definition.'
242  end select
243 
244  ! For restart runs
245  if (run_restart) then
246 
247  ! Read RESTART namelist
248  call read_res_nml(res)
249 
250  ! Update grid-loop start values
251  if (trim(p_system) == 'QHO') then
252  alpha_start = res%i_qoi
253  else
254  bond_start = res%i_qoi
255  if (res%auto) then
256  ! For auto-search routines
257  auto_start = res%i_par
258  else
259  ! For grid-search routines
260  grid_start = res%i_par
261  endif
262 
263  endif
264 
265  ! Print restarts header.
266  if (my_rank==0) then
267  write(*, "('------------- Restarted Program -------------')")
268  write(*, "('')")
269  endif
270 
271  end if
272 
273 
274  end subroutine read_inputs
275 
276 
277 end module input_parser
Contains routines that read the input file params.txt.
subroutine read_h2(H2)
Reads the PARAMETER namelist in params.txt for the H2 molecule system. Assigns the input data to the ...
subroutine read_control(p_system, run_equil, run_restart, write_restart, restart_num, write_chains, write_log)
Reads the CONTROL namelist in params.txt and assigns its data to the corresponding global variables d...
subroutine read_inputs()
Main input parser function that reads the input file params.txt and calls the required namelist parse...
subroutine read_h2plus(H2plus)
Reads the PARAMETER namelist in params.txt for the H2 ion system. Assigns the input data to the corre...
subroutine read_qho(QHO)
Reads the PARAMETER namelist in params.txt for the QHO system. Assigns the input data to the correspo...
Contains routines to read and write restart files.
Definition: restart_fns.f90:15
subroutine read_res_nml(res)
Reads the RESTART namelist in res_nml.txt. Assigns the input data to the corresponding variables in t...
integer rc
To capture error states during file i/o.
Definition: restart_fns.f90:24
integer fu
To store LUN of files during i/o.
Definition: restart_fns.f90:23
Contains derived types, and global variables to store input values of simulation parameters.
Definition: shared_data.f90:49
integer(int32) run_steps
Number of MMC steps after burning (for MPI worksharing)
integer(int32) restart_num
Interval of MMC loops between writing restart file.
integer(int32) d_eqsteps_qho
Default total steps for each QHO equilibration MMC chain.
type(h2_type) h2
To store inputs for H2 molecule system.
type(h2plus_type) h2plus
To store inputs for H2 ion system.
integer(int32) alpha_start
Start value for alpha grid, can be >1 for restarts.
logical run_restart
Tag for restart runs.
type(restart_type) res
Instance of restart_type for reading restart files.
integer(int32) tstep
Interval of steps for thinning in non-equil runs (for MPI worksharing)
integer(int32) auto_start
Start value for automatic search of parameter c, can be >1 for restarts.
logical write_chains
Tag to write final MMC chains.
type(qho_type) qho
To store inputs for QHO system.
integer(int32) d_eqsteps_h2
Default total steps for each H2 equilibration MMC chain.
logical run_equil
Tag for equilibration runs.
integer(int32) grid_start
Start value for grid search of parameter c, can be >1 for restarts.
integer(int32) bond_start
Start value for bondlength grid, can be >1 for restarts.
character(len=10) p_system
System of interest: QHO, H2plus, H2.
logical write_log
Tag to write logfile.
logical write_restart
Tag for writing restart files.
integer(int32) d_eqsteps_h2plus
Default total steps for each H2plus equilibration MMC chain.
integer(int32) my_rank
Rank of current processor.
Derived Type for Hydrogen Molecule, including VQMC defaults.
Definition: shared_data.f90:97
Derived Type for Hydrogen Ion, including VQMC defaults.
Definition: shared_data.f90:79
Derived Type for Quantum Harmonic Oscillator, including VQMC defaults.
Definition: shared_data.f90:67