From 90f75dc33f98fa3903c86c96d1a5fca1bf2cb586 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 00:55:34 +0200 Subject: [PATCH 1/8] `Job`: Reduce default output and use a progress bar instead --- src/felupe/mechanics/_job.py | 71 ++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/src/felupe/mechanics/_job.py b/src/felupe/mechanics/_job.py index bdbbf2c9..acc42a94 100644 --- a/src/felupe/mechanics/_job.py +++ b/src/felupe/mechanics/_job.py @@ -55,6 +55,29 @@ def log_strain(field, substep=None): return [tovoigt(strain.mean(-2), True).T] +def header(verbose): + if verbose == 1: + return "\n".join([ + f"FElupe Version {version}", + f"{platform(terse=True)} {machine()} {architecture()[0]}", + "", + ]) + elif verbose > 1: + return f""" + _______ _______ ___ __ __ _______ _______ +| || || | | | | || || | +| ___|| ___|| | | | | || _ || ___| +| |___ | |___ | | | |_| || |_| || |___ +| ___|| ___|| |___ | || ___|| ___| +| | | |___ | || || | | |___ +|___| |_______||_______||_______||___| |_______| +FElupe Version {version} ({platform(terse=True)} {machine()} {architecture()[0]}) + +Run Job +======= +""" + + class Job: "A job with a list of steps." @@ -90,29 +113,20 @@ def evaluate( parallel=False, **kwargs, ): + try: + from tqdm import tqdm + except ModuleNotFoundError: + verbose = 2 if verbose: - print( - f""" - _______ _______ ___ __ __ _______ _______ -| || || | | | | || || | -| ___|| ___|| | | | | || _ || ___| -| |___ | |___ | | | |_| || |_| || |___ -| ___|| ___|| |___ | || ___|| ___| -| | | |___ | || || | | |___ -|___| |_______||_______||_______||___| |_______| -FElupe Version {version} ({platform(terse=True)} {machine()} {architecture()[0]}) - -""" - ) - - print("Run Job") - print("=======\n") + print(header(verbose)) if parallel: if "kwargs" not in kwargs.keys(): kwargs["kwargs"] = {} kwargs["kwargs"]["parallel"] = True + + increment = 0 if filename is not None: from meshio.xdmf import TimeSeriesWriter @@ -123,8 +137,6 @@ def evaluate( else: mesh = self.steps[0].items[0].field.region.mesh.as_meshio() - increment = 0 - pdata = point_data_default if point_data_default is True else {} cdata = cell_data_default if cell_data_default is not None else {} @@ -156,17 +168,23 @@ def evaluate( if filename is not None: writer.write_points_cells(mesh.points, mesh.cells) + + if verbose == 1: + total = sum([step.nsubsteps for step in self.steps]) + progress_bar = tqdm(total=total, unit=" substeps") for j, step in enumerate(self.steps): - if verbose: + newton_verbose = False + if verbose == 2: print(f"Begin Evaluation of Step {j + 1}.") + newton_verbose = True - substeps = step.generate(verbose=verbose, **kwargs) + substeps = step.generate(verbose=newton_verbose, **kwargs) for i, substep in enumerate(substeps): - if verbose: - _substep = f"Substep {i}/{step.nsubsteps - 1}" + if verbose == 2: + _substep = f"Substep {i + 1}/{step.nsubsteps}" _step = f"Step {j + 1}/{self.nsteps}" print(f"{_substep} of {_step} successful.") @@ -186,4 +204,11 @@ def evaluate( point_data={**pdata, **point_data}, cell_data={**cdata, **cell_data}, ) - increment += 1 + + increment += 1 + + if verbose == 1: + progress_bar.update(1) + + if verbose == 1: + progress_bar.close() From 05d9033c501d43033c1317fb1d35d735e97650a0 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 00:59:12 +0200 Subject: [PATCH 2/8] Update test_job.py --- tests/test_job.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index 55fa8abd..8082adba 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -51,7 +51,7 @@ def test_job(): field, step = pre() job = fem.Job(steps=[step]) - job.evaluate(parallel=True, kwargs={"parallel": False}) + job.evaluate(parallel=True, kwargs={"parallel": False}, verbose=0) def test_job_xdmf(): @@ -62,7 +62,7 @@ def test_job_xdmf(): field, step = pre() job = fem.Job(steps=[step]) - job.evaluate(filename="result.xdmf", parallel=True) + job.evaluate(filename="result.xdmf", parallel=True, verbose=2) def test_job_xdmf_global_field(): From 1ee04009b69cc6885f72ba7ee203e4bd9d720f4d Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 00:59:19 +0200 Subject: [PATCH 3/8] Update _job.py --- src/felupe/mechanics/_job.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/felupe/mechanics/_job.py b/src/felupe/mechanics/_job.py index acc42a94..cbbf1a11 100644 --- a/src/felupe/mechanics/_job.py +++ b/src/felupe/mechanics/_job.py @@ -125,7 +125,7 @@ def evaluate( if "kwargs" not in kwargs.keys(): kwargs["kwargs"] = {} kwargs["kwargs"]["parallel"] = True - + increment = 0 if filename is not None: @@ -168,7 +168,7 @@ def evaluate( if filename is not None: writer.write_points_cells(mesh.points, mesh.cells) - + if verbose == 1: total = sum([step.nsubsteps for step in self.steps]) progress_bar = tqdm(total=total, unit=" substeps") @@ -204,11 +204,11 @@ def evaluate( point_data={**pdata, **point_data}, cell_data={**cdata, **cell_data}, ) - + increment += 1 - + if verbose == 1: progress_bar.update(1) - + if verbose == 1: progress_bar.close() From ba33e23393ac5afd8a546a3fe0a28f9b512d4ce1 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 01:03:50 +0200 Subject: [PATCH 4/8] Update index.rst --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 4ac5c8e9..4a9bc5aa 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -57,7 +57,7 @@ Another key feature is the easy and straightforward definition of mixed field fo Installation ------------ -Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy``, ``scipy`` and ``tensortrax``. However, ``einsumt``, ``h5py``, ``matplotlib``, ``meshio`` and ``pyvista`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentiation consider also installing `matADi `_. +Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy``, ``scipy`` and ``tensortrax``. However, ``einsumt``, ``h5py``, ``matplotlib``, ``meshio``, ``pyvista`` and ``tqdm`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentiation consider also installing `matADi `_. .. code-block:: shell From b33ec55908227ece50e36fe6c72bd09e797e5b3f Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 01:03:55 +0200 Subject: [PATCH 5/8] Update pyproject.toml --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 00ac2c7c..1c0e4a2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,6 @@ test = [ "h5py", "matplotlib", "meshio", - "pyvista", "tensortrax", ] all = [ @@ -61,6 +60,8 @@ all = [ "matplotlib", "meshio", "tensortrax", + "pyvista", + "tqdm", ] [tool.setuptools.dynamic] From 201bf7a5077a7f05380664cd77f36ffe716605a5 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 01:04:00 +0200 Subject: [PATCH 6/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d684cbd2..3315bc21 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ In order to make use of all features of FElupe, it is suggested to install all o * `matplotlib` for plotting graphs * `meshio` for mesh-related I/O * `pyvista` for interactive visualizations +* `tqdm` for showing progress bars during job evaluation # Getting Started This tutorial covers the essential high-level parts of creating and solving problems with FElupe. As an introductory example, a quarter model of a solid cube with hyperelastic material behaviour is subjected to a uniaxial elongation applied at a clamped end-face. From 968647cc7e6053fdfcc0af70ca28c0848a8b300e Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 01:04:02 +0200 Subject: [PATCH 7/8] Update tox.ini --- tox.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 833df5b4..0b5f2eea 100644 --- a/tox.ini +++ b/tox.ini @@ -7,9 +7,9 @@ deps = pytest pytest-cov matplotlib -extras = test +extras = all commands = pytest {posargs} -[testenv:all] -extras = all \ No newline at end of file +[testenv:test] +extras = test From 20162faffba8cc17f04fbf575c836deb4f5eeb00 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 28 Apr 2023 01:07:07 +0200 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bbd618b..0e2aea6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format ## [Unreleased] +### Changed +- Show a progress bar during `Job.evaluate(verbose=True)`. The old output is available with `verbose=2`. + ### Removed - Remove config files for MyBinder. They are now located in a different repository [adtzlr/felupe-web](https://github.com/adtzlr/felupe-web).