Skip to content

Commit 2984011

Browse files
authored
FieldPlot now support multi type inputs (line, surfaces, objects) (#859)
* FieldPlot now support multi type inputs (line, surfaces, objects) * FieldPlot now support multi type inputs (line, surfaces, objects) * improved UT * Fixed black * Fixed black Co-authored-by: maxcapodi78 <Shark78>
1 parent 7625c08 commit 2984011

File tree

2 files changed

+154
-37
lines changed

2 files changed

+154
-37
lines changed

_unittest/test_12_PostProcessing.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def test_01B_Field_Plot(self):
5151
plot1 = self.aedtapp.post.create_fieldplot_cutplane(cutlist, quantity_name, setup_name, intrinsic)
5252
plot1.IsoVal = "Tone"
5353
assert plot1.change_plot_scale(min_value, "30000")
54+
assert self.aedtapp.post.create_fieldplot_volume("inner", "Vector_E", setup_name, intrinsic)
55+
assert self.aedtapp.post.create_fieldplot_surface(
56+
self.aedtapp.modeler["outer"].faces[0].id, "Mag_E", setup_name, intrinsic
57+
)
5458

5559
@pytest.mark.skipif(is_ironpython, reason="Not running in ironpython")
5660
def test_01_Animate_plt(self):
@@ -216,7 +220,6 @@ def test_16_create_field_plot(self):
216220
quantityName="Mag_E",
217221
setup_name=self.aedtapp.nominal_adaptive,
218222
intrinsincList={"Freq": "5GHz", "Phase": "0deg"},
219-
objtype="Surface",
220223
listtype="CutPlane",
221224
)
222225
assert plot
@@ -236,3 +239,16 @@ def test_51_get_efields(self):
236239
def test_52_display(self):
237240
img = self.aedtapp.post.nb_display(show_axis=True, show_grid=True, show_ruler=True)
238241
assert isinstance(img, Image)
242+
243+
def test_53_line_plot(self):
244+
udp1 = [0, 0, 0]
245+
udp2 = [1, 0, 0]
246+
setup_name = "Setup1 : LastAdaptive"
247+
intrinsic = {"Freq": "5GHz", "Phase": "180deg"}
248+
self.aedtapp.modeler.create_polyline([udp1, udp2], name="Poly1")
249+
assert self.aedtapp.post.create_fieldplot_line("Poly1", "Mag_E", setup_name, intrinsic)
250+
251+
def test_54_reload(self):
252+
self.aedtapp.save_project()
253+
app2 = Hfss(self.aedtapp.project_name)
254+
assert len(app2.post.field_plots) == len(self.aedtapp.post.field_plots)

pyaedt/modules/PostProcessor.py

Lines changed: 137 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,26 @@ class FieldPlot:
540540
541541
"""
542542

543-
def __init__(self, postprocessor, objlist=[], solutionName="", quantityName="", intrinsincList={}):
543+
def __init__(
544+
self,
545+
postprocessor,
546+
objlist=[],
547+
surfacelist=[],
548+
linelist=[],
549+
cutplanelist=[],
550+
solutionName="",
551+
quantityName="",
552+
intrinsincList={},
553+
):
544554
self._postprocessor = postprocessor
545555
self.oField = postprocessor.ofieldsreporter
546-
self.faceIndexes = objlist
556+
self.volume_indexes = objlist
557+
self.surfaces_indexes = surfacelist
558+
self.line_indexes = linelist
559+
self.cutplane_indexes = cutplanelist
547560
self.solutionName = solutionName
548561
self.quantityName = quantityName
549562
self.intrinsincList = intrinsincList
550-
self.objtype = "Surface"
551-
self.listtype = "FaceList"
552563
self.name = "Field_Plot"
553564
self.plotFolder = "Field_Plot"
554565
self.Filled = False
@@ -573,10 +584,39 @@ def __init__(self, postprocessor, objlist=[], solutionName="", quantityName="",
573584
@property
574585
def plotGeomInfo(self):
575586
"""Plot geometry information."""
576-
info = [1, self.objtype, self.listtype, 0]
577-
for index in self.faceIndexes:
578-
info.append(str(index))
579-
info[3] += 1
587+
id = 0
588+
if self.volume_indexes:
589+
id += 1
590+
if self.surfaces_indexes:
591+
id += 1
592+
if self.cutplane_indexes:
593+
id += 1
594+
if self.line_indexes:
595+
id += 1
596+
info = [id]
597+
if self.volume_indexes:
598+
info.append("Volume")
599+
info.append("ObjList")
600+
info.append(len(self.volume_indexes))
601+
for index in self.volume_indexes:
602+
info.append(str(index))
603+
if self.surfaces_indexes:
604+
info.append("Surface")
605+
info.append("FacesList")
606+
info.append(len(self.surfaces_indexes))
607+
for index in self.surfaces_indexes:
608+
info.append(str(index))
609+
if self.cutplane_indexes:
610+
info.append("Surface")
611+
info.append("CutPlane")
612+
info.append(len(self.cutplane_indexes))
613+
for index in self.cutplane_indexes:
614+
info.append(str(index))
615+
if self.line_indexes:
616+
info.append("Line")
617+
info.append(len(self.line_indexes))
618+
for index in self.line_indexes:
619+
info.append(str(index))
580620
return info
581621

582622
@property
@@ -612,7 +652,7 @@ def plotsettings(self):
612652
list
613653
List of plot settings.
614654
"""
615-
if self.objtype == "Surface":
655+
if self.surfaces_indexes:
616656
arg = [
617657
"NAME:PlotOnSurfaceSettings",
618658
"Filled:=",
@@ -1672,16 +1712,17 @@ def _get_intrinsic(self, setup):
16721712
def _get_volume_objects(self, list_objs):
16731713
if self._app.solution_type not in ["HFSS3DLayout", "HFSS 3D Layout Design"]:
16741714
obj_list = []
1675-
for obj in list_objs[4:]:
1676-
obj_list.append(self._app._odesign.SetActiveEditor("3D Modeler").GetObjectNameByID(int(obj)))
1715+
editor = self._app._odesign.SetActiveEditor("3D Modeler")
1716+
for obj in list_objs:
1717+
obj_list.append(editor.GetObjectNameByID(int(obj)))
16771718
if obj_list:
16781719
return obj_list
16791720
else:
1680-
return list_objs[4:]
1721+
return list_objs
16811722

16821723
@aedt_exception_handler
16831724
def _get_surface_objects(self, list_objs):
1684-
faces = [int(i) for i in list_objs[4:]]
1725+
faces = [int(i) for i in list_objs]
16851726
if self._app.solution_type not in ["HFSS3DLayout", "HFSS 3D Layout Design"]:
16861727
planes = self._get_cs_plane_ids()
16871728
objs = []
@@ -1730,23 +1771,28 @@ def _get_fields_plot(self):
17301771
if isinstance(setups_data[setup], (OrderedDict, dict)) and "PlotDefinition" in setup:
17311772
plot_name = setups_data[setup]["PlotName"]
17321773
plots[plot_name] = FieldPlot(self)
1733-
plots[plot_name].faceIndexes = []
17341774
plots[plot_name].solutionName = self._get_base_name(setup)
17351775
plots[plot_name].quantityName = self.ofieldsreporter.GetFieldPlotQuantityName(
17361776
setups_data[setup]["PlotName"]
17371777
)
17381778
plots[plot_name].intrinsincList = self._get_intrinsic(setup)
1739-
list_objs = setups_data[setup]["FieldPlotGeometry"]
1740-
if list_objs[1] == 64:
1741-
plots[plot_name].objtype = "Volume"
1742-
plots[plot_name].listtype = "ObjList"
1743-
plots[plot_name].faceIndexes = self._get_volume_objects(list_objs)
1744-
1745-
else:
1746-
plots[plot_name].objtype = "Surface"
1747-
plots[plot_name].listtype, plots[plot_name].faceIndexes = self._get_surface_objects(
1748-
list_objs
1749-
)
1779+
list_objs = setups_data[setup]["FieldPlotGeometry"][1:]
1780+
while list_objs:
1781+
id = list_objs[0]
1782+
num_objects = list_objs[2]
1783+
if id == 64:
1784+
plots[plot_name].volume_indexes = self._get_volume_objects(
1785+
list_objs[3 : num_objects + 3]
1786+
)
1787+
elif id == 128:
1788+
out, faces = self._get_surface_objects(list_objs[3 : num_objects + 3])
1789+
if out == "CutPlane":
1790+
plots[plot_name].cutplane_indexes = faces
1791+
else:
1792+
plots[plot_name].surfaces_indexes = faces
1793+
elif id == 256:
1794+
plots[plot_name].line_indexes = self._get_volume_objects(list_objs[3 : num_objects + 3])
1795+
list_objs = list_objs[num_objects + 3 :]
17501796
plots[plot_name].name = setups_data[setup]["PlotName"]
17511797
plots[plot_name].plotFolder = setups_data[setup]["PlotFolder"]
17521798
surf_setts = setups_data[setup]["PlotOnSurfaceSettings"]
@@ -2293,7 +2339,7 @@ def change_field_plot_scale(self, plot_name, minimum_value, maximum_value, is_lo
22932339
return True
22942340

22952341
@aedt_exception_handler
2296-
def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, objtype, listtype, plot_name=None):
2342+
def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, listtype, plot_name=None):
22972343
if isinstance(objlist, (str, int)):
22982344
objlist = [objlist]
22992345
if not setup_name:
@@ -2309,12 +2355,37 @@ def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, o
23092355
char_set = string.ascii_uppercase + string.digits
23102356
if not plot_name:
23112357
plot_name = quantityName + "_" + "".join(random.sample(char_set, 6))
2312-
plot = FieldPlot(self, objlist, setup_name, quantityName, intrinsincList)
2358+
if listtype == "CutPlane":
2359+
plot = FieldPlot(
2360+
self,
2361+
cutplanelist=objlist,
2362+
solutionName=setup_name,
2363+
quantityName=quantityName,
2364+
intrinsincList=intrinsincList,
2365+
)
2366+
elif listtype == "FacesList":
2367+
plot = FieldPlot(
2368+
self,
2369+
surfacelist=objlist,
2370+
solutionName=setup_name,
2371+
quantityName=quantityName,
2372+
intrinsincList=intrinsincList,
2373+
)
2374+
elif listtype == "ObjList":
2375+
plot = FieldPlot(
2376+
self, objlist=objlist, solutionName=setup_name, quantityName=quantityName, intrinsincList=intrinsincList
2377+
)
2378+
elif listtype == "Line":
2379+
plot = FieldPlot(
2380+
self,
2381+
linelist=objlist,
2382+
solutionName=setup_name,
2383+
quantityName=quantityName,
2384+
intrinsincList=intrinsincList,
2385+
)
23132386
plot.name = plot_name
23142387
plot.plotFolder = plot_name
23152388

2316-
plot.objtype = objtype
2317-
plot.listtype = listtype
23182389
plt = plot.create()
23192390
if "Maxwell" in self._app.design_type and self.post_solution_type == "Transient":
23202391
self.ofieldsreporter.SetPlotsViewSolutionContext([plot_name], setup_name, "Time:" + intrinsincList["Time"])
@@ -2324,6 +2395,40 @@ def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, o
23242395
else:
23252396
return False
23262397

2398+
@aedt_exception_handler
2399+
def create_fieldplot_line(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
2400+
"""Create a field plot of line.
2401+
2402+
Parameters
2403+
----------
2404+
objlist : list
2405+
List of polyline to plot.
2406+
quantityName : str
2407+
Name of the quantity to plot.
2408+
setup_name : str, optional
2409+
Name of the setup in the format ``"setupName : sweepName"``. The default
2410+
is ``None``.
2411+
intrinsincDict : dict, optional
2412+
Dictionary containing all intrinsic variables. The default
2413+
is ``{}``.
2414+
plot_name : str, optional
2415+
Name of the fieldplot to create.
2416+
2417+
Returns
2418+
-------
2419+
type
2420+
Plot object.
2421+
2422+
References
2423+
----------
2424+
2425+
>>> oModule.CreateFieldPlot
2426+
"""
2427+
if plot_name and plot_name in list(self.field_plots.keys()):
2428+
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
2429+
return self.field_plots[plot_name]
2430+
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "Line", plot_name)
2431+
23272432
@aedt_exception_handler
23282433
def create_fieldplot_surface(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
23292434
"""Create a field plot of surfaces.
@@ -2356,9 +2461,7 @@ def create_fieldplot_surface(self, objlist, quantityName, setup_name=None, intri
23562461
if plot_name and plot_name in list(self.field_plots.keys()):
23572462
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
23582463
return self.field_plots[plot_name]
2359-
return self._create_fieldplot(
2360-
objlist, quantityName, setup_name, intrinsincDict, "Surface", "FacesList", plot_name
2361-
)
2464+
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "FacesList", plot_name)
23622465

23632466
@aedt_exception_handler
23642467
def create_fieldplot_cutplane(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
@@ -2393,9 +2496,7 @@ def create_fieldplot_cutplane(self, objlist, quantityName, setup_name=None, intr
23932496
if plot_name and plot_name in list(self.field_plots.keys()):
23942497
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
23952498
return self.field_plots[plot_name]
2396-
return self._create_fieldplot(
2397-
objlist, quantityName, setup_name, intrinsincDict, "Surface", "CutPlane", plot_name
2398-
)
2499+
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "CutPlane", plot_name)
23992500

24002501
@aedt_exception_handler
24012502
def create_fieldplot_volume(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
@@ -2430,7 +2531,7 @@ def create_fieldplot_volume(self, objlist, quantityName, setup_name=None, intrin
24302531
if plot_name and plot_name in list(self.field_plots.keys()):
24312532
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
24322533
return self.field_plots[plot_name]
2433-
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "Volume", "ObjList", plot_name)
2534+
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "ObjList", plot_name)
24342535

24352536
@aedt_exception_handler
24362537
def export_field_jpg(

0 commit comments

Comments
 (0)