Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Icepak #181

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/02-HFSS/HFSS_Dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
# Generate 2D cutout plot. You can define the Theta scan
# and Phi scan.

ffdata.plot_cut(
ffdata.farfield_data.plot_cut(
primary_sweep="theta",
secondary_sweep_value=0,
quantity="RealizedGain",
Expand Down
75 changes: 44 additions & 31 deletions examples/04-Icepak/icepak_3d_components_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# ## Import PyAEDT and download files
# Perform import of required classes from the ``pyaedt`` package and import the ``os`` package.

# +
import os
import tempfile

from pyaedt import Icepak, downloads
# -

# Set constant values

AEDT_VERSION = "2024.1"
NG_MODE = False # Open Electronics UI when the application is launched.

# Download needed files in a temporary folder

Expand All @@ -26,19 +25,13 @@
)


# ## Set non-graphical mode
# Set non-graphical mode.
# You can set ``non_graphical`` either to ``True`` or ``False``.

non_graphical = False

# ## Create heatsink
# Create new empty project in non-graphical mode.

ipk = Icepak(
project=os.path.join(temp_folder.name, "Heatsink.aedt"),
version=AEDT_VERSION,
non_graphical=non_graphical,
non_graphical=NG_MODE,
close_on_exit=True,
new_desktop=True,
)
Expand All @@ -50,18 +43,22 @@

# 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"
n_fins = 11
hs_fins = hs_fin.duplicate_along_line(vector=[0, 3.65, 0], clones=n_fins)

ipk.plot(show=False, export_path=os.path.join(temp_folder.name, "Heatsink.jpg"))
ipk.plot(show=False, output_file=os.path.join(temp_folder.name, "Heatsink.jpg"))

# Definition of 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"
Expand All @@ -87,40 +84,46 @@
monitor_name="TopPoint",
)
ipk.monitor.assign_face_monitor(
face_id=hs_base.bottom_face_z.id, monitor_quantity="Temperature", monitor_name="Bottom"
face_id=hs_base.bottom_face_z.id,
monitor_quantity="Temperature",
monitor_name="Bottom",
)
ipk.monitor.assign_point_monitor_in_object(
name=hs_middle_fin.name, monitor_quantity="Temperature", monitor_name="MiddleFinCenter"
name=hs_middle_fin.name,
monitor_quantity="Temperature",
monitor_name="MiddleFinCenter",
)

# Export the heatsink 3D component in a ``"componentLibrary"`` folder.
# ``auxiliary_dict`` is set to true to export the monitor objects along with the .a3dcomp file.

os.mkdir(os.path.join(temp_folder.name, "componentLibrary"))
ipk.modeler.create_3dcomponent(
component_file=os.path.join(temp_folder.name, "componentLibrary", "Heatsink.a3dcomp"),
component_file=os.path.join(
temp_folder.name, "componentLibrary", "Heatsink.a3dcomp"
),
component_name="Heatsink",
auxiliary_dict=True,
)
ipk.close_project(save_project=False)
ipk.close_project(save=False)

# ## Create QFP
# Open the previously downloaded project containing a QPF.

ipk = Icepak(project=qfp_temp_name)
ipk.plot(show=False, export_path=os.path.join(temp_folder.name, "QFP2.jpg"))
ipk.plot(show=False, output_file=os.path.join(temp_folder.name, "QFP2.jpg"))

# Create dataset for power dissipation.

x_datalist = [45, 53, 60, 70]
y_datalist = [0.5, 3, 6, 9]
ipk.create_dataset(
dsname="PowerDissipationDataset",
xlist=x_datalist,
ylist=y_datalist,
name="PowerDissipationDataset",
x=x_datalist,
y=y_datalist,
is_project_dataset=False,
xunit="cel",
yunit="W",
x_unit="cel",
y_unit="W",
)

# Assign source power condition to the die.
Expand Down Expand Up @@ -166,7 +169,9 @@
# Download and open a project containing the electronic package.

ipk = Icepak(
project=package_temp_name, version=AEDT_VERSION, non_graphical=non_graphical
project=package_temp_name,
version=AEDT_VERSION,
non_graphical=NG_MODE,
)
ipk.plot(
objects=[o for o in ipk.modeler.object_names if not o.startswith("DomainBox")],
Expand Down Expand Up @@ -201,10 +206,10 @@
)

ipk.plot(
objects=[o for o in ipk.modeler.object_names if not o.startswith("DomainBox")],
assignment=[o for o in ipk.modeler.object_names if not o.startswith("DomainBox")],
show=False,
plot_air_objects=False,
export_path=os.path.join(temp_folder.name, "electronic_package.jpg"),
output_file=os.path.join(temp_folder.name, "electronic_package.jpg"),
force_opacity_value=0.5,
)
# -
Expand All @@ -220,23 +225,31 @@
y_pointing=[0, 1, 0],
)

# Export of the whole assembly as 3d component and close project. First, a flattening
# is needed because nested 3d components are not natively supported. Then it is possible
# to export the whole package as 3d component. Here the auxiliary dictionary is needed
# Export of the entire assembly as a 3D component and close the project. First, the nested
# hierarchy must be flattned since nested 3d components are currently not supported. Subsequently,
# the whole package can be exported as a 3D component. The auxiliary dictionary is needed
# to export monitor objects, datasets and native components.

ipk.flatten_3d_components()
ipk.modeler.create_3dcomponent(
component_file=os.path.join(temp_folder.name, "componentLibrary", "PCBAssembly.a3dcomp"),
component_file=os.path.join(
temp_folder.name, "componentLibrary", "PCBAssembly.a3dcomp"
),
component_name="PCBAssembly",
auxiliary_dict=True,
included_cs=["Global", "HeatsinkCS", "PCB_Assembly"],
reference_cs="PCB_Assembly",
)

# ## Release AEDT
#
# Release AEDT and remove the temporary folder.

ipk.release_desktop(close_projects=True, close_desktop=True)

# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.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.

temp_folder.cleanup()
65 changes: 39 additions & 26 deletions examples/04-Icepak/icepak_csv_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@
# Perform required imports including the operating system, regular expression, csv, Ansys PyAEDT
# and its boundary objects.

# +
import csv
import os
import tempfile

from IPython.display import Image
import matplotlib as mpl
import pyaedt
from IPython.display import Image
from matplotlib import cm
from matplotlib import pyplot as plt
import pyaedt

# -

# Set constant values

AEDT_VERSION = "2024.1"
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Download and open project
#
# Download the project and open it in non-graphical mode, using a temporary folder.

# +
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

project_name = os.path.join(temp_folder.name, "Icepak_CSV_Import.aedt")
ipk = pyaedt.Icepak(
project=os.path.join(temp_folder.name, "Icepak_CSV_Import.aedt"),
project=project_name,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=False,
non_graphical=NG_MODE,
)
# -

# Create the PCB as a simple block.

Expand All @@ -59,33 +61,33 @@
#
# The following table does not show the entire rows and data and only serves as a sample.
#
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
#
# | block_type | name | xs | ys | zs | xd | yd | zd | matname | power | Rjb | Rjc | Monitor_point |
# +============+======+========+========+======+=======+=======+======+==================+=======+=====+=====+===============+
# |------------|------|--------|--------|------|-------|-------|------|------------------|-------|-----|-----|---------------|
# | hollow | R8 | 31.75 | -20.32 | 0.40 | 15.24 | 2.54 | 2.54 | | 1 | | | 0 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
# | solid | U1 | 16.55 | 10.20 | 0.40 | 10.16 | 20.32 | 5.08 | Ceramic_material | 0.2 | | | 1 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
# | solid | U2 | -16.51 | 10.16 | 0.40 | 10.16 | 27.94 | 5.08 | Ceramic_material | 0.1 | | | 1 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
# | solid | U2 | -51 | 10.16 | 0.40 | 10.16 | 27.94 | 5.08 | Ceramic_material | 0.1 | | | 1 |
# | network | C180 | 47.62 | 19.05 | 0.40 | 3.81 | 2.54 | 2.43 | | 1.13 | 2 | 3 | 0 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
# | network | C10 | 65.40 | -1.27 | 0.40 | 3.81 | 2.54 | 2.43 | | 0.562 | 2 | 3 | 0 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
# | network | C20 | 113.03 | -0.63 | 0.40 | 2.54 | 3.81 | 2.43 | | 0.445 | 2 | 3 | 0 |
# +------------+------+--------+--------+------+-------+-------+------+------------------+-------+-----+-----+---------------+
#
# In this step the code will loop over the csv file lines and creates the blocks.
# It will create solid blocks and assign BCs.
# Every row of the csv has information of a particular block.

# +
filename = pyaedt.downloads.download_file("icepak", "blocks-list.csv", destination=temp_folder.name)
filename = pyaedt.downloads.download_file(
"icepak", "blocks-list.csv", destination=temp_folder.name
)

with open(filename, "r") as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
origin = [float(row["xs"]), float(row["ys"]), float(row["zs"])] # block starting point
origin = [
float(row["xs"]),
float(row["ys"]),
float(row["zs"]),
] # block starting point
dimensions = [
float(row["xd"]),
float(row["yd"]),
Expand Down Expand Up @@ -132,14 +134,15 @@
# column of the csv file
if row["Monitor_point"] == "1":
ipk.monitor.assign_point_monitor_in_object(
name=row["name"], monitor_quantity="Temperature", monitor_name=row["name"]
name=row["name"],
monitor_quantity="Temperature",
monitor_name=row["name"],
)
# -


# ## Compute power budget
#
# Calculate the power assigned to all the components
# # Calculate the power assigned to all the components

power_budget, total_power = ipk.post.power_budget(units="W")

# ## Plot model
Expand All @@ -153,14 +156,18 @@
# Set the colormap to use

cmap = plt.get_cmap("viridis")
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)

# Apply the color based on the power assigned and the colormap

for actor in pyvista_plot.objects:
if actor.name in power_budget:
actor.color = [int(i * 255) for i in scalarMap.to_rgba(power_budget[actor.name])[0:3]]
actor.color = [
int(i * 255) for i in scalarMap.to_rgba(power_budget[actor.name])[0:3]
]
actor.opacity = 1

# Generate the plot and export
Expand All @@ -171,8 +178,14 @@
Image(os.path.join(temp_folder.name, "object_power.jpg"))

# ## Release AEDT
#
# Release AEDT.

ipk.release_desktop(True, True)

# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.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.

temp_folder.cleanup()
15 changes: 11 additions & 4 deletions examples/04-Icepak/icepak_ecad_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Set constant values

AEDT_VERSION = "2024.1"
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Open project
#
Expand All @@ -28,7 +29,7 @@
project=os.path.join(temp_folder.name, "Icepak_ECAD_Import.aedt"),
version=AEDT_VERSION,
new_desktop=True,
non_graphical=True,
non_graphical=NG_MODE,
)
# -

Expand All @@ -50,7 +51,9 @@
# Download ECAD and IDF files

def_path = pyaedt.downloads.download_file(
source="icepak/Icepak_ECAD_Import/A1_uprev.aedb", name="edb.def", destination=temp_folder.name
source="icepak/Icepak_ECAD_Import/A1_uprev.aedb",
name="edb.def",
destination=temp_folder.name,
)
board_path = pyaedt.downloads.download_file(
source="icepak/Icepak_ECAD_Import/", name="A1.bdf", destination=temp_folder.name
Expand Down Expand Up @@ -99,8 +102,12 @@
)

# ## Release AEDT
#
# Release AEDT.

ipk.release_desktop(close_projects=True, close_desktop=True)

# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.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.

temp_folder.cleanup()
Loading
Loading