Note
Go to the end to download the full example code
Multiphysics: HFSS-Mechanical multiphysics analysis#
This example shows how you can use PyAEDT to create a multiphysics workflow that includes Circuit, HFSS, and Mechanical.
Perform required imports#
Perform required imports.
import os
import pyaedt
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 = False
Download and open project#
Download and open the project. Save it to the temporary folder.
project_temp_name = pyaedt.downloads.download_via_wizard(pyaedt.generate_unique_folder_name())
Start HFSS#
Start HFSS and initialize the PyAEDT object.
version = "2023.1"
hfss = pyaedt.Hfss(projectname=project_temp_name, specified_version=version, non_graphical=non_graphical,
new_desktop_session=True)
pin_names = hfss.excitations
Start Circuit#
Start Circuit and add the HFSS dynamic link component to it.
circuit = pyaedt.Circuit()
hfss_comp = circuit.modeler.schematic.add_subcircuit_dynamic_link(hfss)
Set up dynamic link options#
Set up dynamic link options. The argument for the set_sim_option_on_hfss_subcircuit
method can be the component name, component ID, or component object.
circuit.modeler.schematic.refresh_dynamic_link(hfss_comp.composed_name)
circuit.modeler.schematic.set_sim_option_on_hfss_subcircuit(hfss_comp)
hfss_setup_name = hfss.setups[0].name + " : " + hfss.setups[0].sweeps[0].name
circuit.modeler.schematic.set_sim_solution_on_hfss_subcircuit(hfss_comp.composed_name, hfss_setup_name)
True
Create ports and excitations#
Create ports and excitations. Find component pin locations and create interface ports on them. Define the voltage source on the input port.
circuit.modeler.schematic.create_interface_port(
name="Excitation_1", location=[hfss_comp.pins[0].location[0], hfss_comp.pins[0].location[1]]
)
circuit.modeler.schematic.create_interface_port(
name="Excitation_2", location=[hfss_comp.pins[1].location[0], hfss_comp.pins[1].location[1]]
)
circuit.modeler.schematic.create_interface_port(
name="Port_1", location=[hfss_comp.pins[2].location[0], hfss_comp.pins[2].location[1]]
)
circuit.modeler.schematic.create_interface_port(
name="Port_2", location=[hfss_comp.pins[3].location[0], hfss_comp.pins[3].location[1]]
)
voltage = 1
phase = 0
ports_list = ["Excitation_1", "Excitation_2"]
source = circuit.assign_voltage_sinusoidal_excitation_to_ports(ports_list)
source.ac_magnitude = voltage
source.phase = phase
Create setup#
Create a setup.
setup_name = "MySetup"
LNA_setup = circuit.create_setup(setupname=setup_name)
bw_start = 4.3
bw_stop = 4.4
n_points = 1001
unit = "GHz"
sweep_list = ["LINC", str(bw_start) + unit, str(bw_stop) + unit, str(n_points)]
LNA_setup.props["SweepDefinition"]["Data"] = " ".join(sweep_list)
Solve and push excitations#
Solve the circuit and push excitations to the HFSS model to calculate the correct value of losses.
circuit.analyze()
circuit.push_excitations(instance_name="S1", setup_name=setup_name)
True
Start Mechanical#
Start Mechanical and copy bodies from the HFSS project.
mech = pyaedt.Mechanical()
mech.copy_solid_bodies_from(hfss)
True
Get losses from HFSS and assign convection to Mechanical#
Get losses from HFSS and assign the convection to Mechanical.
mech.assign_em_losses(
designname=hfss.design_name,
setupname=hfss.setups[0].name,
sweepname="LastAdaptive",
map_frequency=hfss.setups[0].props["Frequency"],
surface_objects=hfss.get_all_conductors_names(),
)
diels = ["1_pd", "2_pd", "3_pd", "4_pd", "5_pd"]
for el in diels:
mech.assign_uniform_convection(objects_list=[mech.modeler[el].top_face_y, mech.modeler[el].bottom_face_y],
convection_value=3)
Plot model#
Plot the model.
mech.plot(show=False, export_path=os.path.join(mech.working_directory, "Mech.jpg"), plot_air_objects=False)

<pyaedt.generic.plot.ModelPlotter object at 0x000001BC296FFF40>
Solve and plot thermal results#
Solve and plot the thermal results.
File "C:\actions-runner\_work\_tool\Python\3.8.10\x64\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\actions-runner\_work\_tool\Python\3.8.10\x64\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\actions-runner\_work\pyaedt\pyaedt\testenv\Scripts\sphinx-build.exe\__main__.py", line 7, in <module>
sys.exit(main())
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\cmd\build.py", line 321, in main
return build_main(argv)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\application.py", line 268, in __init__
self._init_builder()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\application.py", line 339, in _init_builder
self.events.emit('builder-inited')
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\events.py", line 96, in emit
results.append(listener.handler(self.app, *args))
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_gallery.py", line 560, in generate_gallery_rst
) = generate_dir_rst(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 459, in generate_dir_rst
intro, title, cost = generate_file_rst(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 1075, in generate_file_rst
output_blocks, time_elapsed = execute_script(script_blocks,
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 993, in execute_script
output_blocks.append(execute_code_block(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 862, in execute_code_block
is_last_expr, mem_max = _exec_and_get_memory(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 708, in _exec_and_get_memory
mem_body, _ = gallery_conf['call_memory'](
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_gallery.py", line 213, in call_memory
return 0., func()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 647, in __call__
exec(self.code, self.fake_main.__dict__)
File "C:\actions-runner\_work\pyaedt\pyaedt\examples\06-Multiphysics\Hfss_Mechanical.py", line 151, in <module>
mech.analyze()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Analysis.py", line 1581, in analyze
return self.analyze_setup(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Analysis.py", line 1716, in analyze_setup
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, config_name)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Design.py", line 1426, in set_registry_key
self.odesktop.SetRegistryString(key_full_name, key_value)
RuntimeError: Error 0x80020009; Logs or message window might have more details
File "C:\actions-runner\_work\_tool\Python\3.8.10\x64\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\actions-runner\_work\_tool\Python\3.8.10\x64\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\actions-runner\_work\pyaedt\pyaedt\testenv\Scripts\sphinx-build.exe\__main__.py", line 7, in <module>
sys.exit(main())
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\cmd\build.py", line 321, in main
return build_main(argv)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\application.py", line 268, in __init__
self._init_builder()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\application.py", line 339, in _init_builder
self.events.emit('builder-inited')
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx\events.py", line 96, in emit
results.append(listener.handler(self.app, *args))
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_gallery.py", line 560, in generate_gallery_rst
) = generate_dir_rst(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 459, in generate_dir_rst
intro, title, cost = generate_file_rst(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 1075, in generate_file_rst
output_blocks, time_elapsed = execute_script(script_blocks,
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 993, in execute_script
output_blocks.append(execute_code_block(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 862, in execute_code_block
is_last_expr, mem_max = _exec_and_get_memory(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 708, in _exec_and_get_memory
mem_body, _ = gallery_conf['call_memory'](
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_gallery.py", line 213, in call_memory
return 0., func()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\sphinx_gallery\gen_rst.py", line 647, in __call__
exec(self.code, self.fake_main.__dict__)
File "C:\actions-runner\_work\pyaedt\pyaedt\examples\06-Multiphysics\Hfss_Mechanical.py", line 151, in <module>
mech.analyze()
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Analysis.py", line 1581, in analyze
return self.analyze_setup(
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Analysis.py", line 1756, in analyze_setup
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, active_config)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\general_methods.py", line 168, in wrapper
out = user_function(*args, **kwargs)
File "c:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\application\Design.py", line 1426, in set_registry_key
self.odesktop.SetRegistryString(key_full_name, key_value)
RuntimeError: Error 0x80020009; Logs or message window might have more details
<pyaedt.modules.solutions.FieldPlot object at 0x000001BC2852BF10>
Release AEDT#
Release AEDT.
mech.release_desktop(True, True)
True
Total running time of the script: ( 4 minutes 3.434 seconds)