Skip to content

Commit

Permalink
FieldPlot now support multi type inputs (line, surfaces, objects) (#859)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
maxcapodi78 authored Feb 16, 2022
1 parent 7625c08 commit 2984011
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 37 deletions.
18 changes: 17 additions & 1 deletion _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def test_01B_Field_Plot(self):
plot1 = self.aedtapp.post.create_fieldplot_cutplane(cutlist, quantity_name, setup_name, intrinsic)
plot1.IsoVal = "Tone"
assert plot1.change_plot_scale(min_value, "30000")
assert self.aedtapp.post.create_fieldplot_volume("inner", "Vector_E", setup_name, intrinsic)
assert self.aedtapp.post.create_fieldplot_surface(
self.aedtapp.modeler["outer"].faces[0].id, "Mag_E", setup_name, intrinsic
)

@pytest.mark.skipif(is_ironpython, reason="Not running in ironpython")
def test_01_Animate_plt(self):
Expand Down Expand Up @@ -216,7 +220,6 @@ def test_16_create_field_plot(self):
quantityName="Mag_E",
setup_name=self.aedtapp.nominal_adaptive,
intrinsincList={"Freq": "5GHz", "Phase": "0deg"},
objtype="Surface",
listtype="CutPlane",
)
assert plot
Expand All @@ -236,3 +239,16 @@ def test_51_get_efields(self):
def test_52_display(self):
img = self.aedtapp.post.nb_display(show_axis=True, show_grid=True, show_ruler=True)
assert isinstance(img, Image)

def test_53_line_plot(self):
udp1 = [0, 0, 0]
udp2 = [1, 0, 0]
setup_name = "Setup1 : LastAdaptive"
intrinsic = {"Freq": "5GHz", "Phase": "180deg"}
self.aedtapp.modeler.create_polyline([udp1, udp2], name="Poly1")
assert self.aedtapp.post.create_fieldplot_line("Poly1", "Mag_E", setup_name, intrinsic)

def test_54_reload(self):
self.aedtapp.save_project()
app2 = Hfss(self.aedtapp.project_name)
assert len(app2.post.field_plots) == len(self.aedtapp.post.field_plots)
173 changes: 137 additions & 36 deletions pyaedt/modules/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,26 @@ class FieldPlot:
"""

def __init__(self, postprocessor, objlist=[], solutionName="", quantityName="", intrinsincList={}):
def __init__(
self,
postprocessor,
objlist=[],
surfacelist=[],
linelist=[],
cutplanelist=[],
solutionName="",
quantityName="",
intrinsincList={},
):
self._postprocessor = postprocessor
self.oField = postprocessor.ofieldsreporter
self.faceIndexes = objlist
self.volume_indexes = objlist
self.surfaces_indexes = surfacelist
self.line_indexes = linelist
self.cutplane_indexes = cutplanelist
self.solutionName = solutionName
self.quantityName = quantityName
self.intrinsincList = intrinsincList
self.objtype = "Surface"
self.listtype = "FaceList"
self.name = "Field_Plot"
self.plotFolder = "Field_Plot"
self.Filled = False
Expand All @@ -573,10 +584,39 @@ def __init__(self, postprocessor, objlist=[], solutionName="", quantityName="",
@property
def plotGeomInfo(self):
"""Plot geometry information."""
info = [1, self.objtype, self.listtype, 0]
for index in self.faceIndexes:
info.append(str(index))
info[3] += 1
id = 0
if self.volume_indexes:
id += 1
if self.surfaces_indexes:
id += 1
if self.cutplane_indexes:
id += 1
if self.line_indexes:
id += 1
info = [id]
if self.volume_indexes:
info.append("Volume")
info.append("ObjList")
info.append(len(self.volume_indexes))
for index in self.volume_indexes:
info.append(str(index))
if self.surfaces_indexes:
info.append("Surface")
info.append("FacesList")
info.append(len(self.surfaces_indexes))
for index in self.surfaces_indexes:
info.append(str(index))
if self.cutplane_indexes:
info.append("Surface")
info.append("CutPlane")
info.append(len(self.cutplane_indexes))
for index in self.cutplane_indexes:
info.append(str(index))
if self.line_indexes:
info.append("Line")
info.append(len(self.line_indexes))
for index in self.line_indexes:
info.append(str(index))
return info

@property
Expand Down Expand Up @@ -612,7 +652,7 @@ def plotsettings(self):
list
List of plot settings.
"""
if self.objtype == "Surface":
if self.surfaces_indexes:
arg = [
"NAME:PlotOnSurfaceSettings",
"Filled:=",
Expand Down Expand Up @@ -1672,16 +1712,17 @@ def _get_intrinsic(self, setup):
def _get_volume_objects(self, list_objs):
if self._app.solution_type not in ["HFSS3DLayout", "HFSS 3D Layout Design"]:
obj_list = []
for obj in list_objs[4:]:
obj_list.append(self._app._odesign.SetActiveEditor("3D Modeler").GetObjectNameByID(int(obj)))
editor = self._app._odesign.SetActiveEditor("3D Modeler")
for obj in list_objs:
obj_list.append(editor.GetObjectNameByID(int(obj)))
if obj_list:
return obj_list
else:
return list_objs[4:]
return list_objs

@aedt_exception_handler
def _get_surface_objects(self, list_objs):
faces = [int(i) for i in list_objs[4:]]
faces = [int(i) for i in list_objs]
if self._app.solution_type not in ["HFSS3DLayout", "HFSS 3D Layout Design"]:
planes = self._get_cs_plane_ids()
objs = []
Expand Down Expand Up @@ -1730,23 +1771,28 @@ def _get_fields_plot(self):
if isinstance(setups_data[setup], (OrderedDict, dict)) and "PlotDefinition" in setup:
plot_name = setups_data[setup]["PlotName"]
plots[plot_name] = FieldPlot(self)
plots[plot_name].faceIndexes = []
plots[plot_name].solutionName = self._get_base_name(setup)
plots[plot_name].quantityName = self.ofieldsreporter.GetFieldPlotQuantityName(
setups_data[setup]["PlotName"]
)
plots[plot_name].intrinsincList = self._get_intrinsic(setup)
list_objs = setups_data[setup]["FieldPlotGeometry"]
if list_objs[1] == 64:
plots[plot_name].objtype = "Volume"
plots[plot_name].listtype = "ObjList"
plots[plot_name].faceIndexes = self._get_volume_objects(list_objs)

else:
plots[plot_name].objtype = "Surface"
plots[plot_name].listtype, plots[plot_name].faceIndexes = self._get_surface_objects(
list_objs
)
list_objs = setups_data[setup]["FieldPlotGeometry"][1:]
while list_objs:
id = list_objs[0]
num_objects = list_objs[2]
if id == 64:
plots[plot_name].volume_indexes = self._get_volume_objects(
list_objs[3 : num_objects + 3]
)
elif id == 128:
out, faces = self._get_surface_objects(list_objs[3 : num_objects + 3])
if out == "CutPlane":
plots[plot_name].cutplane_indexes = faces
else:
plots[plot_name].surfaces_indexes = faces
elif id == 256:
plots[plot_name].line_indexes = self._get_volume_objects(list_objs[3 : num_objects + 3])
list_objs = list_objs[num_objects + 3 :]
plots[plot_name].name = setups_data[setup]["PlotName"]
plots[plot_name].plotFolder = setups_data[setup]["PlotFolder"]
surf_setts = setups_data[setup]["PlotOnSurfaceSettings"]
Expand Down Expand Up @@ -2293,7 +2339,7 @@ def change_field_plot_scale(self, plot_name, minimum_value, maximum_value, is_lo
return True

@aedt_exception_handler
def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, objtype, listtype, plot_name=None):
def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, listtype, plot_name=None):
if isinstance(objlist, (str, int)):
objlist = [objlist]
if not setup_name:
Expand All @@ -2309,12 +2355,37 @@ def _create_fieldplot(self, objlist, quantityName, setup_name, intrinsincList, o
char_set = string.ascii_uppercase + string.digits
if not plot_name:
plot_name = quantityName + "_" + "".join(random.sample(char_set, 6))
plot = FieldPlot(self, objlist, setup_name, quantityName, intrinsincList)
if listtype == "CutPlane":
plot = FieldPlot(
self,
cutplanelist=objlist,
solutionName=setup_name,
quantityName=quantityName,
intrinsincList=intrinsincList,
)
elif listtype == "FacesList":
plot = FieldPlot(
self,
surfacelist=objlist,
solutionName=setup_name,
quantityName=quantityName,
intrinsincList=intrinsincList,
)
elif listtype == "ObjList":
plot = FieldPlot(
self, objlist=objlist, solutionName=setup_name, quantityName=quantityName, intrinsincList=intrinsincList
)
elif listtype == "Line":
plot = FieldPlot(
self,
linelist=objlist,
solutionName=setup_name,
quantityName=quantityName,
intrinsincList=intrinsincList,
)
plot.name = plot_name
plot.plotFolder = plot_name

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

@aedt_exception_handler
def create_fieldplot_line(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
"""Create a field plot of line.
Parameters
----------
objlist : list
List of polyline to plot.
quantityName : str
Name of the quantity to plot.
setup_name : str, optional
Name of the setup in the format ``"setupName : sweepName"``. The default
is ``None``.
intrinsincDict : dict, optional
Dictionary containing all intrinsic variables. The default
is ``{}``.
plot_name : str, optional
Name of the fieldplot to create.
Returns
-------
type
Plot object.
References
----------
>>> oModule.CreateFieldPlot
"""
if plot_name and plot_name in list(self.field_plots.keys()):
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
return self.field_plots[plot_name]
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "Line", plot_name)

@aedt_exception_handler
def create_fieldplot_surface(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
"""Create a field plot of surfaces.
Expand Down Expand Up @@ -2356,9 +2461,7 @@ def create_fieldplot_surface(self, objlist, quantityName, setup_name=None, intri
if plot_name and plot_name in list(self.field_plots.keys()):
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
return self.field_plots[plot_name]
return self._create_fieldplot(
objlist, quantityName, setup_name, intrinsincDict, "Surface", "FacesList", plot_name
)
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "FacesList", plot_name)

@aedt_exception_handler
def create_fieldplot_cutplane(self, objlist, quantityName, setup_name=None, intrinsincDict={}, plot_name=None):
Expand Down Expand Up @@ -2393,9 +2496,7 @@ def create_fieldplot_cutplane(self, objlist, quantityName, setup_name=None, intr
if plot_name and plot_name in list(self.field_plots.keys()):
self.logger.info("Plot {} exists. returning the object.".format(plot_name))
return self.field_plots[plot_name]
return self._create_fieldplot(
objlist, quantityName, setup_name, intrinsincDict, "Surface", "CutPlane", plot_name
)
return self._create_fieldplot(objlist, quantityName, setup_name, intrinsincDict, "CutPlane", plot_name)

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

@aedt_exception_handler
def export_field_jpg(
Expand Down

0 comments on commit 2984011

Please sign in to comment.