diff --git a/_unittest/test_02_3D_modeler.py b/_unittest/test_02_3D_modeler.py index 59a3c21647b..ebdea85e869 100644 --- a/_unittest/test_02_3D_modeler.py +++ b/_unittest/test_02_3D_modeler.py @@ -284,6 +284,11 @@ def test_35_activate_variable_for_tuning(self): assert self.aedtapp.activate_variable_tuning("test_opti") assert self.aedtapp.activate_variable_tuning("$test_opti1", "1mm", "10mm") assert self.aedtapp.deactivate_variable_tuning("test_opti") + try: + self.aedtapp.activate_variable_tuning("Idontexist") + assert False + except: + assert True def test_36_activate_variable_for_optimization(self): assert self.aedtapp.activate_variable_optimization("test_opti") @@ -319,7 +324,7 @@ def test_40_create_coordinate_system(self): cs.change_cs_mode(3) assert False except ValueError: - pass + assert True assert cs.change_cs_mode(0) assert cs.delete() diff --git a/_unittest/test_20_HFSS.py b/_unittest/test_20_HFSS.py index b7e5f95254d..2d7b028260a 100644 --- a/_unittest/test_20_HFSS.py +++ b/_unittest/test_20_HFSS.py @@ -575,12 +575,14 @@ def test_24_create_curvilinear(self): assert mesh.delete() pass - def test_25_create_parametrics(self): + def test_25a_create_parametrics(self): self.aedtapp["w1"] = "10mm" self.aedtapp["w2"] = "2mm" setup1 = self.aedtapp.parametrics.add("w1", 0.1, 20, 0.2, "LinearStep") assert setup1 assert setup1.add_variation("w2", "0.1mm", 10, 11) + assert setup1.add_variation("w2", start_point="0.2mm", variation_type="SingleValue") + assert setup1.add_variation("w1", start_point="0.3mm", end_point=5, step=0.2, variation_type="LinearStep") assert setup1.add_calculation( calculation="dB(S(1,1))", ranges={"Freq": "5GHz"}, solution="MySetupForSweep : LastAdaptive" ) @@ -599,6 +601,18 @@ def test_25_create_parametrics(self): assert oo assert self.aedtapp.parametrics.delete("ParametricsfromFile") + def test_25b_create_parametrics_sync(self): + self.aedtapp["a1"] = "10mm" + self.aedtapp["a2"] = "2mm" + setup1 = self.aedtapp.parametrics.add( + "a1", start_point=0.1, end_point=20, step=10, variation_type="LinearCount" + ) + assert setup1 + assert setup1.add_variation("a2", start_point="0.3mm", end_point=5, step=10, variation_type="LinearCount") + assert setup1.sync_variables(["a1", "a2"], sync_n=1) + assert setup1.sync_variables(["a1", "a2"], sync_n=0) + setup1.add_variation("a1", start_point="13mm", variation_type="SingleValue") + def test_26_create_optimization(self): calculation = "db(S(Cir1,Cir1))" setup2 = self.aedtapp.optimizations.add(calculation, ranges={"Freq": "2.5GHz"}) diff --git a/_unittest/test_21_Circuit.py b/_unittest/test_21_Circuit.py index f00b7bbfe01..6b3f625357b 100644 --- a/_unittest/test_21_Circuit.py +++ b/_unittest/test_21_Circuit.py @@ -408,3 +408,18 @@ def test_33_pop_up(self): assert self.aedtapp.pop_up() active_project_name_2 = self.aedtapp.oproject.GetActiveDesign().GetName() assert active_project_name_1 == active_project_name_2 + + def test_34_activate_variables(self): + self.aedtapp["desvar"] = "1mm" + self.aedtapp["$prjvar"] = "2mm" + assert self.aedtapp["desvar"] == "1.0mm" + assert self.aedtapp["$prjvar"] == "2.0mm" + assert self.aedtapp.activate_variable_tuning("desvar") + assert self.aedtapp.activate_variable_tuning("$prjvar") + assert self.aedtapp.deactivate_variable_tuning("desvar") + assert self.aedtapp.deactivate_variable_tuning("$prjvar") + try: + self.aedtapp.activate_variable_tuning("Idontexist") + assert False + except: + assert True diff --git a/examples/03-Circuit/Circuit_Subcircuit_Example.py b/examples/03-Circuit/Circuit_Subcircuit_Example.py index 9e0f7227eaf..9380b33dff3 100644 --- a/examples/03-Circuit/Circuit_Subcircuit_Example.py +++ b/examples/03-Circuit/Circuit_Subcircuit_Example.py @@ -40,9 +40,9 @@ # They are then connected in series. # The ``pop_up`` method provides for getting back to the parent design. -circuit.variable_manager.set_variable("R_val", "35ohm", circuit_parameter=True) -circuit.variable_manager.set_variable("L_val", "1e-7H", circuit_parameter=True) -circuit.variable_manager.set_variable("C_val", "5e-10F", circuit_parameter=True) +circuit.variable_manager.set_variable("R_val", "35ohm") +circuit.variable_manager.set_variable("L_val", "1e-7H") +circuit.variable_manager.set_variable("C_val", "5e-10F") p1 = circuit.modeler.schematic.create_interface_port("In") r1 = circuit.modeler.schematic.create_resistor(value="R_val") l1 = circuit.modeler.schematic.create_inductor(value="L_val") diff --git a/examples/03-Circuit/Circuit_Transient.py b/examples/03-Circuit/Circuit_Transient.py index eebd3d0d280..fd9f07d2e6d 100644 --- a/examples/03-Circuit/Circuit_Transient.py +++ b/examples/03-Circuit/Circuit_Transient.py @@ -30,7 +30,7 @@ # ~~~~~~~~~ # This method allow user to read an ibis file and place a buffer into the schematic. -ibis = cir.get_ibis_model_from_file(os.path.join(cir.desktop_install_dir, 'buflib' ,'IBIS', 'u26a_800.ibs')) +ibis = cir.get_ibis_model_from_file(os.path.join(cir.desktop_install_dir, 'buflib', 'IBIS', 'u26a_800.ibs')) ibs = ibis.buffers["DQ_u26a_800"].insert(0, 0) ############################################################################### @@ -133,10 +133,10 @@ i += 2 * unit_interval t_steps.append(i) -t = [[i for i in solutions.intrinsics["Time"] if k - 2 * unit_interval < i <= k ] for k in +t = [[i for i in solutions.intrinsics["Time"] if k - 2 * unit_interval < i <= k] for k in t_steps] ys = [[i / 1000 for i, j in zip(solutions.data_real(), solutions.intrinsics["Time"]) if - k - 2 * unit_interval < j <= k ] for k in t_steps] + k - 2 * unit_interval < j <= k] for k in t_steps] fig, ax = plt.subplots(sharex=True) cellst = np.array([]) cellsv = np.array([]) diff --git a/pyaedt/application/Analysis.py b/pyaedt/application/Analysis.py index 57d46339e17..350d66a27e9 100644 --- a/pyaedt/application/Analysis.py +++ b/pyaedt/application/Analysis.py @@ -989,10 +989,7 @@ def nominal_w_values(self): >>> oDesign.GetNominalVariation""" families = [] if self._app.design_type == "HFSS 3D Layout Design": - if self._app._is_object_oriented_enabled(): - listvar = list(self._app._odesign.GetChildObject("Variables").GetChildNames()) - else: - listvar = list(self._app._odesign.GetVariables()) + listvar = self._app.variable_manager._get_var_list_from_aedt(self._app._odesign) for el in listvar: families.append(el + ":=") families.append([self._app._odesign.GetVariableValue(el)]) @@ -1016,10 +1013,7 @@ def nominal_w_values_dict(self): >>> oDesign.GetNominalVariation""" families = {} if self._app.design_type in ["HFSS 3D Layout Design", "Circuit Design", "Twin Builder"]: - if self._app._is_object_oriented_enabled(): - listvar = list(self._app._odesign.GetChildObject("Variables").GetChildNames()) - else: - listvar = list(self._app._odesign.GetVariables()) + listvar = self._app.variable_manager._get_var_list_from_aedt(self._app._odesign) for el in listvar: families[el] = self._app._odesign.GetVariableValue(el) else: @@ -1825,3 +1819,29 @@ def _export_touchstone( ) self.logger.info("Touchstone correctly exported to %s", filename) return True + + @pyaedt_function_handler() + def value_with_units(self, value, units=None): + """Combine a number and a string containing the unit in a single string e.g. "1.2mm". + If the units are not specified, the model units are used. + If value is a string (like containing an expression), it is returned as is. + + Parameters + ---------- + value : float, int, str + Value of the number or string containing an expression. + units : str, optional + Units to combine with value. + + Returns + ------- + str + String that combines the value and the units (e.g. "1.2mm"). + """ + if isinstance(value, str): + val = value + else: + if units is None: + units = self.modeler.model_units + val = "{0}{1}".format(value, units) + return val diff --git a/pyaedt/application/Design.py b/pyaedt/application/Design.py index 6c17d2d1755..0afa39abf39 100644 --- a/pyaedt/application/Design.py +++ b/pyaedt/application/Design.py @@ -1646,16 +1646,21 @@ def _optimetrics_variable_args( ------- """ + if variable_name not in self.variable_manager.variables: + self.logger.error("Variable {} does not exists.".format(variable_name)) + return False if variable_name.startswith("$"): tab = "NAME:ProjectVariableTab" propserver = "ProjectVariables" else: tab = "NAME:LocalVariableTab" - if self.design_type in ["HFSS 3D Layout Design", "Circuit Design"]: + propserver = "LocalVariables" + if self.design_type == "HFSS 3D Layout Design": if variable_name in self.odesign.GetProperties("DefinitionParameterTab", "LocalVariables"): tab = "NAME:DefinitionParameterTab" - - propserver = "LocalVariables" + elif self.design_type == "Circuit Design": + tab = "NAME:DefinitionParameterTab" + propserver = "Instance:{}".format(self._odesign.GetName()) arg2 = ["NAME:" + optimetrics_type, "Included:=", enable] if min_val: arg2.append("Min:=") diff --git a/pyaedt/application/Variables.py b/pyaedt/application/Variables.py index af75c38533a..02d770cc58a 100644 --- a/pyaedt/application/Variables.py +++ b/pyaedt/application/Variables.py @@ -676,16 +676,13 @@ def _variable_dict(self, object_list, dependent=True, independent=True): var_dict = {} all_names = {} for obj in object_list: - if self._app._is_object_oriented_enabled() and self._app.design_type != "Maxwell Circuit": - listvar = list(obj.GetChildObject("Variables").GetChildNames()) - else: - listvar = list(obj.GetVariables()) + listvar = self._get_var_list_from_aedt(obj) for variable_name in listvar: variable_expression = self.get_expression(variable_name) all_names[variable_name] = variable_expression try: value = Variable(variable_expression) - if is_array(value.value): + if is_array(value.value) and dependent: var_dict[variable_name] = value elif independent and is_number(value.value): var_dict[variable_name] = value @@ -811,13 +808,21 @@ def set_variable( description = "" desktop_object = self.aedt_object(variable_name) - test = desktop_object.GetName() - proj_name = self._oproject.GetName() - var_type = "Project" if "$" in variable_name[0] else "Local" - if circuit_parameter and self._app.design_type in ["HFSS 3D Layout Design", "Circuit Design"]: - tab_name = "DefinitionParameterTab" + if variable_name.startswith("$"): + tab_name = "ProjectVariableTab" + prop_server = "ProjectVariables" else: - tab_name = "{0}VariableTab".format(var_type) + tab_name = "LocalVariableTab" + prop_server = "LocalVariables" + if circuit_parameter and self._app.design_type in [ + "HFSS 3D Layout Design", + "Circuit Design", + "Maxwell Circuit", + "Twin Builder", + ]: + tab_name = "DefinitionParameterTab" + if self._app.design_type in ["HFSS 3D Layout Design", "Circuit Design", "Maxwell Circuit", "Twin Builder"]: + prop_server = "Instance:{}".format(desktop_object.GetName()) prop_type = "VariableProp" if postprocessing or "post" in variable_name.lower()[0:5]: @@ -848,20 +853,8 @@ def set_variable( raise Exception("Unhandled input type to the design property or project variable.") # pragma: no cover # Get all design and project variables in lower case for a case-sensitive comparison - if self._app._is_object_oriented_enabled() and self._app.design_type != "Maxwell Circuit": - var_list = list(desktop_object.GetChildObject("Variables").GetChildNames()) - else: - var_list = list(desktop_object.GetVariables()) # pragma: no cover + var_list = self._get_var_list_from_aedt(desktop_object) lower_case_vars = [var_name.lower() for var_name in var_list] - if ( - self._app.design_type in ["HFSS 3D Layout Design", "Circuit Design", "Maxwell Circuit"] - and "$" not in variable_name - ): - prop_server = "Instance:{}".format(desktop_object.GetName()) - elif self._app.design_type == "Circuit Design" and circuit_parameter: - prop_server = "DefinitionParameters" - else: - prop_server = "{0}Variables".format(var_type) if variable_name.lower() not in lower_case_vars: try: @@ -942,10 +935,7 @@ def set_variable( ], ] ) - if self._app._is_object_oriented_enabled() and self._app.design_type != "Maxwell Circuit": - var_list = list(desktop_object.GetChildObject("Variables").GetChildNames()) - else: - var_list = list(desktop_object.GetVariables()) # pragma: no cover + var_list = self._get_var_list_from_aedt(desktop_object) lower_case_vars = [var_name.lower() for var_name in var_list] if variable_name not in lower_case_vars: return False @@ -1015,12 +1005,8 @@ def delete_variable(self, var_name): """ desktop_object = self.aedt_object(var_name) var_type = "Project" if desktop_object == self._oproject else "Local" - if self._app._is_object_oriented_enabled() and self._app.design_type != "Maxwell Circuit": - var_list = list(desktop_object.GetChildObject("Variables").GetChildNames()) - else: - var_list = list(desktop_object.GetVariables()) # pragma: no cover + var_list = self._get_var_list_from_aedt(desktop_object) lower_case_vars = [var_name.lower() for var_name in var_list] - if var_name.lower() in lower_case_vars: try: desktop_object.ChangeProperty( @@ -1038,6 +1024,15 @@ def delete_variable(self, var_name): pass return False + @pyaedt_function_handler() + def _get_var_list_from_aedt(self, desktop_object): + var_list = [] + if self._app._is_object_oriented_enabled() and self._app.design_type != "Maxwell Circuit": + var_list += list(desktop_object.GetChildObject("Variables").GetChildNames()) + tmp = [i for i in list(desktop_object.GetVariables()) if i not in var_list] + var_list += tmp + return var_list + class Variable(object): """Stores design properties and project variables and provides operations to perform on them. diff --git a/pyaedt/icepak.py b/pyaedt/icepak.py index 21ecf0438c5..e03148b29cf 100644 --- a/pyaedt/icepak.py +++ b/pyaedt/icepak.py @@ -1459,7 +1459,7 @@ def assign_em_losses( Name of the EM setup. The default is ``"Setup1"``. sweepname : str, optional Name of the EM sweep to use for the mapping. The default is ``"LastAdaptive"``. - map_frequency : optional + map_frequency : str, optional String containing the frequency to map. The default is ``None``. The value must be ``None`` for Eigenmode analysis. surface_objects : list, optional @@ -1467,8 +1467,13 @@ def assign_em_losses( source_project_name : str, optional Name of the source project. The default is ``None``, in which case the source from the same project is used. - paramlist :list, optional - List of all parameters in the EM to map. The default is ``None``. + paramlist : list, dict, optional + List of all parameters to map from source and icepak design. The default is ``None``. + If ``None`` the variables will be set to their values (no mapping). + If it is a list, the specified variables in the icepak design will be mapped to variables + in the source design having the same name. + If it is a dictionary, it is possible to map variables to the source design having a different name. + The dict structure is {"source_design_variable": "icepak_variable"}. object_list : list, optional List of objects. The default is ``None``. @@ -1484,8 +1489,6 @@ def assign_em_losses( """ if surface_objects == None: surface_objects = [] - if paramlist == None: - paramlist = [] if object_list == None: object_list = [] @@ -1515,8 +1518,12 @@ def assign_em_losses( for el in self.available_variations.nominal_w_values_dict: argparam[el] = self.available_variations.nominal_w_values_dict[el] - for el in paramlist: - argparam[el] = el + if paramlist and isinstance(paramlist, list): + for el in paramlist: + argparam[el] = el + elif paramlist and isinstance(paramlist, dict): + for el in paramlist: + argparam[el] = paramlist[el] props = OrderedDict( { @@ -2674,7 +2681,7 @@ def apply_icepak_settings( Parameters ---------- - ambienttemp : float, optional + ambienttemp : float, str, optional Ambient temperature, which can be an integer or a parameter already created in AEDT. The default is ``20``. gravityDir : int, optional @@ -2700,10 +2707,7 @@ def apply_icepak_settings( >>> oDesign.SetDesignSettings """ - try: - AmbientTemp = str(float(ambienttemp)) + "cel" - except: - AmbientTemp = ambienttemp + AmbientTemp = self.modeler._arg_with_dim(ambienttemp, "cel") IceGravity = ["X", "Y", "Z"] GVPos = False diff --git a/pyaedt/modeler/Modeler.py b/pyaedt/modeler/Modeler.py index 0d428ed0eb9..a0ed9aab3e2 100644 --- a/pyaedt/modeler/Modeler.py +++ b/pyaedt/modeler/Modeler.py @@ -4426,7 +4426,7 @@ def select_allfaces_fromobjects(self, elements): Returns ------- - list + List List of outer faces in the given list of objects. References diff --git a/pyaedt/modeler/Primitives.py b/pyaedt/modeler/Primitives.py index 1d772543a25..ed23348b7bd 100644 --- a/pyaedt/modeler/Primitives.py +++ b/pyaedt/modeler/Primitives.py @@ -3450,15 +3450,14 @@ def _crosssection_arguments(self, type, orient, width, topwidth, height, num_seg return arg_str @pyaedt_function_handler() - def _arg_with_dim(self, prop_value, units=None): - if isinstance(prop_value, str): - val = prop_value + def _arg_with_dim(self, value, units=None): + if isinstance(value, str): + val = value else: if units is None: units = self.model_units + val = "{0}{1}".format(value, units) - assert is_number(prop_value), "Argument {} must be a numeric value".format(prop_value) - val = "{0}{1}".format(prop_value, units) return val @pyaedt_function_handler() diff --git a/pyaedt/modules/DesignXPloration.py b/pyaedt/modules/DesignXPloration.py index b806da8ceb0..90230cb20fd 100644 --- a/pyaedt/modules/DesignXPloration.py +++ b/pyaedt/modules/DesignXPloration.py @@ -670,13 +670,13 @@ def add_variation( if not min_step: min_step = (max_value - min_value) / 100 - min_step = self._app.modeler._arg_with_dim(min_step, self._app.variable_manager[variable_name].units) + min_step = self._app.value_with_units(min_step, self._app.variable_manager[variable_name].units) if not max_step: max_step = (max_value - min_value) / 10 - max_step = self._app.modeler._arg_with_dim(max_step, self._app.variable_manager[variable_name].units) - min_value = self._app.modeler._arg_with_dim(min_value, self._app.variable_manager[variable_name].units) - max_value = self._app.modeler._arg_with_dim(max_value, self._app.variable_manager[variable_name].units) + max_step = self._app.value_with_units(max_step, self._app.variable_manager[variable_name].units) + min_value = self._app.value_with_units(min_value, self._app.variable_manager[variable_name].units) + max_value = self._app.value_with_units(max_value, self._app.variable_manager[variable_name].units) arg = [ "i:=", True, @@ -705,7 +705,7 @@ def add_variation( if not starting_point: starting_point = self._app[variable_name] - self.props["StartingPoint"][variable_name] = self._app.modeler._arg_with_dim( + self.props["StartingPoint"][variable_name] = self._app.value_with_units( starting_point, self._app.variable_manager[variable_name].units ) self.auto_update = True @@ -740,7 +740,7 @@ def delete(self): return True @pyaedt_function_handler() - def add_variation(self, sweep_var, start_point, end_point, step=100, unit=None, variation_type="LinearCount"): + def add_variation(self, sweep_var, start_point, end_point=None, step=100, unit=None, variation_type="LinearCount"): """Add a variation to an existing parametric setup. Parameters @@ -749,14 +749,14 @@ def add_variation(self, sweep_var, start_point, end_point, step=100, unit=None, Name of the variable. start_point : float or int Variation Start Point. - end_point : float or int - Variation End Point. - step : float or int - Variation Step or Count depending on variation_type. + end_point : float or int, optional + Variation End Point. This parameter is optional if a Single Value is defined. + step : float or int, optional + Variation Step or Count depending on variation_type. Default is `100`. unit : str, optional Variation units. Default is `None`. variation_type : float or int - Variation Type. Admitted values are `"LinearCount"`, `"LinearStep"`, `"LogScale"`. + Variation Type. Admitted values are `"LinearCount"`, `"LinearStep"`, `"LogScale"`, `"SingleValue"`. Returns ------- @@ -768,17 +768,22 @@ def add_variation(self, sweep_var, start_point, end_point, step=100, unit=None, >>> oModule.EditSetup """ + if sweep_var not in self._app.variable_manager.variables: + self._app.logger.error("Variable {} does not exists.".format(sweep_var)) + return False sweep_range = "" if not unit: unit = self._app.variable_manager[sweep_var].units - start_point = self._app.modeler._arg_with_dim(start_point, unit) - end_point = self._app.modeler._arg_with_dim(end_point, unit) + start_point = self._app.value_with_units(start_point, unit) + end_point = self._app.value_with_units(end_point, unit) if variation_type == "LinearCount": sweep_range = "LINC {} {} {}".format(start_point, end_point, step) elif variation_type == "LinearStep": - sweep_range = "LIN {} {} {}".format(start_point, end_point, self._app.modeler._arg_with_dim(step, unit)) + sweep_range = "LIN {} {} {}".format(start_point, end_point, self._app.value_with_units(step, unit)) elif variation_type == "LogScale": - sweep_range = "DEC {} {} {}".format(start_point, end_point, self._app.modeler._arg_with_dim(step, unit)) + sweep_range = "DEC {} {} {}".format(start_point, end_point, self._app.value_with_units(step, unit)) + elif variation_type == "SingleValue": + sweep_range = "{}".format(self._app.value_with_units(start_point, unit)) if not sweep_range: return False self._activate_variable(sweep_var) @@ -791,12 +796,69 @@ def add_variation(self, sweep_var, start_point, end_point, step=100, unit=None, self.props["Sweeps"]["SweepDefinition"] = sweepdefinition elif type(self.props["Sweeps"]["SweepDefinition"]) is not list: self.props["Sweeps"]["SweepDefinition"] = [self.props["Sweeps"]["SweepDefinition"]] - self.props["Sweeps"]["SweepDefinition"].append(sweepdefinition) + self._append_sweepdefinition(sweepdefinition) else: - self.props["Sweeps"]["SweepDefinition"].append(sweepdefinition) + self._append_sweepdefinition(sweepdefinition) return self.update() + @pyaedt_function_handler() + def _append_sweepdefinition(self, sweepdefinition): + for sweep_def in self.props["Sweeps"]["SweepDefinition"]: + if sweepdefinition["Variable"] == sweep_def["Variable"]: + sweep_def["Data"] += " " + sweepdefinition["Data"] + return True + self.props["Sweeps"]["SweepDefinition"].append(sweepdefinition) + return True + + @pyaedt_function_handler() + def sync_variables(self, variables, sync_n=1): + """Sync variable variations in an existing parametric setup. + Setting the sync number to `0` will effectively unsync the variables. + + Parameters + ---------- + variables : list + List of variables to sync. + sync_n : int, optional + Sync number. Sweep variables with the same Sync number will be synchronizad. + Default is `1`. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + + References + ---------- + + >>> oModule.EditSetup + """ + if type(self.props["Sweeps"]["SweepDefinition"]) is not list: + self._app.logger.error("Not enough variables are defined in the Parametric setup") + return False + existing_variables = [s["Variable"] for s in self.props["Sweeps"]["SweepDefinition"]] + undo_vals = {} + for v in variables: + if v not in existing_variables: + self._app.logger.error("Variable {} is not defined in the Parametric setup".format(v)) + return False + for v in variables: + for sweep_def in self.props["Sweeps"]["SweepDefinition"]: + if v == sweep_def["Variable"]: + undo_vals[v] = sweep_def["Synchronize"] + sweep_def["Synchronize"] = sync_n + try: + return self.update() + except Exception: # pragma: no cover + # If it fails to sync (due to e.g. different number of variations), reverts to original values. + for v in variables: + for sweep_def in self.props["Sweeps"]["SweepDefinition"]: + if v == sweep_def["Variable"]: + sweep_def["Synchronize"] = undo_vals[v] + self._app.logger.error("Failed to sync the Parametric setup.") + return False + @pyaedt_function_handler() def add_calculation( self, @@ -908,7 +970,7 @@ def add( self, sweep_var, start_point, - end_point, + end_point=None, step=100, variation_type="LinearCount", solution=None, @@ -923,13 +985,13 @@ def add( sweep_var : str Name of the variable. start_point : float or int - Variation Start Point. - end_point : float or int - Variation End Point. + Variation Start Point if a variation is defined or Single Value. + end_point : float or int, optional + Variation End Point. This parameter is optional if a Single Value is defined. step : float or int - Variation Step or Count depending on variation_type. + Variation Step or Count depending on variation_type. The default is ``100``. variation_type : float or int - Variation Type. Admitted values are `"LinearCount"`, `"LinearStep"`, `"LogScale"`. + Variation Type. Admitted values are `"LinearCount"`, `"LinearStep"`, `"LogScale"`, `"SingleValue"`. solution : str, optional Type of the solution. The default is ``None``, in which case the default solution is used. @@ -947,6 +1009,9 @@ def add( >>> oModule.InsertSetup """ + if sweep_var not in self._app.variable_manager.variables: + self._app.logger.error("Variable {} not found.".format(sweep_var)) + return False if not solution: solution = self._app.nominal_sweep setupname = solution.split(" ")[0] @@ -958,9 +1023,6 @@ def add( setup.props["Sim. Setups"] = [setupname] setup.props["Sweeps"] = OrderedDict({"SweepDefinition": None}) setup.create() - if sweep_var not in self._app.variable_manager.variables: - self._app.logger.error("Variable {} not found.".format(sweep_var)) - return setup unit = self._app.variable_manager[sweep_var].units setup.add_variation(sweep_var, start_point, end_point, step, unit, variation_type) setup.auto_update = True diff --git a/pyaedt/modules/report_templates.py b/pyaedt/modules/report_templates.py index 9f032950e6b..312f45f0d99 100644 --- a/pyaedt/modules/report_templates.py +++ b/pyaedt/modules/report_templates.py @@ -749,7 +749,7 @@ def add_cartesian_y_marker(self, val, name=None, y_axis=1): # pragma: no cover Parameters ---------- - val : str + val : str, float Value to apply with units. name : str, optional Marker Name