Skip to content

Commit

Permalink
Merge branch 'main' into release/0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Nov 29, 2024
2 parents 161dbae + 34f3198 commit cd03934
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
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 add_derivatives(self, derivative_list):
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"]
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 = [
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)
if self.is_solved:
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
self._app.odesign.SetTuningRanges(arg)
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 add_derivatives(self, derivative_list):
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"]
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 = [
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)
if self.is_solved:
self._app.osolution.SetTuningOffsets(["TuningRanges:=", arg])
self._app.odesign.SetTuningRanges(arg)
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.
7 changes: 6 additions & 1 deletion tests/system/general/test_12_1_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def test_01B_Field_Plot(self):
assert len(self.aedtapp.post.available_display_types()) > 0
assert len(self.aedtapp.post.available_report_types) > 0
assert len(self.aedtapp.post.available_report_quantities()) > 0
assert isinstance(self.aedtapp.post.get_all_report_quantities(), dict)
assert isinstance(self.aedtapp.post.get_all_report_quantities(solution="Setup1 : LastAdaptive"), dict)
assert len(self.aedtapp.post.available_report_solutions()) > 0
cutlist = ["Global:XY", "Global:XZ", "Global:YZ"]
Expand Down Expand Up @@ -819,3 +818,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})

0 comments on commit cd03934

Please sign in to comment.