Skip to content

Commit cd03934

Browse files
Merge branch 'main' into release/0.11
2 parents 161dbae + 34f3198 commit cd03934

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed

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

+62-14
Original file line numberDiff line numberDiff line change
@@ -2480,27 +2480,51 @@ def add_derivatives(self, derivative_list):
24802480
def set_tuning_offset(self, offsets):
24812481
"""Set derivative variable to a specific offset value.
24822482
2483+
This method adjusts the tuning ranges for derivative variables in the design, allowing for specific offset
2484+
values to be applied. If a variable is not specified in the ``offsets`` dictionary,
2485+
its offset is set to ``0`` by default. Each value must be within ±10% of the nominal
2486+
value of the corresponding variable.
2487+
24832488
Parameters
24842489
----------
24852490
offsets : dict
2486-
Dictionary containing the variable name and it's offset value.
2491+
Dictionary where keys are variable names and values are the corresponding offset values to be applied.
24872492
24882493
Returns
24892494
-------
24902495
bool
2496+
``True`` when successful, ``False`` when failed.
2497+
2498+
References
2499+
----------
2500+
>>> oDesign.SetTuningRanges
2501+
2502+
Examples
2503+
--------
2504+
>>> from ansys.aed.core import Hfss
2505+
>>> hfss = Hfss()
2506+
>>> hfss["der_var"] = "1mm"
2507+
>>> setup = hfss.create_setup(setup_type=1)
2508+
>>> setup.add_derivatives("der_var")
2509+
>>> hfss.analyze()
2510+
>>> setup.set_tuning_offset({"der_var": 0.05})
24912511
"""
24922512
variables = self.get_derivative_variables()
24932513
for v in variables:
24942514
if v not in offsets:
24952515
offsets[v] = 0
2496-
arg = []
2516+
arg = ["NAME:TuningRanges"]
24972517
for k, v in offsets.items():
2498-
arg.append(f"DeltaOffset({k})")
2499-
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * (-0.1)}")
2500-
arg.append(f"{v}")
2501-
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * 0.1}")
2518+
arg.append("Range:=")
2519+
arg2 = [
2520+
f"DeltaOffset({k})",
2521+
abs(self._app.variable_manager[k].numeric_value) * (-0.1),
2522+
v,
2523+
abs(self._app.variable_manager[k].numeric_value) * 0.1,
2524+
]
2525+
arg.append(arg2)
25022526
if self.is_solved:
2503-
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
2527+
self._app.odesign.SetTuningRanges(arg)
25042528
return True
25052529
else:
25062530
self._app.logger.error(f"Setup {self.name} is not solved. Solve it before tuning variables.")
@@ -3197,27 +3221,51 @@ def add_derivatives(self, derivative_list):
31973221
def set_tuning_offset(self, offsets):
31983222
"""Set derivative variable to a specific offset value.
31993223
3224+
This method adjusts the tuning ranges for derivative variables in the design, allowing for specific offset
3225+
values to be applied. If a variable is not specified in the ``offsets`` dictionary,
3226+
its offset is set to ``0`` by default. Each value must be within ±10% of the nominal
3227+
value of the corresponding variable.
3228+
32003229
Parameters
32013230
----------
32023231
offsets : dict
3203-
Dictionary containing the variable name and it's offset value.
3232+
Dictionary where keys are variable names and values are the corresponding offset values to be applied.
32043233
32053234
Returns
32063235
-------
32073236
bool
3237+
``True`` when successful, ``False`` when failed.
3238+
3239+
References
3240+
----------
3241+
>>> oDesign.SetTuningRanges
3242+
3243+
Examples
3244+
--------
3245+
>>> from ansys.aed.core import Hfss
3246+
>>> hfss = Hfss()
3247+
>>> hfss["der_var"] = "1mm"
3248+
>>> setup = hfss.create_setup(setup_type=0)
3249+
>>> setup.add_derivatives("der_var")
3250+
>>> hfss.analyze()
3251+
>>> setup.set_tuning_offset({"der_var": 0.05})
32083252
"""
32093253
variables = self.get_derivative_variables()
32103254
for v in variables:
32113255
if v not in offsets:
32123256
offsets[v] = 0
3213-
arg = []
3257+
arg = ["NAME:TuningRanges"]
32143258
for k, v in offsets.items():
3215-
arg.append(f"DeltaOffset({k})")
3216-
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * (-0.1)}")
3217-
arg.append(f"{v}")
3218-
arg.append(f"{abs(self._app.variable_manager[k].numeric_value) * 0.1}")
3259+
arg.append("Range:=")
3260+
arg2 = [
3261+
f"DeltaOffset({k})",
3262+
abs(self._app.variable_manager[k].numeric_value) * (-0.1),
3263+
v,
3264+
abs(self._app.variable_manager[k].numeric_value) * 0.1,
3265+
]
3266+
arg.append(arg2)
32193267
if self.is_solved:
3220-
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
3268+
self._app.odesign.SetTuningRanges(arg)
32213269
return True
32223270
else:
32233271
self._app.logger.error(f"Setup {self.name} is not solved. Solve it before tuning variables.")
Binary file not shown.

tests/system/general/test_12_1_PostProcessing.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def test_01B_Field_Plot(self):
9090
assert len(self.aedtapp.post.available_display_types()) > 0
9191
assert len(self.aedtapp.post.available_report_types) > 0
9292
assert len(self.aedtapp.post.available_report_quantities()) > 0
93-
assert isinstance(self.aedtapp.post.get_all_report_quantities(), dict)
9493
assert isinstance(self.aedtapp.post.get_all_report_quantities(solution="Setup1 : LastAdaptive"), dict)
9594
assert len(self.aedtapp.post.available_report_solutions()) > 0
9695
cutlist = ["Global:XY", "Global:XZ", "Global:YZ"]
@@ -819,3 +818,9 @@ def test_74_dynamic_update(self):
819818
val = self.aedtapp.post.update_report_dynamically
820819
self.aedtapp.post.update_report_dynamically = not val
821820
assert self.aedtapp.post.update_report_dynamically != val
821+
822+
def test_75_tune_derivative(self):
823+
setup_derivative = self.aedtapp.setups[1]
824+
setup_derivative_auto = self.aedtapp.setups[2]
825+
assert setup_derivative.set_tuning_offset({"inner_radius": 0.1})
826+
assert setup_derivative_auto.set_tuning_offset({"inner_radius": 0.1})

0 commit comments

Comments
 (0)