{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mesh Analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "sigmaepsilon.mesh provides some useful classes and algorithms for mesh management and operations related to the geometry or the topology of polygonal meshes." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pyvista as pv\n", "import numpy as np\n", "from sigmaepsilon.mesh import PolyData\n", "\n", "d, h, a = 6.0, 15.0, 15.0\n", "cyl = pv.CylinderStructured(\n", " center=(0.0, 0.0, 0.0),\n", " direction=(0.0, 0.0, 1.0),\n", " radius=np.linspace(d / 2, a / 2, 15),\n", " height=h,\n", " theta_resolution=100,\n", " z_resolution=40,\n", ")\n", "mesh: PolyData = PolyData.from_pv(cyl)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Nodal Distribution Factors" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1. , 0.47580645, 0.23790323, ..., 0.23790323, 0.11895161,\n", " 0.25 ],\n", " [0.52419355, 0.47794118, 0.23897059, ..., 0.23897059, 0.11948529,\n", " 0.13104839],\n", " [0.52205882, 0.47972973, 0.23986486, ..., 0.23986486, 0.11993243,\n", " 0.13051471],\n", " ...,\n", " [0.12807377, 0.12207031, 0.24414062, ..., 0.24414062, 0.48828125,\n", " 0.51229508],\n", " [0.12792969, 0.12220149, 0.24440299, ..., 0.24440299, 0.48880597,\n", " 0.51171875],\n", " [0.12779851, 0.25 , 0.5 , ..., 0.5 , 1. ,\n", " 0.51119403]])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.nodal_distribution_factors()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Nodal Adjacency" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To access the nodal adjacency matrix as a scipy sparse matrix:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<60600x60600 sparse array of type ''\n", "\twith 1527274 stored elements in Compressed Sparse Row format>" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.nodal_adjacency(frmt=\"scipy-csr\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.nodal_adjacency(frmt=\"nx\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "as an `Awkward` array:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
[[0, 1, 15, 16, 1515, 1516, 1530, 1531],\n",
       " [0, 1, 2, 15, 16, 17, 1515, 1516, 1517, 1530, 1531, 1532],\n",
       " [1, 2, 3, 16, 17, 18, 1516, 1517, 1518, 1531, 1532, 1533],\n",
       " [2, 3, 4, 17, 18, 19, 1517, 1518, 1519, 1532, 1533, 1534],\n",
       " [3, 4, 5, 18, 19, 20, 1518, 1519, 1520, 1533, 1534, 1535],\n",
       " [4, 5, 6, 19, 20, 21, 1519, 1520, 1521, 1534, 1535, 1536],\n",
       " [5, 6, 7, 20, 21, 22, 1520, 1521, 1522, 1535, 1536, 1537],\n",
       " [6, 7, 8, 21, 22, 23, 1521, 1522, 1523, 1536, 1537, 1538],\n",
       " [7, 8, 9, 22, 23, 24, 1522, 1523, 1524, 1537, 1538, 1539],\n",
       " [8, 9, 10, 23, 24, 25, 1523, 1524, 1525, 1538, 1539, 1540],\n",
       " ...,\n",
       " [59060, 59061, 59062, 59075, 59076, ..., 60576, 60577, 60590, 60591, 60592],\n",
       " [59061, 59062, 59063, 59076, 59077, ..., 60577, 60578, 60591, 60592, 60593],\n",
       " [59062, 59063, 59064, 59077, 59078, ..., 60578, 60579, 60592, 60593, 60594],\n",
       " [59063, 59064, 59065, 59078, 59079, ..., 60579, 60580, 60593, 60594, 60595],\n",
       " [59064, 59065, 59066, 59079, 59080, ..., 60580, 60581, 60594, 60595, 60596],\n",
       " [59065, 59066, 59067, 59080, 59081, ..., 60581, 60582, 60595, 60596, 60597],\n",
       " [59066, 59067, 59068, 59081, 59082, ..., 60582, 60583, 60596, 60597, 60598],\n",
       " [59067, 59068, 59069, 59082, 59083, ..., 60583, 60584, 60597, 60598, 60599],\n",
       " [59068, 59069, 59083, 59084, 60583, 60584, 60598, 60599]]\n",
       "-----------------------------------------------------------------------------\n",
       "type: 60600 * var * int64
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.nodal_adjacency(frmt=\"jagged\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or as a Numba-jittable CSR matrix from `sigmaepsilon.math`:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "60600x60600 CSR matrix of 1527274 values." ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.nodal_adjacency(frmt=\"csr\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pseudo Peripheral Nodes" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from sigmaepsilon.math.topology.graph import pseudo_peripheral_nodes\n", "\n", "csr = mesh.nodal_adjacency(frmt=\"csr\")\n", "ppn = pseudo_peripheral_nodes(csr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rooted Level Structure" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from sigmaepsilon.math.topology.graph import rooted_level_structure\n", "\n", "rls = rooted_level_structure(csr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## K-Nearest-Neighbours with ``Scipy`` or ``SkLearn``" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0, 1, 4],\n", " [1, 2, 0],\n", " [2, 1, 3],\n", " [3, 2, 7],\n", " [4, 5, 0]], dtype=int64)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sigmaepsilon.mesh import grid, PolyData, PointData\n", "from sigmaepsilon.mesh.cells import H8\n", "\n", "size = 80, 60, 20\n", "shape = 10, 8, 4\n", "coords, topo = grid(size=size, shape=shape, eshape=\"H8\")\n", "pd = PointData(coords=coords)\n", "cd = H8(topo=topo)\n", "mesh = PolyData(pd, cd)\n", "mesh.k_nearest_cell_neighbours(k=3, knn_options=dict(max_distance=10.0))[:5]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.10 ('.sigeps': venv)", "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" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "5facf25dadae24d0f6f3d9b821e9851478f51388ee31821a60476e833f1169c6" } } }, "nbformat": 4, "nbformat_minor": 2 }