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

Post-processing refactoring #4410

Merged
merged 31 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ece10db
fix typos
gmalinve Mar 25, 2024
4f57c5a
fix typos
gmalinve Mar 25, 2024
7c874b8
fix typos and refactoring
gmalinve Mar 26, 2024
f5826e9
Merge branch 'main' into refacto_keywords_args
gmalinve Mar 26, 2024
e760c9d
decorator + test
gmalinve Mar 26, 2024
0603b5e
remove pass
gmalinve Mar 26, 2024
58a5227
Merge branch 'main' into refacto_keywords_args
gmalinve Mar 26, 2024
9fd0110
add decorator in pyaedt_function_handler
gmalinve Mar 26, 2024
1da55dd
refactoring Post-Processing
gmalinve Mar 27, 2024
cf84870
refactoring Post-Processing
gmalinve Mar 27, 2024
05a47d0
Merge branch 'main' into refacto_keywords_args
gmalinve Mar 28, 2024
096df9d
fix doc
gmalinve Mar 28, 2024
4258b13
remove import
gmalinve Mar 28, 2024
91ca32b
remove import
gmalinve Mar 28, 2024
c88ad78
refacto AdvancedPostProcessing.py
gmalinve Mar 28, 2024
61f4322
refacto AdvancedPostProcessing.py
gmalinve Mar 28, 2024
bf3cce5
refacto solutions.py
gmalinve Mar 28, 2024
a761ca1
Merge branch 'main' into refacto_keywords_args
gmalinve Mar 28, 2024
7267ab5
Merge branch 'main' into refacto_keywords_args
maxcapodi78 Apr 3, 2024
cb5c69a
back compatibility with ipy
Apr 3, 2024
13f65c9
Merge remote-tracking branch 'origin/refacto_keywords_args' into refa…
Apr 3, 2024
8590292
reverted unit test
Apr 3, 2024
caf6f3d
fixed UT
Apr 3, 2024
d053b96
fixed UT
Apr 3, 2024
345d2b0
Merge branch 'main' into refacto_keywords_args
maxcapodi78 Apr 3, 2024
b6cc6a1
Apply suggestions from code review
maxcapodi78 Apr 4, 2024
2acaac0
Update pyaedt/modules/PostProcessor.py
maxcapodi78 Apr 4, 2024
f65a6c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2024
6d59955
PR review
gmalinve Apr 4, 2024
f58ef11
Merge branch 'main' into refacto_keywords_args
maxcapodi78 Apr 4, 2024
cc3eb6f
Merge branch 'main' into refacto_keywords_args
maxcapodi78 Apr 4, 2024
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
10 changes: 10 additions & 0 deletions _unittest/test_01_general_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from pyaedt.generic.DataHandlers import str_to_bool
from pyaedt.generic.general_methods import deprecated_alias
from pyaedt.generic.general_methods import number_aware_string_key


Expand All @@ -9,6 +10,11 @@ def desktop():
return


@deprecated_alias(t="n")
def operation(n, m):
return n + m


class TestClass(object):
def test_00_number_aware_string_key(self):
assert number_aware_string_key("C1") == ("C", 1)
Expand All @@ -30,3 +36,7 @@ def test_02_str_to_bool(self):
assert True in list(map(str_to_bool, test_list_1))
test_list_2 = ["Stop", "go", "run", "crawl", "False"]
assert False in list(map(str_to_bool, test_list_2))

def test_03_argument_decorator(self):
assert operation(n=2, m=3) == 5
assert operation(t=2, m=3) == 5
2 changes: 1 addition & 1 deletion _unittest_solvers/test_01_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def aedtapp(add_app):

class TestClass(object):
def test_create_pdf(self, local_scratch):
report = AnsysReport(project_name="Coaxial", design_name="Design1")
report = AnsysReport(design_name="Design1", project_name="Coaxial")
report.aedt_version = desktop_version
assert "AnsysTemplate" in report.template_name
report.template_name = "AnsysTemplate"
Expand Down
2 changes: 1 addition & 1 deletion doc/source/User_guide/postprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ You can plot the field plot directly in HFSS and export it to image files.
plot1 = hfss.post.create_fieldplot_cutplane(objlist=cutlist,
quantityName=quantity_name,
setup_name=setup_name,
intrinsincDict=intrinsic)
intrinsics=intrinsic)


.. image:: ../Resources/field_plot.png
Expand Down
2 changes: 1 addition & 1 deletion examples/03-Maxwell/Maxwell2D_DCConduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
# ~~~~~~~~~~~~~~~~~~~
# Generate a PDF report with output of simulation.

pdf_report = AnsysReport(project_name=m2d.project_name, design_name=m2d.design_name, version=aedt_version)
pdf_report = AnsysReport(version=aedt_version, design_name=m2d.design_name, project_name=m2d.project_name)

# Customize text font.

Expand Down
3 changes: 1 addition & 2 deletions examples/03-Maxwell/Maxwell2D_Electrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@
# and as ``In surface objects`` only the region.

plot = M2D.post.create_fieldplot_line_traces(seeding_faces=["Ground", "Electrode", "Region"],
in_volume_tracing_objs="Region",
plot_name="LineTracesTest")
in_volume_tracing_objs="Region", plot_name="LineTracesTest")

###################################################################################
# Update Field Line Traces Plot
Expand Down
7 changes: 2 additions & 5 deletions examples/03-Maxwell/Maxwell2D_PMSynchronousMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,8 @@ def create_cs_magnets(pm_id, cs_name, point_direction):
# formerly created when the section is applied.

faces_reg = mod2D.get_object_faces(object_list[1].name) # Region
plot1 = M2D.post.create_fieldplot_surface(objlist=faces_reg,
quantityName='Flux_Lines',
intrinsincDict={
"Time": M2D.variable_manager.variables["StopTime"].evaluated_value},
plot_name="Flux_Lines")
plot1 = M2D.post.create_fieldplot_surface(objlist=faces_reg, quantityName='Flux_Lines', intrinsic_dict={
"Time": M2D.variable_manager.variables["StopTime"].evaluated_value}, plot_name="Flux_Lines")

##########################################################
# Export a field plot to an image file
Expand Down
6 changes: 3 additions & 3 deletions examples/03-Maxwell/Maxwell3DTeam7.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@

surf_list = m3d.modeler.get_object_faces("Plate")
intrinsic_dict = {"Freq": "200Hz", "Phase": "0deg"}
m3d.post.create_fieldplot_surface(surf_list, "Mag_J", intrinsincDict=intrinsic_dict, plot_name="Mag_J")
m3d.post.create_fieldplot_surface(surf_list, "Mag_B", intrinsincDict=intrinsic_dict, plot_name="Mag_B")
m3d.post.create_fieldplot_surface(surf_list, "Mesh", intrinsincDict=intrinsic_dict, plot_name="Mesh")
m3d.post.create_fieldplot_surface(surf_list, "Mag_J", intrinsic_dict=intrinsic_dict, plot_name="Mag_J")
m3d.post.create_fieldplot_surface(surf_list, "Mag_B", intrinsic_dict=intrinsic_dict, plot_name="Mag_B")
m3d.post.create_fieldplot_surface(surf_list, "Mesh", intrinsic_dict=intrinsic_dict, plot_name="Mesh")

####################################################################################################
# Release AEDT and clean up temporary directory
Expand Down
2 changes: 1 addition & 1 deletion examples/03-Maxwell/Maxwell3D_Team3_bath_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@

ladder_plate = m3d.modeler.objects_by_name["LadderPlate"]
intrinsic_dict = {"Freq": "50Hz", "Phase": "0deg"}
m3d.post.create_fieldplot_surface(ladder_plate.faces, "Mag_J", intrinsincDict=intrinsic_dict, plot_name="Mag_J")
m3d.post.create_fieldplot_surface(ladder_plate.faces, "Mag_J", intrinsic_dict=intrinsic_dict, plot_name="Mag_J")

###############################################################################
# Release AEDT
Expand Down
2 changes: 1 addition & 1 deletion examples/05-Q3D/Q3D_DC_IR.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
# Compute ACL solutions and plot them.

plot1 = q3d.post.create_fieldplot_surface(q3d.modeler.get_objects_by_material("copper"), quantityName=drop_name,
intrinsincDict={"Freq": "1GHz"})
intrinsic_dict={"Freq": "1GHz"})

q3d.post.plot_field_from_fieldplot(
plot1.name,
Expand Down
2 changes: 1 addition & 1 deletion examples/06-Multiphysics/Hfss_Icepak_Coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
# Generate pdf report
# ~~~~~~~~~~~~~~~~~~~
# Generate a pdf report with output of simultion.
report = AnsysReport(project_name=aedtapp.project_name, design_name=aedtapp.design_name, version=aedt_version)
report = AnsysReport(version=aedt_version, design_name=aedtapp.design_name, project_name=aedtapp.project_name)
report.create()
report.add_section()
report.add_chapter("Hfss Results")
Expand Down
12 changes: 5 additions & 7 deletions examples/06-Multiphysics/MRI.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@
# Draw Point1 at origin of the implant coordinate system

hfss.sar_setup(-1, Average_SAR_method=1, TissueMass=1, MaterialDensity=1, )
hfss.post.create_fieldplot_cutplane(objlist="implant:YZ",
quantityName="Average_SAR",
filter_objects=["implant_box"])
hfss.post.create_fieldplot_cutplane(objlist="implant:YZ", quantityName="Average_SAR", filter_objects=["implant_box"])

hfss.modeler.set_working_coordinate_system("implant")
hfss.modeler.create_point([0, 0, 0], name="Point1")
Expand Down Expand Up @@ -214,8 +212,8 @@
# Plot Temperature on cut plane.
# Plot Temperature on point.

mech.post.create_fieldplot_cutplane("implant:YZ", "Temperature", filter_objects=["implant_box"],
intrinsincDict={"Time": "10s"})
mech.post.create_fieldplot_cutplane("implant:YZ", "Temperature", intrinsic_dict={"Time": "10s"},
filter_objects=["implant_box"])
mech.save_project()

data = mech.post.get_solution_data("Temperature", primary_sweep_variable="Time", context="Point1",
Expand Down Expand Up @@ -305,8 +303,8 @@
# Plot Temperature on monitor point.

ipk.analyze(num_cores=4,num_tasks=4)
ipk.post.create_fieldplot_cutplane("implant:YZ", "Temperature", filter_objects=["implant_box"],
intrinsincDict={"Time": "0s"})
ipk.post.create_fieldplot_cutplane("implant:YZ", "Temperature", intrinsic_dict={"Time": "0s"},
filter_objects=["implant_box"])
ipk.save_project()

data = ipk.post.get_solution_data("Point1.Temperature", primary_sweep_variable="Time", report_category="Monitor")
Expand Down
14 changes: 4 additions & 10 deletions examples/06-Multiphysics/Maxwell3D_Icepak_2Way_Coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,11 @@
for name in ["Coil", "Core"]:
surface_list.extend(ipk.modeler.get_object_faces(name))

surf_temperature = ipk.post.create_fieldplot_surface(
surface_list,
quantityName="SurfTemperature",
plot_name="Surface Temperature"
)
surf_temperature = ipk.post.create_fieldplot_surface(surface_list, quantityName="SurfTemperature",
plot_name="Surface Temperature")

velocity_cutplane = ipk.post.create_fieldplot_cutplane(
objlist=["Global:XZ"],
quantityName="Velocity Vectors",
plot_name="Velocity Vectors"
)
velocity_cutplane = ipk.post.create_fieldplot_cutplane(objlist=["Global:XZ"], quantityName="Velocity Vectors",
plot_name="Velocity Vectors")

surf_temperature.export_image()
velocity_cutplane.export_image(orientation="right")
Expand Down
44 changes: 43 additions & 1 deletion pyaedt/generic/general_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datetime
import difflib
import fnmatch
import functools
from functools import update_wrapper
import inspect
import itertools
Expand All @@ -21,6 +22,9 @@
import tempfile
import time
import traceback
from typing import Callable
from typing import Dict
import warnings

from pyaedt.aedt_logger import pyaedt_logger
from pyaedt.generic.constants import CSS4_COLORS
Expand Down Expand Up @@ -258,7 +262,7 @@ def decorating_function(user_function):
def check_numeric_equivalence(a, b, relative_tolerance=1e-7):
"""Check if two numeric values are equivalent to within a relative tolerance.

Paraemters
Parameters
----------
a : int, float
Reference value to compare to.
Expand Down Expand Up @@ -2086,3 +2090,41 @@ def developer_forum(self):
# property = Property

online_help = Help()


def deprecated_alias(**aliases: str) -> Callable:
"""Decorator for deprecated function and method arguments.

Use as follows:

@deprecated_alias(old_arg='new_arg')
def myfunc(new_arg):
...

"""

def deco(f: Callable):
@functools.wraps(f)
def wrapper(*args, **kwargs):
rename_kwargs(f.__name__, kwargs, aliases)
return f(*args, **kwargs)

return wrapper

return deco


def rename_kwargs(func_name: str, kwargs: Dict[str, str], aliases: Dict[str, str]):
"""Helper function for deprecating function arguments."""
for alias, new in aliases.items():
if alias in kwargs:
if new in kwargs:
raise TypeError(
f"{func_name} received both {alias} and {new} as arguments!"
f" {alias} is deprecated, use {new} instead."
)
warnings.warn(
message=(f"`{alias}` is deprecated as an argument to `{func_name}`; use" f" `{new}` instead."),
category=DeprecationWarning,
)
kwargs[new] = kwargs.pop(alias)
8 changes: 6 additions & 2 deletions pyaedt/generic/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ class ReportSpec:


class AnsysReport(FPDF):
def __init__(self, version="2023R2", design_name="design1", project_name="AnsysProject", tempplate_json_file=None):
def __init__(
self, version="2023R2", design_name="design1", project_name="AnsysProject", template_json_file=None, **kwargs
):
super().__init__()
self.report_specs = ReportSpec()
self.read_template(tempplate_json_file)
if "tempplate_json_file" in kwargs.keys():
template_json_file = kwargs["tempplate_json_file"]
self.read_template(template_json_file)
self.report_specs.ansys_version = version
self.report_specs.design_name = design_name
self.report_specs.project_name = project_name
Expand Down
13 changes: 8 additions & 5 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ def assign_grille(
air_faces,
free_loss_coeff=True,
free_area_ratio=0.8,
resistance_type=0,
external_temp="AmbientTemp",
expternal_pressure="AmbientPressure",
external_pressure="AmbientPressure",
x_curve=["0", "1", "2"],
y_curve=["0", "1", "2"],
boundary_name=None,
**kwargs,
):
"""Assign grille to a face or list of faces.

Expand All @@ -251,7 +251,7 @@ def assign_grille(
The default is ``0`` for ``"Perforated Thin Vent"``.
external_temp : str, optional
External temperature. The default is ``"AmbientTemp"``.
expternal_pressure : str, optional
external_pressure : str, optional
External pressure. The default is ``"AmbientPressure"``.
x_curve : list, optional
List of X curves in m_per_sec. The default is ``["0", "1", "2"]``.
Expand All @@ -271,6 +271,9 @@ def assign_grille(

>>> oModule.AssignGrilleBoundary
"""
if "expternal_pressure" in kwargs:
self.logger.warning("``expternal_pressure`` is deprecated, please use ``external_pressure`` instead.")
external_pressure = kwargs["expternal_pressure"]
if boundary_name is None:
boundary_name = generate_unique_name("Grille")

Expand All @@ -283,12 +286,12 @@ def assign_grille(
props["Pressure Loss Type"] = "Coeff"
props["Free Area Ratio"] = str(free_area_ratio)
props["External Rad. Temperature"] = external_temp
props["External Total Pressure"] = expternal_pressure
props["External Total Pressure"] = external_pressure

else:
props["Pressure Loss Type"] = "Curve"
props["External Rad. Temperature"] = external_temp
props["External Total Pressure"] = expternal_pressure
props["External Total Pressure"] = external_pressure

props["X"] = x_curve
props["Y"] = y_curve
Expand Down
4 changes: 2 additions & 2 deletions pyaedt/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def assign_em_losses(

assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."

self.logger.info("Mapping HFSS EM Lossess")
self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
projname = "This Project*"
Expand Down Expand Up @@ -282,7 +282,7 @@ def assign_thermal_map(

assert self.solution_type == "Structural", "This method works only in a Mechanical Structural analysis."

self.logger.info("Mapping HFSS EM Lossess")
self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
projname = "This Project*"
Expand Down
11 changes: 7 additions & 4 deletions pyaedt/modeler/cad/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -4562,7 +4562,8 @@ def import_3d_cad(
create_group=True,
separate_disjoints_lumped_object=False,
import_free_surfaces=False,
point_coicidence_tolerance=1e-6,
point_coincidence_tolerance=1e-6,
**kwargs,
):
"""Import a CAD model.

Expand Down Expand Up @@ -4592,7 +4593,7 @@ def import_3d_cad(
Either to automatically separate disjoint parts. The default is ``False``.
import_free_surfaces : bool, optional
Either to import free surfaces parts. The default is ``False``.
point_coicidence_tolerance : float, optional
point_coincidence_tolerance : float, optional
Tolerance on point. Default is ``1e-6``.

Returns
Expand All @@ -4605,7 +4606,9 @@ def import_3d_cad(

>>> oEditor.Import
"""

if "point_coicidence_tolerance" in kwargs:
self.logger.warning("point_coicidence_tolerance is deprecated, please use instead.")
point_coincidence_tolerance = kwargs["point_coicidence_tolerance"]
if str(healing) in ["0", "1"]:
warnings.warn(
"Assigning `0` or `1` to `healing` option is deprecated. Assign `True` or `False` instead.",
Expand All @@ -4621,7 +4624,7 @@ def import_3d_cad(
vArg1.append("CreateGroup:="), vArg1.append(create_group)
vArg1.append("STLFileUnit:="), vArg1.append("Auto")
vArg1.append("MergeFacesAngle:="), vArg1.append(-1)
vArg1.append("PointCoincidenceTol:="), vArg1.append(point_coicidence_tolerance)
vArg1.append("PointCoincidenceTol:="), vArg1.append(point_coincidence_tolerance)
vArg1.append("CreateLightweightPart:="), vArg1.append(create_lightweigth_part)
vArg1.append("ImportMaterialNames:="), vArg1.append(import_materials)
vArg1.append("SeparateDisjointLumps:="), vArg1.append(separate_disjoints_lumped_object)
Expand Down
4 changes: 2 additions & 2 deletions pyaedt/modeler/cad/object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""
This module contains these classes: `Components3DLayout`,`CircuitComponent',
`EdgePrimitive`, `EdgeTypePrimitive`, `FacePrimitive`, `Geometries3DLayout`,
`Nets3DLayout`, `Objec3DLayout`, `Object3d`, `Padstack`, `PDSHole`, `PDSLayer`,
`Nets3DLayout`, `Object3DLayout`, `Object3d`, `Padstack`, `PDSHole`, `PDSLayer`,
`Pins3DLayout', and `VertexPrimitive`.

This module provides methods and data structures for managing all properties of
objects (points, lines, sheeets, and solids) within the AEDT 3D Modeler.
objects (points, lines, sheets, and solids) within the AEDT 3D Modeler.

"""
from __future__ import absolute_import # noreorder
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/modeler/geometry_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def is_projection_inside(a1, a2, b1, b2):
Returns
-------
bool
``True`` when the projected segment is inside the other segmennt, ``False`` otherwise.
``True`` when the projected segment is inside the other segment, ``False`` otherwise.

"""
if not GeometryOperators.is_parallel(a1, a2, b1, b2):
Expand Down
Loading
Loading