Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
Visualization.h File Reference

Interactive ImGui/ImPlot visualization for solver results. More...

#include "../../Constants.h"
Include dependency graph for Visualization.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OPFVisualData
 Container for all OPF topology and solution data needed by viz_opf(). More...
 

Functions

void visualization_stop ()
 Closes the visualization window and stops the GUI thread.
 
void visualization_set_embedded_mode (bool enabled)
 Use the host ImGui/GLFW context (HarmonyUI) instead of a background window.
 
bool visualization_has_tabs ()
 Returns whether plot tabs are registered.
 
void visualization_clear_tabs ()
 Remove all registered plot tabs (e.g.
 
void visualization_draw_embedded (const char *tabBarId="HarmonyPlotTabs")
 Draw plot tabs inside the current ImGui window (embedded / HarmonyUI mode).
 
void visualization_process_pending_save (GLFWwindow *window)
 Capture a pending PNG save after ImGui::Render() on window.
 
bool visualization_is_running ()
 Returns whether the visualization window is currently open.
 
void visualization_wait ()
 Blocks until the user closes the visualization window.
 
void visualization_save_tab (const std::string &tab_title, const std::filesystem::path &output_dir={})
 Schedules a PNG capture of the named tab on the next rendered frame.
 
std::vector< std::string > visualization_tab_titles ()
 Titles of tabs currently registered in the visualization window.
 
void add_plot_tab (const std::string &title, std::function< void()> fn)
 Registers a custom ImGui/ImPlot draw callback as a new tab.
 
void bode_plot_implot (const std::vector< double > &freq, const std::vector< std::vector< double > > &mag_dB, const std::vector< std::vector< double > > &phase_deg, const std::vector< std::string > &labels, const std::string &title)
 Opens a Bode magnitude/phase plot in the visualization window.
 
void nyquist_plot_implot (const std::vector< std::vector< std::complex< double > > > &H_data, const std::vector< std::string > &labels, const std::string &title)
 Opens a Nyquist plot in the visualization window.
 
void plot_eigenvalues_implot (const std::vector< std::complex< double > > &eigvals, const std::string &title)
 Plots eigenvalues in the complex plane.
 
void plot_participation_factors_implot (const std::vector< std::vector< double > > &P, const std::vector< std::string > &state_labels, const std::vector< std::string > &mode_labels, const std::string &title)
 Plots participation factor heatmap (states vs modes).
 
void plot_abc_waveforms_implot (const std::vector< double > &t, const Eigen::MatrixXd &Xabc, const std::string &title)
 Plots three-phase abc waveforms over time.
 
void plot_abc_groups_implot (const std::vector< double > &t, const std::vector< Eigen::MatrixXd > &Xabc_groups, const std::string &title)
 Plots multiple abc waveform groups on shared axes.
 
void viz_opf (const OPFVisualData &data)
 Registers an "AC/DC OPF" network diagram tab in the visualization window.
 

Detailed Description

Interactive ImGui/ImPlot visualization for solver results.

Provides a shared GUI window with built-in Bode, Nyquist, eigenvalue, participation-factor, and abc waveform plots, plus OPF network rendering and an extension API for custom plot tabs.

Function Documentation

◆ add_plot_tab()

void add_plot_tab ( const std::string &  title,
std::function< void()>  fn 
)

Registers a custom ImGui/ImPlot draw callback as a new tab.

The GUI thread is auto-started on the first call. fn is invoked every frame while the tab is active.

Parameters
titleTab title shown in the tab bar.
fnDraw callback executed each frame.

Registers a custom ImGui/ImPlot draw callback as a new tab.

References add_tab().

◆ bode_plot_implot()

void bode_plot_implot ( const std::vector< double > &  freq,
const std::vector< std::vector< double > > &  mag_dB,
const std::vector< std::vector< double > > &  phase_deg,
const std::vector< std::string > &  labels,
const std::string &  title 
)
extern

Opens a Bode magnitude/phase plot in the visualization window.

Parameters
freqFrequency axis (Hz).
mag_dBMagnitude in dB, one vector per trace.
phase_degPhase in degrees, one vector per trace.
labelsTrace legend labels.
titlePlot window title.

References add_tab(), j, and kHarmonyPlotPanelHeightPx.

Referenced by StabilityEstimate::bodeplotTF(), and Element::plotYParameters().

◆ nyquist_plot_implot()

void nyquist_plot_implot ( const std::vector< std::vector< std::complex< double > > > &  H_data,
const std::vector< std::string > &  labels,
const std::string &  title 
)
extern

Opens a Nyquist plot in the visualization window.

Parameters
H_dataComplex frequency response, one vector per trace.
labelsTrace legend labels.
titlePlot window title.

References add_tab(), and j.

Referenced by StabilityEstimate::nyquistplotTF().

◆ plot_abc_groups_implot()

void plot_abc_groups_implot ( const std::vector< double > &  t,
const std::vector< Eigen::MatrixXd > &  Xabc_groups,
const std::string &  title 
)
extern

Plots multiple abc waveform groups on shared axes.

Parameters
tTime axis (s).
Xabc_groupsOne 3N matrix per signal group.
titlePlot window title.

References add_tab(), and kHarmonyPlotWaveformHeightPx.

Referenced by example_DQsym_DSSS2(), example_DQsym_RLC(), and DQsym::plot().

◆ plot_abc_waveforms_implot()

void plot_abc_waveforms_implot ( const std::vector< double > &  t,
const Eigen::MatrixXd &  Xabc,
const std::string &  title 
)
extern

Plots three-phase abc waveforms over time.

Parameters
tTime axis (s).
XabcWaveform matrix (3 rows N samples).
titlePlot window title.

References add_tab().

Referenced by example_DQsym_math_operations().

◆ plot_eigenvalues_implot()

void plot_eigenvalues_implot ( const std::vector< std::complex< double > > &  eigvals,
const std::string &  title 
)
extern

Plots eigenvalues in the complex plane.

Parameters
eigvalsList of eigenvalues.
titlePlot window title.

References add_tab(), and kHarmonyPlotEigenHeightPx.

Referenced by Converter::plotEigenvalues().

◆ plot_participation_factors_implot()

void plot_participation_factors_implot ( const std::vector< std::vector< double > > &  P,
const std::vector< std::string > &  state_labels,
const std::vector< std::string > &  mode_labels,
const std::string &  title 
)
extern

Plots participation factor heatmap (states vs modes).

Parameters
PParticipation factor matrix [state][mode].
state_labelsRow labels (state names).
mode_labelsColumn labels (mode indices/names).
titlePlot window title.

References add_tab(), and j.

Referenced by Converter::plotParticipationFactors().

◆ visualization_clear_tabs()

void visualization_clear_tabs ( )

Remove all registered plot tabs (e.g.

before a new run).

◆ visualization_draw_embedded()

void visualization_draw_embedded ( const char *  tabBarId = "HarmonyPlotTabs")

Draw plot tabs inside the current ImGui window (embedded / HarmonyUI mode).

References draw_plot_tabs().

◆ visualization_has_tabs()

bool visualization_has_tabs ( )

Returns whether plot tabs are registered.

◆ visualization_is_running()

bool visualization_is_running ( )

Returns whether the visualization window is currently open.

Returns
True if the GUI is running.

Referenced by runJsonSimulation().

◆ visualization_process_pending_save()

void visualization_process_pending_save ( GLFWwindow *  window)

Capture a pending PNG save after ImGui::Render() on window.

Referenced by runHarmonyLauncher().

◆ visualization_save_tab()

void visualization_save_tab ( const std::string &  tab_title,
const std::filesystem::path &  output_dir 
)

Schedules a PNG capture of the named tab on the next rendered frame.

Parameters
tab_titleTitle of the tab to capture (saved as "<tab_title>.png").

Schedules a PNG capture of the named tab on the next rendered frame.

The file is written as "<tab_title>.png" in the working directory. Thread-safe: can be called from any thread.

◆ visualization_set_embedded_mode()

void visualization_set_embedded_mode ( bool  enabled)

Use the host ImGui/GLFW context (HarmonyUI) instead of a background window.

Call before any simulation runs. Prevents a second GLFW/ImGui context that can crash with ImGui focus-scope errors.

Referenced by runHarmonyLauncher().

◆ visualization_stop()

void visualization_stop ( )

Closes the visualization window and stops the GUI thread.

Referenced by runHarmonyLauncher().

◆ visualization_tab_titles()

std::vector< std::string > visualization_tab_titles ( )

Titles of tabs currently registered in the visualization window.

◆ visualization_wait()

void visualization_wait ( )

Blocks until the user closes the visualization window.

Call at the end of main() to keep the process alive while the GUI is open.

Blocks until the user closes the visualization window.

Referenced by runJsonSimulation().

◆ viz_opf()

void viz_opf ( const OPFVisualData data)

Registers an "AC/DC OPF" network diagram tab in the visualization window.

Returns immediately; the window stays open until the user closes it or visualization_stop() / visualization_wait() is called.

Parameters
dataOPF topology and solved bus/branch quantities.