From 11ecd301abc9d84cea27fd9ecc9366ab2b6d7913 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 29 Aug 2024 18:33:09 +0000 Subject: [PATCH 1/3] added possibility to not display the progress bar --- festim/problem.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/festim/problem.py b/festim/problem.py index 79c73a110..f8444155b 100644 --- a/festim/problem.py +++ b/festim/problem.py @@ -37,6 +37,7 @@ def __init__( self.volume_meshtags = None self.formulation = None self.bc_forms = [] + self.progress_bar = True @property def volume_subdomains(self): @@ -102,14 +103,16 @@ def run(self): if self.settings.transient: # Solve transient - self.progress = tqdm.autonotebook.tqdm( - desc=f"Solving {self.__class__.__name__}", - total=self.settings.final_time, - unit_scale=True, - ) + if self.progress_bar: + self.progress = tqdm.autonotebook.tqdm( + desc=f"Solving {self.__class__.__name__}", + total=self.settings.final_time, + unit_scale=True, + ) while self.t.value < self.settings.final_time: self.iterate() - self.progress.refresh() # refresh progress bar to show 100% + if self.progress_bar: + self.progress.refresh() # refresh progress bar to show 100% else: # Solve steady-state self.solver.solve(self.u) @@ -117,9 +120,10 @@ def run(self): def iterate(self): """Iterates the model for a given time step""" - self.progress.update( - min(self.dt.value, abs(self.settings.final_time - self.t.value)) - ) + if self.progress_bar: + self.progress.update( + min(self.dt.value, abs(self.settings.final_time - self.t.value)) + ) self.t.value += self.dt.value self.update_time_dependent_values() From a005f5707183e26d89bcbbec42f886b824d79db9 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 29 Aug 2024 18:37:42 +0000 Subject: [PATCH 2/3] docs + renamed attribute --- festim/problem.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/festim/problem.py b/festim/problem.py index f8444155b..582ea6385 100644 --- a/festim/problem.py +++ b/festim/problem.py @@ -10,6 +10,10 @@ class ProblemBase: """ Base class for HeatTransferProblem and HTransportProblem. + + show_progress_bar (bool): True if a progress bar is displayed during the + simulation + progress_bar (tqdm.autonotebook.tqdm) the progress bar """ def __init__( @@ -37,7 +41,7 @@ def __init__( self.volume_meshtags = None self.formulation = None self.bc_forms = [] - self.progress_bar = True + self.show_progress_bar = True @property def volume_subdomains(self): @@ -103,16 +107,16 @@ def run(self): if self.settings.transient: # Solve transient - if self.progress_bar: - self.progress = tqdm.autonotebook.tqdm( + if self.show_progress_bar: + self.progress_bar = tqdm.autonotebook.tqdm( desc=f"Solving {self.__class__.__name__}", total=self.settings.final_time, unit_scale=True, ) while self.t.value < self.settings.final_time: self.iterate() - if self.progress_bar: - self.progress.refresh() # refresh progress bar to show 100% + if self.show_progress_bar: + self.progress_bar.refresh() # refresh progress bar to show 100% else: # Solve steady-state self.solver.solve(self.u) @@ -120,8 +124,8 @@ def run(self): def iterate(self): """Iterates the model for a given time step""" - if self.progress_bar: - self.progress.update( + if self.show_progress_bar: + self.progress_bar.update( min(self.dt.value, abs(self.settings.final_time - self.t.value)) ) self.t.value += self.dt.value From 348183b4b2382a338f69e7414b7c5cf7ecae61c4 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 29 Aug 2024 18:40:36 +0000 Subject: [PATCH 3/3] fixed tests --- test/test_h_transport_problem.py | 6 +++--- test/test_heat_transfer_problem.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_h_transport_problem.py b/test/test_h_transport_problem.py index f2e00ded0..bec6e2fd7 100644 --- a/test/test_h_transport_problem.py +++ b/test/test_h_transport_problem.py @@ -129,7 +129,7 @@ def test_iterate(): my_model.settings = F.Settings(atol=1e-6, rtol=1e-6, final_time=10) my_model.settings.stepsize = 2.0 - my_model.progress = tqdm.autonotebook.tqdm( + my_model.progress_bar = tqdm.autonotebook.tqdm( desc="Solving H transport problem", total=my_model.settings.final_time, unit_scale=True, @@ -915,7 +915,7 @@ def test_adaptive_timestepping_grows(): my_model.initialise() - my_model.progress = tqdm.autonotebook.tqdm( + my_model.progress_bar = tqdm.autonotebook.tqdm( desc="Solving H transport problem", total=my_model.settings.final_time, unit_scale=True, @@ -951,7 +951,7 @@ def test_adaptive_timestepping_shrinks(): my_model.initialise() - my_model.progress = tqdm.autonotebook.tqdm( + my_model.progress_bar = tqdm.autonotebook.tqdm( desc="Solving H transport problem", total=my_model.settings.final_time, unit_scale=True, diff --git a/test/test_heat_transfer_problem.py b/test/test_heat_transfer_problem.py index b83982575..30027dd4a 100644 --- a/test/test_heat_transfer_problem.py +++ b/test/test_heat_transfer_problem.py @@ -514,7 +514,7 @@ def test_adaptive_timestepping_grows(): my_model.initialise() - my_model.progress = tqdm.autonotebook.tqdm( + my_model.progress_bar = tqdm.autonotebook.tqdm( desc="Solving H transport problem", total=my_model.settings.final_time, unit_scale=True, @@ -548,7 +548,7 @@ def test_adaptive_timestepping_shrinks(): my_model.initialise() - my_model.progress = tqdm.autonotebook.tqdm( + my_model.progress_bar = tqdm.autonotebook.tqdm( desc="Solving H transport problem", total=my_model.settings.final_time, unit_scale=True,