Skip to content

Commit

Permalink
Revert "Solve issue with side effects during scipy.optimize.newton"
Browse files Browse the repository at this point in the history
This reverts commit 2b866c4.

Signed-off-by: Benjamin Maier <[email protected]>
  • Loading branch information
maierbn committed Nov 12, 2024
1 parent 110505a commit e284770
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 48 deletions.
2 changes: 1 addition & 1 deletion demos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import sys, os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
11 changes: 6 additions & 5 deletions src/pylife/materiallaws/notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import numpy as np
from scipy import optimize
import pandas as pd
import copy

import pylife.materiallaws.rambgood

Expand Down Expand Up @@ -136,7 +135,7 @@ def stress(self, load, *, rtol=1e-4, tol=1e-4):
'''
stress = optimize.newton(
func=self._stress_implicit,
x0=copy.copy(load),
x0=load,
fprime=self._d_stress_implicit,
args=([load]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -193,9 +192,10 @@ 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=copy.copy(stress),
x0=stress,
fprime=self._d_load_implicit,
args=([stress]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -225,7 +225,7 @@ def stress_secondary_branch(self, delta_load, *, rtol=1e-4, tol=1e-4):
'''
delta_stress = optimize.newton(
func=self._stress_secondary_implicit,
x0=copy.copy(delta_load),
x0=delta_load,
fprime=self._d_stress_secondary_implicit,
args=([delta_load]),
rtol=rtol, tol=tol, maxiter=20
Expand Down Expand Up @@ -281,9 +281,10 @@ 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=copy.copy(delta_stress),
x0=delta_stress,
fprime=self._d_load_secondary_implicit,
args=([delta_stress]),
rtol=rtol, tol=tol, maxiter=20
Expand Down
41 changes: 1 addition & 40 deletions tests/materiallaws/test_notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ 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)
assessment_parameters = pd.Serie({"E": E, "K_prime": K, "n_prime": n, "K_p": K_p})

L = pd.Series([100, -200, 100, -250, 200, 0, 200, -200])
c = 1.4
gamma_L = (250+6.6)/250
L = c * gamma_L * L

# initialize notch approximation law and damage parameter
E, K_prime, n_prime, K_p = assessment_parameters[["E", "K_prime", "n_prime", "K_p"]]
notch_approximation_law = ExtendedNeuber(E, K, n, K_p)

assert notch_approximation_law.E == E
Expand All @@ -54,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, 100)
notch_approximation_law, maximum_absolute_load)

# 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 @@ -74,8 +72,6 @@ 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 @@ -122,41 +118,6 @@ 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_scalar():
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)

stress_value = 150.0
stress = notch_approximation_law.stress(stress_value)
stress_secondary_branch = notch_approximation_law.stress_secondary_branch(150.0)

assert stress_value == 150.0
assert np.isclose(stress, 148.46, rtol=1e-3)
assert np.isclose(stress_secondary_branch, 149.8, rtol=1e-3)



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.linspace(0, 710, 100)
stress = notch_approximation_law.stress(load)
stress_secondary_branch = notch_approximation_law.stress_secondary_branch(load)

np.testing.assert_allclose(load, np.linspace(0, 710, 100))
#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,8 +72,6 @@ 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

0 comments on commit e284770

Please sign in to comment.