|
7 | 7 |
|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
10 | | -import warnings |
11 | 10 | from dataclasses import dataclass, field |
12 | 11 | from functools import lru_cache |
13 | | -from typing import TYPE_CHECKING |
| 12 | +from typing import TYPE_CHECKING, Any, Callable |
14 | 13 |
|
15 | 14 | import numpy as np |
16 | 15 | import numpy.typing as npt |
17 | | -from numba import njit |
18 | | -from numba.core.errors import NumbaPerformanceWarning |
19 | 16 |
|
20 | 17 |
|
21 | 18 | if TYPE_CHECKING: |
22 | 19 | from sectionproperties.pre.pre import Material |
23 | 20 |
|
24 | 21 |
|
| 22 | +# numba is an optional dependency |
| 23 | +try: |
| 24 | + from numba import njit |
| 25 | +except ImportError: |
| 26 | + |
| 27 | + def njit(**options: Any) -> Callable[[Any], Any]: |
| 28 | + """Empty decorator if numba is not installed. |
| 29 | +
|
| 30 | + Args: |
| 31 | + options: Optional keyword arguments for numba that are discarded. |
| 32 | +
|
| 33 | + Returns: |
| 34 | + Empty njit decorator. |
| 35 | + """ |
| 36 | + |
| 37 | + def decorator(func: Callable[[Any], Any]) -> Callable[[Any], Any]: |
| 38 | + """Decorator. |
| 39 | +
|
| 40 | + Args: |
| 41 | + func: Function to decorate. |
| 42 | +
|
| 43 | + Returns: |
| 44 | + Decorated function. |
| 45 | + """ |
| 46 | + |
| 47 | + def wrapper(*args: Any, **kwargs: Any) -> Callable[[Any], Any]: |
| 48 | + """Wrapper. |
| 49 | +
|
| 50 | + Args: |
| 51 | + args: Arguments. |
| 52 | + kwargs: Keyword arguments. |
| 53 | +
|
| 54 | + Returns: |
| 55 | + Wrapped function. |
| 56 | + """ |
| 57 | + return func(*args, **kwargs) # type: ignore |
| 58 | + |
| 59 | + return wrapper |
| 60 | + |
| 61 | + return decorator |
| 62 | + |
| 63 | + |
25 | 64 | @njit(cache=True, nogil=True) # type: ignore |
26 | 65 | def _assemble_torsion( |
27 | 66 | k_el: npt.NDArray[np.float64], |
@@ -587,9 +626,9 @@ def element_stress( |
587 | 626 | sig_zz_myy_gp = np.zeros(n_points) |
588 | 627 | sig_zz_m11_gp = np.zeros(n_points) |
589 | 628 | sig_zz_m22_gp = np.zeros(n_points) |
590 | | - sig_zxy_mzz_gp = np.zeros((n_points, 2)) |
591 | | - sig_zxy_vx_gp = np.zeros((n_points, 2)) |
592 | | - sig_zxy_vy_gp = np.zeros((n_points, 2)) |
| 629 | + sig_zxy_mzz_gp = np.zeros((n_points, 2), order="F") |
| 630 | + sig_zxy_vx_gp = np.zeros((n_points, 2), order="F") |
| 631 | + sig_zxy_vy_gp = np.zeros((n_points, 2), order="F") |
593 | 632 |
|
594 | 633 | # Gauss points for 6 point Gaussian integration |
595 | 634 | gps = gauss_points(n=n_points) |
@@ -646,19 +685,17 @@ def element_stress( |
646 | 685 | * (b.dot(phi_shear) - nu / 2 * np.array([h1, h2])) |
647 | 686 | ) |
648 | 687 |
|
649 | | - # extrapolate results to nodes, ignore numba warnings about performance |
650 | | - with warnings.catch_warnings(): |
651 | | - warnings.simplefilter("ignore", category=NumbaPerformanceWarning) |
652 | | - sig_zz_mxx = extrapolate_to_nodes(w=sig_zz_mxx_gp) |
653 | | - sig_zz_myy = extrapolate_to_nodes(w=sig_zz_myy_gp) |
654 | | - sig_zz_m11 = extrapolate_to_nodes(w=sig_zz_m11_gp) |
655 | | - sig_zz_m22 = extrapolate_to_nodes(w=sig_zz_m22_gp) |
656 | | - sig_zx_mzz = extrapolate_to_nodes(w=sig_zxy_mzz_gp[:, 0]) |
657 | | - sig_zy_mzz = extrapolate_to_nodes(w=sig_zxy_mzz_gp[:, 1]) |
658 | | - sig_zx_vx = extrapolate_to_nodes(w=sig_zxy_vx_gp[:, 0]) |
659 | | - sig_zy_vx = extrapolate_to_nodes(w=sig_zxy_vx_gp[:, 1]) |
660 | | - sig_zx_vy = extrapolate_to_nodes(w=sig_zxy_vy_gp[:, 0]) |
661 | | - sig_zy_vy = extrapolate_to_nodes(w=sig_zxy_vy_gp[:, 1]) |
| 688 | + # extrapolate results to nodes |
| 689 | + sig_zz_mxx = extrapolate_to_nodes(w=sig_zz_mxx_gp) |
| 690 | + sig_zz_myy = extrapolate_to_nodes(w=sig_zz_myy_gp) |
| 691 | + sig_zz_m11 = extrapolate_to_nodes(w=sig_zz_m11_gp) |
| 692 | + sig_zz_m22 = extrapolate_to_nodes(w=sig_zz_m22_gp) |
| 693 | + sig_zx_mzz = extrapolate_to_nodes(w=sig_zxy_mzz_gp[:, 0]) |
| 694 | + sig_zy_mzz = extrapolate_to_nodes(w=sig_zxy_mzz_gp[:, 1]) |
| 695 | + sig_zx_vx = extrapolate_to_nodes(w=sig_zxy_vx_gp[:, 0]) |
| 696 | + sig_zy_vx = extrapolate_to_nodes(w=sig_zxy_vx_gp[:, 1]) |
| 697 | + sig_zx_vy = extrapolate_to_nodes(w=sig_zxy_vy_gp[:, 0]) |
| 698 | + sig_zy_vy = extrapolate_to_nodes(w=sig_zxy_vy_gp[:, 1]) |
662 | 699 |
|
663 | 700 | return ( |
664 | 701 | sig_zz_n, |
|
0 commit comments