{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Creating Custom Geometry\n\n\nCalculate section properties of a user-defined section from points and facets.\n\nThe following example demonstrates how geometry objects can be created from a\nlist of points, facets, holes and control points. An straight angle section with\na plate at its base is created from a list of points and facets. The bottom plate\nis assigned a separate control point meaning two discrete regions are created.\nCreating separate regions allows the user to control the mesh size in each region\nand assign material properties to different regions. The geometry is cleaned to\nremove the overlapping facet at the junction of the angle and the plate. A\ngeometric, warping and plastic analysis is then carried out.\n\nThe geometry and mesh are plotted before the analysis is carried out. Once the\nanalysis is complete, a plot of the various calculated centroids is generated.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# sphinx_gallery_thumbnail_number = 2\n\nfrom sectionproperties.pre.geometry import CompoundGeometry\nfrom sectionproperties.analysis.section import Section"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define parameters for the angle section\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "a = 1\nb = 2\nt = 0.1"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Build the lists of points, facets, holes and control points\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "points = [\n    [-t / 2, -2 * a],\n    [t / 2, -2 * a],\n    [t / 2, -t / 2],\n    [a, -t / 2],\n    [a, t / 2],\n    [-t / 2, t / 2],\n    [-b / 2, -2 * a],\n    [b / 2, -2 * a],\n    [b / 2, -2 * a - t],\n    [-b / 2, -2 * a - t],\n]\nfacets = [\n    [0, 1],\n    [1, 2],\n    [2, 3],\n    [3, 4],\n    [4, 5],\n    [5, 0],\n    [6, 7],\n    [7, 8],\n    [8, 9],\n    [9, 6],\n]\nholes = []\ncontrol_points = [[0, 0], [0, -2 * a - t / 2]]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Because we have two separate geometry regions (as indicated by our control_points)\nwe create a CompoundGeometry from points\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "geometry = CompoundGeometry.from_points(points, facets, control_points, holes)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create the mesh and section. For the mesh, use a smaller refinement for the angle region.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "geometry.create_mesh(mesh_sizes=[0.0005, 0.001])\n\nsection = Section(geometry)\nsection.plot_mesh()  # plot the generated mesh"
      ]
    },
    {
      "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": [
        "section.calculate_geometric_properties()\nsection.calculate_warping_properties()\nsection.calculate_plastic_properties()\n\nsection.plot_centroids()"
      ]
    }
  ],
  "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
}