Skip to content

Commit c7f72ad

Browse files
committed
Error-handling of (small) negative heat capacity due to rounding errors
1 parent aa15772 commit c7f72ad

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/metropolis.F90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ subroutine metropolis_simulated_annealing(setup, metropolis, my_rank)
359359
C = (step_Esq/n_save_energy - (step_E/n_save_energy)**2) &
360360
/(sim_temp*temp)/setup%n_atoms
361361

362+
! Heat capacity should always be positive, but floating point
363+
! errors in the summation means we sometimes get a negative
364+
! number, so make it zero if this is the case
365+
if (C .lt. 0.0_real64) then
366+
C = 0.0_real64
367+
end if
368+
369+
! If the simulation temperature is exactly zero, set the heat
370+
! capacity to be zero, too.
371+
if (temp .le. 0.0_real64) then
372+
C = 0.0_real64
373+
end if
374+
362375
! Store the specific heat capacity at this temperature
363376
C_of_T(j) = C
364377
end if

0 commit comments

Comments
 (0)