(self, cond, step_funcs)
| 2802 | return dname |
| 2803 | |
| 2804 | def _run_until(self, cond, step_funcs): |
| 2805 | self.interactive = False |
| 2806 | if self.fields is None: |
| 2807 | self.init_sim() |
| 2808 | |
| 2809 | if not isinstance(cond, list): |
| 2810 | cond = [cond] |
| 2811 | |
| 2812 | self.progress = False |
| 2813 | for i in range(len(cond)): |
| 2814 | if isinstance(cond[i], numbers.Number): |
| 2815 | stop_time = cond[i] |
| 2816 | t0 = self.round_time() |
| 2817 | |
| 2818 | def stop_cond(sim): |
| 2819 | return sim.round_time() >= t0 + stop_time |
| 2820 | |
| 2821 | cond[i] = stop_cond |
| 2822 | |
| 2823 | step_funcs = list(step_funcs) |
| 2824 | step_funcs.append( |
| 2825 | display_progress(t0, t0 + stop_time, self.progress_interval) |
| 2826 | ) |
| 2827 | |
| 2828 | if do_progress: |
| 2829 | self.progress = FloatProgress( |
| 2830 | value=t0, min=t0, max=t0 + stop_time, description="0% done " |
| 2831 | ) |
| 2832 | display(self.progress) |
| 2833 | else: |
| 2834 | assert callable( |
| 2835 | cond[i] |
| 2836 | ), "Stopping condition {} is not an integer or a function".format( |
| 2837 | cond[i] |
| 2838 | ) |
| 2839 | |
| 2840 | while not any([x(self) for x in cond]): |
| 2841 | for func in step_funcs: |
| 2842 | _eval_step_func(self, func, "step") |
| 2843 | self.fields.step() |
| 2844 | |
| 2845 | # Translating the recursive scheme version of run-until into an iterative version |
| 2846 | # (because python isn't tail-call-optimized) means we need one extra iteration to |
| 2847 | # be the same as scheme. |
| 2848 | for func in step_funcs: |
| 2849 | _eval_step_func(self, func, "step") |
| 2850 | |
| 2851 | for func in step_funcs: |
| 2852 | _eval_step_func(self, func, "finish") |
| 2853 | |
| 2854 | if do_progress and self.progress: |
| 2855 | self.progress.value = t0 + stop_time |
| 2856 | self.progress.description = "100% done " |
| 2857 | |
| 2858 | if verbosity.meep > 0: |
| 2859 | print( |
| 2860 | "run {} finished at t = {} ({} timesteps)".format( |
| 2861 | self.run_index, self.meep_time(), self.fields.t |
no test coverage detected