Skip to content

Commit 51a6d85

Browse files
FEAT: edit sources harmonic loss q3d (#6826)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 5a28b0a commit 51a6d85

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

doc/changelog.d/6826.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Edit sources harmonic loss q3d

src/ansys/aedt/core/q3d.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,7 @@ def export_mesh_stats(self, setup, variations="", output_file=None, setup_type="
267267
return str(output_file)
268268

269269
@pyaedt_function_handler()
270-
def edit_sources(
271-
self,
272-
cg=None,
273-
acrl=None,
274-
dcrl=None,
275-
):
270+
def edit_sources(self, cg=None, acrl=None, dcrl=None, harmonic_loss=None):
276271
"""Set up the source loaded for Q3D or Q2D in multiple sources simultaneously.
277272
278273
Parameters
@@ -293,6 +288,12 @@ def edit_sources(
293288
- 1 Magnitude to set up ``0deg`` as the default
294289
- 2 Values tuple or list (magnitude and phase)
295290
291+
harmonic_loss: dict, optional
292+
Dictionary of real and imaginary currents for each source in order to compute harmonic loss.
293+
Dictionary values can be:
294+
- 1 Real part of the current
295+
- 2 Imag part of the current
296+
296297
Returns
297298
-------
298299
bool
@@ -306,11 +307,17 @@ def edit_sources(
306307
>>> sources_acrl = {"Box1:Source1": ("5A", "0deg")}
307308
Values can also be passed as lists instead of tuples.
308309
>>> sources_dcrl = {"Box1_1:Source2": ["5V", "0deg"]}
309-
>>> q3d.edit_sources(cg=sources_cg, acrl=sources_acrl, dcrl=sources_dcrl)
310+
Assuming to have two TAB files containing respectively the real and imaginary parts
311+
of the current for the source ``Box1:Source1``.
312+
>>> real_data_set = q3d.import_dataset1d("real_dataset_file_path", name="real_dataset")
313+
>>> imag_data_set = q3d.import_dataset1d("imag_dataset_file_path", name="imag_dataset")
314+
>>> harmonic_loss = {"Box1:Source1": (real_data_set.name, imag_data_set.name)}
315+
>>> q3d.edit_sources(cg=sources_cg, acrl=sources_acrl, dcrl=sources_dcrl, harmonic_loss=harmonic_loss)
310316
"""
311317
settings_ac = []
312318
settings_cg = []
313319
settings_dc = []
320+
settings_harmonic_loss = []
314321
if cg:
315322
source_list = ["NAME:Source Names"]
316323
if self.default_solution_type == "Q3D Extractor":
@@ -399,8 +406,36 @@ def edit_sources(
399406

400407
settings_dc = ["NAME:DC", "Value Type:=", magnitude_unit, source_list, magnitude_list, phase_list]
401408

409+
if harmonic_loss:
410+
source_list = ["NAME:Source Names"]
411+
source_real_dataset_names = ["NAME:Source real dataset names"]
412+
source_imag_dataset_names = ["NAME:Source imag dataset names"]
413+
sources = [source.name for source in self.excitations_by_type["Source"]]
414+
415+
for key, vals in harmonic_loss.items():
416+
if key not in sources and key not in self.get_all_sources():
417+
self.logger.error("Not existing source " + key)
418+
return False
419+
420+
source_list.append(key)
421+
if not isinstance(vals, (tuple, list)):
422+
self.logger.error("Real and Imag part of current must be provided")
423+
return False
424+
else:
425+
source_real_dataset_names.append(vals[0])
426+
source_imag_dataset_names.append(vals[1])
427+
428+
settings_harmonic_loss = [
429+
"NAME:HarmonicLoss",
430+
"Value Type:=",
431+
"A",
432+
source_list,
433+
source_real_dataset_names,
434+
source_imag_dataset_names,
435+
]
436+
402437
if self.default_solution_type == "Q3D Extractor":
403-
self.osolution.EditSources(settings_ac, settings_cg, settings_dc)
438+
self.osolution.EditSources(settings_ac, settings_cg, settings_dc, settings_harmonic_loss)
404439
else:
405440
self.osolution.EditSources(settings_cg, settings_ac)
406441
return True

tests/system/extensions/test_via_clustering.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from tests import TESTS_EXTENSIONS_PATH
3636

3737

38+
@pytest.mark.skipif(is_linux, reason="Not supported in Linux.")
3839
def test_via_clustering_main_function(local_scratch):
3940
"""Test the main function of the Via Clustering extension."""
4041
# Copy test model to scratch directory
-652 Bytes
Binary file not shown.

tests/system/solvers/test_31_Q3D.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ def test_14_edit_sources(self, q3d_solved):
383383
sources_dc = {"Box1:Source1": "20v"}
384384
assert q3d_solved.edit_sources(None, None, sources_dc)
385385

386+
real_dataset = q3d_solved.design_datasets["ds1"].name
387+
imag_dataset = q3d_solved.design_datasets["ds2"].name
388+
harmonic_loss = {"Box1:Source1": (real_dataset, imag_dataset)}
389+
assert q3d_solved.edit_sources(harmonic_loss=harmonic_loss)
390+
harmonic_loss = {"invalid": (real_dataset, imag_dataset)}
391+
assert not q3d_solved.edit_sources(harmonic_loss=harmonic_loss)
392+
harmonic_loss = {"Box1:Source1": real_dataset}
393+
assert not q3d_solved.edit_sources(harmonic_loss=harmonic_loss)
394+
386395
def test_15_insert_reduced(self, q3d_solved):
387396
q3d = q3d_solved
388397
mm = q3d.insert_reduced_matrix("JoinSeries", ["Source1", "Sink4"], "JointTest_r")

0 commit comments

Comments
 (0)