{ "cells": [ { "cell_type": "markdown", "id": "2a8f0895", "metadata": {}, "source": [ "# External delta circuit\n", "\n", "This example shows how to create an external delta circuit and connect it with a Maxwell 2D design.\n", "\n", "Keywords: **Maxwell 2D**, **Circuit**, **netlist**" ] }, { "cell_type": "markdown", "id": "38ec6e65", "metadata": {}, "source": [ "## Perform imports and define constants" ] }, { "cell_type": "code", "execution_count": null, "id": "c82a3c74", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "8ae406b4", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "a1a3b745", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "6cc5b1cc", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NUM_CORES = 4\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "325013f3", "metadata": {}, "source": [ "## Create temporary directory\n", "\n", "Create a temporary directory where downloaded data or\n", "dumped data can be stored.\n", "If you'd like to retrieve the project data for subsequent use,\n", "the temporary folder name is given by ``temp_folder.name``." ] }, { "cell_type": "code", "execution_count": null, "id": "0d735bc7", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "111ce36a", "metadata": {}, "source": [ "## Launch AEDT and Maxwell 2D\n", "\n", "Launch AEDT and Maxwell 2D providing the version, path to the project, and the graphical mode." ] }, { "cell_type": "code", "execution_count": null, "id": "d52c83d1", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"Maxwell_circuit_example.aedt\")\n", "design_name = \"1 Maxwell\"\n", "circuit_name = \"2 Delta circuit\"" ] }, { "cell_type": "code", "execution_count": null, "id": "eb8eb28f", "metadata": {}, "outputs": [], "source": [ "m2d = ansys.aedt.core.Maxwell2d(\n", " version=AEDT_VERSION,\n", " new_desktop=False,\n", " design=design_name,\n", " project=project_name,\n", " solution_type=\"TransientXY\",\n", " non_graphical=NG_MODE,\n", ")" ] }, { "cell_type": "markdown", "id": "7a597991", "metadata": {}, "source": [ "## Initialize dictionaries and define variables\n", "\n", "Initialize dictionaries that contain all design variable definitions." ] }, { "cell_type": "code", "execution_count": null, "id": "ae79e3c0", "metadata": {}, "outputs": [], "source": [ "voltage = \"230V\"\n", "frequency = \"50Hz\"" ] }, { "cell_type": "code", "execution_count": null, "id": "8dc2afb0", "metadata": {}, "outputs": [], "source": [ "transient_parameters = {\n", " \"voltage\": voltage,\n", " \"frequency\": frequency,\n", " \"electric_period\": \"1 / frequency s\",\n", " \"stop_time\": \"2 * electric_period s\",\n", " \"time_step\": \"electric_period / 20 s\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "e9f47261", "metadata": {}, "outputs": [], "source": [ "circuit_parameters = {\n", " \"voltage\": voltage,\n", " \"frequency\": frequency,\n", " \"resistance_value\": \"1Ohm\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "7d47384a", "metadata": {}, "outputs": [], "source": [ "for k, v in transient_parameters.items():\n", " m2d[k] = v" ] }, { "cell_type": "markdown", "id": "113d6a16", "metadata": {}, "source": [ "## Create geometry\n", "\n", "Create copper coils and a vacuum region. Assign mesh operations, and then assign a balloon boundary to the region edges." ] }, { "cell_type": "code", "execution_count": null, "id": "a26fb5e3", "metadata": {}, "outputs": [], "source": [ "coil1_id = m2d.modeler.create_circle(\n", " orientation=\"Z\", origin=[0, 0, 0], radius=10, name=\"coil1\", material=\"copper\"\n", ")\n", "coil2_id = m2d.modeler.create_circle(\n", " orientation=\"Z\", origin=[25, 0, 0], radius=10, name=\"coil2\", material=\"copper\"\n", ")\n", "coil3_id = m2d.modeler.create_circle(\n", " orientation=\"Z\", origin=[50, 0, 0], radius=10, name=\"coil3\", material=\"copper\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "31cb3f41", "metadata": {}, "outputs": [], "source": [ "region = m2d.modeler.create_region(pad_value=[200, 400, 200, 400])" ] }, { "cell_type": "code", "execution_count": null, "id": "d9c966fa", "metadata": {}, "outputs": [], "source": [ "m2d.mesh.assign_length_mesh(\n", " assignment=[coil1_id, coil2_id, coil3_id, region], maximum_length=5\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "96c03b1e", "metadata": {}, "outputs": [], "source": [ "m2d.assign_vector_potential(assignment=region.edges, vector_value=0)" ] }, { "cell_type": "markdown", "id": "b55e559a", "metadata": {}, "source": [ "## Assign excitations\n", "\n", "Assign external windings" ] }, { "cell_type": "code", "execution_count": null, "id": "353c4fe9", "metadata": {}, "outputs": [], "source": [ "wdg1 = m2d.assign_winding(\n", " assignment=[\"coil1\"],\n", " is_solid=False,\n", " winding_type=\"External\",\n", " name=\"winding1\",\n", " current=0,\n", ")\n", "wdg2 = m2d.assign_winding(\n", " assignment=[\"coil2\"],\n", " is_solid=False,\n", " winding_type=\"External\",\n", " name=\"winding2\",\n", " current=0,\n", ")\n", "wdg3 = m2d.assign_winding(\n", " assignment=[\"coil3\"],\n", " is_solid=False,\n", " winding_type=\"External\",\n", " name=\"winding3\",\n", " current=0,\n", ")" ] }, { "cell_type": "markdown", "id": "14ff0dd5", "metadata": {}, "source": [ "## Create simulation setup\n", "\n", "Create the simulation setup, defining the stop time and time step." ] }, { "cell_type": "code", "execution_count": null, "id": "db9f4d79", "metadata": {}, "outputs": [], "source": [ "setup = m2d.create_setup()\n", "setup[\"StopTime\"] = \"stop_time\"\n", "setup[\"TimeStep\"] = \"time_step\"" ] }, { "cell_type": "markdown", "id": "78c332d0", "metadata": {}, "source": [ "## Create external circuit\n", "\n", "Create the circuit design, including all windings of type ``External`` in the Maxwell design." ] }, { "cell_type": "code", "execution_count": null, "id": "610c5c47", "metadata": {}, "outputs": [], "source": [ "circuit = m2d.create_external_circuit(circuit_design=circuit_name)" ] }, { "cell_type": "markdown", "id": "cd460412", "metadata": {}, "source": [ "## Define variables from dictionaries\n", "\n", "Define design variables from the created dictionaries." ] }, { "cell_type": "code", "execution_count": null, "id": "a04611e8", "metadata": {}, "outputs": [], "source": [ "for k, v in circuit_parameters.items():\n", " circuit[k] = v" ] }, { "cell_type": "code", "execution_count": null, "id": "fe88fc8a", "metadata": {}, "outputs": [], "source": [ "windings = [\n", " circuit.modeler.schematic.components[k]\n", " for k in list(circuit.modeler.schematic.components.keys())\n", " if circuit.modeler.schematic.components[k].parameters[\"Info\"] == \"Winding\"\n", "]" ] }, { "cell_type": "markdown", "id": "3d66df35", "metadata": {}, "source": [ "## Finalize external circuit\n", "\n", "Draw these other components: resistors, voltage sources, and grounds" ] }, { "cell_type": "code", "execution_count": null, "id": "f3001def", "metadata": {}, "outputs": [], "source": [ "circuit.modeler.schematic_units = \"mil\"" ] }, { "cell_type": "code", "execution_count": null, "id": "e1c685c4", "metadata": {}, "outputs": [], "source": [ "resistors = []\n", "v_sources = []\n", "ground = []" ] }, { "cell_type": "code", "execution_count": null, "id": "bc658eff", "metadata": {}, "outputs": [], "source": [ "for i in range(len(windings)):\n", " r = circuit.modeler.schematic.create_resistor(\n", " name=\"R\" + str(i + 1), value=\"resistance_value\", location=[1000, i * 1000]\n", " )\n", " resistors.append(r)\n", "\n", " v = circuit.modeler.schematic.create_component(\n", " component_library=\"Sources\",\n", " component_name=\"VSin\",\n", " location=[2000, i * 1000],\n", " angle=90,\n", " )\n", " v_sources.append(v)\n", "\n", " v.parameters[\"Va\"] = \"voltage\"\n", " v.parameters[\"VFreq\"] = \"frequency\"\n", " v.parameters[\"Phase\"] = str(i * 120) + \"deg\"\n", "\n", " g = circuit.modeler.schematic.create_gnd([2300, i * 1000], angle=90)\n", " ground.append(g)" ] }, { "cell_type": "markdown", "id": "da8bdd05", "metadata": {}, "source": [ "## Connect components\n", "\n", "Connect the components by drawing wires." ] }, { "cell_type": "code", "execution_count": null, "id": "f7562ef1", "metadata": {}, "outputs": [], "source": [ "windings[2].pins[1].connect_to_component(resistors[2].pins[0], use_wire=True)\n", "windings[1].pins[1].connect_to_component(resistors[1].pins[0], use_wire=True)\n", "windings[0].pins[1].connect_to_component(resistors[0].pins[0], use_wire=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "eb357a7b", "metadata": {}, "outputs": [], "source": [ "resistors[2].pins[1].connect_to_component(v_sources[2].pins[1], use_wire=True)\n", "resistors[1].pins[1].connect_to_component(v_sources[1].pins[1], use_wire=True)\n", "resistors[0].pins[1].connect_to_component(v_sources[0].pins[1], use_wire=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "92c43e70", "metadata": {}, "outputs": [], "source": [ "circuit.modeler.schematic.create_wire(\n", " points=[\n", " resistors[2].pins[1].location,\n", " [1200, 2500],\n", " [-600, 2500],\n", " [-600, 0],\n", " windings[0].pins[0].location,\n", " ]\n", ")\n", "circuit.modeler.schematic.create_wire(\n", " points=[\n", " resistors[1].pins[1].location,\n", " [1200, 1500],\n", " [-300, 1500],\n", " [-300, 2000],\n", " windings[2].pins[0].location,\n", " ]\n", ")\n", "circuit.modeler.schematic.create_wire(\n", " points=[\n", " resistors[0].pins[1].location,\n", " [1200, 500],\n", " [-300, 500],\n", " [-300, 1000],\n", " windings[1].pins[0].location,\n", " ]\n", ")" ] }, { "cell_type": "markdown", "id": "3a26a60b", "metadata": {}, "source": [ "## Export and import netlist\n", "\n", "Export the netlist file and then import it to Maxwell 2D." ] }, { "cell_type": "code", "execution_count": null, "id": "2425041d", "metadata": {}, "outputs": [], "source": [ "netlist_file = os.path.join(temp_folder.name, \"_netlist.sph\")\n", "circuit.export_netlist_from_schematic(netlist_file)" ] }, { "cell_type": "code", "execution_count": null, "id": "14ea6915", "metadata": {}, "outputs": [], "source": [ "m2d.edit_external_circuit(\n", " netlist_file_path=netlist_file, schematic_design_name=circuit_name\n", ")" ] }, { "cell_type": "markdown", "id": "871c732c", "metadata": {}, "source": [ "## Analyze setup\n" ] }, { "cell_type": "code", "execution_count": null, "id": "36e6196b", "metadata": {}, "outputs": [], "source": [ "setup.analyze(cores=NUM_CORES)" ] }, { "cell_type": "markdown", "id": "36adbc15", "metadata": {}, "source": [ "## Create rectangular plot\n", "\n", "Plot winding currents" ] }, { "cell_type": "code", "execution_count": null, "id": "17ec1619", "metadata": {}, "outputs": [], "source": [ "m2d.post.create_report(\n", " expressions=[\"Current(winding1)\", \"Current(winding2)\", \"Current(winding3)\"],\n", " domain=\"Sweep\",\n", " primary_sweep_variable=\"Time\",\n", " plot_name=\"Winding Currents\",\n", ")" ] }, { "cell_type": "markdown", "id": "ef96f7c0", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "3b72ce31", "metadata": {}, "outputs": [], "source": [ "m2d.save_project()\n", "m2d.release_desktop()\n", "# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.\n", "time.sleep(3)" ] }, { "cell_type": "markdown", "id": "da756557", "metadata": {}, "source": [ "## Clean up\n", "\n", "All project files are saved in the folder ``temp_dir.name``.\n", "If you've run this example as a Jupyter notebook, you\n", "can retrieve those project files. The following cell\n", "removes all temporary files, including the project folder." ] }, { "cell_type": "code", "execution_count": null, "id": "86a6bb71", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }