Skip to content

Plugin fibre section #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Analysis
examples/analysis/warping_analysis
examples/analysis/frame_analysis
examples/analysis/stress_analysis
examples/analysis/export_fibre_section

Results
-------
Expand Down
278 changes: 278 additions & 0 deletions docs/examples/analysis/export_fibre_section.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "db82db5006f2f216",
"metadata": {},
"source": [
"# Export to Fibre Section\n",
"\n",
"This example shows how to export a section to a fibre section that can be used in [suanPan](https://github.com/TLCFEM/suanPan).\n",
"\n",
"[suanPan](https://github.com/TLCFEM/suanPan) is a finite element analysis framework. Sections can be exported and used to perform nonlinear analysis of frame structures.\n",
"\n",
"There are three analysis types available.\n",
"\n",
"1. '2D' ---> 2D planar analysis (axial force, bending moment). Elements: `B21`, `F21`.\n",
"2. '3D' ---> 3D spatial analysis (axial force, bending moment). Elements: `B31`, `F31`.\n",
"3. '3DOS' ---> 3D spatial analysis with warping and torsion (axial force, bending moment, torsion). Elements: `B31OS`.\n",
"\n",
"The section is discretised into triangular elements in `sectionproperties`. Each triangle can be deemed as a small cell/fibre. Its area and properties at the centre of the triangle are calculated and exported to create a fibre section.\n",
"\n",
"For '2D' and '3D' analyses, the location and area are used. For '3DOS' analysis, the additional warping function and its derivatives are used.\n",
"\n",
"## The Export Function\n",
"\n",
"One shall call the function with a geometry object with mesh created."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1fe6766c73110947",
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.post.fibre import to_fibre_section\n",
"from sectionproperties.pre.library import i_section\n",
"\n",
"geom = i_section(d=203, b=133, t_f=7.8, t_w=5.8, r=8.9, n_r=8)\n",
"geom.create_mesh(mesh_sizes=10)\n",
"\n",
"commands = to_fibre_section(geom, analysis_type='3DOS')\n",
"\n",
"print(commands[:3000])"
]
},
{
"cell_type": "markdown",
"id": "3e59149a988e3681",
"metadata": {},
"source": [
"The output can be saved to a file and later be used to create beam elements."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e62e5df634d337ed",
"metadata": {},
"outputs": [],
"source": [
"from shutil import which\n",
"\n",
"# write the fibre section to a file\n",
"with open('200UB25.4.sp', 'w') as f:\n",
" f.write(commands)\n",
"\n",
"# write the main analysis file\n",
"# since we assigned '3DOS' analysis type, we need to use compatible elements, for example, 'B31OS'.\n",
"model = '''# Example torsion analysis\n",
"node 1 0 0 0\n",
"node 2 1 0 0\n",
"material ElasticOS 1 200. .25\n",
"file 200UB25.4.sp\n",
"orientation B3DOSL 1 0. 0. 1.\n",
"element B31OS 1 1 2 1 1 6\n",
"fix2 1 E 1\n",
"displacement 1 0 1E-1 4 2\n",
"plainrecorder 1 Node RF4 2\n",
"plainrecorder 2 Element BEAMS 1\n",
"step static 1\n",
"set ini_step_size 1E-1\n",
"set fixed_step_size true\n",
"converger RelIncreDisp 1 1E-10 5 1\n",
"analyze\n",
"save recorder 1 2\n",
"exit\n",
"'''\n",
"with open('torsion_analysis.sp', 'w') as f:\n",
" f.write(model)"
]
},
{
"cell_type": "markdown",
"id": "e3a7872e157397ad",
"metadata": {},
"source": [
"For further details, check [this](https://tlcfem.github.io/suanPan-manual/3.2/Example/Structural/Statics/thin-walled-section/) example."
]
},
{
"cell_type": "markdown",
"id": "a905cac642f4ba76",
"metadata": {},
"source": [
"## A Bit More Details\n",
"\n",
"### Shift Section\n",
"\n",
"As the header states, the function computes properties in the local coordinate system of the section.\n",
"\n",
"For the above I-section, one may want to shift the section to the centroid of the section.\n",
"The user shall explicitly perform this step."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0342167a9608431",
"metadata": {},
"outputs": [],
"source": [
"geom.plot_geometry()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72fd533e96ae001c",
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"sec = Section(geom)\n",
"sec.calculate_geometric_properties()\n",
"x, y = sec.get_c()\n",
"geom = geom.shift_section(-x, -y) # or whatever shift you want\n",
"geom.create_mesh(mesh_sizes=5)\n",
"geom.plot_geometry()"
]
},
{
"cell_type": "markdown",
"id": "c0091da299e91349",
"metadata": {},
"source": [
"### Overwrite Material\n",
"\n",
"Material names shall be converted to material tags.\n",
"\n",
"One can provide such a mapping dictionary to the function.\n",
"With the shifted geometry, one can do the following."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "381c615fd4cf7f58",
"metadata": {},
"outputs": [],
"source": [
"commands = to_fibre_section(geom, analysis_type='3DOS', material_mapping={'default': 1})\n",
"print(commands[:5000])"
]
},
{
"cell_type": "markdown",
"id": "6f3179efd747b6ff",
"metadata": {},
"source": [
"## Run Analysis\n",
"\n",
"If `suanPan` is installed, one can run the analysis using the previously saved script."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2997fa9f72909c12",
"metadata": {},
"outputs": [],
"source": [
"from os.path import exists\n",
"\n",
"# write the fibre section to a file with material tag replaced\n",
"with open('200UB25.4.sp', 'w') as f:\n",
" f.write(commands)\n",
"\n",
"# run the analysis\n",
"if which('suanpan') is not None:\n",
" from subprocess import run\n",
"\n",
" result_available = True\n",
" run(['suanpan', '-f', 'torsion_analysis.sp'])\n",
"else:\n",
" result_available = exists('R1-RF42.txt')\n",
" print('suanPan is not installed.')"
]
},
{
"cell_type": "markdown",
"id": "d77fc35609b5228e",
"metadata": {},
"source": [
"## Plot Results\n",
"\n",
"The results are stored in `R1-RF42.txt` (**R**ecorder **1** --> **RF4** for node **2**) and `R2-BEAMS1.txt` (**R**ecorder **2** --> **BEAMS** for element **1**).\n",
"\n",
"The sixth component of `BEAMS` is the St. Venant torsion."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "91298a718a2935a9",
"metadata": {},
"outputs": [],
"source": [
"if result_available:\n",
" from matplotlib import pyplot as plt\n",
" import numpy as np\n",
"\n",
" data = np.loadtxt('R1-RF42.txt')\n",
" twist = data[:, 0] * .1\n",
" torque = data[:, 1]\n",
" plt.plot(twist, torque)\n",
" plt.xlabel('twist (rad)')\n",
" plt.ylabel('total torque')\n",
" plt.legend(['200UB25.4'])\n",
" plt.tight_layout()\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e93238cf396c115d",
"metadata": {},
"outputs": [],
"source": [
"if result_available:\n",
" data = np.loadtxt('R2-BEAMS1.txt')\n",
" twist = data[:, 0] * .1\n",
" torque = data[:, 6]\n",
" ref_torque = twist * 80 * 62.7e3 # G=80, J=62.7\n",
" plt.plot(twist, torque)\n",
" plt.plot(twist, ref_torque)\n",
" plt.xlabel('twist (rad)')\n",
" plt.ylabel('St. Venant torsion')\n",
" plt.legend(['numerical', 'theoretical'])\n",
" plt.tight_layout()\n",
" plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading