+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format

## [Unreleased]

### Added
- Add JOSS badge to README.md and change CITATION.cff to JOSS.
- Add the keyword `Job.evaluate(tqdm="auto")` and `newtonrhapson(tqdm="auto")` with additional options `None` and `"notebook"`. In a Jupyter console, a progress bar from `tqdm.auto` does not update. The `tqdm`-keyword allows to switch the tqdm-backend manually.

## [9.4.1] - 2025-09-27

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/felupe/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "9.4.1"
__version__ = "9.5.0-dev"
17 changes: 16 additions & 1 deletion src/felupe/mechanics/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def evaluate(
cell_data_default=True,
verbose=None,
parallel=False,
tqdm="auto",
**kwargs,
):
"""Evaluate the steps.
Expand Down Expand Up @@ -188,6 +189,10 @@ def evaluate(
Flag to use a threaded version of :func:`numpy.einsum` during assembly.
Requires ``einsumt``. This may add additional overhead to small-sized
problems. Default is False.
tqdm : str or None, optional
If verbose is True, choose a backend for ``tqdm`` (None, ``"auto"`` or
``"notebook"``. Default is ``"auto"``. Note that ``tqdm.auto`` does not
update the progress bar in a Jupyter console, which is used in Spyder IDE.
**kwargs : dict
Optional keyword arguments for :meth:`~felupe.Step.generate`. If
``parallel=True``, it is added as ``kwargs["parallel"] = True`` to the dict
Expand Down Expand Up @@ -223,7 +228,17 @@ def evaluate(

if verbose:
try:
from tqdm.auto import tqdm
backend = str(tqdm).lower()

if backend == "none":
from tqdm import tqdm
elif backend == "auto":
from tqdm.auto import tqdm
elif backend == "notebook":
from tqdm.notebook import tqdm
else:
raise ValueError('tqdm must be None, "auto" or "notebook".')

except ModuleNotFoundError: # pragma: no cover
verbose = 2 # pragma: no cover

Expand Down
22 changes: 18 additions & 4 deletions src/felupe/tools/_newton.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def newtonrhapson(
callback=None,
callback_kwargs=None,
progress_bar=None,
tqdm="auto",
):
r"""Find a root of a real function using the Newton-Raphson method.

Expand Down Expand Up @@ -278,9 +279,13 @@ def newtonrhapson(
An optional callback function with function signature
``callback = lambda dx, x, iteration, xnorm, fnorm, success: None``, which is
called after each completed iteration. Default is None.
progress_bar : str or None, optional
A progress bar if verbose is True. If None and verbose is True, a new bar is
created.
progress_bar : tqdm or None, optional
Use an existing instance of a progress bar if verbose is True. If None and
verbose is True, a new bar is created. Default is None.
tqdm : str or None, optional
If verbose is True, choose a backend for ``tqdm`` (None, ``"auto"`` or
``"notebook"``. Default is ``"auto"``. Note that ``tqdm.auto`` does not
update the progress bar in a Jupyter console, which is used in Spyder IDE.

Returns
-------
Expand Down Expand Up @@ -396,7 +401,16 @@ def newtonrhapson(

if verbose:
try:
from tqdm import tqdm
backend = str(tqdm).lower()

if backend == "none":
from tqdm import tqdm
elif backend == "auto":
from tqdm.auto import tqdm
elif backend == "notebook":
from tqdm.notebook import tqdm
else:
raise ValueError('tqdm must be None, "auto" or "notebook".')

decades = None

Expand Down
34 changes: 32 additions & 2 deletions tests/test_job.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# -*- coding: utf-8 -*-
"""
_______ _______ ___ __ __ _______ _______
| || || | | | | || || |
| ___|| ___|| | | | | || _ || ___|
| |___ | |___ | | | |_| || |_| || |___
| ___|| ___|| |___ | || ___|| ___|
| | | |___ | || || | | |___
|___| |_______||_______||_______||___| |_______|

This file is part of felupe.

Felupe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Felupe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Felupe. If not, see <http://www.gnu.org/licenses/>.

"""
import os

import numpy as np
Expand Down Expand Up @@ -73,7 +99,7 @@ def test_job_xdmf_global_field():

field, step = pre()
job = fem.Job(steps=[step])
job.evaluate(filename="result.xdmf", x0=field)
job.evaluate(filename="result.xdmf", x0=field, tqdm=None)


def test_curve():
Expand Down Expand Up @@ -147,7 +173,11 @@ def test_empty():

step = fem.Step(items=[solid], ramp=None, boundaries=None)
job = fem.Job(steps=[step])
job.evaluate()

with pytest.raises(ValueError):
job.evaluate(tqdm="my_fancy_backend")

job.evaluate(tqdm="notebook")


def test_noramp():
Expand Down
11 changes: 11 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,28 @@ def test_newton_plane():
field,
verbose=True,
kwargs=dict(umat=umat),
tqdm=None,
**loadcase,
)

# define the constitutive material behavior
umat = fem.constitution.LinearElasticPlaneStrain(E=1.0, nu=0.3)

with pytest.raises(ValueError):
res = fem.newtonrhapson(
field,
verbose=True,
kwargs=dict(umat=umat),
tqdm="my_fancy_backend",
**loadcase,
)

# newton-rhapson procedure
res = fem.newtonrhapson(
field,
verbose=True,
kwargs=dict(umat=umat),
tqdm="notebook",
**loadcase,
)

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载