Skip to content

Commit

Permalink
Merge pull request festim-dev#879 from festim-dev/progress-bar-optional
Browse files Browse the repository at this point in the history
added possibility to not display the progress bar
  • Loading branch information
RemDelaporteMathurin authored Aug 30, 2024
2 parents 02a374f + 348183b commit 77c97b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
26 changes: 17 additions & 9 deletions festim/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -37,6 +41,7 @@ def __init__(
self.volume_meshtags = None
self.formulation = None
self.bc_forms = []
self.show_progress_bar = True

@property
def volume_subdomains(self):
Expand Down Expand Up @@ -102,24 +107,27 @@ 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.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()
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)
self.post_processing()

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.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

self.update_time_dependent_values()
Expand Down
6 changes: 3 additions & 3 deletions test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/test_heat_transfer_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 77c97b3

Please sign in to comment.