Skip to content

Commit

Permalink
improve method
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalinve committed Nov 28, 2024
1 parent 29b7f96 commit fae9d3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
45 changes: 26 additions & 19 deletions src/ansys/aedt/core/modules/solve_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3498,22 +3498,29 @@ class SetupMaxwell(Setup, object):
def __init__(self, app, solution_type, name="MySetupAuto", is_new_setup=True):
Setup.__init__(self, app, solution_type, name, is_new_setup)

@pyaedt_function_handler()
@pyaedt_function_handler(range_type="sweep_type", start="start_frequency", end="stop_frequency", count="step_size")
def add_eddy_current_sweep(
self, range_type="LinearStep", start=0.1, end=100, count=0.1, units="Hz", clear=True, save_all_fields=True
self,
sweep_type="LinearStep",
start_frequency=0.1,
stop_frequency=100,
step_size=0.1,
units="Hz",
clear=True,
save_all_fields=True,
):
"""Create a Maxwell Eddy Current Sweep.
Parameters
----------
range_type : str
sweep_type : str
Type of the subrange. Options are ``"LinearCount"``,
``"LinearStep"``, ``"LogScale"`` and ``"SinglePoints"``.
start : float
start_frequency : float
Starting frequency.
end : float, optional
stop_frequency : float, optional
Stopping frequency. Required for ``range_type="LinearCount"|"LinearStep"|"LogScale"``.
count : int or float, optional
step_size : int or float, optional
Frequency count or frequency step. Required for ``range_type="LinearCount"|"LinearStep"|"LogScale"``.
units : str, optional
Unit of the frequency. For example, ``"MHz`` or ``"GHz"``. The default is ``"Hz"``.
Expand All @@ -3524,7 +3531,6 @@ def add_eddy_current_sweep(
Save fields at all frequency points to save fields for the entire set of sweep ranges.
Default is ``True``.
Returns
-------
bool
Expand All @@ -3536,19 +3542,20 @@ def add_eddy_current_sweep(
return False
legacy_update = self.auto_update
self.auto_update = False
sweep_props = {"RangeType": range_type, "RangeStart": f"{start}{units}"}
sweep_props = {
"RangeType": sweep_type,
"RangeStart": f"{start_frequency}{units}",
"RangeEnd": f"{stop_frequency}{units}",
}
self.props["HasSweepSetup"] = True
if range_type == "LinearStep":
sweep_props["RangeEnd"] = f"{end}{units}"
sweep_props["RangeStep"] = f"{count}{units}"
elif range_type == "LinearCount":
sweep_props["RangeEnd"] = f"{end}{units}"
sweep_props["RangeCount"] = count
elif range_type == "LogScale":
sweep_props["RangeEnd"] = f"{end}{units}"
sweep_props["RangeSamples"] = count
elif range_type == "SinglePoints":
sweep_props["RangeEnd"] = f"{start}{units}"
if sweep_type == "LinearStep":
sweep_props["RangeStep"] = f"{step_size}{units}"
elif sweep_type == "LinearCount":
sweep_props["RangeCount"] = step_size
elif sweep_type == "LogScale":
sweep_props["RangeSamples"] = step_size

Check warning on line 3556 in src/ansys/aedt/core/modules/solve_setup.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modules/solve_setup.py#L3556

Added line #L3556 was not covered by tests
elif sweep_type == "SinglePoints":
sweep_props["RangeEnd"] = f"{start_frequency}{units}"
if clear:
self.props["SweepRanges"]["Subrange"] = sweep_props
elif isinstance(self.props["SweepRanges"]["Subrange"], list):
Expand Down
2 changes: 1 addition & 1 deletion tests/system/general/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_07a_setup(self):
assert setup.props["SaveAllFields"]
assert setup.add_eddy_current_sweep("LinearCount", dc_freq, stop_freq, count, clear=False)
assert isinstance(setup.props["SweepRanges"]["Subrange"], list)
assert setup.add_eddy_current_sweep("SinglePoints", start=0.01, clear=False)
assert setup.add_eddy_current_sweep("SinglePoints", start_frequency=0.01, clear=False)
assert setup.update()
assert setup.enable_expression_cache(["CoreLoss"], "Fields", "Phase='0deg' ", True)
assert setup.props["UseCacheFor"] == ["Pass", "Freq"]
Expand Down

0 comments on commit fae9d3b

Please sign in to comment.