Skip to content

Commit

Permalink
Merge branch 'main' into FEAT__Add_distributed_filters_topology
Browse files Browse the repository at this point in the history
  • Loading branch information
ramin4667 authored Jan 22, 2025
2 parents f35f87d + 8c592a1 commit 25292f4
Show file tree
Hide file tree
Showing 80 changed files with 3,292 additions and 59,144 deletions.
22 changes: 18 additions & 4 deletions doc/source/Resources/pyaedt_installer_from_aedt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@


VENV_DIR_PREFIX = ".pyaedt_env"

"""
It is possible create Python virtual environment in a specific directory by setting variable VENV_DIR.
For example,
VENV_DIR = "e:/pyaedt_env"
"""
VENV_DIR = None
if not VENV_DIR:
if is_windows:
VENV_DIR = os.path.join(os.environ["APPDATA"], VENV_DIR_PREFIX)
else:
VENV_DIR = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX)


DISCLAIMER = (
"This script will download and install certain third-party software and/or "
"open-source software (collectively, 'Third-Party Software'). Such Third-Party "
Expand Down Expand Up @@ -99,10 +113,10 @@ def run_pyinstaller_from_c_python(oDesktop):
# Add PyAEDT tabs in AEDT
# Virtual environment path and Python executable
if is_windows:
venv_dir = os.path.join(os.environ["APPDATA"], VENV_DIR_PREFIX, python_version_new)
venv_dir = os.path.join(VENV_DIR, python_version_new)
python_exe = os.path.join(venv_dir, "Scripts", "python.exe")
else:
venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, python_version_new)
venv_dir = os.path.join(VENV_DIR, python_version_new)
python_exe = os.path.join(venv_dir, "bin", "python")
pyaedt_path = os.path.join(venv_dir, "Lib", "site-packages", "ansys", "aedt", "core")
if is_linux:
Expand Down Expand Up @@ -207,11 +221,11 @@ def install_pyaedt():
python_version = "3_7"

if is_windows:
venv_dir = Path(os.environ["APPDATA"], VENV_DIR_PREFIX, python_version)
venv_dir = Path(VENV_DIR, python_version)
python_exe = venv_dir / "Scripts" / "python.exe"
pip_exe = venv_dir / "Scripts" / "pip.exe"
else:
venv_dir = Path(os.environ["HOME"], VENV_DIR_PREFIX, python_version)
venv_dir = Path(VENV_DIR, python_version)
python_exe = venv_dir / "bin" / "python"
pip_exe = venv_dir / "bin" / "pip"
os.environ["ANSYSEM_ROOT{}".format(args.version)] = args.edt_root
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies = [
"pyyaml",
"defusedxml>=0.7,<8.0",
"attrs!=24.3.0",
"referencing<0.36.0",
]

[project.optional-dependencies]
Expand Down
13 changes: 13 additions & 0 deletions src/ansys/aedt/core/application/aedt_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, desktop=None, project=None, design=None, is_inherithed=False)
self._o_symbol_manager = None
self._opadstackmanager = None
self._oradfield = None
self._onetwork_data_explorer = None

@property
def oradfield(self):
Expand Down Expand Up @@ -429,3 +430,15 @@ def o_model_manager(self):
if not self._o_model_manager and self.odefinition_manager:
self._o_model_manager = self.odefinition_manager.GetManager("Model")
return self._o_model_manager

@property
def onetwork_data_explorer(self):
"""Network data explorer module.
References
----------
>>> oDesktop.GetTool("NdExplorer")
"""
if not self._onetwork_data_explorer:
self._onetwork_data_explorer = self._odesktop.GetTool("NdExplorer")
return self._onetwork_data_explorer
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ def get_object_material_properties(self, assignment=None, prop_names=None):

dict = {}
for entry in assignment:
mat_name = self.modeler[entry].material_name
mat_name = self.modeler[entry].material_name.casefold()
mat_props = self.materials.material_keys[mat_name]
if prop_names is None:
dict[entry] = mat_props._props
Expand Down
42 changes: 18 additions & 24 deletions src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os

from ansys.aedt.core.application.analysis import Analysis
from ansys.aedt.core.generic.checks import min_aedt_version
from ansys.aedt.core.generic.configurations import Configurations
from ansys.aedt.core.generic.constants import unit_converter
from ansys.aedt.core.generic.general_methods import generate_unique_name
Expand Down Expand Up @@ -224,6 +225,7 @@ def components3d(self):
return components_dict

@pyaedt_function_handler(objects="assignment", export_path="output_file")
@min_aedt_version("2021.2")
def plot(
self,
assignment=None,
Expand Down Expand Up @@ -280,23 +282,20 @@ def plot(
:class:`ansys.aedt.core.generic.plot.ModelPlotter`
Model Object.
"""
if self._aedt_version < "2021.2":
self.logger.warning("Plot is supported from AEDT 2021 R2.")
else:
return self.post.plot_model_obj(
objects=assignment,
show=show,
export_path=output_file,
plot_as_separate_objects=plot_as_separate_objects,
plot_air_objects=plot_air_objects,
force_opacity_value=force_opacity_value,
clean_files=clean_files,
view=view,
show_legend=show_legend,
dark_mode=dark_mode,
show_bounding=show_bounding,
show_grid=show_grid,
)
return self.post.plot_model_obj(
objects=assignment,
show=show,
export_path=output_file,
plot_as_separate_objects=plot_as_separate_objects,
plot_air_objects=plot_air_objects,
force_opacity_value=force_opacity_value,
clean_files=clean_files,
view=view,
show_legend=show_legend,
dark_mode=dark_mode,
show_bounding=show_bounding,
show_grid=show_grid,
)

@pyaedt_function_handler(setup_name="setup", variation_string="variations")
def export_mesh_stats(self, setup, variations="", mesh_path=None):
Expand Down Expand Up @@ -1145,6 +1144,7 @@ def flatten_3d_components(self, components=None, purge_history=True, password=No
return True

@pyaedt_function_handler(object_name="assignment")
@min_aedt_version("2023.2")
def identify_touching_conductors(self, assignment=None):
# type: (str) -> dict
"""Identify all touching components and group in a dictionary.
Expand All @@ -1161,10 +1161,7 @@ def identify_touching_conductors(self, assignment=None):
dict
"""
if settings.aedt_version < "2023.2": # pragma: no cover
self.logger.error("This method requires CPython and PyVista.")
return {}
if settings.aedt_version >= "2023.2" and self.design_type == "HFSS": # pragma: no cover
if self.design_type == "HFSS": # pragma: no cover
nets_aedt = self.oboundary.IdentifyNets(True)
nets = {}
for net in nets_aedt[1:]:
Expand Down Expand Up @@ -1312,9 +1309,6 @@ def import_dxf(
import_method : int, bool
Whether the import method is ``Script`` or ``Acis``.
The default is ``1``, which means that the ``Acis`` is used.
sheet_bodies_2d : bool, optional
Whether importing as 2D sheet bodies causes imported objects to
be organized in terms of 2D sheets. The default is ``True``.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from ansys.aedt.core.generic.constants import AEDT_UNITS
from ansys.aedt.core.generic.constants import unit_system
from ansys.aedt.core.generic.data_handlers import variation_string_to_dict
from ansys.aedt.core.generic.general_methods import GrpcApiError
from ansys.aedt.core.generic.errors import GrpcApiError
from ansys.aedt.core.generic.general_methods import check_and_download_file
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import inner_project_settings
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from ansys.aedt.core.generic.constants import SI_UNITS
from ansys.aedt.core.generic.constants import _resolve_unit_system
from ansys.aedt.core.generic.constants import unit_system
from ansys.aedt.core.generic.general_methods import GrpcApiError
from ansys.aedt.core.generic.errors import GrpcApiError
from ansys.aedt.core.generic.general_methods import check_numeric_equivalence
from ansys.aedt.core.generic.general_methods import is_array
from ansys.aedt.core.generic.general_methods import is_number
Expand Down
1 change: 0 additions & 1 deletion src/ansys/aedt/core/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def __init__(
remove_lock=remove_lock,
)
ScatteringMethods.__init__(self, self)
self.onetwork_data_explorer = self._desktop.GetTool("NdExplorer")

def _init_from_design(self, *args, **kwargs):
self.__init__(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ def __init__(
if getattr(self, "_initialized", None) is not None and self._initialized:
try:
self.grpc_plugin.recreate_application(True)
except Exception: # nosec
pass
except Exception:
pyaedt_logger.debug("Failed to recreate application.")
return
else:
self._initialized = True
Expand Down
12 changes: 5 additions & 7 deletions src/ansys/aedt/core/emit_core/couplings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
This module provides for interacting with EMIT Analysis and Results windows.
"""

import warnings
from ansys.aedt.core.generic.checks import min_aedt_version


class CouplingsEmit(object):
Expand Down Expand Up @@ -156,9 +156,12 @@ def update_link(self, coupling_name):
self._odesign.UpdateLink(coupling_name)

@property
@min_aedt_version("2022.2")
def linkable_design_names(self):
"""List the available link names.
This property is only available in AEDT version 2022.2 or higher.
Parameters
----------
None
Expand All @@ -174,12 +177,7 @@ def linkable_design_names(self):
>>> app = Emit("Apache with multiple links")
>>> links = app.couplings.linkable_design_names
"""
desktop_version = self._desktop.GetVersion()[0:6]
if desktop_version >= "2022.2":
return self._odesign.GetAvailableLinkNames()
else:
warnings.warn("The function linkable_design_names() requires AEDT 2022 R2 or later.")
return []
return self._odesign.GetAvailableLinkNames()

@property
def cad_nodes(self):
Expand Down
89 changes: 89 additions & 0 deletions src/ansys/aedt/core/generic/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Provides functions for performing common checks."""

from ansys.aedt.core.generic.errors import AEDTRuntimeError


def min_aedt_version(min_version: str):
"""Compare a minimum required version to the current AEDT version.
This decorator should only be used on methods where the associated object can reach the desktop instance.
Otherwise, there is no way to check version compatibility and an error is raised.
Parameters
----------
min_version: str
Minimum AEDT version required by the method.
The value should follow the format YEAR.RELEASE, for example '2024.2'.
Raises
------
AEDTRuntimeError
If the method version is higher than the AEDT version.
"""

def fetch_odesktop_from_common_attributes_names(item):
attributes_to_check = ["odesktop", "_odesktop", "_desktop"]
for attribute in attributes_to_check:
odesktop = getattr(item, attribute, None)
if odesktop is not None:
return odesktop

def fetch_odesktop_from_private_app_attribute(item):
app = getattr(item, f"_{item.__class__.__name__}__app", None)
if app is not None:
return app.odesktop

def fetch_odesktop_from_desktop_class(item):
attributes_to_check = ["desktop_class", "_desktop_class"]
for attribute in attributes_to_check:
desktop_class = getattr(item, attribute, None)
if desktop_class is not None:
return desktop_class.odesktop

def aedt_version_decorator(method):
def wrapper(self, *args, **kwargs):
odesktop = (
fetch_odesktop_from_common_attributes_names(self)
or fetch_odesktop_from_private_app_attribute(self)
or fetch_odesktop_from_desktop_class(self)
)
if odesktop is None:
raise AEDTRuntimeError("The AEDT desktop object is not available.")

desktop_version = odesktop.GetVersion()
if desktop_version < min_version:
raise AEDTRuntimeError(
f"The method '{method.__name__}' requires a minimum Ansys release version of "
+ f"{min_version}, but the current version used is {desktop_version}."
)
else:
return method(self, *args, **kwargs)

return wrapper

return aedt_version_decorator
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ansys.aedt.core import __version__
from ansys.aedt.core.application.variables import decompose_variable_value
from ansys.aedt.core.generic.data_handlers import _arg2dict
from ansys.aedt.core.generic.general_methods import GrpcApiError
from ansys.aedt.core.generic.errors import GrpcApiError
from ansys.aedt.core.generic.general_methods import generate_unique_folder_name
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import open_file
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/generic/data_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

from decimal import Decimal
import math
import random
import re
import secrets
import string
import unicodedata

Expand Down Expand Up @@ -272,7 +272,7 @@ def random_string(length=6, only_digits=False, char_set=None):
char_set = string.digits
else:
char_set = string.ascii_uppercase + string.digits
random_str = "".join(random.choice(char_set) for _ in range(int(length)))
random_str = "".join(secrets.choice(char_set) for _ in range(int(length)))
return random_str


Expand Down
Loading

0 comments on commit 25292f4

Please sign in to comment.