{ "cells": [ { "cell_type": "markdown", "id": "781687e2", "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": "ff48db42", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "a63f2742", "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": "0978c30d", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "c6aaacc5", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.1\"\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "d17f1408", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "462f6a8a", "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": "5b030d60", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "576d1e46", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "f5f41b6e", "metadata": {}, "source": [ "## Create an empty dictionary to host all configurations." ] }, { "cell_type": "code", "execution_count": null, "id": "0bb08cdb", "metadata": {}, "outputs": [], "source": [ "cfg = dict()" ] }, { "cell_type": "markdown", "id": "e2a01727", "metadata": {}, "source": [ "## Create an SIwave SYZ setup" ] }, { "cell_type": "markdown", "id": "e7938666", "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": "eaff687c", "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": "fb518f48", "metadata": {}, "source": [ "## Create a HFSS setup" ] }, { "cell_type": "markdown", "id": "34d1533a", "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": "ebba9fd9", "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": "074f54cc", "metadata": {}, "source": [ "## Add setups in configuration" ] }, { "cell_type": "code", "execution_count": null, "id": "89a8c78a", "metadata": {}, "outputs": [], "source": [ "cfg[\"setups\"] = [siwave_setup, hfss_setup]" ] }, { "cell_type": "markdown", "id": "23c6f87a", "metadata": {}, "source": [ "## Write configuration into as json file" ] }, { "cell_type": "code", "execution_count": null, "id": "508d3a1f", "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": "ba91e1cf", "metadata": {}, "source": [ "Equivalent toml file looks like below " ] }, { "cell_type": "code", "execution_count": null, "id": "dc25855e", "metadata": {}, "outputs": [], "source": [ "toml_string = toml.dumps(cfg)\n", "print(toml_string)" ] }, { "cell_type": "markdown", "id": "9937b6be", "metadata": {}, "source": [ "## Import configuration into example layout" ] }, { "cell_type": "code", "execution_count": null, "id": "818c9166", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(config_file=file_json)\n", "edbapp.configuration.run()" ] }, { "cell_type": "markdown", "id": "9d4b2e4f", "metadata": {}, "source": [ "## Review" ] }, { "cell_type": "code", "execution_count": null, "id": "058e8bdd", "metadata": {}, "outputs": [], "source": [ "edbapp.setups" ] }, { "cell_type": "markdown", "id": "863988a4", "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": "37e087d3", "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 }