Uniaxial equivalent stress amplitude functionality#55
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
typo in the file name iniaxial
| from numpy.typing import ArrayLike, NDArray | ||
|
|
||
|
|
||
| def _validate_stress_inputs( |
There was a problem hiding this comment.
This function seems to implement DRY principle, but to me seems a bit clunky and hard to extend
reason might be, that it is trying to do multiple things, so it does not have 1 responsibility only, thus it branches in its logic and is harder to fit to use cases.
think it through if it could not be improved
| for compressive-dominated loading conditions. | ||
|
|
||
| """ | ||
| stress_amp_arr, mean_stress_arr = _validate_stress_inputs(stress_amp, mean_stress) |
There was a problem hiding this comment.
I would convert ArrayLike to np.ndarray here and check for positive values
It is more explicit and does not create too much boilerplate code
In this case validate function seems as overkill to me
There was a problem hiding this comment.
I am not saying that we have to do that. Just going through cases of usage of validate function
| "appropriate for compressive-dominated loading conditions." | ||
| ) | ||
|
|
||
| return np.sqrt(stress_amp_arr * (mean_stress_arr + stress_amp_arr)) |
There was a problem hiding this comment.
** 0.5 might be more readable than np.sqrt but it does not matter as much, just is more consistent with the mathematical formulas
| ratio = abs_mean / material_param_arr | ||
|
|
||
| if np.any(ratio >= 1.0): | ||
| raise ValueError( |
There was a problem hiding this comment.
what about case, where user inputs real values, where some are simply too high, so some results are negative?
Is it okay to disallow user from calculating all values ?
I personally would rather raise warning and exclude it from this validation function
| ("mean_equals_material", False, "Mean stress magnitude.*exceeds or equals"), | ||
| ], | ||
| ) | ||
| def test_validate_stress_inputs_parametrized( |
There was a problem hiding this comment.
validate function requires more then it brings value
There was a problem hiding this comment.
I would recommend using test classes to separate different test baste on function tested
There was a problem hiding this comment.
Test class than would be more generic, where each test case within the test class repeats for each tested function
class TestFunctioon1:
def test_feature1():
pass
def test_feature2(): ...
# now same thing for class TestFunction2
There was a problem hiding this comment.
it puts a bit more structure into the test file, so it is easier to navigate
also you can run tests based on the test class and more
|
Additionally the things should be added / considered:
|
|
On top of equivalent stress amplitude functionality requested by issues, several other functions were added based on this source: Mean stress effect in stress-life fatigue prediction re-evaluated Use-case info blocks in docstrings still need to be revised. |
pavkukula
left a comment
There was a problem hiding this comment.
SWT's validity condition σ_a > |σ_m| is incorrect — it rejects R≥0 loading, which is the canonical SWT case; should be σ_a + σ_m > 0.
invalid = (stress_amp_arr + mean_stress_arr) <= 0
|
ASME is more strict than Bagci/Gerber for no good reason |
|
ratio == 1.0 is a fragile float comparison |
|
Strongly compressive σ_m is silently accepted by Goodman/Linear/Morrow/Soderberg/Smith |
|
The structure is good — approved as the template, with three additions to bake in before you propagate, so all 11 get them:
Also note for the warning-based methods (Bagci/Gerber/etc.): they'll each need a pytest.warns(UserWarning) test, which the ASME template doesn't include since ASME raises instead of warns (Bagci and Gerber do have a warning path, and that path needs to be tested.) Question is whether Bagci and Gerber should warn-and-continue at all, or whether they should raise like ASME. Returning a negative equivalent stress amplitude with only a warning is arguably worse than just stopping, because a caller can easily miss a warning but can't miss an exception. That's a design decision for us: either make all three exponential methods raise (consistent, and then no pytest.warns test is needed anywhere), or keep the warn-vs-raise split deliberately (and then make sure each warning path gets a pytest.warns test). Either is defensible — it just needs to be decided rather than left as an accident of how the original code happened to be written. |
Pull request following issue #60 and is prepared for other stress based uniaxial fatigue criteria like #40, #44 , #45 and #46.