Skip to content

Commit

Permalink
Merge pull request #446 from adtzlr/einsumt-fallback-to-numpy
Browse files Browse the repository at this point in the history
Threaded einsum: Fall-back to numpy if `einsumt` is not available
  • Loading branch information
adtzlr authored Apr 14, 2023
2 parents 8432ffd + ffd296c commit bf4cf21
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ All notable changes to this project will be documented in this file. The format
- Don't invoke `CharacteristicCurve.evaluate()` from `CharacteristicCurve.plot()`, raise an error if the current job is not evaluated instead.
- Make the endpoint of `math.linsteps(endpoint=True)` optional.
- Don't modify the mesh for the dual regions `RegionConstantQuad()` and `RegionConstantHexahedron()`. Instead, it is required to pass a dual (disconnected) mesh with one point per cell `RegionConstantQuad(mesh.dual(points_per_cell=1))`.
- Make requirement `einsumt` optional again due to issues with JupyterLite.
- Add `matplotlib` to optional requirements.

### Fixed
- Catch `ModuleNotFoundError` if `from einsumt import einsumt` fails (in JupyterLite) and fall back to `from numpy import einsum as einsumt`.

## [7.0.0] - 2023-04-07

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Install Python, fire up a terminal and run
pip install felupe[all]
```

where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy`, `scipy` and `einsumt`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`h5py`, `meshio` and `tensortrax`).
where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy` and `scipy`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`einsumt`, `h5py`, `matplotlib`, `meshio` and `tensortrax`).

# Getting Started
A quarter model of a solid cube with hyperelastic material behaviour is subjected to a uniaxial elongation applied at a clamped end-face. This involves the creation of a mesh, a region as well as a displacement field (encapsulated in a field container). Furthermore, the boundary conditions are created by a template for a uniaxial loadcase. An isotropic pseudo-elastic Ogden-Roxburgh Mullins-softening model formulation in combination with an isotropic hyperelastic Neo-Hookean material formulation is applied on a nearly-incompressible solid body. A step generates the consecutive substep-movements of a given boundary condition. The step is further added to a list of steps of a job (here, a characteristic-curve job is used). During evaluation, each substep of each step is solved by an iterative Newton-Rhapson procedure. The solution is exported after each completed substep as a time-series XDMF file. For more details beside this high-level code snippet, please have a look at the [documentation](https://felupe.readthedocs.io/en/latest/?badge=latest).
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``einsumt``. However, ``meshio``, ``h5py`` and ``tensortrax`` 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 Differentation consider also installing `matADi <https://github.com/adtzlr/matadi>`_.
Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy`` and ``scipy``. However, ``einsumt``, ``h5py``, ``matplotlib``, ``meshio`` and ``tensortrax`` 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 Differentation consider also installing `matADi <https://github.com/adtzlr/matadi>`_.

.. code-block:: shell
Expand Down
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ requires-python = ">=3.7"
dependencies = [
"numpy",
"scipy",
"einsumt",
]

[project.optional-dependencies]
all = [
test = [
"h5py",
"matplotlib",
"meshio",
"tensortrax",
]
all = [
"einsumt",
"h5py",
"matplotlib",
"meshio",
"tensortrax",
]

Expand Down
7 changes: 6 additions & 1 deletion src/felupe/_assembly/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
"""

import numpy as np
from einsumt import einsumt

try:
from einsumt import einsumt
except ModuleNotFoundError:
from numpy import einsum as einsumt

from scipy.sparse import csr_matrix as sparsematrix


Expand Down
6 changes: 5 additions & 1 deletion src/felupe/_basis/_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"""

import numpy as np
from einsumt import einsumt

try:
from einsumt import einsumt
except ModuleNotFoundError:
from numpy import einsum as einsumt


class Basis:
Expand Down
6 changes: 5 additions & 1 deletion src/felupe/constitution/_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"""

import numpy as np
from einsumt import einsumt

try:
from einsumt import einsumt
except ModuleNotFoundError:
from numpy import einsum as einsumt

from ..math import cdya_ik, cdya_il, det, dot, dya, identity, inv, transpose

Expand Down
6 changes: 5 additions & 1 deletion src/felupe/math/_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"""

import numpy as np
from einsumt import einsumt

try:
from einsumt import einsumt
except ModuleNotFoundError:
from numpy import einsum as einsumt


def identity(A=None, dim=None, shape=None):
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ deps =
pytest
pytest-cov
matplotlib
extras = all
extras = test
commands =
pytest {posargs}
pytest {posargs}

[testenv:all]
extras = all

0 comments on commit bf4cf21

Please sign in to comment.