{ "cells": [ { "cell_type": "markdown", "id": "b993b0a2", "metadata": {}, "source": [ "# Example of a reference subsea power cable construction for floating offshore application" ] }, { "cell_type": "markdown", "id": "f736d98f", "metadata": {}, "source": [ "This example shows how to use PyAEDT to perform these tasks:\n", "\n", " - Import Design Variables and Material definitions from a json configuration file.\n", " - Create a Maxwell2D design.\n", " - Generate the geometry for a reference cable for floating offshore wind applications.\n", "\n", "\n", "For information on the cable model used in this example, see\n", "(https://www.mdpi.com/2071-1050/16/7/2899).\n", "\n", "Keywords: **Maxwell2D**, **subsea power cable**." ] }, { "cell_type": "markdown", "id": "a72fa52f", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "34a4e8db", "metadata": {}, "outputs": [], "source": [ "\n", "from dataclasses import dataclass\n", "import os\n", "import tempfile\n", "import time\n", "from pathlib import Path\n", "\n", "import ansys.aedt.core\n", "from ansys.aedt.core.examples.downloads import download_file\n" ] }, { "cell_type": "markdown", "id": "52e73c87", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "3f577244", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2026.1\"\n", "NG_MODE = False # Open AEDT UI when it is launched.\n", "JSON_FILENAME = \"config_power_cable.json\"" ] }, { "cell_type": "markdown", "id": "53e3eba2", "metadata": {}, "source": [ "## Create temporary directory and paths\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": "526ad7ac", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")\n", "data_folder = Path(download_file(r\"pyaedt/maxwell_power_cable\", local_path=temp_folder.name))\n", "json_path = data_folder / JSON_FILENAME" ] }, { "cell_type": "markdown", "id": "21044308", "metadata": {}, "source": [ "## Set up for model creation\n", "\n", "Start an instance of Maxwell 2d, providing the version, project name, design\n", "name, and type." ] }, { "cell_type": "code", "execution_count": null, "id": "0cc6c799", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"PowerCableExample.aedt\")\n", "m2d_design_name = \"2D_Cable\"\n", "setup_name = \"AnalysisSetup\"\n", "sweep_name = \"FreqSweep\"\n", "tb_design_name = \"CableSystem\"\n", "m2d = ansys.aedt.core.Maxwell2d(\n", " project=project_name,\n", " design=m2d_design_name,\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", ")\n", "m2d.modeler.model_units = \"mm\"" ] }, { "cell_type": "markdown", "id": "7e04c432", "metadata": {}, "source": [ "Download and import json configuration file for design variables and material definition" ] }, { "cell_type": "code", "execution_count": null, "id": "e931bcb7", "metadata": {}, "outputs": [], "source": [ "conf_settings = m2d.configurations.import_config(json_path)\n", "mat_from_json_keys_list = list(m2d.materials.material_keys.keys())\n", "for mat_name in mat_from_json_keys_list:\n", " m2d.materials.add_material(name=mat_name)" ] }, { "cell_type": "markdown", "id": "a37d8739", "metadata": {}, "source": [ "## Create model\n", "\n", "Create the geometry for the conductor structures." ] }, { "cell_type": "code", "execution_count": null, "id": "f9516f2f", "metadata": { "lines_to_next_cell": 1 }, "outputs": [], "source": [ "m2d.modeler.create_coordinate_system(origin=[\"x0_cond\", \"y0_cond\", \"0mm\"], name=\"CS_cond_1\")\n", "m2d.modeler.set_working_coordinate_system(\"CS_cond_1\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b969121d", "metadata": { "lines_to_next_cell": 1 }, "outputs": [], "source": [ "# Create cable layer object\n", "@dataclass\n", "class CableLayer:\n", " radius: str\n", " name: str\n", " material: str\n", " color: tuple" ] }, { "cell_type": "code", "execution_count": null, "id": "04b1924a", "metadata": {}, "outputs": [], "source": [ "# Create layer instances\n", "obj_cond_1 = CableLayer(\"dia_conductor/2\", \"cond_1\", \"copper\", (255,0,0))\n", "obj_cond_screen_1 = CableLayer(\"dia_conductor_screen/2\", \"cond_screen_1\", \"copper\", (255,0,0))\n", "obj_cond_ins_1 = CableLayer(\"dia_conductor_insulation/2\", \"cond_insulation_1\", \"XLPE\", (255,255,0))\n", "obj_cond_ins_screen_1 = CableLayer(\"dia_conductor_insulation_screen/2\", \"cond_insulation_screen_1\", \"copper\", (0, 128, 128))\n", "obj_cond_sheat_1 = CableLayer(\"dia_conductor_sheat/2\", \"cond_dia_conductor_sheat_1\", \"MDPE\", (143,159,165))\n", "cond_layers = [\n", " obj_cond_1,\n", " obj_cond_screen_1,\n", " obj_cond_ins_1,\n", " obj_cond_ins_screen_1,\n", " obj_cond_sheat_1,\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "4ad0732c", "metadata": {}, "outputs": [], "source": [ "# Create conductor assembly layer by layer\n", "cond_ids = [\n", " m2d.modeler.create_circle(\n", " origin = [\"0mm\", \"0mm\", \"0mm\"],\n", " radius = layer.radius,\n", " name = layer.name,\n", " material = layer.material,\n", " color = layer.color\n", " )\n", " for layer in cond_layers\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "bd8f7bf9", "metadata": {}, "outputs": [], "source": [ "# Duplicate around axis to generate the further 2 inner cables\n", "m2d.modeler.set_working_coordinate_system(\"Global\")\n", "all_obj_names = m2d.get_all_conductors_names() + m2d.get_all_dielectrics_names()\n", "m2d.modeler.duplicate_around_axis(all_obj_names, axis=\"Z\", angle=120, clones=3)" ] }, { "cell_type": "markdown", "id": "183f7485", "metadata": {}, "source": [ "Create the geometry for the outer structures." ] }, { "cell_type": "code", "execution_count": null, "id": "74000a32", "metadata": {}, "outputs": [], "source": [ "# Create layer instances\n", "obj_filler= CableLayer (\"dia_filler/2\",\"filler_background\",\"MDPE\", (175,143,175))\n", "obj_bedding = CableLayer(\"dia_bedding/2\",\"bedding\",\"PPY\",(128,0,255))\n", "obj_inner_sheat = CableLayer(\"dia_inner_sheath/2\",\"inner_sheath\",\"HDPE\",(128,0,255))\n", "obj_inner_armor = CableLayer(\"dia_armor_inner/2\",\"inner_armor\",\"stainless_steel\",(128,0,255))\n", "obj_armor_bedding = CableLayer(\"dia_bedding_armor/2\",\"bedding_armor\",\"PPY\",(128,0,255))\n", "obj_outer_armor = CableLayer(\"dia_armor_outer/2\",\"outer_armour\",\"stainless_steel\",(128,0,255))\n", "obj_outer_sheat = CableLayer(\"dia_outer_sheat/2\",\"outer_sheat\",\"HDPE\",(128,0,255))\n", "outer_layers = [\n", " obj_filler,\n", " obj_bedding,\n", " obj_inner_sheat,\n", " obj_inner_armor,\n", " obj_armor_bedding,\n", " obj_outer_armor,\n", " obj_outer_sheat,\n", "]" ] }, { "cell_type": "markdown", "id": "86f37755", "metadata": {}, "source": [ "Create outer assembly layer by layer" ] }, { "cell_type": "code", "execution_count": null, "id": "907c6d38", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "outer_ids = [\n", " m2d.modeler.create_circle(\n", " origin = [\"0mm\", \"0mm\", \"0mm\"],\n", " radius = layer.radius,\n", " name = layer.name,\n", " material = layer.material,\n", " color = layer.color\n", " ) for layer in outer_layers\n", "]" ] }, { "cell_type": "markdown", "id": "c06dbb32", "metadata": {}, "source": [ "Finalize the filler modeling\n", "create local coordinate sys to split the object" ] }, { "cell_type": "code", "execution_count": null, "id": "94f48238", "metadata": {}, "outputs": [], "source": [ "m2d.modeler.copy(outer_ids[0])\n", "filler_background_water = m2d.modeler.paste()\n", "m2d.assign_material(filler_background_water,\"water_sea\")\n", "m2d.modeler.create_coordinate_system(\n", " origin = [\"0mm\", \"0mm\", \"0mm\"],\n", " mode = \"axis\",\n", " x_pointing = [\"cos(30deg)\", \"-sin(30deg)\", \"0mm\"],\n", " y_pointing = [\"sin(30deg)\", \"cos(30deg)\", \"0mm\"],\n", " name = \"CS_rot_1\"\n", ")\n", "m2d.modeler.split(outer_ids[0],\"ZX\")\n", "m2d.modeler.create_coordinate_system(\n", " origin = [\"0mm\", \"0mm\", \"0mm\"],\n", " mode = \"axis\",\n", " x_pointing = [\"-cos(30deg)\", \"-sin(30deg)\", \"0mm\"],\n", " y_pointing = [\"-sin(30deg)\", \"cos(30deg)\", \"0mm\"],\n", " name = \"CS_rot_2\"\n", ")\n", "m2d.modeler.split(outer_ids[0],\"ZX\")\n", "m2d.modeler.delete_objects_containing(\"Split\")\n", "m2d.modeler.set_working_coordinate_system(\"Global\")\n", "tool_ellipse = m2d.modeler.create_ellipse(\n", " origin = [\"0mm\",\"-65mm\",\"0mm\"],\n", " major_radius = 60,\n", " ratio = 0.55\n", ")\n", "m2d.modeler.intersect([outer_ids[0],tool_ellipse])\n", "m2d.modeler.subtract(\n", " [outer_ids[0]],\n", " [\"cond_dia_conductor_sheat_1\",\"cond_dia_conductor_sheat_1_2\"]\n", ")\n", "m2d.modeler.duplicate_around_axis(outer_ids[0], axis=\"Z\", angle=120, clones=3)" ] }, { "cell_type": "markdown", "id": "242fea86", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "3ed05719", "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": "d89d16ea", "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": "3b4bc560", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] }, { "cell_type": "code", "execution_count": null, "id": "37b44537", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }