Skip to content

Various fixes and improvements #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 15 additions & 1 deletion _unittest/test_20_HFSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"})
Expand Down
15 changes: 15 additions & 0 deletions _unittest/test_21_Circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions examples/03-Circuit/Circuit_Subcircuit_Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions examples/03-Circuit/Circuit_Transient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

###############################################################################
Expand Down Expand Up @@ -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([])
Expand Down
36 changes: 28 additions & 8 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand All @@ -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:
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:=")
Expand Down
61 changes: 28 additions & 33 deletions pyaedt/application/Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down
28 changes: 16 additions & 12 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,16 +1459,21 @@ 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
List of objects in the source that are metals. The default is ``None``.
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``.

Expand All @@ -1484,8 +1489,6 @@ def assign_em_losses(
"""
if surface_objects == None:
surface_objects = []
if paramlist == None:
paramlist = []
if object_list == None:
object_list = []

Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/modeler/Modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4426,7 +4426,7 @@ def select_allfaces_fromobjects(self, elements):

Returns
-------
list
List
List of outer faces in the given list of objects.

References
Expand Down
9 changes: 4 additions & 5 deletions pyaedt/modeler/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading