{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Navier's Solution to Simply-Supported Plates\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom dewloosh.mpl.triplot import triplot\nfrom polymesh import PolyData\nfrom polymesh.grid import grid\nfrom polymesh.tri.trimesh import triangulate\nfrom polymesh.topo.tr import Q4_to_T3\nimport matplotlib.pyplot as plt\nfrom matplotlib import gridspec\nplt.style.use('default')\n\nsize = Lx, Ly = (600., 800.)\nE = 2890.\nnu = 0.2\nt = 25.0"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Set up a material model\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "G = E/2/(1+nu)\nD = np.array([[1, nu, 0], [nu, 1, 0], [0., 0, (1-nu)/2]]) * t**3 * (E / (1-nu**2)) / 12\nS = np.array([[G, 0], [0, G]]) * t * 5 / 6"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define some loads\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "loads = {\n        'LG1' : {\n            'LC1' : {\n                'type' : 'rect',\n                'points' : [[0, 0], [Lx, Ly]],\n                'value' : [0, 0, -0.01],\n                    },\n            'LC2' : {\n                'type' : 'rect',\n                'region' : [0.2*Lx, 0.5*Ly, 0.2*Lx, 0.3*Ly],\n                'value' : [0, 0, -100],\n                    }\n                },\n        'LG2' : {\n            'LC3' : {\n                'type' : 'point',\n                'point' : [Lx/3, Ly/2],\n                'value' : [0, 0, -10],\n                    },\n            'LC4' : {\n                'type' : 'point',\n                'point' : [2*Lx/3, Ly/2],\n                'value' : [0, 0, 10],\n                    }\n                },\n        'dummy1' : 10\n            }"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Solve the problem\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from sigmaepsilon.solid.fourier import RectangularPlate\n\nProblem = RectangularPlate(size, (50, 50), D=D, S=S, model='kirchhoff')\nLoads = Problem.add_loads_from_dict(loads)\nProblem.solve()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "shape = nx, ny = (30, 40)\ngridparams = {\n    'size' : size,\n    'shape' : shape,\n    'origo' : (0, 0),\n    'start' : 0,\n    'eshape' : 'Q4'\n    }\ncoords_, topo = grid(**gridparams)\ncoords = np.zeros((coords_.shape[0], 3))\ncoords[:, :2] = coords_[:, :]\ndel coords_\ncoords, triangles = Q4_to_T3(coords, topo)\n\ntriobj = triangulate(points=coords[:, :2], triangles=triangles)[-1]\nMesh = PolyData(coords=coords, topo=triangles)\ncenters = Mesh.centers()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "Problem.postproc(centers[:, :2], squeeze=False, cleanup=False)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "UZ, ROTX, ROTY, CX, CY, CXY, EXZ, EYZ, MX, MY, MXY, QX, QY = list(range(13))\nlabels = {UZ : 'UZ', ROTX : 'ROTX', ROTY : 'ROTY', CX : 'CX', \n          CY : 'CY', CXY : 'CXY', EXZ : 'EXZ', EYZ : 'EYZ', \n          MX : 'MX', MY : 'MY', MXY : 'MXY', QX : 'QX', QY : 'QY'}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "res2d = Loads['LG1', 'LC1'].res2d"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(8, 3))  # in inches\nfig.patch.set_facecolor('white')\ncmap = 'jet'\ngs = gridspec.GridSpec(1, 3)\nfor i, key in enumerate([UZ, ROTX, ROTY]):\n    ax = fig.add_subplot(gs[i])\n    triplot(triobj, ax=ax, fig=fig, title=labels[key],\n            data=res2d[key, :], cmap=cmap, axis='off')\nfig.tight_layout()\n\nfig = plt.figure(figsize=(12, 3))  # in inches\nfig.patch.set_facecolor('white')\ncmap = 'seismic'\ngs = gridspec.GridSpec(1, 5)\nfor i, key in enumerate([MX, MY, MXY, QX, QY]):\n    ax = fig.add_subplot(gs[i])\n    triplot(triobj, ax=ax, fig=fig, title=labels[key],\n            data=res2d[key, :], cmap=cmap, axis='off')\nfig.tight_layout()"
      ]
    }
  ],
  "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.8.10"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}