Skip to content
1 change: 1 addition & 0 deletions doc/changelog.d/5937.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exception error for multiple design
43 changes: 40 additions & 3 deletions src/ansys/aedt/core/filtersolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import warnings

from ansys.aedt.core import settings
import ansys.aedt.core.filtersolutions_core
from ansys.aedt.core.filtersolutions_core.attributes import Attributes
Expand All @@ -45,11 +47,19 @@


class FilterDesignBase:
"""Provides the `FilterSolutions` main parameters applicable for all design types.
This class has access to ideal filter attributes and calculated output parameters.
"""
"""Provides the `FilterSolutions` main parameters applicable for all design types."""

_active_design = None

def __init__(self, version=None):
if FilterDesignBase._active_design:
warnings.warn(
"FilterSolutions API currently supports only one design at a time. \n"
"Opening a new design will overwrite the existing design with default values.",
UserWarning,
)
FilterDesignBase._active_design.close()
FilterDesignBase._active_design = self
self.version = version if version else settings.aedt_version
ansys.aedt.core.filtersolutions_core._dll_interface(version)
self.attributes = Attributes()
Expand All @@ -59,6 +69,33 @@ def __init__(self, version=None):
self.transmission_zeros_bandwidth = TransmissionZeros(TableFormat.BANDWIDTH)
self.export_to_aedt = ExportToAedt()

def close(self):
Comment thread
myoung301 marked this conversation as resolved.
"""Closes the current design and clears the active design."""
if FilterDesignBase._active_design == self:
print(f"Closing design: {self}")
self._cleanup_resources()
FilterDesignBase._active_design = None

def _cleanup_resources(self):
"""Perform cleanup operations for the design."""
print("Cleaning up resources...")
self.attributes = None
self.ideal_response = None
self.graph_setup = None
self.transmission_zeros_ratio = None
self.transmission_zeros_bandwidth = None
self.export_to_aedt = None
self.source_impedance_table = None
self.load_impedance_table = None
self.multiple_bands_table = None
self.optimization_goals_table = None
self.topology = None
self.parasitics = None
self.leads_and_nodes = None
self.substrate = None
self.geometry = None
self.radial = None


class LumpedDesign(FilterDesignBase):
"""Provides the `FilterSolutions` application interface for lumped filter designs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import ansys.aedt.core.filtersolutions
from ansys.aedt.core.filtersolutions_core.attributes import BesselRipplePercentage
from ansys.aedt.core.filtersolutions_core.attributes import DiplexerType
from ansys.aedt.core.filtersolutions_core.attributes import FilterClass
Expand Down Expand Up @@ -50,6 +51,24 @@
@pytest.mark.skipif(is_linux, reason="FilterSolutions API is not supported on Linux.")
@pytest.mark.skipif(config["desktopVersion"] < "2025.1", reason="Skipped on versions earlier than 2025.1")
class TestClass:
def test_multiple_designs(self, lumped_design):
lumped_design.attributes.filter_class = FilterClass.BAND_PASS
assert lumped_design.attributes.filter_class == FilterClass.BAND_PASS
lumped_design.attributes.filter_type = FilterType.ELLIPTIC
assert lumped_design.attributes.filter_type == FilterType.ELLIPTIC
lumped_design.attributes.filter_order = 8
assert lumped_design.attributes.filter_order == 8
with pytest.warns(
UserWarning,
match="FilterSolutions API currently supports only one design at a time. \n"
"Opening a new design will overwrite the existing design with default values.",
):
new_lumped_design = ansys.aedt.core.filtersolutions.LumpedDesign()
new_lumped_design = ansys.aedt.core.filtersolutions.LumpedDesign()
assert new_lumped_design.attributes.filter_class == FilterClass.LOW_PASS
assert new_lumped_design.attributes.filter_type == FilterType.BUTTERWORTH
assert new_lumped_design.attributes.filter_order == 5

def test_filter_type(self, lumped_design):
assert lumped_design.attributes.filter_type == FilterType.BUTTERWORTH
assert hasattr(FilterType, "CHEBY") is False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ def test_raise_error(self, lumped_design):
with pytest.raises(RuntimeError) as info:
lumped_design.transmission_zeros_ratio.row(0)
assert info.value.args[0] == test_transmission_zeros.TestClass.no_transmission_zero_msg

@pytest.mark.skipif(config["desktopVersion"] < "2025.2", reason="Skipped on versions earlier than 2025.2")
def test_close_lumped_design(self, lumped_design):
lumped_design.close()
for attr_name in dir(lumped_design):
if attr_name.startswith("_") or callable(getattr(lumped_design, attr_name)):
continue
if attr_name in ["version"]:
continue
assert getattr(lumped_design, attr_name) is None

@pytest.mark.skipif(config["desktopVersion"] < "2025.2", reason="Skipped on versions earlier than 2025.2")
def test_close_distributed_design(self, distributed_design):
distributed_design.close()
for attr_name in dir(distributed_design):
if attr_name.startswith("_") or callable(getattr(distributed_design, attr_name)):
continue
if attr_name in ["version"]:
continue
assert getattr(distributed_design, attr_name) is None