Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Apply value to derivative variable #5499

Merged
merged 8 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions src/ansys/aedt/core/modules/solve_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2480,27 +2480,51 @@
def set_tuning_offset(self, offsets):
"""Set derivative variable to a specific offset value.

This method adjusts the tuning ranges for derivative variables in the design, allowing for specific offset
values to be applied. If a variable is not specified in the ``offsets`` dictionary,
its offset is set to ``0`` by default. Each value must be within ±10% of the nominal
value of the corresponding variable.

Parameters
----------
offsets : dict
Dictionary containing the variable name and it's offset value.
Dictionary where keys are variable names and values are the corresponding offset values to be applied.

Returns
-------
bool
``True`` when successful, ``False`` when failed.

References
----------
>>> oDesign.SetTuningRanges

Examples
--------
>>> from ansys.aed.core import Hfss
>>> hfss = Hfss()
>>> hfss["der_var"] = "1mm"
>>> setup = hfss.create_setup(setup_type=1)
>>> setup.add_derivatives("der_var")
>>> hfss.analyze()
>>> setup.set_tuning_offset({"der_var": 0.05})
"""
variables = self.get_derivative_variables()
for v in variables:
if v not in offsets:
offsets[v] = 0
arg = []
arg = ["NAME:TuningRanges"]

Check warning on line 2516 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#L2516

Added line #L2516 was not covered by tests
for k, v in offsets.items():
arg.append(f"DeltaOffset({k})")
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * (-0.1)}")
arg.append(f"{v}")
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * 0.1}")
arg.append("Range:=")
arg2 = [

Check warning on line 2519 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#L2518-L2519

Added lines #L2518 - L2519 were not covered by tests
f"DeltaOffset({k})",
abs(self._app.variable_manager[k].numeric_value) * (-0.1),
v,
abs(self._app.variable_manager[k].numeric_value) * 0.1,
]
arg.append(arg2)

Check warning on line 2525 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#L2525

Added line #L2525 was not covered by tests
if self.is_solved:
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
self._app.odesign.SetTuningRanges(arg)

Check warning on line 2527 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#L2527

Added line #L2527 was not covered by tests
return True
else:
self._app.logger.error(f"Setup {self.name} is not solved. Solve it before tuning variables.")
Expand Down Expand Up @@ -3197,27 +3221,51 @@
def set_tuning_offset(self, offsets):
"""Set derivative variable to a specific offset value.

This method adjusts the tuning ranges for derivative variables in the design, allowing for specific offset
values to be applied. If a variable is not specified in the ``offsets`` dictionary,
its offset is set to ``0`` by default. Each value must be within ±10% of the nominal
value of the corresponding variable.

Parameters
----------
offsets : dict
Dictionary containing the variable name and it's offset value.
Dictionary where keys are variable names and values are the corresponding offset values to be applied.

Returns
-------
bool
``True`` when successful, ``False`` when failed.

References
----------
>>> oDesign.SetTuningRanges

Examples
--------
>>> from ansys.aed.core import Hfss
>>> hfss = Hfss()
>>> hfss["der_var"] = "1mm"
>>> setup = hfss.create_setup(setup_type=0)
>>> setup.add_derivatives("der_var")
>>> hfss.analyze()
>>> setup.set_tuning_offset({"der_var": 0.05})
"""
variables = self.get_derivative_variables()
for v in variables:
if v not in offsets:
offsets[v] = 0
arg = []
arg = ["NAME:TuningRanges"]

Check warning on line 3257 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#L3257

Added line #L3257 was not covered by tests
for k, v in offsets.items():
arg.append(f"DeltaOffset({k})")
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * (-0.1)}")
arg.append(f"{v}")
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * 0.1}")
arg.append("Range:=")
arg2 = [

Check warning on line 3260 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#L3259-L3260

Added lines #L3259 - L3260 were not covered by tests
f"DeltaOffset({k})",
abs(self._app.variable_manager[k].numeric_value) * (-0.1),
v,
abs(self._app.variable_manager[k].numeric_value) * 0.1,
]
arg.append(arg2)

Check warning on line 3266 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#L3266

Added line #L3266 was not covered by tests
if self.is_solved:
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
self._app.odesign.SetTuningRanges(arg)

Check warning on line 3268 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#L3268

Added line #L3268 was not covered by tests
return True
else:
self._app.logger.error(f"Setup {self.name} is not solved. Solve it before tuning variables.")
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/system/general/test_12_1_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,9 @@ def test_74_dynamic_update(self):
val = self.aedtapp.post.update_report_dynamically
self.aedtapp.post.update_report_dynamically = not val
assert self.aedtapp.post.update_report_dynamically != val

def test_75_tune_derivative(self):
setup_derivative = self.aedtapp.setups[1]
setup_derivative_auto = self.aedtapp.setups[2]
assert setup_derivative.set_tuning_offset({"inner_radius": 0.1})
assert setup_derivative_auto.set_tuning_offset({"inner_radius": 0.1})
Loading