diff --git a/.coveragerc b/.coveragerc index 0e3e12a2..cee66491 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,12 +2,13 @@ [run] branch = True source = pylife -# omit = bad_file.py +omit = + src/pylife/strength/helpers.py + src/pylife/strength/sn_curve.py [paths] source = src/ - */site-packages/ [report] # Regexes for lines to exclude from consideration diff --git a/docs/reference.rst b/docs/reference.rst index 65cc560b..f35fc2b7 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -31,8 +31,6 @@ Strength strength/meanstress strength/failure_probability strength/miner - strength/sn_curve - strength/helpers Materiallaws ------------ diff --git a/docs/strength/helpers.rst b/docs/strength/helpers.rst deleted file mode 100644 index d52b0644..00000000 --- a/docs/strength/helpers.rst +++ /dev/null @@ -1,6 +0,0 @@ -The ``helpers`` module -###################### - -.. automodule:: pylife.strength.helpers - :undoc-members: - :members: diff --git a/docs/strength/sn_curve.rst b/docs/strength/sn_curve.rst deleted file mode 100644 index 9d2264b1..00000000 --- a/docs/strength/sn_curve.rst +++ /dev/null @@ -1,6 +0,0 @@ -The ``sn_curve`` module -####################### - -.. automodule:: pylife.strength.sn_curve - :undoc-members: - :members: diff --git a/src/pylife/strength/helpers.py b/src/pylife/strength/helpers.py index 983a17b5..f40eb5e8 100644 --- a/src/pylife/strength/helpers.py +++ b/src/pylife/strength/helpers.py @@ -21,8 +21,16 @@ __author__ = "Cedric Philip Wagner" __maintainer__ = "Johannes Mueller" +import warnings + import numpy as np +warnings.warn( + FutureWarning( + "The module pylife.strength.helpers is deprecated and no longer under test. " + "We will restore the functionality in another module if needed." + ) +) class StressRelations: """Namespace for simple relations of stress / amplitude / R-ratio diff --git a/src/pylife/strength/sn_curve.py b/src/pylife/strength/sn_curve.py index 7c831d19..4833f95c 100644 --- a/src/pylife/strength/sn_curve.py +++ b/src/pylife/strength/sn_curve.py @@ -24,6 +24,12 @@ import pylife.strength.fatigue import pylife.stress +warnings.warn( + FutureWarning( + "The module pylife.strength.helpers is deprecated and no longer under test. " + "The functionality is now avaliable in the pylife.materiallaws.WoehlerCurve." + ) +) class FiniteLifeBase: """Base class for SN curve calculations - either in logarithmic or regular scale""" diff --git a/tests/strength/test_helpers.py b/tests/strength/test_helpers.py deleted file mode 100644 index 971c5269..00000000 --- a/tests/strength/test_helpers.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright (c) 2019-2022 - for information on the respective copyright owner -# see the NOTICE file and/or the repository -# https://github.com/boschresearch/pylife -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from pylife.strength import helpers as hlp - -import numpy as np -import pytest - - - -class TestStressRelations: - - @pytest.mark.parametrize("amplitude, max_stress, R", [(200, 200, -1), (200, 400, 0)]) - def test_get_max_stress_from_amplitude(self, amplitude, max_stress, R): - max_stress_calculated = hlp.StressRelations.get_max_stress_from_amplitude( - amplitude=amplitude, - R=R - ) - np.testing.assert_almost_equal(max_stress, max_stress_calculated) - - @pytest.mark.parametrize("amplitude, mean_stress, R", [(200, 0, -1), (200, 200, 0)]) - def test_get_mean_stress_from_amplitude(self, amplitude, mean_stress, R): - mean_stress_calculated = hlp.StressRelations.get_mean_stress_from_amplitude( - amplitude=amplitude, - R=R - ) - np.testing.assert_almost_equal(mean_stress, mean_stress_calculated) - - -def test_irregularity_factor(): - """ - Consider the turning points series with 8 bins from 0 to 7: - 1 - 5 - 4 - 5 - 1 - 2 - 1 - 5 (mean bin = 3) - - The resulting rainflow matrix contains: - - 5 -> 4 - - 5 -> 1 (2 mean value crossings: 1x upwards, 1x downwards) - - 1 -> 2 - - With the residuals: - - 1 -> 5 (1 mean value crossing: 1x upwards) - - The two sided irregularity factor is the quotient of - - the sum of mean value crossings (which is 3) and - - the sum of turnings points (which is 8) - - So the irregularity factor is 3 / 8 = 0.375 - """ - rfm = np.array([ - # to - # 0 1 2 3 4 5 6 7 - [0, 0, 0, 0, 0, 0, 0, 0], # 0 - [0, 0, 1, 0, 0, 0, 0, 0], # 1 - [0, 0, 0, 0, 0, 0, 0, 0], # 2 f - [0, 0, 0, 0, 0, 0, 0, 0], # 3 r - [0, 0, 0, 0, 0, 0, 0, 0], # 4 o - [0, 1, 0, 0, 1, 0, 0, 0], # 5 m - [0, 0, 0, 0, 0, 0, 0, 0], # 6 - [0, 0, 0, 0, 0, 0, 0, 0], # 7 - ]) - - residuals = np.array( - [1, 5] - ) - - duplicated_residuals = np.array( - [1, 1, 1, 5, 5] - ) - - # Calculated correctly - np.testing.assert_almost_equal(hlp.irregularity_factor(rfm, residuals), 3./8, 4) - - # Decision bin inferred correctly - np.testing.assert_almost_equal(hlp.irregularity_factor(rfm, decision_bin=None, residuals=residuals), - hlp.irregularity_factor(rfm, decision_bin=3, residuals=residuals), 4) - - # Decision bin broadcast - np.testing.assert_almost_equal(hlp.irregularity_factor(rfm, residuals, decision_bin=3.), 3./8, 4) - with np.testing.assert_raises(ValueError): - hlp.irregularity_factor(rfm, residuals, decision_bin="three") - - # Duplicates removed correctly - np.testing.assert_almost_equal(hlp.irregularity_factor(rfm, residuals=residuals), - hlp.irregularity_factor(rfm, residuals=duplicated_residuals), 4) - - - -def test_irregularity_factor_non_square_rainflow(): - rfm = np.array([ - # to - # 0 1 2 3 4 5 6 7 - [0, 0, 0, 0, 0, 0, 0, 0], # 0 - [0, 0, 1, 0, 0, 0, 0, 0], # 1 - [0, 0, 0, 0, 0, 0, 0, 0], # 2 f - [0, 0, 0, 0, 0, 0, 0, 0], # 3 r - [0, 0, 0, 0, 0, 0, 0, 0], # 4 o - [0, 1, 0, 0, 1, 0, 0, 0], # 5 m - [0, 0, 0, 0, 0, 0, 0, 0], # 6 - ]) - - with pytest.raises(ValueError, match=r"Rainflow matrix must be square shaped in order to calculate the irregularity factor."): - hlp.irregularity_factor(rfm) diff --git a/tests/strength/test_meanstress.py b/tests/strength/test_meanstress.py index f06da179..42e5a3fe 100644 --- a/tests/strength/test_meanstress.py +++ b/tests/strength/test_meanstress.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys, os, copy import warnings import pytest @@ -23,7 +22,6 @@ import numpy.testing as testing import pylife.strength.meanstress as MST -from pylife.strength.sn_curve import FiniteLifeCurve def goodman_signal_sm(): diff --git a/tests/strength/test_sn_curve.py b/tests/strength/test_sn_curve.py deleted file mode 100644 index 1eb3b6d9..00000000 --- a/tests/strength/test_sn_curve.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (c) 2019-2022 - for information on the respective copyright owner -# see the NOTICE file and/or the repository -# https://github.com/boschresearch/pylife -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import pandas as pd -import pytest -from pylife.strength import sn_curve - - -def load_index(): - nCode_Xbinsize = 62.375 - nCode_XMax = 468.8125 - nCode_XMin = 32.1875 - - return pd.interval_range(start=nCode_XMin-nCode_Xbinsize/2, - end=nCode_XMax+nCode_Xbinsize/2, periods=8, name="range") - - -def nCode_reference_results(): - elementar = pd.DataFrame([[2.057849E-06, 1.868333E-06, 3.067487E-06], - [3.039750E-05, 3.894329E-05, 1.999014E-08], - [1.507985E-05, 4.829155E-05, 0.000000E+00], - [6.434856E-06, 1.543643E-05, 0.000000E+00], - [6.296737E-06, 1.357734E-05, 0.000000E+00], - [1.751881E-06, 1.379607E-05, 0.000000E+00], - [0.000000E+00, 1.023415E-05, 0.000000E+00], - [0.000000E+00, 7.548524E-07, 0.000000E+00]], - index=load_index()).stack() - miner_haibach = pd.DataFrame([[2.293973E-08, 2.083222E-08, 3.419927E-08], - [7.414563E-05, 9.499395E-05, 4.876799E-08], - [4.631857E-04, 1.483300E-03, 0.000000E+00], - [4.779392E-04, 1.146517E-03, 0.000000E+00], - [6.006944E-04, 1.295247E-03, 0.000000E+00], - [2.041326E-04, 1.607545E-03, 0.000000E+00], - [0.000000E+00, 1.408691E-03, 0.000000E+00], - [0.000000E+00, 1.198482E-04, 0.000000E+00]], - index=load_index()).stack() - original = pd.DataFrame([[0.00000000E+00, 0.00000000E+00, 0.00000000E+00], - [0.00000000E+00, 0.00000000E+00, 0.00000000E+00], - [2.08681840E-05, 6.68280320E-05, 0.00000000E+00], - [1.73881920E-05, 4.17121220E-05, 0.00000000E+00], - [2.80698130E-05, 6.05255350E-05, 0.00000000E+00], - [1.16511320E-05, 9.17526660E-05, 0.00000000E+00], - [0.00000000E+00, 9.49790820E-05, 0.00000000E+00], - [0.00000000E+00, 9.32071420E-06, 0.00000000E+00]], - index=load_index()).stack() - elementar.name = 'damage' - miner_haibach.name = 'damage' - original.name = 'damage' - return [elementar, miner_haibach, original] - - -material = pd.DataFrame(index=['k_1', 'ND_50', 'SD_50'], - columns=['elementar', 'MinerHaibach', 'original'], - data=[[4, 5, 6], [4e7, 1e6, 1e8], [100, 90, 75]]) - -loads = pd.DataFrame([[1.227E5, 1.114E5, 1.829E5], [2.433E4, 3.117E4, 16], - [1591, 5095, 0], [178, 427, 0], [64, 138, 0], [8, 63, 0], - [0, 24, 0], [0, 1, 0]], - index=load_index()).stack() - - -@pytest.mark.parametrize('method, expected', zip(material, nCode_reference_results())) -def test_calc_damage(method, expected): - with pytest.warns(DeprecationWarning): - damage_calc = sn_curve.FiniteLifeCurve(**material[method]) - damage = damage_calc.calc_damage(loads, method=method) - pd.testing.assert_series_equal(damage, expected, rtol=0.001, atol=0) - - -def test_calc_damage_index_name(): - foo_loads = loads.copy() - foo_loads.index.name = 'foo' - with pytest.warns(DeprecationWarning): - damage = sn_curve.FiniteLifeCurve(**material['elementar']).calc_damage(foo_loads, - method='elementar', - index_name='foo') - - assert damage.index.names[0] == 'foo'