Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7988ac7
named expressions template
gmalinve Apr 9, 2025
39663eb
add Maxwell named expression maxwell
gmalinve Apr 10, 2025
2d9b310
Merge branch 'refs/heads/main' into feat/named_expressions_template
gmalinve Apr 10, 2025
de45c77
add quantity
gmalinve Apr 10, 2025
e53cbbd
Merge branch 'refs/heads/main' into feat/named_expressions_template
gmalinve Apr 14, 2025
6d22b7f
add named expressions fields calc
gmalinve Apr 14, 2025
2b82920
fixes
gmalinve Apr 14, 2025
5e396b0
improve tests
gmalinve Apr 14, 2025
855a599
delete template
gmalinve Apr 14, 2025
16de75b
clean code
gmalinve Apr 14, 2025
3cddf5e
fix populate_listbox
gmalinve Apr 14, 2025
63e9ac2
chore: adding changelog file 6027.added.md [dependabot-skip]
pyansys-ci-bot Apr 14, 2025
142d4b3
add-improve docs
gmalinve Apr 15, 2025
4b9945f
fix .rst
gmalinve Apr 15, 2025
a8fe4a3
fix .rst
gmalinve Apr 15, 2025
350168e
change dimensions
gmalinve Apr 15, 2025
aeb269b
change picture
gmalinve Apr 15, 2025
2e0a6d4
theme
gmalinve Apr 15, 2025
f446deb
change dimensions
gmalinve Apr 15, 2025
6b521b0
PyVista name
gmalinve Apr 15, 2025
13c456a
chore: adding changelog file 6027.added.md [dependabot-skip]
pyansys-ci-bot Apr 15, 2025
07b532c
delete will
gmalinve Apr 16, 2025
2859afc
fix doc and improve codecov
gmalinve Apr 16, 2025
84e8762
Apply suggestions from code review
gmalinve Apr 16, 2025
a9cfb94
fix doc and improve codecov
gmalinve Apr 17, 2025
b5fc5f9
fix doc style
gmalinve Apr 17, 2025
7c1bcdd
Merge branch 'refs/heads/main' into feat/named_expressions_template
gmalinve Apr 17, 2025
698ee36
review comments
gmalinve Apr 17, 2025
866ed1a
Apply suggestions from code review
gmalinve Apr 18, 2025
05f61d2
minor adds
gmalinve Apr 18, 2025
82c891f
Merge branch 'main' into feat/named_expressions_template
gmalinve Apr 18, 2025
f4761bd
Merge branch 'main' into feat/named_expressions_template
Samuelopez-ansys Apr 21, 2025
5dfbad1
Merge main
Samuelopez-ansys Apr 21, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/6027.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
populate named expressions and improve doc
4 changes: 2 additions & 2 deletions doc/source/User_guide/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ They are small automated workflows with a simple GUI.

Manage pyaedt and pyedb versions.

.. grid-item-card:: Points cloud generator
:link: pyaedt_extensions_doc/project/points_cloud_generator
.. grid-item-card:: Point cloud generator
:link: pyaedt_extensions_doc/project/point_cloud_generator
:link-type: doc
:margin: 2 2 0 0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Fields distribution
===================

This extensions allows to export fields distribution in generic formats such as CSV, TAB, or NPY on a defined grid of points or on mesh nodes.
The user can import a PTS file or generate a point cloud thanks to the **Point Cloud Generator** extension.

You can access the extension from the icon created on the **Automation** tab using the Extension Manager.

The following image shows the extension user interface:

.. image:: ../../../_static/extensions/fields_distribution.png
:width: 600
:alt: Fields Distribution UI

The user can select the field to export from the **Export options** list. This list displays all the available named expressions in the fields calculator.
The **Objects list** option allows the user to select the object or multiple objects on which the field is exported.

In the **Sample points file** field, the user can specify a PTS file containing the points where the field is exported
or generate a point cloud using the **Point Cloud Generator** extension by clicking on the button.
In the latter case a new window appears:

.. image:: ../../../_static/extensions/fields_distribution_pop_up.png
:width: 300
:alt: PTS import options

In case the user has a PTS file, the browse file window appears:

.. image:: ../../../_static/extensions/fields_distribution_browse.png
:width: 600
:alt: Browse PTS file

The **Save as** button allows to browse the location to save the output file in the selected format (CSV, TAB, or NPY).

Finally, the user has the option to preview the field distribution on the selected object surface with PyVista or simply export
the field in the desired location both in the selected format and as a FLD file.

You can also launch the extension user interface from the terminal. An example can be found here:


.. toctree::
:maxdepth: 2

../commandline
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Maxwell extensions

.. grid:: 2

.. grid-item-card:: Transformer loss distribution
:link: transformer_loss_distribution
.. grid-item-card:: Fields distribution
:link: fields_distribution
:link-type: doc
:margin: 2 2 0 0

Predict and export loss distribution in transformers.
Predict and export fields distribution on a defined grid of points or on mesh nodes.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Project extensions

Lear how to convert projects from 2022R2 to newer versions.

.. grid-item-card:: Points cloud generator
:link: points_cloud_generator
.. grid-item-card:: Point cloud generator
:link: point_cloud_generator
:link-type: doc
:margin: 2 2 0 0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Point cloud generator
=====================

With this extension, you can generate point cloud that conform to objects and surfaces.

You can access the extension from the icon created on the **Automation** tab using the Extension Manager.

The following image shows the extension user interface:

.. image:: ../../../_static/extensions/points_cloud_ui.png
:width: 800
:alt: Point Cloud Generator UI

This extension relies on the PyVista point cloud, a collection of points in 3D space,
typically used to represent the shape or surface of an object.
Each point in the cloud is defined by its own coordinates (x, y, z).
Selected objects are defined by an OBJ file which is a standard 3D model format used to represent 3D geometries.
It contains information about the vertices, vertex normals, and texture coordinates of the model, as well as the faces that make up the 3D object.
The extension first reads a mesh data from the OBJ file and loads it into a PyVista mesh object (mesh).
The mesh is then converted into a triangulated form. This means that all the faces of the mesh are broken down into triangles.
The triangulated mesh is then used to generate a point cloud. The point cloud is created by sampling points from the surface of the mesh.

The extension generates a PTS file in the working directory.

For HFSS designs, it enables conformal domains for near-field calculations.

You can also launch the extension user interface from the terminal. An example can be found here:


.. toctree::
:maxdepth: 2

../commandline

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/workflows/hfss/toolkits_catalog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template = "run_pyaedt_toolkit_script"
pip = ""

[PointCloudGenerator]
name = "Points Cloud Generator"
name = "Point Cloud Generator"
script = "points_cloud.py"
icon = "images/large/cloud.png"
template = "run_pyaedt_toolkit_script"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"objects_list": [],
"solution_option": "",
}
extension_description = "Transformer loss distribution"
extension_description = "Fields distribution"

Check warning on line 52 in src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py#L52

Added line #L52 was not covered by tests


def _text_size(path, entry): # pragma: no cover
Expand All @@ -74,6 +74,16 @@
entry.insert(tk.END, path)


def _populate_listbox(frame, listbox, listbox_height, objects_list): # pragma: no cover
listbox.pack(expand=True, fill=tk.BOTH, side=tk.LEFT)
if len(objects_list) > 6:
scroll_bar = tk.Scrollbar(frame, orient=tk.VERTICAL, command=listbox.yview)
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
listbox.config(yscrollcommand=scroll_bar.set, height=listbox_height)
for opt in objects_list:
listbox.insert(tk.END, opt)


def frontend(): # pragma: no cover
from tkinter import filedialog
from tkinter import messagebox
Expand All @@ -96,10 +106,19 @@
active_project_name = active_project.GetName()
active_design_name = active_design.GetName()
design_type = active_design.GetDesignType()
output_dict = {}
if design_type == "Maxwell 2D":
maxwell = ansys.aedt.core.Maxwell2d(active_project_name, active_design_name)
elif design_type == "Maxwell 3D":
maxwell = ansys.aedt.core.Maxwell3d(active_project_name, active_design_name)
else: # pragma: no cover
return output_dict

point = maxwell.modeler.create_point([0, 0, 0])
named_expressions = maxwell.post.available_report_quantities(
report_category="Fields", context=point.name, quantities_category="Calculator Expressions"
)
point.delete()

# Create UI
master = tk.Tk()
Expand Down Expand Up @@ -128,7 +147,7 @@
# Configure style for ttk buttons
style = ttk.Style()
theme = ExtensionTheme()

theme.default_font = ("Arial", 10)
theme.apply_light_theme(style)
master.theme = "light"

Expand All @@ -138,18 +157,17 @@
# Export options
export_options_frame = tk.Frame(master, width=20)
export_options_frame.grid(row=0, column=0, pady=10, padx=10, sticky="ew")
export_options_list = ["Ohmic loss", "Surface AC Force Density"]
export_options_list = named_expressions
# Determine the height of the ListBox
listbox_height = min(len(export_options_list), 6)
export_options_label = ttk.Label(
export_options_frame, text="Export options:", width=15, style="PyAEDT.TLabel", justify=tk.CENTER, anchor="w"
)
export_options_label.pack(side=tk.TOP, fill=tk.BOTH)
export_options_lb = tk.Listbox(
export_options_frame, selectmode=tk.SINGLE, height=2, width=15, justify=tk.CENTER, exportselection=False
export_options_frame, selectmode=tk.SINGLE, height=listbox_height, justify=tk.CENTER, exportselection=False
)
export_options_lb.pack(expand=True, fill=tk.BOTH, side=tk.LEFT)
for opt in export_options_list:
export_options_lb.insert(tk.END, opt)
export_options_lb.config(selectmode=tk.SINGLE)
_populate_listbox(export_options_frame, export_options_lb, listbox_height, export_options_list)

# Objects list
objects_list_frame = tk.Frame(master, width=20)
Expand All @@ -164,13 +182,7 @@
objects_list_lb = tk.Listbox(
objects_list_frame, selectmode=tk.MULTIPLE, justify=tk.CENTER, exportselection=False, height=listbox_height
)
objects_list_lb.pack(expand=True, fill=tk.BOTH, side=tk.LEFT)
if len(objects_list) > 6:
scroll_bar = tk.Scrollbar(objects_list_frame, orient=tk.VERTICAL, command=objects_list_lb.yview)
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
objects_list_lb.config(yscrollcommand=scroll_bar.set, height=listbox_height)
for obj in objects_list:
objects_list_lb.insert(tk.END, obj)
_populate_listbox(objects_list_frame, objects_list_lb, listbox_height, objects_list)

# Solution
solution_frame = tk.Frame(master, width=20, bg="white")
Expand Down Expand Up @@ -240,8 +252,6 @@
objects_list_lb.configure(
background=theme.light["widget_bg"], foreground=theme.light["text"], font=theme.default_font
)
if len(objects_list) > 6:
scroll_bar.configure(background=theme.light["widget_bg"])
solution_dropdown.configure(background=theme.light["widget_bg"], foreground=theme.light["text"])
export_file_entry.configure(
background=theme.light["widget_bg"], foreground=theme.light["text"], font=theme.default_font
Expand Down Expand Up @@ -277,8 +287,6 @@
export_file_frame.configure(bg=theme.dark["widget_bg"])
export_options_lb.configure(bg=theme.dark["widget_bg"], foreground=theme.dark["text"], font=theme.default_font)
objects_list_lb.configure(bg=theme.dark["widget_bg"], foreground=theme.dark["text"], font=theme.default_font)
if len(objects_list) > 6:
scroll_bar.configure(bg=theme.dark["widget_bg"])
solution_dropdown.configure(bg=theme.dark["widget_bg"], foreground=theme.dark["text"])
export_file_entry.configure(bg=theme.dark["widget_bg"], foreground=theme.dark["text"], font=theme.default_font)
sample_points_entry.configure(
Expand Down Expand Up @@ -306,14 +314,8 @@
messagebox.showerror("Error", "Selected setup is not solved.")
return None

# export
if master.export_option == "Ohmic loss":
quantity = "Ohmic_Loss"
else:
quantity = "Surface_AC_Force_Density"

maxwell.post.plot_field(
quantity=quantity,
quantity=master.export_option,
assignment=master.objects_list,
plot_type="Surface",
setup=master.solution_option,
Expand All @@ -330,7 +332,6 @@
)
sample_points_entry.insert(tk.END, filename)
master.file_path = sample_points_entry.get("1.0", tk.END).strip()
# master.destroy()

def show_popup():
popup = tk.Toplevel(master)
Expand Down Expand Up @@ -372,12 +373,12 @@
def save_as_files():
filename = filedialog.asksaveasfilename(
initialdir="/",
defaultextension=".tab",
defaultextension="*.tab",
filetypes=[
("tab data file", ".tab"),
("csv data file", ".csv"),
("tab data file", "*.tab"),
("csv data file", "*.csv"),
# ("MATLAB", ".mat"),
("Numpy array", ".npy"),
("Numpy array", "*.npy"),
],
)
_text_size(filename, export_file_entry)
Expand Down Expand Up @@ -417,7 +418,6 @@

maxwell.release_desktop(False, False)

output_dict = {}
if master.flag:
output_dict = {
"points_file": points_file,
Expand Down Expand Up @@ -468,25 +468,29 @@
else:
assignment = objects_list[0]

if export_option == "Ohmic loss":
quantity = "Ohmic_Loss"
else:
quantity = "SurfaceAcForceDensity"

setup_name = solution_option.split(":")[0].strip()
is_solved = [s.is_solved for s in aedtapp.setups if s.name == setup_name][0]
if not is_solved:
aedtapp.logger.error("The setup is not solved. Please solve the setup before exporting the field data.")
return False

Check warning on line 475 in src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py#L475

Added line #L475 was not covered by tests
field_path = str(Path(export_file).with_suffix(".fld"))

aedtapp.post.export_field_file(
quantity=quantity,
solution=solution_option,
output_file=field_path,
sample_points_file=points_file,
assignment=assignment,
objects_type="Surf",
)
if not points_file:
aedtapp.post.export_field_file(

Check warning on line 479 in src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py#L478-L479

Added lines #L478 - L479 were not covered by tests
quantity=export_option,
solution=solution_option,
output_file=field_path,
sample_points_file=points_file,
assignment=assignment,
objects_type="Surf",
)
else:
aedtapp.post.export_field_file(

Check warning on line 488 in src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py#L488

Added line #L488 was not covered by tests
quantity=export_option,
solution=solution_option,
output_file=field_path,
sample_points_file=points_file,
)

with open(field_path, "r") as file:
lins_to_skip = 2
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/workflows/project/points_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# Extension batch arguments
extension_arguments = {"choice": "", "points": 1000, "output_file": ""}
extension_description = "Points cloud generator"
extension_description = "Point cloud generator"

Check warning on line 47 in src/ansys/aedt/core/workflows/project/points_cloud.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/points_cloud.py#L47

Added line #L47 was not covered by tests


def frontend(): # pragma: no cover
Expand Down
Loading