diff --git a/doc/changelog.d/6770.fixed.md b/doc/changelog.d/6770.fixed.md new file mode 100644 index 00000000000..c007c7f0d65 --- /dev/null +++ b/doc/changelog.d/6770.fixed.md @@ -0,0 +1 @@ +6744-Update analysis.py diff --git a/src/ansys/aedt/core/application/analysis.py b/src/ansys/aedt/core/application/analysis.py index c5a8146402f..709b3c56eb0 100644 --- a/src/ansys/aedt/core/application/analysis.py +++ b/src/ansys/aedt/core/application/analysis.py @@ -962,7 +962,7 @@ def export_results( self.logger.warning("Touchstone format not valid. ``MagPhase`` will be set as default") touchstone_format_value = 0 - nominal_variation = self.available_variations.get_independent_nominal_values() + nominal_variation = self.available_variations.nominal_variation(dependent_params=False) for s in self.setups: if self.design_type == "Circuit Design": @@ -1133,7 +1133,7 @@ def export_convergence(self, setup, variations="", output_file=None): if not output_file: output_file = os.path.join(self.working_directory, generate_unique_name("Convergence") + ".prop") if not variations: - nominal_variation = self.available_variations.get_independent_nominal_values() + nominal_variation = self.available_variations.nominal_variation(dependent_params=False) val_str = [] for el, val in nominal_variation.items(): val_str.append(f"{el}={val}") @@ -2327,7 +2327,7 @@ def _export_touchstone( file name when successful, ``False`` when failed. """ if variations is None: - variations = self.available_variations.get_independent_nominal_values() + variations = self.available_variations.nominal_variation() variations_keys = list(variations.keys()) if variations_value is None: variations_value = [str(x) for x in list(variations.values())] @@ -2384,7 +2384,7 @@ def _export_touchstone( if self.design_type == "HFSS": self.osolution.ExportNetworkData( - DesignVariations, + DesignVariations.strip(), SolutionSelectionArray, FileFormat, OutFile, @@ -2401,7 +2401,7 @@ def _export_touchstone( ) else: self.odesign.ExportNetworkData( - DesignVariations, + DesignVariations.strip(), SolutionSelectionArray, FileFormat, OutFile, @@ -2802,14 +2802,42 @@ def variations(self, setup_sweep: str, output_as_dict: bool = False) -> Union[Li def get_independent_nominal_values(self) -> Dict: """Retrieve variations for a given setup. + .. deprecated:: 0.22.0 + Use :func:`nominal_variation` method instead. + Returns ------- dict Dictionary of independent nominal variations with values. """ + return self.nominal_variation(dependent_params=False) + + @pyaedt_function_handler() + def nominal_variation(self, dependent_params=True, expressions=False) -> Dict: + """Retrieve variations for a given setup. + + Parameters + ---------- + dependent_params : bool, optional + Return dependent parameters. The default is ``True``. + expressions : bool, optional + Return dependent parameter values as their expression. The default is ``False`` + in which case the parameter value is returned. + + Returns + ------- + dict + Dictionary containing the nominal variation for the current design. + """ independent_flag = self.independent - self.independent = True - variations = self.nominal_values + self.independent = not dependent_params + + available_variables = self.__available_variables() + if expressions: + variations = {k: v.expression for k, v in list(available_variables.items())} + else: + variations = {k: v.evaluated_value for k, v in list(available_variables.items())} + self.independent = independent_flag return variations diff --git a/src/ansys/aedt/core/application/analysis_3d_layout.py b/src/ansys/aedt/core/application/analysis_3d_layout.py index 580014fec10..3a12224a387 100644 --- a/src/ansys/aedt/core/application/analysis_3d_layout.py +++ b/src/ansys/aedt/core/application/analysis_3d_layout.py @@ -254,7 +254,7 @@ def export_mesh_stats(self, setup, variations="", output_file=None): """ if not output_file: output_file = str(Path(self.working_directory) / "meshstats.ms") - self.odesign.ExportMeshStats(setup, variations, output_file) + self.odesign.ExportMeshStats(setup, variations, str(output_file)) return output_file @property diff --git a/src/ansys/aedt/core/application/design.py b/src/ansys/aedt/core/application/design.py index 26e01bea241..75a9fbec7ff 100644 --- a/src/ansys/aedt/core/application/design.py +++ b/src/ansys/aedt/core/application/design.py @@ -1602,7 +1602,7 @@ def export_profile(self, setup, variation="", output_file=None): output_file = Path(self.working_directory) / (generate_unique_name("Profile") + ".prof") if not variation: val_str = [] - nominal_variation = self.available_variations.get_independent_nominal_values() + nominal_variation = self.available_variations.nominal_variation() for el, val in nominal_variation.items(): val_str.append(f"{el}={val}") if self.design_type == "HFSS 3D Layout Design": diff --git a/src/ansys/aedt/core/hfss.py b/src/ansys/aedt/core/hfss.py index 3efae0596ff..b3484460831 100644 --- a/src/ansys/aedt/core/hfss.py +++ b/src/ansys/aedt/core/hfss.py @@ -2705,7 +2705,7 @@ def create_sbr_linked_antenna( if not setup: setup = assignment.nominal_adaptive params = {} - pars = assignment.available_variations.get_independent_nominal_values() + pars = assignment.available_variations.nominal_variation(dependent_params=False) for el in pars: params[el] = pars[el] @@ -6357,7 +6357,7 @@ def get_rcs_data( from ansys.aedt.core.visualization.post.rcs_exporter import MonostaticRCSExporter if not variations: - variations = self.available_variations.get_independent_nominal_values() + variations = self.available_variations.nominal_variation(dependent_params=False) if not setup: setup = self.nominal_adaptive diff --git a/src/ansys/aedt/core/icepak.py b/src/ansys/aedt/core/icepak.py index 99acab2f21e..21f673bcd6a 100644 --- a/src/ansys/aedt/core/icepak.py +++ b/src/ansys/aedt/core/icepak.py @@ -1795,7 +1795,7 @@ def assign_em_losses( intr = [] argparam = {} - nominal_variation = self.available_variations.get_independent_nominal_values() + nominal_variation = self.available_variations.nominal_variation(dependent_params=False) for key, value in nominal_variation.items(): argparam[key] = value diff --git a/src/ansys/aedt/core/mechanical.py b/src/ansys/aedt/core/mechanical.py index 4b543f3855c..de66d6bc762 100644 --- a/src/ansys/aedt/core/mechanical.py +++ b/src/ansys/aedt/core/mechanical.py @@ -251,7 +251,7 @@ def assign_em_losses( argparam = {} - variations = self.available_variations.get_independent_nominal_values() + variations = self.available_variations.nominal_variation(dependent_params=False) for key, value in variations.items(): argparam[key] = value @@ -346,7 +346,7 @@ def assign_thermal_map( all_objects = assignment[:] argparam = {} - variations = self.available_variations.get_independent_nominal_values() + variations = self.available_variations.nominal_variation(dependent_params=False) for key, value in variations.items(): argparam[key] = value diff --git a/src/ansys/aedt/core/modules/solve_setup.py b/src/ansys/aedt/core/modules/solve_setup.py index 712350733fe..25c3d39bd5a 100644 --- a/src/ansys/aedt/core/modules/solve_setup.py +++ b/src/ansys/aedt/core/modules/solve_setup.py @@ -980,7 +980,7 @@ def add_mesh_link( # parameters mesh_link["Params"] = {} - nominal_values = self._app.available_variations.get_independent_nominal_values() + nominal_values = self._app.available_variations.nominal_variation(dependent_params=False) if parameters is None: parameters = self._app.available_variations.nominal_w_values_dict @@ -1008,7 +1008,7 @@ def add_mesh_link( def _parse_link_parameters(self, map_variables_by_name, parameters): # parameters params = {} - nominal_values = self._app.available_variations.get_independent_nominal_values() + nominal_values = self._app.available_variations.nominal_variation(dependent_params=False) if map_variables_by_name: parameters = nominal_values parameters = self._app.available_variations.nominal_w_values_dict diff --git a/src/ansys/aedt/core/q3d.py b/src/ansys/aedt/core/q3d.py index 6986cb45b35..2906742e6b1 100644 --- a/src/ansys/aedt/core/q3d.py +++ b/src/ansys/aedt/core/q3d.py @@ -558,7 +558,7 @@ def export_matrix_data( return False if variations is None: - nominal_values = self.available_variations.get_independent_nominal_values() + nominal_values = self.available_variations.nominal_variation(dependent_params=False) if not nominal_values: variations = "" else: @@ -950,7 +950,7 @@ def export_equivalent_circuit( analysis_setup = setup + " : " + sweep.replace(" ", "") if variations is None: - nominal_values = self.available_variations.get_independent_nominal_values() + nominal_values = self.available_variations.nominal_variation(dependent_params=False) if not nominal_values: variations = "" diff --git a/src/ansys/aedt/core/visualization/post/common.py b/src/ansys/aedt/core/visualization/post/common.py index 55712e34a40..848e92ff59b 100644 --- a/src/ansys/aedt/core/visualization/post/common.py +++ b/src/ansys/aedt/core/visualization/post/common.py @@ -1019,7 +1019,7 @@ def _get_report_inputs( else: families_input[primary_sweep_variable] = [variations[primary_sweep_variable]] if not variations: - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) for el in list(variations.keys()): if el == primary_sweep_variable: continue @@ -1286,9 +1286,9 @@ def _get_report_object( if not variations: variations = {} if not variations and domain == "Sweep": - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) elif not variations and domain != "Sweep": - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) if setup_name in self._app.design_setups: for v in self._app.design_setups[setup_name].default_intrinsics.keys(): if v not in variations: diff --git a/src/ansys/aedt/core/visualization/post/post_common_3d.py b/src/ansys/aedt/core/visualization/post/post_common_3d.py index 3c3cece6979..42e037ba86b 100644 --- a/src/ansys/aedt/core/visualization/post/post_common_3d.py +++ b/src/ansys/aedt/core/visualization/post/post_common_3d.py @@ -506,7 +506,7 @@ def get_scalar_field_value( self.ofieldsreporter.CalcOp(scalar_function) if not variations: - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) variation = [] for el, value in variations.items(): @@ -684,7 +684,7 @@ def export_field_file_on_grid( return False if not variations: - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) variation = [] for el, value in variations.items(): @@ -851,7 +851,7 @@ def export_field_file( self.ofieldsreporter.CopyNamedExprToStack(quantity) if not variations: - variations = self._app.available_variations.get_independent_nominal_values() + variations = self._app.available_variations.nominal_variation(dependent_params=False) variation = [] for el, value in variations.items(): diff --git a/src/ansys/aedt/core/visualization/post/rcs_exporter.py b/src/ansys/aedt/core/visualization/post/rcs_exporter.py index a3ff1a175f6..07bca5255e0 100644 --- a/src/ansys/aedt/core/visualization/post/rcs_exporter.py +++ b/src/ansys/aedt/core/visualization/post/rcs_exporter.py @@ -94,7 +94,7 @@ def __init__( self.expression = "ComplexMonostaticRCSTheta" if not variations: - variations = app.available_variations.get_independent_nominal_values() + variations = app.available_variations.nominal_variation(dependent_params=False) else: # Set variation to Nominal for var_name, var_value in variations.items(): diff --git a/src/ansys/aedt/core/visualization/report/common.py b/src/ansys/aedt/core/visualization/report/common.py index 504e91862df..977fafcb84c 100644 --- a/src/ansys/aedt/core/visualization/report/common.py +++ b/src/ansys/aedt/core/visualization/report/common.py @@ -450,7 +450,7 @@ def __init__(self, app, report_category, setup_name, expressions=None): self._legacy_props["context"]["secondary_sweep_range"] = ["All"] self._legacy_props["context"]["variations"] = {"Freq": ["All"]} if hasattr(self._app, "available_variations") and self._app.available_variations: - nominal_variation = self._post._app.available_variations.get_independent_nominal_values() + nominal_variation = self._post._app.available_variations.nominal_variation(dependent_params=False) for el, k in nominal_variation.items(): self._legacy_props["context"]["variations"][el] = k self._legacy_props["expressions"] = None @@ -1359,7 +1359,7 @@ def _convert_dict_to_report_sel(self, sweeps): sweep_list.append(_units_assignment(k)) else: sweep_list.append([_units_assignment(k)]) - nominal_values = self._app.available_variations.get_independent_nominal_values() + nominal_values = self._app.available_variations.nominal_variation(dependent_params=False) for el in list(nominal_values.keys()): if el not in sweeps: sweep_list.append(f"{el}:=") diff --git a/tests/system/solvers/example_models/T00/Transient_StrandedWindings.aedtz b/tests/system/solvers/example_models/T00/Transient_StrandedWindings.aedtz index 4214b89a2d3..72982e4a4a1 100644 Binary files a/tests/system/solvers/example_models/T00/Transient_StrandedWindings.aedtz and b/tests/system/solvers/example_models/T00/Transient_StrandedWindings.aedtz differ diff --git a/tests/system/solvers/example_models/T00/h3dl_test_solved.aedtz b/tests/system/solvers/example_models/T00/h3dl_test_solved.aedtz index b4e026257ec..ab166a05880 100644 Binary files a/tests/system/solvers/example_models/T00/h3dl_test_solved.aedtz and b/tests/system/solvers/example_models/T00/h3dl_test_solved.aedtz differ diff --git a/tests/system/solvers/test_00_analyze.py b/tests/system/solvers/test_00_analyze.py index a1b308adeca..7337d950167 100644 --- a/tests/system/solvers/test_00_analyze.py +++ b/tests/system/solvers/test_00_analyze.py @@ -171,9 +171,13 @@ def test_3dl_analyze_setup(self, hfss3dl_solve): assert profile[key0].product == "HFSS3DLayout" assert profile[key0].max_memory() > MemoryGB(0.01) - def test_3dl_export_profile(self, hfss3dl_solved): - assert Path(hfss3dl_solved.export_profile("Setup1")).exists() - assert Path(hfss3dl_solved.export_mesh_stats("Setup1")).exists() + def test_3dl_export_profile(self, hfss3dl_solved, local_scratch): + profile_file = local_scratch.path / "temp.prof" + profile_file = Path(hfss3dl_solved.export_profile("Setup1", output_file=profile_file)) + assert profile_file.exists() + mesh_file = local_scratch.path / "temp.msh" + mesh_file = Path(hfss3dl_solved.export_mesh_stats("Setup1", output_file=mesh_file)) + assert mesh_file.exists() setup = hfss3dl_solved.setups[0] profiles = setup.get_profile() key0 = list(profiles.keys())[0] @@ -186,7 +190,9 @@ def test_3dl_export_profile(self, hfss3dl_solved): sweep_names = list(profile.frequency_sweeps.keys()) assert len(sweep_names) == 1 sweep_name = sweep_names[0] - assert len(profile.frequency_sweeps[sweep_name].frequencies) == 16 + assert ( + len(profile.frequency_sweeps[sweep_name].frequencies) > 0 + ) # This value depends on AEDT version used to solve. assert profile.frequency_sweeps[sweep_name].elapsed_time > timedelta(seconds=1) assert profile.num_adaptive_passes adaptive_passes = profile.num_adaptive_passes @@ -663,6 +669,16 @@ def test_export_to_maxwell(self, add_app, local_scratch): app2.import_configuration(config) assert app2.circuit + def test_variations(self, hfss3dl_solved, local_scratch): + var_w_expr = hfss3dl_solved.available_variations.nominal_variation(expressions=True) + assert var_w_expr["gnd_len"] == "len+gnd_buffer" + assert len(var_w_expr) == 4 + var_w_values = hfss3dl_solved.available_variations.nominal_variation() + assert len(var_w_values) == 4 + assert var_w_values["gnd_len"] == "23.0mm" + var_independent = hfss3dl_solved.available_variations.nominal_variation(dependent_params=False) + assert len(var_independent) == 3 + def test_output_variables_3dlayout(self, hfss3dl_solved): hfss3dl_solved.set_differential_pair( assignment="Port1", reference="Port2", differential_mode="Diff", common_mode="Comm" diff --git a/tests/system/visualization/test_12_1_PostProcessing.py b/tests/system/visualization/test_12_1_PostProcessing.py index 044c3b93e10..68c0fb85dae 100644 --- a/tests/system/visualization/test_12_1_PostProcessing.py +++ b/tests/system/visualization/test_12_1_PostProcessing.py @@ -308,7 +308,7 @@ def test_export_data_to_csv(self, aedtapp, local_scratch): for el2 in portnames: trace_names.append("S(" + el + "," + el2 + ")") families = {"Freq": ["All"]} - nominal_values = aedtapp.available_variations.get_independent_nominal_values() + nominal_values = aedtapp.available_variations.nominal_variation(dependent_params=False) for key, value in nominal_values.items(): families[key] = value my_data = aedtapp.post.get_solution_data(expressions=trace_names, variations=families) diff --git a/tests/system/visualization/test_12_PostProcessing.py b/tests/system/visualization/test_12_PostProcessing.py index 509d6ace505..74f0dcc6dc0 100644 --- a/tests/system/visualization/test_12_PostProcessing.py +++ b/tests/system/visualization/test_12_PostProcessing.py @@ -279,7 +279,7 @@ def test_circuit_available_report_solutions(self, diff_test): assert len(diff_test.post.available_report_solutions()) > 0 def test_circuit_create_report_2(self, diff_test): - variations = diff_test.available_variations.get_independent_nominal_values() + variations = diff_test.available_variations.nominal_variation(dependent_params=False) variations["Freq"] = ["All"] variations["l1"] = ["All"] assert diff_test.post.create_report( diff --git a/tests/system/visualization/test_PostProcessing_Field_Report.py b/tests/system/visualization/test_PostProcessing_Field_Report.py index 58048fb6b70..55fd14e69c3 100644 --- a/tests/system/visualization/test_PostProcessing_Field_Report.py +++ b/tests/system/visualization/test_PostProcessing_Field_Report.py @@ -37,7 +37,7 @@ def h3d_potter_horn(add_app): class TestClass: def test_create_report(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -61,7 +61,7 @@ def test_create_report(self, h3d_potter_horn): h3d_potter_horn.post.delete_report(nominal_report.plot_name) def test_create_report_sweep(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -81,7 +81,7 @@ def test_create_report_sweep(self, h3d_potter_horn): h3d_potter_horn.post.delete_report(sweep_report.plot_name) def test_create_report_from_configuration_sweep_report(self, h3d_potter_horn, local_scratch): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -116,7 +116,7 @@ def test_create_report_time(self, h3d_potter_horn): h3d_potter_horn.post.delete_report(report.plot_name) def test_reports_by_category_far_field(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -130,7 +130,7 @@ def test_reports_by_category_far_field(self, h3d_potter_horn): h3d_potter_horn.post.delete_report(new_report.plot_name) def test_reports_by_category_far_field_1(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -190,7 +190,7 @@ def test_create_report_from_configuration_template(self, h3d_potter_horn): h3d_potter_horn.post.delete_report(new_report4.plot_name) def test_data_plot(self, h3d_potter_horn, local_scratch): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -205,7 +205,7 @@ def test_data_plot(self, h3d_potter_horn, local_scratch): assert data.plot(snapshot_path=os.path.join(local_scratch.path, "reportC.jpg"), show=False) def test_data_plot_3d(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -220,7 +220,7 @@ def test_data_plot_3d(self, h3d_potter_horn): assert data.plot_3d(show=False) def test_create_3d_plot(self, h3d_potter_horn, local_scratch): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -239,7 +239,7 @@ def test_create_3d_plot(self, h3d_potter_horn, local_scratch): ) def test_get_solution_data(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -258,7 +258,7 @@ def test_get_solution_data(self, h3d_potter_horn): assert not np.any(data.get_expression_data("GainTotal2")[0]) def test_create_report_nominal_sweep(self, h3d_potter_horn): - variations = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) variations["Theta"] = ["All"] variations["Phi"] = ["All"] variations["Freq"] = ["30GHz"] @@ -270,7 +270,7 @@ def test_create_report_nominal_sweep(self, h3d_potter_horn): # Improve it for Maxwell def test_reports_by_category_fields(self, h3d_potter_horn): h3d_potter_horn.modeler.create_polyline([[0, 0, 0], [0, 5, 30]], name="Poly1", non_model=True) - variations2 = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations2 = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) assert h3d_potter_horn.setups[0].create_report( "Mag_E", primary_sweep_variable="Distance", report_category="Fields", context="Poly1" ) @@ -284,7 +284,7 @@ def test_reports_by_category_fields(self, h3d_potter_horn): assert new_report.create() def test_reports_by_category_modal_solution(self, h3d_potter_horn): - variations2 = h3d_potter_horn.available_variations.get_independent_nominal_values() + variations2 = h3d_potter_horn.available_variations.nominal_variation(dependent_params=False) new_report = h3d_potter_horn.post.reports_by_category.modal_solution("S(1,1)") new_report.report_type = "Smith Chart" assert new_report.create()