Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Graphical_load_flow.m file #95

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions lib/Graphical_load_flow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
%% GRAPHICAL REPRESENTATION OF POWER FLOW (DRAFT CODE)
%The following code, written as a function, would take the power flow
%solution as an input and it would output the plot with the graphical
%representation.
function Graphical_load_flow(results)
%results is a structure containing the PF solution as obtained from
%Matpower.

%Define the number of buses of the system
num_nodi=length(results.bus(:,1));

%Define the source and the sink buses for each line
s=results.branch(:,1)
t=results.branch(:,2)

%Define the real power and reactive power flows over each line
P=results.branch(:,14)
Q=results.branch(:,15)

%Define the buses to which the generators are connected
Gen_Bus=results.gen(:,1)

%Define the power generated by each generator
Gen_Power=results.gen(:,2)

%Define the buses to which the loads are connected
Load_Bus=results.bus(find(results.bus(:,3)~=0),1)

%Define the power absorbed by each load
Load_Power=results.bus(:,3)

%This code is required for the graph to display the correct directions
%of power flows.
Neg=find(P<0)
[t(Neg) s(Neg)]=deal(s(Neg), t(Neg))

%Create the graph of the power flow
G=digraph(s,t,abs(P))

%Create the plot of the graph with various options (they could be set by
%the user as an input to the function)
Plot=plot(G,'LineWidth',abs(G.Edges.Weight)*0.02,'Layout','force','NodeLabel',[1:num_nodi],'NodeFontSize',8,'EdgeLabel',abs(G.Edges.Weight))

%Set the color of the branches proportional to the power flow
colormap jet;
Plot.EdgeCData=abs(G.Edges.Weight);
colorbar

%Change the colors of the buses based on the characteristics of the bus
highlight(Plot,Gen_Bus,'NodeColor','r')
hold on
highlight(Plot,Load_Bus,'NodeColor','g')
%Gen+Load
GL_Bus=intersect(Gen_Bus,Load_Bus);
if ~isempty(GL_Bus)
highlight(Plot,GL_Bus,'NodeColor','m')
end

%Increase the size of the bus based on the power generated/absorbed
for i=1:length(Gen_Bus)
highlight(Plot,Gen_Bus(i),'MarkerSize',Gen_Power(Gen_Bus(i))/10)
end
for i=1:length(Load_Bus)
highlight(Plot,Load_Bus(i),'MarkerSize',Load_Power(Load_Bus(i))/10)
end