Multiphysics: HFSS-Icepak multiphysics analysis#

This example shows how you can create a project from scratch in HFSS and Icepak (linked to HFSS). This includes creating a setup, solving it, and creating postprocessing outputs.

To provide the advanced postprocessing features needed for this example, the numpy, matplotlib, and pyvista packages must be installed on the machine.

This examples runs only on Windows using CPython.

Perform required imports#

Perform required imports.

import os
import sys
from pyaedt import generate_unique_project_name

from pyaedt.generic.constants import GLOBALCS
from pyaedt import Hfss
from pyaedt import Icepak

Set non-graphical mode#

Set non-graphical mode. "PYAEDT_NON_GRAPHICAL" is needed to generate documentation only. You can set non_graphical either to True or False.

non_graphical = os.getenv("PYAEDT_NON_GRAPHICAL", "False").lower() in ("true", "1", "t")
desktopVersion = "2022.2"

Open project#

Open the project.

NewThread = True

project_file = generate_unique_project_name()

Launch AEDT and initialize HFSS#

Launch AEDT and initialize HFSS. If there is an active HFSS design, the aedtapp object is linked to it. Otherwise, a new design is created.

aedtapp = Hfss(projectname=project_file, specified_version=desktopVersion, non_graphical=non_graphical, new_desktop_session=NewThread)

Initialize variable settings#

Initialize variable settings. You can initialize a variable simply by creating it as a list object. If you enter the prefix $, the variable is created for the project. Otherwise, the variable is created for the design.

aedtapp["$coax_dimension"] = "100mm"
udp = aedtapp.modeler.Position(0, 0, 0)
aedtapp["inner"] = "3mm"

Create coaxial and cylinders#

Create a coaxial and three cylinders. You can apply parameters directly using the pyaedt.modeler.Primitives3D.Primitives3D.create_cylinder() method. You can assign a material directly to the object creation action. Optionally, you can assign a material using the assign_material() method.

# TODO: How does this work when two truesurfaces are defined?
o1 = aedtapp.modeler.create_cylinder(aedtapp.PLANE.ZX, udp, "inner", "$coax_dimension", numSides=0, name="inner")
o2 = aedtapp.modeler.create_cylinder(aedtapp.PLANE.ZX, udp, 8, "$coax_dimension", numSides=0, matname="teflon_based")
o3 = aedtapp.modeler.create_cylinder(aedtapp.PLANE.ZX, udp, 10, "$coax_dimension", numSides=0, name="outer")

Assign colors#

Assign colors to each primitive.

o1.color = (255, 0, 0)
o2.color = (0, 255, 0)
o3.color = (255, 0, 0)
o3.transparency = 0.8

Assign materials#

Assign materials. You can assign materials either directly when creating the primitive, which was done for id2, or after the object is created.

o1.material_name = "Copper"
o3.material_name = "Copper"

Perform modeler operations#

Perform modeler operations. You can subtract, add, and perform other operations using either the object ID or object name.

aedtapp.modeler.subtract(o3, o2, True)
aedtapp.modeler.subtract(o2, o1, True)

Perform mesh operations#

Perform mesh operations. Most mesh operations are available. After a mesh is created, you can access a mesh operation to edit or review parameter values.

aedtapp.mesh.assign_model_resolution([,], None)
aedtapp.mesh.assign_length_mesh(o2.faces, False, 1, 2000)
<pyaedt.modules.Mesh.MeshOperation object at 0x0000021DF192EEE0>

Create excitations#

Create excitations. The create_wave_port_between_objects method automatically identifies the closest faces on a predefined direction and creates a sheet to cover the faces. It also assigns a port to this face. If add_pec_cap=True, the method creates a PEC cap.

aedtapp.create_wave_port_between_objects("inner", "outer", axisdir=1, add_pec_cap=True, portname="P1")
aedtapp.create_wave_port_between_objects("inner", "outer", axisdir=4, add_pec_cap=True, portname="P2")

portnames = aedtapp.get_all_sources()

Create setup#

Create a setup. A setup is created with default values. After its creation, you can change values and update the setup. The update method returns a Boolean value.

setup = aedtapp.create_setup("MySetup")
setup.props["Frequency"] = "1GHz"
setup.props["BasisOrder"] = 2
setup.props["MaximumPasses"] = 1

Create sweep#

Create a sweep. A sweep is created with default values.

sweepname = aedtapp.create_linear_count_sweep("MySetup", "GHz", 0.8, 1.2, 401, sweep_type="Interpolating")

Create Icepak model#

Create an Icepak model. After an HFSS setup is ready, link this model to an Icepak project and run a coupled physics analysis. The FieldAnalysis3D.copy_solid_bodies_from() method imports a model from HFSS with all material settings.

ipkapp = Icepak()

Edit gravity setting#

Edit the gravity setting if necessary because it is important for a fluid analysis.


Set up Icepak project#

Set up the Icepak project. When you create a setup, default settings are applied. When you need to change a property of the setup, you can use the props command to pass the correct value to the property. The update function applies the settings to the setup. The setup creation process is identical for all tools.

setup_ipk = ipkapp.create_setup("SetupIPK")
setup_ipk.props["Convergence Criteria - Max Iterations"] = 3

Edit or review mesh parameters#

Edit or review the mesh parameters. After a mesh is created, you can access a mesh operation to edit or review parameter values.

airbox = ipkapp.modeler.get_obj_id("Region")
ipkapp.modeler[airbox].display_wireframe = True
airfaces = ipkapp.modeler.get_object_faces(airbox)
<pyaedt.modules.Boundary.BoundaryObject object at 0x0000021DF539D400>

Close and open projects#

Close and open the projects to ensure that the HFSS - Icepak coupling works correctly in AEDT versions 2019 R3 through 2021 R1. Closing and opening projects can be helpful when performing operations on multiple projects.

aedtapp = Hfss(project_file)
ipkapp = Icepak()
ipkapp.solution_type = ipkapp.SOLUTIONS.Icepak.SteadyTemperatureAndFlow

Solve Icepak project#

Solve the Icepak project and the HFSS sweep.

setup1 = ipkapp.analyze_setup("SetupIPK")

Generate field plots and export#

Generate field plots on the HFSS project and export them as images.

vollist = []
setup_name = "MySetup : LastAdaptive"
quantity_name = "ComplexMag_E"
quantity_name2 = "ComplexMag_H"
intrinsic = {"Freq": "1GHz", "Phase": "0deg"}
surflist = aedtapp.modeler.get_object_faces("outer")
plot1 =, quantity_name2, setup_name, intrinsic)

results_folder = os.path.join(aedtapp.working_directory, "Coaxial_Results_NG")
if not os.path.exists(results_folder):
Hfss Icepak Coupling
<pyaedt.generic.plot.ModelPlotter object at 0x0000021D8741FF70>

Generate animation from field plots#

Generate an animation from field plots using PyVista.

import time

start = time.time()
cutlist = ["Global:XY"]
phases = [str(i * 5) + "deg" for i in range(18)]
animated =
    intrinsic_dict={"Freq": "1GHz", "Phase": "0deg"},
animated.gif_file = os.path.join(aedtapp.working_directory, "animate.gif")
animated.camera_position = [0, 50, 200]
animated.focal_point = [0, 50, 0]
# Set off_screen to False to visualize the animation.
# animated.off_screen = False

endtime = time.time() - start
print("Total Time", endtime)
Hfss Icepak Coupling
Total Time 10.760182857513428

Create Icepak plots and export#

Create Icepak plots and export them as images using the same functions that were used early. Only the quantity is different.

quantity_name = "Temperature"
setup_name = ipkapp.existing_analysis_sweeps[0]
intrinsic = ""
surflist = ipkapp.modeler.get_object_faces("inner")
plot5 =, "SurfTemperature"),

Hfss Icepak Coupling

Generate plots outside of AEDT#

Generate plots outside of AEDT using Matplotlib and NumPy.

trace_names = aedtapp.get_traces_for_plot(category="S")
cxt = ["Domain:=", "Sweep"]
families = ["Freq:=", ["All"]]
my_data =
my_data.plot(trace_names, "db20", xlabel="Frequency (Ghz)", ylabel="SParameters(dB)", title="Scattering Chart")
Scattering Chart
<Figure size 2000x1000 with 1 Axes>

Close project and release AEDT#

Close the project and release AEDT.

# aedtapp.close_project(aedtapp.project_name)

Total running time of the script: ( 2 minutes 28.768 seconds)

Gallery generated by Sphinx-Gallery