Skip to content

Commit 8606592

Browse files
maxcapodi78pyansys-ci-botSamuelopez-ansys
authored
REFACTOR: Solution Data (#6706)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Samuelopez-ansys <[email protected]>
1 parent d46c724 commit 8606592

File tree

17 files changed

+608
-441
lines changed

17 files changed

+608
-441
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Solution Data

src/ansys/aedt/core/extensions/hfss/shielding_effectiveness.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,16 @@ def main(data: ShieldingEffectivenessExtensionData):
435435
frequency_units = free_space_1meter.units_sweeps["Freq"]
436436

437437
# 1 Meter shielding
438-
original_1meter = np.array(original_1meter.data_magnitude())
439-
free_space_1meter = np.array(free_space_1meter.data_magnitude())
438+
original_1meter = original_1meter.get_expression_data(formula="magnitude")[1]
439+
free_space_1meter = np.array(free_space_1meter.get_expression_data(formula="magnitude")[1])
440440

441441
shielding_1meter = original_1meter / free_space_1meter
442442

443443
shielding_1meter_db = -20 * np.log10(shielding_1meter)
444444

445445
# 3 meter shielding
446-
original_3meters = np.array(original_3meters.data_magnitude())
447-
free_space_3meters = np.array(free_space_3meters.data_magnitude())
446+
original_3meters = np.array(original_3meters.get_expression_data(formula="magnitude")[1])
447+
free_space_3meters = np.array(free_space_3meters.get_expression_data(formula="magnitude")[1])
448448

449449
shielding_3meters = original_3meters / free_space_3meters
450450

src/ansys/aedt/core/hfss.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from typing import Union
3232
import warnings
3333

34+
import numpy as np
35+
3436
from ansys.aedt.core.application.analysis_3d import FieldAnalysis3D
3537
from ansys.aedt.core.application.analysis_hf import ScatteringMethods
3638
from ansys.aedt.core.generic.constants import InfiniteSphereType
@@ -6266,8 +6268,10 @@ def get_antenna_data(
62666268
]
62676269

62686270
if frequencies is not None:
6269-
if not isinstance(frequencies, list):
6271+
if not isinstance(frequencies, (list, np.ndarray)):
62706272
frequencies = [frequencies]
6273+
elif isinstance(frequencies, np.ndarray):
6274+
frequencies = frequencies.tolist()
62716275
frequencies = _units_assignment(frequencies)
62726276
else: # pragma: no cover
62736277
self.logger.info("Frequencies could not be obtained.")

src/ansys/aedt/core/hfss3dlayout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ def get_dcir_element_data_loop_resistance(self, setup):
23512351
for i in terms:
23522352
data2 = []
23532353
for ex in [f"LoopRes({i},{j})" for j in terms]:
2354-
d = solution_data.data_magnitude(ex)
2354+
d = solution_data.get_expression_data(formula="magnitude", expression=ex)[1]
23552355
if d is not False:
23562356
data2.append(d[0])
23572357
else:
@@ -2389,7 +2389,7 @@ def get_dcir_element_data_current_source(self, setup):
23892389
data = {"Voltage": []}
23902390
for t_name in terms:
23912391
ex = f"V({t_name})"
2392-
value = solution_data.data_magnitude(ex, convert_to_SI=True)
2392+
value = solution_data.get_expression_data(formula="magnitude", expression=ex, convert_to_SI=True)[1]
23932393
if value is not False:
23942394
data["Voltage"].append(value[0])
23952395
df = pd.DataFrame(data)
@@ -2424,7 +2424,7 @@ def get_dcir_element_data_via(self, setup):
24242424
tmp_via_names.append(matches[0])
24252425

24262426
for ex in solution_data.expressions:
2427-
value = solution_data.data_magnitude(ex, convert_to_SI=True)[0]
2427+
value = solution_data.get_expression_data(formula="magnitude", expression=ex, convert_to_SI=True)[1][0]
24282428
data[cat].append(value)
24292429

24302430
df_tmp = pd.DataFrame(data)

src/ansys/aedt/core/modules/solve_sweeps.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from ansys.aedt.core.generic.constants import unit_converter
3333
from ansys.aedt.core.generic.data_handlers import _dict2arg
3434
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
35+
from ansys.aedt.core.generic.numbers_utils import Quantity
3536
from ansys.aedt.core.generic.numbers_utils import _units_assignment
3637
from ansys.aedt.core.generic.settings import settings
3738
from ansys.aedt.core.internal.load_aedt_file import load_entire_aedt_file
@@ -177,7 +178,7 @@ def frequencies(self):
177178
sol = self._app._app.post.reports_by_category.standard(setup=f"{self.setup_name} : {self.name}")
178179
soldata = sol.get_solution_data()
179180
if soldata and "Freq" in soldata.intrinsics:
180-
return soldata.intrinsics["Freq"]
181+
return [Quantity(i, soldata.units_sweeps["Freq"]) for i in soldata.intrinsics["Freq"]]
181182
return []
182183

183184
@property
@@ -694,7 +695,7 @@ def frequencies(self):
694695
sol = self._app._app.post.reports_by_category.standard(setup=f"{self.setup_name} : {self.name}")
695696
soldata = sol.get_solution_data()
696697
if soldata and "Freq" in soldata.intrinsics:
697-
return soldata.intrinsics["Freq"]
698+
return [Quantity(i, soldata.units_sweeps["Freq"]) for i in soldata.intrinsics["Freq"]]
698699
return []
699700

700701
@property
@@ -923,7 +924,7 @@ def frequencies(self):
923924
)
924925
soldata = sol.get_solution_data()
925926
if soldata and "Freq" in soldata.intrinsics:
926-
return soldata.intrinsics["Freq"]
927+
return [Quantity(i, soldata.units_sweeps["Freq"]) for i in soldata.intrinsics["Freq"]]
927928
return []
928929

929930
@pyaedt_function_handler()

src/ansys/aedt/core/visualization/advanced/touchstone_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def __init__(self, solution_data=None, touchstone_file=None):
9494
p_b = m.group(2)
9595
p_a_number = ports.index(p_a)
9696
p_b_number = ports.index(p_b)
97-
sdata_real = solution_data.data_real(expression, True)
98-
sdata_img = solution_data.data_imag(expression, True)
97+
sdata_real = solution_data.get_expression_data(expression, formula="real", convert_to_SI=True)[1]
98+
sdata_img = solution_data.get_expression_data(expression, formula="imag", convert_to_SI=True)[1]
9999
sdata_2d = np.array(sdata_real, dtype=complex) + 1j * np.array(sdata_img, dtype=complex)
100100
sdata_3d[:, p_a_number, p_b_number] = sdata_2d
101101
sdata_3d[:, p_b_number, p_a_number] = sdata_2d

src/ansys/aedt/core/visualization/plot/matplotlib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ def car2spherical(self):
402402
y = np.array(self.cartesian_data[1], dtype=float)
403403
z = np.array(self.cartesian_data[2], dtype=float)
404404
r = np.sqrt(x * x + y * y + z * z)
405-
theta = np.arccos(z / r) * 180 / math.pi # to degrees
405+
with np.errstate(invalid="ignore", divide="ignore"):
406+
ratio = np.where(r != 0, z / r, 0) # or np.nan if you prefer
407+
ratio = np.clip(ratio, -1.0, 1.0) # ensure valid domain for arccos
408+
theta = np.arccos(ratio) * 180 / math.pi
406409
phi = np.arctan2(y, x) * 180 / math.pi
407410
self._spherical_data = [r, theta, phi]
408411

src/ansys/aedt/core/visualization/post/common.py

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ def available_quantities_categories(
229229
context = ""
230230

231231
if solution and report_category and display_type:
232-
return list(self.oreportsetup.GetAllCategories(report_category, display_type, solution, context))
232+
try:
233+
return list(self.oreportsetup.GetAllCategories(report_category, display_type, solution, context))
234+
except Exception: # pragma: no cover
235+
return []
233236
return [] # pragma: no cover
234237

235238
@pyaedt_function_handler()
@@ -466,16 +469,31 @@ def get_all_report_quantities(
466469
third key the report categories.
467470
"""
468471
rep_quantities = {}
472+
if not context and self._app.design_type in [
473+
"HFSS",
474+
"Maxwell 3D",
475+
"Maxwell 2D",
476+
"Q3D Extractor",
477+
"2D Extractor",
478+
"Icepak",
479+
"Mechanical",
480+
]:
481+
if not context and "2D" in self._app.modeler.design_type:
482+
if self._app.modeler.point_names:
483+
context = self._app.modeler.point_names[0]
484+
elif not context:
485+
if self._app.modeler.line_names:
486+
context = self._app.modeler.line_names[0]
469487
for rep in self.available_report_types:
470488
rep_quantities[rep] = {}
471489
solutions = [solution] if isinstance(solution, str) else self.available_report_solutions(rep)
472-
for solution in solutions:
473-
rep_quantities[rep][solution] = {}
490+
for sol in solutions:
491+
rep_quantities[rep][sol] = {}
474492
for quant in self.available_quantities_categories(
475-
rep, context=context, solution=solution, is_siwave_dc=is_siwave_dc
493+
rep, context=context, solution=sol, is_siwave_dc=is_siwave_dc
476494
):
477-
rep_quantities[rep][solution][quant] = self.available_report_quantities(
478-
rep, quantities_category=quant, context=context, solution=solution, is_siwave_dc=is_siwave_dc
495+
rep_quantities[rep][sol][quant] = self.available_report_quantities(
496+
rep, quantities_category=quant, context=context, solution=sol, is_siwave_dc=is_siwave_dc
479497
)
480498

481499
return rep_quantities
@@ -1122,6 +1140,56 @@ def _get_report_inputs(
11221140
]
11231141
return [plot_name, modal_data, plot_type, setup_sweep_name, ctxt, families_input, arg]
11241142

1143+
@pyaedt_function_handler()
1144+
def _check_category_context(self, expression, report_category, context):
1145+
field_ctx = context
1146+
if self._app.design_type in [
1147+
"HFSS",
1148+
"Maxwell 3D",
1149+
"Maxwell 2D",
1150+
"Q3D Extractor",
1151+
"2D Extractor",
1152+
"Icepak",
1153+
"Mechanical",
1154+
]:
1155+
if not field_ctx and "2D" in self._app.modeler.design_type:
1156+
if self._app.modeler.point_names:
1157+
field_ctx = self._app.modeler.point_names[0]
1158+
elif not field_ctx:
1159+
if self._app.modeler.line_names:
1160+
field_ctx = self._app.modeler.line_names[0]
1161+
if not report_category:
1162+
sols = self.get_all_report_quantities(context=field_ctx)
1163+
for cat, sol in sols.items():
1164+
for s, q in sol.items():
1165+
for _, v in q.items():
1166+
if any([i in expression for i in v]):
1167+
report_category = cat
1168+
self._app.logger.warning(f"No report category provided. Automatically identified {cat}")
1169+
break
1170+
if report_category:
1171+
break
1172+
if report_category:
1173+
break
1174+
if not context:
1175+
if report_category == "Far Fields" and not context:
1176+
for setup in self._app.field_setups:
1177+
if setup.type == "FarFieldSphere":
1178+
context = setup.name
1179+
self._app.logger.warning(f"No Far Fields infinite sphere provided. Assigned setup: {context}")
1180+
1181+
break
1182+
elif report_category == "Near Fields" and not context:
1183+
for setup in self._app.field_setups:
1184+
if setup.type.startswith("NearField"):
1185+
context = setup.name
1186+
self._app.logger.warning(f"No Near Fields setup provided. Assigned setup: {context}")
1187+
break
1188+
elif report_category == "Fields" and not context:
1189+
context = field_ctx
1190+
self._app.logger.warning(f"No context provided for Fields. Assigned object: {context}")
1191+
return report_category, context
1192+
11251193
@pyaedt_function_handler()
11261194
def _get_report_object(
11271195
self,
@@ -1177,6 +1245,7 @@ def _get_report_object(
11771245
]
11781246
elif isinstance(expressions, str):
11791247
expressions = [expressions]
1248+
report_category, context = self._check_category_context(expressions[0], report_category, context)
11801249

11811250
# Report Category
11821251
if domain in ["Spectral", "Spectrum"]:
@@ -1826,7 +1895,7 @@ def _report_plotter(self, report):
18261895
props["symbol_style"] = markers[pp["symbol_style"]]
18271896
except KeyError:
18281897
pass
1829-
report_plotter.add_trace([sw, sols.data_real(curve)], 0, properties=props, name=curve)
1898+
report_plotter.add_trace([sw, sols.get_expression_data(curve)[1]], 0, properties=props, name=curve)
18301899
for name, line in report._legacy_props.get("limitLines", {}).items():
18311900
props = {}
18321901
try:

0 commit comments

Comments
 (0)