{ "cells": [ { "cell_type": "markdown", "id": "4f7c874c", "metadata": {}, "source": [ "Copyright (C) 2022 Michele Castriotta, Igor Baratta, Jørgen S. Dokken" ] }, { "cell_type": "code", "execution_count": null, "id": "a06eed45", "metadata": {}, "outputs": [], "source": [ "import sys" ] }, { "cell_type": "code", "execution_count": null, "id": "a25612c7", "metadata": {}, "outputs": [], "source": [ "try:\n", " import gmsh\n", "except ModuleNotFoundError:\n", " print(\"This demo requires gmsh to be installed\")\n", " sys.exit(0)\n", "from numpy import pi" ] }, { "cell_type": "code", "execution_count": null, "id": "807a3b86", "metadata": {}, "outputs": [], "source": [ "from mpi4py import MPI" ] }, { "cell_type": "code", "execution_count": null, "id": "241bf9fd", "metadata": {}, "outputs": [], "source": [ "def generate_mesh_wire(\n", " radius_wire: float, radius_dom: float, in_wire_size: float,\n", " on_wire_size: float, bkg_size: float, boundary_size: float,\n", " au_tag: int, bkg_tag: int, boundary_tag: int):\n", "\n", " gmsh.initialize(sys.argv)\n", " if MPI.COMM_WORLD.rank == 0:\n", "\n", " gmsh.model.add(\"nanowire\")\n", "\n", " # A dummy boundary is added for setting a finer mesh\n", " gmsh.model.occ.addCircle(0.0, 0.0, 0.0, radius_wire * 0.8,\n", " angle1=0.0, angle2=2 * pi, tag=1)\n", " gmsh.model.occ.addCircle(0.0, 0.0, 0.0, radius_wire,\n", " angle1=0, angle2=2 * pi, tag=2)\n", "\n", " # A dummy boundary is added for setting a finer mesh\n", " gmsh.model.occ.addCircle(0.0, 0.0, 0.0, radius_dom * 0.9,\n", " angle1=0.0, angle2=2 * pi, tag=3)\n", " gmsh.model.occ.addCircle(\n", " 0.0, 0.0, 0.0, radius_dom, angle1=0.0, angle2=2 * pi, tag=4)\n", "\n", " gmsh.model.occ.addCurveLoop([1], tag=1)\n", " gmsh.model.occ.addPlaneSurface([1], tag=1)\n", "\n", " gmsh.model.occ.addCurveLoop([2], tag=2)\n", " gmsh.model.occ.addCurveLoop([1], tag=3)\n", " gmsh.model.occ.addPlaneSurface([2, 3], tag=2)\n", "\n", " gmsh.model.occ.addCurveLoop([3], tag=4)\n", " gmsh.model.occ.addCurveLoop([2], tag=5)\n", " gmsh.model.occ.addPlaneSurface([4, 5], tag=3)\n", "\n", " gmsh.model.occ.addCurveLoop([4], tag=6)\n", " gmsh.model.occ.addCurveLoop([3], tag=7)\n", " gmsh.model.occ.addPlaneSurface([6, 7], tag=4)\n", "\n", " gmsh.model.occ.synchronize()\n", "\n", " gmsh.model.addPhysicalGroup(2, [1, 2], tag=au_tag)\n", " gmsh.model.addPhysicalGroup(2, [3, 4], tag=bkg_tag)\n", "\n", " gmsh.model.addPhysicalGroup(1, [4], tag=boundary_tag)\n", "\n", " gmsh.model.mesh.setSize([(0, 1)], size=in_wire_size)\n", " gmsh.model.mesh.setSize([(0, 2)], size=on_wire_size)\n", " gmsh.model.mesh.setSize([(0, 3)], size=bkg_size)\n", " gmsh.model.mesh.setSize([(0, 4)], size=boundary_size)\n", "\n", " gmsh.model.mesh.generate(2)\n", "\n", " return gmsh.model" ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:light" }, "kernelspec": { "display_name": "Python 3 (DOLFINx complex)", "language": "python", "name": "python3-complex" }, "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.10.4" } }, "nbformat": 4, "nbformat_minor": 5 }