.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell2D_DCConduction.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_Maxwell2D_DCConduction.py: Maxwell 2D: resistance calculation ---------------------------------- This example uses PyAEDT to set up a resistance calculation and solve it using the Maxwell 2D DCConduction solver. Keywords: DXF import, material sweep, expression cache .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: default import os.path import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 13-18 Launch AEDT and Maxwell 2D ~~~~~~~~~~~~~~~~~~~~~~~~~~ Launch AEDT and Maxwell 2D after first setting up the project and design names, the solver, and the version. The following code also creates an instance of the ``Maxwell2d`` class named ``m2d``. .. GENERATED FROM PYTHON SOURCE LINES 18-27 .. code-block:: default m2d = pyaedt.Maxwell2d( specified_version="2023.2", new_desktop_session=True, close_on_exit=True, solution_type="DCConduction", designname="Ansys_resistor" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! .. GENERATED FROM PYTHON SOURCE LINES 28-33 Import geometry as a DXF file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can test importing a DXF or a Parasolid file by commenting/uncommenting the following lines. Importing DXF files only works in graphical mode. .. GENERATED FROM PYTHON SOURCE LINES 33-40 .. code-block:: default # DXFPath = pyaedt.downloads.download_file("dxf", "Ansys_logo_2D.dxf") # dxf_layers = m2d.get_dxf_layers(DXFPath) # m2d.import_dxf(DXFPath, dxf_layers, scale=1E-05) ParasolidPath = pyaedt.downloads.download_file("x_t", "Ansys_logo_2D.x_t") m2d.modeler.import_3d_cad(ParasolidPath) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 41-45 Define variables ~~~~~~~~~~~~~~~~ Define conductor thickness in z-direction, material array with 4 materials, and MaterialIndex referring to the material array .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: default m2d["MaterialThickness"] = "5mm" m2d["ConductorMaterial"] = "[\"Copper\", \"Aluminum\", \"silver\", \"gold\"]" MaterialIndex = 0 m2d["MaterialIndex"] = str(MaterialIndex) no_materials = 4 .. GENERATED FROM PYTHON SOURCE LINES 54-58 Assign materials ~~~~~~~~~~~~~~~~ Voltage ports will be defined as perfect electric conductor (pec), conductor gets the material defined by the 0th entry of the material array .. GENERATED FROM PYTHON SOURCE LINES 58-63 .. code-block:: default m2d.assign_material(["ANSYS_LOGO_2D_1", "ANSYS_LOGO_2D_2"], "pec") m2d.modeler["ANSYS_LOGO_2D_3"].material_name = "ConductorMaterial[MaterialIndex]" .. GENERATED FROM PYTHON SOURCE LINES 64-67 Assign voltages ~~~~~~~~~~~~~~~ 1V and 0V .. GENERATED FROM PYTHON SOURCE LINES 67-71 .. code-block:: default m2d.assign_voltage(["ANSYS_LOGO_2D_1"], amplitude=1, name="1V") m2d.assign_voltage(["ANSYS_LOGO_2D_2"], amplitude=0, name="0V") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 72-75 Setup conductance calculation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1V is the source, 0V ground .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. code-block:: default m2d.assign_matrix(sources=['1V'], group_sources=['0V'], matrix_name="Matrix1") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 79-82 Assign mesh operation ~~~~~~~~~~~~~~~~~~~~~ 3mm on the conductor .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: default m2d.mesh.assign_length_mesh(["ANSYS_LOGO_2D_3"], meshop_name="conductor", maxlength=3, maxel=None) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 86-90 Create simulation setup and enable expression cache ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create simulation setup with minimum 4 adaptive passes to ensure convergence. Enable expression cache to observe the convergence. .. GENERATED FROM PYTHON SOURCE LINES 90-100 .. code-block:: default setup1 = m2d.create_setup(setupname="Setup1", MinimumPasses=4) setup1.enable_expression_cache( # doesn't work? report_type="DCConduction", expressions="1/Matrix1.G(1V,1V)/MaterialThickness", isconvergence=True, conv_criteria=1, use_cache_for_freq=False) setup1.analyze() .. GENERATED FROM PYTHON SOURCE LINES 101-105 Create parametric sweep ~~~~~~~~~~~~~~~~~~~~~~~ Create parametric sweep to sweep all the entries in the material array. Save fields and mesh and use the mesh for all the materials. .. GENERATED FROM PYTHON SOURCE LINES 105-114 .. code-block:: default param_sweep = m2d.parametrics.add( "MaterialIndex", 0, no_materials-1, 1, "LinearStep", parametricname="MaterialSweep") param_sweep["SaveFields"] = True param_sweep["CopyMesh"] = True param_sweep["SolveWithCopiedMeshOnly"] = True param_sweep.analyze() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 115-118 Create resistance report ~~~~~~~~~~~~~~~~~~~~~~~~ Create R. vs. material report .. GENERATED FROM PYTHON SOURCE LINES 118-135 .. code-block:: default variations = {"MaterialIndex": ["All"], "MaterialThickness": ["Nominal"]} report = m2d.post.create_report( expressions="1/Matrix1.G(1V,1V)/MaterialThickness", primary_sweep_variable="MaterialIndex", report_category="DCConduction", plot_type="Data Table", variations=variations, plotname="Resistance vs. Material", ) d = report.get_solution_data() d.primary_sweep = "MaterialIndex" d.plot() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_001.png :alt: Simulation Results Plot :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 136-139 Field overlay ~~~~~~~~~~~~~ Plot electric field and current density on the conductor surface .. GENERATED FROM PYTHON SOURCE LINES 139-144 .. code-block:: default conductor_surface = m2d.modeler["ANSYS_LOGO_2D_3"].faces m2d.post.create_fieldplot_surface(conductor_surface, "Mag_E", plot_name="Electric Field") m2d.post.create_fieldplot_surface(conductor_surface, "Mag_J", plot_name="Current Density") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 145-148 Field overlay ~~~~~~~~~~~~~ Plot electric field using pyvista and saving to an image .. GENERATED FROM PYTHON SOURCE LINES 148-158 .. code-block:: default py_vista_plot = m2d.post.plot_field("Mag_E", conductor_surface, plot_cad_objs=False, show=False) py_vista_plot.isometric_view = False py_vista_plot.camera_position = [0, 0, 7] py_vista_plot.focal_point = [0, 0, 0] py_vista_plot.roll_angle = 0 py_vista_plot.elevation_angle = 0 py_vista_plot.azimuth_angle = 0 py_vista_plot.plot(os.path.join(m2d.working_directory, "Image.jpg")) .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_002.png :alt: Maxwell2D DCConduction :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 159-162 Field animation ~~~~~~~~~~~~~~~ Plot current density vs the Material index. .. GENERATED FROM PYTHON SOURCE LINES 162-182 .. code-block:: default animated = m2d.post.plot_animated_field( quantity="Mag_J", object_list=conductor_surface, export_path=m2d.working_directory, variation_variable="MaterialIndex", variation_list=[0,1,2,3], show=False, export_gif=False, log_scale=True, ) animated.isometric_view = False animated.camera_position = [0, 0, 7] animated.focal_point = [0, 0, 0] animated.roll_angle = 0 animated.elevation_angle = 0 animated.azimuth_angle = 0 animated.animate() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_003.png :alt: Maxwell2D DCConduction :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_DCConduction_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 183-185 Release desktop ~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 185-186 .. code-block:: default m2d.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 38.366 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell2D_DCConduction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell2D_DCConduction.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell2D_DCConduction.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_