{ "cells": [ { "cell_type": "markdown", "id": "a98e4737", "metadata": {}, "source": [ "# Lorentz actuator\n", "\n", "This example uses PyAEDT to set up a Lorentz actuator\n", "and solve it using the Maxwell 2D transient solver.\n", "\n", "Keywords: **Maxwell2D**, **transient**, **translational motion**, **mechanical transient**" ] }, { "cell_type": "markdown", "id": "22cc8537", "metadata": {}, "source": [ "## Perform imports and define constantss\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "e457ecc7", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "907d67ec", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "5632cb98", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "c405d90f", "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": "4f565a59", "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": "6f845f09", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "c4371423", "metadata": {}, "source": [ "## Initialize dictionaries\n", "\n", "Initialize the following:\n", "\n", "- Electric and geometric parameters for the actuator\n", "- Simulation specifications\n", "- Materials for the actuator component" ] }, { "cell_type": "code", "execution_count": null, "id": "f71e776e", "metadata": {}, "outputs": [], "source": [ "dimensions = {\n", " \"Core_outer_x\": \"100mm\",\n", " \"Core_outer_y\": \"80mm\",\n", " \"Core_thickness\": \"10mm\",\n", " \"Magnet_thickness\": \"10mm\",\n", " \"Coil_width\": \"30mm\",\n", " \"Coil_thickness\": \"5mm\",\n", " \"Coil_inner_diameter\": \"20mm\",\n", " \"Coil_magnet_distance\": \"5mm\",\n", " \"Coil_start_position\": \"3mm\",\n", " \"Band_clearance\": \"1mm\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "41c60661", "metadata": {}, "outputs": [], "source": [ "coil_specifications = {\n", " \"Winding_current\": \"5A\",\n", " \"No_of_turns\": \"100\",\n", " \"Coil_mass\": \"0.2kg\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "ff3a5cc7", "metadata": {}, "outputs": [], "source": [ "simulation_specifications = {\n", " \"Mesh_bands\": \"0.5mm\",\n", " \"Mesh_other_objects\": \"2mm\",\n", " \"Stop_time\": \"10ms\",\n", " \"Time_step\": \"0.5ms\",\n", " \"Save_fields_interval\": \"1\",\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "2aaf6d74", "metadata": {}, "outputs": [], "source": [ "materials = {\n", " \"Coil_material\": \"copper\",\n", " \"Core_material\": \"steel_1008\",\n", " \"Magnet_material\": \"NdFe30\",\n", "}" ] }, { "cell_type": "markdown", "id": "74463137", "metadata": {}, "source": [ "## Launch AEDT and Maxwell 2D\n", "\n", "Launch AEDT and Maxwell 2D after first setting up the project name.\n", "The following code also creates an instance of the\n", "``Maxwell2d`` class named ``m2d`` by providing\n", "the project name, the design name, the solver, the version, and the graphical mode." ] }, { "cell_type": "code", "execution_count": null, "id": "dab570a4", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"Lorentz_actuator.aedt\")\n", "m2d = ansys.aedt.core.Maxwell2d(\n", " project=project_name,\n", " design=\"1 transient 2D\",\n", " solution_type=\"TransientXY\",\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", ")" ] }, { "cell_type": "markdown", "id": "28f18e29", "metadata": {}, "source": [ "## Define variables from dictionaries\n", "\n", "Define design variables from the created dictionaries." ] }, { "cell_type": "code", "execution_count": null, "id": "2048eab0", "metadata": {}, "outputs": [], "source": [ "m2d.variable_manager.set_variable(name=\"Dimensions\")\n", "for k, v in dimensions.items():\n", " m2d[k] = v" ] }, { "cell_type": "code", "execution_count": null, "id": "7f1ad793", "metadata": {}, "outputs": [], "source": [ "m2d.variable_manager.set_variable(name=\"Winding data\")\n", "for k, v in coil_specifications.items():\n", " m2d[k] = v" ] }, { "cell_type": "code", "execution_count": null, "id": "166c45f5", "metadata": {}, "outputs": [], "source": [ "m2d.variable_manager.set_variable(name=\"Simulation data\")\n", "for k, v in simulation_specifications.items():\n", " m2d[k] = v" ] }, { "cell_type": "markdown", "id": "d10aa628", "metadata": {}, "source": [ "Definem materials." ] }, { "cell_type": "code", "execution_count": null, "id": "74d3a6d2", "metadata": {}, "outputs": [], "source": [ "m2d.variable_manager.set_variable(name=\"Material data\")\n", "m2d.logger.clear_messages()\n", "for i, key in enumerate(materials.keys()):\n", " if key == \"Coil_material\":\n", " coil_mat_index = i\n", " elif key == \"Core_material\":\n", " core_mat_index = i\n", " elif key == \"Magnet_material\":\n", " magnet_mat_index = i\n", "material_array = []\n", "for k, v in materials.items():\n", " material_array.append('\"' + v + '\"')\n", "s = \", \".join(material_array)\n", "m2d[\"Materials\"] = \"[{}]\".format(s)" ] }, { "cell_type": "markdown", "id": "5093818d", "metadata": {}, "source": [ "## Create geometry\n", "\n", "Create magnetic core, coils, and magnets. Assign materials and create a coordinate system to\n", "define the magnet orientation." ] }, { "cell_type": "code", "execution_count": null, "id": "834197e7", "metadata": {}, "outputs": [], "source": [ "core_id = m2d.modeler.create_rectangle(\n", " origin=[0, 0, 0],\n", " sizes=[\"Core_outer_x\", \"Core_outer_y\"],\n", " name=\"Core\",\n", " material=\"Materials[\" + str(core_mat_index) + \"]\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "0e89bb85", "metadata": {}, "outputs": [], "source": [ "hole_id = m2d.modeler.create_rectangle(\n", " origin=[\"Core_thickness\", \"Core_thickness\", 0],\n", " sizes=[\"Core_outer_x-2*Core_thickness\", \"Core_outer_y-2*Core_thickness\"],\n", " name=\"hole\",\n", ")\n", "m2d.modeler.subtract(blank_list=[core_id], tool_list=[hole_id])" ] }, { "cell_type": "code", "execution_count": null, "id": "07f94390", "metadata": {}, "outputs": [], "source": [ "magnet_n_id = m2d.modeler.create_rectangle(\n", " origin=[\"Core_thickness\", \"Core_outer_y-2*Core_thickness\", 0],\n", " sizes=[\"Core_outer_x-2*Core_thickness\", \"Magnet_thickness\"],\n", " name=\"magnet_n\",\n", " material=\"Materials[\" + str(magnet_mat_index) + \"]\",\n", ")\n", "magnet_s_id = m2d.modeler.create_rectangle(\n", " origin=[\"Core_thickness\", \"Core_thickness\", 0],\n", " sizes=[\"Core_outer_x-2*Core_thickness\", \"Magnet_thickness\"],\n", " name=\"magnet_s\",\n", " material=\"Materials[\" + str(magnet_mat_index) + \"]\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "2ced194f", "metadata": {}, "outputs": [], "source": [ "m2d.modeler.create_coordinate_system(\n", " origin=[0, 0, 0], x_pointing=[0, 1, 0], y_pointing=[1, 0, 0], name=\"cs_x_positive\"\n", ")\n", "m2d.modeler.create_coordinate_system(\n", " origin=[0, 0, 0], x_pointing=[0, -1, 0], y_pointing=[1, 0, 0], name=\"cs_x_negative\"\n", ")\n", "magnet_s_id.part_coordinate_system = \"cs_x_positive\"\n", "magnet_n_id.part_coordinate_system = \"cs_x_negative\"\n", "m2d.modeler.set_working_coordinate_system(\"Global\")" ] }, { "cell_type": "markdown", "id": "4777e769", "metadata": {}, "source": [ "## Assign current\n", "\n", "Create coil terminals with 100 turns and winding with 5A current." ] }, { "cell_type": "code", "execution_count": null, "id": "e9d61199", "metadata": {}, "outputs": [], "source": [ "coil_in_id = m2d.modeler.create_rectangle(\n", " origin=[\n", " \"Core_thickness+Coil_start_position\",\n", " \"Core_thickness+Magnet_thickness+Coil_magnet_distance\",\n", " 0,\n", " ],\n", " sizes=[\"Coil_width\", \"Coil_thickness\"],\n", " name=\"coil_in\",\n", " material=\"Materials[\" + str(coil_mat_index) + \"]\",\n", ")\n", "coil_out_id = m2d.modeler.create_rectangle(\n", " origin=[\n", " \"Core_thickness+Coil_start_position\",\n", " \"Core_thickness+Magnet_thickness+Coil_magnet_distance+Coil_inner_diameter+Coil_thickness\",\n", " 0,\n", " ],\n", " sizes=[\"Coil_width\", \"Coil_thickness\"],\n", " name=\"coil_out\",\n", " material=\"Materials[\" + str(coil_mat_index) + \"]\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "ed261cdf", "metadata": {}, "outputs": [], "source": [ "m2d.assign_coil(\n", " assignment=[coil_in_id],\n", " conductors_number=\"No_of_turns\",\n", " name=\"coil_terminal_in\",\n", " polarity=\"Negative\",\n", ")\n", "m2d.assign_coil(\n", " assignment=[coil_out_id],\n", " conductors_number=\"No_of_turns\",\n", " name=\"coil_terminal_out\",\n", " polarity=\"Positive\",\n", ")\n", "m2d.assign_winding(is_solid=False, current=\"Winding_current\", name=\"Winding1\")\n", "m2d.add_winding_coils(\n", " assignment=\"Winding1\", coils=[\"coil_terminal_in\", \"coil_terminal_out\"]\n", ")" ] }, { "cell_type": "markdown", "id": "a1313f9d", "metadata": {}, "source": [ "## Assign motion\n", "\n", "Create band objects. All the objects within the band move. The inner band ensures that the mesh is good,\n", "and additionally it is required when there is more than one moving object.\n", "Assign linear motion with mechanical transient." ] }, { "cell_type": "code", "execution_count": null, "id": "b54bacdb", "metadata": {}, "outputs": [], "source": [ "band_id = m2d.modeler.create_rectangle(\n", " origin=[\n", " \"Core_thickness + Band_clearance\",\n", " \"Core_thickness+Magnet_thickness+Band_clearance\",\n", " 0,\n", " ],\n", " sizes=[\n", " \"Core_outer_x-2*(Core_thickness+Band_clearance)\",\n", " \"Core_outer_y-2*(Core_thickness+Band_clearance+Magnet_thickness)\",\n", " ],\n", " name=\"Motion_band\",\n", ")\n", "inner_band_id = m2d.modeler.create_rectangle(\n", " origin=[\n", " \"Core_thickness+Coil_start_position-Band_clearance\",\n", " \"Core_thickness+Magnet_thickness+Coil_magnet_distance-Band_clearance\",\n", " 0,\n", " ],\n", " sizes=[\n", " \"Coil_width + 2*Band_clearance\",\n", " \"Coil_inner_diameter+2*(Coil_thickness+Band_clearance)\",\n", " ],\n", " name=\"Motion_band_inner\",\n", ")\n", "motion_limit = \"Core_outer_x-2*(Core_thickness+Band_clearance)-(Coil_width + 2*Band_clearance)-2*Band_clearance\"\n", "m2d.assign_translate_motion(\n", " assignment=\"Motion_band\",\n", " axis=\"X\",\n", " periodic_translate=None,\n", " mechanical_transient=True,\n", " mass=\"Coil_mass\",\n", " start_position=0,\n", " negative_limit=0,\n", " positive_limit=motion_limit,\n", ")" ] }, { "cell_type": "markdown", "id": "4ddfe9f7", "metadata": {}, "source": [ "## Create simulation domain\n", "\n", "Create a region and assign zero vector potential on the region edges." ] }, { "cell_type": "code", "execution_count": null, "id": "a26c8f65", "metadata": {}, "outputs": [], "source": [ "region_id = m2d.modeler.create_region(pad_percent=2)\n", "m2d.assign_vector_potential(assignment=region_id.edges, boundary=\"VectorPotential1\")" ] }, { "cell_type": "markdown", "id": "cb05242c", "metadata": {}, "source": [ "## Assign mesh operations\n", "\n", "The transient solver does not have adaptive mesh refinement, so the mesh operations must be assigned." ] }, { "cell_type": "code", "execution_count": null, "id": "03761d4d", "metadata": {}, "outputs": [], "source": [ "m2d.mesh.assign_length_mesh(\n", " assignment=[band_id, inner_band_id],\n", " maximum_length=\"Mesh_bands\",\n", " maximum_elements=None,\n", " name=\"Bands\",\n", ")\n", "m2d.mesh.assign_length_mesh(\n", " assignment=[coil_in_id, coil_in_id, core_id, magnet_n_id, magnet_s_id, region_id],\n", " maximum_length=\"Mesh_other_objects\",\n", " maximum_elements=None,\n", " name=\"Coils_core_magnets\",\n", ")" ] }, { "cell_type": "markdown", "id": "af68c8b3", "metadata": {}, "source": [ "## Turn on eddy effects\n", "\n", "Assign eddy effects to the magnets." ] }, { "cell_type": "code", "execution_count": null, "id": "a53f4e06", "metadata": {}, "outputs": [], "source": [ "m2d.eddy_effects_on(assignment=[\"magnet_n\", \"magnet_s\"])" ] }, { "cell_type": "markdown", "id": "8a48a3cb", "metadata": {}, "source": [ "## Turn on core loss\n", "\n", "Enable core loss for the core." ] }, { "cell_type": "code", "execution_count": null, "id": "e341074d", "metadata": {}, "outputs": [], "source": [ "m2d.set_core_losses(assignment=\"Core\")" ] }, { "cell_type": "markdown", "id": "8dc3eee9", "metadata": {}, "source": [ "## Create simulation setup" ] }, { "cell_type": "code", "execution_count": null, "id": "f55b2645", "metadata": {}, "outputs": [], "source": [ "setup = m2d.create_setup(name=\"Setup1\")\n", "setup.props[\"StopTime\"] = \"Stop_time\"\n", "setup.props[\"TimeStep\"] = \"Time_step\"\n", "setup.props[\"SaveFieldsType\"] = \"Every N Steps\"\n", "setup.props[\"N Steps\"] = \"Save_fields_interval\"\n", "setup.props[\"Steps From\"] = \"0ms\"\n", "setup.props[\"Steps To\"] = \"Stop_time\"" ] }, { "cell_type": "markdown", "id": "55391048", "metadata": {}, "source": [ "## Create report\n", "\n", "Create an XY-report with force on the coil, the position of the coil on the Y axis,\n", "and time on the X axis." ] }, { "cell_type": "code", "execution_count": null, "id": "5bc9cc26", "metadata": {}, "outputs": [], "source": [ "m2d.post.create_report(\n", " expressions=[\"Moving1.Force_x\", \"Moving1.Position\"],\n", " plot_name=\"Force on Coil and Position of Coil\",\n", " primary_sweep_variable=\"Time\",\n", ")" ] }, { "cell_type": "markdown", "id": "aea36c09", "metadata": {}, "source": [ "## Analyze project" ] }, { "cell_type": "code", "execution_count": null, "id": "7314218a", "metadata": {}, "outputs": [], "source": [ "setup.analyze(cores=NUM_CORES, use_auto_settings=False)" ] }, { "cell_type": "markdown", "id": "5f0cae4a", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "5ca2096f", "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": "ccfc5c3c", "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": "c95552f5", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }