diff --git a/src/ansys/aedt/core/modules/solve_setup.py b/src/ansys/aedt/core/modules/solve_setup.py index 75a5073d85e..efcd68cd16f 100644 --- a/src/ansys/aedt/core/modules/solve_setup.py +++ b/src/ansys/aedt/core/modules/solve_setup.py @@ -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.") @@ -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.") diff --git a/tests/system/general/example_models/T12/coax_setup_solved_231.aedtz b/tests/system/general/example_models/T12/coax_setup_solved_231.aedtz index ebc0f6ab755..2965c23f5eb 100644 Binary files a/tests/system/general/example_models/T12/coax_setup_solved_231.aedtz and b/tests/system/general/example_models/T12/coax_setup_solved_231.aedtz differ diff --git a/tests/system/general/test_12_1_PostProcessing.py b/tests/system/general/test_12_1_PostProcessing.py index 59374d48539..642f5302bfb 100644 --- a/tests/system/general/test_12_1_PostProcessing.py +++ b/tests/system/general/test_12_1_PostProcessing.py @@ -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"] @@ -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})