{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Creating a Composite Section\n\nCreate a section of mixed materials.\n\nThe following example demonstrates how to create a composite cross-section by assigning\ndifferent material properties to various regions of the mesh. A steel 310UB40.4 is modelled\nwith a 50Dx600W timber panel placed on its top flange.\n\nThe geometry and mesh are plotted, and the mesh information printed to the terminal\nbefore the analysis is carried out. All types of cross-section analyses are carried\nout, with an axial force, bending moment and shear force applied during the stress\nanalysis. Once the analysis is complete, the cross-section properties are printed\nto the terminal and a plot of the centroids and cross-section stresses generated.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# sphinx_gallery_thumbnail_number = 2\n\nimport sectionproperties.pre.library.primitive_sections as sections\nimport sectionproperties.pre.library.steel_sections as steel_sections\nfrom sectionproperties.pre.geometry import CompoundGeometry\nfrom sectionproperties.pre.pre import Material\nfrom sectionproperties.analysis.section import Section"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create material properties\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "steel = Material(\n    name=\"Steel\",\n    elastic_modulus=200e3,\n    poissons_ratio=0.3,\n    yield_strength=500,\n    density=8.05e-6,\n    color=\"grey\",\n)\ntimber = Material(\n    name=\"Timber\",\n    elastic_modulus=8e3,\n    poissons_ratio=0.35,\n    yield_strength=20,\n    density=0.78e-6,\n    color=\"burlywood\",\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create 310UB40.4\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ub = steel_sections.i_section(\n    d=304, b=165, t_f=10.2, t_w=6.1, r=11.4, n_r=8, material=steel\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create timber panel on top of the UB\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "panel = sections.rectangular_section(d=50, b=600, material=timber)\npanel = panel.align_center(ub).align_to(ub, on=\"top\")\n# Create intermediate nodes in panel to match nodes in ub\npanel = (panel - ub) | panel"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Merge the two sections into one geometry object\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "section_geometry = CompoundGeometry([ub, panel])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create a mesh and a Section object. For the mesh use a mesh size of 5 for\nthe UB, 20 for the panel\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "section_geometry.create_mesh(mesh_sizes=[5, 20])\ncomp_section = Section(section_geometry, time_info=True)\ncomp_section.display_mesh_info()  # display the mesh information"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the mesh with coloured materials and a line transparency of 0.6\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "comp_section.plot_mesh(materials=True, alpha=0.6)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Perform a geometric, warping and plastic analysis\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "comp_section.calculate_geometric_properties()\ncomp_section.calculate_warping_properties()\ncomp_section.calculate_plastic_properties(verbose=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Perform a stress analysis with N = 100 kN, Mxx = 120 kN.m and Vy = 75 kN\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "stress_post = comp_section.calculate_stress(N=-100e3, Mxx=-120e6, Vy=-75e3)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Print the results to the terminal\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "comp_section.display_results()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the centroids\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "comp_section.plot_centroids()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the axial stress\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "stress_post.plot_stress_n_zz(pause=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the bending stress\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "stress_post.plot_stress_m_zz(pause=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the shear stress\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "stress_post.plot_stress_v_zxy()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}