Skip to content

Commit

Permalink
The ModelViewer can now display the orientation vectors of the
Browse files Browse the repository at this point in the history
aerodynamic panels for visual inspection.
  • Loading branch information
ArneVoss committed Dec 6, 2024
1 parent 39a78a3 commit 5a7037a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
22 changes: 18 additions & 4 deletions modelviewer/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def plot_nothing(self):
self.show_strc = False
self.show_mode = False
self.show_aero = False
self.show_panel_normal_vectors = False
self.show_cfdgrids = False
self.show_coupling = False
self.show_cs = False
Expand Down Expand Up @@ -192,17 +193,30 @@ def update_mode_display(self, offsets):
self.ug_strc.modified()

def hide_aero(self):
self.src_aerogrid.remove()
self.src_MAC.remove()
self.show_aero = False
mlab.draw(self.fig)
if self.show_aero:
self.src_aerogrid.remove()
self.src_MAC.remove()
self.show_aero = False
mlab.draw(self.fig)
if self.show_panel_normal_vectors:
self.src_panel_normal_vectors.remove()
self.show_panel_normal_vectors = False

def plot_aero(self, scalars=None, colormap='coolwarm', vminmax=[-10.0, 10.0]):
self.setup_aero_display(scalars, colormap, vminmax)
self.setup_mac_display()
self.show_aero = True
mlab.draw(self.fig)

def plot_panel_normal_vectors(self):
# This function plots the normal vectors on each aerodynamic panel to identify the orientation visually.
x, y, z = self.aerogrid['offset_k'][:,0], self.aerogrid['offset_k'][:,1], self.aerogrid['offset_k'][:,2]
Nx, Ny, Nz, = self.aerogrid['N'][:,0], self.aerogrid['N'][:,1], self.aerogrid['N'][:,2]
self.src_panel_normal_vectors = mlab.quiver3d(x, y, z, Nx, Ny, Nz, color=(0,1,0), opacity=0.4,
scale_mode='vector', scale_factor=1.0)
self.show_panel_normal_vectors = True
mlab.draw(self.fig)

def setup_mac_display(self):
ug2 = tvtk.UnstructuredGrid(points=np.array([self.MAC]))
self.src_MAC = mlab.pipeline.add_dataset(ug2)
Expand Down
21 changes: 11 additions & 10 deletions modelviewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def initAeroTab(self):
self.cb_w2gj = QtGui.QCheckBox('Color by W2GJ [deg]')
self.cb_w2gj.setChecked(False)
self.cb_w2gj.stateChanged.connect(self.get_aero_for_plotting)
self.cb_normal_vectors = QtGui.QCheckBox('Panel normal vectors')
self.cb_normal_vectors.setChecked(False)
self.cb_normal_vectors.stateChanged.connect(self.get_aero_for_plotting)
bt_aero_hide = QtGui.QPushButton('Hide')
bt_aero_hide.clicked.connect(self.plotting.hide_aero)
self.lb_MAC = QtGui.QLabel(
Expand All @@ -245,6 +248,7 @@ def initAeroTab(self):
layout_aero.addWidget(self.lb_MAC)
layout_aero.addWidget(self.lb_MAC2)
layout_aero.addWidget(self.cb_w2gj)
layout_aero.addWidget(self.cb_normal_vectors)
layout_aero.addWidget(bt_aero_hide)
layout_aero.addWidget(self.list_markers)
layout_aero.addWidget(bt_cfdgrid_hide)
Expand Down Expand Up @@ -517,19 +521,16 @@ def get_aero_for_plotting(self):
if self.list_aero.currentItem() is not None:
key = self.list_aero.currentItem().data(0)
self.calc_MAC(key)
self.lb_MAC.setText(
'MAC: x={:0.4f}, y={:0.4f} m'.format(self.MAC[0], self.MAC[1]))
self.lb_MAC2.setText(
'(based on AIC from "{}", rigid, subsonic)'.format(key))
self.lb_MAC.setText('MAC: x={:0.4f}, y={:0.4f} m'.format(self.MAC[0], self.MAC[1]))
self.lb_MAC2.setText('(based on AIC from "{}", rigid, subsonic)'.format(key))
if self.plotting.show_aero:
self.plotting.hide_aero()
if self.cb_w2gj.isChecked():
if self.plotting.show_aero:
self.plotting.hide_aero()
self.plotting.plot_aero(
self.model['camber_twist']['cam_rad'][()] / np.pi * 180.0)
self.plotting.plot_aero(self.model['camber_twist']['cam_rad'][()] / np.pi * 180.0)
else:
if self.plotting.show_aero:
self.plotting.hide_aero()
self.plotting.plot_aero()
if self.cb_normal_vectors.isChecked():
self.plotting.plot_panel_normal_vectors()

def get_new_cs_for_plotting(self, *args):
# To show a different control surface, new points need to be created. Thus, remove last control surface from plot.
Expand Down

0 comments on commit 5a7037a

Please sign in to comment.