diff --git a/fluidsim/base/output/movies.py b/fluidsim/base/output/movies.py index 751474ed55dc487a4ef09823af4e086e5139cde4..c4c4a1207029386ce37c1597ad7fb63b5b17376f 100644 --- a/fluidsim/base/output/movies.py +++ b/fluidsim/base/output/movies.py @@ -56,11 +56,11 @@ class MoviesBase: tmax = self.sim.time_stepping.t if tmin is None: - tmin = 0 + tmin = self.phys_fields.set_of_phys_files.get_min_time() if tmin > tmax: raise ValueError( - "Error tmin > tmax. " "Value tmin should be smaller than tmax" + "Error tmin > tmax. Value tmin should be smaller than tmax" ) if dt_equations is None: @@ -210,10 +210,17 @@ class MoviesBase: self.init_animation( key_field, numfig, dt_equations, tmin, tmax, fig_kw, **kwargs ) + + if isinstance(repeat, int): + nb_repeat = repeat + repeat = False + else: + nb_repeat = 1 + self._animation = animation.FuncAnimation( self.fig, self.update_animation, - len(self.ani_times), + nb_repeat * len(self.ani_times), fargs=fargs.items(), interval=dt_frame_in_sec * 1000, blit=False, @@ -374,7 +381,7 @@ class MoviesBase1D(MoviesBase): def update_animation(self, frame, **fargs): """Loads contour data and updates figure.""" print("update_animation for frame", frame, " ", end="\r") - time = self.ani_times[frame] + time = self.ani_times[frame % len(self.ani_times)] get_field_to_plot = self.phys_fields.get_field_to_plot y, time = get_field_to_plot(time=time, key=self.key_field) x = self._get_axis_data() diff --git a/fluidsim/base/output/phys_fields.py b/fluidsim/base/output/phys_fields.py index 3a42fa17b013cd6cbbcf115315e517bf868b9c2d..7a894355a487ceaf468425219340cdac58709152 100644 --- a/fluidsim/base/output/phys_fields.py +++ b/fluidsim/base/output/phys_fields.py @@ -315,6 +315,11 @@ class SetOfPhysFieldFiles: self.path_files = sorted(path_files) self.times = np.array([time_from_path(path) for path in self.path_files]) + def get_min_time(self): + if hasattr(self, "times"): + return self.times.min() + return 0. + def get_field_to_plot( self, time=None, diff --git a/fluidsim/base/output/phys_fields2d.py b/fluidsim/base/output/phys_fields2d.py index 6afdf07123bfbe51e91288659d91587b5b4dcd27..7fe672d761f9b4e533f24ec8d4c8aecc1786c04f 100644 --- a/fluidsim/base/output/phys_fields2d.py +++ b/fluidsim/base/output/phys_fields2d.py @@ -167,7 +167,7 @@ class MoviesBasePhysFields2D(MoviesBase2D): """Loads data and updates figure.""" print("update_animation for frame", frame, " ", end="\r") - time = self.ani_times[frame] + time = self.ani_times[frame % len(self.ani_times)] step = self._step get_field_to_plot = self.phys_fields.get_field_to_plot @@ -227,7 +227,7 @@ class MoviesBasePhysFields2D(MoviesBase2D): self._ani_cbar.set_ticks(ticks) def _get_spatial_means(self, key_spatial="E"): - """ Get field for the inset plot.""" + """Get field for the inset plot.""" # Check if key_spatial can be loaded. keys_spatial = ["E", "EK", "EA"] if key_spatial not in keys_spatial: