Skip to content

Commit

Permalink
Merge branch 'main' into release/0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcapodi78 committed Jan 27, 2022
2 parents 73ea854 + 7c64c1c commit 917a936
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 79 deletions.
16 changes: 7 additions & 9 deletions _unittest/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def setup_class(self):
# set a scratch directory and the environment / test data
with Scratch(scratch_path) as self.local_scratch:
self.aedtapp = Maxwell3d(solution_type="EddyCurrent")
core_loss_file = "PlanarTransformer.aedt"
example_project = os.path.join(local_path, "example_models", core_loss_file)
self.file_path = self.local_scratch.copyfile(example_project)

def teardown_class(self):
self.aedtapp._desktop.ClearMessages("", "", 3)
Expand Down Expand Up @@ -225,18 +228,13 @@ def test_30_assign_movement(self):
assert bound.props["Velocity"] == "1m_per_sec"

def test_31_core_losses(self):
core_loss_file = "PlanarTransformer.aedt"
example_project = os.path.join(local_path, "example_models", core_loss_file)
file_path = self.local_scratch.copyfile(example_project)
m3d1 = Maxwell3d(file_path)

m3d1 = Maxwell3d(self.file_path)
assert m3d1.set_core_losses(["PQ_Core_Bottom", "PQ_Core_Top"])
assert m3d1.set_core_losses(["PQ_Core_Bottom"], False)
self.aedtapp.close_project(m3d1.project_name)
self.aedtapp.close_project(m3d1.project_name, False)

def test_32_matrix(self):
core_loss_file = "PlanarTransformer.aedt"
example_project = os.path.join(local_path, "example_models", core_loss_file)
file_path = self.local_scratch.copyfile(example_project)
m3d1 = Maxwell3d(file_path)
m3d1 = Maxwell3d(self.file_path)
assert m3d1.assign_matrix("pri", "mymatrix") == "mymatrix"
self.aedtapp.close_project(m3d1.project_name, False)
2 changes: 1 addition & 1 deletion doc/source/API/ClientServer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ To bypass current IronPython limits, you can launch PyAEDT on a Linux machine:
faces = client.convert_remote_object(box1.faces)
.. image:: Resources/IronPython2Cpython.png
.. image:: /Resources/IronPython2Cpython.png
:width: 800
:alt: Electronics Desktop Launched
22 changes: 22 additions & 0 deletions doc/source/Resources/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ To use standalone IronPython, run this ``install`` command:
.. code:: python
ipy64 -X:Frames -m pip install pyaedt
Installing Pyaedt from Bat File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ansys Electronics Desktop already includes a CPython 3.7 that could be used to run pyaedt.
User can download the following batch file and run in local machine.
The batch file works on Windows and executes the following steps:
1. Create a python virtual environment in your %APPDATA% folder. To do that it uses CPython in your latest version of AEDT installed in your machine.
2. Install Pyaedt.
3. Install Spyder.
4. Install Jupyter Lab.
5. Create a symbolic link from pyaedt installation to Ansys PersonalLib. In this way scripts can be run also within AEDT.
6. Update pyaedt
7. Run the tool you choose (Spyder, Jupyter or simple console).

Steps from 1 to 5 are executed only first time. Step 6 is executed only running the command with
the following option:
pyaedt_with_IDE.bat -update

With this approach users can have a complete IDE to write Pyaedt Scripts in Windows with a simple batch file.

:download:`PyAEDT Environment with IDE <pyaedt_with_IDE.bat>`
34 changes: 33 additions & 1 deletion doc/source/Resources/User_Guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,36 @@ As an alternative, the user can upload the script to run to the server and run i
remote_script ="path/to/my/remote/pyaedt/script.py"
upload(local_script, remote_script, "servername")
ansysem = "/path/to/AnsysEMxxx/Linux64"
my_client.root.run_script(remote_script, ansysem_path=ansysem)
my_client.root.run_script(remote_script, ansysem_path=ansysem)
CPython on Linux with Client-Server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To bypass current IronPython limits, you can launch PyAEDT on a Linux machine:
1. Using pip, install PyAEDT 0.4.23 or later on a Linux machine.
2. Launche CPython and run PyAEDT.
.. code:: python
# Launch the latest installed version of PyAEDT in non-graphical mode.
from pyaedt.common_rpc import launch_ironpython_server
client = launch_ironpython_server(ansysem_path="/path/to/ansys/executable/folder", non_graphical=True, port=18000)
hfss = client.root.hfss()
# put your code here
3. If the method returns a list or dictionary, use the following method to work around an
issue with CPython handling:
.. code:: python
box1 = hfss.modeler.create_box([0,0,0],[1,1,1])
# convert_remote_object method convert remote ironpython list to local cpython.
faces = client.convert_remote_object(box1.faces)
.. image:: ./IronPython2Cpython.png
:width: 800
:alt: Electronics Desktop Launched
51 changes: 51 additions & 0 deletions doc/source/Resources/pyaedt_with_IDE.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@echo off
if "%ANSYSEM_ROOT221%" =="" (
if "%ANSYSEM_ROOT212%" =="" (
if "%ANSYSEM_ROOT211%" =="" (
echo AEDT 21R1 or greater has to be installed
pause
EXIT /B
) else (
set aedt_path=%ANSYSEM_ROOT211%
set aedt_var=ANSYSEM_ROOT211
echo Found AEDT Version 21R1
)
) else (
set aedt_path=%ANSYSEM_ROOT212%
set aedt_var=ANSYSEM_ROOT212
echo Found AEDT Version 21R2
)
) else (
set aedt_path=%ANSYSEM_ROOT221%
set aedt_var=ANSYSEM_ROOT221
echo Found AEDT Version 22R1
)

set /p run=Python or Jupyter?(0=Spyder, 1=Jupyter, 2=Console)
setlocal enableDelayedExpansion
cd "%APPDATA%"
if not exist "%APPDATA%\pyaedt_env_ide\" (
echo Installing Pyaedt
"%aedt_path%\commonfiles\CPython\3_7\winx64\Release\python\python.exe" -m venv "%APPDATA%\pyaedt_env_ide"
"%APPDATA%\pyaedt_env_ide\Scripts\python.exe" -m pip install --upgrade pip
"%APPDATA%\pyaedt_env_ide\Scripts\pip" install pyaedt
"%APPDATA%\pyaedt_env_ide\Scripts\pip" install jupyterlab
"%APPDATA%\pyaedt_env_ide\Scripts\pip" install spyder
"%APPDATA%\pyaedt_env_ide\Scripts\pip" install ipython -U
call "%APPDATA%\pyaedt_env_ide\Scripts\python" "%APPDATA%\pyaedt_env_ide\Lib\site-packages\pyaedt\misc\aedtlib_personalib_install.py" %aedt_var%
)
if [%1%]==[-update] (
echo Updating Pyaedt
"%APPDATA%\pyaedt_env_ide\Scripts\pip" install pyaedt -U
)
if %run%==1 (
echo Launching Jupyter Lab
"%APPDATA%\pyaedt_env_ide\Scripts\jupyter.exe" lab
) else ( if %run%==0 (
echo Launching Spyder
"%APPDATA%\pyaedt_env_ide\Scripts\spyder.exe"
) else (
"%APPDATA%\pyaedt_env_ide\Scripts\ipython.exe"
)
)

2 changes: 1 addition & 1 deletion examples/02-HFSS/Flex_CPWG.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Flex Coplanar Waveguide Example
--------------------/----------
-------------------------------
This example shows how you can use PyAEDT to create a flex cable coplanar waveguide.
"""

Expand Down
9 changes: 9 additions & 0 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,15 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, props={}):
setuptype = self.design_solutions.default_setup
name = self.generate_unique_setup_name(setupname)
setup = Setup(self, setuptype, name)
if self.design_type == "HFSS" and not self.get_excitations_name() and "MaxDeltaS" in setup.props:
new_dict = OrderedDict()
for k, v in setup.props.items():
if k == "MaxDeltaS":
new_dict["MaxDeltaE"] = 0.01
else:
new_dict[k] = v

setup.props = new_dict
setup.create()
if props:
for el in props:
Expand Down
31 changes: 8 additions & 23 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,12 @@
from pyaedt.generic.DataHandlers import variation_string_to_dict
from pyaedt.modules.Boundary import BoundaryObject
from pyaedt.generic.general_methods import generate_unique_name

from pyaedt.application.design_solutions import model_names, solutions_defaults

if sys.version_info.major > 2:
import base64


model_names = {
"Maxwell 2D": "Maxwell2DModel",
"Maxwell 3D": "Maxwell3DModel",
"Twin Builder": "SimplorerCircuit",
"Circuit Design": "NexximCircuit",
"2D Extractor": "2DExtractorModel",
"Q3D Extractor": "Q3DModel",
"HFSS": "HFSSModel",
"Mechanical": "MechanicalModel",
"Icepak": "IcepakModel",
"RMxprtSolution": "RMxprtDesign",
"ModelCreation": "RMxprtDesign",
"HFSS 3D Layout Design": "PlanarEMCircuit",
"EMIT Design": "EMIT Design",
}


def list_difference(list1, list2):
return list(set(list1) - set(list2))

Expand Down Expand Up @@ -898,10 +881,7 @@ def default_solution_type(self):
Default for the solution type.
"""
if self.design_solutions._solution_options[self.design_solutions.solution_types[0]]["name"]:
return self.design_solutions._solution_options[self.design_solutions.solution_types[0]]["name"]
else:
return self.design_solutions.solution_types[0]
return solutions_defaults[self._design_type]

@property
def odesign(self):
Expand Down Expand Up @@ -2563,7 +2543,12 @@ def _insert_design(self, design_type, design_name=None, solution_type=None):
"RMxprt", unique_design_name, "Model Creation Inner-Rotor Induction Machine", ""
)
else:
new_design = self._oproject.InsertDesign(design_type, unique_design_name, self.default_solution_type, "")
if design_type == "HFSS" and self._aedt_version < "2021.2":
new_design = self._oproject.InsertDesign(design_type, unique_design_name, "DrivenModal", "")
else:
new_design = self._oproject.InsertDesign(
design_type, unique_design_name, self.default_solution_type, ""
)
logging.getLogger().info("Added design '%s' of type %s.", unique_design_name, design_type)
name = new_design.GetName()
if ";" in name:
Expand Down
Loading

0 comments on commit 917a936

Please sign in to comment.