Skip to content

Commit

Permalink
Merge branch 'main' into subprocess-stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored May 16, 2024
2 parents 92135a2 + 6785a3b commit b29ab73
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 29 deletions.
8 changes: 6 additions & 2 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pyaedt.generic.settings import settings
from pyaedt.modules.Boundary import MaxwellParameters
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.Boundary import NativeComponentPCB
from pyaedt.modules.DesignXPloration import OptimizationSetups
from pyaedt.modules.DesignXPloration import ParametricSetups
from pyaedt.modules.SolveSetup import Setup
Expand Down Expand Up @@ -203,7 +204,7 @@ def setups(self):
Returns
-------
:class:`pyaedt.modules.SolveSetup.Setup`
List[:class:`pyaedt.modules.SolveSetup.Setup`]
Setups in the project.
"""
Expand Down Expand Up @@ -955,7 +956,10 @@ def _get_native_data(self):
if isinstance(ds, (OrderedDict, dict)):
component_type = ds["NativeComponentDefinitionProvider"]["Type"]
component_name = ds["BasicComponentInfo"]["ComponentName"]
native_component_object = NativeComponentObject(self, component_type, component_name, ds)
if component_type == "PCB":
native_component_object = NativeComponentPCB(self, component_type, component_name, ds)
else:
native_component_object = NativeComponentObject(self, component_type, component_name, ds)
boundaries.append(native_component_object)
except Exception:
msg = "Failed to add native component object."
Expand Down
6 changes: 5 additions & 1 deletion pyaedt/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pyaedt.modules.Boundary import BoundaryObject
from pyaedt.modules.Boundary import BoundaryProps
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.Boundary import NativeComponentPCB
from pyaedt.modules.DesignXPloration import SetupOpti
from pyaedt.modules.DesignXPloration import SetupParam
from pyaedt.modules.MaterialLib import Material
Expand Down Expand Up @@ -2054,7 +2055,10 @@ def apply_operations_to_native_components(obj, operation_dict, native_dict): #
nc_dict = copy.deepcopy(native_dict["Properties"])
nc_dict["TargetCS"] = instance_dict["CS"]
component3d_names = list(self._app.modeler.oeditor.Get3DComponentInstanceNames(native_name))
native = NativeComponentObject(self._app, native_dict["Type"], native_name, nc_dict)
if native_dict["Type"] == "PCB":
native = NativeComponentPCB(self._app, native_dict["Type"], native_name, nc_dict)
else:
native = NativeComponentObject(self._app, native_dict["Type"], native_name, nc_dict)
prj_list = set(self._app.project_list)
definition_names = set(self._app.oeditor.Get3DComponentDefinitionNames())
instance_names = {
Expand Down
64 changes: 59 additions & 5 deletions pyaedt/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3608,23 +3608,77 @@ def edit_source_from_file(
file_name : str
Full name of the input file.
is_time_domain : bool, optional
Either if the input data is Time based or Frequency Based. Frequency based data are Mag/Phase (deg).
Whether the input data is time-based or frequency-based. Frequency based data are Mag/Phase (deg).
x_scale : float, optional
Scaling factor for x axis.
Scaling factor for the x axis. This argument is ignored if the algorithm
identifies the format from the file header.
y_scale : float, optional
Scaling factor for y axis.
Scaling factor for the y axis. This argument is ignored if the algorithm
identifies the format from the file header.
impedance : float, optional
Excitation impedance. Default is `50`.
data_format : str, optional
Either `"Power"`, `"Current"` or `"Voltage"`.
Data format. Options are ``"Current"``, ``"Power"``, and ``"Voltage"``. This
argument is ignored if the algoritmm identifies the format from the
file header.
encoding : str, optional
Csv file encoding.
CSV file encoding.
Returns
-------
bool
"""

def find_scale(data, header_line):
for td in data.keys():
if td in header_line:
return data[td]
return None

with open(file_name, "r") as f:
header = f.readlines()[0]
time_data = {"[ps]": 1e-12, "[ns]": 1e-9, "[us]": 1e-6, "[ms]": 1e-3, "[s]": 1}
curva_data_V = {
"[nV]": 1e-9,
"[pV]": 1e-12,
"[uV]": 1e-6,
"[mV]": 1e-3,
"[V]": 1,
"[kV]": 1e3,
}
curva_data_W = {
"[nW]": 1e-9,
"[pW]": 1e-12,
"[uW]": 1e-6,
"[mW]": 1e-3,
"[W]": 1,
"[kW]": 1e3,
}
curva_data_A = {
"[nA]": 1e-9,
"[pA]": 1e-12,
"[uA]": 1e-6,
"[mA]": 1e-3,
"[A]": 1,
"[kA]": 1e3,
}
scale = find_scale(time_data, header)
x_scale = scale if scale else x_scale
scale = find_scale(curva_data_V, header)
if scale:
y_scale = scale
data_format = "Voltage"
else:
scale = find_scale(curva_data_W, header)
if scale:
y_scale = scale
data_format = "Power"
else:
scale = find_scale(curva_data_A, header)
if scale:
y_scale = scale
data_format = "Current"
if self.solution_type == "Modal":
out = "Power"
else:
Expand Down
5 changes: 3 additions & 2 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from pyaedt.modules.Boundary import ExponentialDictionary
from pyaedt.modules.Boundary import LinearDictionary
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.Boundary import NativeComponentPCB
from pyaedt.modules.Boundary import NetworkObject
from pyaedt.modules.Boundary import PieceWiseLinearDictionary
from pyaedt.modules.Boundary import PowerLawDictionary
Expand Down Expand Up @@ -2386,7 +2387,7 @@ def create_ipk_3dcomponent_pcb(
Returns
-------
:class:`pyaedt.modules.Boundary.NativeComponentObject`
:class:`pyaedt.modules.Boundary.NativeComponentPCB`
NativeComponentObject object.
References
Expand Down Expand Up @@ -2481,7 +2482,7 @@ def create_ipk_3dcomponent_pcb(
# compDefinition += ["Power:=", powerin, hfssLinkInfo]

native_props["TargetCS"] = PCB_CS
native = NativeComponentObject(self, "PCB", compName, native_props)
native = NativeComponentPCB(self, "PCB", compName, native_props)
if native.create():
user_defined_component = UserDefinedComponent(
self.modeler, native.name, native_props["NativeComponentDefinitionProvider"], "PCB"
Expand Down
50 changes: 33 additions & 17 deletions pyaedt/modeler/modeler3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,26 +993,24 @@ def _write_solid_stl(triangle, nas_to_dict):
tri = (int(n1), int(n2), int(n3))
nas_to_dict["Triangles"][tria_id].append(tri)

elif line_type in ["CPENTA", "CHEXA", "CTETRA"]:
# obj_id = line[16:24].strip()
elif line_type in [
"CTETRA",
"CPYRAM",
"CPYRA",
]:
# obj_id = line[8:16].strip()
n = []
el_id = line[24:32].strip()
el_id = line[16:24].strip()
if el_id not in nas_to_dict["Solids"]:
nas_to_dict["Solids"][el_id] = []

n.append(int(line[24:32]))
n.append(int(line[32:40]))
n.append(int(line[40:48]))
n.append(int(line[48:56]))
if line_type == "CPENTA":
if line_type in ["CPYRA", "CPYRAM"]:
n.append(int(line[56:64]))
n.append(int(line[64:72]))

if line_type == "CHEXA":
n.append(int(line[56:64]))
n.append(int(line[64:72]))
lk += 1
n.append(int(lines[lk][8:16].strip()))
n.append(int(lines[lk][16:24].strip()))
from itertools import combinations

for k in list(combinations(n, 3)):
Expand All @@ -1021,7 +1019,11 @@ def _write_solid_stl(triangle, nas_to_dict):
tri = tuple(tri)
nas_to_dict["Solids"][el_id].append(tri)

elif line_type in ["CTETRA*"]:
elif line_type in [
"CTETRA*",
"CPYRAM*",
"CPYRA*",
]:
# obj_id = line[8:24].strip()
n = []
el_id = line[24:40].strip()
Expand All @@ -1036,11 +1038,25 @@ def _write_solid_stl(triangle, nas_to_dict):

from itertools import combinations

for k in list(combinations(n, 3)):
tri = [int(k[0]), int(k[1]), int(k[2])]
tri.sort()
tri = tuple(tri)
nas_to_dict["Solids"][el_id].append(tri)
if line_type == "CTETRA*":
for k in list(combinations(n, 3)):
tri = [int(k[0]), int(k[1]), int(k[2])]
tri.sort()
tri = tuple(tri)
nas_to_dict["Solids"][el_id].append(tri)
else:
spli1 = [n[0], n[1], n[2], n[4]]
for k in list(combinations(spli1, 3)):
tri = [int(k[0]), int(k[1]), int(k[2])]
tri.sort()
tri = tuple(tri)
nas_to_dict["Solids"][el_id].append(tri)
spli1 = [n[0], n[2], n[3], n[4]]
for k in list(combinations(spli1, 3)):
tri = [int(k[0]), int(k[1]), int(k[2])]
tri.sort()
tri = tuple(tri)
nas_to_dict["Solids"][el_id].append(tri)

elif line_type in ["CROD", "CBEAM"]:
obj_id = int(line[16:24])
Expand Down
26 changes: 26 additions & 0 deletions pyaedt/modules/Boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,32 @@ def delete(self):
return True


class NativeComponentPCB(NativeComponentObject, object):
"""Manages Native Component PCB data and execution.
Parameters
----------
app : object
AEDT application from the ``pyaedt.application`` class.
component_type : str
Type of the component.
component_name : str
Name of the component.
props : dict
Properties of the boundary.
Examples
--------
In this example, the returned object, ``par_beam`` is a ``pyaedt.modules.Boundary.NativeComponentObject`` instance.
>>> from pyaedt import Icepak
>>> ipk = Icepak(solution_type="SBR+")
>>> par_beam = ipk.create_ipk_3dcomponent_pcb()
"""

def __init__(self, app, component_type, component_name, props):
NativeComponentObject.__init__(self, app, component_type, component_name, props)


class BoundaryObject(BoundaryCommon, object):
"""Manages boundary data and execution.
Expand Down
Binary file added pyaedt/workflows/hfss/images/large/push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions pyaedt/workflows/hfss/push_excitation_from_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os.path
from tkinter import Button

# import filedialog module
from tkinter import END
from tkinter import Label
from tkinter import StringVar
from tkinter import Text
from tkinter import Tk
from tkinter import filedialog
from tkinter import mainloop
from tkinter import ttk
from tkinter.ttk import Combobox

import PIL.Image
import PIL.ImageTk

import pyaedt
from pyaedt import Desktop
from pyaedt import Hfss
import pyaedt.workflows

choice = ""
file_path = ""


def browse_port(port_selection):
# Function for opening the
# file explorer window

master = Tk()

master.geometry("700x150")

master.title("Assign push excitation to port from transient data")

# Load the logo for the main window
icon_path = os.path.join(pyaedt.workflows.__path__[0], "images", "large", "logo.png")
im = PIL.Image.open(icon_path)
photo = PIL.ImageTk.PhotoImage(im)

# Set the icon for the main window
master.iconphoto(True, photo)

# Configure style for ttk buttons
style = ttk.Style()
style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 8))

var = StringVar()
label = Label(master, textvariable=var)
var.set("Choose a port:")
label.grid(row=0, column=0, pady=10)
# label.pack(pady=10)
combo = Combobox(master, width=30) # Set the width of the combobox
combo["values"] = port_selection
combo.current(0)
# combo.pack(pady=10)
combo.grid(row=0, column=1, pady=10, padx=5)
combo.focus_set()
var2 = StringVar()
label2 = Label(master, textvariable=var2)
var2.set("Browse file:")
label2.grid(row=1, column=0, pady=10)
text = Text(master, width=50, height=1)
# text.pack(pady=10)
text.grid(row=1, column=1, pady=10, padx=5)

def browseFiles():
filename = filedialog.askopenfilename(
initialdir="/",
title="Select a Transient File",
filetypes=(("Transient curve", "*.csv*"), ("all files", "*.*")),
)
text.insert(END, filename)
# # Change label contents
# return filename

b1 = Button(master, text="...", width=10, command=browseFiles)
b1.grid(row=3, column=0)
# b1.pack(pady=10)
b1.grid(row=1, column=2, pady=10)

def callback():
global choice, file_path
choice = combo.get()
file_path = text.get("1.0", END).strip()
master.destroy()
return True

b = Button(master, text="Ok", width=40, command=callback)
# b.pack(pady=10)
b.grid(row=2, column=1, pady=10)

mainloop()


if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = os.environ["PYAEDT_SCRIPT_PORT"]
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
version = "2023.2"
with Desktop(new_desktop_session=False, close_on_exit=False, specified_version=version, port=port) as d:
proj = d.active_project()
des = d.active_design()
projname = proj.GetName()
desname = des.GetName()
app = Hfss(projname, desname)
browse_port(port_selection=app.excitations)
if choice:
app.edit_source_from_file(
choice,
file_path,
is_time_domain=True,
)
d.logger.info("Excitation assigned correctly.")
else:
d.logger.error("Failed to select a port.")
Loading

0 comments on commit b29ab73

Please sign in to comment.