fix: floating point number practically causing an infinite loop

This commit is contained in:
Anthony Berg 2025-03-29 22:16:55 +01:00
parent 5a27445de8
commit aa21733806

View File

@ -157,7 +157,7 @@ class BaseSimulator(object):
self.num_substeps = num_substeps
#Handle autotuning block size
if (self.context.autotuner):
if self.context.autotuner:
peak_configuration = self.context.autotuner.get_peak_performance(self.__class__)
block_width = int(peak_configuration["block_width"])
block_height = int(peak_configuration["block_height"])
@ -202,22 +202,22 @@ class BaseSimulator(object):
t_end = t_start + t
update_dt = True
if (dt is not None):
if dt is not None:
update_dt = False
self.dt = dt
with tqdm(total=t_end) as pbar:
while(self.simTime() < t_end):
for _ in tqdm(range(math.ceil(t_end / self.dt))):
# Update dt every 100 timesteps and cross your fingers it works
# for the next 100
if (update_dt and (self.simSteps() % 100 == 0)):
# TODO this is probably broken now after fixing the "infinite" loop
if update_dt and (self.simSteps() % 100 == 0):
self.dt = self.computeDt()*self.cfl_scale
# Compute timestep for "this" iteration (i.e., shorten last timestep)
current_dt = np.float32(min(self.dt, t_end-self.simTime()))
# Stop if end reached (should not happen)
if (current_dt <= 0.0):
if current_dt <= 0.0:
self.logger.warning("Timestep size {:d} is less than or equal to zero!".format(self.simSteps()))
break
@ -225,7 +225,6 @@ class BaseSimulator(object):
self.step(current_dt)
#Print info
pbar.update(current_dt)
# print_string = printer.getPrintString(self.simTime() - t_start)
# if (print_string):
# self.logger.info("%s: %s", self, print_string)