From fa55a25603fbea7f589fc255b68fc5b44a95bae8 Mon Sep 17 00:00:00 2001 From: boyang2022 Date: Mon, 28 Oct 2024 16:21:00 +0100 Subject: [PATCH 1/7] add current probe and test --- _unittest/test_21_Circuit.py | 4 ++ .../modeler/circuits/primitives_nexxim.py | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/_unittest/test_21_Circuit.py b/_unittest/test_21_Circuit.py index 1c7a147fa51..ae2bac0eb04 100644 --- a/_unittest/test_21_Circuit.py +++ b/_unittest/test_21_Circuit.py @@ -985,3 +985,7 @@ def test_51_import_asc(self): self.aedtapp.insert_design("ASC") asc_file = os.path.join(local_path, "example_models", test_subfolder, "butter.asc") assert self.aedtapp.create_schematic_from_asc_file(asc_file) + + def test_52_create_current_probe(self): + iprobe = self.aedtapp.modeler.schematic.create_current_probe(name="test_probe", location=[0.4, 0.2]) + assert type(iprobe.id) is int \ No newline at end of file diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index d57fbf6e470..0736dde1289 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -850,6 +850,49 @@ def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_i cmpid.set_property("Name", name) return cmpid + @pyaedt_function_handler(probe_name="name") + def create_current_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False): + """Create a current probe. + + Parameters + ---------- + name : + Name of the current probe. The default is ``None``. + location : list of float, optional + Position on the X axis and Y axis. The default is ``None``. + angle : float, optional + Angle rotation in degrees. The default is ``0``. + use_instance_id_netlist : bool, optional + Whether to use the instance ID in the net list. + The default is ``False``. + + Returns + ------- + :class:`ansys.aedt.core.modeler.cad.object_3dcircuit.CircuitComponent` + Circuit Component Object. + + References + ---------- + + >>> oEditor.CreateComponent + """ + if location is None: + location = [] + else: + location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000] + + cmpid = self.create_component( + None, + component_library="Probes", + component_name="IPROBE", + location=location, + angle=angle, + use_instance_id_netlist=use_instance_id_netlist, + ) + + cmpid.set_property("Name", name) + return cmpid + @pyaedt_function_handler(compname="name") def create_current_pulse(self, name=None, value_lists=None, location=None, angle=0, use_instance_id_netlist=False): """Create a current pulse. From 232c5f226d0b442168631ab4912e5820c320b528 Mon Sep 17 00:00:00 2001 From: boyang2022 Date: Mon, 28 Oct 2024 18:47:33 +0100 Subject: [PATCH 2/7] add current probe and test --- _unittest/test_21_Circuit.py | 3 ++- src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/_unittest/test_21_Circuit.py b/_unittest/test_21_Circuit.py index ae2bac0eb04..450da45502a 100644 --- a/_unittest/test_21_Circuit.py +++ b/_unittest/test_21_Circuit.py @@ -988,4 +988,5 @@ def test_51_import_asc(self): def test_52_create_current_probe(self): iprobe = self.aedtapp.modeler.schematic.create_current_probe(name="test_probe", location=[0.4, 0.2]) - assert type(iprobe.id) is int \ No newline at end of file + assert type(iprobe.id) is int + assert iprobe.InstanceName == "test_probe" diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index 0736dde1289..cd1a9c8c400 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -882,7 +882,7 @@ def create_current_probe(self, name=None, location=None, angle=0, use_instance_i location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000] cmpid = self.create_component( - None, + name, component_library="Probes", component_name="IPROBE", location=location, From dead085e81c24e459d9d64a95253dbf4eaeb9227 Mon Sep 17 00:00:00 2001 From: Samuelopez-ansys Date: Tue, 12 Nov 2024 08:42:49 +0100 Subject: [PATCH 3/7] Add generic probe method --- _unittest/test_21_Circuit.py | 2 +- .../modeler/circuits/primitives_nexxim.py | 64 ++++++++++++------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/_unittest/test_21_Circuit.py b/_unittest/test_21_Circuit.py index 450da45502a..7232519a4ce 100644 --- a/_unittest/test_21_Circuit.py +++ b/_unittest/test_21_Circuit.py @@ -514,7 +514,7 @@ def test_35_netlist_data_block(self): assert self.aedtapp.analyze() def test_36_create_voltage_probe(self): - myprobe = self.aedtapp.modeler.components.create_voltage_probe(name="test_probe", location=[0.4, 0.2]) + myprobe = self.aedtapp.modeler.components.create_voltage_probe() assert type(myprobe.id) is int def test_37_draw_graphical_primitives(self): diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index cd1a9c8c400..f4b4c2b1b61 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -808,13 +808,13 @@ def create_voltage_dc(self, name=None, value=1, location=None, angle=0, use_inst return cmpid @pyaedt_function_handler(probe_name="name") - def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False): + def create_voltage_probe(self, name, location=None, angle=0, use_instance_id_netlist=False): """Create a voltage probe. Parameters ---------- - name : - Name of the voltage probe. The default is ``None``. + name : str + Name of the voltage probe. location : list of float, optional Position on the X axis and Y axis. The default is ``None``. angle : float, optional @@ -830,34 +830,31 @@ def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_i References ---------- - >>> oEditor.CreateComponent - """ - if location is None: - location = [] - else: - location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000] - cmpid = self.create_component( - None, - component_library="Probes", - component_name="VPROBE", + Examples + -------- + >>> from ansys.aedt.core import Circuit + >>> cir = Circuit() + >>> cir.modeler.components.create_voltage_probe(name="probe") + >>> cir.release_desktop(False, False) + """ + return self.__create_probe( + name=name, + probe_type="voltage", location=location, angle=angle, use_instance_id_netlist=use_instance_id_netlist, ) - cmpid.set_property("Name", name) - return cmpid - - @pyaedt_function_handler(probe_name="name") - def create_current_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False): + @pyaedt_function_handler() + def create_current_probe(self, name, location=None, angle=0, use_instance_id_netlist=False): """Create a current probe. Parameters ---------- - name : - Name of the current probe. The default is ``None``. + name : str + Name of the current probe. location : list of float, optional Position on the X axis and Y axis. The default is ``None``. angle : float, optional @@ -873,9 +870,32 @@ def create_current_probe(self, name=None, location=None, angle=0, use_instance_i References ---------- - >>> oEditor.CreateComponent + + Examples + -------- + >>> from ansys.aedt.core import Circuit + >>> cir = Circuit() + >>> cir.modeler.components.create_current_probe(name="probe") + >>> cir.release_desktop(False, False) """ + return self.__create_probe( + name=name, + probe_type="current", + location=location, + angle=angle, + use_instance_id_netlist=use_instance_id_netlist, + ) + + def __create_probe(self, name=None, probe_type="voltage", location=None, angle=0.0, use_instance_id_netlist=False): + if probe_type == "voltage": + component_name = "VPROBE" + elif probe_type == "current": + component_name = "IPROBE" + else: # pragma: no cover + self.logger.error("Wrong probe type assigned.") + return False + if location is None: location = [] else: @@ -884,7 +904,7 @@ def create_current_probe(self, name=None, location=None, angle=0, use_instance_i cmpid = self.create_component( name, component_library="Probes", - component_name="IPROBE", + component_name=component_name, location=location, angle=angle, use_instance_id_netlist=use_instance_id_netlist, From 7b6795aa4b48131c782d546c601c79b70cd32eab Mon Sep 17 00:00:00 2001 From: Samuelopez-ansys Date: Tue, 12 Nov 2024 09:20:45 +0100 Subject: [PATCH 4/7] Add name --- tests/system/general/test_21_Circuit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/general/test_21_Circuit.py b/tests/system/general/test_21_Circuit.py index dc62f8bbbe8..6da837cf0c5 100644 --- a/tests/system/general/test_21_Circuit.py +++ b/tests/system/general/test_21_Circuit.py @@ -517,7 +517,7 @@ def test_35_netlist_data_block(self): assert self.aedtapp.analyze() def test_36_create_voltage_probe(self): - myprobe = self.aedtapp.modeler.components.create_voltage_probe() + myprobe = self.aedtapp.modeler.components.create_voltage_probe(name="voltage_probe") assert type(myprobe.id) is int def test_37_draw_graphical_primitives(self): From d6dab16fdf1f9501820a109890af75a9133f8264 Mon Sep 17 00:00:00 2001 From: Samuelopez-ansys Date: Tue, 12 Nov 2024 10:46:02 +0100 Subject: [PATCH 5/7] Add name optional --- .../core/modeler/circuits/primitives_nexxim.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index f4b4c2b1b61..5a0fd1d37df 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -813,8 +813,8 @@ def create_voltage_probe(self, name, location=None, angle=0, use_instance_id_net Parameters ---------- - name : str - Name of the voltage probe. + name : str, optional + Name of the voltage probe. The default is ``None``. location : list of float, optional Position on the X axis and Y axis. The default is ``None``. angle : float, optional @@ -853,8 +853,8 @@ def create_current_probe(self, name, location=None, angle=0, use_instance_id_net Parameters ---------- - name : str - Name of the current probe. + name : str, optional + Name of the current probe. The default is ``None``. location : list of float, optional Position on the X axis and Y axis. The default is ``None``. angle : float, optional @@ -902,15 +902,15 @@ def __create_probe(self, name=None, probe_type="voltage", location=None, angle=0 location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000] cmpid = self.create_component( - name, + None, component_library="Probes", component_name=component_name, location=location, angle=angle, use_instance_id_netlist=use_instance_id_netlist, ) - - cmpid.set_property("Name", name) + if name: + cmpid.set_property("Name", name) return cmpid @pyaedt_function_handler(compname="name") From 32ff562d73c877fa730cdc12ed48e06bb2499818 Mon Sep 17 00:00:00 2001 From: Samuelopez-ansys Date: Tue, 12 Nov 2024 10:53:42 +0100 Subject: [PATCH 6/7] Add name optional --- src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index 5a0fd1d37df..cdd849ba7c9 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -808,7 +808,7 @@ def create_voltage_dc(self, name=None, value=1, location=None, angle=0, use_inst return cmpid @pyaedt_function_handler(probe_name="name") - def create_voltage_probe(self, name, location=None, angle=0, use_instance_id_netlist=False): + def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False): """Create a voltage probe. Parameters @@ -848,7 +848,7 @@ def create_voltage_probe(self, name, location=None, angle=0, use_instance_id_net ) @pyaedt_function_handler() - def create_current_probe(self, name, location=None, angle=0, use_instance_id_netlist=False): + def create_current_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False): """Create a current probe. Parameters From 77af806ebfbc1d81e700b221808ab695dc3d7328 Mon Sep 17 00:00:00 2001 From: Samuelopez-ansys Date: Tue, 12 Nov 2024 12:20:14 +0100 Subject: [PATCH 7/7] Add name optional --- src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py | 4 ++-- tests/system/general/test_21_Circuit.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py index cdd849ba7c9..4179ed83b9b 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py @@ -902,7 +902,7 @@ def __create_probe(self, name=None, probe_type="voltage", location=None, angle=0 location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000] cmpid = self.create_component( - None, + name, component_library="Probes", component_name=component_name, location=location, @@ -910,7 +910,7 @@ def __create_probe(self, name=None, probe_type="voltage", location=None, angle=0 use_instance_id_netlist=use_instance_id_netlist, ) if name: - cmpid.set_property("Name", name) + cmpid.set_property("InstanceName", name) return cmpid @pyaedt_function_handler(compname="name") diff --git a/tests/system/general/test_21_Circuit.py b/tests/system/general/test_21_Circuit.py index 6da837cf0c5..6d99dd229ae 100644 --- a/tests/system/general/test_21_Circuit.py +++ b/tests/system/general/test_21_Circuit.py @@ -993,3 +993,5 @@ def test_52_create_current_probe(self): iprobe = self.aedtapp.modeler.schematic.create_current_probe(name="test_probe", location=[0.4, 0.2]) assert type(iprobe.id) is int assert iprobe.InstanceName == "test_probe" + iprobe2 = self.aedtapp.modeler.schematic.create_current_probe(location=[0.8, 0.2]) + assert type(iprobe2.id) is int