|
23 | 23 | import numpy.testing as testing
|
24 | 24 | import pylife
|
25 | 25 | import pylife.strength.fkm_nonlinear
|
| 26 | +import pylife.strength.fkm_nonlinear.constants |
26 | 27 | import pylife.strength.fkm_nonlinear.parameter_calculations
|
27 | 28 | import pylife.strength.fkm_nonlinear.parameter_calculations as parameter_calculations
|
28 | 29 |
|
@@ -101,6 +102,55 @@ def test_material_constants():
|
101 | 102 | pd.testing.assert_series_equal(df_to_test.loc["b_M",:], df_reference.loc["b_M",["Steel", "SteelCast", "Al_wrought"]], check_names=False)
|
102 | 103 |
|
103 | 104 |
|
| 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 | + |
104 | 154 | def test_computation_functions_1():
|
105 | 155 | """Example 2.10.2, "Welle mit V-Kerbe", p.138 """
|
106 | 156 |
|
|
0 commit comments