Skip to content

Commit 484ff18

Browse files
committed
All user function to modify fkm nonlinear constants
Signed-off-by: Benjamin Maier <[email protected]>
1 parent bbf1e68 commit 484ff18

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Diff for: src/pylife/strength/fkm_nonlinear/constants.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,15 @@ def for_material_group(assessment_parameters):
147147
All constants that are defined by FKM nonlinear for the given material group.
148148
149149
"""
150+
# call user hook to modify constants if necessary
151+
global all_constants
152+
if "user_hook" in assessment_parameters:
153+
all_constants = assessment_parameters["user_hook"](all_constants)
150154

151155
# select set of constants according to given material group
152156
assert "MatGroupFKM" in assessment_parameters
153157

154158
material_group = assessment_parameters["MatGroupFKM"]
155-
assert material_group in ["Steel", "SteelCast", "Al_wrought"]
156159

157160
resulting_constants = all_constants[material_group]
158161

Diff for: tests/strength/fkm_nonlinear/test_fkm_nonlinear.py

+50
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy.testing as testing
2424
import pylife
2525
import pylife.strength.fkm_nonlinear
26+
import pylife.strength.fkm_nonlinear.constants
2627
import pylife.strength.fkm_nonlinear.parameter_calculations
2728
import pylife.strength.fkm_nonlinear.parameter_calculations as parameter_calculations
2829

@@ -101,6 +102,55 @@ def test_material_constants():
101102
pd.testing.assert_series_equal(df_to_test.loc["b_M",:], df_reference.loc["b_M",["Steel", "SteelCast", "Al_wrought"]], check_names=False)
102103

103104

105+
def test_material_constants_existing_material():
106+
assessment_parameters = {
107+
"MatGroupFKM": "Al_wrought",
108+
}
109+
constants = pylife.strength.fkm_nonlinear.constants.for_material_group(assessment_parameters=assessment_parameters)
110+
assert constants["E"] == 70e3
111+
112+
113+
def test_material_constants_unknown_material_fails():
114+
assessment_parameters = {
115+
"MatGroupFKM": "new_material",
116+
}
117+
with pytest.raises(KeyError, match="new_material"):
118+
pylife.strength.fkm_nonlinear.constants.for_material_group(assessment_parameters=assessment_parameters)
119+
120+
121+
def test_material_constants_new_material():
122+
123+
# define user function to extend the parameter set
124+
def add_new_material(constants):
125+
126+
if "new_material" in constants:
127+
return constants
128+
129+
new_material_constants = pd.DataFrame({
130+
"new_material": {
131+
"E": 99e3,
132+
"n_prime": 0.123,
133+
}
134+
})
135+
return pd.concat([constants, new_material_constants], axis="columns")
136+
137+
# add user function
138+
assessment_parameters = {
139+
"MatGroupFKM": "new_material",
140+
"user_hook": add_new_material
141+
}
142+
143+
# retrieve constants
144+
constants = pylife.strength.fkm_nonlinear.constants.for_material_group(assessment_parameters=assessment_parameters)
145+
146+
assert constants["E"] == 99e3
147+
assert constants["n_prime"] == 0.123
148+
149+
# constants are now also updated directly in the module
150+
assert "new_material" in pylife.strength.fkm_nonlinear.constants.all_constants
151+
assert pylife.strength.fkm_nonlinear.constants.all_constants["new_material"]["E"] == 99e3
152+
153+
104154
def test_computation_functions_1():
105155
"""Example 2.10.2, "Welle mit V-Kerbe", p.138 """
106156

0 commit comments

Comments
 (0)