.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell3D_Team3_bath_plate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_03-Maxwell_Maxwell3D_Team3_bath_plate.py: Maxwell 3D: bath plate analysis ------------------------------- This example uses PyAEDT to set up the TEAM 3 bath plate problem and solve it using the Maxwell 3D Eddy Current solver. https://www.compumag.org/wp/wp-content/uploads/2018/06/problem3.pdf .. GENERATED FROM PYTHON SOURCE LINES 9-12 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python import os import ansys.aedt.core import tempfile .. GENERATED FROM PYTHON SOURCE LINES 18-21 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python aedt_version = "2024.2" .. GENERATED FROM PYTHON SOURCE LINES 25-28 Create temporary directory ~~~~~~~~~~~~~~~~~~~~~~~~~~ Create temporary directory. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python temp_dir = tempfile.TemporaryDirectory(suffix=".ansys") .. GENERATED FROM PYTHON SOURCE LINES 32-36 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 40-45 Launch AEDT and Maxwell 3D ~~~~~~~~~~~~~~~~~~~~~~~~~~ Launch AEDT and Maxwell 3D after first setting up the project and design names, the solver, and the version. The following code also creates an instance of the ``Maxwell3d`` class named ``M3D``. .. GENERATED FROM PYTHON SOURCE LINES 45-60 .. code-block:: Python project_name = os.path.join(temp_dir.name, "COMPUMAG.aedt") design_name = "TEAM 3 Bath Plate" solver = "EddyCurrent" m3d = ansys.aedt.core.Maxwell3d( project=project_name, design=design_name, solution_type=solver, version=aedt_version, non_graphical=non_graphical, new_desktop=True, ) m3d.modeler.model_units = "mm" .. rst-class:: sphx-glr-script-out .. code-block:: none C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 8196 is still running _warn("subprocess %s is still running" % self.pid, C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\ansys\aedt\core\generic\settings.py:231: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys_e2d20e3b-9695-435f-b997-3384e4e2f807.log' mode='a' encoding='cp1252'> self.__logger = val .. GENERATED FROM PYTHON SOURCE LINES 61-65 Add variable ~~~~~~~~~~~~ Add a design variable named ``Coil_Position`` that you use later to adjust the position of the coil. .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: Python Coil_Position = -20 m3d["Coil_Position"] = str(Coil_Position) + m3d.modeler.model_units .. GENERATED FROM PYTHON SOURCE LINES 70-73 Add material ~~~~~~~~~~~~ Add a material named ``team3_aluminium`` for the ladder plate. .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: Python mat = m3d.materials.add_material("team3_aluminium") mat.conductivity = 32780000 .. GENERATED FROM PYTHON SOURCE LINES 78-81 Draw background region ~~~~~~~~~~~~~~~~~~~~~~ Draw a background region that uses the default properties for an air region. .. GENERATED FROM PYTHON SOURCE LINES 81-84 .. code-block:: Python m3d.modeler.create_air_region(x_pos=100, y_pos=100, z_pos=100, x_neg=100, y_neg=100, z_neg=100) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 85-88 Draw ladder plate and assign material ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Draw a ladder plate and assign it the newly created material ``team3_aluminium``. .. GENERATED FROM PYTHON SOURCE LINES 88-94 .. code-block:: Python m3d.modeler.create_box(origin=[-30, -55, 0], sizes=[60, 110, -6.35], name="LadderPlate", material="team3_aluminium") m3d.modeler.create_box(origin=[-20, -35, 0], sizes=[40, 30, -6.35], name="CutoutTool1") m3d.modeler.create_box(origin=[-20, 5, 0], sizes=[40, 30, -6.35], name="CutoutTool2") m3d.modeler.subtract("LadderPlate", ["CutoutTool1", "CutoutTool2"], keep_originals=False) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 95-98 Add mesh refinement to ladder plate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add a mesh refinement to the ladder plate. .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. code-block:: Python m3d.mesh.assign_length_mesh("LadderPlate", maximum_length=3, maximum_elements=None, name="Ladder_Mesh") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 102-106 Draw search coil and assign excitation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Draw a search coil and assign it a ``stranded`` current excitation. The stranded type forces the current density to be constant in the coil. .. GENERATED FROM PYTHON SOURCE LINES 106-117 .. code-block:: Python m3d.modeler.create_cylinder(orientation="Z", origin=[0, "Coil_Position", 15], radius=40, height=20, name="SearchCoil", material="copper") m3d.modeler.create_cylinder(orientation="Z", origin=[0, "Coil_Position", 15], radius=20, height=20, name="Bore", material="copper") m3d.modeler.subtract("SearchCoil", "Bore", keep_originals=False) m3d.modeler.section("SearchCoil", "YZ") m3d.modeler.separate_bodies("SearchCoil_Section1") m3d.modeler.delete("SearchCoil_Section1_Separate1") m3d.assign_current(assignment=["SearchCoil_Section1"], amplitude=1260, solid=False, name="SearchCoil_Excitation") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 118-123 Draw a line for plotting Bz ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Draw a line for plotting Bz later. Bz is the Z component of the flux density. The following code also adds a small diameter cylinder to refine the mesh locally around the line. .. GENERATED FROM PYTHON SOURCE LINES 123-129 .. code-block:: Python line_points = [["0mm", "-55mm", "0.5mm"], ["0mm", "55mm", "0.5mm"]] m3d.modeler.create_polyline(points=line_points, name="Line_AB") poly = m3d.modeler.create_polyline(points=line_points, name="Line_AB_MeshRefinement") poly.set_crosssection_properties(type="Circle", width="0.5mm") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 130-133 Plot model ~~~~~~~~~~ Plot the model. .. GENERATED FROM PYTHON SOURCE LINES 133-136 .. code-block:: Python m3d.plot(show=False, output_file=os.path.join(temp_dir.name, "Image.jpg"), plot_air_objects=False) .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_001.png :alt: Maxwell3D Team3 bath plate :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 137-140 Add Maxwell 3D setup ~~~~~~~~~~~~~~~~~~~~ Add a Maxwell 3D setup with frequency points at 50 Hz and 200 Hz. .. GENERATED FROM PYTHON SOURCE LINES 140-146 .. code-block:: Python setup = m3d.create_setup(name="Setup1") setup.props["Frequency"] = "200Hz" setup.props["HasSweepSetup"] = True setup.add_eddy_current_sweep(range_type="LinearStep", start=50, end=200, count=150, clear=True) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 147-151 Adjust eddy effects ~~~~~~~~~~~~~~~~~~~ Adjust eddy effects for the ladder plate and the search coil. The setting for eddy effect is ignored for the stranded conductor type used in the search coil. .. GENERATED FROM PYTHON SOURCE LINES 151-155 .. code-block:: Python m3d.eddy_effects_on(assignment=["LadderPlate"], enable_eddy_effects=True, enable_displacement_current=True) m3d.eddy_effects_on(assignment=["SearchCoil"], enable_eddy_effects=False, enable_displacement_current=True) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 156-159 Add linear parametric sweep ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add a linear parametric sweep for the two coil positions. .. GENERATED FROM PYTHON SOURCE LINES 159-166 .. code-block:: Python sweep_name = "CoilSweep" param = m3d.parametrics.add("Coil_Position", -20, 0, 20, "LinearStep", name=sweep_name) param["SaveFields"] = True param["CopyMesh"] = False param["SolveWithCopiedMeshOnly"] = True .. GENERATED FROM PYTHON SOURCE LINES 167-170 Solve parametric sweep ~~~~~~~~~~~~~~~~~~~~~~ Solve the parametric sweep directly so that results of all variations are available. .. GENERATED FROM PYTHON SOURCE LINES 170-173 .. code-block:: Python m3d.analyze_setup(sweep_name) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 174-177 Create expression for Bz ~~~~~~~~~~~~~~~~~~~~~~~~ Create an expression for Bz using the fields calculator. .. GENERATED FROM PYTHON SOURCE LINES 177-186 .. code-block:: Python Fields = m3d.ofieldsreporter Fields.EnterQty("B") Fields.CalcOp("ScalarZ") Fields.EnterScalar(1000) Fields.CalcOp("*") Fields.CalcOp("Smooth") Fields.AddNamedExpression("Bz", "Fields") .. GENERATED FROM PYTHON SOURCE LINES 187-190 Plot mag(Bz) as a function of frequency ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plot mag(Bz) as a function of frequency for both coil positions. .. GENERATED FROM PYTHON SOURCE LINES 190-195 .. code-block:: Python variations = {"Distance": ["All"], "Freq": ["All"], "Phase": ["0deg"], "Coil_Position": ["All"]} m3d.post.create_report(expressions="mag(Bz)", variations=variations, primary_sweep_variable="Distance", report_category="Fields", context="Line_AB", plot_name="mag(Bz) Along 'Line_AB' Coil") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 196-199 Get simulation results from a solved setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get simulation results from a solved setup as a ``SolutionData`` object. .. GENERATED FROM PYTHON SOURCE LINES 199-208 .. code-block:: Python solutions = m3d.post.get_solution_data( expressions="mag(Bz)", report_category="Fields", context="Line_AB", variations=variations, primary_sweep_variable="Distance", ) .. GENERATED FROM PYTHON SOURCE LINES 209-212 Set up sweep value and plot solution ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set up a sweep value and plot the solution. .. GENERATED FROM PYTHON SOURCE LINES 212-216 .. code-block:: Python solutions.active_variation["Coil_Position"] = -0.02 solutions.plot() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_002.png :alt: Simulation Results Plot :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 217-220 Change sweep value and plot solution ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change the sweep value and plot the solution again. .. GENERATED FROM PYTHON SOURCE LINES 220-224 .. code-block:: Python solutions.active_variation["Coil_Position"] = 0 solutions.plot() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_003.png :alt: Simulation Results Plot :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell3D_Team3_bath_plate_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 225-228 Plot induced current density on surface of ladder plate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plot the induced current density, ``"Mag_J"``, on the surface of the ladder plate. .. GENERATED FROM PYTHON SOURCE LINES 228-233 .. code-block:: Python ladder_plate = m3d.modeler.objects_by_name["LadderPlate"] intrinsic_dict = {"Freq": "50Hz", "Phase": "0deg"} m3d.post.create_fieldplot_surface(ladder_plate.faces, "Mag_J", intrinsics=intrinsic_dict, plot_name="Mag_J") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 234-237 Release AEDT ~~~~~~~~~~~~ Release AEDT from the script engine, leaving both AEDT and the project open. .. GENERATED FROM PYTHON SOURCE LINES 237-241 .. code-block:: Python m3d.release_desktop() temp_dir.cleanup() .. rst-class:: sphx-glr-timing **Total running time of the script:** (17 minutes 28.096 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell3D_Team3_bath_plate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell3D_Team3_bath_plate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell3D_Team3_bath_plate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Maxwell3D_Team3_bath_plate.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_