Skip to content

Commit

Permalink
Set JMAG Versions to be Specified by User (#340)
Browse files Browse the repository at this point in the history
* Update BSPM analyzer and example to include version

* add SynR changes to JMAG versioning

* add warnings for non-existent JMAG versions

* adjust tutorials and documentation for new versioning system

---------

Co-authored-by: dmnewman3 <[email protected]>
  • Loading branch information
dmnewman3 and dmnewman3 authored Mar 27, 2024
1 parent 64698da commit cd1e2cf
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/source/EM_analyzers/SynR_jmag2d_analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Input from User
To use this analyzer, users must pass in a ``MachineDesign`` object. An instance of the ``MachineDesign`` class can be created by passing in
``machine`` and ``operating_point`` objects. The machine must be a ``SynR_Machine`` and the ``operating_point`` must be of type
``SynR_Machine_Oper_Pt``. More information on both these classes is available in the ``SynR Design`` section under ``MACHINE DESIGNS``. To
initialize the ``SynR_JMAG_2D_FEA_Analyzer``, users must also specify analyzer configuration parameters.
initialize the ``SynR_JMAG_2D_FEA_Analyzer``, users must also specify analyzer configuration parameters. One can control the version of JMAG
desired for use in this analyzer using ``jmag_version``. For example, the use of JMAG-Designer21.1 would require an input of ``21.1``.

The tables below provide the input expected by the ``MachineDesign`` class and the configuration input required to initialize the
``SynR_JMAG_2D_FEA_Analyzer``.
Expand Down Expand Up @@ -217,6 +218,7 @@ A copy of this file lies in the ``eMach\examples\mach_eval_examples\SynR_eval``
jmag_scheduler=False,
jmag_visible=True,
scale_axial_length = True,
jmag_version=None,
)
SynR_em_analysis = SynR_em.SynR_EM_Analyzer(configuration)
Expand Down
4 changes: 3 additions & 1 deletion docs/source/EM_analyzers/bspm_jmag2d_analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Other Configurations

In addition to time step and mesh size, several other changes can be made to the BSPM JMAG analyzer. Most of these configurations are self
explanatory and are described using comments within the ``JMAG_2D_Config`` class. For example, by setting the ``jmag_visible`` to ``True`` or
``False``, users can control whether the JMAG application will be visible while a FEA evaluation is running.
``False``, users can control whether the JMAG application will be visible while a FEA evaluation is running. One can control the version of JMAG
desired for use in this analyzer using ``jmag_version``. For example, the use of JMAG-Designer21.1 would require an input of ``21.1``.

Input from User
*********************************
Expand Down Expand Up @@ -197,6 +198,7 @@ is shown below:
num_cpus=4,
jmag_scheduler=False,
jmag_visible=True,
jmag_visible=None,
)
em_analysis = BSPM_EM_Analyzer(jmag_config)
Expand Down
1 change: 1 addition & 0 deletions docs/source/EM_analyzers/inductance_analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ initializes the analyzer class with an explanation of the required configuration
jmag_scheduler=False,
jmag_visible=True,
scale_axial_length = True,
jmag_version=None,
)
SynR_inductance_analysis = SynR_inductance.SynR_Inductance_Analyzer(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ is stored in ``State`` for future reference. It is worth noting that the losses
num_cpus=4,
jmag_scheduler=False,
jmag_visible=False,
jmag_version=None,
)
em_analysis = em.BSPM_EM_Analyzer(jmag_config)
# define AnalysysStep for EM evaluation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_problem(state):
jmag_visible=True,
non_zero_end_ring_res = False,
scale_axial_length = True,
jmag_version="22.1",
)

SynR_em_analysis = SynR_em.SynR_EM_Analyzer(configuration)
Expand Down
1 change: 1 addition & 0 deletions examples/mach_eval_examples/SynR_eval/inductance_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_problem(state):
jmag_visible=True,
non_zero_end_ring_res = False,
scale_axial_length = True,
jmag_version="21.1",
)

SynR_inductance_analysis = SynR_inductance.SynR_Inductance_Analyzer(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_problem(state):
num_cpus=4,
jmag_scheduler=False,
jmag_visible=False,
jmag_version="21.1",
)
em_analysis = em.BSPM_EM_Analyzer(jmag_config)
# define AnalysysStep for EM evaluation
Expand Down
9 changes: 7 additions & 2 deletions mach_cad/tools/jmag/jmag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from win32com.client import DispatchEx
import os
import string

from ..tool_abc import toolabc as abc
from ..token_draw import TokenDraw
Expand All @@ -13,8 +14,12 @@
class JmagDesigner(
abc.ToolBase, abc.DrawerBase, abc.MakerExtrudeBase, abc.MakerRevolveBase
):
def __init__(self):
self.jd_instance = DispatchEx("designerstarter.InstanceManager")
def __init__(self, jmag_version=None):
if jmag_version is None:
self.jd_instance = DispatchEx("designerstarter.InstanceManager")
else:
jmag_version = jmag_version.translate(str.maketrans('', '', string.punctuation))
self.jd_instance = DispatchEx("designerstarter.InstanceManager.%s" % jmag_version)
self.jd = None # JMAG-Designer Application object
self.geometry_editor = None # The Geometry Editor object
self.doc = None # The document object in Geometry Editor
Expand Down
7 changes: 6 additions & 1 deletion mach_eval/analyzers/electromagnetic/SynR/SynR_em_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ def analyze(self, problem):
if attempts > 1:
self.project_name = self.project_name + "_attempts_%d" % (attempts)

toolJmag = JMAG.JmagDesigner()
JMAG_exist = os.path.exists("C:/Program Files/JMAG-Designer%s" % self.config.jmag_version)
if JMAG_exist is True:
toolJmag = JMAG.JmagDesigner(self.config.jmag_version)
else:
print('WARNING: The JMAG version does not exist, defaulting to newest JMAG version available!')
toolJmag = JMAG.JmagDesigner()

toolJmag.visible = self.config.jmag_visible
toolJmag.open(comp_filepath=expected_project_file, length_unit="DimMillimeter", study_type="Transient2D")
Expand Down
3 changes: 2 additions & 1 deletion mach_eval/analyzers/electromagnetic/SynR/SynR_em_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ def __init__(self, **kwargs) -> None:
self.num_cpus = kwargs["num_cpus"] # number of cpus or cores used. Only value if multiple_cpus = True
self.jmag_scheduler = kwargs["jmag_scheduler"] # True if it is desired to schedule jobs instead of solving immediately
self.jmag_visible = kwargs["jmag_visible"] # JMAG application visible if true
self.scale_axial_length = kwargs["scale_axial_length"] # True: scale axial length to get the required rated torque
self.scale_axial_length = kwargs["scale_axial_length"] # True: scale axial length to get the required rated torque
self.jmag_version = kwargs["jmag_version"] # JMAG application version
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def analyze(self, problem):
if attempts > 1:
self.project_name = self.project_name + "_attempts_%d" % (attempts)

toolJmag = JMAG.JmagDesigner()
JMAG_exist = os.path.exists("C:/Program Files/JMAG-Designer%s" % self.config.jmag_version)
if JMAG_exist is True:
toolJmag = JMAG.JmagDesigner(self.config.jmag_version)
else:
print('WARNING: The JMAG version does not exist, defaulting to newest JMAG version available!')
toolJmag = JMAG.JmagDesigner()

toolJmag.visible = self.config.jmag_visible
toolJmag.open(comp_filepath=expected_project_file, length_unit="DimMillimeter", study_type="Transient2D")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ def __init__(self, **kwargs) -> None:
self.num_cpus = kwargs["num_cpus"] # number of cpus or cores used. Only value if multiple_cpus = True
self.jmag_scheduler = kwargs["jmag_scheduler"] # True if it is desired to schedule jobs instead of solving immediately
self.jmag_visible = kwargs["jmag_visible"] # JMAG application visible if true
self.scale_axial_length = kwargs["scale_axial_length"] # True: scale axial length to get the required rated torque
self.scale_axial_length = kwargs["scale_axial_length"] # True: scale axial length to get the required rated torque
self.jmag_version = kwargs["jmag_version"] # JMAG application version
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import win32com.client
import os
import logging
import string

EPS = 0.01 # mm

Expand Down Expand Up @@ -28,9 +29,13 @@ def __init__(self, configuration):

self.config = configuration

def open(self, expected_project_file_path):
def open(self, expected_project_file_path, jmag_version=None):
if self.app is None:
app = win32com.client.Dispatch("designer.Application")
if jmag_version is None:
app = win32com.client.Dispatch("designer.Application")
else:
jmag_version = jmag_version.translate(str.maketrans('', '', string.punctuation))
app = win32com.client.Dispatch("designer.Application.%s" % jmag_version)
if self.config.jmag_visible == True:
app.Show()
else:
Expand Down
9 changes: 8 additions & 1 deletion mach_eval/analyzers/electromagnetic/bspm/jmag_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ def analyze(self, problem):
from .electrical_analysis.JMAG import JMAG

toolJd = JMAG(self.config)
app, attempts = toolJd.open(expected_project_file)

JMAG_exist = os.path.exists("C:/Program Files/JMAG-Designer%s" % self.config.jmag_version)
if JMAG_exist is True:
app, attempts = toolJd.open(expected_project_file, self.config.jmag_version)
else:
print('WARNING: The JMAG version does not exist, defaulting to newest JMAG version available!')
app, attempts = toolJd.open(expected_project_file)

if attempts > 1:
self.project_name = self.project_name + "attempts_%d" % (attempts)

Expand Down
1 change: 1 addition & 0 deletions mach_eval/analyzers/electromagnetic/bspm/jmag_2d_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ def __init__(self, **kwargs) -> None:
self.num_cpus = kwargs["num_cpus"] # number of cpus or cores used. Only value if multiple_cpus = True
self.jmag_scheduler = kwargs["jmag_scheduler"] # True if it is desired to schedule jobs instead of solving immediately
self.jmag_visible = kwargs["jmag_visible"] # JMAG application visible if true
self.jmag_version = kwargs["jmag_version"] # JMAG application version

0 comments on commit cd1e2cf

Please sign in to comment.