Skip to content

Commit

Permalink
Fix on the Mesh interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
mesonepigreco committed Nov 20, 2024
1 parent fbb69b8 commit 37aac7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Modules/Ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ def get_free_energy(self, return_error = False):
return free_energy


def get_free_energy_interpolating(self, target_supercell, support_dyn_coarse = None, support_dyn_fine = None, error_on_imaginary_frequency = True, return_error = False):
def get_free_energy_interpolating(self, target_supercell, support_dyn_coarse = None, support_dyn_fine = None, error_on_imaginary_frequency = True, return_error = False, use_lo_to_splitting = False):
"""
GET THE FREE ENERGY IN A BIGGER CELL
====================================
Expand Down Expand Up @@ -2337,6 +2337,7 @@ def get_free_energy_interpolating(self, target_supercell, support_dyn_coarse = N
return_error : bool
As the normal get_free_energy, if this flag is True, the stochastic error is returned.
Returns
-------
free_energy : float
Expand All @@ -2354,17 +2355,17 @@ def get_free_energy_interpolating(self, target_supercell, support_dyn_coarse = N


# Interpolate the dynamical matrix
if support_dyn_fine is not None:
new_dyn = self.current_dyn.Interpolate( self.current_dyn.GetSupercell(),
target_supercell,
support_dyn_coarse,
support_dyn_fine)
if not use_lo_to_splitting:
if support_dyn_fine is not None:
new_dyn = self.current_dyn.Interpolate( self.current_dyn.GetSupercell(),
target_supercell,
support_dyn_coarse,
support_dyn_fine)
else:
new_dyn = self.current_dyn.Interpolate( self.current_dyn.GetSupercell(),
target_supercell)
else:
new_dyn = self.current_dyn.Interpolate( self.current_dyn.GetSupercell(),
target_supercell)

#else:
# new_dyn = self.current_dyn.InterpolateMesh(target_supercell, lo_to_splitting = True)
new_dyn = self.current_dyn.InterpolateMesh(target_supercell, lo_to_splitting = True)

#print("dyn after interpolation:", new_dyn.GetSupercell())

Expand Down
7 changes: 7 additions & 0 deletions Modules/SchaMinimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def __init__(self, ensemble = None, root_representation = "normal",

# Setup the meaningful_factor
self.meaningful_factor = meaningful_factor
self.abs_conv_thr = 1e-8 # Below this number the minimization is considered converged

# Setup the minimization algorithm
self.minimization_algorithm = minimization_algorithm
Expand Down Expand Up @@ -935,6 +936,7 @@ def print_info(self):
print (" number of configurations = ", self.ensemble.N)
print (" max number of steps (infinity if negative) = ", self.max_ka)
print (" meaningful factor = ", self.meaningful_factor)
print (" absolute convergence threshold = ", self.abs_conv_thr)
print (" gradient to watch (for stopping) = ", self.gradi_op)
print (" Kong-Liu minimum effective sample size = ", self.ensemble.N * self.kong_liu_ratio)
print (" (Kong-Liu ratio = ", self.kong_liu_ratio, ")")
Expand Down Expand Up @@ -1617,6 +1619,11 @@ def check_stop(self, timer=None):
gc_cond = (last_gc < last_gc_err * self.meaningful_factor)
gw_cond = (last_gw < last_gw_err * self.meaningful_factor)

# Add a condition on the absolute value of the gradient
# (For perfectly harmonic systems, the error goes to zero)
gc_cond = gc_cond or (last_gc < self.abs_conv_thr)
gw_cond = gw_cond or (last_gw < self.abs_conv_thr)

total_cond = False

if gc_cond:
Expand Down

0 comments on commit 37aac7a

Please sign in to comment.