Download this example
Download this example as a Jupyter Notebook or as a Python script.
Configuration files#
This example shows how to use PyAEDT to export configuration files and reuse them to import in a new project. A configuration file is supported by these applications:
HFSS
2D Extractor and Q3D Extractor
Maxwell
Icepak (in AEDT)
Mechanical (in AEDT)
The following topics are covered:
Variables
Mesh operations (except Icepak)
Setup and optimetrics
Material properties
Object properties
Boundaries and excitations
When a boundary is attached to a face, PyAEDT tries to match it with a FaceByPosition
on the same object name on the target design. If for any reason this face position has changed or the object name in the target design has changed, the boundary fails to apply.
Keywords: AEDT, general, configuration file, setup.
Perform imports and define constants#
Import the required packages.
[1]:
import os
import tempfile
import time
import ansys.aedt.core
Define constants.
[2]:
AEDT_VERSION = "2024.2"
NG_MODE = False # Open AEDT UI when it is launched.
Create temporary directory#
Create the temporary directory. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name
.
[3]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
Download project#
Download the Icepack project.
[4]:
project_full_name = ansys.aedt.core.downloads.download_icepak(
destination=temp_folder.name
)
Open project#
Open the Icepak project from the project folder.
[5]:
ipk = ansys.aedt.core.Icepak(
project=project_full_name,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=NG_MODE,
)
ipk.autosave_disable()
PyAEDT INFO: Parsing C:\Users\ansys\AppData\Local\Temp\tmpe4dqjnmc.ansys\icepak\Graphics_card.aedt.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_648408af-3d58-4496-a40f-de1fba9e01ba.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 54141
PyAEDT INFO: File C:\Users\ansys\AppData\Local\Temp\tmpe4dqjnmc.ansys\icepak\Graphics_card.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 4108.
PyAEDT INFO: Project Graphics_card has been opened.
PyAEDT INFO: Active Design set to IcepakDesign1
PyAEDT INFO: Aedt Objects correctly read
[5]:
True
Create source blocks#
Create a source block on the CPU and memories.
[6]:
ipk.create_source_block(object_name="CPU", input_power="25W")
ipk.create_source_block(object_name=["MEMORY1", "MEMORY1_1"], input_power="5W")
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Block on ['CPU'] with 25W power created correctly.
PyAEDT INFO: Block on ['MEMORY1', 'MEMORY1_1'] with 5W power created correctly.
[6]:
<ansys.aedt.core.modules.boundary.BoundaryObject at 0x2237f0d4b80>
Assign boundaries#
Assign the opening and grille.
[7]:
region = ipk.modeler["Region"]
ipk.assign_openings(air_faces=region.bottom_face_x.id)
ipk.assign_grille(air_faces=region.top_face_x.id, free_area_ratio=0.8)
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 0sec
PyAEDT INFO: Opening Assigned
PyAEDT INFO: Grille Assigned
[7]:
<ansys.aedt.core.modules.boundary.BoundaryObject at 0x223043e4670>
Create setup#
Create the setup. Properties can be set up from the setup
object with getters and setters. They don’t have to perfectly match the property syntax.
[8]:
setup1 = ipk.create_setup()
setup1["FlowRegime"] = "Turbulent"
setup1["Max Iterations"] = 5
setup1["Solver Type Pressure"] = "flex"
setup1["Solver Type Temperature"] = "flex"
ipk.save_project()
PyAEDT INFO: Key FlowRegime matched internal key 'Flow Regime' with confidence of 94.
PyAEDT INFO: Key Max Iterations matched internal key 'Convergence Criteria - Max Iterations' with confidence of 54.
PyAEDT INFO: Key Solver Type Pressure matched internal key 'Linear Solver Type - Pressure' with confidence of 80.
PyAEDT INFO: Key Solver Type Temperature matched internal key 'Linear Solver Type - Temperature' with confidence of 82.
PyAEDT INFO: Project Graphics_card Saved correctly
[8]:
True
Export project to step file#
Export the project to the step file.
[9]:
filename = ipk.design_name
file_path = os.path.join(ipk.working_directory, filename + ".step")
ipk.export_3d_model(
file_name=filename,
file_path=ipk.working_directory,
file_format=".step",
assignment_to_export=[],
assignment_to_remove=[],
)
[9]:
True
Export configuration files#
Export the configuration files. You can optionally disable the export and import sections. Supported formats are JSON and TOML files.
[10]:
conf_file = ipk.configurations.export_config(
os.path.join(ipk.working_directory, "config.toml")
)
ipk.close_project()
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.03258085250854492
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 4108!
PyAEDT INFO: Project temp_proj has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'Icepak_6TF' of type Icepak.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.pyaedt/IcepakDesign1/config_export_temp_project/pyaedt_prj_U5S/temp_proj.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.pyaedt/IcepakDesign1/config_export_temp_project/pyaedt_prj_U5S/temp_proj.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.0
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/icepak/Graphics_card.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.032515525817871094
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 0sec
PyAEDT INFO: Deleted 10 Objects: SERIAL_PORT,ALPHA_MAIN_PCB,Region,CAPACITOR_1,CPU,HEAT_SINK,CAPACITOR,KB,MEMORY1_1,MEMORY1.
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Closing the AEDT Project temp_proj
PyAEDT INFO: Project temp_proj closed correctly
PyAEDT INFO: C:\Users\ansys\AppData\Local\Temp\tmpe4dqjnmc.ansys\icepak\Graphics_card.pyaedt\IcepakDesign1\config.toml correctly created.
PyAEDT INFO: Json file C:\Users\ansys\AppData\Local\Temp\tmpe4dqjnmc.ansys\icepak\Graphics_card.pyaedt\IcepakDesign1\config.toml created correctly.
PyAEDT INFO: Closing the AEDT Project Graphics_card
PyAEDT INFO: Project Graphics_card closed correctly
[10]:
True
Create project#
Create an Icepak project and import the step.
[11]:
new_project = os.path.join(temp_folder.name, "example.aedt")
app = ansys.aedt.core.Icepak(version=AEDT_VERSION, project=new_project)
app.modeler.import_3d_cad(file_path)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 4108!
PyAEDT INFO: Project example has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'Icepak_K4G' of type Icepak.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/example.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpe4dqjnmc.ansys/example.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.0
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmpe4dqjnmc.ansys\icepak\Graphics_card.pyaedt\IcepakDesign1\IcepakDesign1.step imported
[11]:
True
Import and apply configuration file#
Import and apply the configuration file. You can apply all or part of the JSON file that you import using options in the configurations
object.
[12]:
out = app.configurations.import_config(conf_file)
is_conf_imported = app.configurations.results.global_import_success
PyAEDT INFO: Dataset Ceramic_material_39 doesn't exist.
PyAEDT INFO: Dataset $Ceramic_material_39 created successfully.
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec
PyAEDT WARNING: Material Al-Extruded already exists. Renaming to Al-Extruded_89KJTH
PyAEDT WARNING: Material Ceramic_material already exists. Renaming to Ceramic_material_94BGJ5
PyAEDT WARNING: Material air already exists. Renaming to air_PDUAQC
PyAEDT WARNING: No mesh operation found.
PyAEDT WARNING: No mesh region found.
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Object Properties updated.
PyAEDT INFO: Boundary Operation CPU added.
PyAEDT INFO: Boundary Operation Grille_UO9VRI added.
PyAEDT INFO: Boundary Operation MEMORY1 added.
PyAEDT INFO: Boundary Operation Opening_71828E added.
PyAEDT INFO: Setup Setup added.
Release AEDT#
Close the project and release AEDT.
[13]:
app.release_desktop()
time.sleep(3) # Allow AEDT to shut down before cleaning the temporary project folder.
PyAEDT INFO: Desktop has been released and closed.
Clean up#
All project files are saved in the folder temp_folder.name
. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.
[14]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.