Skip to content

Commit

Permalink
Synchronous Machine model and bug fixes
Browse files Browse the repository at this point in the history
- Added a synchronous machine block which can be initialized with its output transformer
- Some bug fixes
  • Loading branch information
l2ep-epmlab committed Jun 12, 2023
1 parent aa5f5c4 commit 4e75697
Show file tree
Hide file tree
Showing 69 changed files with 172 additions and 8 deletions.
Binary file removed R2021a/Library/Source_Lib.slx
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions R2021a/R2021a/Library/Init_Base_SM.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%% Compute Base values
% Can be used for all models
% Index 1 = VSC side
% Index 2 = grid side
fb = fn;
Pb = Pn;
cos_phi_n = Pn/Sn;
Sb = Pb/cos_phi_n;
Vn1 = Un1/sqrt(3);
Vb1 = Vn1;
Vn2 = Un2/sqrt(3);
Vb2 = Vn2;
Ib1 = Sb / (3*Vb1);
Ib2 = Sb / (3*Vb2);
Zb = (3*Vb1^2)/Sb;
wb = 2*pi*fb; wb_pu=1;
Lb = Zb/wb;
Cb = 1/(Zb*wb);
% Vdcb = Udcn;
% Idcb = Pb / Vdcb;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Lf_pu = Lc_eq; %Lt_pu;
Rf_pu = Rc_eq; %Rt_pu;
%wn_i = 3/Tr_i;
Kp_i = 2*zeta_i*wn_i*Lf_pu/wb-Rf_pu;
Ti_i = 2*zeta_i/wn_i-Rf_pu/(wn_i^2*Lf_pu/wb);
Ki_i = Kp_i/Ti_i;
%Kp_i = 2*zeta_i*wn_i*Lf_pu/wb-Rf_pu;
%Ti_i = 2*zeta_i/wn_i-Rf_pu/(wn_i^2*Lf_pu/wb);
%Ki_i = Kp_i/Ti_i;
%Kffi = 1;

% Ki_i = Rt_pu*wn_i;
% Kp_i = Lt_pu/wb*wn_i;

Ki_i = 0;%Rc_eq*wn_i;
Ki_i = Rc_eq*wn_i;
Kp_i = Lc_eq/wb*wn_i;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions R2021a/R2021a/Library/Init_LF_SM.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
%% Initialization file for model with an output L-filter
% Compute initial state of power and control component
% Can be used for 2-level or MMC VSCs

% Compute the delay compensation between control and power parts
%if (Time_Step == -1)
% Solver_Time_Step = 0;
%else
% Solver_Time_Step = Time_Step;
%end

% Compute Initial Voltage of VSC
% from steady-state output transformer model and Loadflow result

R1_pu = Rt_pu/2;
L1_pu = Lt_pu/2;
R2_pu = Rt_pu/2;
L2_pu = Lt_pu/2;
X1_pu = L1_pu;
X2_pu = L2_pu;
Xm_pu = Lm_pu;

Zm_pu = 1/(1/Rm_pu+1/(1i*Xm_pu));

Vpcc = V0*exp(1i*Theta0/180*pi);

S0=P0+1i*Q0;
I2 = conj(S0/Vpcc);
% I2 = conj(S0)/V0;

Vm = (R2_pu+1i*X2_pu)*I2 + Vpcc;
Im = Vm/Zm_pu;

I1 = I2 + Im;
V1 = (R1_pu+1i*X1_pu) * I1 + Vm;

Vm0 = abs(V1);
Theta_Vm0 = angle(V1) * 180/pi+Theta0;

Vvsc0 = Vm0;
Theta_Vvsc0 = Theta_Vm0;


% Generate string to display LF results on Mask
mo = get_param(gcb,'MaskObject');
mo.getDialogControl('LF_vsc_str').Prompt = ['V0 = ', num2str(Vvsc0),' pu, Angle = ', num2str(Theta_Vvsc0),'°'];
mo.getDialogControl('LF_pcc_str').Prompt = ['V0 = ', num2str(V0),' pu, Angle = ', num2str(Theta0),'°'];
mo.getDialogControl('LF_pcc_Power_str').Prompt = ['P0 = ', num2str(P0),' pu, Q0 = ', num2str(Q0),' pu'];
File renamed without changes.
42 changes: 42 additions & 0 deletions R2021a/R2021a/Library/Init_SM.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
%
Ism = I1 + conj(Paux/V1);

Ssm = V1*conj(Ism);
Psm = real(Ssm);
Qsm = imag(Ssm);
cos_phi = Psm/abs(Ssm);
sin_phi = Qsm/abs(Ssm);
phi = atan(Qsm/Psm);

Vsum = abs(V1);
Vangle = angle(V1);
Isum = abs(Ism);
Iangle = angle(Ism);
% current init
ia0 = Isum ;
ib0 = Isum ;
ic0 = Isum ;

pha0 = Iangle*180/pi;
phb0 = Iangle*180/pi -120;
phc0 = Iangle*180/pi + 120;

Xaaqu = SM_Ll + SM_Lmq;
Xaadu = SM_Ll + SM_Lmd;
Rau = SM_Rs;

deltai = atan((Xaaqu*Isum*cos_phi-Rau*Isum*sin_phi)/...
(Vsum+Xaaqu*Isum*sin_phi+Rau*Isum*cos_phi));...

delta0 = (deltai + Vangle)*180/pi-90;

Isqu = Isum*cos(phi+deltai);
Isdu = Isum*sin(phi+deltai);
Vsqu = Vsum*cos(deltai);

Ifdu = 1/SM_Lmd*(Vsqu + Rau*Isqu + Xaadu*Isdu);
Efdu = SM_Rf * Ifdu;
N = SM_Rf/SM_Lmd;
Vfu0 = Efdu/N;

Cmu0 = Psm + Rau*Isum*Isum;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
VSC_Lib_handle.VSC.idx = find_system(model2update,'MaskType','VSC');
VSC_Lib_handle.VSC.to_be_linked = zeros(1,length(VSC_Lib_handle.VSC.idx));

% Search All synchronous machines by looking for the Masktype
VSC_Lib_handle.SM.idx = find_system(model2update,'MaskType','SM');
VSC_Lib_handle.SM.to_be_linked = zeros(1,length(VSC_Lib_handle.SM.idx));

%% Search All Generic Voltage Source by looking for the Masktype
VSC_Lib_handle.GenVSource.idx = find_system(model2update,'MaskType','GenericVoltageSource');
VSC_Lib_handle.GenVSource.to_be_linked = zeros(1,length(VSC_Lib_handle.GenVSource.idx));
Expand All @@ -21,7 +25,7 @@
VSC_Lib_handle.VSC.to_be_linked(i) = 0;
end
set_param([VSC_Lib_handle.VSC.idx{i} '/Source_For_LF'],'Commented','off','Frequency','fb','PhaseAngle','0','Voltage','Un2');
set_param([VSC_Lib_handle.VSC.idx{i} '/Output_Transformer'],'Commented','on');
set_param([VSC_Lib_handle.VSC.idx{i} '/Output_Transformer'],'Commented','on');
set_param([VSC_Lib_handle.VSC.idx{i} '/Bridge_Model'],'Commented','on');
set_param([VSC_Lib_handle.VSC.idx{i} '/Bridge_Model/Three-Phase Source'],'Voltage','Vm0*Un1','PhaseAngle','Theta_Vm0','Frequency','fb');

Expand All @@ -30,6 +34,24 @@
VSC_Lib_handle.Ub = max(VSC_Lib_handle.Ub, evalin('base',get_param([VSC_Lib_handle.VSC.idx{i}],'Un2')));
end

for i=1:length(VSC_Lib_handle.SM.idx)
if (strcmp(get_param(VSC_Lib_handle.SM.idx{i},'LinkStatus'),'resolved'))
set_param(VSC_Lib_handle.SM.idx{i}, 'LinkStatus', 'inactive');
VSC_Lib_handle.SM.to_be_linked(i) = 1;
else
VSC_Lib_handle.SM.to_be_linked(i) = 0;
end
set_param([VSC_Lib_handle.SM.idx{i} '/Source_For_LF'],'Commented','off','Frequency','fb','PhaseAngle','0','Voltage','Un2');
set_param([VSC_Lib_handle.SM.idx{i} '/Output_Transformer'],'Commented','on');
set_param([VSC_Lib_handle.SM.idx{i} '/SG'],'Commented','on');
set_param([VSC_Lib_handle.SM.idx{i} '/Aux'],'Commented','on');
set_param([VSC_Lib_handle.SM.idx{i} '/Selector'],'Commented','on');

VSC_Lib_handle.Sb = max(VSC_Lib_handle.Sb, evalin('base',get_param([VSC_Lib_handle.SM.idx{i}],'Sn')));
VSC_Lib_handle.fb = max(VSC_Lib_handle.fb, evalin('base',get_param([VSC_Lib_handle.SM.idx{i}],'fn')));
VSC_Lib_handle.Ub = max(VSC_Lib_handle.Ub, evalin('base',get_param([VSC_Lib_handle.SM.idx{i}],'Un2')));
end

for i=1:length(VSC_Lib_handle.GenVSource.idx)
if (strcmp(get_param(VSC_Lib_handle.GenVSource.idx{i},'LinkStatus'),'resolved'))
set_param(VSC_Lib_handle.GenVSource.idx{i}, 'LinkStatus', 'inactive');
Expand Down Expand Up @@ -71,6 +93,11 @@
set_param(VSC_Lib_handle.VSC.idx{i}, 'LinkStatus', 'restore');
end
end
for i=1:length(VSC_Lib_handle.SM.idx)
if (VSC_Lib_handle.SM.to_be_linked == 1)
set_param(VSC_Lib_handle.SM.idx{i}, 'LinkStatus', 'restore');
end
end
for i=1:length(VSC_Lib_handle.GenVSource.idx)
if (VSC_Lib_handle.GenVSource.to_be_linked == 1)
set_param(VSC_Lib_handle.GenVSource.idx{i}, 'LinkStatus', 'restore');
Expand Down Expand Up @@ -107,18 +134,45 @@
set_param(VSC_Lib_handle.VSC.idx{i}, 'LinkStatus', 'restore');
end
end
%% Update all VSC with a Masktype equal to 'SM'
for i=1:length(VSC_Lib_handle.SM.idx)
% look at the line in the Loadflow related to the internal fake
% Voltage source
Vsm_handle = find_system(VSC_Lib_handle.SM.idx{i},'FindAll','on','LookUnderMasks','on','IncludeCommented','on','Name','Source_For_LF');
for j=1:length(LF.vsrc)
if (LF.vsrc(j).handle == Vsm_handle)
Vsrc_idx = j;
Pb_VSC = evalin('base', get_param(VSC_Lib_handle.SM.idx{i},'Sn'));
%set_param(VSC_idx{i},'V_mag_0',num2str(LF.bus(test).vbase * abs(LF.bus(test).Vbus) / sqrt(3)),'Theta0',num2str(angle(LF.bus(test).Vbus) * 180/pi));
set_param(VSC_Lib_handle.SM.idx{i},'V0',num2str(abs(LF.vsrc(Vsrc_idx).Vt)),'Theta0',num2str(angle(LF.vsrc(Vsrc_idx).Vt) * 180/pi));
set_param(VSC_Lib_handle.SM.idx{i},'P0',num2str(real(LF.vsrc(Vsrc_idx).S)*LF_Pbase/Pb_VSC),'Q0',num2str(imag(LF.vsrc(Vsrc_idx).S)*LF_Pbase/Pb_VSC));

%p.setParameters('V_mag_0') = LF.bus(test).vbase * LF.bus(test).vref / sqrt(3);
%p.setParameters('Theta0') = LF.bus(test).angle;
end
end

set_param([VSC_Lib_handle.SM.idx{i} '/Source_For_LF'],'Commented','on');
set_param([VSC_Lib_handle.SM.idx{i} '/Output_Transformer'],'Commented','off');
set_param([VSC_Lib_handle.SM.idx{i} '/SG'],'Commented','off');
set_param([VSC_Lib_handle.SM.idx{i} '/Aux'],'Commented','off');
set_param([VSC_Lib_handle.SM.idx{i} '/Selector'],'Commented','off');

if (VSC_Lib_handle.SM.to_be_linked(i) == 1)
set_param(VSC_Lib_handle.VSC.idx{i}, 'LinkStatus', 'restore');
end
end
%% Update all Generic Voltage Sources
for i=1:length(VSC_Lib_handle.GenVSource.idx)
block_name = get_param(VSC_Lib_handle.GenVSource.idx{i},'Name');
test = find(strcmp({LF.bus.ID},block_name));
%GenVSource_Sb = eval(get_param(VSC_Lib_handle.GenVSource.idx{i},'Sn'));
GenVSource_Sb = eval(get_param(VSC_Lib_handle.GenVSource.idx{i},'Sn'));
%GenVSource_Vb = eval(get_param(VSC_Lib_handle.GenVSource.idx{i},'Un'))/sqrt(3);

if (isempty(test)==0) % if a loadflow bus with the same name as the block name exists, then execute the following configuration of the block:

set_param(VSC_Lib_handle.GenVSource.idx{i},'V0_pu',num2str(abs(LF.bus(test).Vbus)),'Theta0_deg',num2str(angle(LF.bus(test).Vbus)*180/pi));
set_param(VSC_Lib_handle.GenVSource.idx{i},'P0',num2str(real(LF.bus(test).Sbus)*LF_Pbase),'Q0',num2str(imag(LF.bus(test).Sbus)*LF_Pbase));
set_param(VSC_Lib_handle.GenVSource.idx{i},'V0',num2str(abs(LF.bus(test).Vbus)),'Theta0',num2str(angle(LF.bus(test).Vbus)*180/pi));
set_param(VSC_Lib_handle.GenVSource.idx{i},'P0',num2str(real(LF.bus(test).Sbus)*LF_Pbase/GenVSource_Sb),'Q0',num2str(imag(LF.bus(test).Sbus)*LF_Pbase/GenVSource_Sb));

end

Expand Down
File renamed without changes.
Binary file added R2021a/R2021a/Library/Source_Lib.slx
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4e75697

Please sign in to comment.