{ "cells": [ { "cell_type": "markdown", "id": "a42e7807", "metadata": { "language": "markdown", "papermill": { "duration": 0.001523, "end_time": "2026-05-26T01:18:07.232726+00:00", "exception": false, "start_time": "2026-05-26T01:18:07.231203+00:00", "status": "completed" }, "tags": [] }, "source": [ "# Dipole Antenna Mesh with PalaceToolkit\n", "\n", "This notebook uses PalaceToolkit utilities with a robust workflow:\n", "- build primitives\n", "- fragment once for conformal topology\n", "- define `Entity` objects from fragmented geometry\n", "- run `run_meshing_pipeline`, refine with `refine_near_surfaces`, then `generate_3d_mesh`\n", "- visualize with `palacetoolkit.viz`\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "906648bd", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:18:07.237177Z", "iopub.status.busy": "2026-05-26T01:18:07.236915Z", "iopub.status.idle": "2026-05-26T01:18:07.973443Z", "shell.execute_reply": "2026-05-26T01:18:07.972087Z" }, "language": "python", "papermill": { "duration": 0.739868, "end_time": "2026-05-26T01:18:07.974228+00:00", "exception": false, "start_time": "2026-05-26T01:18:07.234360+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "from pathlib import Path\n", "import math\n", "import gmsh\n", "\n", "from palacetoolkit.geometry import xmin, xmax, ymin, ymax, zmin, zmax, extract_tag\n", "from palacetoolkit.mesh import Entity, run_meshing_pipeline, generate_3d_mesh, refine_near_surfaces\n", "from palacetoolkit.viz import view_mesh\n", "from palacetoolkit.simulation import generate_palace_config_from_entities, run_palace\n", "from palacetoolkit.verify_topology import verify, print_report, visualise_problems" ] }, { "cell_type": "code", "execution_count": 2, "id": "5b1a7aa6", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:18:07.977853Z", "iopub.status.busy": "2026-05-26T01:18:07.977598Z", "iopub.status.idle": "2026-05-26T01:18:07.982280Z", "shell.execute_reply": "2026-05-26T01:18:07.980915Z" }, "language": "python", "papermill": { "duration": 0.007855, "end_time": "2026-05-26T01:18:07.983582+00:00", "exception": false, "start_time": "2026-05-26T01:18:07.975727+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "wavelength = 4.0\n", "arm_length = wavelength / 4\n", "arm_radius = arm_length / 20\n", "gap_size = arm_length / 50\n", "outer_boundary_radius = 1.5 * wavelength\n", "mesh_file = \"dipole.msh\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "f66556ad", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:18:07.989481Z", "iopub.status.busy": "2026-05-26T01:18:07.989145Z", "iopub.status.idle": "2026-05-26T01:18:39.618599Z", "shell.execute_reply": "2026-05-26T01:18:39.617356Z" }, "language": "python", "papermill": { "duration": 31.634225, "end_time": "2026-05-26T01:18:39.619934+00:00", "exception": false, "start_time": "2026-05-26T01:18:07.985709+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "if gmsh.isInitialized():\n", " gmsh.finalize()\n", "gmsh.initialize()\n", "gmsh.option.setNumber(\"General.Verbosity\", 2)\n", "gmsh.model.add(\"dipole_entity_pipeline\")\n", "occ = gmsh.model.occ\n", "\n", "air = occ.addSphere(0, 0, 0, outer_boundary_radius)\n", "top_arm = occ.addBox(-arm_radius, -arm_radius, gap_size / 2, 2 * arm_radius, 2 * arm_radius, arm_length)\n", "bot_arm = occ.addBox(-arm_radius, -arm_radius, -gap_size / 2 - arm_length, 2 * arm_radius, 2 * arm_radius, arm_length)\n", "port_sheet = occ.addRectangle(-arm_radius, -gap_size / 2, 0, 2 * arm_radius, gap_size)\n", "occ.rotate([(2, port_sheet)], 0, 0, 0, 1, 0, 0, math.pi / 2)\n", "occ.synchronize()" ] }, { "cell_type": "code", "execution_count": 4, "id": "bc7e7def", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Physical group 'air' (dim=3): pg=1, tags=[1]\n", " Physical group 'top_arm' (dim=3): pg=2, tags=[2]\n", " Physical group 'bot_arm' (dim=3): pg=3, tags=[3]\n", " Physical group 'port' (dim=2): pg=4, tags=[14]\n", " Physical group 'air__None' (dim=2): pg=5, tags=[23]\n", " Physical group 'air__bot_arm' (dim=2): pg=6, tags=[19, 10, 21, 22, 11, 12, 20]\n", " Physical group 'air__top_arm' (dim=2): pg=7, tags=[15, 4, 7, 5, 17, 18, 16]\n", " ppw_near=30 ppw_far=5\n", " SizeMax=0.8000 transition=1.0000\n", " global: 7 curves, SizeMin=0.1333\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Warning : Unknown curve 11\n", "Warning : Unknown curve 21\n", "Warning : ------------------------------\n", "Warning : Mesh generation error summary\n", "Warning : 2 warnings\n", "Warning : 0 errors\n", "Warning : Check the full log for details\n", "Warning : ------------------------------\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Mesh saved to dipole.msh\n", " Nodes: 1994\n", " Elements: 10919\n" ] }, { "data": { "text/plain": [ "{'port': 4,\n", " 'air__None': 5,\n", " 'air__bot_arm': 6,\n", " 'air__top_arm': 7,\n", " 'air': 1,\n", " 'top_arm': 2,\n", " 'bot_arm': 3}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Entity + boolean pipeline for named physical groups.\n", "entities = [\n", " Entity(\"air\", dim=3, mesh_order=2, btype=\"dielectric\", tags=[air], loss_tan=0.0, eps_r=1.0, mu_r=1.0),\n", " Entity(\"top_arm\", dim=3, mesh_order=1, btype=\"pec\", tags=[top_arm]),\n", " Entity(\"bot_arm\", dim=3, mesh_order=1, btype=\"pec\", tags=[bot_arm]),\n", " Entity(\"port\", dim=2, mesh_order=0, btype=\"lumped_port\", tags=[port_sheet], R=50.0, direction=\"+Z\", excitation=True),\n", "]\n", "pg_map = run_meshing_pipeline(entities)\n", "\n", "refine_near_surfaces(\n", " entities[2].dimtags,\n", " wavelength,\n", " ppw_near=30,\n", " ppw_far=5,\n", " transition_distance=wavelength / 4,\n", " set_as_background=True\n", ")\n", "\n", "generate_3d_mesh(entities, output_file=mesh_file, optimize=True)\n", "gmsh.finalize()\n", "pg_map" ] }, { "cell_type": "code", "execution_count": 5, "id": "91c6664f", "metadata": { "execution": { "iopub.execute_input": "2026-05-26T01:18:39.623943Z", "iopub.status.busy": "2026-05-26T01:18:39.623738Z", "iopub.status.idle": "2026-05-26T01:18:41.070528Z", "shell.execute_reply": "2026-05-26T01:18:41.069298Z" }, "language": "python", "papermill": { "duration": 1.449963, "end_time": "2026-05-26T01:18:41.071511+00:00", "exception": false, "start_time": "2026-05-26T01:18:39.621548+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading mesh file: dipole.msh\n", "Groups to render transparent: ['air__None']\n", "\n", "Mesh loaded successfully with 2 cell blocks\n", "Found 2006 triangles total\n", "Physical group tags in mesh: {4: 'port', 5: 'air__None', 6: 'air__bot_arm', 7: 'air__top_arm'}\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "