{ "cells": [ { "cell_type": "markdown", "id": "5ed63800", "metadata": { "papermill": { "duration": 0.003751, "end_time": "2026-05-26T01:20:36.739475+00:00", "exception": false, "start_time": "2026-05-26T01:20:36.735724+00:00", "status": "completed" }, "tags": [] }, "source": [ "### Patch Antenna\n", "We now apply a refined mesh for the patch antenna. Because the electromagnetic fields change rapidly near the metallic patch and the substrate edges, we increase the mesh density in these areas to ensure high simulation accuracy for resonance and radiation patterns." ] }, { "cell_type": "code", "execution_count": 1, "id": "9437354e", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:36.748666Z", "iopub.status.busy": "2026-05-26T01:20:36.748358Z", "iopub.status.idle": "2026-05-26T01:20:37.499637Z", "shell.execute_reply": "2026-05-26T01:20:37.498257Z" }, "papermill": { "duration": 0.757945, "end_time": "2026-05-26T01:20:37.500464+00:00", "exception": false, "start_time": "2026-05-26T01:20:36.742519+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import gmsh\n", "import math\n", "\n", "from palacetoolkit.plot_farfield import load_data, polar_plots, three_d_plot\n", "from palacetoolkit.postpro import s_params\n", "from palacetoolkit.simulation import generate_palace_config_from_entities\n", "from palacetoolkit.viz import view_mesh\n", "from palacetoolkit.mesh import (\n", " Entity, \n", " run_meshing_pipeline, \n", " generate_3d_mesh, \n", " refine_near_surfaces\n", ")" ] }, { "cell_type": "markdown", "id": "1d956d7d", "metadata": { "papermill": { "duration": 0.002165, "end_time": "2026-05-26T01:20:37.505287+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.503122+00:00", "status": "completed" }, "tags": [] }, "source": [ "\n", "### Parameters:\n", "- l : Patch length along x-axis, specified as a scalar in meters.\n", "- w : Patch width along y-axis, specified as a scalar in meters.\n", "- h : Patch height along z-axis, specified as a scalar in meters. \n", "- l1 : Ground plane length along x-axis, specified as a scalar in meters\n", "- w1 : Ground plane width along y-axis, specified as a scalar in meters\n", "- l2 : Notch length along x-axis, specified as a scalar in meters. \n", "- w2 : Notch width along x-axis, specified as a scalar in meters. \n", "- w3 : Strip line width along y-axis, specified as a scalar in meters.\n", "- airsphere_radius : Air sphere radius, specified as a scalar in meters.\n", "- freq : Simulation frequency in GHz, specified as a scalar.\n", "- filename : Output mesh filename, specified as a string.\n", "- eps_r: relative permittivity of the substrate\n", "- loss_tan: loss tangent of the substrate\n", "- port_impedance: characteristic impedance of the lumped port (Ohms)" ] }, { "cell_type": "code", "execution_count": 2, "id": "4049c4db", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:37.511184Z", "iopub.status.busy": "2026-05-26T01:20:37.510704Z", "iopub.status.idle": "2026-05-26T01:20:37.516809Z", "shell.execute_reply": "2026-05-26T01:20:37.515100Z" }, "papermill": { "duration": 0.010912, "end_time": "2026-05-26T01:20:37.518361+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.507449+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Patch\n", "l: float = 0.030\n", "w: float = 0.029\n", "\n", "# Ground plane\n", "l1: float = 0.06\n", "w1: float = 0.06\n", "\n", "# Notch\n", "l2: float = 0.008\n", "w2: float = 0.003\n", "\n", "# Feed line\n", "w3: float = 0.002\n", "\n", "# Substrate\n", "h: float = 0.0013\n", "\n", "freq: float = 3.3\n", "eps_r: float = 2.2\n", "loss_tan: float = 0.0009\n", "mu_r = 1.0\n", "port_impedance: float = 50.0\n", "wavelength = 3e8 / (freq * 1e9)\n", "\n", "# Air sphere\n", "airsphere_radius: float = wavelength\n", "\n", "# Filename where the mesh is loadeds\n", "filename = \"patch_antenna.msh\"" ] }, { "cell_type": "markdown", "id": "6d496609", "metadata": { "papermill": { "duration": 0.002318, "end_time": "2026-05-26T01:20:37.523808+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.521490+00:00", "status": "completed" }, "tags": [] }, "source": [ "### Initialize the model" ] }, { "cell_type": "code", "execution_count": 3, "id": "e6a08089", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:37.530284Z", "iopub.status.busy": "2026-05-26T01:20:37.530065Z", "iopub.status.idle": "2026-05-26T01:20:37.535981Z", "shell.execute_reply": "2026-05-26T01:20:37.534750Z" }, "papermill": { "duration": 0.0107, "end_time": "2026-05-26T01:20:37.536897+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.526197+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "gmsh.initialize()\n", "gmsh.model.add(\"patch_antenna\")\n", "kernel = gmsh.model.occ" ] }, { "cell_type": "markdown", "id": "783686ab", "metadata": { "papermill": { "duration": 0.002164, "end_time": "2026-05-26T01:20:37.541629+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.539465+00:00", "status": "completed" }, "tags": [] }, "source": [ "### Geometry Construction\n", "In this step, we build the physical structure of the patch antenna. We define the substrate, the metallic ground plane, and the antenna patch itself.\n", "\n", "Patch Design: We combine the main patch and the feed line, including an inset to help with impedance matching.\n", "Excitation: A lumped port is created and positioned to feed the antenna.\n", "Domain Setup: We enclose the entire structure in an \"air sphere,\" which defines the simulation region (the radiation space).\n", "Finalizing: We use boolean operations (fragmenting) to ensure all components are properly connected and recognized as a single cohesive model by the solver." ] }, { "cell_type": "code", "execution_count": 4, "id": "474cc986", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:37.548181Z", "iopub.status.busy": "2026-05-26T01:20:37.547931Z", "iopub.status.idle": "2026-05-26T01:20:37.562115Z", "shell.execute_reply": "2026-05-26T01:20:37.560500Z" }, "papermill": { "duration": 0.018833, "end_time": "2026-05-26T01:20:37.563257+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.544424+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Info : Cannot bind existing OpenCASCADE surface 8 to second tag 9 \n", "Info : Could not preserve tag of 2D object 9 (->8)\n" ] } ], "source": [ "substrate = kernel.addBox(-l1/2, -w1/2, 0, l1, w1, h)\n", "\n", "# Ground plane\n", "ground_plane = kernel.addRectangle(-l1/2, -w1/2, 0, l1, w1)\n", "\n", "# Patch definition\n", "main_patch = kernel.addRectangle(-l/2, -w/2, h, l, w)\n", "inset = kernel.addRectangle(-l/2, -w2/2, h, l2, w2)\n", "\n", "patch_dimtags, _ = kernel.cut(\n", " [(2, main_patch)], \n", " [(2, inset)], \n", " removeObject=True, removeTool=True\n", ")\n", "kernel.synchronize()\n", "\n", "feed_length = (l1 - l)/2 + l2\n", "feed_line = kernel.addRectangle(-l1/2, -w3/2, h, feed_length, w3)\n", "\n", "# Our patch\n", "top_conductor, _ = kernel.fuse(\n", " patch_dimtags, [(2, feed_line)],\n", " removeObject=True, removeTool=True\n", ")\n", "kernel.synchronize()\n", "\n", "# Gap bewteen the gropund plane and the bottom of the lumped port.\n", "lumped_port = kernel.addRectangle(-l1/2, -w3/2, 0, h, w3)\n", "kernel.rotate([(2, lumped_port)], -l1/2, 0, 0, 0, 1, 0, -math.pi/2)\n", "kernel.synchronize()\n", "\n", "def create_air_sphere(airsphere_radius: float) -> int:\n", " return kernel.addSphere(0.0, 0.0, 0.0, airsphere_radius)\n", "\n", "air_sphere = create_air_sphere(airsphere_radius)\n", "kernel.synchronize()" ] }, { "cell_type": "markdown", "id": "12cb1ff3", "metadata": { "papermill": { "duration": 0.003324, "end_time": "2026-05-26T01:20:37.570657+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.567333+00:00", "status": "completed" }, "tags": [] }, "source": [ "### Entities definition and mesh refinement." ] }, { "cell_type": "code", "execution_count": 5, "id": "fdbadb7b", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:37.579929Z", "iopub.status.busy": "2026-05-26T01:20:37.579710Z", "iopub.status.idle": "2026-05-26T01:20:45.096905Z", "shell.execute_reply": "2026-05-26T01:20:45.095130Z" }, "papermill": { "duration": 7.521963, "end_time": "2026-05-26T01:20:45.097904+00:00", "exception": false, "start_time": "2026-05-26T01:20:37.575941+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Physical group 'air_sphere' (dim=3): pg=1, tags=[2] \n", " Physical group 'substrate' (dim=3): pg=2, tags=[1]\n", " Physical group 'top_conductor' (dim=2): pg=3, tags=[8]\n", " Physical group 'ground_plane' (dim=2): pg=4, tags=[7]\n", " Physical group 'lumped_port' (dim=2): pg=5, tags=[9]\n", " Physical group 'air_sphere__None' (dim=2): pg=6, tags=[16]\n", " Physical group 'air_sphere__substrate' (dim=2): pg=7, tags=[10, 11, 13, 15, 14, 12]\n", " ppw_near=400 ppw_far=5\n", " SizeMax=0.0182 transition=0.0227\n", " global: 15 curves, SizeMin=0.0002\n", "Info : Meshing 1D...\n", "Info : [ 0%] Meshing curve 45 (Line)\n", "Info : [ 10%] Meshing curve 46 (Line)\n", "Info : [ 10%] Meshing curve 47 (Line)\n", "Info : [ 10%] Meshing curve 48 (Line)\n", "Info : [ 20%] Meshing curve 49 (Line)\n", "Info : [ 20%] Meshing curve 50 (Line)\n", "Info : [ 20%] Meshing curve 51 (Line)\n", "Info : [ 30%] Meshing curve 52 (Line)\n", "Info : [ 30%] Meshing curve 53 (Line)\n", "Info : [ 30%] Meshing curve 54 (Line)\n", "Info : [ 40%] Meshing curve 55 (Line)\n", "Info : [ 40%] Meshing curve 56 (Line)\n", "Info : [ 40%] Meshing curve 57 (Line)\n", "Info : [ 50%] Meshing curve 58 (Line)\n", "Info : [ 50%] Meshing curve 59 (Line)\n", "Info : [ 50%] Meshing curve 60 (Line)\n", "Info : [ 60%] Meshing curve 61 (Line)\n", "Info : [ 60%] Meshing curve 62 (Line)\n", "Info : [ 60%] Meshing curve 63 (Line)\n", "Info : [ 60%] Meshing curve 64 (Line)\n", "Info : [ 70%] Meshing curve 65 (Line)\n", "Info : [ 70%] Meshing curve 66 (Line)\n", "Info : [ 70%] Meshing curve 67 (Line)\n", "Info : [ 80%] Meshing curve 68 (Line)\n", "Info : [ 80%] Meshing curve 69 (Line)\n", "Info : [ 80%] Meshing curve 70 (Line)\n", "Info : [ 90%] Meshing curve 71 (Line)\n", "Info : [ 90%] Meshing curve 72 (Line)\n", "Info : [100%] Meshing curve 74 (Circle)\n", "Info : [100%] Meshing curve 76 (Line)\n", "Info : Done meshing 1D (Wall 0.236431s, CPU 0.227489s)\n", "Info : Meshing 2D...\n", "Info : [ 0%] Meshing surface 7 (Plane, MeshAdapt)\n", "Info : [ 20%] Meshing surface 8 (Plane, MeshAdapt)\n", "Info : [ 30%] Meshing surface 9 (Plane, MeshAdapt)\n", "Info : [ 40%] Meshing surface 10 (Plane, MeshAdapt)\n", "Info : [ 50%] Meshing surface 11 (Plane, MeshAdapt)\n", "Info : [ 60%] Meshing surface 12 (Plane, MeshAdapt)\n", "Info : [ 70%] Meshing surface 13 (Plane, MeshAdapt)\n", "Info : [ 80%] Meshing surface 14 (Plane, MeshAdapt)\n", "Info : [ 90%] Meshing surface 15 (Plane, MeshAdapt)\n", "Info : [100%] Meshing surface 16 (Sphere, MeshAdapt)\n", "Info : Done meshing 2D (Wall 0.373643s, CPU 0.371467s)\n", "Info : Meshing 3D...\n", "Info : 3D Meshing 2 volumes with 1 connected component\n", "Info : Tetrahedrizing 3397 nodes...\n", "Info : Done tetrahedrizing 3405 nodes (Wall 0.0230094s, CPU 0.023024s)\n", "Info : Reconstructing mesh...\n", "Info : - Creating surface mesh\n", "Info : - Identifying boundary edges\n", "Info : - Recovering boundary\n", "Info : Done reconstructing mesh (Wall 0.0450368s, CPU 0.044711s)\n", "Info : Found volume 2\n", "Info : Found volume 1\n", "Info : It. 0 - 0 nodes created - worst tet radius 11.0285 (nodes removed 0 0)\n", "Info : It. 500 - 500 nodes created - worst tet radius 1.43714 (nodes removed 0 0)\n", "Info : It. 1000 - 1000 nodes created - worst tet radius 1.17669 (nodes removed 0 0)\n", "Info : It. 1500 - 1500 nodes created - worst tet radius 1.03815 (nodes removed 0 0)\n", "Info : 3D refinement terminated (5056 nodes total):\n", "Info : - 1 Delaunay cavities modified for star shapeness\n", "Info : - 0 nodes could not be inserted\n", "Info : - 28108 tetrahedra created in 0.102852 sec. (273286 tets/s)\n", "Info : 0 node relocations\n", "Info : Done meshing 3D (Wall 0.196644s, CPU 0.196658s)\n", "Info : Optimizing mesh...\n", "Info : Optimizing volume 1\n", "Info : Optimization starts (volume = 4.68e-06) with worst = 0.00812265 / average = 0.606544:\n", "Info : 0.00 < quality < 0.10 : 32 elements\n", "Info : 0.10 < quality < 0.20 : 103 elements\n", "Info : 0.20 < quality < 0.30 : 252 elements\n", "Info : 0.30 < quality < 0.40 : 666 elements\n", "Info : 0.40 < quality < 0.50 : 1737 elements\n", "Info : 0.50 < quality < 0.60 : 2185 elements\n", "Info : 0.60 < quality < 0.70 : 2006 elements\n", "Info : 0.70 < quality < 0.80 : 1616 elements\n", "Info : 0.80 < quality < 0.90 : 1061 elements\n", "Info : 0.90 < quality < 1.00 : 416 elements\n", "Info : 289 edge swaps, 11 node relocations (volume = 4.68e-06): worst = 0.146028 / average = 0.618471 (Wall 0.0025048s, CPU 0.002533s)\n", "Info : 304 edge swaps, 15 node relocations (volume = 4.68e-06): worst = 0.158684 / average = 0.618763 (Wall 0.00341546s, CPU 0.003466s)\n", "Info : 308 edge swaps, 17 node relocations (volume = 4.68e-06): worst = 0.158684 / average = 0.61881 (Wall 0.00427831s, CPU 0.00435s)\n", "Info : No ill-shaped tets in the mesh :-)\n", "Info : 0.00 < quality < 0.10 : 0 elements\n", "Info : 0.10 < quality < 0.20 : 6 elements\n", "Info : 0.20 < quality < 0.30 : 84 elements\n", "Info : 0.30 < quality < 0.40 : 712 elements\n", "Info : 0.40 < quality < 0.50 : 1706 elements\n", "Info : 0.50 < quality < 0.60 : 2169 elements\n", "Info : 0.60 < quality < 0.70 : 2023 elements\n", "Info : 0.70 < quality < 0.80 : 1631 elements\n", "Info : 0.80 < quality < 0.90 : 1092 elements\n", "Info : 0.90 < quality < 1.00 : 409 elements\n", "Info : Optimizing volume 2\n", "Info : Optimization starts (volume = 0.00309809) with worst = 0.0111154 / average = 0.620966:\n", "Info : 0.00 < quality < 0.10 : 76 elements\n", "Info : 0.10 < quality < 0.20 : 294 elements\n", "Info : 0.20 < quality < 0.30 : 433 elements\n", "Info : 0.30 < quality < 0.40 : 1064 elements\n", "Info : 0.40 < quality < 0.50 : 2553 elements\n", "Info : 0.50 < quality < 0.60 : 3613 elements\n", "Info : 0.60 < quality < 0.70 : 3699 elements\n", "Info : 0.70 < quality < 0.80 : 3145 elements\n", "Info : 0.80 < quality < 0.90 : 2391 elements\n", "Info : 0.90 < quality < 1.00 : 766 elements\n", "Info : 673 edge swaps, 61 node relocations (volume = 0.00309809): worst = 0.0962665 / average = 0.637204 (Wall 0.00600244s, CPU 0.006037s)\n", "Info : 708 edge swaps, 74 node relocations (volume = 0.00309809): worst = 0.0962665 / average = 0.637422 (Wall 0.00803917s, CPU 0.00811s)\n", "Info : No ill-shaped tets in the mesh :-)\n", "Info : 0.00 < quality < 0.10 : 1 elements\n", "Info : 0.10 < quality < 0.20 : 33 elements\n", "Info : 0.20 < quality < 0.30 : 47 elements\n", "Info : 0.30 < quality < 0.40 : 1146 elements\n", "Info : 0.40 < quality < 0.50 : 2503 elements\n", "Info : 0.50 < quality < 0.60 : 3605 elements\n", "Info : 0.60 < quality < 0.70 : 3723 elements\n", "Info : 0.70 < quality < 0.80 : 3189 elements\n", "Info : 0.80 < quality < 0.90 : 2405 elements\n", "Info : 0.90 < quality < 1.00 : 769 elements\n", "Info : Done optimizing mesh (Wall 0.0239096s, CPU 0.024129s)\n", "Info : 5056 nodes 35023 elements\n", "Info : Optimizing mesh (Netgen)...\n", "Info : Optimizing volume 1\n", "Info : CalcLocalH: 3265 Points 9839 Elements 5952 Surface Elements \n", "Info : Remove Illegal Elements \n", "Info : 188 illegal tets \n", "Info : SplitImprove \n", "Info : badmax = 193.075 \n", "Info : 25 splits performed \n", "Info : SwapImprove \n", "Info : 23 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : 150 illegal tets \n", "Info : SplitImprove \n", "Info : badmax = 193.075 \n", "Info : 29 splits performed \n", "Info : SwapImprove \n", "Info : 9 swaps performed \n", "Info : SwapImprove2 \n", "Info : 3 swaps performed \n", "Info : 86 illegal tets \n", "Info : SplitImprove \n", "Info : badmax = 3349.48 \n", "Info : 24 splits performed \n", "Info : SwapImprove \n", "Info : 5 swaps performed \n", "Info : SwapImprove2 \n", "Info : 2 swaps performed \n", "Info : 26 illegal tets \n", "Info : SplitImprove \n", "Info : badmax = 1865.02 \n", "Info : 9 splits performed \n", "Info : SwapImprove \n", "Info : 2 swaps performed \n", "Info : SwapImprove2 \n", "Info : 1 swaps performed \n", "Info : 8 illegal tets \n", "Info : SplitImprove \n", "Info : badmax = 411.944 \n", "Info : 3 splits performed \n", "Info : SwapImprove \n", "Info : 0 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : 0 illegal tets \n", "Info : Volume Optimization \n", "Info : CombineImprove \n", "Info : 27 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 21659.3 \n", "Info : Total badness = 19580.3 \n", "Info : SplitImprove \n", "Info : badmax = 135.164 \n", "Info : 1 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 19588.1 \n", "Info : Total badness = 19505.8 \n", "Info : SwapImprove \n", "Info : 477 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 18595.8 \n", "Info : Total badness = 18407.6 \n", "Info : CombineImprove \n", "Info : 1 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 18398 \n", "Info : Total badness = 18389.7 \n", "Info : SplitImprove \n", "Info : badmax = 85.9383 \n", "Info : 2 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 18404.5 \n", "Info : Total badness = 18403.9 \n", "Info : SwapImprove \n", "Info : 124 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 18282.4 \n", "Info : Total badness = 18197.2 \n", "Info : CombineImprove \n", "Info : 2 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 18166.1 \n", "Info : Total badness = 18161 \n", "Info : SplitImprove \n", "Info : badmax = 85.934 \n", "Info : 0 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 18161 \n", "Info : Total badness = 18160.6 \n", "Info : SwapImprove \n", "Info : 50 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 18098.4 \n", "Info : Total badness = 18061.9 \n", "Info : Optimizing volume 2\n", "Info : CalcLocalH: 4769 Points 17490 Elements 6786 Surface Elements \n", "Info : Remove Illegal Elements \n", "Info : 0 illegal tets \n", "Info : Volume Optimization \n", "Info : CombineImprove \n", "Info : 27 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 33185.9 \n", "Info : Total badness = 29557.2 \n", "Info : SplitImprove \n", "Info : badmax = 107.923 \n", "Info : 4 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 29588.9 \n", "Info : Total badness = 29195.3 \n", "Info : SwapImprove \n", "Info : 934 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 27513.4 \n", "Info : Total badness = 26943.9 \n", "Info : CombineImprove \n", "Info : 3 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 26896.8 \n", "Info : Total badness = 26860.6 \n", "Info : SplitImprove \n", "Info : badmax = 64.8656 \n", "Info : 1 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 26867.1 \n", "Info : Total badness = 26859.8 \n", "Info : SwapImprove \n", "Info : 280 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 26625.8 \n", "Info : Total badness = 26454.3 \n", "Info : CombineImprove \n", "Info : 0 elements combined \n", "Info : ImproveMesh \n", "Info : Total badness = 26454.3 \n", "Info : Total badness = 26446.7 \n", "Info : SplitImprove \n", "Info : badmax = 60.9791 \n", "Info : 0 splits performed \n", "Info : ImproveMesh \n", "Info : Total badness = 26446.7 \n", "Info : Total badness = 26445.9 \n", "Info : SwapImprove \n", "Info : 105 swaps performed \n", "Info : SwapImprove2 \n", "Info : 0 swaps performed \n", "Info : ImproveMesh \n", "Info : Total badness = 26368.2 \n", "Info : Total badness = 26301.2 \n", "Info : Done optimizing mesh (Wall 0.859175s, CPU 0.860999s)\n", "Info : Writing 'patch_antenna.msh'...\n", "Mesh saved to patch_antenna.mshInfo : Done writing 'patch_antenna.msh'\n", "\n", " Nodes: 5094\n", " Elements: 34488\n", "Info : Writing 'patch_antenna.msh'...\n", "Info : Done writing 'patch_antenna.msh'\n" ] } ], "source": [ "# Define the entities which later will become the physical groups.\n", "entities = [\n", " Entity(\"air_sphere\", dim = 3, mesh_order = 2, btype = \"dielectric\", tags = [air_sphere], loss_tan = 0.0, eps_r = 1.0, mu_r = 1.0),\n", " Entity(\"substrate\", dim = 3, mesh_order = 1, btype = \"dielectric\", tags = [substrate], loss_tan = loss_tan, eps_r = eps_r, mu_r = mu_r),\n", " Entity(\"top_conductor\", dim = 2, mesh_order= 1, btype = \"pec\", tags = [top_conductor[0][1]]),\n", " Entity(\"ground_plane\", dim = 2, mesh_order = 1, btype = \"pec\", tags = [ground_plane]),\n", " Entity(\"lumped_port\", dim = 2, mesh_order = 0, btype = \"lumped_port\", tags = [lumped_port], R = port_impedance, direction = '+Z', excitation = True)\n", "]\n", "\n", "# Boolean operations to guarantee a nice mesh, algo it returns the\n", "# physical group map.\n", "pg_map = run_meshing_pipeline(entities)\n", "\n", "# Refine near the top conductor and locally the lumped port\n", "refine_near_surfaces(entities[2].dimtags + entities[-1].dimtags, \n", " wavelength, \n", " ppw_near=400, \n", " ppw_far=5, \n", " transition_distance=wavelength/4,\n", " set_as_background=True)\n", "\n", "# # Mesh sizes\n", "# mesh_sizes = {\n", "# \"substrate\": wavelength / 12,\n", "# \"air_sphere\": wavelength / 4,\n", "# \"lumped_port\": wavelength / 150,\n", "# \"ground_plane\" : wavelength / 10,\n", "# \"top_conductor\": wavelength / 50\n", "# }\n", "\n", "generate_3d_mesh(entities, output_file=filename, optimize=True)\n", "gmsh.option.setNumber(\"Mesh.MshFileVersion\", 2.2)\n", "gmsh.write(filename)\n", "gmsh.finalize()" ] }, { "cell_type": "markdown", "id": "a77751bc", "metadata": { "papermill": { "duration": 0.00395, "end_time": "2026-05-26T01:20:45.106818+00:00", "exception": false, "start_time": "2026-05-26T01:20:45.102868+00:00", "status": "completed" }, "tags": [] }, "source": [ "### Mesh visualization" ] }, { "cell_type": "code", "execution_count": 6, "id": "3c212d13", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:20:45.116938Z", "iopub.status.busy": "2026-05-26T01:20:45.116647Z", "iopub.status.idle": "2026-05-26T01:20:46.530121Z", "shell.execute_reply": "2026-05-26T01:20:46.528653Z" }, "papermill": { "duration": 1.42018, "end_time": "2026-05-26T01:20:46.531281+00:00", "exception": false, "start_time": "2026-05-26T01:20:45.111101+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading mesh file: patch_antenna.msh\n", "Groups to render transparent: air_sphere__None\n", "\n", "Mesh loaded successfully with 2 cell blocks\n", "Found 6786 triangles total\n", "Physical group tags in mesh: {3: 'top_conductor', 4: 'ground_plane', 5: 'lumped_port', 6: 'air_sphere__None', 7: 'air_sphere__substrate'}\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "