Skip to content

Commit e72a06a

Browse files
committed
Adding ability to write initial grid configurations at each temperature in Metropolis routines
1 parent f364b1e commit e72a06a

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

src/metropolis.F90

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
6363
step_Esq, C, acceptance
6464

6565
! Name of file for grid state and xyz file at this temperature
66-
character(len=72) :: grid_file, xyz_file, xyz_trajectory_file
66+
character(len=80) :: grid_file, xyz_file, xyz_trajectory_file
6767

6868
! Name of file for writing diagnostics at the end
6969
character(len=72) :: energy_trajectory_file, asro_trajectory_file
@@ -100,6 +100,10 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
100100
if(my_rank == 0) call execute_command_line('mkdir -p trajectories')
101101
end if
102102

103+
! Make sure the required directories have been made before moving
104+
! to later portions of the calculation
105+
call comms_wait()
106+
103107
#ifdef USE_MPI
104108

105109
! Initialise some global arrays
@@ -171,9 +175,9 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
171175
! Store this in an array
172176
temperature(j) = temp
173177

174-
!---------!
175-
! Burn in !
176-
!---------!
178+
!----------------------------------------------------------------!
179+
! Burn in !
180+
!----------------------------------------------------------------!
177181
if (j==1) then
178182
if (metropolis%burn_in_start) then
179183
do i=1, metropolis%n_burn_in_steps
@@ -253,6 +257,7 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
253257
!-----------------------------------------------------------------!
254258
! Gather information about initial state of trajectory, if needed !
255259
!-----------------------------------------------------------------!
260+
256261
! Storing of data to do with energies
257262
if (metropolis%calculate_energies) then
258263
current_energy = setup%full_energy(config)
@@ -274,6 +279,31 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
274279
call xyz_writer(trim(xyz_trajectory_file), config, setup, .True.)
275280
end if
276281

282+
!-----------------------------------------------------------------!
283+
! Gather information about initial state of simulation, if needed !
284+
!-----------------------------------------------------------------!
285+
286+
! Dump grids as xyz files if needed
287+
if (metropolis%write_initial_config_xyz) then
288+
write(xyz_file, '(A13,I4.4,A20,I4.4,F2.1,A4)') 'configs/proc_', &
289+
my_rank, '_initial_config_at_T_', int(temp), temp-int(temp),'.xyz'
290+
291+
! Write xyz file
292+
call xyz_writer(trim(xyz_file), config, setup)
293+
end if
294+
295+
! Dump grids as NetCDF files if needed
296+
if (metropolis%write_initial_config_nc) then
297+
write(grid_file, '(A13,I4.4,A19,I4.4,F2.1,A3)') 'configs/proc_', my_rank, '_initial_config_at_T_', &
298+
int(temp), temp-int(temp), '.nc'
299+
! Write grid to file
300+
call ncdf_grid_state_writer(trim(grid_file), ierr, config, setup)
301+
end if
302+
303+
!----------------------------------------------------------------!
304+
! Main Monte Carlo loop !
305+
!----------------------------------------------------------------!
306+
277307
! Chop the run up into sweeps during which we need no draw no data
278308
! (Avoids unneccessary branching)
279309
n_sweeps = metropolis%n_mc_steps/metropolis%n_sample_steps
@@ -282,9 +312,6 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
282312
! Set acceptance rate back to zero for main MC loop
283313
acceptance = 0.0_real64
284314

285-
!-----------------------!
286-
! Main Monte Carlo loop !
287-
!-----------------------!
288315
do i=1, n_sweeps
289316

290317
do k=1, n_sweep_steps
@@ -388,16 +415,16 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
388415

389416
! Dump grids as xyz files if needed
390417
if (metropolis%write_final_config_xyz) then
391-
write(xyz_file, '(A13,I4.4,A12,I4.4,F2.1,A4)') 'configs/proc_', &
392-
my_rank, '_config_at_T_', int(temp), temp-int(temp),'.xyz'
418+
write(xyz_file, '(A13,I4.4,A18,I4.4,F2.1,A4)') 'configs/proc_', &
419+
my_rank, '_final_config_at_T_', int(temp), temp-int(temp),'.xyz'
393420

394421
! Write xyz file
395422
call xyz_writer(trim(xyz_file), config, setup)
396423
end if
397424

398425
! Dump grids as NetCDF files if needed
399426
if (metropolis%write_final_config_nc) then
400-
write(grid_file, '(A13,I4.4,A11,I4.4,F2.1,A3)') 'configs/proc_', my_rank, '_grid_at_T_', &
427+
write(grid_file, '(A13,I4.4,A17,I4.4,F2.1,A3)') 'configs/proc_', my_rank, '_final_config_at_T_', &
401428
int(temp), temp-int(temp), '.nc'
402429
! Write grid to file
403430
call ncdf_grid_state_writer(trim(grid_file), ierr, config, setup)
@@ -422,8 +449,10 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
422449

423450
end do ! Loop over temperature
424451

425-
426-
452+
!------------------------------------------------------------------!
453+
! Final results !
454+
!------------------------------------------------------------------!
455+
427456
! Write energy diagnostics
428457
if (metropolis%calculate_energies) then
429458
write(diagnostics_file, '(A,I4.4,A)') 'energies/proc_', my_rank, &
@@ -471,6 +500,10 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
471500

472501
#endif
473502

503+
!------------------------------------------------------------------!
504+
! Clean up !
505+
!------------------------------------------------------------------!
506+
474507
if (allocated(r_densities)) deallocate(r_densities)
475508
if (allocated(asro)) deallocate(asro)
476509
if (allocated(order)) deallocate(order)
@@ -520,7 +553,7 @@ subroutine metropolis_decorrelated_samples(setup, metropolis, my_rank)
520553
real(real64) :: beta, temp, sim_temp, current_energy, acceptance
521554

522555
! Name of xyz file
523-
character(len=42) :: xyz_file
556+
character(len=50) :: xyz_file
524557

525558
! Read the Metropolis control file
526559
call parse_metropolis_inputs(metropolis, my_rank)

0 commit comments

Comments
 (0)