{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import lostinmsh as lsm\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "%matplotlib inline\n", "plt.rcParams.update({\"font.size\": 15})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define the polygon\n", "\n", "First we need to define the polygon from its vertices given as a sequence of 2d points and we also need to provide a name." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "vertices = [[0, 0], [1, 0], [0, 1]]\n", "polygon = lsm.Polygon.from_vertices(vertices, \"Cavity\")\n", "\n", "fig, ax = plt.subplots(figsize=[5, 5], layout=\"constrained\")\n", "lsm.plot_polygon(polygon, ax=ax)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define the geometry\n", "\n", "Then, we need to define the geometry from a polygon and a border.\n", "Two type of borders are implemented Circular and Rectangular borders without with a PML.\n", "The border can be given explicitly." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "fig, axs = plt.subplots(nrows=2, ncols=2, figsize=[10, 10], layout=\"constrained\")\n", "center = np.array([1 / 3, 1 / 3])\n", "borders = [\n", " [\n", " lsm.Rectangular(center=center, half_width=1, half_height=1),\n", " lsm.Rectangular(center=center, half_width=1, half_height=1, thickness=0.2),\n", " ],\n", " [\n", " lsm.Circular(center=center, radius=1),\n", " lsm.Circular(center=center, radius=1, thickness=0.2),\n", " ],\n", "]\n", "\n", "for i in range(2):\n", " for j in range(2):\n", " border, ax = borders[i][j], axs[i, j]\n", " geometry = lsm.Geometry.from_polygon(polygon, border)\n", " lsm.plot_geometry(geometry, ax=ax)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or the border can be computed automaticaly." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "fig, axs = plt.subplots(nrows=2, ncols=2, figsize=[10, 10], layout=\"constrained\")\n", "borders = [\n", " [\n", " lsm.AutoRectangular(border_factor=0.5),\n", " lsm.AutoRectangular(border_factor=0.5, thickness_factor=0.25),\n", " ],\n", " [\n", " lsm.AutoCircular(border_factor=0.5),\n", " lsm.AutoCircular(border_factor=0.5, thickness_factor=0.25),\n", " ],\n", "]\n", "\n", "for i in range(2):\n", " for j in range(2):\n", " border, ax = borders[i][j], axs[i, j]\n", " geometry = lsm.Geometry.from_polygon(polygon, border)\n", " lsm.plot_geometry(geometry, ax=ax)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mesh the geometry" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Info : Increasing process stack size (8192 kB < 16 MB)\n" ] } ], "source": [ "lsm.mesh_unstructured(geometry, 0.1, lsm.GmshOptions(gui=True))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Locally structured mesh the geometry" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "tags": [] }, "outputs": [], "source": [ "lsm.mesh_loc_struct(geometry, 0.1, lsm.GmshOptions(gui=True))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.0rc1" }, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 4 }