From 579cedd1e9e53a65a865c7686f9678ebee3fb0ee Mon Sep 17 00:00:00 2001 From: Devin Date: Sat, 7 Mar 2026 16:00:54 -0600 Subject: [PATCH 1/2] Update formatting and remove whitespace Some changes made automatically by pre-commit. --- .../components/component_conversion.py | 13 ++-- .../components/reuse_component.py | 59 ++++++---------- examples/aedt_general/configuration_files.py | 9 +-- .../aedt_general/modeler/circuit_schematic.py | 21 ++---- .../modeler/netlist_to_schematic.py | 1 + examples/aedt_general/modeler/polyline.py | 67 +++++------------- examples/aedt_general/optimetrics.py | 9 +-- .../aedt_general/report/automatic_report.py | 45 ++++-------- .../aedt_general/report/touchstone_file.py | 4 +- .../legacy_standalone/differential_vias.py | 3 +- .../edb/legacy_standalone/edb_to_ipc2581.py | 1 + .../edb/legacy_standalone/gds_workflow.py | 17 ++--- examples/edb/use_configuration/dcir.py | 1 + .../use_configuration/import_components.py | 11 +-- .../edb/use_configuration/import_material.py | 10 +-- .../use_configuration/import_operations.py | 7 +- .../import_padstack_definitions.py | 12 ++-- .../edb/use_configuration/import_ports.py | 7 +- .../edb/use_configuration/import_setup_ac.py | 7 +- .../edb/use_configuration/import_sources.py | 7 +- .../modeler_simple_transmission_line.py | 1 + examples/edb/use_configuration/pcb_dc_ir.py | 5 +- .../edb/use_configuration/pdn_analysis.py | 2 +- .../post_layout_parametrize.py | 1 + examples/electrothermal/component_3d.py | 28 ++------ examples/electrothermal/components_csv.py | 35 +++------- examples/electrothermal/ecad_import.py | 11 ++- examples/electrothermal/electrothermal.py | 5 +- examples/electrothermal/graphic_card.py | 35 +++------- .../icepak_circuit_hfss_coupling.py | 60 ++++------------ examples/electrothermal/sherlock.py | 21 ++---- .../antenna/5G_antenna_parametrics.py | 7 +- examples/high_frequency/antenna/array.py | 16 ++--- examples/high_frequency/antenna/dipole.py | 59 +++++++++------- .../antenna/interferences/hfss_emit.py | 5 +- .../antenna/interferences/interference.py | 10 +-- .../antenna/interferences/protection.py | 17 ++--- .../antenna/large_scenarios/doppler.py | 27 +++---- .../antenna/large_scenarios/time_domain.py | 1 + examples/high_frequency/antenna/patch.py | 22 ++---- examples/high_frequency/emc/armoured_cable.py | 31 ++------ .../high_frequency/emc/double_pulse_test.py | 9 +-- examples/high_frequency/emc/eigenmode.py | 29 ++++---- examples/high_frequency/emc/subcircuit.py | 4 +- .../layout/signal_integrity/ami.py | 60 +++++----------- .../signal_integrity/circuit_transient.py | 15 ++-- .../signal_integrity/serdes_differential.py | 1 - .../multiphysics/hfss_mechanical.py | 4 +- .../multiphysics/microwave_oven.py | 70 ++++++++----------- 49 files changed, 324 insertions(+), 578 deletions(-) diff --git a/examples/aedt_general/components/component_conversion.py b/examples/aedt_general/components/component_conversion.py index aa00b82d2..ee8fe8ff1 100644 --- a/examples/aedt_general/components/component_conversion.py +++ b/examples/aedt_general/components/component_conversion.py @@ -6,9 +6,9 @@ # 3D components from older versions of AEDT # that relied on the ACIS modeling kernel, to the new # versions of AEDT that employ -# the Parasolid kernel. Specifically, if your +# the Parasolid kernel. Specifically, if your # encrypted 3D -# components were created with version 22R2 or +# components were created with version 22R2 or # earlier, you'll need to convert them # to a version ≥ 23R1 that supports the Parasolid modeler. # @@ -27,6 +27,7 @@ from ansys.aedt.core import Desktop, Hfss, settings from ansys.aedt.core.examples.downloads import download_file + # - # ### Define constants @@ -46,14 +47,14 @@ temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Covert the encrypted component +# ## Convert the encrypted component # # ### Retrieve the component that will be converted # # The ``download_file()`` method provides access to a library -# of examples and models from the Ansys GitHub organization: +# of examples and models from the Ansys GitHub organization: # [example-data repository](https://github.com/ansys/example-data/tree/master/pyaedt). Download the "old" -# encrypted 3D component and define a name to use for the new, coverted component. +# encrypted 3D component and define a name to use for the new, converted component. # + a3dcomp = download_file( @@ -100,7 +101,7 @@ # Launch another instance of AEDT to enable conversion of the # 3D component. # -# After the new version of AEDT is started, the process ID +# After the new version of AEDT is started, the process ID # is retrieved via the property ``aedt.aedt_process_id`` and is passed # as an argument to `Hfss()`. This ensures that the newly created # `hfss2` object diff --git a/examples/aedt_general/components/reuse_component.py b/examples/aedt_general/components/reuse_component.py index 2ea9c3ff4..eafe4e16d 100644 --- a/examples/aedt_general/components/reuse_component.py +++ b/examples/aedt_general/components/reuse_component.py @@ -20,6 +20,7 @@ import time from ansys.aedt.core import Hfss + # - # ### Define constants @@ -36,15 +37,16 @@ # > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to # > retrieve the AEDT project and data, do so before executing the final cell in the notebook. # -# This example creates two projects defined in `project_names. +# This example creates two projects defined in `project_names. # The first will be used to # create the patch antenna model and the 2nd project # will be used to demonstrate the use 3D components. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -project_names = [os.path.join(temp_folder.name, "start_project.aedt"), - os.path.join(temp_folder.name, "final_project.aedt"), - ] +project_names = [ + os.path.join(temp_folder.name, "start_project.aedt"), + os.path.join(temp_folder.name, "final_project.aedt"), +] # ### Launch HFSS # AEDT is started when an instance of the ``Hfss()`` class is @@ -65,9 +67,9 @@ # # ### Define parameters # -# Parameters can be defined in the HFSS design and subsequently +# Parameters can be defined in the HFSS design and subsequently # used to optimiuze -# performance, run parametric studies or +# performance, run parametric studies or # explore the impact of tolerance on performance. hfss["thickness"] = "0.1mm" @@ -75,10 +77,10 @@ # ### Build the antenna model # -# The compact, -# [pythonic syntax](https://docs.python-guide.org/writing/style/#code-style) +# The compact, +# [pythonic syntax](https://docs.python-guide.org/writing/style/#code-style) # allows you to create the model from simple -# primitives. This patch antenna is comprised of the FR-4 substrate, a rectangle, +# primitives. This patch antenna is comprised of the FR-4 substrate, a rectangle, # and the coaxial # probe feed. Each primitive is of type ``Object3D``. # @@ -95,9 +97,7 @@ feed_length = "0.1mm" # This parameter is defined only in Python and is not varied -patch = hfss.modeler.create_rectangle( - "XY", ["-width/2", "-width/2", "0mm"], ["width", "width"], name="patch" -) +patch = hfss.modeler.create_rectangle("XY", ["-width/2", "-width/2", "0mm"], ["width", "width"], name="patch") inner_conductor = hfss.modeler.create_cylinder( 2, @@ -127,14 +127,12 @@ # ### Assign boundaries to the via # -# The following statement selects the outer surface of the cylinder +# The following statement selects the outer surface of the cylinder # ``via_outer``, excluding the upper and lower faces, and assigns # the "perfect conductor" boundary condition. # + -side_face = [i for i in via_outer.faces if i.id not in - [via_outer.top_face_z.id, via_outer.bottom_face_z.id] - ] +side_face = [i for i in via_outer.faces if i.id not in [via_outer.top_face_z.id, via_outer.bottom_face_z.id]] hfss.assign_perfecte_to_sheets(side_face, name="feed_gnd") hfss.assign_perfecte_to_sheets(substrate.bottom_face_z, name="ground_plane") @@ -144,14 +142,10 @@ # ### Create wave port # -# A wave port is assigned to the bottom face of the via. Note that the property `via_outer.bottom_face_z` +# A wave port is assigned to the bottom face of the via. Note that the property `via_outer.bottom_face_z` # is a ``FacePrimitive`` object. -p1 = hfss.wave_port( - via_outer.bottom_face_z, - name="P1", - create_pec_cap=True -) +p1 = hfss.wave_port(via_outer.bottom_face_z, name="P1", create_pec_cap=True) # ### Query the object properties # @@ -187,7 +181,7 @@ # ### Insert 3D components # -# Place 4 antennas to make a small array. +# Place 4 antennas to make a small array. # - The substrate thickness is modified by creating the parameter "p_thick" and # assigning it to the "thickness" parameter of the components. # - The first antenna is placed at the origin. @@ -216,11 +210,8 @@ count = 1 for p in positions: cs.append(hfss2.modeler.create_coordinate_system(origin=p, name="cs_" + str(count))) # Create the patch coordinate system. - elements.append(hfss2.modeler.insert_3d_component(component_path, # Place the patch element. - coordinate_system=cs[-1].name, - name="patch_" + str(count)) - ) - count +=1 + elements.append(hfss2.modeler.insert_3d_component(component_path, coordinate_system=cs[-1].name, name="patch_" + str(count))) # Place the patch element. + count += 1 elements[-1].parameters["thickness"] = "p_thick" elements[-1].parameters["width"] = "w" @@ -234,7 +225,7 @@ # ### Move 3D components # -# The position of each 3D component can be changed by modifying the ``origin`` +# The position of each 3D component can be changed by modifying the ``origin`` # of the corresponding coordinate system. hfss2.modeler.coordinate_systems[0].origin = [0, "2*w", 0] @@ -243,10 +234,10 @@ # # The volume of the solution domain is defined # by an air region object. The following cell creates the -# region object and assigns the radiation boundary to the outer surfaces of +# region object and assigns the radiation boundary to the outer surfaces of # the region. -hfss2.modeler.create_air_region( x_pos=2, y_pos=2, z_pos=2.5, x_neg=2, y_neg=2, z_neg=2, is_percentage=False) +hfss2.modeler.create_air_region(x_pos=2, y_pos=2, z_pos=2.5, x_neg=2, y_neg=2, z_neg=2, is_percentage=False) hfss2.assign_radiation_boundary_to_faces(hfss2.modeler["Region"].faces) # ### Create solution setup and optimetrics analysis @@ -255,11 +246,7 @@ # + setup1 = hfss2.create_setup(RangeStart="60GHz", RangeEnd="80GHz") -optim = hfss2.parametrics.add("w", start_point="0.8mm", - end_point="1.2mm", - step="0.05mm", - variation_type="LinearStep", - name="Sweep Patch Width") +optim = hfss2.parametrics.add("w", start_point="0.8mm", end_point="1.2mm", step="0.05mm", variation_type="LinearStep", name="Sweep Patch Width") if hfss.valid_design: print(f"The HFSS design '{hfss.design_name}' is ready to solve.") diff --git a/examples/aedt_general/configuration_files.py b/examples/aedt_general/configuration_files.py index d00e7d682..12daf85a9 100644 --- a/examples/aedt_general/configuration_files.py +++ b/examples/aedt_general/configuration_files.py @@ -35,6 +35,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_icepak + # - # Define constants. @@ -54,9 +55,7 @@ # # Download the Icepack project. -project_full_name = download_icepak( - local_path=temp_folder.name -) +project_full_name = download_icepak(local_path=temp_folder.name) # ## Open project # @@ -117,9 +116,7 @@ # Export the configuration files. You can optionally disable the export and # import sections. Supported formats are JSON and TOML files. -conf_file = ipk.configurations.export_config( - os.path.join(ipk.working_directory, "config.toml") -) +conf_file = ipk.configurations.export_config(os.path.join(ipk.working_directory, "config.toml")) ipk.close_project() # ## Create project diff --git a/examples/aedt_general/modeler/circuit_schematic.py b/examples/aedt_general/modeler/circuit_schematic.py index 4e419cecb..13a8c2123 100644 --- a/examples/aedt_general/modeler/circuit_schematic.py +++ b/examples/aedt_general/modeler/circuit_schematic.py @@ -18,6 +18,7 @@ import ansys.aedt.core from ansys.aedt.core.generic.constants import Setups + # - # Define constants. @@ -65,15 +66,9 @@ # Place components such as an inductor, resistor, and capacitor. The ``location`` argument # provides the ``[x, y]`` coordinates to place the component. -inductor = circuit.modeler.schematic.create_inductor( - name="L1", value=1e-9, location=[0, 0] -) -resistor = circuit.modeler.schematic.create_resistor( - name="R1", value=50, location=[500, 0] -) -capacitor = circuit.modeler.schematic.create_capacitor( - name="C1", value=1e-12, location=[1000, 0] -) +inductor = circuit.modeler.schematic.create_inductor(name="L1", value=1e-9, location=[0, 0]) +resistor = circuit.modeler.schematic.create_resistor(name="R1", value=50, location=[500, 0]) +capacitor = circuit.modeler.schematic.create_capacitor(name="C1", value=1e-12, location=[1000, 0]) # ## Get all pins # @@ -88,9 +83,7 @@ # # Place a port and a ground in the schematic. -port = circuit.modeler.schematic.create_interface_port( - name="myport", location=[-300, 50] -) +port = circuit.modeler.schematic.create_interface_port(name="myport", location=[-300, 50]) gnd = circuit.modeler.schematic.create_gnd(location=[1200, -100]) # ## Connect components @@ -107,9 +100,7 @@ # # Create a transient setup. -setup2 = circuit.create_setup( - name="MyTransient", setup_type=Setups.NexximTransient -) +setup2 = circuit.create_setup(name="MyTransient", setup_type=Setups.NexximTransient) setup2.props["TransientData"] = ["0.01ns", "200ns"] setup3 = circuit.create_setup(name="MyDC", setup_type=Setups.NexximDC) diff --git a/examples/aedt_general/modeler/netlist_to_schematic.py b/examples/aedt_general/modeler/netlist_to_schematic.py index 23463554d..a9d098359 100644 --- a/examples/aedt_general/modeler/netlist_to_schematic.py +++ b/examples/aedt_general/modeler/netlist_to_schematic.py @@ -18,6 +18,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_netlist + # - # ## Define constants. diff --git a/examples/aedt_general/modeler/polyline.py b/examples/aedt_general/modeler/polyline.py index b1c5f0754..e13fe01a9 100644 --- a/examples/aedt_general/modeler/polyline.py +++ b/examples/aedt_general/modeler/polyline.py @@ -13,6 +13,7 @@ import time import ansys.aedt.core + # - # Define constants @@ -87,14 +88,8 @@ # Create an arc primitive. The ``position_list`` parameter must contain at # least three position values. The first three position values are used. -line2 = modeler.create_polyline( - points=test_points[0:3], segment_type="Arc", name="PL02_arc" -) -print( - "Created object with id {} and name {}.".format( - line2.id, modeler.objects[line2.id].name - ) -) +line2 = modeler.create_polyline(points=test_points[0:3], segment_type="Arc", name="PL02_arc") +print("Created object with id {} and name {}.".format(line2.id, modeler.objects[line2.id].name)) # ### Create spline primitive # @@ -124,9 +119,7 @@ center_point = [0, 0, 0] line4 = modeler.create_polyline( points=[start_point], - segment_type=modeler.polyline_segment( - "AngularArc", arc_center=center_point, arc_angle="30deg" - ), + segment_type=modeler.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg"), name="PL04_center_point_arc", ) @@ -139,16 +132,12 @@ center_point = [0, 0, 0] line4_xy = modeler.create_polyline( points=[start_point], - segment_type=modeler.polyline_segment( - "AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="XY" - ), + segment_type=modeler.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="XY"), name="PL04_center_point_arc_rot_XY", ) line4_zx = modeler.create_polyline( points=[start_point], - segment_type=modeler.polyline_segment( - "AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="ZX" - ), + segment_type=modeler.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="ZX"), name="PL04_center_point_arc_rot_ZX", ) @@ -165,9 +154,7 @@ # You can specify the segment type as an optional named argument to # define the segment type used to connect the points. -line5 = modeler.create_polyline( - points=test_points, segment_type=["Line", "Arc"], name="PL05_compound_line_arc" -) +line5 = modeler.create_polyline(points=test_points, segment_type=["Line", "Arc"], name="PL05_compound_line_arc") # Setting the named argument ``close_surface=True`` ensures # that the polyline starting point and @@ -175,16 +162,12 @@ # polyline by setting the last point equal # to the first point in the list of points. -line7 = modeler.create_polyline( - points=test_points, close_surface=True, name="PL07_segmented_compound_line_closed" -) +line7 = modeler.create_polyline(points=test_points, close_surface=True, name="PL07_segmented_compound_line_closed") # Setting the named argument ``cover_surface=True`` also # covers the polyline and creates a sheet object. -line_cover = modeler.create_polyline( - points=test_points, cover_surface=True, name="SPL01_segmented_compound_line" -) +line_cover = modeler.create_polyline(points=test_points, cover_surface=True, name="SPL01_segmented_compound_line") # ## Insert compound lines # @@ -215,17 +198,13 @@ # that the segment is inserted after the first segment of the original polyline. # + -line8_segment_arc = modeler.create_polyline( - points=test_points, close_surface=False, name="PL08_segmented_compound_insert_arc" -) +line8_segment_arc = modeler.create_polyline(points=test_points, close_surface=False, name="PL08_segmented_compound_insert_arc") start_point = line8_segment_arc.vertex_positions[1] insert_point1 = ["90mm", "20mm", "0mm"] insert_point2 = [40, 40, 0] -line8_segment_arc.insert_segment( - points=[start_point, insert_point1, insert_point2], segment="Arc" -) +line8_segment_arc.insert_segment(points=[start_point, insert_point1, insert_point2], segment="Arc") # - # ### Insert compound line at end of a center-point arc @@ -243,9 +222,7 @@ line_arc = modeler.create_polyline( name="First_Arc", points=[start_point], - segment_type=modeler.polyline_segment( - type="AngularArc", arc_angle=arc_angle_1, arc_center=arc_center_1 - ), + segment_type=modeler.polyline_segment(type="AngularArc", arc_angle=arc_angle_1, arc_center=arc_center_1), ) # - @@ -261,9 +238,7 @@ arc_center_2 = [3400, 200, 3800] line_arc.insert_segment( points=[end_of_line_segment], - segment=modeler.polyline_segment( - type="AngularArc", arc_center=arc_center_2, arc_angle=arc_angle_2 - ), + segment=modeler.polyline_segment(type="AngularArc", arc_center=arc_center_2, arc_angle=arc_angle_2), ) # You can use the compound polyline definition to complete all three steps in @@ -272,13 +247,9 @@ modeler.create_polyline( points=[start_point, end_of_line_segment], segment_type=[ - modeler.polyline_segment( - type="AngularArc", arc_angle="43.47deg", arc_center=arc_center_1 - ), + modeler.polyline_segment(type="AngularArc", arc_angle="43.47deg", arc_center=arc_center_1), modeler.polyline_segment(type="Line"), - modeler.polyline_segment( - type="AngularArc", arc_angle=arc_angle_2, arc_center=arc_center_2 - ), + modeler.polyline_segment(type="AngularArc", arc_angle=arc_angle_2, arc_center=arc_center_2), ], name="Compound_Polyline_One_Command", ) @@ -322,17 +293,13 @@ line_segments = ["Line", "Arc", "Line", "Arc", "Line"] -line_complex1 = modeler.create_polyline( - points=line_points, segment_type=line_segments, name="Polyline_example" -) +line_complex1 = modeler.create_polyline(points=line_points, segment_type=line_segments, name="Polyline_example") # Here is an example that provides more points than the segment list requires. # This is valid usage. The remaining points are ignored. line_segments = ["Line", "Arc", "Line", "Arc"] -line_complex2 = modeler.create_polyline( - line_points, segment_type=line_segments, name="Polyline_example2" -) +line_complex2 = modeler.create_polyline(line_points, segment_type=line_segments, name="Polyline_example2") # ## Save project # diff --git a/examples/aedt_general/optimetrics.py b/examples/aedt_general/optimetrics.py index 031a8fce0..95f2bdf41 100644 --- a/examples/aedt_general/optimetrics.py +++ b/examples/aedt_general/optimetrics.py @@ -15,6 +15,7 @@ import ansys.aedt.core from ansys.aedt.core.generic.constants import Axis + # - # Define constants. @@ -110,9 +111,7 @@ # # Create an optimetrics sensitivity analysis with output calculations. -sweep2 = hfss.optimizations.add( - calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optimization_type="Sensitivity" -) +sweep2 = hfss.optimizations.add(calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optimization_type="Sensitivity") sweep2.add_variation("w1", 0.1, 3, 0.5) sweep2.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"}) @@ -145,9 +144,7 @@ # # Create a DOE based on a goal and a calculation. -sweep5 = hfss.optimizations.add( - calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optimization_type="DXDOE" -) +sweep5 = hfss.optimizations.add(calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optimization_type="DXDOE") # ### Create another DOE # diff --git a/examples/aedt_general/report/automatic_report.py b/examples/aedt_general/report/automatic_report.py index 97b73fee2..c84769c71 100644 --- a/examples/aedt_general/report/automatic_report.py +++ b/examples/aedt_general/report/automatic_report.py @@ -19,6 +19,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file from IPython.display import Image + # - # Define constants. @@ -51,9 +52,7 @@ # to the extracted project is accessible from the ``cir.project_file`` property. # + -project_path = download_file( - source="custom_reports/", local_path=temp_folder.name -) +project_path = download_file(source="custom_reports/", local_path=temp_folder.name) circuit = ansys.aedt.core.Circuit( project=os.path.join(project_path, "CISPR25_Radiated_Emissions_Example23R1.aedtz"), @@ -70,12 +69,8 @@ # add notes to a report and modify the axes, grid, and legend. Custom reports # can be created in AEDT in non-graphical mode using version 2023 R2 and later. -report1 = circuit.post.create_report_from_configuration( - os.path.join(project_path, "Spectrum_CISPR_Basic.json") -) -out = circuit.post.export_report_to_jpg( - project_path=circuit.working_directory, plot_name=report1.plot_name -) +report1 = circuit.post.create_report_from_configuration(os.path.join(project_path, "Spectrum_CISPR_Basic.json")) +out = circuit.post.export_report_to_jpg(project_path=circuit.working_directory, plot_name=report1.plot_name) # Render the image. @@ -84,12 +79,8 @@ # You can customize every aspect of the report. The method ``crate_report_from_configuration()`` reads the # report configuration from a JSON file and generates the custom report. -report1_full = circuit.post.create_report_from_configuration( - os.path.join(project_path, "Spectrum_CISPR_Custom.json") -) -out = circuit.post.export_report_to_jpg( - circuit.working_directory, report1_full.plot_name -) +report1_full = circuit.post.create_report_from_configuration(os.path.join(project_path, "Spectrum_CISPR_Custom.json")) +out = circuit.post.export_report_to_jpg(circuit.working_directory, report1_full.plot_name) Image(os.path.join(circuit.working_directory, report1_full.plot_name + ".jpg")) # ## Create a transient report @@ -98,13 +89,9 @@ # The following code modifies the trace rendering prior to creating the report. # + -props = ansys.aedt.core.generic.file_utils.read_json( - os.path.join(project_path, "Transient_CISPR_Custom.json") -) +props = ansys.aedt.core.generic.file_utils.read_json(os.path.join(project_path, "Transient_CISPR_Custom.json")) -report2 = circuit.post.create_report_from_configuration( - report_settings=props, solution_name="NexximTransient" -) +report2 = circuit.post.create_report_from_configuration(report_settings=props, solution_name="NexximTransient") out = circuit.post.export_report_to_jpg(circuit.working_directory, report2.plot_name) Image(os.path.join(circuit.working_directory, report2.plot_name + ".jpg")) # - @@ -114,9 +101,7 @@ props["expressions"] = {"V(Battery)": {}, "V(U1_VDD)": {}} props["plot_name"] = "Battery Voltage" -report3 = circuit.post.create_report_from_configuration( - report_settings=props, solution_name="NexximTransient" -) +report3 = circuit.post.create_report_from_configuration(report_settings=props, solution_name="NexximTransient") out = circuit.post.export_report_to_jpg(circuit.working_directory, report3.plot_name) Image(os.path.join(circuit.working_directory, report3.plot_name + ".jpg")) @@ -124,20 +109,14 @@ # # You can use the JSON file to create an eye diagram. The following code includes the eye. -report4 = circuit.post.create_report_from_configuration( - os.path.join(project_path, "EyeDiagram_CISPR_Basic.json") -) +report4 = circuit.post.create_report_from_configuration(os.path.join(project_path, "EyeDiagram_CISPR_Basic.json")) out = circuit.post.export_report_to_jpg(circuit.working_directory, report4.plot_name) Image(os.path.join(circuit.working_directory, report4.plot_name + ".jpg")) # + -report4_full = circuit.post.create_report_from_configuration( - os.path.join(project_path, "EyeDiagram_CISPR_Custom.json") -) +report4_full = circuit.post.create_report_from_configuration(os.path.join(project_path, "EyeDiagram_CISPR_Custom.json")) -out = circuit.post.export_report_to_jpg( - circuit.working_directory, report4_full.plot_name -) +out = circuit.post.export_report_to_jpg(circuit.working_directory, report4_full.plot_name) Image(os.path.join(circuit.working_directory, report4_full.plot_name + ".jpg")) # - diff --git a/examples/aedt_general/report/touchstone_file.py b/examples/aedt_general/report/touchstone_file.py index ea9714d6f..511fb0f57 100644 --- a/examples/aedt_general/report/touchstone_file.py +++ b/examples/aedt_general/report/touchstone_file.py @@ -15,8 +15,8 @@ # + from ansys.aedt.core.examples.downloads import download_touchstone -from ansys.aedt.core.visualization.advanced.touchstone_parser import \ - read_touchstone +from ansys.aedt.core.visualization.advanced.touchstone_parser import read_touchstone + # - # ### Download example data diff --git a/examples/edb/legacy_standalone/differential_vias.py b/examples/edb/legacy_standalone/differential_vias.py index 4bdaabc79..4ae821c6f 100644 --- a/examples/edb/legacy_standalone/differential_vias.py +++ b/examples/edb/legacy_standalone/differential_vias.py @@ -16,6 +16,7 @@ import os import tempfile + import pyedb # ### Define constants @@ -39,7 +40,7 @@ # # ### Add stackup layers # -# A stackup can be created layer by layer or imported from a +# A stackup can be created layer by layer or imported from a # [configuration file](https://examples.aedt.docs.pyansys.com/version/dev/examples/edb/use_configuration/import_stackup.html). edb.stackup.add_layer("GND") diff --git a/examples/edb/legacy_standalone/edb_to_ipc2581.py b/examples/edb/legacy_standalone/edb_to_ipc2581.py index 72538aecb..7f37ec22c 100644 --- a/examples/edb/legacy_standalone/edb_to_ipc2581.py +++ b/examples/edb/legacy_standalone/edb_to_ipc2581.py @@ -11,6 +11,7 @@ import pyedb from pyedb.generic.general_methods import generate_unique_name from pyedb.misc.downloads import download_file + # - # ## Download the AEDB file and copy it in the temporary folder. diff --git a/examples/edb/legacy_standalone/gds_workflow.py b/examples/edb/legacy_standalone/gds_workflow.py index 3b4c42816..df26381dc 100644 --- a/examples/edb/legacy_standalone/gds_workflow.py +++ b/examples/edb/legacy_standalone/gds_workflow.py @@ -16,14 +16,15 @@ import os import tempfile + +from ansys.aedt.core.hfss3dlayout import Hfss3dLayout from pyedb import Edb from pyedb.misc.downloads import download_file -from ansys.aedt.core.hfss3dlayout import Hfss3dLayout # ### Define constant # Constants help ensure consistency and avoid repetition throughout the example. -AEDT_VERSION= "2025.2" +AEDT_VERSION = "2025.2" NG_MODE = False # Open AEDT UI when it is launched. # ### Create temporary directory @@ -38,8 +39,8 @@ # ### Import a GDS file. # -# Download the test case folder and copy it to the working directory. The -# method ``download_file()`` retrieves example data from the +# Download the test case folder and copy it to the working directory. The +# method ``download_file()`` retrieves example data from the # [Ansys GitHub "example_data" repository](https://github.com/ansys/example-data/tree/main/pyaedt). # # The following files are used in this example: @@ -78,9 +79,9 @@ # ### Save and close the EDB # # The GDS file has been converted to an EDB and is ready for subsequent processing either in the -# 3D Layout UI of Electronics Desktop or using -# PyEDB. -# The following commands save and close the EDB. +# 3D Layout UI of Electronics Desktop or using +# PyEDB. +# The following commands save and close the EDB. edb_path = os.path.join(temp_folder.name, "gds_design.aedb") edb.save_as(edb_path) @@ -95,7 +96,7 @@ h3d = Hfss3dLayout(project=edb_path, version=AEDT_VERSION, new_desktop=NG_MODE) -# ### Close the HFSS 3D Layout +# ### Close the HFSS 3D Layout # The following command releases Ansys Electronics Desktop and closes the project. h3d.release_desktop() diff --git a/examples/edb/use_configuration/dcir.py b/examples/edb/use_configuration/dcir.py index ecd450af5..c87e0ea06 100644 --- a/examples/edb/use_configuration/dcir.py +++ b/examples/edb/use_configuration/dcir.py @@ -12,6 +12,7 @@ from ansys.aedt.core import Hfss3dLayout from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. diff --git a/examples/edb/use_configuration/import_components.py b/examples/edb/use_configuration/import_components.py index 5d07ab537..a6a620095 100644 --- a/examples/edb/use_configuration/import_components.py +++ b/examples/edb/use_configuration/import_components.py @@ -11,14 +11,15 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path -from IPython.display import display -from ansys.aedt.core.examples.downloads import download_file import pandas as pd +import toml +from ansys.aedt.core.examples.downloads import download_file +from IPython.display import display from pyedb import Edb + # - # Define constants. @@ -106,7 +107,7 @@ with open(cfg_file_path, "w") as f: json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_material.py b/examples/edb/use_configuration/import_material.py index 952fabc58..0fce33e5d 100644 --- a/examples/edb/use_configuration/import_material.py +++ b/examples/edb/use_configuration/import_material.py @@ -7,13 +7,13 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path -from IPython.display import display -from ansys.aedt.core.examples.downloads import download_file import pandas as pd +import toml +from ansys.aedt.core.examples.downloads import download_file +from IPython.display import display from pyedb import Edb # - @@ -79,7 +79,7 @@ with open(file_json, "w") as f: json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_operations.py b/examples/edb/use_configuration/import_operations.py index 67b53f74e..584975cbe 100644 --- a/examples/edb/use_configuration/import_operations.py +++ b/examples/edb/use_configuration/import_operations.py @@ -10,12 +10,11 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path +import toml from ansys.aedt.core.examples.downloads import download_file - from pyedb import Edb AEDT_VERSION = "2025.2" @@ -172,7 +171,7 @@ json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_padstack_definitions.py b/examples/edb/use_configuration/import_padstack_definitions.py index fa8a6c1cd..9aa22464f 100644 --- a/examples/edb/use_configuration/import_padstack_definitions.py +++ b/examples/edb/use_configuration/import_padstack_definitions.py @@ -11,15 +11,15 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path -from IPython.display import display -from ansys.aedt.core.examples.downloads import download_file import pandas as pd - +import toml +from ansys.aedt.core.examples.downloads import download_file +from IPython.display import display from pyedb import Edb + # - # Define constants. @@ -125,7 +125,7 @@ json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_ports.py b/examples/edb/use_configuration/import_ports.py index 24950d923..893a3330f 100644 --- a/examples/edb/use_configuration/import_ports.py +++ b/examples/edb/use_configuration/import_ports.py @@ -18,12 +18,13 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path +import toml from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. @@ -149,7 +150,7 @@ json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_setup_ac.py b/examples/edb/use_configuration/import_setup_ac.py index 6959255f0..4a86c800e 100644 --- a/examples/edb/use_configuration/import_setup_ac.py +++ b/examples/edb/use_configuration/import_setup_ac.py @@ -12,12 +12,13 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path +import toml from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. @@ -129,7 +130,7 @@ json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/import_sources.py b/examples/edb/use_configuration/import_sources.py index 643dd1329..44d8967cd 100644 --- a/examples/edb/use_configuration/import_sources.py +++ b/examples/edb/use_configuration/import_sources.py @@ -17,12 +17,13 @@ # + import json -import toml -from pathlib import Path import tempfile +from pathlib import Path +import toml from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. @@ -157,7 +158,7 @@ with open(file_json, "w") as f: json.dump(cfg, f, indent=4, ensure_ascii=False) -# Equivalent toml file looks like below +# Equivalent toml file looks like below toml_string = toml.dumps(cfg) print(toml_string) diff --git a/examples/edb/use_configuration/modeler_simple_transmission_line.py b/examples/edb/use_configuration/modeler_simple_transmission_line.py index 97ca7e804..13af8a31b 100644 --- a/examples/edb/use_configuration/modeler_simple_transmission_line.py +++ b/examples/edb/use_configuration/modeler_simple_transmission_line.py @@ -10,6 +10,7 @@ import tempfile from pyedb import Edb + # - # Define constants. diff --git a/examples/edb/use_configuration/pcb_dc_ir.py b/examples/edb/use_configuration/pcb_dc_ir.py index 952de8f55..e014eed71 100644 --- a/examples/edb/use_configuration/pcb_dc_ir.py +++ b/examples/edb/use_configuration/pcb_dc_ir.py @@ -14,6 +14,7 @@ from ansys.aedt.core import Hfss3dLayout, Icepak from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. @@ -144,9 +145,7 @@ # ## Define Cutout -cfg["operations"] = { - "cutout": {"signal_list": ["1V0"], "reference_list": ["GND"], "extent_type": "ConvexHull", "expansion_size": 0.02} -} +cfg["operations"] = {"cutout": {"signal_list": ["1V0"], "reference_list": ["GND"], "extent_type": "ConvexHull", "expansion_size": 0.02}} # ## Define package for thermal analysis (optional) diff --git a/examples/edb/use_configuration/pdn_analysis.py b/examples/edb/use_configuration/pdn_analysis.py index 234cb4cc4..226ed8481 100644 --- a/examples/edb/use_configuration/pdn_analysis.py +++ b/examples/edb/use_configuration/pdn_analysis.py @@ -12,10 +12,10 @@ import tempfile import matplotlib.pyplot as plt - from ansys.aedt.core import Hfss3dLayout from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb + # - # Define constants. diff --git a/examples/edb/use_configuration/post_layout_parametrize.py b/examples/edb/use_configuration/post_layout_parametrize.py index 448c7588e..591a5d885 100644 --- a/examples/edb/use_configuration/post_layout_parametrize.py +++ b/examples/edb/use_configuration/post_layout_parametrize.py @@ -19,6 +19,7 @@ import ansys.aedt.core import pyedb from pyedb.misc.downloads import download_file + # - # ## Create an instance of a pyedb.Edb object. diff --git a/examples/electrothermal/component_3d.py b/examples/electrothermal/component_3d.py index e59f9b9a3..a74a9dbbd 100644 --- a/examples/electrothermal/component_3d.py +++ b/examples/electrothermal/component_3d.py @@ -29,9 +29,7 @@ # the temporary folder name is given by ``temp_folder.name``. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -package_temp_name, qfp_temp_name = download_icepak_3d_component( - local_path=temp_folder.name -) +package_temp_name, qfp_temp_name = download_icepak_3d_component(local_path=temp_folder.name) # ## Create heatsink # Create an empty project in non-graphical mode. @@ -51,9 +49,7 @@ # Define the heatsink using multiple boxes. -hs_base = ipk.modeler.create_box( - origin=[0, 0, 0], sizes=[37.5, 37.5, 2], name="HS_Base" -) +hs_base = ipk.modeler.create_box(origin=[0, 0, 0], sizes=[37.5, 37.5, 2], name="HS_Base") hs_base.material_name = "Al-Extruded" hs_fin = ipk.modeler.create_box(origin=[0, 0, 2], sizes=[37.5, 1, 18], name="HS_Fin1") hs_fin.material_name = "Al-Extruded" @@ -64,9 +60,7 @@ # Define a mesh region around the heatsink. -mesh_region = ipk.mesh.assign_mesh_region( - assignment=[hs_base.name, hs_fin.name] + hs_fins -) +mesh_region = ipk.mesh.assign_mesh_region(assignment=[hs_base.name, hs_fin.name] + hs_fins) mesh_region.manual_settings = True mesh_region.settings["MaxElementSizeX"] = "5mm" mesh_region.settings["MaxElementSizeY"] = "5mm" @@ -81,11 +75,7 @@ # Assign monitor objects. hs_middle_fin = ipk.modeler.get_object_from_name(assignment=hs_fins[n_fins // 2]) -point_monitor_position = [ - 0.5 * (hs_base.bounding_box[i] + hs_base.bounding_box[i + 3]) for i in range(2) -] + [ - hs_middle_fin.bounding_box[-1] -] # average x,y, top z +point_monitor_position = [0.5 * (hs_base.bounding_box[i] + hs_base.bounding_box[i + 3]) for i in range(2)] + [hs_middle_fin.bounding_box[-1]] # average x,y, top z ipk.monitor.assign_point_monitor( point_position=point_monitor_position, monitor_quantity=["Temperature", "HeatFlux"], @@ -134,7 +124,7 @@ ) # Assign a source power condition to the die. -bc_ds=ipk.create_temp_dep_assignment("PowerDissipationDataset") +bc_ds = ipk.create_temp_dep_assignment("PowerDissipationDataset") ipk.assign_source( assignment="DieSource", assignment_value=bc_ds, @@ -154,12 +144,8 @@ # Assign monitor objects. -ipk.monitor.assign_point_monitor_in_object( - name="QFP2_die", monitor_quantity="Temperature", monitor_name="DieCenter" -) -ipk.monitor.assign_surface_monitor( - surface_name="Die_Attach", monitor_quantity="Temperature", monitor_name="DieAttach" -) +ipk.monitor.assign_point_monitor_in_object(name="QFP2_die", monitor_quantity="Temperature", monitor_name="DieCenter") +ipk.monitor.assign_surface_monitor(surface_name="Die_Attach", monitor_quantity="Temperature", monitor_name="DieAttach") # Export the QFP 3D component in the ``"componentLibrary"`` folder and close the project. # Here the auxiliary dictionary allows exporting not only the monitor objects but also the dataset diff --git a/examples/electrothermal/components_csv.py b/examples/electrothermal/components_csv.py index d8db27b75..2673a6b57 100644 --- a/examples/electrothermal/components_csv.py +++ b/examples/electrothermal/components_csv.py @@ -15,13 +15,14 @@ from pathlib import Path import ansys.aedt.core -from ansys.aedt.core.examples.downloads import download_file import matplotlib as mpl import numpy as np import pyvista as pv +from ansys.aedt.core.examples.downloads import download_file from IPython.display import Image from matplotlib import cm from matplotlib import pyplot as plt + # - # Define constants. @@ -55,9 +56,7 @@ # # Components are represented as simple cubes with dimensions and properties specified in a CSV file. -filename = download_file( - "icepak", "blocks-list.csv", local_path=temp_folder.name -) +filename = download_file("icepak", "blocks-list.csv", local_path=temp_folder.name) # The CSV file lists block properties: # @@ -109,9 +108,7 @@ material_name = "copper" # Creates the block with the given name, coordinates, material, and type - block = ipk.modeler.create_box( - origin=origin, sizes=dimensions, name=block_name, material=material_name - ) + block = ipk.modeler.create_box(origin=origin, sizes=dimensions, name=block_name, material=material_name) # Assign boundary conditions if row["block_type"] == "solid": @@ -157,17 +154,13 @@ # Set the colormap to use. You can use the previously computed power budget to set the minimum and maximum values. cmap = plt.get_cmap("plasma") -norm = mpl.colors.Normalize( - vmin=min(power_budget.values()), vmax=max(power_budget.values()) -) +norm = mpl.colors.Normalize(vmin=min(power_budget.values()), vmax=max(power_budget.values())) scalarMap = cm.ScalarMappable(norm=norm, cmap=cmap) # Color the objects depending for obj in ipk.modeler.objects.values(): if obj.name in power_budget: - obj.color = [ - int(i * 255) for i in scalarMap.to_rgba(power_budget[obj.name])[0:3] - ] + obj.color = [int(i * 255) for i in scalarMap.to_rgba(power_budget[obj.name])[0:3]] obj.transparency = 0 else: obj.color = [0, 0, 0] @@ -180,9 +173,7 @@ obj_list_noregion = list(ipk.modeler.object_names) obj_list_noregion.remove("Region") export_file = os.path.join(temp_folder.name, "object_power_AEDTExport.jpg") -ipk.post.export_model_picture( - export_file, selections=obj_list_noregion, width=1920, height=1080 -) +ipk.post.export_model_picture(export_file, selections=obj_list_noregion, width=1920, height=1080) Image(export_file) # ### Plot model using PyAEDT @@ -192,9 +183,7 @@ # Export all models objects to OBJ files. -f = ipk.post.export_model_obj( - export_path=temp_folder.name, export_as_multiple_objects=True, air_objects=False -) +f = ipk.post.export_model_obj(export_path=temp_folder.name, export_as_multiple_objects=True, air_objects=False) # Add objects to the PyVista plotter. These objects are either set to a black color or assigned scalar values, # allowing them to be visualized with a colormap. @@ -204,9 +193,7 @@ plotter.add_mesh(mesh=pv.read(file), color="black", opacity=opacity) else: mesh = pv.read(filename=file) - mesh["Power"] = np.full( - shape=mesh.n_points, fill_value=power_budget[Path(file).stem] - ) + mesh["Power"] = np.full(shape=mesh.n_points, fill_value=power_budget[Path(file).stem]) plotter.add_mesh(mesh=mesh, scalars="Power", cmap="viridis", opacity=opacity) # Add a label to the object with the maximum temperature. @@ -230,9 +217,7 @@ ipk.save_project() ipk.release_desktop() -time.sleep( - 3 -) # Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory. +time.sleep(3) # Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory. # ## Clean up # diff --git a/examples/electrothermal/ecad_import.py b/examples/electrothermal/ecad_import.py index 14b4ac04d..f15c62763 100644 --- a/examples/electrothermal/ecad_import.py +++ b/examples/electrothermal/ecad_import.py @@ -13,8 +13,9 @@ import tempfile import time -from ansys.aedt.core.examples.downloads import download_file from ansys.aedt.core import Hfss3dLayout, Icepak +from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -60,12 +61,8 @@ name="edb.def", local_path=temp_folder.name, ) -board_path = download_file( - source="icepak/Icepak_ECAD_Import/", name="A1.bdf", local_path=temp_folder.name -) -library_path = download_file( - source="icepak/Icepak_ECAD_Import/", name="A1.ldf", local_path=temp_folder.name -) +board_path = download_file(source="icepak/Icepak_ECAD_Import/", name="A1.bdf", local_path=temp_folder.name) +library_path = download_file(source="icepak/Icepak_ECAD_Import/", name="A1.ldf", local_path=temp_folder.name) # Import IDF file. diff --git a/examples/electrothermal/electrothermal.py b/examples/electrothermal/electrothermal.py index f3142d17c..2784a2557 100644 --- a/examples/electrothermal/electrothermal.py +++ b/examples/electrothermal/electrothermal.py @@ -27,6 +27,7 @@ from ansys.aedt.core.examples.downloads import download_file from pyedb import Edb, Siwave + # - # Define constants. @@ -199,9 +200,7 @@ # ## Export Icepak project -siwave.export_icepak_project( - os.path.join(temp_folder.name, "from_siwave.aedt"), "siwave_dc" -) +siwave.export_icepak_project(os.path.join(temp_folder.name, "from_siwave.aedt"), "siwave_dc") # ## Close SIWave project diff --git a/examples/electrothermal/graphic_card.py b/examples/electrothermal/graphic_card.py index 49df9111c..13dece199 100644 --- a/examples/electrothermal/graphic_card.py +++ b/examples/electrothermal/graphic_card.py @@ -17,9 +17,10 @@ import time import ansys.aedt.core -from ansys.aedt.core.examples.downloads import download_icepak import pandas as pd +from ansys.aedt.core.examples.downloads import download_icepak from IPython.display import Image + # - # Define constants. @@ -36,9 +37,7 @@ # the temporary folder name is given by ``temp_folder.name``. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -project_temp_name = download_icepak( - local_path=temp_folder.name -) +project_temp_name = download_icepak(local_path=temp_folder.name) # ## Open project # @@ -83,9 +82,7 @@ # (fixed pressure condition) at x_max and x_min. region = ipk.modeler["Region"] -ipk.assign_pressure_free_opening( - assignment=region.top_face_x.id, boundary_name="Outlet" -) +ipk.assign_pressure_free_opening(assignment=region.top_face_x.id, boundary_name="Outlet") ipk.assign_velocity_free_opening( assignment=region.bottom_face_x.id, boundary_name="Inlet", @@ -144,9 +141,7 @@ speed_monitors = [] for x_pos in range(0, 10, 2): - m = ipk.monitor.assign_point_monitor( - point_position=[f"{x_pos}mm", "40mm", "15mm"], monitor_quantity="Speed" - ) + m = ipk.monitor.assign_point_monitor(point_position=[f"{x_pos}mm", "40mm", "15mm"], monitor_quantity="Speed") speed_monitors.append(m) # ## Solve project @@ -167,18 +162,14 @@ # Get the point monitor data. A dictionary is returned with ``'Min'``, ``'Max'``, and ``'Mean'`` keys. -temperature_data = ipk.post.evaluate_monitor_quantity( - monitor=m1, quantity="Temperature" -) +temperature_data = ipk.post.evaluate_monitor_quantity(monitor=m1, quantity="Temperature") temperature_data # It is also possible to get the data as a Pandas dataframe for advanced postprocessing. speed_fs = ipk.post.create_field_summary() for m_name in speed_monitors: - speed_fs.add_calculation( - entity="Monitor", geometry="Volume", geometry_name=m_name, quantity="Speed" - ) + speed_fs.add_calculation(entity="Monitor", geometry="Volume", geometry_name=m_name, quantity="Speed") speed_data = speed_fs.get_field_summary_data(pandas_output=True) # All the data is now in a dataframe, making it easy to visualize and manipulate. @@ -190,9 +181,7 @@ for i in range(3): direction = ["X", "Y", "Z"][i] - speed_data["Position" + direction] = [ - ipk.monitor.all_monitors[entity].location[i] for entity in speed_data["Entity"] - ] + speed_data["Position" + direction] = [ipk.monitor.all_monitors[entity].location[i] for entity in speed_data["Entity"]] # Plot the velocity profile at different X positions @@ -222,9 +211,7 @@ # The two dataframes can be merged using the `pd.merge()` function. With the merge, suffixes are # added to the column names to differentiate between the columns from each original dataframe. -merged_df = pd.merge( - temperature_fs, speed_data, on="Entity", suffixes=("_temperature", "_speed") -) +merged_df = pd.merge(temperature_fs, speed_data, on="Entity", suffixes=("_temperature", "_speed")) merged_df.head() # The column names are renamed based on the ``Quantity`` column of the original dataframes. @@ -268,9 +255,7 @@ surflist = [i.id for i in ipk.modeler["CPU"].faces] surflist += [i.id for i in ipk.modeler["MEMORY1"].faces] surflist += [i.id for i in ipk.modeler["MEMORY1_1"].faces] -plot3 = ipk.post.create_fieldplot_surface( - assignment=surflist, quantity="SurfTemperature" -) +plot3 = ipk.post.create_fieldplot_surface(assignment=surflist, quantity="SurfTemperature") path = plot3.export_image( full_path=os.path.join(temp_folder.name, "temperature.png"), orientation="top", diff --git a/examples/electrothermal/icepak_circuit_hfss_coupling.py b/examples/electrothermal/icepak_circuit_hfss_coupling.py index 188d2ea22..0e7cdfb4b 100644 --- a/examples/electrothermal/icepak_circuit_hfss_coupling.py +++ b/examples/electrothermal/icepak_circuit_hfss_coupling.py @@ -48,6 +48,7 @@ import ansys.aedt.core as aedt from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -69,9 +70,7 @@ # # Download and open the project. Save it to the temporary folder. -project_name = download_file( - "circuit_hfss_icepak", "Circuit-HFSS-Icepak-workflow.aedtz", temp_folder.name -) +project_name = download_file("circuit_hfss_icepak", "Circuit-HFSS-Icepak-workflow.aedtz", temp_folder.name) # ## Launch AEDT and initialize HFSS # @@ -108,9 +107,7 @@ material_name = hfss.modeler.objects_by_name[device3D_body_name].material_name new_material_name = material_name + "_dataset" -new_material = hfss.materials.duplicate_material( - material=material_name, name=new_material_name -) +new_material = hfss.materials.duplicate_material(material=material_name, name=new_material_name) # ## Modify material properties # @@ -171,10 +168,7 @@ hfss_component_name = "" hfss_instance_name = "" for component in circuit.modeler.schematic.components.values(): - if ( - component.model_name is not None - and hfss.design_name in component.model_name - ): + if component.model_name is not None and hfss.design_name in component.model_name: hfss_component_name = component.model_name hfss_instance_name = component.refdes break @@ -195,9 +189,7 @@ # Step 4: Extract the resistor's power loss value from the Circuit design. # # Evaluate the power loss on the resistor. - r_losses = circuit.post.get_solution_data( - expressions="0.5*mag(I(I1)*V(V1))" - ).get_expression_data()[1][0] + r_losses = circuit.post.get_solution_data(expressions="0.5*mag(I(I1)*V(V1))").get_expression_data()[1][0] # Save the losses in the stats. stats[cp_iter]["losses"] = r_losses @@ -228,9 +220,7 @@ # Step 7: Export the temperature map from the Icepak design and create a new 3D dataset with it. # # Export the temperature map to a file. - fld_filename = os.path.join( - icepak.working_directory, f"temperature_map_{cp_iter}.fld" - ) + fld_filename = os.path.join(icepak.working_directory, f"temperature_map_{cp_iter}.fld") icepak.post.export_field_file( quantity="Temp", output_file=fld_filename, @@ -256,16 +246,12 @@ # Import the 3D dataset. dataset_name = f"temp_map_step_{cp_iter}" - hfss.import_dataset3d( - input_file=tab_filename, name=dataset_name, is_project_dataset=True - ) + hfss.import_dataset3d(input_file=tab_filename, name=dataset_name, is_project_dataset=True) # Step 8: Update material properties in the HFSS design based on the new dataset. # # Set the new conductivity value. - new_material.conductivity.value = ( - f"{old_conductivity}*Pwl($TempDepCond,clp(${dataset_name},X,Y,Z))" - ) + new_material.conductivity.value = f"{old_conductivity}*Pwl($TempDepCond,clp(${dataset_name},X,Y,Z))" # Switch off the thermal modifier of the material, if any. new_material.conductivity.thermalmodifier = None @@ -273,9 +259,7 @@ # Step 9: Extract the average temperature of the resistor from the Icepak design. # # Get the mean temperature value on the high-resistivity object. - mean_temp = icepak.post.get_scalar_field_value( - quantity="Temp", scalar_function="Mean", object_name=resistor_body_name - ) + mean_temp = icepak.post.get_scalar_field_value(quantity="Temp", scalar_function="Mean", object_name=resistor_body_name) # Save the temperature in the iteration statistics. stats[cp_iter]["temp"] = mean_temp @@ -296,12 +280,8 @@ converged = False stats[cp_iter]["converged"] = converged if cp_iter > 1: - delta_temp = abs(stats[cp_iter]["temp"] - stats[cp_iter - 1]["temp"]) / abs( - stats[cp_iter - 1]["temp"] - ) - delta_losses = abs( - stats[cp_iter]["losses"] - stats[cp_iter - 1]["losses"] - ) / abs(stats[cp_iter - 1]["losses"]) + delta_temp = abs(stats[cp_iter]["temp"] - stats[cp_iter - 1]["temp"]) / abs(stats[cp_iter - 1]["temp"]) + delta_losses = abs(stats[cp_iter]["losses"] - stats[cp_iter - 1]["losses"]) / abs(stats[cp_iter - 1]["losses"]) if delta_temp <= temp_residual_limit and delta_losses <= loss_residual_limit: converged = True stats[cp_iter]["converged"] = converged @@ -323,21 +303,9 @@ for i in stats: txt = "yes" if stats[i]["converged"] else "no" - delta_temp = ( - f"{stats[i]['delta_temp']:.4f}" - if stats[i]["delta_temp"] is not None - else "None" - ) - delta_losses = ( - f"{stats[i]['delta_losses']:.4f}" - if stats[i]["delta_losses"] is not None - else "None" - ) - print( - f"Step {i}: temp={stats[i]['temp']:.3f}, losses={stats[i]['losses']:.3f}, " - f"delta_temp={delta_temp}, delta_losses={delta_losses}, " - f"converged={txt}" - ) + delta_temp = f"{stats[i]['delta_temp']:.4f}" if stats[i]["delta_temp"] is not None else "None" + delta_losses = f"{stats[i]['delta_losses']:.4f}" if stats[i]["delta_losses"] is not None else "None" + print(f"Step {i}: temp={stats[i]['temp']:.3f}, losses={stats[i]['losses']:.3f}, " f"delta_temp={delta_temp}, delta_losses={delta_losses}, " f"converged={txt}") # ## Release AEDT # diff --git a/examples/electrothermal/sherlock.py b/examples/electrothermal/sherlock.py index 616fd17a9..1972dd7af 100644 --- a/examples/electrothermal/sherlock.py +++ b/examples/electrothermal/sherlock.py @@ -16,6 +16,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_sherlock + # - # Define constants @@ -53,9 +54,7 @@ # ## Create Icepak model -ipk = ansys.aedt.core.Icepak( - project=project_name, version=AEDT_VERSION, non_graphical=NG_MODE -) +ipk = ansys.aedt.core.Icepak(project=project_name, version=AEDT_VERSION, non_graphical=NG_MODE) # Disable autosave to speed up the import. @@ -64,9 +63,7 @@ # Import a PCB from an AEDB file. odb_path = os.path.join(input_dir, aedt_odb_project) -ipk.create_pcb_from_3dlayout( - component_name="Board", project_name=odb_path, design_name=aedt_odb_design_name -) +ipk.create_pcb_from_3dlayout(component_name="Board", project_name=odb_path, design_name=aedt_odb_design_name) # Create an offset coordinate system to match ODB++ with the Sherlock STEP file. # The thickness is computed from the ``"Board"`` component. (``"Board1"`` is the @@ -74,9 +71,7 @@ bb = ipk.modeler.user_defined_components["Board1"].bounding_box stackup_thickness = bb[-1] - bb[2] -ipk.modeler.create_coordinate_system( - origin=[0, 0, stackup_thickness / 2], mode="view", view="XY" -) +ipk.modeler.create_coordinate_system(origin=[0, 0, stackup_thickness / 2], mode="view", view="XY") # Import the board components from an MCAD file and remove the PCB object as it is already # imported with the ECAD. @@ -92,9 +87,7 @@ # # Use the Sherlock file to assign materials. -ipk.assignmaterial_from_sherlock_files( - component_file=component_list, material_file=material_list -) +ipk.assignmaterial_from_sherlock_files(component_file=component_list, material_file=material_list) # Delete objects with no material assignments. @@ -128,9 +121,7 @@ # ### Add postprocessing object # Create the point monitor. -point1 = ipk.monitor.assign_point_monitor( - point_position=ipk.modeler["COMP_U10"].top_face_z.center, monitor_name="Point1" -) +point1 = ipk.monitor.assign_point_monitor(point_position=ipk.modeler["COMP_U10"].top_face_z.center, monitor_name="Point1") # Create a line for reporting after the simulation. diff --git a/examples/high_frequency/antenna/5G_antenna_parametrics.py b/examples/high_frequency/antenna/5G_antenna_parametrics.py index 13e159b14..8be7c0ae4 100644 --- a/examples/high_frequency/antenna/5G_antenna_parametrics.py +++ b/examples/high_frequency/antenna/5G_antenna_parametrics.py @@ -14,6 +14,7 @@ import ansys.aedt.core import pyedb + # - # ### Define constants @@ -38,9 +39,9 @@ # ### Create primitive data classes to simplify geometry creation # # The ``Line``, ``Patch`` and ``Array`` classes wrap geometry -# operations and properties into simple Python classes that help +# operations and properties into simple Python classes that help # simplify the creation of the microstrip -# array with the ``pyedb.Edb`` class. +# array with the ``pyedb.Edb`` class. # + class Patch: @@ -124,7 +125,7 @@ def points(self): # ### Create a patch antenna and feed line # -# Instances of the ``Patch`` and ``Line``classes are used to define the geometry. These +# Instances of the ``Patch`` and ``Line``classes are used to define the geometry. These # classes provide for parameterization of the array layout. # # diff --git a/examples/high_frequency/antenna/array.py b/examples/high_frequency/antenna/array.py index ab57e3b86..57d7d52cd 100644 --- a/examples/high_frequency/antenna/array.py +++ b/examples/high_frequency/antenna/array.py @@ -18,10 +18,12 @@ import time from ansys.aedt.core import Hfss -from ansys.aedt.core.visualization.advanced.farfield_visualization import \ - FfdSolutionData from ansys.aedt.core.examples.downloads import download_3dcomponent from ansys.aedt.core.generic import file_utils +from ansys.aedt.core.visualization.advanced.farfield_visualization import ( + FfdSolutionData, +) + # - # ### Define constants @@ -70,9 +72,7 @@ # # Read array definition from the JSON file. -array_definition = file_utils.read_json( - os.path.join(path_to_3dcomp, "array_simple.json") -) +array_definition = file_utils.read_json(os.path.join(path_to_3dcomp, "array_simple.json")) # ### Add the 3D component definition # @@ -170,7 +170,7 @@ # # An instance of the ``FfdSolutionData`` class # can be instantiated from the metadata file. Embedded element -# patters are linked through the metadata file. +# patterns are linked through the metadata file. ffdata = FfdSolutionData(input_file=metadata_file) @@ -179,9 +179,7 @@ # Generate a contour plot. You can define the Theta scan # and Phi scan. -ffdata.plot_contour( - quantity="RealizedGain", title=f"Contour at {ffdata.frequency * 1e-9:.1f} GHz" -) +ffdata.plot_contour(quantity="RealizedGain", title=f"Contour at {ffdata.frequency * 1e-9:.1f} GHz") # ### Generate 2D cutout plots # diff --git a/examples/high_frequency/antenna/dipole.py b/examples/high_frequency/antenna/dipole.py index 63018375e..6b3d66e1a 100644 --- a/examples/high_frequency/antenna/dipole.py +++ b/examples/high_frequency/antenna/dipole.py @@ -17,6 +17,7 @@ import time from ansys.aedt.core import Hfss + # - # ### Define constants @@ -45,12 +46,13 @@ # create and simulate the dipole antenna. project_name = os.path.join(temp_folder.name, "dipole.aedt") -hfss = Hfss(version=AEDT_VERSION, - non_graphical=NG_MODE, - project=project_name, - new_desktop=True, - solution_type="Modal", - ) +hfss = Hfss( + version=AEDT_VERSION, + non_graphical=NG_MODE, + project=project_name, + new_desktop=True, + solution_type="Modal", +) # ## Model Preparation # @@ -111,7 +113,7 @@ # mesh refinement. Selection of two frequencies, one above and one below the # expected resonance frequency help improve mesh quality at the resonant frequency. # -# > **Note:** The parameter names used here are passed directly to the native AEDT API and therfore +# > **Note:** The parameter names used here are passed directly to the native AEDT API and therefore # > do not adhere to [PEP-8](https://peps.python.org/pep-0008/). # # Both a discrete frequency sweep and an interpolating sweep are added to the solution setup. @@ -165,15 +167,16 @@ variations["Freq"] = [center_freq] variations["Theta"] = ["All"] variations["Phi"] = ["All"] -elevation_ffd_plot = hfss.post.create_report(expressions="db(GainTheta)", - setup_sweep_name=disc_sweep.name, - variations=variations, - primary_sweep_variable="Theta", - context="Elevation", # Far-field setup is pre-defined. - report_category="Far Fields", - plot_type="Radiation Pattern", - plot_name="Elevation Gain (dB)" - ) +elevation_ffd_plot = hfss.post.create_report( + expressions="db(GainTheta)", + setup_sweep_name=disc_sweep.name, + variations=variations, + primary_sweep_variable="Theta", + context="Elevation", # Far-field setup is pre-defined. + report_category="Far Fields", + plot_type="Radiation Pattern", + plot_name="Elevation Gain (dB)", +) elevation_ffd_plot.children["Legend"].properties["Show Trace Name"] = False elevation_ffd_plot.children["Legend"].properties["Show Solution Name"] = False @@ -192,10 +195,12 @@ # # + -report_3d = hfss.post.reports_by_category.far_field("db(RealizedGainTheta)", - disc_sweep.name, - sphere_name="3D", - Freq= [center_freq],) +report_3d = hfss.post.reports_by_category.far_field( + "db(RealizedGainTheta)", + disc_sweep.name, + sphere_name="3D", + Freq=[center_freq], +) report_3d.report_type = "3D Polar Plot" report_3d.create(name="Realized Gain (dB)") @@ -203,7 +208,7 @@ # ### Retrieve solution data for post-processing in Python # -# An instance of the ``SolutionData`` class can be created from the report by calling ``get_solution_data()``. +# An instance of the ``SolutionData`` class can be created from the report by calling ``get_solution_data()``. # This class provides access to data for further post-processing using # [Matplotlib](https://matplotlib.org/). @@ -218,11 +223,13 @@ # + xpol_expressions = ["db(RealizedGainTheta)", "db(RealizedGainPhi)"] -xpol = hfss.post.reports_by_category.far_field(["db(RealizedGainTheta)", "db(RealizedGainPhi)"], - disc_sweep.name, - name="Cross Polarization", - sphere_name="Azimuth", - Freq= [center_freq],) +xpol = hfss.post.reports_by_category.far_field( + ["db(RealizedGainTheta)", "db(RealizedGainPhi)"], + disc_sweep.name, + name="Cross Polarization", + sphere_name="Azimuth", + Freq=[center_freq], +) xpol.report_type = "Radiation Pattern" xpol.create(name="xpol") diff --git a/examples/high_frequency/antenna/interferences/hfss_emit.py b/examples/high_frequency/antenna/interferences/hfss_emit.py index 99d5d9376..e77a4fd9c 100644 --- a/examples/high_frequency/antenna/interferences/hfss_emit.py +++ b/examples/high_frequency/antenna/interferences/hfss_emit.py @@ -22,7 +22,6 @@ import time import ansys.aedt.core - from ansys.aedt.core.emit_core.emit_constants import ResultType, TxRxMode from ansys.aedt.core.emit_core.nodes.generated import AntennaNode, RadioNode # - @@ -92,8 +91,8 @@ rad1, ant1 = aedtapp.schematic.create_radio_antenna("Bluetooth Low Energy (LE)") rad2, ant2 = aedtapp.schematic.create_radio_antenna("Bluetooth Low Energy (LE)") -#rad1, ant1 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)") -#rad2, ant2 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)") +# rad1, ant1 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)") +# rad2, ant2 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)") # ## Define coupling among RF systems # diff --git a/examples/high_frequency/antenna/interferences/interference.py b/examples/high_frequency/antenna/interferences/interference.py index 294556cc1..8256fd34b 100644 --- a/examples/high_frequency/antenna/interferences/interference.py +++ b/examples/high_frequency/antenna/interferences/interference.py @@ -12,10 +12,10 @@ import sys import tempfile -from ansys.aedt.core.examples.downloads import download_file import plotly.graph_objects as go from ansys.aedt.core import Emit from ansys.aedt.core.emit_core.emit_constants import InterfererType +from ansys.aedt.core.examples.downloads import download_file # - # Define constants. @@ -40,15 +40,11 @@ # Download project -project_name = download_file( - "emit", "interference.aedtz", local_path=temp_folder.name -) +project_name = download_file("emit", "interference.aedtz", local_path=temp_folder.name) # ## Launch EMIT and open project -emitapp = Emit( - non_graphical=NG_MODE, new_desktop=True, project=project_name, version=AEDT_VERSION -) +emitapp = Emit(non_graphical=NG_MODE, new_desktop=True, project=project_name, version=AEDT_VERSION) # ## Get lists of transmitters and receivers # diff --git a/examples/high_frequency/antenna/interferences/protection.py b/examples/high_frequency/antenna/interferences/protection.py index 0bd4b1f56..8f722be28 100644 --- a/examples/high_frequency/antenna/interferences/protection.py +++ b/examples/high_frequency/antenna/interferences/protection.py @@ -18,6 +18,7 @@ import plotly.graph_objects as go from ansys.aedt.core import Emit + # - # from ansys.aedt.core.emit_core.emit_constants import \ @@ -50,9 +51,7 @@ project_name = os.path.join(temp_folder.name, "emit.aedt") -emitapp = Emit( - non_graphical=NG_MODE, new_desktop=True, project=project_name, version=AEDT_VERSION -) +emitapp = Emit(non_graphical=NG_MODE, new_desktop=True, project=project_name, version=AEDT_VERSION) # ## Specify protection levels # @@ -84,13 +83,9 @@ # # Set up the scenario with radios connected to antennas. -bluetooth, blue_ant = emitapp.modeler.components.create_radio_antenna( - "Bluetooth Low Energy (LE)", "Bluetooth" -) +bluetooth, blue_ant = emitapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)", "Bluetooth") gps, gps_ant = emitapp.modeler.components.create_radio_antenna("GPS Receiver", "GPS") -wifi, wifi_ant = emitapp.modeler.components.create_radio_antenna( - "WiFi - 802.11-2012", "WiFi" -) +wifi, wifi_ant = emitapp.modeler.components.create_radio_antenna("WiFi - 802.11-2012", "WiFi") # ## Configure the radios # @@ -103,12 +98,12 @@ if "HR-DSSS" in band.node_name: if "Ch 1-13" in band.node_name: band.enabled = True - band.set_band_power_level(-20, 'dBm') + band.set_band_power_level(-20, "dBm") # Reduce the bluetooth transmit power bands = bluetooth.bands() for band in bands: - band.set_band_power_level(-20, 'dBm') + band.set_band_power_level(-20, "dBm") def get_radio_node(radio_name): diff --git a/examples/high_frequency/antenna/large_scenarios/doppler.py b/examples/high_frequency/antenna/large_scenarios/doppler.py index 32e530222..7f14445ea 100644 --- a/examples/high_frequency/antenna/large_scenarios/doppler.py +++ b/examples/high_frequency/antenna/large_scenarios/doppler.py @@ -15,9 +15,8 @@ import time import ansys.aedt.core -from ansys.aedt.core.examples.downloads import download_multiparts -from ansys.aedt.core.examples.downloads import download_file -from ansys.aedt.core.examples.downloads import unzip +from ansys.aedt.core.examples.downloads import download_file, download_multiparts, unzip + # - # Define constants. @@ -38,15 +37,9 @@ # ## Download 3D component # Download the 3D component that is needed to run the example. -library_path = download_multiparts( - local_path=temp_folder.name -) +library_path = download_multiparts(local_path=temp_folder.name) -zip_file = download_file( - "frtm", - name="doppler_sbr.results.zip", - local_path=temp_folder.name -) +zip_file = download_file("frtm", name="doppler_sbr.results.zip", local_path=temp_folder.name) results = os.path.join(temp_folder.name, "doppler_sbr.results") @@ -118,9 +111,7 @@ yaw=180, name="Devin", ) -car1 = app.modeler.add_vehicle( - input_dir=car_folder, speed=8.7, global_offset=[3, -2.5, 0], name="LuxuryCar" -) +car1 = app.modeler.add_vehicle(input_dir=car_folder, speed=8.7, global_offset=[3, -2.5, 0], name="LuxuryCar") bike1 = app.modeler.add_vehicle( input_dir=bike_folder, speed=2.1, @@ -185,9 +176,11 @@ # PyAEDT offers sophisticated tools for FRTM post-processing # [FRTM](https://aedt.docs.pyansys.com/version/stable/API/visualization/advanced.html#frtm-processing/) -from ansys.aedt.core.visualization.advanced.frtm_visualization import get_results_files -from ansys.aedt.core.visualization.advanced.frtm_visualization import FRTMPlotter -from ansys.aedt.core.visualization.advanced.frtm_visualization import FRTMData +from ansys.aedt.core.visualization.advanced.frtm_visualization import ( + FRTMData, + FRTMPlotter, + get_results_files, +) # ## Load FRTM files # diff --git a/examples/high_frequency/antenna/large_scenarios/time_domain.py b/examples/high_frequency/antenna/large_scenarios/time_domain.py index 032109570..1b55b2066 100644 --- a/examples/high_frequency/antenna/large_scenarios/time_domain.py +++ b/examples/high_frequency/antenna/large_scenarios/time_domain.py @@ -16,6 +16,7 @@ from ansys.aedt.core import Hfss from ansys.aedt.core.examples.downloads import download_sbr_time + # - # Define constants. diff --git a/examples/high_frequency/antenna/patch.py b/examples/high_frequency/antenna/patch.py index f8b7573f1..3b7998540 100644 --- a/examples/high_frequency/antenna/patch.py +++ b/examples/high_frequency/antenna/patch.py @@ -58,7 +58,7 @@ ) # ### Specify units -# Length units can be applied to the modeler in HFSS. The default frequency units, howver, cannot be modified through the Python interface. +# Length units can be applied to the modeler in HFSS. The default frequency units, however, cannot be modified through the Python interface. # # The variable ``freq_units`` can be used throughout this example to ensure that frequency assignments are consistent with the specified units. @@ -73,18 +73,10 @@ # + stackup = Stackup3D(hfss) -ground = stackup.add_ground_layer( - "ground", material="copper", thickness=0.035, fill_material="air" -) -dielectric = stackup.add_dielectric_layer( - "dielectric", thickness="0.5" + length_units, material="Duroid (tm)" -) -signal = stackup.add_signal_layer( - "signal", material="copper", thickness=0.035, fill_material="air" -) -patch = signal.add_patch( - patch_length=9.57, patch_width=9.25, patch_name="Patch", frequency=1e10 -) +ground = stackup.add_ground_layer("ground", material="copper", thickness=0.035, fill_material="air") +dielectric = stackup.add_dielectric_layer("dielectric", thickness="0.5" + length_units, material="Duroid (tm)") +signal = stackup.add_signal_layer("signal", material="copper", thickness=0.035, fill_material="air") +patch = signal.add_patch(patch_length=9.57, patch_width=9.25, patch_name="Patch", frequency=1e10) stackup.resize_around_element(patch) pad_length = [3, 3, 3, 3, 3, 3] # Air bounding box buffer in mm. @@ -102,7 +94,7 @@ # ### Define solution setup # The solution setup specifies details used to run # the finite element analysis in HFSS. The following specifies that adaptive refinement occur at 10 GHz while all other settings are set to -# default values. +# default values. # # The frequency sweep is used to specify the range over which scattering # parameters will be calculated. @@ -121,7 +113,7 @@ hfss.save_project() # Save the project. # - -# The `hfss` instance allows you to query or modify nearly all +# The `hfss` instance allows you to query or modify nearly all # properties of the HFSS design. Here is a simple example demonstrating how to query # information from the ``hfss`` instance. diff --git a/examples/high_frequency/emc/armoured_cable.py b/examples/high_frequency/emc/armoured_cable.py index b4dbf23de..e91fa39b0 100644 --- a/examples/high_frequency/emc/armoured_cable.py +++ b/examples/high_frequency/emc/armoured_cable.py @@ -50,9 +50,7 @@ # Initialize radii of further structures incrementally adding thicknesses. -filling_radius = 1.4142 * ( - core_xy_coord + 3 * c_strand_radius + core_xlpe_ins_thickness + 0.5 -) +filling_radius = 1.4142 * (core_xy_coord + 3 * c_strand_radius + core_xlpe_ins_thickness + 0.5) inner_sheath_radius = filling_radius + 0.75 armour_thickness = 3 armour_radius = inner_sheath_radius + armour_thickness @@ -127,9 +125,7 @@ # # Create the geometry for core strands, fill, and XLPE insulation. -q2d.modeler.create_coordinate_system( - origin=["c_strand_xy_coord", "c_strand_xy_coord", "0mm"], name="CS_c_strand_1" -) +q2d.modeler.create_coordinate_system(origin=["c_strand_xy_coord", "c_strand_xy_coord", "0mm"], name="CS_c_strand_1") q2d.modeler.set_working_coordinate_system("CS_c_strand_1") c1_id = q2d.modeler.create_circle( origin=["0mm", "0mm", "0mm"], @@ -137,9 +133,7 @@ name="c_strand_1", material="copper", ) -c2_id = c1_id.duplicate_along_line( - vector=["0mm", "2.0*c_strand_radius", "0mm"], clones=2 -) +c2_id = c1_id.duplicate_along_line(vector=["0mm", "2.0*c_strand_radius", "0mm"], clones=2) q2d.modeler.duplicate_around_axis(c2_id, axis="Z", angle=360 / core_n_strands, clones=6) c_unite_name = q2d.modeler.unite(q2d.get_all_conductors_names()) @@ -163,9 +157,7 @@ all_obj_names = q2d.get_all_conductors_names() + q2d.get_all_dielectrics_names() -q2d.modeler.duplicate_around_axis( - all_obj_names, axis="Z", angle=360 / cable_n_cores, clones=4 -) +q2d.modeler.duplicate_around_axis(all_obj_names, axis="Z", angle=360 / cable_n_cores, clones=4) cond_names = q2d.get_all_conductors_names() # Define the filling object. @@ -217,9 +209,7 @@ material="steel_stainless", ) arm_strand_1_id.color = (128, 128, 64) -arm_strand_1_id.duplicate_around_axis( - axis="Z", angle="360deg/n_arm_strands", clones="n_arm_strands" -) +arm_strand_1_id.duplicate_around_axis(axis="Z", angle="360deg/n_arm_strands", clones="n_arm_strands") arm_strand_names = q2d.modeler.get_objects_w_string("arm_strand") # Define the outer region that defines the solution domain. @@ -230,16 +220,9 @@ # Assign conductors and reference ground. obj = [q2d.modeler.get_object_from_name(i) for i in cond_names] -[ - q2d.assign_single_conductor( - name="C1" + str(obj.index(i) + 1), assignment=i, conductor_type="SignalLine" - ) - for i in obj -] +[q2d.assign_single_conductor(name="C1" + str(obj.index(i) + 1), assignment=i, conductor_type="SignalLine") for i in obj] obj = [q2d.modeler.get_object_from_name(i) for i in arm_strand_names] -q2d.assign_single_conductor( - name="gnd", assignment=obj, conductor_type="ReferenceGround" -) +q2d.assign_single_conductor(name="gnd", assignment=obj, conductor_type="ReferenceGround") q2d.modeler.fit_all() # Specify the design settings. diff --git a/examples/high_frequency/emc/double_pulse_test.py b/examples/high_frequency/emc/double_pulse_test.py index ec8cb1b6f..af6179a42 100644 --- a/examples/high_frequency/emc/double_pulse_test.py +++ b/examples/high_frequency/emc/double_pulse_test.py @@ -139,9 +139,7 @@ assignment="voltage_g", location=[100, 2900], angle=270 ) voltm_g.parameters["Name"] = "voltage_g" -voltm_ds = circuit.modeler.schematic.components_catalog["Probes:VPROBE_DIFF"].place( - assignment="voltage_ds", location=[2500, 3300], angle=0 -) +voltm_ds = circuit.modeler.schematic.components_catalog["Probes:VPROBE_DIFF"].place(assignment="voltage_ds", location=[2500, 3300], angle=0) voltm_ds.parameters["Name"] = "voltage_ds" amm_top = circuit.modeler.schematic.components_catalog["Probes:IPROBE"].place( assignment="Itop", location=[1100, 5200], angle=0 @@ -171,11 +169,6 @@ # ## Create wiring to complete the schematic. -circuit.modeler.schematic.connect_components_in_series( - assignment=[l_load, r_load], use_wire=True -) -circuit.modeler.schematic.connect_components_in_series( - assignment=[v_gate_top, r_g1], use_wire=True ) circuit.modeler.schematic.connect_components_in_series( assignment=[v_pwl, r_g2], use_wire=True diff --git a/examples/high_frequency/emc/eigenmode.py b/examples/high_frequency/emc/eigenmode.py index c470e6054..a76078ae8 100644 --- a/examples/high_frequency/emc/eigenmode.py +++ b/examples/high_frequency/emc/eigenmode.py @@ -10,9 +10,9 @@ # # HFSS relies on # specification of a lower frequency limit for the search5 -# range. The number of desired modes must also be specified. +# range. The number of desired modes must also be specified. # -# If performance is to be determined over a wide bandwith, +# If performance is to be determined over a wide bandwidth, # the large number of modes can increase compute time. An # iterative search that limits the number of modes being sought # for each iteration improves time and memory requirements. @@ -23,15 +23,17 @@ # # ### Perform imports -# + -from pathlib import Path import tempfile import time -import numpy as np + +# + +from pathlib import Path import ansys.aedt.core +import numpy as np from ansys.aedt.core.examples.downloads import download_file from ansys.aedt.core.generic.settings import settings + # - # ### Define constants @@ -58,9 +60,7 @@ # [example-data](https://github.com/ansys/example-data) # GitHub repository. -project_path = download_file( - "eigenmode", "emi_PCB_house.aedt", temp_folder.name -) +project_path = download_file("eigenmode", "emi_PCB_house.aedt", temp_folder.name) # ### Launch Ansys Electronics Desktop (AEDT) # @@ -100,6 +100,7 @@ # # + def find_resonance(num_modes): # Setup creation next_min_freq = f"{next_fmin} GHz" @@ -116,21 +117,17 @@ def find_resonance(num_modes): hfss.analyze_setup(setup_name, cores=NUM_CORES, use_auto_settings=True) # Get the quantity names for the quality factor values. - q_solution_names = hfss.post.available_report_quantities( - quantities_category="Eigen Q" - ) + q_solution_names = hfss.post.available_report_quantities(quantities_category="Eigen Q") # Get the quantity names for the frequency. - f_solution_names = hfss.post.available_report_quantities( - quantities_category="Eigen Modes" - ) + f_solution_names = hfss.post.available_report_quantities(quantities_category="Eigen Modes") # Store a list of [q_factor, frequency] pairs data = [] get_solution = lambda quantity: hfss.post.get_solution_data(expressions=quantity, report_category="Eigenmode") get_data = lambda solution: float(solution.get_expression_data()[1][0]) - + for q_name, f_name in zip(q_solution_names, f_solution_names): eigen_q_value = get_solution(q_name) eigen_f_value = get_solution(f_name) @@ -157,7 +154,7 @@ def find_resonance(num_modes): while next_fmin < fmax: modes = find_resonance(6) # Limit the search to 6 modes per iteration. - next_fmin = modes[-1][1] / 1E9 + next_fmin = modes[-1][1] / 1e9 setup_nr += 1 cont_res = len(modes) valid_modes = [q for q in modes if q[0] > limit] diff --git a/examples/high_frequency/emc/subcircuit.py b/examples/high_frequency/emc/subcircuit.py index a919f45be..46a77abd9 100644 --- a/examples/high_frequency/emc/subcircuit.py +++ b/examples/high_frequency/emc/subcircuit.py @@ -69,9 +69,7 @@ l1 = circuit.modeler.schematic.create_inductor(value="L_val") c1 = circuit.modeler.schematic.create_capacitor(value="C_val") p2 = circuit.modeler.schematic.create_interface_port(name="Out") -circuit.modeler.schematic.connect_components_in_series( - assignment=[p1, r1, l1, c1, p2], use_wire=True -) +circuit.modeler.schematic.connect_components_in_series(assignment=[p1, r1, l1, c1, p2], use_wire=True) circuit.pop_up() # ## Release AEDT diff --git a/examples/high_frequency/layout/signal_integrity/ami.py b/examples/high_frequency/layout/signal_integrity/ami.py index 15f5468b1..e339cd54f 100644 --- a/examples/high_frequency/layout/signal_integrity/ami.py +++ b/examples/high_frequency/layout/signal_integrity/ami.py @@ -17,9 +17,10 @@ import time import ansys.aedt.core -from ansys.aedt.core.examples.downloads import download_file import numpy as np +from ansys.aedt.core.examples.downloads import download_file from matplotlib import pyplot as plt + # - # Define constants. @@ -49,9 +50,7 @@ # # Files are placed in the destination folder. -project_path = download_file( - "ami", name="ami_usb.aedtz", local_path=temp_folder.name -) +project_path = download_file("ami", name="ami_usb.aedtz", local_path=temp_folder.name) # ## Launch AEDT with Circuit and enable Pandas as the output format @@ -159,21 +158,15 @@ if stop_index_waveform >= sample_index_array.size: stop_index_waveform = sample_index_array.size - 1 -original_data_zoom = original_data_value[plot_name][ - start_index_original_data:stop_index_original_data -] -sampled_data_zoom = ( - sample_waveform[0].values[start_index_waveform:stop_index_waveform] * scale_data -) -sampled_time_zoom = ( - sample_waveform[0].index[start_index_waveform:stop_index_waveform] * scale_time -) +original_data_zoom = original_data_value[plot_name][start_index_original_data:stop_index_original_data] +sampled_data_zoom = sample_waveform[0].values[start_index_waveform:stop_index_waveform] * scale_data +sampled_time_zoom = sample_waveform[0].index[start_index_waveform:stop_index_waveform] * scale_time fig, ax = plt.subplots() ax.plot(sampled_time_zoom, sampled_data_zoom, "r*") ax.plot( - np.array(list(original_data_zoom[:,0])), - original_data_zoom[:,1], + np.array(list(original_data_zoom[:, 0])), + original_data_zoom[:, 1], color="blue", ) ax.set_title("WaveAfterProbe") @@ -208,14 +201,8 @@ plot_name = "V(b_input_43.int_ami_rx.eye_probe.out)" circuit.solution_type = "NexximTransient" -context = {"time_start": "0ps","time_stop": "100ns"} -original_data = circuit.post.get_solution_data( - expressions=plot_name, - setup_sweep_name="NexximTransient", - domain="Time", - variations=circuit.available_variations.nominal, - context=context -) +context = {"time_start": "0ps", "time_stop": "100ns"} +original_data = circuit.post.get_solution_data(expressions=plot_name, setup_sweep_name="NexximTransient", domain="Time", variations=circuit.available_variations.nominal, context=context) # ## Extract sample waveform # @@ -248,12 +235,8 @@ # + tstop = 40.0e-9 tstart = 25.0e-9 -scale_time = ansys.aedt.core.constants.unit_converter( - 1, unit_system="Time", input_units="s", output_units=waveform_sweep_unit -) -scale_data = ansys.aedt.core.constants.unit_converter( - 1, unit_system="Voltage", input_units="V", output_units=waveform_unit -) +scale_time = ansys.aedt.core.constants.unit_converter(1, unit_system="Time", input_units="s", output_units=waveform_sweep_unit) +scale_data = ansys.aedt.core.constants.unit_converter(1, unit_system="Voltage", input_units="V", output_units=waveform_unit) tstop_ns = scale_time * tstop tstart_ns = scale_time * tstart @@ -278,15 +261,9 @@ break cont += 1 -original_data_zoom = original_data_value[ - start_index_original_data:stop_index_original_data -] -original_sweep_zoom = original_data_sweep[ - start_index_original_data:stop_index_original_data -] -original_data_zoom_array = np.array( - list(map(list, zip(original_sweep_zoom, original_data_zoom))) -) +original_data_zoom = original_data_value[start_index_original_data:stop_index_original_data] +original_sweep_zoom = original_data_sweep[start_index_original_data:stop_index_original_data] +original_data_zoom_array = np.array(list(map(list, zip(original_sweep_zoom, original_data_zoom)))) original_data_zoom_array[:, 0] *= 1 sampled_slice = sample_waveform[start_index_waveform:stop_index_waveform] # Build a homogeneous Nx2 array [time, value] from the sliced frames, with a guard for empty slices. @@ -320,11 +297,8 @@ # Create the plot from a start time to stop time in seconds. sample_waveform_array = np.array( - [ - [float(frame[0]), float(np.asarray(frame[1]).ravel()[0])] - for frame in sample_waveform - ], - dtype=float, + [[float(frame[0]), float(np.asarray(frame[1]).ravel()[0])] for frame in sample_waveform], + dtype=float, ) fig, ax2 = plt.subplots() diff --git a/examples/high_frequency/layout/signal_integrity/circuit_transient.py b/examples/high_frequency/layout/signal_integrity/circuit_transient.py index b5ddbab50..d555bf55c 100644 --- a/examples/high_frequency/layout/signal_integrity/circuit_transient.py +++ b/examples/high_frequency/layout/signal_integrity/circuit_transient.py @@ -15,9 +15,10 @@ import time import ansys.aedt.core -from ansys.aedt.core.generic.constants import LineStyle, TraceType, SymbolStyle import numpy as np +from ansys.aedt.core.generic.constants import LineStyle, SymbolStyle, TraceType from matplotlib import pyplot as plt + # - # Define constants. @@ -50,18 +51,14 @@ # # Read an IBIS file and place a buffer in the schematic editor. -ibis = circuit.get_ibis_model_from_file( - os.path.join(circuit.desktop_install_dir, "buflib", "IBIS", "u26a_800.ibs") -) +ibis = circuit.get_ibis_model_from_file(os.path.join(circuit.desktop_install_dir, "buflib", "IBIS", "u26a_800.ibs")) ibs = ibis.buffers["DQ_FULL_800"].insert(0, 0) # ## Place ideal transmission line # # Place an ideal transmission line in the schematic and parametrize it. -tr1 = circuit.modeler.schematic.components_catalog["Ideal Distributed:TRLK_NX"].place( - "tr1" -) +tr1 = circuit.modeler.schematic.components_catalog["Ideal Distributed:TRLK_NX"].place("tr1") tr1.parameters["P"] = "50mm" # ## Place components @@ -129,9 +126,7 @@ trace_type=TraceType.Continuous, color=(0, 0, 255), ) - vout.set_symbol_properties( - style=SymbolStyle.Circle, fill=True, color=(255, 255, 0) - ) + vout.set_symbol_properties(style=SymbolStyle.Circle, fill=True, color=(255, 255, 0)) ll = new_report.limit_lines[0] ll.set_line_properties( style=LineStyle.Solid, diff --git a/examples/high_frequency/layout/signal_integrity/serdes_differential.py b/examples/high_frequency/layout/signal_integrity/serdes_differential.py index 410903205..b4b056ac6 100644 --- a/examples/high_frequency/layout/signal_integrity/serdes_differential.py +++ b/examples/high_frequency/layout/signal_integrity/serdes_differential.py @@ -13,7 +13,6 @@ import tempfile import ansys.aedt.core - import pyedb from pyedb.misc.downloads import download_file # - diff --git a/examples/high_frequency/multiphysics/hfss_mechanical.py b/examples/high_frequency/multiphysics/hfss_mechanical.py index 354cdcf11..9535040dc 100644 --- a/examples/high_frequency/multiphysics/hfss_mechanical.py +++ b/examples/high_frequency/multiphysics/hfss_mechanical.py @@ -36,9 +36,7 @@ # # Download and open the project. Save it to the temporary folder. -project_name = download_via_wizard( - local_path=temp_folder.name -) +project_name = download_via_wizard(local_path=temp_folder.name) # ## Start HFSS # diff --git a/examples/high_frequency/multiphysics/microwave_oven.py b/examples/high_frequency/multiphysics/microwave_oven.py index f82d6fd76..afa4e1021 100644 --- a/examples/high_frequency/multiphysics/microwave_oven.py +++ b/examples/high_frequency/multiphysics/microwave_oven.py @@ -11,17 +11,18 @@ # # ### Perform imports -# + -import ansys.aedt.core import os -import time import tempfile +import time -import pyvista +# + +import ansys.aedt.core import numpy as np +import pyvista from ansys.aedt.core import generate_unique_name from ansys.aedt.core.examples.downloads import download_file from ansys.aedt.core.visualization.plot.pdf import AnsysReport + # - # ### Define constants. @@ -43,12 +44,8 @@ # Download and open the project. Save it to the temporary working folder. -parasolid_path = download_file( - source="oven", name="gingerbread.x_t", local_path=working_dir.name -) -oven_path = download_file( - source="oven", name="microwave_oven.aedt", local_path=working_dir.name -) +parasolid_path = download_file(source="oven", name="gingerbread.x_t", local_path=working_dir.name) +oven_path = download_file(source="oven", name="microwave_oven.aedt", local_path=working_dir.name) # ### Launch HFSS # Open AEDT and initialize the microwave oven project. @@ -67,7 +64,7 @@ # This phase is fundamental because we need to assign correct material properties that are valid for both electrical # and thermal analysis. # -# PyAEDT simplifies the creation and modification of a material +# PyAEDT simplifies the creation and modification of a material # definitions using _getter_ and _setter_ methods. In this example we modify 5 material parameters. ginger_material = hfss.materials.add_material(name="ginger_bread") @@ -79,7 +76,7 @@ # ### Import the gingerbread man and assign material # -# Once the object is imported all of its properties can be edited. +# Once the object is imported all of its properties can be edited. # We are going to move the gingerbread at the center of the plate and assign material to it. # # Finally, we are going to change the transparency of the glass bowl. @@ -96,7 +93,7 @@ # # We now save an image of the model as a PNG file to insert into the report later. -hfss.post.export_model_picture(full_name=os.path.join(working_dir.name, 'ginger_bread_cookie.png')) +hfss.post.export_model_picture(full_name=os.path.join(working_dir.name, "ginger_bread_cookie.png")) # ### Launch Icepak # @@ -119,7 +116,7 @@ # ### Thermal boundaries # -# Main thermal boundaries will be free opening of the microwave oven. +# Main thermal boundaries will be free opening of the microwave oven. # # In this example we set 2 different types of openings on the two faces of the oven. @@ -149,14 +146,14 @@ # ### Icepak mesh settings # -# Icepak mesh settings are used to optimize the simulation time and accuracy. +# Icepak mesh settings are used to optimize the simulation time and accuracy. ipk.mesh.global_mesh_region.manual_settings = True ipk.mesh.global_mesh_region.settings["MaxElementSizeX"] = "15mm" ipk.mesh.global_mesh_region.settings["MaxElementSizeY"] = "15mm" ipk.mesh.global_mesh_region.settings["MaxElementSizeZ"] = "15mm" -ipk.mesh.global_mesh_region.settings["BufferLayers"] = '2' -ipk.mesh.global_mesh_region.settings["MaxLevels"] = '2' +ipk.mesh.global_mesh_region.settings["BufferLayers"] = "2" +ipk.mesh.global_mesh_region.settings["MaxLevels"] = "2" ipk.mesh.global_mesh_region.update() # ### Icepak solution setup @@ -180,7 +177,10 @@ ginger_bread_thermal.transparency = 1 objects = ipk.modeler.non_model_objects[::] + ["glassBowl"] -microwave_objects = ipk.post.export_model_obj(objects, export_as_multiple_objects=True, ) +microwave_objects = ipk.post.export_model_obj( + objects, + export_as_multiple_objects=True, +) # - # ### Initialize Ansys report @@ -190,9 +190,7 @@ # that include text, images, tables and charts. # + -report = AnsysReport( - version=ipk.aedt_version_id, design_name=ipk.design_name, project_name=ipk.project_name -) +report = AnsysReport(version=ipk.aedt_version_id, design_name=ipk.design_name, project_name=ipk.project_name) report.create() report.add_section() report.add_chapter(f"Ansys GingerBread Recipe") @@ -202,8 +200,7 @@ report.add_text("Leave to cool for about 10 mins.") report.add_text("Step 2: Tip the flour, baking soda and spices into a large bowl.") -report.add_text( - "Add the warm syrup mixture and the egg, stir everything together, then gently knead in the bowl until smooth and streak-free.") +report.add_text("Add the warm syrup mixture and the egg, stir everything together, then gently knead in the bowl until smooth and streak-free.") report.add_text("The dough will firm up once cooled. Wrap in cling film and chill for at least 30 mins.") report.add_text("Step 3: Remove the dough from the fridge, leave at room temperature until softened. ") @@ -214,8 +211,7 @@ report.add_text("1- Ansys HFSS") report.add_text("2- PyAEDT") -report.add_image(path=os.path.join(working_dir.name, 'ginger_bread_cookie.png'), - caption="HFSS Design of Ansys Microwave Oven") +report.add_image(path=os.path.join(working_dir.name, "ginger_bread_cookie.png"), caption="HFSS Design of Ansys Microwave Oven") report.add_page_break() report.add_sub_chapter("Determine cooking time... with Icepak") @@ -253,14 +249,11 @@ def get_average_temperature(): # the gingerbread inside the microwave oven with velocity streamline plot. # The view is set to front $(y-z)$. + def generate_streamline(stop): def generate_case(quantity_in, field_time, assignment=["ovenCavity", "rotating_cylinder"]): - f1 = ipk.post.create_fieldplot_volume(assignment=assignment, - quantity=quantity_in, - intrinsics={"Time": f"{field_time}s"}) - air_ux_case = ipk.post.export_field_plot(plot_name=f1.name, - output_dir=working_dir.name, - file_format="case") + f1 = ipk.post.create_fieldplot_volume(assignment=assignment, quantity=quantity_in, intrinsics={"Time": f"{field_time}s"}) + air_ux_case = ipk.post.export_field_plot(plot_name=f1.name, output_dir=working_dir.name, file_format="case") mesh_in = pyvista.read(air_ux_case) return mesh_in @@ -285,9 +278,7 @@ def generate_case(quantity_in, field_time, assignment=["ovenCavity", "rotating_c ux_block.point_data["Velocity"] = velocity ux_block.point_data["Temperature"] = temperature seed = pyvista.Box(bounds=(50, 260, 0, 500, -1, 150), level=10) - streamlines = ux_block.streamlines_from_source( - seed, max_time=200.0, integration_direction="both" - ) + streamlines = ux_block.streamlines_from_source(seed, max_time=200.0, integration_direction="both") pl = pyvista.Plotter(off_screen=True, window_size=(3840, 2160)) for filename, color, opacity in microwave_objects: @@ -334,10 +325,9 @@ def generate_temps(stop): ) for mw_obj in microwave_objects: pl.add_object(mw_obj[0], mw_obj[1], mw_obj[2]) - pl.camera_position = 'yz' + pl.camera_position = "yz" pl.elevation_angle = 20 - pl.plot(export_image_path=os.path.join(working_dir.name, f'{generate_unique_name("Temperature")}.jpg'), - show=False) + pl.plot(export_image_path=os.path.join(working_dir.name, f'{generate_unique_name("Temperature")}.jpg'), show=False) return pl @@ -363,13 +353,11 @@ def generate_temps(stop): plot4 = generate_temps(stop_time) report.add_image(plot4.image_file, f"GingerBread at the end of cooking.") else: - ipk.logger.info( - f'Mean Temperature in the Gingerbread is {mean_temperature} after {stop_time}s in the microwave') + ipk.logger.info(f"Mean Temperature in the Gingerbread is {mean_temperature} after {stop_time}s in the microwave") if mean_temperature > 30: report.add_text(f"Gingerbread is almost ready. Don't worry we will notify you when ready.") output_file = generate_streamline(stop_time) - report.add_image(os.path.join(working_dir.name, "streamlines.png"), - f"GingerBread while cooking after {stop_time}s") + report.add_image(os.path.join(working_dir.name, "streamlines.png"), f"GingerBread while cooking after {stop_time}s") else: report.add_text(f"Take a cup of tea and relax. It will take longer.") ipk.save_project() From 09e462fff56307827eaf912f782e56c682e9d7a3 Mon Sep 17 00:00:00 2001 From: Devin Date: Thu, 19 Mar 2026 04:55:52 -0500 Subject: [PATCH 2/2] Cleanup - Clean up whitespace and spelling issues. - Put commands on a single line where space permits. --- examples/high_frequency/emc/busbar.py | 9 +-- .../high_frequency/emc/double_pulse_test.py | 18 ++--- .../coplanar_waveguide.py | 27 +++---- .../distributed_filter.py | 35 ++++---- .../radiofrequency_mmwave/iris_filter.py | 5 +- .../low_frequency/general/control_program.py | 5 +- .../low_frequency/general/electrostatic.py | 25 ++---- .../low_frequency/general/external_circuit.py | 21 ++--- .../low_frequency/general/field_export.py | 9 +-- examples/low_frequency/general/resistance.py | 5 +- .../general/twin_builder/rc_circuit.py | 1 + .../general/twin_builder/static_rom.py | 9 +-- .../magnetic/magneto_motive_line.py | 5 +- .../motor/aedt_motor/ipm_optimization.py | 28 +++---- .../motor/aedt_motor/magnet_segmentation.py | 5 +- .../motor/aedt_motor/pm_synchronous.py | 79 +++++++++---------- .../low_frequency/motor/aedt_motor/rmxpert.py | 1 + .../motor/aedt_motor/transformer.py | 21 ++--- .../aedt_motor/transformer_inductance.py | 1 + examples/template.py | 14 ++-- 20 files changed, 136 insertions(+), 187 deletions(-) diff --git a/examples/high_frequency/emc/busbar.py b/examples/high_frequency/emc/busbar.py index 0fb9c8f08..3d00fb5cb 100644 --- a/examples/high_frequency/emc/busbar.py +++ b/examples/high_frequency/emc/busbar.py @@ -15,6 +15,7 @@ import time import ansys.aedt.core + # - # Define constants. @@ -180,12 +181,8 @@ # # Capacitances - Original Matrix. -original_matrix_self = q3d.matrices[0].get_sources_for_plot( - get_self_terms=True, get_mutual_terms=False -) -original_matrix_mutual = q3d.matrices[0].get_sources_for_plot( - get_self_terms=False, get_mutual_terms=True -) +original_matrix_self = q3d.matrices[0].get_sources_for_plot(get_self_terms=True, get_mutual_terms=False) +original_matrix_mutual = q3d.matrices[0].get_sources_for_plot(get_self_terms=False, get_mutual_terms=True) # ACL - Reduced Matrix MR_1_Series diff --git a/examples/high_frequency/emc/double_pulse_test.py b/examples/high_frequency/emc/double_pulse_test.py index af6179a42..a8867b761 100644 --- a/examples/high_frequency/emc/double_pulse_test.py +++ b/examples/high_frequency/emc/double_pulse_test.py @@ -21,6 +21,7 @@ import ansys.aedt.core from ansys.aedt.core.generic.constants import Setups + # - # Define constants. @@ -169,10 +170,9 @@ # ## Create wiring to complete the schematic. -) -circuit.modeler.schematic.connect_components_in_series( - assignment=[v_pwl, r_g2], use_wire=True -) +circuit.modeler.schematic.connect_components_in_series(assignment=[l_load, r_load], use_wire=True) +circuit.modeler.schematic.connect_components_in_series(assignment=[v_gate_top, r_g1], use_wire=True) +circuit.modeler.schematic.connect_components_in_series(assignment=[v_pwl, r_g2], use_wire=True) circuit.modeler.schematic.create_wire( [ [v_dc_bus.pins[1].location[0], v_dc_bus.pins[1].location[1]], @@ -327,18 +327,14 @@ [voltm_ds.pins[1].location[0], y_lower_pin], ] ) -gnd = circuit.modeler.schematic.create_gnd( - location=[voltm_ds.pins[1].location[0], y_lower_pin - 100] -) +gnd = circuit.modeler.schematic.create_gnd(location=[voltm_ds.pins[1].location[0], y_lower_pin - 100]) r_g1.pins[1].connect_to_component(assignment=nmos_h.pins[1], use_wire=True) r_g2.pins[1].connect_to_component(assignment=nmos_l.pins[1], use_wire=True) # ## Create a transient setup setup_name = "MyTransient" -setup1 = circuit.create_setup( - name=setup_name, setup_type=Setups.NexximTransient -) +setup1 = circuit.create_setup(name=setup_name, setup_type=Setups.NexximTransient) setup1.props["TransientData"] = ["0.05ns", "15us"] circuit.modeler.zoom_to_fit() @@ -359,7 +355,7 @@ ], domain="Time", plot_name="Plot V,I", - context={"time_stop": "15us"} + context={"time_stop": "15us"}, ) # ## Release AEDT diff --git a/examples/high_frequency/radiofrequency_mmwave/coplanar_waveguide.py b/examples/high_frequency/radiofrequency_mmwave/coplanar_waveguide.py index 5e8f8412f..a21bbe943 100644 --- a/examples/high_frequency/radiofrequency_mmwave/coplanar_waveguide.py +++ b/examples/high_frequency/radiofrequency_mmwave/coplanar_waveguide.py @@ -15,6 +15,7 @@ import time import ansys.aedt.core + # - # ### Define constants @@ -37,8 +38,8 @@ # ### Launch AEDT # -# Launch an instance of the Ansys Electronics Desktop (AEDT) in graphical mode. -# The ``Q2d`` class inserts a 2-D Extractor design in AEDT. +# Launch an instance of the Ansys Electronics Desktop (AEDT) in graphical mode. +# The ``Q2d`` class inserts a 2-D Extractor design in AEDT. q2d = ansys.aedt.core.Q2d( version=AEDT_VERSION, @@ -73,7 +74,7 @@ # # Expressions are passed to the methods that we'll use to # create the geometric cross-section of the -# coplanar waveguide. These expressions depend on the +# coplanar waveguide. These expressions depend on the # independent parameters defined in the previous cell, ``cpw_params``. delta_w_half = "cond_h/e_factor" @@ -93,7 +94,7 @@ for name, value in cpw_params.items(): q2d[name] = value -# Create the signal conductor by drawing two lines and connecting them to +# Create the signal conductor by drawing two lines and connecting them to # create a 2D sheet. # + @@ -108,9 +109,7 @@ q2d.modeler.move(assignment=[top_line_obj], vector=[delta_w_half, 0, 0]) q2d.modeler.connect([base_line_obj, top_line_obj]) -q2d.modeler.move( - assignment=[base_line_obj], vector=["gnd_w+clearance", 0, 0] -) +q2d.modeler.move(assignment=[base_line_obj], vector=["gnd_w+clearance", 0, 0]) # - # Create adjacent ground layers. @@ -175,19 +174,13 @@ e_obj_list.append(e_obj) e_obj_1 = e_obj_list[0] q2d.modeler.unite(e_obj_list) - _ = q2d.modeler.sweep_along_vector( - assignment=e_obj_1.id, sweep_vector=[0, "sm_h", 0] - ) + _ = q2d.modeler.sweep_along_vector(assignment=e_obj_1.id, sweep_vector=[0, "sm_h", 0]) sm_obj_list.append(e_obj_1) -new_obj = q2d.modeler.create_rectangle( - origin=["gnd_w", layer_2_lh, 0], sizes=["clearance", "sm_h"] -) +new_obj = q2d.modeler.create_rectangle(origin=["gnd_w", layer_2_lh, 0], sizes=["clearance", "sm_h"]) sm_obj_list.append(new_obj) -new_obj2 = q2d.modeler.create_rectangle( - origin=["gnd_w", layer_2_lh, 0], sizes=["clearance", "sm_h"] -) +new_obj2 = q2d.modeler.create_rectangle(origin=["gnd_w", layer_2_lh, 0], sizes=["clearance", "sm_h"]) q2d.modeler.move(assignment=[new_obj2], vector=["sig_bot_w+clearance", 0, 0]) sm_obj_list.append(new_obj2) @@ -237,7 +230,7 @@ # ### Define solution setup # -# The solution steup specifies the frequency range for the solution and other +# The solution steup specifies the frequency range for the solution and other # solution settings # + diff --git a/examples/high_frequency/radiofrequency_mmwave/distributed_filter.py b/examples/high_frequency/radiofrequency_mmwave/distributed_filter.py index c82847b17..ab9071786 100644 --- a/examples/high_frequency/radiofrequency_mmwave/distributed_filter.py +++ b/examples/high_frequency/radiofrequency_mmwave/distributed_filter.py @@ -1,6 +1,6 @@ # # Distributed filter design # -# This example demonstrates using PyAEDT and the ``FilterSolutions`` module to design a low-pass Chebyshev-I filter, +# This example demonstrates using PyAEDT and the ``FilterSolutions`` module to design a low-pass Chebyshev-I filter, # visualize its frequency response, and export the distributed model to HFSS. # # Keywords: **filter solutions** @@ -13,16 +13,22 @@ import os import tempfile import time + import ansys.aedt.core import ansys.aedt.core.filtersolutions import matplotlib.pyplot as plt from ansys.aedt.core.filtersolutions_core.attributes import FilterClass, FilterType +from ansys.aedt.core.filtersolutions_core.distributed_substrate import ( + SubstrateEr, + SubstrateResistivity, + SubstrateType, +) +from ansys.aedt.core.filtersolutions_core.distributed_topology import TopologyType from ansys.aedt.core.filtersolutions_core.export_to_aedt import ExportFormat from ansys.aedt.core.filtersolutions_core.ideal_response import ( SParametersResponseColumn, ) -from ansys.aedt.core.filtersolutions_core.distributed_topology import TopologyType -from ansys.aedt.core.filtersolutions_core.distributed_substrate import SubstrateType, SubstrateEr, SubstrateResistivity + # - # ### Define constants. @@ -47,6 +53,7 @@ # on the same graph, using a logarithmic scale for the x-axis (frequency) and a linear scale # for the y-axis (magnitude in dB). + def plot(data_list): for freq, data, label in data_list: plt.plot(freq, data, linewidth=2.0, label=label) @@ -58,15 +65,18 @@ def plot(data_list): plt.grid() plt.show() + # ### Create distributed filter design # # Create a distributed filter design using DistributedDesign function form FilterSolutions # module and assign the class, type, frequency, and order. -# This example creates a low-pass Chebyshev-I filter with a center +# This example creates a low-pass Chebyshev-I filter with a center # frequency of 2 GHz and a filter order of 7. The default values for other parameters are used. -# These design is created in the specified AEDT version. The parmeters define the filter's characteristics. +# These design is created in the specified AEDT version. The parameters define the filter's characteristics. -distributed_design = ansys.aedt.core.filtersolutions.DistributedDesign(version=AEDT_VERSION,) +distributed_design = ansys.aedt.core.filtersolutions.DistributedDesign( + version=AEDT_VERSION, +) distributed_design.attributes.filter_class = FilterClass.LOW_PASS distributed_design.attributes.filter_type = FilterType.CHEBYSHEV_I distributed_design.attributes.pass_band_center_frequency = "2 GHz" @@ -114,7 +124,7 @@ def plot(data_list): # ### Export distributed model of the filter to HFSS 3D Layout and simulate # -# The designed filter is exported as a distributed model to Ansys HFSS 3D Layout +# The designed filter is exported as a distributed model to Ansys HFSS 3D Layout # and simulated using the specified export parameters. # During export, the target schematic name is set, along with any required reports. # In this workflow: @@ -127,7 +137,7 @@ def plot(data_list): distributed_design.export_to_aedt.schematic_name = project_name distributed_design.export_to_aedt.simulate_after_export_enabled = True distributed_design.export_to_aedt.optimitrics_enabled = False -distributed_design.export_to_aedt.include_forward_transfer_s21_enabled = True +distributed_design.export_to_aedt.include_forward_transfer_s21_enabled = True distributed_design.export_to_aedt.include_return_loss_s11_enabled = True distributed_design.export_to_aedt.insert_hfss_3dl_design = True hfss3dl = distributed_design.export_to_aedt.export_design(export_format=ExportFormat.DIRECT_TO_AEDT) @@ -140,7 +150,7 @@ def plot(data_list): # To update the plot with the simulated data, the HFSS 3D Layout design is analyzed using the analyze method. # The S-parameters S11 and S21 in dB are extracted from the simulation results and plotted against frequency. # The simulated S-parameters are overlaid on the synthesized frequency response for comparison. - + hfss3dl.analyze() solutions = hfss3dl.post.get_solution_data( expressions=hfss3dl.get_traces_for_plot(category="S"), @@ -150,12 +160,7 @@ def plot(data_list): sim_freq_ghz = [i * 1e9 for i in sim_freq] sim_s11_db = solutions.get_expression_data("S(Port1,Port1)", "dB20")[1] sim_s21_db = solutions.get_expression_data("S(Port2,Port1)", "dB20")[1] -plot_data = [ - (freq, s11_db, "Synthesized S11"), - (freq, s21_db, "Synthesized S21"), - (sim_freq_ghz, sim_s11_db, "Simulated S11"), - (sim_freq_ghz, sim_s21_db, "Simulated S21") -] +plot_data = [(freq, s11_db, "Synthesized S11"), (freq, s21_db, "Synthesized S21"), (sim_freq_ghz, sim_s11_db, "Simulated S11"), (sim_freq_ghz, sim_s21_db, "Simulated S21")] plot(plot_data) # diff --git a/examples/high_frequency/radiofrequency_mmwave/iris_filter.py b/examples/high_frequency/radiofrequency_mmwave/iris_filter.py index b0cadcfcc..b65477de6 100644 --- a/examples/high_frequency/radiofrequency_mmwave/iris_filter.py +++ b/examples/high_frequency/radiofrequency_mmwave/iris_filter.py @@ -18,6 +18,7 @@ import time import ansys.aedt.core + # - # Define constants. @@ -92,9 +93,7 @@ for v in wgparams[key]: this_key = key + str(count) hfss[this_key] = str(v) + wgparams["units"] - var_mapping[ - this_key - ] = v # Used to parse expressions and generate numerical values. + var_mapping[this_key] = v # Used to parse expressions and generate numerical values. count += 1 if len(wgparams["l"]) % 2 == 0: diff --git a/examples/low_frequency/general/control_program.py b/examples/low_frequency/general/control_program.py index 63c68b855..b8c524842 100644 --- a/examples/low_frequency/general/control_program.py +++ b/examples/low_frequency/general/control_program.py @@ -17,6 +17,7 @@ from ansys.aedt.core import Maxwell2d from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -43,9 +44,7 @@ name="ControlProgramDemo.aedt", local_path=temp_folder.name, ) -ctrl_prg_file = download_file( - source="maxwell_ctrl_prg", name="timestep_only.py", local_path=temp_folder.name -) +ctrl_prg_file = download_file(source="maxwell_ctrl_prg", name="timestep_only.py", local_path=temp_folder.name) # ## Launch Maxwell 2D # diff --git a/examples/low_frequency/general/electrostatic.py b/examples/low_frequency/general/electrostatic.py index ea8e35c07..cb167b723 100644 --- a/examples/low_frequency/general/electrostatic.py +++ b/examples/low_frequency/general/electrostatic.py @@ -18,6 +18,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -39,9 +40,7 @@ # # Set the local temporary folder to export the Excel (XLSX) file to. -file_name_xlsx = download_file( - source="field_line_traces", name="my_copper.xlsx", local_path=temp_folder.name -) +file_name_xlsx = download_file(source="field_line_traces", name="my_copper.xlsx", local_path=temp_folder.name) # ## Initialize dictionaries # @@ -131,9 +130,7 @@ poly1_points = [[-9, 2, 0], [-4, 2, 0], [2, -2, 0], [8, 2, 0]] poly2_points = [[-9, 0, 0], [9, 0, 0]] -poly1_id = m2d.modeler.create_polyline( - points=poly1_points, segment_type="Spline", name="Poly1" -) +poly1_id = m2d.modeler.create_polyline(points=poly1_points, segment_type="Spline", name="Poly1") poly2_id = m2d.modeler.create_polyline(points=poly2_points, name="Poly2") m2d.modeler.split(assignment=[poly1_id, poly2_id], plane="YZ", sides="NegativeOnly") m2d.modeler.create_region(pad_value=[20, 100, 20, 100]) @@ -166,15 +163,9 @@ # Evaluate the E Field tangential component along the given polylines. # Add these operations to the **Named Expression** list in the field calculator. -e_line = m2d.post.fields_calculator.add_expression( - calculation="e_line", assignment=None -) -m2d.post.fields_calculator.expression_plot( - calculation="e_line", assignment="Poly1", names=[e_line] -) -m2d.post.fields_calculator.expression_plot( - calculation="e_line", assignment="Poly12", names=[e_line] -) +e_line = m2d.post.fields_calculator.add_expression(calculation="e_line", assignment=None) +m2d.post.fields_calculator.expression_plot(calculation="e_line", assignment="Poly1", names=[e_line]) +m2d.post.fields_calculator.expression_plot(calculation="e_line", assignment="Poly12", names=[e_line]) # ## Create field line traces plot # @@ -203,9 +194,7 @@ # Export the field line traces plot. # For the field lint traces plot, the export file format is ``.fldplt``. -m2d.post.export_field_plot( - plot_name="LineTracesTest", output_dir=temp_folder.name, file_format="fldplt" -) +m2d.post.export_field_plot(plot_name="LineTracesTest", output_dir=temp_folder.name, file_format="fldplt") # ## Export mesh field plot # diff --git a/examples/low_frequency/general/external_circuit.py b/examples/low_frequency/general/external_circuit.py index 2c5d2e87e..2a7f4bd4e 100644 --- a/examples/low_frequency/general/external_circuit.py +++ b/examples/low_frequency/general/external_circuit.py @@ -12,6 +12,7 @@ import time import ansys.aedt.core + # - # Define constants. @@ -74,21 +75,13 @@ # # Create copper coils and a vacuum region. Assign mesh operations, and then assign a balloon boundary to the region edges. -coil1_id = m2d.modeler.create_circle( - orientation="Z", origin=[0, 0, 0], radius=10, name="coil1", material="copper" -) -coil2_id = m2d.modeler.create_circle( - orientation="Z", origin=[25, 0, 0], radius=10, name="coil2", material="copper" -) -coil3_id = m2d.modeler.create_circle( - orientation="Z", origin=[50, 0, 0], radius=10, name="coil3", material="copper" -) +coil1_id = m2d.modeler.create_circle(orientation="Z", origin=[0, 0, 0], radius=10, name="coil1", material="copper") +coil2_id = m2d.modeler.create_circle(orientation="Z", origin=[25, 0, 0], radius=10, name="coil2", material="copper") +coil3_id = m2d.modeler.create_circle(orientation="Z", origin=[50, 0, 0], radius=10, name="coil3", material="copper") region = m2d.modeler.create_region(pad_value=[200, 400, 200, 400]) -m2d.mesh.assign_length_mesh( - assignment=[coil1_id, coil2_id, coil3_id, region], maximum_length=5 -) +m2d.mesh.assign_length_mesh(assignment=[coil1_id, coil2_id, coil3_id, region], maximum_length=5) m2d.assign_vector_potential(assignment=region.edges, vector_value=0) @@ -223,9 +216,7 @@ netlist_file = os.path.join(temp_folder.name, "_netlist.sph") circuit.export_netlist_from_schematic(netlist_file) -m2d.edit_external_circuit( - netlist_file_path=netlist_file, schematic_design_name=circuit_name -) +m2d.edit_external_circuit(netlist_file_path=netlist_file, schematic_design_name=circuit_name) # ## Analyze setup # diff --git a/examples/low_frequency/general/field_export.py b/examples/low_frequency/general/field_export.py index fd161cbf2..86c591e12 100644 --- a/examples/low_frequency/general/field_export.py +++ b/examples/low_frequency/general/field_export.py @@ -18,6 +18,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file from ansys.aedt.core.generic.constants import unit_converter + # - # Define constants. @@ -49,9 +50,7 @@ # # Initialize and launch Maxwell 3D, providing the version and the path of the project. -m3d = ansys.aedt.core.Maxwell3d( - project=project_path, version=AEDT_VERSION, non_graphical=NG_MODE -) +m3d = ansys.aedt.core.Maxwell3d(project=project_path, version=AEDT_VERSION, non_graphical=NG_MODE) # ## Create setup and validate # @@ -157,9 +156,7 @@ file_format="aedtplt", ) m3d.post.create_fieldplot_surface( - assignment=[ - o for o in m3d.modeler.solid_objects if o.material_name == "copper" - ], + assignment=[o for o in m3d.modeler.solid_objects if o.material_name == "copper"], quantity="Mag_J", plot_name="Mag_J_Coils_{}_ms".format(time_step), intrinsics={"Time": "ms"}, diff --git a/examples/low_frequency/general/resistance.py b/examples/low_frequency/general/resistance.py index c9a95af18..2dd74511e 100644 --- a/examples/low_frequency/general/resistance.py +++ b/examples/low_frequency/general/resistance.py @@ -15,10 +15,11 @@ import time import ansys.aedt.core -from ansys.aedt.core.generic.constants import SolutionsMaxwell2D from ansys.aedt.core.examples.downloads import download_file +from ansys.aedt.core.generic.constants import SolutionsMaxwell2D from ansys.aedt.core.modules.boundary.maxwell_boundary import MatrixElectric from ansys.aedt.core.visualization.plot.pdf import AnsysReport + # - # Define constants. @@ -319,4 +320,4 @@ # can retrieve those project files. The following cell # removes all temporary files, including the project folder. -temp_folder.cleanup() \ No newline at end of file +temp_folder.cleanup() diff --git a/examples/low_frequency/general/twin_builder/rc_circuit.py b/examples/low_frequency/general/twin_builder/rc_circuit.py index dd7f767c3..1bb0aff5c 100644 --- a/examples/low_frequency/general/twin_builder/rc_circuit.py +++ b/examples/low_frequency/general/twin_builder/rc_circuit.py @@ -15,6 +15,7 @@ import time import ansys.aedt.core + # - # Define constants. diff --git a/examples/low_frequency/general/twin_builder/static_rom.py b/examples/low_frequency/general/twin_builder/static_rom.py index b64299caa..0bf8dc1f9 100644 --- a/examples/low_frequency/general/twin_builder/static_rom.py +++ b/examples/low_frequency/general/twin_builder/static_rom.py @@ -19,6 +19,7 @@ from ansys.aedt.core import TwinBuilder from ansys.aedt.core.examples import downloads + # - # Define constants. @@ -58,18 +59,14 @@ ) downloads.download_twin_builder_data(source_build_conf_file, True, temp_folder.name) -downloads.download_twin_builder_data( - source_props_conf_file, True, temp_folder.name -) +downloads.download_twin_builder_data(source_props_conf_file, True, temp_folder.name) # Target folder to extract project files. twin_builder_data_folder = os.path.join(temp_folder.name, "twin_builder") data_folder = os.path.join(twin_builder_data_folder, "Ex04") # Unzip training data and config file -downloads.unzip( - os.path.join(twin_builder_data_folder, source_snapshot_data_zipfilename), data_folder -) +downloads.unzip(os.path.join(twin_builder_data_folder, source_snapshot_data_zipfilename), data_folder) shutil.copyfile( os.path.join(twin_builder_data_folder, source_build_conf_file), os.path.join(data_folder, source_build_conf_file), diff --git a/examples/low_frequency/magnetic/magneto_motive_line.py b/examples/low_frequency/magnetic/magneto_motive_line.py index 7dbdfc5b0..50fb6c91b 100644 --- a/examples/low_frequency/magnetic/magneto_motive_line.py +++ b/examples/low_frequency/magnetic/magneto_motive_line.py @@ -23,6 +23,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -126,9 +127,7 @@ # # Create a parametrized polyline, specifying its ends. -poly = m2d.modeler.create_polyline( - points=[["xl", -10, 0], ["xl", 10, 0]], name="polyline_sweep" -) +poly = m2d.modeler.create_polyline(points=[["xl", -10, 0], ["xl", 10, 0]], name="polyline_sweep") # ## Add parametric sweep # diff --git a/examples/low_frequency/motor/aedt_motor/ipm_optimization.py b/examples/low_frequency/motor/aedt_motor/ipm_optimization.py index d26499215..2092a2df7 100644 --- a/examples/low_frequency/motor/aedt_motor/ipm_optimization.py +++ b/examples/low_frequency/motor/aedt_motor/ipm_optimization.py @@ -7,7 +7,7 @@ # The model applies electrical symmetry # and neglects end-winding 3D effects, thereby allowing analysis of one # quarter of a -# 2D cross-section. This common approach greatly +# 2D cross-section. This common approach greatly # accelerates the analysis relative to a full 3D analysis. The # model cross-section is shown below. # @@ -27,6 +27,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file + # - # ### Define constants @@ -51,7 +52,7 @@ # ### Download the example project file # # Many PyAEDT examples use project files or data from the -# [Ansys example data repository](https://www.github.com/ansys/example-data) +# [Ansys example data repository](https://www.github.com/ansys/example-data) # in GitHub. # # > *Note:* You can update ``settings`` as shown below @@ -105,13 +106,12 @@ # ### Assign the material definition to the permanent magnets # # Retrieve all permanent magnet objects using the string "Mag" for -# the object name and assign the material definition +# the object name and assign the material definition # ``"mat_sweep[mat_index]"``. This allows the material assignment to # be modified by changing the value of ``mat_index`` in Maxwell 2D. # + -magnets = [o for name, o in m2d.modeler.objects_by_name.items() - if "Mag" in name] +magnets = [o for name, o in m2d.modeler.objects_by_name.items() if "Mag" in name] for mag in magnets: mag.material_name = "mat_sweep[mat_index]" @@ -128,12 +128,12 @@ # scope of the parametric investigation. This approach provides a powerful # interface for advanced design of experiments and optimization. -param_sweep = m2d.parametrics.add( # Define parametric analysis. - variable="bridge", # Single value for "bridge" +param_sweep = m2d.parametrics.add( # Define parametric analysis. + variable="bridge", # Single value for "bridge" start_point="0.5mm", variation_type="SingleValue", ) -param_sweep.add_variation( # Sweep "din". +param_sweep.add_variation( # Sweep "din". sweep_variable="din", start_point=78, end_point=80, @@ -141,7 +141,7 @@ units="mm", variation_type="LinearStep", ) -param_sweep.add_variation( # Single value for "phase_advance". +param_sweep.add_variation( # Single value for "phase_advance". sweep_variable="phase_advance", start_point=45, units="deg", @@ -179,7 +179,7 @@ # ``` # Table of parametric variations: # -# | Simulation
ID
| mat_index | bridge | Ipeak | phase_adv | din | +# | Simulation
ID
| mat_index | bridge | Ipeak | phase_adv | din | # | :---: | :----: | :----: | :----: | :----: | :----: | # | 1 | 0 | 0.5mm | 200 A | 45 ° | 78 mm | # | 2 | 1 | 0.5mm | 200 A | 45 ° | 78 mm | @@ -227,7 +227,7 @@ # Plot torque vs ``"din"`` with the PM material # set to NdFeB (``"XG196/96_2DSF1.000_X"``). -report_torque_constant_mat= m2d.post.create_report( +report_torque_constant_mat = m2d.post.create_report( expressions="Moving1.Torque", domain="Sweep", variations={ @@ -242,7 +242,7 @@ plot_name="torque_constant_mat", ) -# The same approach is applied to visualize the loss in all solids and +# The same approach is applied to visualize the loss in all solids and # the core. Quantities ``"SolidLoss"`` and ``"CoreLoss"`` are calculated # from the field solution and were pre-defined in the project. @@ -383,9 +383,7 @@ } ) - with open( - os.path.join(temp_folder.name, "motor_optimization.csv"), "w", newline="" - ) as csvfile: + with open(os.path.join(temp_folder.name, "motor_optimization.csv"), "w", newline="") as csvfile: fields = [ "active_variation", "average_torque", diff --git a/examples/low_frequency/motor/aedt_motor/magnet_segmentation.py b/examples/low_frequency/motor/aedt_motor/magnet_segmentation.py index e35f19179..82907e654 100644 --- a/examples/low_frequency/motor/aedt_motor/magnet_segmentation.py +++ b/examples/low_frequency/motor/aedt_motor/magnet_segmentation.py @@ -15,6 +15,7 @@ import ansys.aedt.core from ansys.aedt.core.examples.downloads import download_file + # - # Define constants. @@ -78,9 +79,7 @@ segments_number = 2 object_name = "PM_I1_1" magnet_id = [obj.id for obj in m3d.modeler.object_list if obj.name == object_name][0] -sheets_2 = m3d.modeler.objects_segmentation( - magnet_id, segments=segments_number, apply_mesh_sheets=True -) +sheets_2 = m3d.modeler.objects_segmentation(magnet_id, segments=segments_number, apply_mesh_sheets=True) # ## Segment third magnet by specifying segmentation thickness # diff --git a/examples/low_frequency/motor/aedt_motor/pm_synchronous.py b/examples/low_frequency/motor/aedt_motor/pm_synchronous.py index 71989c774..a9758c8ae 100644 --- a/examples/low_frequency/motor/aedt_motor/pm_synchronous.py +++ b/examples/low_frequency/motor/aedt_motor/pm_synchronous.py @@ -22,9 +22,8 @@ import ansys.aedt.core import matplotlib.pyplot as plt import numpy as np - - from ansys.aedt.core.examples.downloads import download_file + # - # ### Define constants @@ -58,17 +57,17 @@ version=AEDT_VERSION, design="Sinusoidal", solution_type="TransientXY", -# new_desktop=True, + # new_desktop=True, non_graphical=NG_MODE, ) -m2d.modeler.model_units = "mm" # Specify model units +m2d.modeler.model_units = "mm" # Specify model units # ### Define parameters # # Initialize parameters to define the stator, rotor, and shaft # geometric properties. # The parameter names are consistent with those -# used in +# used in # [RMxprt](https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/Electronics/v252/en/Subsystems/Maxwell/Maxwell.htm%23Maxwell/GettingStartedwithRMxprt.htm?TocPath=Maxwell%2520Help%257CGetting%2520Started%2520with%2520RMxprt%257C_____0). # # Rotor geometric parameters: @@ -110,7 +109,7 @@ "Magnetic_Axial_Length": "150mm", "Stator_Lam_Length": "0mm", "StatorSkewAngle": "0deg", - "NumTorquePointsPerCycle": "30", # Number of points to sample torque during simulation. + "NumTorquePointsPerCycle": "30", # Number of points to sample torque during simulation. "mapping_angle": "0.125*4deg", "num_m": "16", "Section_Angle": "360deg/SymmetryFactor", # Used to apply symmetry boundaries. @@ -130,7 +129,7 @@ # - $I_x\rightarrow$ ``"IPeak"`` Amplitude of the current source for each winding. # - $f \rightarrow$ ``"ElectricFrequency"`` Frequency of the current source. # - $\theta_i$ ``"Theta_i"`` Initial rotor angle at $t=0$. -# - $\phi_x$ is the phase angle. $x=A\rightarrow 0^\circ, x=B\rightarrow120^\circ, +# - $\phi_x$ is the phase angle. $x=A\rightarrow 0^\circ, x=B\rightarrow120^\circ, # x=C\rightarrow 240^\circ$. oper_params = { @@ -163,7 +162,7 @@ # First, download the $B$-$H$ curves for the nonlinear magnetic materials from the [example-data](https://github.com/ansys/example-data/tree/main/pyaedt) repository. # -data_folder = Path(download_file(r'pyaedt/nissan', local_path=temp_folder.name)) +data_folder = Path(download_file(r"pyaedt/nissan", local_path=temp_folder.name)) # #### Annealed copper at 65o C @@ -175,7 +174,7 @@ # #### Nonlinear magnetic materials # -# Define material properties. +# Define material properties. # # The nonlinear $B$-$H$ curves # were retrieved @@ -185,12 +184,14 @@ # The method ``bh_list()`` helps simplify assignment of data from the text file to the # material permeability. + def bh_list(filepath): with open(filepath) as f: - reader = csv.reader(f, delimiter="\t") # Ignore header + reader = csv.reader(f, delimiter="\t") # Ignore header next(reader) return [[float(row[0]), float(row[1])] for row in reader] # Return a list of B,H values + # #### Define the magnetic material properties. # # The following image @@ -199,14 +200,14 @@ def bh_list(filepath): # # # -# Define the material ``"Arnold_Magnetics_N30UH_80C"``. +# Define the material ``"Arnold_Magnetics_N30UH_80C"``. mat_PM = m2d.materials.add_material(name="Arnold_Magnetics_N30UH_80C_new") mat_PM.update() mat_PM.conductivity = "555555.5556" mat_PM.set_magnetic_coercivity(value=-800146.66287534, x=1, y=0, z=0) mat_PM.mass_density = "7500" -mat_PM.permeability = bh_list(data_folder / 'BH_Arnold_Magnetics_N30UH_80C.tab') +mat_PM.permeability = bh_list(data_folder / "BH_Arnold_Magnetics_N30UH_80C.tab") # Define the laminate material, ``"30DH_20C_smooth"``. @@ -220,7 +221,7 @@ def bh_list(filepath): eq_depth = 0.001 mat_lam.set_electrical_steel_coreloss(kh, kc, ke, kdc, eq_depth) mat_lam.mass_density = "7650" -mat_lam.permeability = bh_list(data_folder / '30DH_20C_smooth.tab') +mat_lam.permeability = bh_list(data_folder / "30DH_20C_smooth.tab") # ## Create the stator # @@ -322,9 +323,10 @@ def bh_list(filepath): # magnet. # # The method ``create_cs_magnets()`` will be used to -# create the +# create the # coordinate system at the center of each magnet. + def create_magnet_cs(pm, cs_name, point_direction): """ Parameters @@ -437,7 +439,7 @@ def create_magnet_cs(pm, cs_name, point_direction): is_covered=True, name="Band", ) -bandOUT= m2d.modeler.create_circle( +bandOUT = m2d.modeler.create_circle( origin=[0, 0, 0], radius="(DiaGap - (0.5 * Airgap))/2", num_sides="mapping_angle", @@ -448,7 +450,7 @@ def create_magnet_cs(pm, cs_name, point_direction): # ### Assign "vacuum" material # # The band objects, region and shaft will all be assigned the -# material "vacuum". +# material "vacuum". vacuum_obj = [ shaft, @@ -464,7 +466,7 @@ def create_magnet_cs(pm, cs_name, point_direction): # # # -# Create the rotor with holes and pockets for the +# Create the rotor with holes and pockets for the # permanent magnets. # + @@ -570,13 +572,11 @@ def create_magnet_cs(pm, cs_name, point_direction): # Create linked boundary conditions to apply # electrical symmetry. # Edges of the region object are selected based on their position. -# The edge selection point on the region object lies in the +# The edge selection point on the region object lies in the # air-gap. pos_1 = "((DiaGap - (1.0 * Airgap))/4)" -id_bc_1 = m2d.modeler.get_edgeid_from_position( - position=[pos_1, 0, 0], assignment="Region" -) +id_bc_1 = m2d.modeler.get_edgeid_from_position(position=[pos_1, 0, 0], assignment="Region") id_bc_2 = m2d.modeler.get_edgeid_from_position( position=[ pos_1 + "*cos((360deg/SymmetryFactor))", @@ -596,8 +596,8 @@ def create_magnet_cs(pm, cs_name, point_direction): # ### Assign outer boundary condition # -# Assign the boundary condition for the magnetic -# vector potnetial, $A_z=0$ on the +# Assign the boundary condition for the magnetic +# vector potnetial, $A_z=0$ on the # outer perimeter of the motor. pos_2 = "(DiaOuter/2)" @@ -609,9 +609,7 @@ def create_magnet_cs(pm, cs_name, point_direction): ], assignment="Region", ) -m2d.assign_vector_potential( - assignment=id_bc_az, vector_value=0, boundary="VectorPotentialZero" -) +m2d.assign_vector_potential(assignment=id_bc_az, vector_value=0, boundary="VectorPotentialZero") # ### Define stator winding current sources @@ -622,6 +620,7 @@ def create_magnet_cs(pm, cs_name, point_direction): # were defined earlier parameters that were defined earlier in this example. The windigs have 6 conductors each. # The following function can be used define the windings and assign excitations: + def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): """ Parameters @@ -636,7 +635,7 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): Number of strands per winding. name : str String to use for naming sources and windings. - + """ phase_str = f"+ Theta_i - {phase}" ph_current = f"IPeak * cos(2*pi*ElectricFrequency*time {phase_str})" @@ -648,13 +647,13 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): conductors_number=nconductors, polarity="Positive", name=pos_coil_name, - ) + ) m2d.assign_coil( assignment=[obj_n], conductors_number=nconductors, polarity="Negative", name=neg_coil_name, - ) + ) m2d.assign_winding( assignment=None, winding_type="Current", @@ -662,10 +661,8 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): current=ph_current, parallel_branches=1, name=phase_name, - ) - m2d.add_winding_coils( - assignment=phase_name, coils=[pos_coil_name, neg_coil_name] -) + ) + m2d.add_winding_coils(assignment=phase_name, coils=[pos_coil_name, neg_coil_name]) assign_winding("A", "0deg", "Coil", "Coil_5") @@ -684,21 +681,21 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): # mesh so the simulation runs quickly. Accuracy can be improved # by increasing mesh density (reducing ``maximum_length``). -m2d.mesh.assign_length_mesh( # Coils +m2d.mesh.assign_length_mesh( # Coils assignment=id_coils, inside_selection=True, maximum_length=3, maximum_elements=None, name="coils", ) -m2d.mesh.assign_length_mesh( # Stator +m2d.mesh.assign_length_mesh( # Stator assignment=stator, inside_selection=True, maximum_length=3, maximum_elements=None, name="stator", ) -m2d.mesh.assign_length_mesh( # Rotor +m2d.mesh.assign_length_mesh( # Rotor assignment=rotor, inside_selection=True, maximum_length=3, @@ -711,11 +708,9 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): core_loss_list = ["Rotor", "Stator"] m2d.set_core_losses(core_loss_list, core_loss_on_field=True) -# Enable calcuation of the time-dependent inductance +# Enable calculation of the time-dependent inductance -m2d.change_inductance_computation( - compute_transient_inductance=True, incremental_matrix=False -) +m2d.change_inductance_computation(compute_transient_inductance=True, incremental_matrix=False) # Specify the length of the motor. # @@ -889,9 +884,7 @@ def assign_winding(name="A", phase="", obj_p=None, obj_n=None, nconductors=6): # # Export 2D plot data to a CSV file. -m2d.post.export_report_to_file( - output_dir=temp_folder.name, plot_name="TorquePlots", extension=".csv" -) +m2d.post.export_report_to_file(output_dir=temp_folder.name, plot_name="TorquePlots", extension=".csv") # ### Plot torque over the second quarter of the electric period # diff --git a/examples/low_frequency/motor/aedt_motor/rmxpert.py b/examples/low_frequency/motor/aedt_motor/rmxpert.py index 071afa57e..b595576ab 100644 --- a/examples/low_frequency/motor/aedt_motor/rmxpert.py +++ b/examples/low_frequency/motor/aedt_motor/rmxpert.py @@ -18,6 +18,7 @@ import time import ansys.aedt.core + # - # Define constants. diff --git a/examples/low_frequency/motor/aedt_motor/transformer.py b/examples/low_frequency/motor/aedt_motor/transformer.py index 6832e4fc6..49600ce50 100644 --- a/examples/low_frequency/motor/aedt_motor/transformer.py +++ b/examples/low_frequency/motor/aedt_motor/transformer.py @@ -17,6 +17,7 @@ from ansys.aedt.core.examples import downloads from ansys.aedt.core.generic.constants import unit_converter from ansys.aedt.core.generic.file_utils import read_csv_pandas + # - # Define constants. @@ -96,21 +97,11 @@ # and finally set the Power-Ferrite core loss model. mat = m3d.materials.add_material("newmat") -freq_25kHz = unit_converter( - values=25, unit_system="Freq", input_units="kHz", output_units="Hz" -) -freq_100kHz = unit_converter( - values=100, unit_system="Freq", input_units="kHz", output_units="Hz" -) -freq_200kHz = unit_converter( - values=200, unit_system="Freq", input_units="kHz", output_units="Hz" -) -freq_400kHz = unit_converter( - values=400, unit_system="Freq", input_units="kHz", output_units="Hz" -) -freq_700kHz = unit_converter( - values=700, unit_system="Freq", input_units="kHz", output_units="Hz" -) +freq_25kHz = unit_converter(values=25, unit_system="Freq", input_units="kHz", output_units="Hz") +freq_100kHz = unit_converter(values=100, unit_system="Freq", input_units="kHz", output_units="Hz") +freq_200kHz = unit_converter(values=200, unit_system="Freq", input_units="kHz", output_units="Hz") +freq_400kHz = unit_converter(values=400, unit_system="Freq", input_units="kHz", output_units="Hz") +freq_700kHz = unit_converter(values=700, unit_system="Freq", input_units="kHz", output_units="Hz") pv = { freq_25kHz: curves_csv_25kHz, freq_100kHz: curves_csv_100kHz, diff --git a/examples/low_frequency/motor/aedt_motor/transformer_inductance.py b/examples/low_frequency/motor/aedt_motor/transformer_inductance.py index c2f51d637..77fd41e6a 100644 --- a/examples/low_frequency/motor/aedt_motor/transformer_inductance.py +++ b/examples/low_frequency/motor/aedt_motor/transformer_inductance.py @@ -16,6 +16,7 @@ import time from ansys.aedt.core import Maxwell2d + # - # Define constants, diff --git a/examples/template.py b/examples/template.py index 824929d0c..edc4c6c2a 100644 --- a/examples/template.py +++ b/examples/template.py @@ -1,10 +1,10 @@ -# # Short, Descriptive Title +# # Short, Descriptive Title # # (do not specify the solver type in the title, i.e.: Maxwell2D, Maxwell3D etc) # # Most examples can be described as a series of steps that comprise a workflow. # 1. Import packages and instantiate the application. -# 2. Do something useful and interesting like creating the model, assing materials and boundary conditions, etc. +# 2. Do something useful and interesting like creating the model, assign materials and boundary conditions, etc. # 3. Run one or more analyses. # 4. View the results. # @@ -14,12 +14,14 @@ # # ### Perform imports -# + -from pathlib import Path import tempfile import time +# + +from pathlib import Path + import ansys.aedt.core # Interface to Ansys Electronics Desktop + # - # ### Define constants @@ -97,13 +99,13 @@ # After generating results demonstrate how to visualize and evaluate results # in this section. # Level 3 headers can be used to identify various post-processing -# steps. +# steps. # # ### Evaluate loss # > For example, in this section you may use code to demonstrate how to evaluate loss. # # ### Visualize fields -# > PyAEDT provides access to field solution data via the +# > PyAEDT provides access to field solution data via the # ## Finish