Skip to content

Commit

Permalink
Merge pull request #145 from boschresearch/optimize-rainflow
Browse files Browse the repository at this point in the history
Refactor HCM Rainflow counter
  • Loading branch information
johannes-mueller authored Dec 10, 2024
2 parents 693cf86 + 0ccd59a commit ae95724
Show file tree
Hide file tree
Showing 11 changed files with 1,312 additions and 1,156 deletions.
95 changes: 42 additions & 53 deletions demos/fkm_nonlinear/fkm_nonlinear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"id": "312c5770",
"metadata": {},
"source": [
"### Run FKM nonlinear algorithm"
"## Run FKM nonlinear algorithm"
]
},
{
Expand All @@ -150,7 +150,7 @@
"id": "941a473e",
"metadata": {},
"source": [
"#### Output resulting lifetimes"
"## Output resulting lifetimes"
]
},
{
Expand Down Expand Up @@ -209,7 +209,7 @@
"id": "165ca7d3",
"metadata": {},
"source": [
"#### Lifetime $N$ for given failure probability $P_A$\n",
"## Lifetime $N$ for given failure probability $P_A$\n",
"The dashed lines show the lifetime if the scaling factor $\\gamma_M$ is not clipped at 1.1 (P_RAM), respective 1.2 (P_RAJ)."
]
},
Expand Down Expand Up @@ -239,7 +239,7 @@
"id": "7c518856",
"metadata": {},
"source": [
"#### Plot failure probability\n",
"## Plot failure probability\n",
"The marked points have $P_A$ = 50%."
]
},
Expand Down Expand Up @@ -274,7 +274,7 @@
"id": "94ac0271",
"metadata": {},
"source": [
"#### Woehler curves"
"## Woehler curves"
]
},
{
Expand Down Expand Up @@ -366,7 +366,7 @@
"id": "2e8a779f",
"metadata": {},
"source": [
"#### Hystereses"
"## Hystereses"
]
},
{
Expand Down Expand Up @@ -398,33 +398,27 @@
"# plot resulting stress-strain curve\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"plotting_data = detector.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
" \n",
"primary = plotting_data.loc[~plotting_data.secondary_branch]\n",
"secondary = plotting_data.loc[plotting_data.secondary_branch]\n",
"\n",
"strain_values_primary = plotting_data[\"strain_values_primary\"]\n",
"stress_values_primary = plotting_data[\"stress_values_primary\"]\n",
"hysteresis_index_primary = plotting_data[\"hysteresis_index_primary\"]\n",
"strain_values_secondary = plotting_data[\"strain_values_secondary\"]\n",
"stress_values_secondary = plotting_data[\"stress_values_secondary\"]\n",
"hysteresis_index_secondary = plotting_data[\"hysteresis_index_secondary\"]\n",
"\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"plotting_data_1st = detector_1st.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
"\n",
"strain_values_primary_1st = plotting_data_1st[\"strain_values_primary\"]\n",
"stress_values_primary_1st = plotting_data_1st[\"stress_values_primary\"]\n",
"hysteresis_index_primary_1st = plotting_data_1st[\"hysteresis_index_primary\"]\n",
"strain_values_secondary_1st = plotting_data_1st[\"strain_values_secondary\"]\n",
"stress_values_secondary_1st = plotting_data_1st[\"stress_values_secondary\"]\n",
"hysteresis_index_secondary_1st = plotting_data_1st[\"hysteresis_index_secondary\"]\n",
"\n",
"plotting_data_1st = detector.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
" \n",
"primary_1st = plotting_data_1st.loc[~plotting_data_1st.secondary_branch]\n",
"secondary_1st = plotting_data_1st.loc[plotting_data_1st.secondary_branch]\n",
"\n",
"# stress-strain diagram\n",
"axes[1,0].plot(strain_values_primary, stress_values_primary, \"y-\", lw=2, label=\"HCM second run\")\n",
"axes[1,0].plot(strain_values_secondary, stress_values_secondary, \"y-.\", lw=2)\n",
"axes[1,0].plot(strain_values_primary_1st, stress_values_primary_1st, \"g-\", lw=2, label=\"HCM first run\")\n",
"axes[1,0].plot(strain_values_secondary_1st, stress_values_secondary_1st, \"g-.\", lw=2)\n",
"for i, prim in primary.groupby(\"load_segment\"):\n",
" axes[1,0].plot(prim.strain, prim.stress, \"y-\", lw=2, label=\"HCM second run\" if i == 0 else None)\n",
"for _, sec in secondary.groupby(\"load_segment\"):\n",
" axes[1,0].plot(sec.strain, sec.stress, \"y-.\", lw=2)\n",
"for i, prim in primary_1st.groupby(\"load_segment\"):\n",
" axes[1,0].plot(prim.strain, prim.stress, \"g-\", lw=2, label=\"HCM first run\" if i == 0 else None)\n",
"for _, sec in secondary_1st.groupby(\"load_segment\"):\n",
" axes[1,0].plot(sec.strain, sec.stress, \"g-.\", lw=2)\n",
"axes[1,0].grid()\n",
"axes[1,0].set_xlabel(\"$\\epsilon$\")\n",
"axes[1,0].set_ylabel(\"$\\sigma$ [MPa]\")\n",
"axes[1,0].set_xlabel(r\"$\\epsilon$\")\n",
"axes[1,0].set_ylabel(r\"$\\sigma$ [MPa]\")\n",
"axes[1,0].set_title(f\"P_{parameter_name} material response\")\n",
"\n",
"\n",
Expand All @@ -442,32 +436,27 @@
"# plot resulting stress-strain curve\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"plotting_data = detector.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
" \n",
"primary = plotting_data.loc[~plotting_data.secondary_branch]\n",
"secondary = plotting_data.loc[plotting_data.secondary_branch]\n",
"\n",
"strain_values_primary = plotting_data[\"strain_values_primary\"]\n",
"stress_values_primary = plotting_data[\"stress_values_primary\"]\n",
"hysteresis_index_primary = plotting_data[\"hysteresis_index_primary\"]\n",
"strain_values_secondary = plotting_data[\"strain_values_secondary\"]\n",
"stress_values_secondary = plotting_data[\"stress_values_secondary\"]\n",
"hysteresis_index_secondary = plotting_data[\"hysteresis_index_secondary\"]\n",
"\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"plotting_data_1st = detector_1st.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
"\n",
"strain_values_primary_1st = plotting_data_1st[\"strain_values_primary\"]\n",
"stress_values_primary_1st = plotting_data_1st[\"stress_values_primary\"]\n",
"hysteresis_index_primary_1st = plotting_data_1st[\"hysteresis_index_primary\"]\n",
"strain_values_secondary_1st = plotting_data_1st[\"strain_values_secondary\"]\n",
"stress_values_secondary_1st = plotting_data_1st[\"stress_values_secondary\"]\n",
"hysteresis_index_secondary_1st = plotting_data_1st[\"hysteresis_index_secondary\"]\n",
"plotting_data_1st = detector.interpolated_stress_strain_data(n_points_per_branch=sampling_parameter)\n",
" \n",
"primary_1st = plotting_data_1st.loc[~plotting_data_1st.secondary_branch]\n",
"secondary_1st = plotting_data_1st.loc[plotting_data_1st.secondary_branch]\n",
"\n",
"# stress-strain diagram\n",
"axes[1,1].plot(strain_values_primary, stress_values_primary, \"y-\", lw=2, label=\"HCM second run\")\n",
"axes[1,1].plot(strain_values_secondary, stress_values_secondary, \"y-.\", lw=2)\n",
"axes[1,1].plot(strain_values_primary_1st, stress_values_primary_1st, \"g-\", lw=2, label=\"HCM first run\")\n",
"axes[1,1].plot(strain_values_secondary_1st, stress_values_secondary_1st, \"g-.\", lw=2)\n",
"for i, prim in primary.groupby(\"load_segment\"):\n",
" axes[1,1].plot(prim.strain, prim.stress, \"y-\", lw=2, label=\"HCM second run\" if i == 0 else None)\n",
"for _, sec in secondary.groupby(\"load_segment\"):\n",
" axes[1,1].plot(sec.strain, sec.stress, \"y-.\", lw=2)\n",
"for i, prim in primary_1st.groupby(\"load_segment\"):\n",
" axes[1,1].plot(prim.strain, prim.stress, \"g-\", lw=2, label=\"HCM first run\" if i == 0 else None)\n",
"for _, sec in secondary_1st.groupby(\"load_segment\"):\n",
" axes[1,1].plot(sec.strain, sec.stress, \"g-.\", lw=2)\n",
"axes[1,1].grid()\n",
"axes[1,1].set_xlabel(\"$\\epsilon$\")\n",
"axes[1,1].set_ylabel(\"$\\sigma$ [MPa]\")\n",
"axes[1,1].set_xlabel(r\"$\\epsilon$\")\n",
"axes[1,1].set_ylabel(r\"$\\sigma$ [MPa]\")\n",
"axes[1,1].set_title(f\"P_{parameter_name} material response\")\n",
"\n",
"plt.tight_layout()"
Expand All @@ -478,7 +467,7 @@
"id": "31668d98",
"metadata": {},
"source": [
"#### Damaging effects of hystereses"
"## Damaging effects of hystereses"
]
},
{
Expand Down Expand Up @@ -546,7 +535,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit ae95724

Please sign in to comment.