{ "cells": [ { "cell_type": "markdown", "id": "19c43db8", "metadata": {}, "source": [ "# Cable parameter identification" ] }, { "cell_type": "markdown", "id": "94cacd3c", "metadata": {}, "source": [ "This example shows how to use PyAEDT to perform these tasks:\n", "\n", " - Create a Q2D design using modeler primitives and an imported CAD.\n", " - Set up the simulation.\n", " - Link the solution to a Simplorer design.\n", "\n", "For information on the cable model used in this example, see\n", "[4 Core Armoured Power Cable](https://www.luxingcable.com/low-voltage-cables/4-core-armoured-power-cable.html).\n", "\n", "Keywords: **Q2D**, **EMC**, **cable**." ] }, { "cell_type": "markdown", "id": "d585f33a", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "9a4a99e8", "metadata": {}, "outputs": [], "source": [ "import math\n", "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "65f40d0c", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "3b3dd9e4", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "7939b45b", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "44623e0f", "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": "85ff5252", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "7e48b5c4", "metadata": {}, "source": [ "## Set up for model creation\n", "\n", "Initialize cable sizing by specifying radii in millimeters." ] }, { "cell_type": "code", "execution_count": null, "id": "c02114ce", "metadata": {}, "outputs": [], "source": [ "c_strand_radius = 2.575\n", "cable_n_cores = 4\n", "core_n_strands = 6\n", "core_xlpe_ins_thickness = 0.5\n", "core_xy_coord = math.ceil(3 * c_strand_radius + 2 * core_xlpe_ins_thickness)" ] }, { "cell_type": "markdown", "id": "e641d37a", "metadata": {}, "source": [ "Initialize radii of further structures incrementally adding thicknesses." ] }, { "cell_type": "code", "execution_count": null, "id": "42d96b73", "metadata": {}, "outputs": [], "source": [ "filling_radius = 1.4142 * (\n", " core_xy_coord + 3 * c_strand_radius + core_xlpe_ins_thickness + 0.5\n", ")\n", "inner_sheath_radius = filling_radius + 0.75\n", "armour_thickness = 3\n", "armour_radius = inner_sheath_radius + armour_thickness\n", "outer_sheath_radius = armour_radius + 2" ] }, { "cell_type": "markdown", "id": "3e6737b4", "metadata": {}, "source": [ "Initialize radii." ] }, { "cell_type": "code", "execution_count": null, "id": "f70106f4", "metadata": {}, "outputs": [], "source": [ "armour_centre_pos = inner_sheath_radius + armour_thickness / 2.0\n", "arm_strand_rad = armour_thickness / 2.0 - 0.2\n", "n_arm_strands = 30" ] }, { "cell_type": "markdown", "id": "f598bfbc", "metadata": {}, "source": [ "Start an instance of Q2D Extractor, providing the version, project name, design\n", "name, and type." ] }, { "cell_type": "code", "execution_count": null, "id": "260d842b", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"Q2D_ArmouredCableExample.aedt\")\n", "q2d_design_name = \"2D_Extractor_Cable\"\n", "setup_name = \"AnalysisSeetup\"\n", "sweep_name = \"FreqSweep\"\n", "tb_design_name = \"CableSystem\"\n", "q2d = ansys.aedt.core.Q2d(\n", " project=project_name,\n", " design=q2d_design_name,\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", ")\n", "q2d.modeler.model_units = \"mm\"" ] }, { "cell_type": "markdown", "id": "e2465d9e", "metadata": {}, "source": [ "Assign variables to the Q3D design." ] }, { "cell_type": "code", "execution_count": null, "id": "69e6ddd0", "metadata": {}, "outputs": [], "source": [ "core_params = {\n", " \"n_cores\": str(cable_n_cores),\n", " \"n_strands_core\": str(core_n_strands),\n", " \"c_strand_radius\": str(c_strand_radius) + \"mm\",\n", " \"c_strand_xy_coord\": str(core_xy_coord) + \"mm\",\n", "}\n", "outer_params = {\n", " \"filling_radius\": str(filling_radius) + \"mm\",\n", " \"inner_sheath_radius\": str(inner_sheath_radius) + \"mm\",\n", " \"armour_radius\": str(armour_radius) + \"mm\",\n", " \"outer_sheath_radius\": str(outer_sheath_radius) + \"mm\",\n", "}\n", "armour_params = {\n", " \"armour_centre_pos\": str(armour_centre_pos) + \"mm\",\n", " \"arm_strand_rad\": str(arm_strand_rad) + \"mm\",\n", " \"n_arm_strands\": str(n_arm_strands),\n", "}\n", "for k, v in core_params.items():\n", " q2d[k] = v\n", "for k, v in outer_params.items():\n", " q2d[k] = v\n", "for k, v in armour_params.items():\n", " q2d[k] = v" ] }, { "cell_type": "markdown", "id": "1fae477c", "metadata": {}, "source": [ "Cable insulators require the definition of specific materials since they are not\n", "included in the ``Sys`` library.\n", "\n", "Define Plastic, PE (cross-linked, wire, and cable grade):" ] }, { "cell_type": "code", "execution_count": null, "id": "83352b68", "metadata": {}, "outputs": [], "source": [ "mat_pe_cable_grade = q2d.materials.add_material(\"plastic_pe_cable_grade\")\n", "mat_pe_cable_grade.conductivity = \"1.40573e-16\"\n", "mat_pe_cable_grade.permittivity = \"2.09762\"\n", "mat_pe_cable_grade.dielectric_loss_tangent = \"0.000264575\"\n", "mat_pe_cable_grade.update()" ] }, { "cell_type": "markdown", "id": "b30298e2", "metadata": {}, "source": [ "Define Plastic, PP (10% carbon fiber):" ] }, { "cell_type": "code", "execution_count": null, "id": "451b8d39", "metadata": {}, "outputs": [], "source": [ "mat_pp = q2d.materials.add_material(\"plastic_pp_carbon_fiber\")\n", "mat_pp.conductivity = \"0.0003161\"\n", "mat_pp.update()" ] }, { "cell_type": "markdown", "id": "0a5904ec", "metadata": {}, "source": [ "## Create model\n", "\n", "Create the geometry for core strands, fill, and XLPE insulation." ] }, { "cell_type": "code", "execution_count": null, "id": "f553296b", "metadata": {}, "outputs": [], "source": [ "q2d.modeler.create_coordinate_system(\n", " origin=[\"c_strand_xy_coord\", \"c_strand_xy_coord\", \"0mm\"], name=\"CS_c_strand_1\"\n", ")\n", "q2d.modeler.set_working_coordinate_system(\"CS_c_strand_1\")\n", "c1_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"c_strand_radius\",\n", " name=\"c_strand_1\",\n", " material=\"copper\",\n", ")\n", "c2_id = c1_id.duplicate_along_line(\n", " vector=[\"0mm\", \"2.0*c_strand_radius\", \"0mm\"], clones=2\n", ")\n", "q2d.modeler.duplicate_around_axis(c2_id, axis=\"Z\", angle=360 / core_n_strands, clones=6)\n", "c_unite_name = q2d.modeler.unite(q2d.get_all_conductors_names())" ] }, { "cell_type": "code", "execution_count": null, "id": "8769292c", "metadata": {}, "outputs": [], "source": [ "fill_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"3*c_strand_radius\",\n", " name=\"c_strand_fill\",\n", " material=\"plastic_pp_carbon_fiber\",\n", ")\n", "fill_id.color = (255, 255, 0)" ] }, { "cell_type": "code", "execution_count": null, "id": "7612de92", "metadata": {}, "outputs": [], "source": [ "xlpe_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"3*c_strand_radius+\" + str(core_xlpe_ins_thickness) + \"mm\",\n", " name=\"c_strand_xlpe\",\n", " material=\"plastic_pe_cable_grade\",\n", ")\n", "xlpe_id.color = (0, 128, 128)" ] }, { "cell_type": "code", "execution_count": null, "id": "112d3ced", "metadata": {}, "outputs": [], "source": [ "q2d.modeler.set_working_coordinate_system(\"Global\")" ] }, { "cell_type": "code", "execution_count": null, "id": "83af7a30", "metadata": {}, "outputs": [], "source": [ "all_obj_names = q2d.get_all_conductors_names() + q2d.get_all_dielectrics_names()" ] }, { "cell_type": "code", "execution_count": null, "id": "304a6b57", "metadata": {}, "outputs": [], "source": [ "q2d.modeler.duplicate_around_axis(\n", " all_obj_names, axis=\"Z\", angle=360 / cable_n_cores, clones=4\n", ")\n", "cond_names = q2d.get_all_conductors_names()" ] }, { "cell_type": "markdown", "id": "f0cef157", "metadata": {}, "source": [ "Define the filling object." ] }, { "cell_type": "code", "execution_count": null, "id": "b12cc991", "metadata": {}, "outputs": [], "source": [ "filling_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"filling_radius\",\n", " name=\"Filling\",\n", " material=\"plastic_pp_carbon_fiber\",\n", ")\n", "filling_id.color = (255, 255, 180)" ] }, { "cell_type": "markdown", "id": "cf77df3a", "metadata": {}, "source": [ "Define the inner sheath." ] }, { "cell_type": "code", "execution_count": null, "id": "fa89e43c", "metadata": {}, "outputs": [], "source": [ "inner_sheath_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"inner_sheath_radius\",\n", " name=\"InnerSheath\",\n", " material=\"PVC plastic\",\n", ")\n", "inner_sheath_id.color = (0, 0, 0)" ] }, { "cell_type": "markdown", "id": "3dbafae6", "metadata": {}, "source": [ "Create the armature fill." ] }, { "cell_type": "code", "execution_count": null, "id": "93035819", "metadata": {}, "outputs": [], "source": [ "arm_fill_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"armour_radius\",\n", " name=\"ArmourFilling\",\n", " material=\"plastic_pp_carbon_fiber\",\n", ")\n", "arm_fill_id.color = (255, 255, 255)" ] }, { "cell_type": "markdown", "id": "fbd4ad45", "metadata": {}, "source": [ "Create the geometry for the outer sheath." ] }, { "cell_type": "code", "execution_count": null, "id": "73a9f4a0", "metadata": {}, "outputs": [], "source": [ "outer_sheath_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"0mm\", \"0mm\"],\n", " radius=\"outer_sheath_radius\",\n", " name=\"OuterSheath\",\n", " material=\"PVC plastic\",\n", ")\n", "outer_sheath_id.color = (0, 0, 0)" ] }, { "cell_type": "markdown", "id": "4bb81b11", "metadata": {}, "source": [ "Create the geometry for the armature steel strands." ] }, { "cell_type": "code", "execution_count": null, "id": "a30acf2a", "metadata": {}, "outputs": [], "source": [ "arm_strand_1_id = q2d.modeler.create_circle(\n", " origin=[\"0mm\", \"armour_centre_pos\", \"0mm\"],\n", " radius=\"1.1mm\",\n", " name=\"arm_strand_1\",\n", " material=\"steel_stainless\",\n", ")\n", "arm_strand_1_id.color = (128, 128, 64)\n", "arm_strand_1_id.duplicate_around_axis(\n", " axis=\"Z\", angle=\"360deg/n_arm_strands\", clones=\"n_arm_strands\"\n", ")\n", "arm_strand_names = q2d.modeler.get_objects_w_string(\"arm_strand\")" ] }, { "cell_type": "markdown", "id": "f6cd4a70", "metadata": {}, "source": [ "Define the outer region that defines the solution domain." ] }, { "cell_type": "code", "execution_count": null, "id": "f55f14c5", "metadata": {}, "outputs": [], "source": [ "region = q2d.modeler.create_region([500, 500, 500, 500])\n", "region.material_name = \"vacuum\"" ] }, { "cell_type": "markdown", "id": "a4083f36", "metadata": {}, "source": [ "Assign conductors and reference ground." ] }, { "cell_type": "code", "execution_count": null, "id": "c80e10ed", "metadata": {}, "outputs": [], "source": [ "obj = [q2d.modeler.get_object_from_name(i) for i in cond_names]\n", "[\n", " q2d.assign_single_conductor(\n", " name=\"C1\" + str(obj.index(i) + 1), assignment=i, conductor_type=\"SignalLine\"\n", " )\n", " for i in obj\n", "]\n", "obj = [q2d.modeler.get_object_from_name(i) for i in arm_strand_names]\n", "q2d.assign_single_conductor(\n", " name=\"gnd\", assignment=obj, conductor_type=\"ReferenceGround\"\n", ")\n", "q2d.modeler.fit_all()" ] }, { "cell_type": "markdown", "id": "b984483f", "metadata": {}, "source": [ "Specify the design settings." ] }, { "cell_type": "code", "execution_count": null, "id": "f8d5a65f", "metadata": {}, "outputs": [], "source": [ "lumped_length = \"100m\"\n", "q2d.design_settings[\"LumpedLength\"] = lumped_length" ] }, { "cell_type": "markdown", "id": "f5cb1736", "metadata": {}, "source": [ "## Solve model\n", "\n", "Insert the setup and frequency sweep." ] }, { "cell_type": "code", "execution_count": null, "id": "e152e6bc", "metadata": {}, "outputs": [], "source": [ "q2d_setup = q2d.create_setup(name=setup_name)\n", "q2d_sweep = q2d_setup.add_sweep(name=sweep_name)" ] }, { "cell_type": "markdown", "id": "74d70277", "metadata": {}, "source": [ "The cable model is generated by running two solution types:\n", "\n", "1. Capacitance and conductance per unit length (CG).\n", "For this model, the CG solution runs in a few seconds.\n", "\n", "2. Series resistance and inductance (RL).\n", "For this model, the solution time can range from 15-20 minutes,\n", "depending on the available hardware.\n", "\n", "Uncomment the following line to run the analysis." ] }, { "cell_type": "code", "execution_count": null, "id": "07682c82", "metadata": {}, "outputs": [], "source": [ "# q2d.analyze()" ] }, { "cell_type": "markdown", "id": "fadc3e9f", "metadata": {}, "source": [ "## Evaluate results\n", "\n", "Add a Simplorer/Twin Builder design and the Q3D dynamic component." ] }, { "cell_type": "code", "execution_count": null, "id": "4af98a31", "metadata": {}, "outputs": [], "source": [ "tb = ansys.aedt.core.TwinBuilder(design=tb_design_name, version=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "447dcd36", "metadata": {}, "source": [ "Add a Q2D dynamic component." ] }, { "cell_type": "code", "execution_count": null, "id": "c0b4c1b6", "metadata": {}, "outputs": [], "source": [ "tb.add_q3d_dynamic_component(\n", " project_name,\n", " q2d_design_name,\n", " q2d_setup.name,\n", " q2d_sweep.name,\n", " model_depth=lumped_length,\n", " coupling_matrix_name=\"Original\",\n", ")" ] }, { "cell_type": "markdown", "id": "c73f12dd", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "ce00962d", "metadata": {}, "outputs": [], "source": [ "tb.save_project()\n", "tb.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": "f507ac9c", "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": "b0623747", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }