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

fix problem with side effect in SeegerBeste.stress #131

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def stress(self, load, *, rtol=1e-4, tol=1e-4):
# or (value, converged, zero_der) for vector-valued invocation

# only for multiple points at once, if some points diverged
if sum(stress[1]) < len(stress[1]):
if len(stress) == 3 and sum(stress[1]) < len(stress[1]):
stress = self._stress_fix_not_converged_values(stress, load, x0, rtol, tol)

return stress[0]
Expand Down Expand Up @@ -209,7 +209,7 @@ def stress_secondary_branch(self, delta_load, *, rtol=1e-4, tol=1e-4):
# or (value, converged, zero_der) for vector-valued invocation

# only for multiple points at once, if some points diverged
if sum(delta_stress[1]) < len(delta_stress[1]):
if len(delta_stress) == 3 and sum(delta_stress[1]) < len(delta_stress[1]):
delta_stress = self._stress_secondary_fix_not_converged_values(delta_stress, delta_load, x0, rtol, tol)

return delta_stress[0]
Expand Down
35 changes: 35 additions & 0 deletions tests/materiallaws/test_notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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.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(load, np.array([150.0, 175.0, 200.0]))
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
15 changes: 15 additions & 0 deletions tests/materiallaws/test_notch_approximation_law_seegerbeste.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ def test_seeger_beste_example_2():
binned_notch_approximation_law._lut_secondary_branch, expected_matrix_AST_171_seeger_beste, rtol=2e-3, atol=1e-5)


def test_seeger_beste_example_no_binning():
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 = SeegerBeste(E, K, n, K_p)

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

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


@pytest.mark.skip(reason="Derivatives not implemented at the moment, left in the code because it might be useful in the future for performance optimization with gradient-based root finding algorithms.")
@pytest.mark.parametrize('stress, load', [
(4, 9),
Expand Down
Loading