Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13 compliance #139

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 13 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- develop
- ci-debug
schedule:
- cron: "0 9 * * 0"

Expand All @@ -19,23 +20,30 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
include:
- python-version: "3.13"
only-minimal: true
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install python essentials
run: |
python -m pip install --upgrade pip
pip install -U setuptools setuptools_scm wheel
pip install flake8 pytest pytest-cov
pip install -e .[all,testing]
- name: Install dependencies complete
if: matrix.only-minimal != true
run: pip install -e .[all,testing]
- name: Install dependencies minimal
if: matrix.only-minimal == true
run: pip install -e .[testing]
- name: Unit tests
run: pytest
- name: Notebook flow tests
if: matrix.only-minimal != true
uses: coactions/setup-xvfb@v1
with:
run: python -m pytest -m demos
11 changes: 5 additions & 6 deletions src/pylife/materiallaws/notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import numpy as np
from scipy import optimize
import pandas as pd
import copy

import pylife.materiallaws.rambgood

Expand Down Expand Up @@ -132,7 +133,7 @@ def stress(self, load, *, rtol=1e-4, tol=1e-4):
"""
stress = optimize.newton(
func=self._stress_implicit,
x0=load,
x0=np.asarray(load),
fprime=self._d_stress_implicit,
args=([load]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -189,10 +190,9 @@ def load(self, stress, *, rtol=1e-4, tol=1e-4):
# => sigma/E + (sigma/K')^(1/n') = (L/sigma * K_p * e_star)
# => (sigma/E + (sigma/K')^(1/n')) / K_p * sigma = L * e_star(L)
# <=> self._ramberg_osgood_relation.strain(stress) / self._K_p * stress = L * e_star(L)

load = optimize.newton(
func=self._load_implicit,
x0=stress,
x0=np.asarray(stress),
fprime=self._d_load_implicit,
args=([stress]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -222,7 +222,7 @@ def stress_secondary_branch(self, delta_load, *, rtol=1e-4, tol=1e-4):
"""
delta_stress = optimize.newton(
func=self._stress_secondary_implicit,
x0=delta_load,
x0=np.asarray(delta_load),
fprime=self._d_stress_secondary_implicit,
args=([np.asarray(delta_load, dtype=np.float64)]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -278,10 +278,9 @@ def load_secondary_branch(self, delta_stress, *, rtol=1e-4, tol=1e-4):
# => sigma/E + (sigma/K')^(1/n') = (L/sigma * K_p * e_star)
# => (sigma/E + (sigma/K')^(1/n')) / K_p * sigma = L * e_star(L)
# <=> self._ramberg_osgood_relation.strain(stress) / self._K_p * stress = L * e_star(L)

delta_load = optimize.newton(
func=self._load_secondary_implicit,
x0=delta_stress,
x0=np.asarray(delta_stress),
fprime=self._d_load_secondary_implicit,
args=([delta_stress]),
rtol=rtol, tol=tol, maxiter=20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def stress(self, load, *, rtol=1e-4, tol=1e-4):

stress = optimize.newton(
func=self._stress_implicit,
x0=x0,
x0=np.asarray(x0),
args=([load]),
full_output=True,
rtol=rtol, tol=tol, maxiter=50
Expand Down Expand Up @@ -198,7 +198,7 @@ def stress_secondary_branch(self, delta_load, *, rtol=1e-4, tol=1e-4):

delta_stress = optimize.newton(
func=self._stress_secondary_implicit,
x0=x0,
x0=np.asarray(x0),
args=([delta_load]),
full_output=True,
rtol=rtol, tol=tol, maxiter=50
Expand Down Expand Up @@ -502,4 +502,3 @@ def _stress_secondary_fix_not_converged_values(self, delta_stress, delta_load, x
if result[1].converged:
delta_stress[0][index_diverged] = result[0]
return delta_stress

22 changes: 20 additions & 2 deletions tests/materiallaws/test_notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_extended_neuber_example_1():
K = 1184 # [MPa]
n = 0.187 # [-]
K_p = 3.5 # [-] (de: Traglastformzahl) K_p = F_plastic / F_yield (3.1.1)

L = pd.Series([100, -200, 100, -250, 200, 0, 200, -200])
c = 1.4
gamma_L = (250+6.6)/250
Expand All @@ -52,7 +52,7 @@ def test_extended_neuber_example_1():
assert np.isclose(maximum_absolute_load, 359.3, rtol=1e-3)

binned_notch_approximation_law = pylife.materiallaws.notch_approximation_law.Binned(
notch_approximation_law, maximum_absolute_load)
notch_approximation_law, maximum_absolute_load, 100)

# some rows of PFAD are given in the FKM nonlinear example on p.76
pd.testing.assert_series_equal(binned_notch_approximation_law._lut_primary_branch.iloc[0], \
Expand All @@ -72,6 +72,8 @@ def test_extended_neuber_example_1():
pd.testing.assert_frame_equal(
binned_notch_approximation_law._lut_secondary_branch, expected_matrix_AST_162, rtol=1e-3, atol=1e-5)

assert np.isclose(binned_notch_approximation_law._lut_primary_branch.load.max(), maximum_absolute_load)


def test_extended_neuber_example_2():
""" example under 2.7.2, p.78 of FKM nonlinear, "Welle mit V-Kerbe" """
Expand Down Expand Up @@ -118,6 +120,22 @@ def test_extended_neuber_example_2():
binned_notch_approximation_law._lut_secondary_branch, expected_matrix_AST_171, rtol=1e-3, atol=1e-5)


def test_extended_neuber_example_no_binning_vectorized():
E = 206e3 # [MPa] Young's modulus
K = 1184 # [MPa]
n = 0.187 # [-]
K_p = 3.5 # [-] (de: Traglastformzahl) K_p = F_plastic / F_yield (3.1.1)

notch_approximation_law = ExtendedNeuber(E, K, n, K_p)

load = np.array([150.0, 175.0, 200.0])
stress = notch_approximation_law.stress(load)
stress_secondary_branch = notch_approximation_law.stress_secondary_branch(load)

np.testing.assert_allclose(stress, np.array([148.463622, 171.674936, 193.702502]), rtol=1e-3)
np.testing.assert_allclose(stress_secondary_branch, np.array([149.92007905, 174.81829204, 199.63066067]), rtol=1e-3)


@pytest.mark.parametrize('stress, load', [
(22, 42),
(40, 40),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def test_seeger_beste_example_1():
pd.testing.assert_frame_equal(
binned_notch_approximation_law._lut_secondary_branch, expected_matrix_AST_162_seeger_beste, rtol=1e-3, atol=1e-5)

assert np.isclose(binned_notch_approximation_law._lut_primary_branch.load.max(), maximum_absolute_load)


def test_seeger_beste_example_2():
""" example under 2.7.2, p.78 of FKM nonlinear, "Welle mit V-Kerbe" """
Expand Down