Skip to content

Commit

Permalink
Improvements from review and some refactorings
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Mueller <[email protected]>
  • Loading branch information
johannes-mueller committed Feb 6, 2025
1 parent 0e7c15e commit 1867584
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 82 deletions.
19 changes: 13 additions & 6 deletions src/pylife/materiallaws/notch_approximation_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class NotchApproxBinner:
def __init__(self, notch_approximation_law, number_of_bins=100):
self._n_bins = number_of_bins
self._notch_approximation_law = notch_approximation_law
self.ramberg_osgood_relation = notch_approximation_law.ramberg_osgood_relation
self._ramberg_osgood_relation = notch_approximation_law.ramberg_osgood_relation
self._max_load_rep = None

def initialize(self, max_load):
Expand All @@ -579,14 +579,14 @@ def initialize(self, max_load):
----------
max_load : array_like
The state of the maximum nominal load that is expected. The first
element is chosen as representative to caclulate the lookup table.
element is chosen as representative to calculate the lookup table.
Returns
-------
self
"""
max_load = np.asarray(max_load)
self._max_load_rep, _ = self._rep_abs_and_sign(max_load)
self._max_load_rep, _ = self._representative_value_and_sign(max_load)

load = self._param_for_lut(self._n_bins, max_load)
self._lut_primary = self._notch_approximation_law.primary(load)
Expand All @@ -596,6 +596,13 @@ def initialize(self, max_load):

return self

@property
def ramberg_osgood_relation(self):
"""the Ramberg-Osgood relation object, i.e., an object of type RambergOsgood
provided by the notch approximation law.
"""
return self._ramberg_osgood_relation

def primary(self, load):
"""Lookup the stress strain of the primary branch.
Expand All @@ -619,7 +626,7 @@ def primary(self, load):
"""
self._raise_if_uninitialized()
load_rep, sign = self._rep_abs_and_sign(load)
load_rep, sign = self._representative_value_and_sign(load)

if load_rep > self._max_load_rep:
msg = f"Requested load `{load_rep}`, higher than initialized maximum load `{self._max_load_rep}`"
Expand Down Expand Up @@ -651,7 +658,7 @@ def secondary(self, delta_load):
"""
self._raise_if_uninitialized()
delta_load_rep, sign = self._rep_abs_and_sign(delta_load)
delta_load_rep, sign = self._representative_value_and_sign(delta_load)

if delta_load_rep > 2.0 * self._max_load_rep:
msg = f"Requested load `{delta_load_rep}`, higher than initialized maximum delta load `{2.0*self._max_load_rep}`"
Expand All @@ -669,7 +676,7 @@ def _param_for_lut(self, number_of_bins, max_val):
max_val, scale_m = np.meshgrid(max_val, scale)
return (max_val * scale_m)

def _rep_abs_and_sign(self, value):
def _representative_value_and_sign(self, value):
value = np.asarray(value)
value_rep = value if len(value.shape) == 0 else value[0]
return np.abs(value_rep), np.sign(value_rep)
Loading

0 comments on commit 1867584

Please sign in to comment.