{ "cells": [ { "cell_type": "markdown", "id": "c68560fe", "metadata": {}, "source": [ "# Transformer" ] }, { "cell_type": "markdown", "id": "f499c58c", "metadata": {}, "source": [ "This example shows how to use PyAEDT to set core loss given a set\n", "of power-volume [kw/m^3] curves at different frequencies.\n", "\n", "Keywords: **Maxwell 3D**, **Transformer**." ] }, { "cell_type": "markdown", "id": "d0804f41", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "98899c45", "metadata": {}, "outputs": [], "source": [ "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "b4c35455", "metadata": {}, "outputs": [], "source": [ "from ansys.aedt.core import Maxwell3d, downloads\n", "from ansys.aedt.core.generic.constants import unit_converter\n", "from ansys.aedt.core.generic.general_methods import read_csv_pandas" ] }, { "cell_type": "markdown", "id": "8e9d67aa", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "e8c066ab", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "f89aea5a", "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": "3d504088", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "2937d2f2", "metadata": {}, "source": [ "## Download AEDT file example\n", "\n", "Download the files required to run this example to the temporary working folder." ] }, { "cell_type": "code", "execution_count": null, "id": "51556dff", "metadata": {}, "outputs": [], "source": [ "aedt_file = downloads.download_file(\n", " source=\"core_loss_transformer\",\n", " name=\"Ex2-PlanarTransformer_2023R2.aedtz\",\n", " destination=temp_folder.name,\n", ")\n", "freq_curve_csv_25kHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_25kHz.csv\", destination=temp_folder.name\n", ")\n", "freq_curve_csv_100kHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_100kHz.csv\", destination=temp_folder.name\n", ")\n", "freq_curve_csv_200kHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_200kHz.csv\", destination=temp_folder.name\n", ")\n", "freq_curve_csv_400kHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_400kHz.csv\", destination=temp_folder.name\n", ")\n", "freq_curve_csv_700kHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_700kHz.csv\", destination=temp_folder.name\n", ")\n", "freq_curve_csv_1MHz = downloads.download_file(\n", " source=\"core_loss_transformer\", name=\"mf3_1MHz.csv\", destination=temp_folder.name\n", ")\n", "\n", "data = read_csv_pandas(input_file=freq_curve_csv_25kHz)\n", "curves_csv_25kHz = list(zip(data[data.columns[0]], data[data.columns[1]]))\n", "data = read_csv_pandas(input_file=freq_curve_csv_100kHz)\n", "curves_csv_100kHz = list(zip(data[data.columns[0]], data[data.columns[1]]))\n", "data = read_csv_pandas(input_file=freq_curve_csv_200kHz)\n", "curves_csv_200kHz = list(zip(data[data.columns[0]], data[data.columns[1]]))\n", "data = read_csv_pandas(input_file=freq_curve_csv_400kHz)\n", "curves_csv_400kHz = list(zip(data[data.columns[0]], data[data.columns[1]]))\n", "data = read_csv_pandas(input_file=freq_curve_csv_700kHz)\n", "curves_csv_700kHz = list(zip(data[data.columns[0]], data[data.columns[1]]))\n", "data = read_csv_pandas(input_file=freq_curve_csv_1MHz)\n", "curves_csv_1MHz = list(zip(data[data.columns[0]], data[data.columns[1]]))" ] }, { "cell_type": "markdown", "id": "9ccd85dd", "metadata": {}, "source": [ "## Launch AEDT and Maxwell 3D\n", "\n", "Create an instance of the ``Maxwell3d`` class named ``m3d`` by providing\n", "the project and design names, the version, and the graphical mode." ] }, { "cell_type": "code", "execution_count": null, "id": "4162f183", "metadata": {}, "outputs": [], "source": [ "m3d = Maxwell3d(\n", " project=aedt_file,\n", " design=\"02_3D eddycurrent_CmXY_for_thermal\",\n", " version=AEDT_VERSION,\n", " new_desktop=True,\n", " non_graphical=False,\n", ")" ] }, { "cell_type": "markdown", "id": "aa1f55c4", "metadata": {}, "source": [ "## Set core loss at frequencies\n", "\n", "Create a new material, create a dictionary of power-volume [kw/m^3] points\n", "for a set of frequencies retrieved from datasheet provided by a supplier,\n", "and finally set the Power-Ferrite core loss model." ] }, { "cell_type": "code", "execution_count": null, "id": "78135c78", "metadata": {}, "outputs": [], "source": [ "mat = m3d.materials.add_material(\"newmat\")\n", "freq_25kHz = unit_converter(\n", " values=25, unit_system=\"Freq\", input_units=\"kHz\", output_units=\"Hz\"\n", ")\n", "freq_100kHz = unit_converter(\n", " values=100, unit_system=\"Freq\", input_units=\"kHz\", output_units=\"Hz\"\n", ")\n", "freq_200kHz = unit_converter(\n", " values=200, unit_system=\"Freq\", input_units=\"kHz\", output_units=\"Hz\"\n", ")\n", "freq_400kHz = unit_converter(\n", " values=400, unit_system=\"Freq\", input_units=\"kHz\", output_units=\"Hz\"\n", ")\n", "freq_700kHz = unit_converter(\n", " values=700, unit_system=\"Freq\", input_units=\"kHz\", output_units=\"Hz\"\n", ")\n", "pv = {\n", " freq_25kHz: curves_csv_25kHz,\n", " freq_100kHz: curves_csv_100kHz,\n", " freq_200kHz: curves_csv_200kHz,\n", " freq_400kHz: curves_csv_400kHz,\n", " freq_700kHz: curves_csv_700kHz,\n", "}\n", "m3d.materials[mat.name].set_coreloss_at_frequency(\n", " points_at_frequency=pv,\n", " coefficient_setup=\"kw_per_cubic_meter\",\n", " core_loss_model_type=\"Power Ferrite\",\n", ")\n", "coefficients = m3d.materials[mat.name].get_core_loss_coefficients(\n", " points_at_frequency=pv, coefficient_setup=\"kw_per_cubic_meter\"\n", ")" ] }, { "cell_type": "markdown", "id": "6a24931b", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "9c689b3f", "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": "348a74ad", "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": "14ea70e0", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }