diff --git a/demos/__init__.py b/demos/__init__.py index 60b6853b..a78ea3f5 100644 --- a/demos/__init__.py +++ b/demos/__init__.py @@ -1,3 +1,3 @@ import sys, os -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) \ No newline at end of file +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) \ No newline at end of file diff --git a/src/pylife/materiallaws/notch_approximation_law.py b/src/pylife/materiallaws/notch_approximation_law.py index d9b26a3f..2233a866 100644 --- a/src/pylife/materiallaws/notch_approximation_law.py +++ b/src/pylife/materiallaws/notch_approximation_law.py @@ -20,6 +20,7 @@ import numpy as np from scipy import optimize import pandas as pd +import copy import pylife.materiallaws.rambgood @@ -135,7 +136,7 @@ def stress(self, load, *, rtol=1e-4, tol=1e-4): ''' stress = optimize.newton( func=self._stress_implicit, - x0=load, + x0=copy.copy(load), fprime=self._d_stress_implicit, args=([load]), rtol=rtol, tol=tol, maxiter=20 @@ -192,10 +193,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=copy.copy(stress), fprime=self._d_load_implicit, args=([stress]), rtol=rtol, tol=tol, maxiter=20 @@ -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=delta_load, + x0=copy.copy(delta_load), fprime=self._d_stress_secondary_implicit, args=([delta_load]), rtol=rtol, tol=tol, maxiter=20 @@ -281,10 +281,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=copy.copy(delta_stress), fprime=self._d_load_secondary_implicit, args=([delta_stress]), rtol=rtol, tol=tol, maxiter=20 diff --git a/tests/materiallaws/test_notch_approximation_law.py b/tests/materiallaws/test_notch_approximation_law.py index a0eceb2d..dc03edda 100644 --- a/tests/materiallaws/test_notch_approximation_law.py +++ b/tests/materiallaws/test_notch_approximation_law.py @@ -32,6 +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) + 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 @@ -39,6 +40,7 @@ def test_extended_neuber_example_1(): 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 @@ -52,7 +54,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], \ @@ -72,6 +74,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" """ @@ -118,6 +122,41 @@ 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), diff --git a/tests/materiallaws/test_notch_approximation_law_seegerbeste.py b/tests/materiallaws/test_notch_approximation_law_seegerbeste.py index b0b5185d..6de65643 100644 --- a/tests/materiallaws/test_notch_approximation_law_seegerbeste.py +++ b/tests/materiallaws/test_notch_approximation_law_seegerbeste.py @@ -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" """