Skip to content

Commit

Permalink
Reorganize plotting cell in jupyter notebook to remove if in for loop
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Maier <[email protected]>
  • Loading branch information
maierbn committed Oct 10, 2023
1 parent 4032d95 commit a344d54
Showing 1 changed file with 72 additions and 42 deletions.
114 changes: 72 additions & 42 deletions demos/fkm_nonlinear/fkm_nonlinear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# FKM nonlinear assessment for a single point\n",
"This jupyter notebook is the main example how to apply the FKM nonlinear, i.e., the local strain concept using pylife.\n",
"If you have voilà installed (``pip install voila``), you can also open the notebook by clicking on the voila button in the top bar. This hides the code blocks and makes the plots better visible.\n",
"If you have voilà installed (``pip install voila``), you can also open the notebook by clicking on the voila button in the top bar. This will hide the code blocks and make the plots better visible.\n",
"\n",
"The algorithm follows the document `\"RICHTLINIE NICHTLINEAR / Rechnerischer Festigkeitsnachweis unter expliziter Erfassung nichtlinearen Werkstoffverformungsverhaltens / Für Bauteile aus Stahl, Stahlguss und Aluminiumknetlegierungen / 1.Auflage, 2019\"`. If you want to learn more about how the algorithm works, have a look at the notebook [fkm_nonlinear_full](fkm_nonlinear_full.ipynb)."
]
Expand Down Expand Up @@ -377,48 +377,78 @@
"outputs": [],
"source": [
"fig, axes = plt.subplots(2, 2, figsize=(12,10))\n",
" \n",
"for i, parameter_name in enumerate([\"RAM\", \"RAJ\"]):\n",
"\n",
" detector = result[f\"P_{parameter_name}_detector\"]\n",
" detector_1st = result[f\"P_{parameter_name}_detector_1st\"]\n",
"\n",
" # plot resulting stress-strain curve\n",
" sampling_parameter = 50 # choose larger for smoother plot\n",
" strain_values_primary, stress_values_primary, hysteresis_index_primary, \\\n",
" strain_values_secondary, stress_values_secondary, hysteresis_index_secondary \\\n",
" = detector.interpolated_stress_strain_data(sampling_parameter)\n",
"\n",
" sampling_parameter = 50 # choose larger for smoother plot\n",
" strain_values_primary_1st, stress_values_primary_1st, hysteresis_index_primary_1st, \\\n",
" strain_values_secondary_1st, stress_values_secondary_1st, hysteresis_index_secondary_1st \\\n",
" = detector_1st.interpolated_stress_strain_data(sampling_parameter)\n",
"\n",
" # load-time diagram\n",
" if i == 0:\n",
" import matplotlib\n",
" matplotlib.rcParams.update({'font.size': 14})\n",
" axes[0,0].plot(load_sequence, \"o-\", lw=2)\n",
" axes[0,0].grid()\n",
" axes[0,0].set_xlabel(\"t [s]\")\n",
" axes[0,0].set_ylabel(\"L [N]\")\n",
" axes[0,0].set_title(\"Load sequence\")\n",
" else:\n",
" axes[0,1].axis(\"off\")\n",
" axes[0,1].legend(handles, labels, bbox_to_anchor=(0.0,0), loc='lower left')\n",
" \n",
"\n",
" # stress-strain diagram\n",
" axes[1,i].plot(strain_values_primary, stress_values_primary, \"y-\", lw=2, label=\"HCM second run\")\n",
" axes[1,i].plot(strain_values_secondary, stress_values_secondary, \"y-.\", lw=2)\n",
" axes[1,i].plot(strain_values_primary_1st, stress_values_primary_1st, \"g-\", lw=2, label=\"HCM first run\")\n",
" axes[1,i].plot(strain_values_secondary_1st, stress_values_secondary_1st, \"g-.\", lw=2)\n",
" axes[1,i].grid()\n",
" axes[1,i].set_xlabel(\"$\\epsilon$\")\n",
" axes[1,i].set_ylabel(\"$\\sigma$ [MPa]\")\n",
" axes[1,i].set_title(f\"P_{parameter_name} material response\")\n",
" handles, labels = axes[1,i].get_legend_handles_labels()\n",
" \n",
"# set font size \n",
"import matplotlib\n",
"matplotlib.rcParams.update({'font.size': 14})\n",
"\n",
"# prepare first plot\n",
"axes[0,0].plot(load_sequence, \"o-\", lw=2)\n",
"axes[0,0].grid()\n",
"axes[0,0].set_xlabel(\"t [s]\")\n",
"axes[0,0].set_ylabel(\"L [N]\")\n",
"axes[0,0].set_title(\"Load sequence\")\n",
"\n",
"# plot hystereses for P_RAM\n",
"# ---------------------------\n",
"parameter_name = \"RAM\"\n",
"detector = result[f\"P_{parameter_name}_detector\"]\n",
"detector_1st = result[f\"P_{parameter_name}_detector_1st\"]\n",
"\n",
"# plot resulting stress-strain curve\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"strain_values_primary, stress_values_primary, hysteresis_index_primary, \\\n",
"strain_values_secondary, stress_values_secondary, hysteresis_index_secondary \\\n",
" = detector.interpolated_stress_strain_data(sampling_parameter)\n",
"\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"strain_values_primary_1st, stress_values_primary_1st, hysteresis_index_primary_1st, \\\n",
"strain_values_secondary_1st, stress_values_secondary_1st, hysteresis_index_secondary_1st \\\n",
" = detector_1st.interpolated_stress_strain_data(sampling_parameter)\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",
"axes[1,0].grid()\n",
"axes[1,0].set_xlabel(\"$\\epsilon$\")\n",
"axes[1,0].set_ylabel(\"$\\sigma$ [MPa]\")\n",
"axes[1,0].set_title(f\"P_{parameter_name} material response\")\n",
"\n",
"\n",
"# show only legend in field axes[0,1]\n",
"handles, labels = axes[1,0].get_legend_handles_labels()\n",
"axes[0,1].axis(\"off\")\n",
"axes[0,1].legend(handles, labels, bbox_to_anchor=(0.0,0), loc='lower left')\n",
"\n",
"# plot hystereses for P_RAJ\n",
"# ---------------------------\n",
"parameter_name = \"RAJ\"\n",
"detector = result[f\"P_{parameter_name}_detector\"]\n",
"detector_1st = result[f\"P_{parameter_name}_detector_1st\"]\n",
"\n",
"# plot resulting stress-strain curve\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"strain_values_primary, stress_values_primary, hysteresis_index_primary, \\\n",
"strain_values_secondary, stress_values_secondary, hysteresis_index_secondary \\\n",
" = detector.interpolated_stress_strain_data(sampling_parameter)\n",
"\n",
"sampling_parameter = 50 # choose larger for smoother plot\n",
"strain_values_primary_1st, stress_values_primary_1st, hysteresis_index_primary_1st, \\\n",
"strain_values_secondary_1st, stress_values_secondary_1st, hysteresis_index_secondary_1st \\\n",
" = detector_1st.interpolated_stress_strain_data(sampling_parameter)\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",
"axes[1,1].grid()\n",
"axes[1,1].set_xlabel(\"$\\epsilon$\")\n",
"axes[1,1].set_ylabel(\"$\\sigma$ [MPa]\")\n",
"axes[1,1].set_title(f\"P_{parameter_name} material response\")\n",
"\n",
"plt.tight_layout()"
]
},
Expand Down

0 comments on commit a344d54

Please sign in to comment.