Skip to content

FEATURE: Add support for multiple frequencies in a frequency sweep #541

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 1 commit into from
May 5, 2025
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
2 changes: 2 additions & 0 deletions doc/source/api/simulation_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Classes
simulation_setup.FreqSweepType
simulation_setup.HFSSRegionComputeResource
simulation_setup.InterpolatingSweepData
simulation_setup.FrequencyData
raptor_x_simulation_settings.RaptorXSimulationSettings
raptor_x_simulation_settings.RaptorXGeneralSettings
raptor_x_simulation_settings.RaptorXAdvancedSettings
Expand Down Expand Up @@ -71,6 +72,7 @@ Enums
:toctree: _autosummary

simulation_setup.SimulationSetupType
simulation_setup.Distribution
hfss_simulation_settings.AdaptType
hfss_simulation_settings.BasisFunctionOrder
hfss_simulation_settings.SolverType
Expand Down
118 changes: 78 additions & 40 deletions src/ansys/edb/core/simulation_setup/simulation_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Simulation Setup."""

from enum import Enum
from typing import List, Union

from ansys.api.edb.v1 import edb_defs_pb2
from ansys.api.edb.v1.simulation_setup_pb2 import (
Expand Down Expand Up @@ -38,6 +39,16 @@ class FreqSweepType(Enum):
BROADBAND_SWEEP = edb_defs_pb2.BROADBAND_SWEEP


class Distribution(Enum):
"""Enum representing frequency distribution types."""

LIN = "LIN"
LINC = "LINC"
ESTP = "ESTP"
DEC = "DEC"
OCT = "OCT"


class HFSSRegionComputeResource:
"""Class representing HFSS region computation resources.

Expand Down Expand Up @@ -114,21 +125,64 @@ def __init__(self):
self.min_solutions = 0


class SweepData:
r"""Class representing a sweep data setting.
class FrequencyData:
r"""Class representing a frequency setting.

Attributes
----------
name : str
Name of this sweep.
distribution : str
distribution : .Distribution
Sweep distribution type (see table below).
start_f : str
Start frequency is number with optional frequency units.
end_f : str
End frequency is number with optional frequency units.
step : str
Step is either frequency with optional frequency units or an integer when a count is needed.
Step is either frequency with optional frequency units or an integer

Notes
-----
Here are the choices for the distribution parameter:

.. list-table:: Values for distribution parameter
:widths: 20 45 25
:header-rows: 1

* - Distribution
- Description
- Example
* - LIN
- linear (start, stop, step)
- LIN 2GHz 4GHz 100MHz or LIN 1dBm 10dBm 1dB
* - LINC
- linear (start, stop, count)
- LINC 2GHz 4GHz 11
* - ESTP
- Exponential step (start, stop, count)
- ESTP 2MHz 10MHz 3
* - DEC
- decade (start, stop, number of decades)
- DEC 10KHz 10GHz 6
* - OCT
- octave (start, stop, number of octaves)
- OCT 10MHz 160MHz 5

"""

def __init__(self, distribution: Distribution, start_f: str, end_f: str, step: str):
"""Initialize a frequency setting."""
self.distribution = distribution
self.start_f = start_f
self.end_f = end_f
self.step = step


class SweepData:
r"""Class representing a sweep data setting.

Attributes
----------
name : str
Name of this sweep.
enabled : bool
True if this is enabled.
type : FreqSweepType
Expand Down Expand Up @@ -171,43 +225,14 @@ class SweepData:
Stop meshing frequency.
interpolation_data : InterpolatingSweepData
Data for interpolating frequency sweeps.

Notes
-----
Here are the choices for the distribution parameter:

.. list-table:: Values for distribution parameter
:widths: 20 45 25
:header-rows: 1

* - Distribution
- Description
- Example
* - LIN
- linear (start, stop, step)
- LIN 2GHz 4GHz 100MHz or LIN 1dBm 10dBm 1dB
* - LINC
- linear (start, stop, count)
- LINC 2GHz 4GHz 11
* - ESTP
- Exponential step (start, stop, count)
- ESTP 2MHz 10MHz 3
* - DEC
- decade (start, stop, number of decades)
- DEC 10KHz 10GHz 6
* - OCT
- octave (start, stop, number of octaves)
- OCT 10MHz 160MHz 5
frequency_data : .FrequencyData or list of .FrequencyData
List of frequency data.

"""

def __init__(self, name, distribution, start_f, end_f, step):
def __init__(self, name: str, frequency_data: Union[FrequencyData, List[FrequencyData]]):
"""Initialize a sweep data setting."""
self.name = name
self.distribution = distribution
self.start_f = start_f
self.end_f = end_f
self.step = step
self.enabled = True
self.type = FreqSweepType.INTERPOLATING_SWEEP
self.use_q3d_for_dc = False
Expand All @@ -229,11 +254,24 @@ def __init__(self, name, distribution, start_f, end_f, step):
self.mesh_freq_range_start = "-1.0"
self.mesh_freq_range_stop = "-1.0"
self.interpolation_data = InterpolatingSweepData()
self.frequency_data = frequency_data

@property
def frequency_string(self):
""":obj:`str`: String representing the frequency sweep data."""
return self.distribution + " " + self.start_f + " " + self.end_f + " " + self.step
""":obj:`str`: String representing the frequency sweep data.

This property is read-only.
"""
frequencies = []
if isinstance(self.frequency_data, FrequencyData):
frequencies.append(self.frequency_data)
elif isinstance(self.frequency_data, list):
frequencies = self.frequency_data

freq_str = ""
for freq in frequencies:
freq_str += f"{freq.distribution.value} {freq.start_f} {freq.end_f} {freq.step}\t\n"
return freq_str


def _hfss_region_compute_resource_message(res):
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/integration_tests/test_spiral_inductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ansys.edb.core.simulation_setup.adaptive_solutions import SingleFrequencyAdaptiveSolution
from ansys.edb.core.simulation_setup.hfss_simulation_setup import HfssSimulationSetup
from ansys.edb.core.simulation_setup.mesh_operation import SkinDepthMeshOperation
from ansys.edb.core.simulation_setup.simulation_setup import SweepData
from ansys.edb.core.simulation_setup.simulation_setup import Distribution, FrequencyData, SweepData
from ansys.edb.core.terminal.point_terminal import PointTerminal

# Wrapper class over Database
Expand Down Expand Up @@ -411,7 +411,9 @@ def create_adaptive_settings(self):
name="SPIRAL_M9", net_layer_info=[("SPIRAL", "M9", False)], num_layers="3"
)
]
sweep_data = SweepData("Sweep 1", "LIN", "0GHz", "30GHz", "0.01GHz")
sweep_data = SweepData(
"Sweep 1", FrequencyData(Distribution.LIN, "0GHz", "30GHz", "0.01GHz")
)
sweep_data.interpolation_data.fast_sweep = True
setup.sweep_data = [sweep_data]

Expand Down
Loading