Skip to content

Commit

Permalink
Merge branch 'main' into release/0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcapodi78 authored and maxcapodi78 committed Sep 1, 2023
2 parents 898f30e + 5334f5c commit bc332ee
Show file tree
Hide file tree
Showing 30 changed files with 1,376 additions and 168 deletions.
11 changes: 10 additions & 1 deletion _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,21 @@ def test_75_plot_field_line_traces(self, m2dtest):
plot.surfaces_indexes.append(8)
assert not plot.update()

def test_98_get_variations(self, field_test):
vars = field_test.available_variations.get_variation_strings()
assert vars
variations = field_test.available_variations.variations()
assert type(variations) is list
assert type(variations[0]) is list
vars_dict = field_test.available_variations.variations(output_as_dict=True)
assert type(vars_dict) is list
assert type(vars_dict[0]) is dict

def test_z99_delete_variations(self, q3dtest):
assert q3dtest.cleanup_solution()

def test_z99_delete_variations_B(self, field_test):
vars = field_test.available_variations.get_variation_strings()
assert field_test.available_variations.variations()
assert field_test.cleanup_solution(vars, entire_solution=False)
assert field_test.cleanup_solution(vars, entire_solution=True)

Expand Down
15 changes: 15 additions & 0 deletions _unittest/test_27_Maxwell2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ def test_14a_model_depth(self):
self.aedtapp.model_depth = 2.0
assert self.aedtapp.change_design_settings({"ModelDepth": "3mm"})

def test_14b_skew_model(self):
self.aedtapp.set_active_design("Basis_Model_For_Test")
assert self.aedtapp.apply_skew()
assert not self.aedtapp.apply_skew(skew_type="Invalid")
assert not self.aedtapp.apply_skew(skew_part="Invalid")
assert not self.aedtapp.apply_skew(
skew_type="Continuous", skew_part="Stator", skew_angle="0.5", skew_angle_unit="Invalid"
)
assert not self.aedtapp.apply_skew(
skew_type="User Defined", number_of_slices="4", custom_slices_skew_angles=["1", "2", "3"]
)
assert self.aedtapp.apply_skew(
skew_type="User Defined", number_of_slices="4", custom_slices_skew_angles=["1", "2", "3", "4"]
)

def test_15_assign_movement(self):
self.aedtapp.set_active_design("Y_Connections")
self.aedtapp.insert_design("Motion")
Expand Down
58 changes: 40 additions & 18 deletions doc/source/Resources/PyAEDTInstallerFromDesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,37 @@ def run_pyinstaller_from_c_python(oDesktop):
return_code = run_command(" ".join(command))
err_msg = "There was an error while installing PyAEDT. Refer to the Terminal window where AEDT was launched " \
"from."

if version >= "232":
oDesktop.RefreshToolkitUI()

if is_windows:
venv_dir = os.path.join(os.environ["APPDATA"], "pyaedt_env_ide", "v" + version)
python_exe = os.path.join(venv_dir, "Scripts", "python.exe")
else:
venv_dir = os.path.join(os.environ["HOME"], "pyaedt_env_ide", "v" + version)
python_exe = os.path.join(venv_dir, "bin", "python")
if str(return_code) != "0":
oDesktop.AddMessage("", "", 2, err_msg)
return
else:
oDesktop.AddMessage("", "", 0, "PyAEDT setup complete.")


msg = "PyAEDT setup complete."
import tempfile
python_script = os.path.join(tempfile.gettempdir(), "configure_pyaedt.py")
with open(python_script, "w") as f:
# enable in debu mode
#f.write("import sys\n")
#f.write('sys.path.insert(0, r"c:\\ansysdev\\git\\repos\\pyaedt")\n')
f.write("from pyaedt.misc.aedtlib_personalib_install import add_pyaedt_to_aedt\n")
f.write('add_pyaedt_to_aedt(aedt_version="{}", is_student_version={}, use_sys_lib=False, new_desktop_session=False, pers_dir=r"{}")\n'.format(oDesktop.GetVersion()[:6], is_student_version(oDesktop), oDesktop.GetPersonalLibDirectory()))

command = r'"{}" "{}"'.format(python_exe, python_script)
oDesktop.AddMessage("", "", 0, command)
ret_code = os.system(command)
if ret_code != 0:
oDesktop.AddMessage("", "", 2, "Error configuring the configuration Tab.")
return
if version >= "232":
oDesktop.RefreshToolkitUI()
msg = "PyAEDT configuration complete."
if is_linux:
msg += " Please ensure Ansys Electronics Desktop is launched in gRPC mode (i.e. launch ansysedt with -grpcsrv" \
" argument) to take advantage of the new toolkits."
Expand Down Expand Up @@ -152,19 +174,19 @@ def install_pyaedt():
else:
run_command('"{}" --default-timeout=1000 install pyaedt[full]'.format(pip_exe))

if is_windows:
pyaedt_setup_script = "{}/Lib/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(venv_dir)
else:
pyaedt_setup_script = "{}/lib/python{}/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(
venv_dir, args.python_version)

if not os.path.isfile(pyaedt_setup_script):
sys.exit("[ERROR] PyAEDT was not setup properly since {} file does not exist.".format(pyaedt_setup_script))

command = '"{}" "{}" --version={}'.format(python_exe, pyaedt_setup_script, args.version)
if args.student:
command += " --student"
run_command(command)
# if is_windows:
# pyaedt_setup_script = "{}/Lib/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(venv_dir)
# else:
# pyaedt_setup_script = "{}/lib/python{}/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(
# venv_dir, args.python_version)
#
# if not os.path.isfile(pyaedt_setup_script):
# sys.exit("[ERROR] PyAEDT was not setup properly since {} file does not exist.".format(pyaedt_setup_script))
#
# command = '"{}" "{}" --version={}'.format(python_exe, pyaedt_setup_script, args.version)
# if args.student:
# command += " --student"
# run_command(command)
sys.exit(0)


Expand Down
51 changes: 35 additions & 16 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from collections import OrderedDict
import os
import re
import shutil
import tempfile
import time
Expand Down Expand Up @@ -919,41 +920,59 @@ def variables(self):
list of str
List of names of independent variables.
"""
return [i for i in self._app.variable_manager.independent_variables]
return self._app.variable_manager.independent_variable_names

@pyaedt_function_handler()
def variations(self, setup_sweep=None):
def variations(self, setup_sweep=None, output_as_dict=False):
"""Variations.
Parameters
----------
setup_sweep : str, optional
Setup name with the sweep to search for variations on. The default is ``None``.
output_as_dict : bool, optional
Whether to output the variations as a dict. The default is ``False``.
Returns
-------
list of lists
list of lists, List of dicts
List of variation families.
References
----------
>>> oModule.GetAvailableVariations
"""
vs = self.get_variation_strings(setup_sweep)
variations_string = self.get_variation_strings(setup_sweep)
variables = [k for k, v in self._app.variable_manager.variables.items() if not v.post_processing]
families = []
if vs:
for v in vs:
variations = v.split(" ")
family = []
for el in self.variables:
family.append(el + ":=")
i = 0
while i < len(variations):
if variations[i][0 : len(el)] == el:
family.append([variations[i][len(el) + 2 : -1]])
i += 1
families.append(family)
if variations_string:
for vs in variations_string:
vsplit = vs.split(" ")
variation = []
for v in vsplit:
m = re.search(r"(.+?)='(.+?)'", v)
if m and len(m.groups()) == 2:
variation.append([m.group(1), m.group(2)])
else: # pragma: no cover
raise Exception("Error in splitting the variation variable.")
family_list = []
family_dict = {}
count = 0
for var in variables:
family_list.append(var + ":=")
for v in variation:
if var == v[0]:
family_list.append([v[1]])
family_dict[v[0]] = v[1]
count += 1
break
if count != len(variation): # pragma: no cover
raise IndexError("Not all variations were found in variables.")
if output_as_dict:
families.append(family_dict)
else:
families.append(family_list)
return families

@pyaedt_function_handler()
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/application/Analysis3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FieldAnalysis3D(Analysis, object):
Name of the setup to use as the nominal. The default is
``None``, in which case the active setup is used or
nothing is used.
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
non_graphical : bool, optional
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/application/Analysis3DLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FieldAnalysis3DLayout(Analysis):
Name of the setup to use as the nominal. The default is
``None``, in which case the active setup is used or
nothing is used.
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
NG : bool, optional
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/application/AnalysisMaxwellCircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnalysisMaxwellCircuit(Analysis):
Name of the design to select. The default is ``None``, in
which case an attempt is made to get an active design. If no
designs are present, an empty design is created.
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``. If ``None``,
the active setup is used or the latest installed version is
used.
Expand Down
15 changes: 11 additions & 4 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Design(AedtObjects):
solution_type : str, optional
Solution type to apply to the design. The default is
``None``, in which case the default type is applied.
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
non_graphical : bool, optional
Expand Down Expand Up @@ -2828,9 +2828,16 @@ def change_design_settings(self, settings):
bool
"""
arg = ["NAME:Design Settings Data"]
for k, v in settings.items():
arg.append(k + ":=")
arg.append(v)
for key, value in settings.items():
if "SkewSliceTable" not in key:
arg.append(key + ":=")
arg.append(value)
else:
arg_skew = [key]
if isinstance(value, list):
for v in value:
arg_skew.append(v)
arg.append(arg_skew)
self.odesign.SetDesignSettings(arg)
return True

Expand Down
11 changes: 6 additions & 5 deletions pyaedt/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class Circuit(FieldAnalysisCircuit, object):
Name of the setup to use as the nominal. The default is
``None``, in which case the active setup is used or
nothing is used.
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
This parameter is ignored when Script is launched within AEDT.
Examples of input values are ``232``, ``23.2``,``2023.2``,``"2023.2"``.
non_graphical : bool, optional
Whether to run AEDT in non-graphical mode. The default
is ``False``, in which case AEDT is launched in graphical mode.
Expand Down Expand Up @@ -104,15 +105,15 @@ class Circuit(FieldAnalysisCircuit, object):
>>> aedtapp = Circuit("myfile.aedt")
Create an instance of Circuit using the 2021 R1 version and
Create an instance of Circuit using the 2023 R2 version and
open the specified project, which is ``"myfile.aedt"``.
>>> aedtapp = Circuit(specified_version="2021.2", projectname="myfile.aedt")
>>> aedtapp = Circuit(specified_version=2023.2, projectname="myfile.aedt")
Create an instance of Circuit using the 2021 R2 student version and open
Create an instance of Circuit using the 2023 R2 student version and open
the specified project, which is named ``"myfile.aedt"``.
>>> hfss = Circuit(specified_version="2021.2", projectname="myfile.aedt", student_version=True)
>>> hfss = Circuit(specified_version="2023.2", projectname="myfile.aedt", student_version=True)
"""

Expand Down
17 changes: 11 additions & 6 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pyaedt.generic.desktop_sessions import _desktop_sessions
from pyaedt.generic.general_methods import active_sessions
from pyaedt.generic.general_methods import com_active_sessions
from pyaedt.generic.general_methods import get_string_version
from pyaedt.generic.general_methods import grpc_active_sessions
from pyaedt.generic.general_methods import inside_desktop
from pyaedt.generic.general_methods import is_ironpython
Expand Down Expand Up @@ -383,9 +384,10 @@ class Desktop(object):
Parameters
----------
specified_version : str, optional
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case the
active setup or latest installed version is used.
Examples of input values are ``232``, ``23.2``,``2023.2``,``"2023.2"``.
non_graphical : bool, optional
Whether to launch AEDT in non-graphical mode. The default
is ``False``, in which case AEDT is launched in graphical mode.
Expand Down Expand Up @@ -416,19 +418,19 @@ class Desktop(object):
Examples
--------
Launch AEDT 2021 R1 in non-graphical mode and initialize HFSS.
Launch AEDT 2023 R1 in non-graphical mode and initialize HFSS.
>>> import pyaedt
>>> desktop = pyaedt.Desktop(specified_version="2021.2", non_graphical=True)
>>> desktop = pyaedt.Desktop(specified_version="2023.2", non_graphical=True)
PyAEDT INFO: pyaedt v...
PyAEDT INFO: Python version ...
>>> hfss = pyaedt.Hfss(designname="HFSSDesign1")
PyAEDT INFO: Project...
PyAEDT INFO: Added design 'HFSSDesign1' of type HFSS.
Launch AEDT 2021 R1 in graphical mode and initialize HFSS.
Launch AEDT 2023 R2 in graphical mode and initialize HFSS.
>>> desktop = Desktop("2021.2")
>>> desktop = Desktop(232)
PyAEDT INFO: pyaedt v...
PyAEDT INFO: Python version ...
>>> hfss = pyaedt.Hfss(designname="HFSSDesign1")
Expand Down Expand Up @@ -474,11 +476,12 @@ def __init__(
port=0,
aedt_process_id=None,
):
if aedt_process_id: # pragma no cover
aedt_process_id = int(aedt_process_id)
if getattr(self, "_initialized", None) is not None and self._initialized:
return
else:
self._initialized = True

self._initialized_from_design = True if Desktop._invoked_from_design else False
Desktop._invoked_from_design = False

Expand Down Expand Up @@ -551,6 +554,7 @@ def __init__(
sessions = active_sessions(
version=specified_version, student_version=student_version_flag, non_graphical=non_graphical
)
self.logger.info(sessions)
if aedt_process_id in sessions:
if sessions[aedt_process_id] != -1:
self.port = sessions[aedt_process_id]
Expand Down Expand Up @@ -749,6 +753,7 @@ def _assert_version(self, specified_version, student_version):
self.logger.warning("Only AEDT Student Version found on the system. Using Student Version.")
elif student_version:
specified_version += "SV"
specified_version = get_string_version(specified_version)

if float(specified_version[0:6]) < 2019:
raise ValueError("PyAEDT supports AEDT version 2021 R1 and later. Recommended version is 2022 R2 or later.")
Expand Down
8 changes: 6 additions & 2 deletions pyaedt/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pyaedt.generic.constants import AEDT_UNITS
from pyaedt.generic.constants import SolverType
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import get_string_version
from pyaedt.generic.general_methods import inside_desktop
from pyaedt.generic.general_methods import is_ironpython
from pyaedt.generic.general_methods import is_linux
Expand Down Expand Up @@ -79,8 +80,9 @@ class Edb(Database):
isreadonly : bool, optional
Whether to open EBD in read-only mode when it is
owned by HFSS 3D Layout. The default is ``False``.
edbversion : str, optional
Version of EDB to use. The default is ``"2021.2"``.
edbversion : str, int, float, optional
Version of EDB to use. The default is ``None``.
Examples of input values are ``232``, ``23.2``,``2023.2``,``"2023.2"``.
isaedtowned : bool, optional
Whether to launch EDB from HFSS 3D Layout. The
default is ``False``.
Expand Down Expand Up @@ -138,6 +140,8 @@ def __init__(
use_ppe=False,
technology_file=None,
):
edbversion = get_string_version(edbversion)

self._clean_variables()
Database.__init__(self, edbversion=edbversion, student_version=student_version)
self.standalone = True
Expand Down
Loading

0 comments on commit bc332ee

Please sign in to comment.