{ "cells": [ { "cell_type": "markdown", "id": "a4d7b606", "metadata": {}, "source": [ "# Choke setup\n", "\n", "This example shows how to use PyAEDT to create a choke setup in Maxwell 3D.\n", "\n", "Keywords: **Maxwell 3D**, **choke**." ] }, { "cell_type": "markdown", "id": "22597ada", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "e9623a2a", "metadata": {}, "outputs": [], "source": [ "import json\n", "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "85362730", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "724fd08c", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "529070b2", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "7734d500", "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": "04cb0ae7", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "6e9f30fc", "metadata": {}, "source": [ "## Launch Maxwell3D\n", "\n", "Launch Maxwell 3D 2024 R2 in graphical mode." ] }, { "cell_type": "code", "execution_count": null, "id": "2d4643d9", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"choke.aedt\")\n", "m3d = ansys.aedt.core.Maxwell3d(\n", " project=project_name,\n", " solution_type=\"EddyCurrent\",\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")" ] }, { "cell_type": "markdown", "id": "0500e0a5", "metadata": {}, "source": [ "## Define parameters\n", "\n", "The dictionary values contain the different parameter values of the core and\n", "the windings that compose the choke. You must not change the main structure of\n", "the dictionary. The dictionary has many primary keys, including\n", "``\"Number of Windings\"``, ``\"Layer\"``, and ``\"Layer Type\"``, that have\n", "dictionaries as values. The keys of these dictionaries are secondary keys\n", "of the dictionary values, such as ``\"1\"``, ``\"2\"``, ``\"3\"``, ``\"4\"``, and\n", "``\"Simple\"``.\n", "\n", "You must not modify the primary or secondary keys. You can modify only their values.\n", "You must not change the data types for these keys. For the dictionaries from\n", "``\"Number of Windings\"`` through ``\"Wire Section\"``, values must be Boolean. Only\n", "one value per dictionary can be ``True``. If all values are ``True``, only the first one\n", "remains set to ``True``. If all values are ``False``, the first value is chosen as the\n", "correct one by default. For the dictionaries from ``\"Core\"`` through ``\"Inner Winding\"``,\n", "values must be strings, floats, or integers.\n", "\n", "Descriptions follow for the primary keys:\n", "\n", "- ``\"Number of Windings\"``: Number of windings around the core.\n", "- ``\"Layer\"``: Number of layers of all windings.\n", "- ``\"Layer Type\"``: Whether layers of a winding are linked to each other\n", "- ``\"Similar Layer\"``: Whether layers of a winding have the same number of turns and\n", "same spacing between turns.\n", "- ``\"Mode\"``: When there are only two windows, whether they are in common or differential mode.\n", "- ``\"Wire Section\"``: Type of wire section and number of segments.\n", "- ``\"Core\"``: Design of the core.\n", "- ``\"Outer Winding\"``: Design of the first layer or outer layer of a winding and the common\n", "parameters for all layers.\n", "- ``\"Mid Winding\"``: Turns and turns spacing (``Coil Pit``) for the second or\n", "mid layer if it is necessary.\n", "- ``\"Inner Winding\"``: Turns and turns spacing (``Coil Pit``) for the third or inner\n", "layer if it is necessary.\n", "- ``\"Occupation(%)\"``: An informative parameter that is useless to modify.\n", "\n", "The following parameter values work. You can modify them if you want." ] }, { "cell_type": "code", "execution_count": null, "id": "ce5c90eb", "metadata": {}, "outputs": [], "source": [ "values = {\n", " \"Number of Windings\": {\"1\": False, \"2\": False, \"3\": True, \"4\": False},\n", " \"Layer\": {\"Simple\": False, \"Double\": False, \"Triple\": True},\n", " \"Layer Type\": {\"Separate\": False, \"Linked\": True},\n", " \"Similar Layer\": {\"Similar\": False, \"Different\": True},\n", " \"Mode\": {\"Differential\": True, \"Common\": False},\n", " \"Wire Section\": {\"None\": False, \"Hexagon\": False, \"Octagon\": True, \"Circle\": False},\n", " \"Core\": {\n", " \"Name\": \"Core\",\n", " \"Material\": \"ferrite\",\n", " \"Inner Radius\": 100,\n", " \"Outer Radius\": 143,\n", " \"Height\": 25,\n", " \"Chamfer\": 0.8,\n", " },\n", " \"Outer Winding\": {\n", " \"Name\": \"Winding\",\n", " \"Material\": \"copper\",\n", " \"Inner Radius\": 100,\n", " \"Outer Radius\": 143,\n", " \"Height\": 25,\n", " \"Wire Diameter\": 5,\n", " \"Turns\": 2,\n", " \"Coil Pit(deg)\": 4,\n", " \"Occupation(%)\": 0,\n", " },\n", " \"Mid Winding\": {\"Turns\": 7, \"Coil Pit(deg)\": 4, \"Occupation(%)\": 0},\n", " \"Inner Winding\": {\"Turns\": 10, \"Coil Pit(deg)\": 4, \"Occupation(%)\": 0},\n", "}" ] }, { "cell_type": "markdown", "id": "57dafe9b", "metadata": {}, "source": [ "## Convert dictionary to JSON file\n", "\n", "Convert the dictionary to a JSON file. PyAEDT methods ask for the path of the\n", "JSON file as an argument. You can convert a dictionary to a JSON file." ] }, { "cell_type": "code", "execution_count": null, "id": "9b6bee89", "metadata": {}, "outputs": [], "source": [ "json_path = os.path.join(temp_folder.name, \"choke_example.json\")\n", "\n", "with open(json_path, \"w\") as outfile:\n", " json.dump(values, outfile)" ] }, { "cell_type": "markdown", "id": "d17d69cc", "metadata": {}, "source": [ "## Verify parameters of JSON file\n", "\n", "Verify parameters of the JSON file. The ``check_choke_values()`` method takes\n", "the JSON file path as an argument and does the following:\n", "\n", "- Checks if the JSON file is correctly written (as explained earlier)\n", "- Checks equations on windings parameters to avoid having unintended intersections" ] }, { "cell_type": "code", "execution_count": null, "id": "12fc6c1a", "metadata": {}, "outputs": [], "source": [ "dictionary_values = m3d.modeler.check_choke_values(\n", " input_dir=json_path, create_another_file=False\n", ")\n", "print(dictionary_values)" ] }, { "cell_type": "markdown", "id": "48b57ea1", "metadata": {}, "source": [ "## Create choke\n", "\n", "Create the choke. The ``create_choke()`` method takes the JSON file path as an\n", "argument." ] }, { "cell_type": "code", "execution_count": null, "id": "9f0e9362", "metadata": {}, "outputs": [], "source": [ "list_object = m3d.modeler.create_choke(input_file=json_path)\n", "print(list_object)\n", "core = list_object[1]\n", "first_winding_list = list_object[2]\n", "second_winding_list = list_object[3]\n", "third_winding_list = list_object[4]" ] }, { "cell_type": "markdown", "id": "1ac3a6e4", "metadata": {}, "source": [ "## Assign excitations" ] }, { "cell_type": "code", "execution_count": null, "id": "9dcd0dd5", "metadata": {}, "outputs": [], "source": [ "first_winding_faces = m3d.modeler.get_object_faces(\n", " assignment=first_winding_list[0].name\n", ")\n", "second_winding_faces = m3d.modeler.get_object_faces(\n", " assignment=second_winding_list[0].name\n", ")\n", "third_winding_faces = m3d.modeler.get_object_faces(\n", " assignment=third_winding_list[0].name\n", ")\n", "m3d.assign_current(\n", " assignment=[first_winding_faces[-1]],\n", " amplitude=1000,\n", " phase=\"0deg\",\n", " swap_direction=False,\n", " name=\"phase_1_in\",\n", ")\n", "m3d.assign_current(\n", " assignment=[first_winding_faces[-2]],\n", " amplitude=1000,\n", " phase=\"0deg\",\n", " swap_direction=True,\n", " name=\"phase_1_out\",\n", ")\n", "m3d.assign_current(\n", " assignment=[second_winding_faces[-1]],\n", " amplitude=1000,\n", " phase=\"120deg\",\n", " swap_direction=False,\n", " name=\"phase_2_in\",\n", ")\n", "m3d.assign_current(\n", " assignment=[second_winding_faces[-2]],\n", " amplitude=1000,\n", " phase=\"120deg\",\n", " swap_direction=True,\n", " name=\"phase_2_out\",\n", ")\n", "m3d.assign_current(\n", " assignment=[third_winding_faces[-1]],\n", " amplitude=1000,\n", " phase=\"240deg\",\n", " swap_direction=False,\n", " name=\"phase_3_in\",\n", ")\n", "m3d.assign_current(\n", " assignment=[third_winding_faces[-2]],\n", " amplitude=1000,\n", " phase=\"240deg\",\n", " swap_direction=True,\n", " name=\"phase_3_out\",\n", ")" ] }, { "cell_type": "markdown", "id": "2b51b856", "metadata": {}, "source": [ "## Assign matrix" ] }, { "cell_type": "code", "execution_count": null, "id": "bcc2eb66", "metadata": {}, "outputs": [], "source": [ "m3d.assign_matrix(\n", " assignment=[\"phase_1_in\", \"phase_2_in\", \"phase_3_in\"], matrix_name=\"current_matrix\"\n", ")" ] }, { "cell_type": "markdown", "id": "81845083", "metadata": {}, "source": [ "## Create mesh operation" ] }, { "cell_type": "code", "execution_count": null, "id": "2f77b462", "metadata": {}, "outputs": [], "source": [ "mesh = m3d.mesh\n", "mesh.assign_skin_depth(\n", " assignment=[first_winding_list[0], second_winding_list[0], third_winding_list[0]],\n", " skin_depth=0.20,\n", " triangulation_max_length=\"10mm\",\n", " name=\"skin_depth\",\n", ")\n", "mesh.assign_surface_mesh_manual(\n", " assignment=[first_winding_list[0], second_winding_list[0], third_winding_list[0]],\n", " surface_deviation=None,\n", " normal_dev=\"30deg\",\n", " name=\"surface_approx\",\n", ")" ] }, { "cell_type": "markdown", "id": "270c2c0b", "metadata": {}, "source": [ "## Create boundaries\n", "\n", "Create the boundaries. A region with openings is needed to run the analysis." ] }, { "cell_type": "code", "execution_count": null, "id": "eb3aa989", "metadata": {}, "outputs": [], "source": [ "region = m3d.modeler.create_air_region(\n", " x_pos=100, y_pos=100, z_pos=100, x_neg=100, y_neg=100, z_neg=0\n", ")" ] }, { "cell_type": "markdown", "id": "3241818d", "metadata": {}, "source": [ "## Create setup\n", "\n", "Create a setup with a sweep to run the simulation. Depending on your machine's\n", "computing power, the simulation can take some time to run." ] }, { "cell_type": "code", "execution_count": null, "id": "1837d57b", "metadata": {}, "outputs": [], "source": [ "setup = m3d.create_setup(\"MySetup\")\n", "print(setup.props)\n", "setup.props[\"Frequency\"] = \"100kHz\"\n", "setup.props[\"PercentRefinement\"] = 15\n", "setup.props[\"MaximumPasses\"] = 10\n", "setup.props[\"HasSweepSetup\"] = True\n", "setup.add_eddy_current_sweep(\n", " range_type=\"LinearCount\", start=100, end=1000, count=12, units=\"kHz\", clear=True\n", ")" ] }, { "cell_type": "markdown", "id": "55f2916e", "metadata": {}, "source": [ "## Save project" ] }, { "cell_type": "code", "execution_count": null, "id": "ccf7bcb9", "metadata": {}, "outputs": [], "source": [ "m3d.save_project()\n", "m3d.modeler.fit_all()\n", "m3d.plot(\n", " show=False,\n", " output_file=os.path.join(temp_folder.name, \"Image.jpg\"),\n", " plot_air_objects=True,\n", ")" ] }, { "cell_type": "markdown", "id": "21f49841", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "3bc412db", "metadata": {}, "outputs": [], "source": [ "m3d.save_project()\n", "m3d.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": "e2cd9acc", "metadata": {}, "source": [ "## Clean up\n", "\n", "All project files are saved in the folder ``temp_folder.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": "909ec9cd", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }