{ "cells": [ { "cell_type": "markdown", "id": "44cb2edd", "metadata": {}, "source": [ "# Eddy current analysis and reduced matrix" ] }, { "cell_type": "markdown", "id": "645315ce", "metadata": {}, "source": [ "This example shows how to leverage PyAEDT to assign a matrix\n", "and perform series or parallel connections in a Maxwell 2D design.\n", "\n", "Keywords: **Maxwell 2D**, **eddy current**, *matrix**." ] }, { "cell_type": "markdown", "id": "60bc6a20", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "5cd6cd98", "metadata": {}, "outputs": [], "source": [ "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "0b437ad3", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "0dd88963", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "8b77817e", "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": "7a14feed", "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": "f80059f2", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "7f92f462", "metadata": {}, "source": [ "## Download AEDT file\n", "\n", "Set the local temporary folder to export the AEDT file to." ] }, { "cell_type": "code", "execution_count": null, "id": "bc49d0ef", "metadata": {}, "outputs": [], "source": [ "project_path = ansys.aedt.core.downloads.download_file(\n", " source=\"maxwell_ec_reduced_matrix\",\n", " name=\"m2d_eddy_current.aedt\",\n", " destination=temp_folder.name,\n", ")" ] }, { "cell_type": "markdown", "id": "12b067fc", "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": "a7a574d8", "metadata": {}, "outputs": [], "source": [ "m2d = ansys.aedt.core.Maxwell2d(\n", " project=project_path,\n", " version=AEDT_VERSION,\n", " design=\"EC_Planar\",\n", " non_graphical=NG_MODE,\n", ")" ] }, { "cell_type": "markdown", "id": "562dbfec", "metadata": {}, "source": [ "## Assign a matrix\n", "\n", "Assign a matrix given the list of sources to assign the matrix to and the return path." ] }, { "cell_type": "code", "execution_count": null, "id": "9fe80604", "metadata": {}, "outputs": [], "source": [ "matrix = m2d.assign_matrix(\n", " assignment=[\"pri\", \"sec\", \"terz\"], matrix_name=\"Matrix1\", return_path=\"infinite\"\n", ")" ] }, { "cell_type": "markdown", "id": "40ad8e0a", "metadata": {}, "source": [ "## Assign reduced matrices\n", "\n", "Assign reduced matrices to the parent matrix previously created.\n", "For 2D/3D Eddy current solvers, two or more excitations can be joined\n", "either in series or parallel connection. The result is known as a reduced matrix." ] }, { "cell_type": "code", "execution_count": null, "id": "254ed16d", "metadata": {}, "outputs": [], "source": [ "series = matrix.join_series(sources=[\"pri\", \"sec\"], matrix_name=\"ReducedMatrix1\")\n", "parallel = matrix.join_parallel(sources=[\"sec\", \"terz\"], matrix_name=\"ReducedMatrix2\")" ] }, { "cell_type": "markdown", "id": "2d1a7df6", "metadata": {}, "source": [ "## Analyze setup\n", "\n", "Run the analysis." ] }, { "cell_type": "code", "execution_count": null, "id": "fda8242b", "metadata": {}, "outputs": [], "source": [ "m2d.save_project()\n", "m2d.analyze(setup=m2d.setup_names[0], cores=NUM_CORES, use_auto_settings=False)" ] }, { "cell_type": "markdown", "id": "7314431f", "metadata": {}, "source": [ "## Get expressions\n", "\n", "Get the available report quantities given the context\n", "and the quantities category ``L``." ] }, { "cell_type": "code", "execution_count": null, "id": "e30a1109", "metadata": {}, "outputs": [], "source": [ "expressions = m2d.post.available_report_quantities(\n", " report_category=\"EddyCurrent\",\n", " display_type=\"Data Table\",\n", " context={\"Matrix1\": \"ReducedMatrix1\"},\n", " quantities_category=\"L\",\n", ")" ] }, { "cell_type": "markdown", "id": "d52d0125", "metadata": {}, "source": [ "## Create report and get solution data\n", "\n", "Create a data table report and get report data given the matrix context." ] }, { "cell_type": "code", "execution_count": null, "id": "7b128f86", "metadata": {}, "outputs": [], "source": [ "report = m2d.post.create_report(\n", " expressions=expressions,\n", " context={\"Matrix1\": \"ReducedMatrix1\"},\n", " plot_type=\"Data Table\",\n", " setup_sweep_name=\"Setup1 : LastAdaptive\",\n", " plot_name=\"reduced_matrix\",\n", ")\n", "data = m2d.post.get_solution_data(\n", " expressions=expressions,\n", " context={\"Matrix1\": \"ReducedMatrix1\"},\n", " report_category=\"EddyCurrent\",\n", " setup_sweep_name=\"Setup1 : LastAdaptive\",\n", ")" ] }, { "cell_type": "markdown", "id": "c19169be", "metadata": {}, "source": [ "## Get matrix data\n", "\n", "Get inductance results for the join connections in ``nH``." ] }, { "cell_type": "code", "execution_count": null, "id": "d9d3bd3a", "metadata": {}, "outputs": [], "source": [ "ind = ansys.aedt.core.generic.constants.unit_converter(\n", " data.data_magnitude()[0],\n", " unit_system=\"Inductance\",\n", " input_units=data.units_data[expressions[0]],\n", " output_units=\"uH\",\n", ")" ] }, { "cell_type": "markdown", "id": "2f00363d", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "ad287bec", "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": "bf169e7e", "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": "3fcf3462", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }