Skip to content

Commit

Permalink
Add advanced plot and rectangular torsion example
Browse files Browse the repository at this point in the history
  • Loading branch information
robbievanleeuwen committed Sep 26, 2023
1 parent 0308da8 commit a6c29c2
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 4 deletions.
121 changes: 119 additions & 2 deletions docs/examples/advanced/advanced_plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,130 @@
"# Advanced Plotting"
]
},
{
"cell_type": "markdown",
"id": "e5f5821a-5b0e-4195-88b3-f8aad0e6ae2c",
"metadata": {},
"source": [
"All plots in `sectionproperties` allow keyword arguments to be passed to [plotting_context()](../..//gen/sectionproperties.post.post.plotting_context.rst#sectionproperties.post.post.plotting_context). This example shows one application of using the `plotting_context()` to generate a custom plot in a 2 x 2 arrangement."
]
},
{
"cell_type": "markdown",
"id": "c4ed61cc-ab12-4e60-aa51-b5e0f52160c8",
"metadata": {},
"source": [
"## Create Geometry and Perform Analysis"
]
},
{
"cell_type": "markdown",
"id": "fbab4168-0b45-4d4e-befe-206b66e21774",
"metadata": {},
"source": [
"We start by creating the geometry for a 100 x 6 SHS."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66522637-ff51-4945-ab72-a1a354ea9e67",
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import rectangular_hollow_section\n",
"\n",
"geom = rectangular_hollow_section(d=100, b=100, t=6, r_out=15, n_r=8)"
]
},
{
"cell_type": "markdown",
"id": "ebc2c4aa-a61f-4b32-abd2-c6421b413e93",
"metadata": {},
"source": [
"Next we create a mesh and a `Section` object."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6875e793-9338-4f0f-af26-94deee9e03bd",
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.analysis.section import Section\n",
"\n",
"geom.create_mesh(mesh_sizes=[5])\n",
"sec = Section(geometry=geom)"
]
},
{
"cell_type": "markdown",
"id": "e9bd87c4-64f7-4fe3-8183-782559a66953",
"metadata": {},
"source": [
"We can now perform a stress analysis by applying a 10 kN.m torsion (after first running the geometric and warping analysis)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ca25a4a4",
"id": "e0be003c-b341-42aa-babc-9659bcf84e95",
"metadata": {},
"outputs": [],
"source": []
"source": [
"sec.calculate_geometric_properties()\n",
"sec.calculate_warping_properties()\n",
"stress = sec.calculate_stress(mzz=10e6)"
]
},
{
"cell_type": "markdown",
"id": "af740576-9c70-4cd0-9d7d-df2fb2abd412",
"metadata": {},
"source": [
"## Generate Plot\n",
"\n",
"We are going to generate a plot of the geometry, mesh, centroids and stress. In the first plot, we will setup the parameters of the entire figure. We make sure we set `render=False` to prevent the plot from displaying before we are finished. In the subsequent plots we pass the axis we would like to display the plot on."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ff4d819e-45c7-4a73-92c5-9f40f8656327",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"# plot the geometry\n",
"ax = geom.plot_geometry(\n",
" labels=[],\n",
" nrows=2,\n",
" ncols=2,\n",
" figsize=(12, 7),\n",
" render=False,\n",
")\n",
"\n",
"# get the figure object from the first plot\n",
"fig = ax.get_figure()\n",
"\n",
"# plot the mesh\n",
"sec.plot_mesh(materials=False, ax=fig.axes[1])\n",
"\n",
"# plot the centroids\n",
"sec.plot_centroids(ax=fig.axes[2])\n",
"\n",
"# plot the torsion stress\n",
"stress.plot_stress(\n",
" stress=\"mzz_zxy\",\n",
" normalize=False,\n",
" ax=fig.axes[3],\n",
")\n",
"\n",
"# finally display the plot\n",
"plt.show()"
]
}
],
"metadata": {
Expand Down
93 changes: 91 additions & 2 deletions docs/examples/advanced/rectangle_torsion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,102 @@
"# Torsion Constant of a Rectangle"
]
},
{
"cell_type": "markdown",
"id": "4dc5e9c9-cfde-413c-8d7d-ff4cab4e8fe3",
"metadata": {},
"source": [
"This example shows how `sectionproperties` can be used as part of a script to conduct multiple analyses. In this example, we examine how the torsion constant varies with the aspect ratio of a rectangle section."
]
},
{
"cell_type": "markdown",
"id": "9a918ccf-a17d-4813-8557-990ca96d904a",
"metadata": {},
"source": [
"## Setup Analysis Parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7ce67c7-f227-4756-83e8-1ffec6590ee0",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# list of aspect ratios to analyse (10^0 = 1 to 10^1.301 = 20)\n",
"# logspace used to concentrate data near aspect ratio = 1\n",
"aspect_ratios = np.logspace(0, 1.301, 50)\n",
"torsion_constants = [] # list of torsion constant results\n",
"area = 1 # cross-section area\n",
"n = 100 # approximate number of finite elements in each analysis"
]
},
{
"cell_type": "markdown",
"id": "e03ba7bb-2971-4f92-a0f3-317a8bd52adf",
"metadata": {},
"source": [
"## Analysis Loop"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e485da27",
"id": "7984f360-8928-4b1c-a528-819ceca24b17",
"metadata": {},
"outputs": [],
"source": []
"source": [
"from sectionproperties.pre.library import rectangular_section\n",
"from sectionproperties.analysis.section import Section\n",
"\n",
"for ar in aspect_ratios:\n",
" # calculate rectangle dimensions\n",
" d = np.sqrt(ar)\n",
" b = 1 / d\n",
" geom = rectangular_section(d=d, b=b)\n",
"\n",
" # create mesh and Section object\n",
" ms = d * b / n\n",
" geom.create_mesh(mesh_sizes=[ms])\n",
" sec = Section(geometry=geom)\n",
"\n",
" # perform analysis\n",
" sec.calculate_frame_properties()\n",
"\n",
" # save the torsion constant\n",
" torsion_constants.append(sec.get_j())"
]
},
{
"cell_type": "markdown",
"id": "222959a8-bab9-44a5-9f4f-67e62ab238e4",
"metadata": {},
"source": [
"## Plot Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79bcd59d-254d-4fd2-b6c1-99bdb17f3ad2",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"_, ax = plt.subplots()\n",
"ax.plot(aspect_ratios, torsion_constants, \"k-\")\n",
"ax.set_xlim(0, 21)\n",
"ax.set_ylim(0, 0.15)\n",
"ax.set_xlabel(\"Aspect Ratio [d/b]\")\n",
"ax.set_ylabel(\"Torsion Constant [J]\")\n",
"ax.set_title(\"Rectangular Section Torsion Constant\")\n",
"ax.grid()\n",
"plt.show()"
]
}
],
"metadata": {
Expand Down

0 comments on commit a6c29c2

Please sign in to comment.