Skip to content

Commit

Permalink
Merge pull request #33 from boschresearch/miner-original
Browse files Browse the repository at this point in the history
Introduce .miner_original and make other miner modifiers non destructive
  • Loading branch information
johannes-mueller authored Sep 29, 2023
2 parents d9fc917 + 1b6f677 commit f5aff70
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 65 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ In this file noteworthy changes of new releases of pyLife are documented since
2.0.0.


## since pylife-2.0.4

### New features

* Introduce `WoehlerCurve.miner_original()`

### Breaking changes

* Non-destructive miner modifiers of `WoehlerCurve`

The methods `WoehlerCurve.miner_elementary()` and
`WoehlerCurve.miner_haibach()` now return modified copies of the original
WoehlerCurve object, rather than modifying the original.


## pylife-2.0.4

Minor bugfix release
Expand Down
39 changes: 25 additions & 14 deletions src/pylife/materiallaws/woehlercurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,38 @@ def transform_to_failure_probability(self, failure_probability):

return WoehlerCurve(transformed)

def miner_original(self):
"""Set k_2 to inf according Miner Original method (k_2 = inf).
Returns
-------
modified copy of self
"""
new = self._obj.copy()
new['k_2'] = np.inf
return self.__class__(new)

def miner_elementary(self):
"""Set k_2 to k_1 according Miner Elementary method (k_2 = k_1).
Returns
-------
self
modified copy of self
"""
self._obj['k_2'] = self._obj.k_1
return self
new = self._obj.copy()
new['k_2'] = self._obj.k_1
return self.__class__(new)

def miner_haibach(self):
"""Set k_2 to value according Miner Haibach method (k_2 = 2 * k_1 - 1).
Returns
-------
self
modified copy of self
"""
self._obj['k_2'] = 2. * self._obj.k_1 - 1.
return self
new = self._obj.copy()
new['k_2'] = 2. * self._obj.k_1 - 1.
return self.__class__(new)

def cycles(self, load, failure_probability=0.5):
"""Calculate the cycles numbers from loads.
Expand Down Expand Up @@ -214,16 +227,14 @@ def basquin_cycles(self, load, failure_probability=0.5):
cycles : numpy.ndarray
The cycle numbers at which the component fails for the given `load` values
"""
transformed = self.transform_to_failure_probability(failure_probability)
def ensure_float_to_prevent_int_overflow(load):
if isinstance(load, pd.Series):
return pd.Series(load, dtype=np.float64)
return np.asarray(load, dtype=np.float64)

if hasattr(load, '__iter__'):
if hasattr(load, 'astype'):
load = load.astype('float64')
else:
load = np.array(load).astype('float64')
else:
load = float(load)
transformed = self.transform_to_failure_probability(failure_probability)

load = ensure_float_to_prevent_int_overflow(load)
ld, wc = transformed.broadcast(load)
cycles = np.full_like(ld, np.inf)

Expand Down
Loading

0 comments on commit f5aff70

Please sign in to comment.