{ "cells": [ { "cell_type": "markdown", "id": "06b253ef", "metadata": {}, "source": [ "# Import Setup AC\n", "This example shows how to import SIwave, HFSS setups for AC analysis. In this example, we are going to\n", "\n", "- Download an example board\n", "- Create a configuration file\n", " - add setups\n", "- Import the configuration file" ] }, { "cell_type": "markdown", "id": "2c423684", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "719e3787", "metadata": {}, "outputs": [], "source": [ "import json\n", "import toml\n", "from pathlib import Path\n", "import tempfile\n", "\n", "from ansys.aedt.core.examples.downloads import download_file\n", "from pyedb import Edb" ] }, { "cell_type": "markdown", "id": "f17c4673", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "cfe7a44c", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.2\"\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "34735259", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "5aa3c287", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")\n", "file_edb = download_file(source=\"edb/ANSYS-HSD_V1.aedb\", local_path=temp_folder.name)" ] }, { "cell_type": "markdown", "id": "bac60558", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "fe7730dc", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "50a5d028", "metadata": {}, "source": [ "## Create an empty dictionary to host all configurations." ] }, { "cell_type": "code", "execution_count": null, "id": "388de9b2", "metadata": {}, "outputs": [], "source": [ "cfg = dict()" ] }, { "cell_type": "markdown", "id": "15c23df4", "metadata": {}, "source": [ "## Create an SIwave SYZ setup" ] }, { "cell_type": "markdown", "id": "7f0d83bc", "metadata": {}, "source": [ "Keywords\n", "\n", "- **name**. Name of the setup.\n", "- **type**. Type of the analysis setup. Supported types are 'siwave_ac', 'siwave_dc', 'hfss'.\n", "- **pi_slider_position**. PI slider position. Supported values are from '0', '1', '2'. 0:speed, 1:balanced,\n", "2:accuracy.\n", "- **freq_sweep**. List of frequency sweeps.\n", " - **name**. Name of the sweep.\n", " - **type**. Type of the sweep. Supported types are 'interpolation', 'discrete', 'broadband'.\n", " - **frequencies**. Frequency distribution.\n", " - **distribution**. Supported distributions are 'linear_count', 'linear_scale', 'log_scale'.\n", " - **start**. Start frequency. Example, 1e6, \"1MHz\".\n", " - **stop**. Stop frequency. Example, 1e9, \"1GHz\".\n", " - **increment**." ] }, { "cell_type": "code", "execution_count": null, "id": "8e03539c", "metadata": {}, "outputs": [], "source": [ "siwave_setup = {\n", " \"name\": \"siwave_1\",\n", " \"type\": \"siwave_ac\",\n", " \"pi_slider_position\": 1,\n", " \"freq_sweep\": [\n", " {\n", " \"name\": \"Sweep1\",\n", " \"type\": \"interpolation\",\n", " \"frequencies\": [{\"distribution\": \"log_scale\", \"start\": 1e6, \"stop\": 1e9, \"increment\": 20}],\n", " }\n", " ],\n", "}" ] }, { "cell_type": "markdown", "id": "8b6cbc0b", "metadata": {}, "source": [ "## Create a HFSS setup" ] }, { "cell_type": "markdown", "id": "183248ca", "metadata": {}, "source": [ "Keywords\n", "\n", "- **name**. Name of the setup.\n", "- **type**. Type of the analysis setup. Supported types are 'siwave_ac', 'siwave_dc', 'hfss'.\n", "- **f_adapt**. Adaptive frequency.\n", "- **max_num_passes**. Maximum number of passes.\n", "- **max_mag_delta_s**. Convergence criteria delta S.\n", "- **mesh_operations**. Mesh operations.\n", " - **name**. Name of the mesh operation.\n", " - **type**. Type of the mesh operation. The supported types are 'base', 'length', 'skin_depth'.\n", " - **max_length**. Maximum length of elements.\n", " - **restrict_length**. Whether to restrict length of elements.\n", " - **refine_inside**. Whether to turn on refine inside objects.\n", " - **nets_layers_list**. {'layer_name':['net_name_1', 'net_name_2']}\n", "- **freq_sweep**. List of frequency sweeps.\n", " - **name**. Name of the sweep.\n", " - **type**. Type of the sweep. Supported types are 'interpolation', 'discrete', 'broadband'.\n", " - **frequencies**. Frequency distribution.\n", " - **distribution**. Supported distributions are 'linear_count', 'linear_scale', 'log_scale'.\n", " - **start**. Start frequency. Example, 1e6, \"1MHz\".\n", " - **stop**. Stop frequency. Example, 1e9, \"1GHz\".\n", " - **increment**." ] }, { "cell_type": "code", "execution_count": null, "id": "7da9420f", "metadata": {}, "outputs": [], "source": [ "hfss_setup = {\n", " \"name\": \"hfss_1\",\n", " \"type\": \"hfss\",\n", " \"f_adapt\": \"5GHz\",\n", " \"max_num_passes\": 10,\n", " \"max_mag_delta_s\": 0.02,\n", " \"mesh_operations\": [\n", " {\n", " \"name\": \"mop_1\",\n", " \"type\": \"length\",\n", " \"max_length\": \"3mm\",\n", " \"restrict_length\": True,\n", " \"refine_inside\": False,\n", " \"nets_layers_list\": {\"GND\": [\"1_Top\", \"16_Bottom\"]},\n", " }\n", " ],\n", " \"freq_sweep\": [\n", " {\n", " \"name\": \"Sweep1\",\n", " \"type\": \"interpolation\",\n", " \"frequencies\": [{\"distribution\": \"log_scale\", \"start\": 1e6, \"stop\": 1e9, \"increment\": 20}],\n", " }\n", " ],\n", "}" ] }, { "cell_type": "markdown", "id": "04462a4f", "metadata": {}, "source": [ "## Add setups in configuration" ] }, { "cell_type": "code", "execution_count": null, "id": "ed561895", "metadata": {}, "outputs": [], "source": [ "cfg[\"setups\"] = [siwave_setup, hfss_setup]" ] }, { "cell_type": "markdown", "id": "90009303", "metadata": {}, "source": [ "## Write configuration into as json file" ] }, { "cell_type": "code", "execution_count": null, "id": "d66444bb", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "file_json = Path(temp_folder.name) / \"edb_configuration.json\"\n", "with open(file_json, \"w\") as f:\n", " json.dump(cfg, f, indent=4, ensure_ascii=False)" ] }, { "cell_type": "markdown", "id": "5982ee87", "metadata": {}, "source": [ "Equivalent toml file looks like below " ] }, { "cell_type": "code", "execution_count": null, "id": "14b15cda", "metadata": {}, "outputs": [], "source": [ "toml_string = toml.dumps(cfg)\n", "print(toml_string)" ] }, { "cell_type": "markdown", "id": "c02a1d2c", "metadata": {}, "source": [ "## Import configuration into example layout" ] }, { "cell_type": "code", "execution_count": null, "id": "9a65ee7d", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(config_file=file_json)\n", "edbapp.configuration.run()" ] }, { "cell_type": "markdown", "id": "609b62ac", "metadata": {}, "source": [ "## Review" ] }, { "cell_type": "code", "execution_count": null, "id": "4657e149", "metadata": {}, "outputs": [], "source": [ "edbapp.setups" ] }, { "cell_type": "markdown", "id": "d2985bbb", "metadata": {}, "source": [ "## Save and close Edb\n", "The temporary folder will be deleted once the execution of this script is finished. Replace **edbapp.save()** with\n", "**edbapp.save_as(\"C:/example.aedb\")** to keep the example project." ] }, { "cell_type": "code", "execution_count": null, "id": "1bd6205e", "metadata": {}, "outputs": [], "source": [ "edbapp.save()\n", "edbapp.close()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }