mirror of
https://github.com/ANL-CEEESA/powersas.m.git
synced 2025-12-06 01:48:52 -06:00
First release of PowerSAS.m
This commit is contained in:
56
util/expect_eq.m
Normal file
56
util/expect_eq.m
Normal file
@@ -0,0 +1,56 @@
|
||||
function res=expect_eq(tested,expected,err,testName,nrm)
|
||||
% Test if equals
|
||||
%
|
||||
% FUNCTION expect_eq
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
|
||||
if nargin<5||isempty(nrm)||nrm<=0||~isinteger(nrm)
|
||||
nrm=2;
|
||||
end
|
||||
|
||||
if nargin<4||isempty(testName)||~ischar(testName)
|
||||
testName='TEST';
|
||||
end
|
||||
|
||||
if nargin<3||isempty(err)||err<0
|
||||
err=1e-8;
|
||||
end
|
||||
|
||||
diff=norm(tested-expected,nrm);
|
||||
|
||||
prefix=['[',testName,'] '];
|
||||
|
||||
if diff>=err
|
||||
warning([prefix,'EXPECT_EQ test FAILED.']);
|
||||
res=-1;
|
||||
else
|
||||
disp([prefix,'EXPECT_EQ test OK.']);
|
||||
res=1;
|
||||
end
|
||||
|
||||
end
|
||||
90
util/findCommonPoints.m
Normal file
90
util/findCommonPoints.m
Normal file
@@ -0,0 +1,90 @@
|
||||
function [tt,sc1x,sc2x]=findCommonPoints(tt1,sc1,tt2,sc2,tt)
|
||||
% Regulate two series with different time steps tt1/tt2 to the same time steps tt
|
||||
%
|
||||
% FUNCTION findCommonPoints
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
% INPUT
|
||||
% tt1 - Time series 1
|
||||
% sc1 - State series corresponding to time steps tt1
|
||||
% tt2 - Time series 2
|
||||
% sc2 - State series corresponding to time steps tt2
|
||||
% tt - Regulated time series
|
||||
%
|
||||
% OUTPUT
|
||||
% tt - Regulated time series
|
||||
% sc1x - Regulated state series 1
|
||||
% sc2x - Regulated state series 2
|
||||
%
|
||||
sc1x=zeros(size(sc1,1),size(tt,2));
|
||||
sc2x=zeros(size(sc2,1),size(tt,2));
|
||||
tth=1e-8;
|
||||
|
||||
for i=1:size(tt,2)
|
||||
|
||||
idxttst=find(tt>=tt(i),1);
|
||||
idxtten=find(tt<=tt(i),1,'last');
|
||||
|
||||
idx1st=find(tt1<=tt(i),1,'last');
|
||||
idx1en=find(tt1>=tt(i),1);
|
||||
if idx1st==idx1en
|
||||
sc1x(:,i)=sc1(:,idx1st);
|
||||
else
|
||||
if abs(tt1(idx1en)-tt1(idx1st))<tth
|
||||
if idxttst==idxtten
|
||||
sc1x(:,i)=(sc1(:,idx1st)+sc1(:,idx1en))/2;
|
||||
else
|
||||
idx1streal=min([idx1st,idx1en]);
|
||||
idx1enreal=max([idx1st,idx1en]);
|
||||
sc1x(:,i)=sc1(:,idx1streal+round((i-idxttst)*(idx1enreal-idx1streal)/(idxtten-idxttst)));
|
||||
end
|
||||
else
|
||||
sc1x(:,i)=(sc1(:,idx1st)*(tt1(idx1en)-tt(i))+sc1(:,idx1en)*(tt(i)-tt1(idx1st)))/...
|
||||
(tt1(idx1en)-tt1(idx1st));
|
||||
end
|
||||
end
|
||||
|
||||
idx2st=find(tt2<=tt(i),1,'last');
|
||||
idx2en=find(tt2>=tt(i),1);
|
||||
if idx2st==idx2en
|
||||
sc2x(:,i)=sc2(:,idx2st);
|
||||
else
|
||||
if abs(tt2(idx2en)-tt2(idx2st))<tth
|
||||
if idxttst==idxtten
|
||||
sc2x(:,i)=(sc2(:,idx2st)+sc2(:,idx2en))/2;
|
||||
else
|
||||
idx2streal=min([idx2st,idx2en]);
|
||||
idx2enreal=max([idx2st,idx2en]);
|
||||
sc2x(:,i)=sc2(:,idx2streal+round((i-idxttst)*(idx2enreal-idx2streal)/(idxtten-idxttst)));
|
||||
end
|
||||
else
|
||||
sc2x(:,i)=(sc2(:,idx2st)*(tt2(idx2en)-tt(i))+sc2(:,idx2en)*(tt(i)-tt2(idx2st)))/...
|
||||
(tt2(idx2en)-tt2(idx2st));
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
99
util/generateBlackStartNet.m
Normal file
99
util/generateBlackStartNet.m
Normal file
@@ -0,0 +1,99 @@
|
||||
function [SysData,maps,Ef,P0,pShare,Tm]=...
|
||||
generateBlackStartNet(SysDataBase,bsBus,bsSyn,bsInd)
|
||||
% Generate system data structure and mappings from base system data
|
||||
%
|
||||
% FUNCTION generateBlackStartNet
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
|
||||
[busBase,swBase,pvBase,pqBase,shuntBase,lineBase,indBase,zipBase,synBase,excBase,tgBase,agcBase,cacBase,clusterBase]=unfoldSysData(SysDataBase);
|
||||
busName=[];
|
||||
nbus=size(busBase,1);
|
||||
|
||||
bus=busBase(bsBus(:,1),:);
|
||||
busMap=zeros(nbus,1);
|
||||
busMap(bsBus(:,1))=1:size(bsBus,1);
|
||||
invBusMap=bsBus(:,1);
|
||||
bus(:,1)=busMap(bus(:,1));
|
||||
|
||||
pv=pvBase(busMap(pvBase(:,1))~=0,:);pv(:,1)=busMap(pv(:,1));
|
||||
pq=pqBase(busMap(pqBase(:,1))~=0,:);pq(:,1)=busMap(pq(:,1));
|
||||
sw=swBase(busMap(swBase(:,1))~=0,:);sw(:,1)=busMap(sw(:,1));
|
||||
zip=zeros(size(bus,1),12);
|
||||
zip(:,1)=bus(:,1);zip(:,2)=100;zip(:,3)=bus(:,2);zip(:,4)=60;
|
||||
zip(:,5:10)=bsBus(:,2:7);
|
||||
zip(:,12)=1;
|
||||
|
||||
shunt=zeros(0,7);
|
||||
line=zeros(0,16);
|
||||
ltc=[];
|
||||
sup=[];
|
||||
dem=[];
|
||||
|
||||
synMap=zeros(size(synBase,1),1);
|
||||
invSynMap=bsSyn(:,1);
|
||||
synMap(bsSyn(:,1))=1:length(invSynMap);
|
||||
syn=synBase(invSynMap,:);
|
||||
syn(:,1)=busMap(synBase(bsSyn(:,1),1));
|
||||
exc=excBase;if ~isempty(excBase);exc(:,1)=synMap(excBase(:,1));exc=exc(exc(:,1)~=0,:);end
|
||||
tg=tgBase;if ~isempty(tgBase);tg(:,1)=synMap(tgBase(:,1));tg=tg(tg(:,1)~=0,:);end
|
||||
Ef=bsSyn(synMap(bsSyn(:,1))~=0,2);
|
||||
P0=bsSyn(synMap(bsSyn(:,1))~=0,3);
|
||||
pShare=bsSyn(synMap(bsSyn(:,1))~=0,4);
|
||||
|
||||
indMap=zeros(size(indBase,1),1);
|
||||
if ~isempty(bsInd)
|
||||
invIndMap=bsInd(:,1);
|
||||
indMap(bsInd(:,1))=1:length(invIndMap);
|
||||
ind=indBase(invIndMap,:);
|
||||
ind(:,1)=busMap(indBase(bsInd(:,1),1));
|
||||
Tm=bsInd(indMap(bsInd(:,1))~=0,2);
|
||||
|
||||
ind(:,15)=Tm;ind(:,16)=0;ind(:,17)=0;
|
||||
else
|
||||
invIndMap=[];
|
||||
indMap=[];
|
||||
ind=indBase;
|
||||
Tm=[];
|
||||
end
|
||||
|
||||
lineMap=zeros(size(lineBase,1),1);
|
||||
invLineMap=zeros(0,1);
|
||||
|
||||
agc=agcBase(busMap(agcBase(:,1))~=0,:);
|
||||
agc(:,1)=busMap(agc(:,1));
|
||||
cac=cacBase;
|
||||
cluster=clusterBase;
|
||||
|
||||
SysData=foldSysData(bus,sw,pv,pq,shunt,line,ind,zip,syn,exc,tg,agc,cac,cluster);
|
||||
|
||||
maps.busMap=busMap;maps.invBusMap=invBusMap;
|
||||
maps.indMap=indMap;maps.invIndMap=invIndMap;
|
||||
maps.synMap=synMap;maps.invSynMap=invSynMap;
|
||||
maps.lineMap=lineMap;maps.invLineMap=invLineMap;
|
||||
|
||||
end
|
||||
53
util/horzcatTime.m
Normal file
53
util/horzcatTime.m
Normal file
@@ -0,0 +1,53 @@
|
||||
function time=horzcatTime(varargin)
|
||||
% Concatenate time sequences
|
||||
%
|
||||
% FUNCTION horzcatTime
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
% INPUT - A cell of time sequences
|
||||
%
|
||||
|
||||
nInterval=length(varargin);
|
||||
rows=zeros(nInterval,1);
|
||||
cols=zeros(nInterval,1);
|
||||
for i=1:nInterval
|
||||
rows(i)=size(varargin{i},1);
|
||||
cols(i)=size(varargin{i},2);
|
||||
end
|
||||
if max(rows)==min(rows)
|
||||
nRow=max(rows);
|
||||
time=zeros(nRow,sum(cols));
|
||||
time(:,1:cols(1))=varargin{1};
|
||||
pos=cols(1);
|
||||
for i=2:nInterval
|
||||
time(:,(pos+1):(pos+cols(i)))=varargin{i}+repmat(time(:,pos),1,cols(i));
|
||||
pos=pos+cols(i);
|
||||
end
|
||||
else
|
||||
time=[];
|
||||
end
|
||||
end
|
||||
213
util/plotCurves.m
Normal file
213
util/plotCurves.m
Normal file
@@ -0,0 +1,213 @@
|
||||
function plotCurves(figId,t,stateCurve,SysDataBase,variable,subIdx,lw,dot,fontSize,width,height,sizeRatio)
|
||||
% Plot the system state trajectories
|
||||
%
|
||||
% FUNCTION plotCurves
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
% INPUT
|
||||
% figId - ID of figure
|
||||
% t - sequence of time
|
||||
% stateCurve - sequence of system states
|
||||
% SysDataBase - system data structure
|
||||
% variable - String denoting the variable to plot
|
||||
% subIdx - Pick part of variables to plot
|
||||
% lw - line width
|
||||
% dot - line type
|
||||
% fontSize - Font size of labels
|
||||
% width - Width (pixels) of figure
|
||||
% height - Height (pixels) of figure
|
||||
% sizeRatio - If specified, the width and height are determined by a ratio of the screen size
|
||||
%
|
||||
[nState,idxs]...
|
||||
=getIndexDyn(SysDataBase);
|
||||
if nargin<6
|
||||
subIdx=[];
|
||||
end
|
||||
if nargin<7||isempty(lw)
|
||||
lw=1;
|
||||
end
|
||||
if nargin<8||isempty(dot)
|
||||
ln='-';
|
||||
else
|
||||
if dot
|
||||
ln='-o';
|
||||
else
|
||||
ln='-';
|
||||
end
|
||||
end
|
||||
if nargin<9||isempty(fontSize)
|
||||
fontSize=12;
|
||||
end
|
||||
if nargin<12||isempty(sizeRatio)
|
||||
sizeRatio=0.7;
|
||||
end
|
||||
screensize = get( 0, 'Screensize' );
|
||||
if nargin<10||isempty(width)
|
||||
width=floor(screensize(3)*sizeRatio);
|
||||
end
|
||||
if nargin<11||isempty(height)
|
||||
height=floor(screensize(4)*sizeRatio);
|
||||
end
|
||||
mksz=lw*3;
|
||||
xdata=t;
|
||||
ydata=[];
|
||||
ylbl='';
|
||||
if strcmpi(variable,'list') || strcmpi(variable,'help')
|
||||
disp('------ Variable List ------')
|
||||
disp('v:Bus voltage magnitude(pu)')
|
||||
disp('a:Bus voltage angle(rad)')
|
||||
disp('delta:Gen rotor angle(rad)')
|
||||
disp('omega:Gen rotor speed(pu)')
|
||||
disp('s:Motor slip')
|
||||
disp('eq1:Gen Eq1(pu)')
|
||||
disp('eq2:Gen Eq2(pu)')
|
||||
disp('ed1:Gen Ed1(pu)')
|
||||
disp('ed2:Gen Ed2(pu)')
|
||||
disp('psid:Gen Psid(pu)')
|
||||
disp('psiq:Gen Psiq(pu)')
|
||||
disp('pg:Gen Pg(pu)')
|
||||
disp('ef:Gen Ef(pu)')
|
||||
disp('vavrm:AVR Variable m(pu)')
|
||||
disp('vavrr:AVR Variable r(pu)')
|
||||
disp('vavrf:AVR Variable f(pu)')
|
||||
disp('vref:AVR Reference volt(pu)')
|
||||
disp('tgovg:TG Variable g(pu)')
|
||||
disp('tgovm:TG Variable m(pu)')
|
||||
disp('tmech:TG Tmech0(pu)')
|
||||
disp('f:bus frequency deviation(pu)')
|
||||
disp('dpg:AGC power')
|
||||
disp('qplt')
|
||||
disp('vg')
|
||||
disp('--------------------------')
|
||||
elseif strcmpi(variable,'v')
|
||||
if isempty(subIdx);idx=idxs.vIdx;else idx=idxs.vIdx(subIdx);end
|
||||
ydata=abs(stateCurve(idx,:));ylbl='Bus voltage magnitude(pu)';
|
||||
elseif strcmpi(variable,'a')
|
||||
if isempty(subIdx);idx=idxs.vIdx;else idx=idxs.vIdx(subIdx);end
|
||||
ydata=angle(stateCurve(idx,:));ylbl='Bus voltage angle(rad)';
|
||||
elseif strcmpi(variable,'delta')
|
||||
if isempty(subIdx);idx=idxs.deltaIdx;else idx=idxs.deltaIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen rotor angle(rad)';
|
||||
elseif strcmpi(variable,'omega')
|
||||
if isempty(subIdx);idx=idxs.omegaIdx;else idx=idxs.omegaIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen rotor speed(pu)';
|
||||
elseif strcmpi(variable,'s')
|
||||
if isempty(subIdx);idx=idxs.sIdx;else idx=idxs.sIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Motor slip';
|
||||
elseif strcmpi(variable,'eq1')
|
||||
if isempty(subIdx);idx=idxs.eq1Idx;else idx=idxs.eq1Idx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Eq1(pu)';
|
||||
elseif strcmpi(variable,'eq2')
|
||||
if isempty(subIdx);idx=idxs.eq2Idx;else idx=idxs.eq2Idx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Eq2(pu)';
|
||||
elseif strcmpi(variable,'ed1')
|
||||
if isempty(subIdx);idx=idxs.ed1Idx;else idx=idxs.ed1Idx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Ed1(pu)';
|
||||
elseif strcmpi(variable,'ed2')
|
||||
if isempty(subIdx);idx=idxs.ed2Idx;else idx=idxs.ed2Idx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Ed2(pu)';
|
||||
elseif strcmpi(variable,'psid')
|
||||
if isempty(subIdx);idx=idxs.psidIdx;else idx=idxs.psidIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Psid(pu)';
|
||||
elseif strcmpi(variable,'psiq')
|
||||
if isempty(subIdx);idx=idxs.psiqIdx;else idx=idxs.psiqIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Psiq(pu)';
|
||||
elseif strcmpi(variable,'pg')
|
||||
if isempty(subIdx);idx=idxs.pgIdx;else idx=idxs.pgIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Pg(pu)';
|
||||
elseif strcmpi(variable,'ef')
|
||||
if isempty(subIdx);idx=idxs.efIdx;else idx=idxs.efIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='Gen Ef(pu)';
|
||||
elseif strcmpi(variable,'vavrm')
|
||||
if isempty(subIdx);idx=idxs.vavrmIdx;else idx=idxs.vavrmIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='AVR Variable m(pu)';
|
||||
elseif strcmpi(variable,'vavrr')
|
||||
if isempty(subIdx);idx=idxs.vavrrIdx;else idx=idxs.vavrrIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='AVR Variable r(pu)';
|
||||
elseif strcmpi(variable,'vavrf')
|
||||
if isempty(subIdx);idx=idxs.vavrfIdx;else idx=idxs.vavrfIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='AVR Variable f(pu)';
|
||||
elseif strcmpi(variable,'vref')
|
||||
if isempty(subIdx);idx=idxs.vavrrefIdx;else idx=idxs.vavrrefIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='AVR Reference volt(pu)';
|
||||
elseif strcmpi(variable,'tgovg')
|
||||
if isempty(subIdx);idx=idxs.tgovgIdx;else idx=idxs.tgovgIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='TG Variable g(pu)';
|
||||
elseif strcmpi(variable,'tgovm')
|
||||
if isempty(subIdx);idx=idxs.tgovmIdx;else idx=idxs.tgovmIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='TG Variable m(pu)';
|
||||
elseif strcmpi(variable,'tmech')
|
||||
if isempty(subIdx);idx=idxs.tmechIdx;else idx=idxs.tmechIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='TG Tmech0(pu)';
|
||||
elseif strcmpi(variable,'f')
|
||||
if isempty(subIdx);idx=idxs.fIdx;else idx=idxs.fIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='delta f(pu)';
|
||||
elseif strcmpi(variable,'dpg')
|
||||
if isempty(subIdx);idx=idxs.dpgIdx;else idx=idxs.dpgIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='AGC delta pg(pu)';
|
||||
elseif strcmpi(variable,'qplt')
|
||||
if isempty(subIdx);idx=idxs.qpltIdx;else idx=idxs.qpltIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='qplt(pu)';
|
||||
elseif strcmpi(variable,'vg')
|
||||
if isempty(subIdx);idx=idxs.vgIdx;else idx=idxs.vgIdx(subIdx);end
|
||||
ydata=real(stateCurve(idx,:));ylbl='vg(pu)';
|
||||
end
|
||||
if ~isempty(ydata)
|
||||
if ~isempty(figId)
|
||||
p=figure(figId);
|
||||
else
|
||||
p=figure();
|
||||
end
|
||||
movegui(p,'center');
|
||||
pos=get(p,'OuterPosition');
|
||||
centerx=pos(1)+pos(3)/2;
|
||||
centery=pos(2)+pos(4)/2;
|
||||
ymin=min(min(ydata));
|
||||
ymax=max(max(ydata));
|
||||
yRange=ymax-ymin;
|
||||
if yRange<1e-3
|
||||
yRange=1e-3;
|
||||
end
|
||||
xmin=min(xdata);
|
||||
xmax=max(xdata);
|
||||
xDispRange=xmax-xmin;
|
||||
if xDispRange<1e-6
|
||||
xDispRange=1e-6;
|
||||
else
|
||||
xDispRange=0;
|
||||
end
|
||||
if length(xdata)==1
|
||||
ln='-o';
|
||||
end
|
||||
plot(xdata,ydata,ln,'LineWidth',lw,'MarkerSize',mksz);
|
||||
xlabel('Time (s)','FontSize', fontSize),...
|
||||
ylabel(ylbl,'FontSize', fontSize),...
|
||||
axis([xmin-0.05*xDispRange,xmax+0.05*xDispRange,ymin-0.05*yRange,ymax+0.05*yRange]);
|
||||
set(p,'units','pixels','OuterPosition',[floor(centerx-width/2),floor(centery-height/2),width,height]);
|
||||
end
|
||||
|
||||
end
|
||||
73
util/readSystems.m
Normal file
73
util/readSystems.m
Normal file
@@ -0,0 +1,73 @@
|
||||
function SysDataList=readSystems(sysFileList,sysDataPaths)
|
||||
% Read a series of system files and generate a series of system data
|
||||
%
|
||||
% FUNCTION readSystems
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
% INPUT
|
||||
% sysFileList - Cell of file names
|
||||
% sysDataPaths - Cell of file paths
|
||||
%
|
||||
% OUTPUT
|
||||
% SysDataList - Cell of system data
|
||||
%
|
||||
|
||||
nSys=length(sysFileList);
|
||||
homePath=pwd;
|
||||
SysDataList=cell(nSys,1);
|
||||
for iSys=1:nSys
|
||||
if ~isempty(sysDataPaths)&&length(sysDataPaths)>=iSys
|
||||
cd(sysDataPaths{iSys})
|
||||
end
|
||||
Bus.con=[];PV.con=[];PQ.con=[];SW.con=[];Line.con=[];Ltc.con=[];Supply.con=[];Demand.con=[];Shunt.con=[];
|
||||
Ind.con=[];Pl.con=[];Syn.con=[];Exc.con=[];Tg.con=[];Bus.names={};Agc.con=[];CAC.con=[];Cluster.con=[];
|
||||
|
||||
eval(sysFileList{iSys});
|
||||
if ~exist('Bus','var')||isempty(Bus)||isempty(Bus.con);busBase=zeros(0,6);else busBase=Bus.con;end
|
||||
if ~exist('PV','var')||isempty(PV)||isempty(PV.con);pvBase=zeros(0,11);else pvBase=PV.con;end
|
||||
if ~exist('PQ','var')||isempty(PQ)||isempty(PQ.con);pqBase=zeros(0,9);else pqBase=PQ.con;end
|
||||
if ~exist('SW','var')||isempty(SW)||isempty(SW.con);swBase=zeros(0,13);else swBase=SW.con;end
|
||||
if ~exist('Line','var')||isempty(Line)||isempty(Line.con);lineBase=zeros(0,16);else lineBase=Line.con;end
|
||||
if ~exist('Ltc','var')||isempty(Ltc)||isempty(Ltc.con);ltcBase=zeros(0,16);else ltcBase=Ltc.con;end
|
||||
if ~exist('Supply','var')||isempty(Supply)||isempty(Supply.con);supBase=zeros(0,20);else supBase=Supply.con;end
|
||||
if ~exist('Demand','var')||isempty(Demand)||isempty(Demand.con);demBase=zeros(0,18);else demBase=Demand.con;end
|
||||
if ~exist('Shunt','var')||isempty(Shunt)||isempty(Shunt.con);shuntBase=zeros(0,7);else shuntBase=Shunt.con;end
|
||||
if ~exist('Ind','var')||isempty(Ind)||isempty(Ind.con);indBase=zeros(0,20);else indBase=Ind.con;end
|
||||
if ~exist('Pl','var')||isempty(Pl)||isempty(Pl.con);zipBase=zeros(0,12);else zipBase=Pl.con;end
|
||||
if ~exist('Syn','var')||isempty(Syn)||isempty(Syn.con);synBase=zeros(0,26);else synBase=Syn.con;end
|
||||
if ~exist('Exc','var')||isempty(Exc)||isempty(Exc.con);excBase=zeros(0,14);else excBase=Exc.con;end
|
||||
if ~exist('Tg','var')||isempty(Tg)||isempty(Tg.con);tgBase=zeros(0,8);else tgBase=Tg.con;end
|
||||
if ~exist('Bus','var')||isempty(Bus)||isempty(Bus.names);busNameBase={};else busNameBase=Bus.names;end
|
||||
if ~exist('Agc','var')||isempty(Agc)||isempty(Agc.con);agcBase=zeros(0,4);else agcBase=Agc.con;end
|
||||
if ~exist('CAC','var')||isempty(CAC)||isempty(CAC.con);cacBase=zeros(0,10);else cacBase=CAC.con;end
|
||||
if ~exist('Cluster','var')||isempty(Cluster)||isempty(Cluster.con);clusterBase=zeros(0,10);else clusterBase=Cluster.con;end
|
||||
cd(homePath);
|
||||
|
||||
SysDataList{iSys}=foldSysData(busBase,swBase,pvBase,pqBase,shuntBase,lineBase,indBase,zipBase,synBase,excBase,tgBase,agcBase,cacBase,clusterBase);
|
||||
|
||||
end
|
||||
end
|
||||
132
util/reformatCurves.m
Normal file
132
util/reformatCurves.m
Normal file
@@ -0,0 +1,132 @@
|
||||
function [t,stateCurve]=reformatCurves(SysDataBase,tList,stateList,SysDataList,mapsList,dt)
|
||||
% Reformat the curves from raw computation results
|
||||
%
|
||||
% FUNCTION reformatCurves
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
% INPUT
|
||||
%
|
||||
% OUTPUT
|
||||
%
|
||||
|
||||
if nargin<6
|
||||
dt=[];
|
||||
end
|
||||
[nState,idxs]...
|
||||
=getIndexDyn(SysDataBase);
|
||||
[busBase,swBase,pvBase,pqBase,shuntBase,lineBase,indBase,zipBase,synBase,excBase,tgBase]=unfoldSysData(SysDataBase);
|
||||
|
||||
if isempty(dt)
|
||||
tListx=tList;
|
||||
tListx1=tList;
|
||||
else
|
||||
tListx=cell(1,length(tList));
|
||||
tListx1=cell(1,length(tList));
|
||||
residue=0.0;
|
||||
for it=1:length(tList)
|
||||
if length(tList{it})<=1
|
||||
seg=tList{it};
|
||||
tListx{it}=seg;
|
||||
tListx1{it}=seg;
|
||||
residue=residue+seg(end)-floor((residue+seg(end))/dt)*dt;
|
||||
else
|
||||
seg=((ceil((tList{it}(1)+residue)/dt)*dt):dt:(floor((tList{it}(end)+residue)/dt)*dt))-residue;
|
||||
seg=seg(seg>=0);
|
||||
if ~isempty(seg)
|
||||
if tList{it}(end)>seg(end)
|
||||
seg=[seg,tList{it}(end)];
|
||||
end
|
||||
if seg(1)>0
|
||||
seg=[0,seg];
|
||||
end
|
||||
else
|
||||
seg=[0,tList{it}(end)];
|
||||
end
|
||||
tListx{it}=seg;
|
||||
tListx1{it}=seg;
|
||||
residue=residue+seg(end)-floor((residue+seg(end))/dt)*dt;
|
||||
end
|
||||
end
|
||||
end
|
||||
t=horzcatTime(tListx1{:});
|
||||
stateCurve=nan(nState,length(t));
|
||||
startIdx=1;
|
||||
|
||||
synToTg=zeros(size(synBase,1),1);
|
||||
synToTg(tgBase(:,1))=1:size(tgBase,1);
|
||||
synToExc=zeros(size(synBase,1),1);
|
||||
synToExc(excBase(:,1))=1:size(excBase,1);
|
||||
|
||||
for seq=1:length(tListx)
|
||||
if isempty(dt)
|
||||
state=stateList{seq};
|
||||
else
|
||||
if length(tList{seq})<=1
|
||||
state=stateList{seq};
|
||||
else
|
||||
state=interp1(tList{seq},stateList{seq}',tListx{seq})';
|
||||
end
|
||||
end
|
||||
SysData=SysDataList{seq};
|
||||
busMap=mapsList{seq}.busMap;
|
||||
invBusMap=mapsList{seq}.invBusMap;
|
||||
indMap=mapsList{seq}.indMap;
|
||||
invIndMap=mapsList{seq}.invIndMap;
|
||||
synMap=mapsList{seq}.synMap;
|
||||
invSynMap=mapsList{seq}.invSynMap;
|
||||
|
||||
[bus,sw,pv,pq,shunt,line,ind,zip,syn,exc,tg]=unfoldSysData(SysData);
|
||||
[V,Q,s,d,w,eq1,eq2,ed1,ed2,psid,psiq,Pm,Ef,Vavrm,Vavrr,Vavrf,Vavrref,tgovg,tgovm,tgovmech,f,dpg,qplt,vg]=...
|
||||
unfoldX(state,SysData);
|
||||
|
||||
iTseq=startIdx:(startIdx+length(tListx{seq})-1);
|
||||
stateCurve(idxs.vIdx(invBusMap),iTseq)=V;
|
||||
stateCurve(idxs.qIdx(invBusMap),iTseq)=Q;
|
||||
stateCurve(idxs.sIdx(invIndMap),iTseq)=s;
|
||||
stateCurve(idxs.deltaIdx(invSynMap),iTseq)=d;
|
||||
stateCurve(idxs.omegaIdx(invSynMap),iTseq)=w;
|
||||
stateCurve(idxs.eq1Idx(invSynMap),iTseq)=eq1;
|
||||
stateCurve(idxs.eq2Idx(invSynMap),iTseq)=eq2;
|
||||
stateCurve(idxs.ed1Idx(invSynMap),iTseq)=ed1;
|
||||
stateCurve(idxs.ed2Idx(invSynMap),iTseq)=ed2;
|
||||
stateCurve(idxs.psidIdx(invSynMap),iTseq)=psid;
|
||||
stateCurve(idxs.psiqIdx(invSynMap),iTseq)=psiq;
|
||||
stateCurve(idxs.pgIdx(invSynMap),iTseq)=Pm;
|
||||
stateCurve(idxs.efIdx(invSynMap),iTseq)=Ef;
|
||||
stateCurve(idxs.vavrmIdx(synToExc(invSynMap(exc(:,1)))),iTseq)=Vavrm;
|
||||
stateCurve(idxs.vavrrIdx(synToExc(invSynMap(exc(:,1)))),iTseq)=Vavrr;
|
||||
stateCurve(idxs.vavrfIdx(synToExc(invSynMap(exc(:,1)))),iTseq)=Vavrf;
|
||||
stateCurve(idxs.vavrrefIdx(synToExc(invSynMap(exc(:,1)))),iTseq)=Vavrref;
|
||||
stateCurve(idxs.tgovgIdx(synToTg(invSynMap(tg(:,1)))),iTseq)=tgovg;
|
||||
stateCurve(idxs.tgovmIdx(synToTg(invSynMap(tg(:,1)))),iTseq)=tgovm;
|
||||
stateCurve(idxs.tmechIdx(synToTg(invSynMap(tg(:,1)))),iTseq)=tgovmech;
|
||||
stateCurve(idxs.fIdx(invBusMap),iTseq)=f;
|
||||
stateCurve(idxs.dpgIdx(invBusMap),iTseq)=dpg;
|
||||
|
||||
startIdx=startIdx+length(tListx{seq});
|
||||
end
|
||||
end
|
||||
64
util/setOptions.m
Normal file
64
util/setOptions.m
Normal file
@@ -0,0 +1,64 @@
|
||||
function options=setOptions(varargin)
|
||||
% General function for setting options in key-value pairs
|
||||
%
|
||||
% FUNCTION setOptions
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
%
|
||||
|
||||
options=[];
|
||||
if nargin<1
|
||||
options=[];
|
||||
else
|
||||
idx=1;
|
||||
if isstruct(varargin{1})
|
||||
options=varargin{1};
|
||||
idx=idx+1;
|
||||
elseif ~ischar(varargin{1})
|
||||
idx=idx+1;
|
||||
end
|
||||
while idx<=nargin
|
||||
opt=varargin{idx};
|
||||
idx=idx+1;
|
||||
if idx<=nargin
|
||||
val=varargin{idx};
|
||||
idx=idx+1;
|
||||
if ischar(opt)
|
||||
try
|
||||
options.(opt)=val;
|
||||
catch ME
|
||||
disp(['setOptions() Argument ',num2str(idx-2),' & ',num2str(idx-1),': ',ME.message]);
|
||||
end
|
||||
else
|
||||
disp(['setOptions() Argument ',num2str(idx-2),': option name should be a string. Check input arguments.']);
|
||||
end
|
||||
else
|
||||
disp(['setOptions() Argument ',num2str(idx-1),': option and value should match in pairs. Check input arguments.']);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
254
util/writeEventList.m
Normal file
254
util/writeEventList.m
Normal file
@@ -0,0 +1,254 @@
|
||||
function writeEventList(outFileName,...
|
||||
nlvl,taylorN,alphaTol,diffTol,diffTolMax,method,diffTolCtrl,eventList,...
|
||||
bsSyn,bsBus,bsInd,Efstd,evtLine,evtLineSpec,evtZip,evtZipSpec,evtZipSpec2,evtInd,evtIndSpec,evtSyn,evtSynSpec,evtFault,evtFaultSpec,...
|
||||
evtDyn,evtDynPQ,evtDynPV,evtDynInd,evtDynZip,evtDynSh,evtDynZipRamp,evtDynTmech,evtDynPm,evtDynEf,evtDynVref,evtDynEq1,intervalEndTimes)
|
||||
% function for writing event definitions
|
||||
%
|
||||
% FUNCTION writeRestorationPlan
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
|
||||
EvtType=getSimEventType();
|
||||
MethodType=getSimMethodType();
|
||||
SimSet=getSimSettingDefault();
|
||||
|
||||
fid = fopen(outFileName, 'w');
|
||||
|
||||
fprintf(fid,'%% Simulation data\r\n');
|
||||
fprintf(fid,'nlvl =%3d;\r\n',nlvl);
|
||||
fprintf(fid,'taylorN =%3d;\r\n',taylorN);
|
||||
fprintf(fid,'alphaTol =%.4e;\r\n',alphaTol);
|
||||
fprintf(fid,'diffTol =%.4e;\r\n',diffTol);
|
||||
fprintf(fid,'diffTolMax =%.4e;\r\n',diffTolMax);
|
||||
fprintf(fid,'method =%2d;\r\n',method);
|
||||
fprintf(fid,'diffTolCtrl =%.4e;\r\n',diffTolCtrl);
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% evtId, startTime, endTime, type, num, method, dt\r\n');
|
||||
fprintf(fid,'%% Type:\r\n');
|
||||
fprintf(fid,'%% %3d: Black start / Full start (steady state)\r\n',EvtType.START);
|
||||
fprintf(fid,'%% %3d: Add line\r\n',EvtType.ADD_LINE);
|
||||
fprintf(fid,'%% %3d: Add static load\r\n',EvtType.ADD_LOAD);
|
||||
fprintf(fid,'%% %3d: Add Motor load\r\n',EvtType.ADD_IND);
|
||||
fprintf(fid,'%% %3d: Add syn gen\r\n',EvtType.ADD_SYN);
|
||||
fprintf(fid,'%% %3d: Dyn simulation\r\n',EvtType.DYN_SIM);
|
||||
fprintf(fid,'%% %3d: Fault\r\n',EvtType.FAULT);
|
||||
fprintf(fid,'%% %3d: Cut line\r\n',EvtType.CUT_LINE);
|
||||
fprintf(fid,'%% %3d: Cut static load\r\n',EvtType.CUT_LOAD);
|
||||
fprintf(fid,'%% %3d: Cut Motor load\r\n',EvtType.CUT_IND);
|
||||
fprintf(fid,'%% %3d: Cut syn gen\r\n',EvtType.CUT_SYN);
|
||||
fprintf(fid,'%% %3d: End of simulation\r\n',EvtType.END);
|
||||
fprintf(fid,'%% Method: X.Y\r\n');
|
||||
fprintf(fid,'%% Method X: Differential eq. 0:HE, 1:Modified Euler, 2:RK-4(not active).\r\n');
|
||||
fprintf(fid,'%% Method Y: Algebraic eq. 0:HE, 1:N-R.\r\n');
|
||||
|
||||
fprintf(fid,'eventList=[...\r\n');
|
||||
fprintf(fid,'%6d %9.3f %9.3f %6d %6d %3.1f %9.3f\r\n',eventList');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Blackstart data\r\n');
|
||||
fprintf(fid,'%% synId, Ef, Pm, pShare\r\n');
|
||||
fprintf(fid,'bsSyn=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %9.6f\r\n',bsSyn');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% busId, Pz, Pi, Ps, Qz, Qi, Qse\r\n');
|
||||
fprintf(fid,'bsBus=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\r\n',bsBus');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% motorId, Tm\r\n');
|
||||
fprintf(fid,'bsInd=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f \r\n',bsInd');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Plain start data\r\n');
|
||||
fprintf(fid,'Efstd=%9.6f;\r\n',Efstd);
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Line event data\r\n');
|
||||
fprintf(fid,'%% evtId start end\r\n');
|
||||
fprintf(fid,'evtLine=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d\r\n',evtLine');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Line events spec\r\n');
|
||||
fprintf(fid,'%% lineId evtType(0-add, 1-trip, 2-fault, 3-resume) pos r-fault x-fault\r\n');
|
||||
fprintf(fid,'evtLineSpec=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d %9.6f %9.6f %% %6d\r\n',[evtLineSpec,(1:size(evtLineSpec,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Static load event data\r\n');
|
||||
fprintf(fid,'%% evtId start end\r\n');
|
||||
fprintf(fid,'evtZip=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d %6d\r\n',evtZip');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% zip event specs\r\n');
|
||||
fprintf(fid,'%% zipId type(0-add, 1-trip)\r\n');
|
||||
fprintf(fid,'evtZipSpec=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %% %6d\r\n',[evtZipSpec,(1:size(evtZipSpec,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% zip event specs 2\r\n');
|
||||
fprintf(fid,'%% Direct add\r\n');
|
||||
fprintf(fid,'evtZipSpec2=[...\r\n');
|
||||
fprintf(fid,'%% Bus S V f g Ip P b Iq Q\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %6d %6d %% %6d\r\n',[evtZipSpec2,(1:size(evtZipSpec2,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Motor load event data\r\n');
|
||||
fprintf(fid,'%% evtId start end\r\n');
|
||||
fprintf(fid,'evtInd=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d\r\n',evtInd');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% ind event specs\r\n');
|
||||
fprintf(fid,'%% indId type(0-add, 1-adjust, 2-trip) Tm s0\r\n');
|
||||
fprintf(fid,'evtIndSpec=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %9.6f %9.6f %% %6d\r\n',[evtIndSpec,(1:size(evtIndSpec,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Syncronous generator event data\r\n');
|
||||
fprintf(fid,'%% evtId start end\r\n');
|
||||
fprintf(fid,'evtSyn=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d\r\n',evtSyn');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% syn event specs\r\n');
|
||||
fprintf(fid,'%% synId type(0-add, 1-adjust, 2-trip) d0 Pm0 Ef0\r\n');
|
||||
fprintf(fid,'evtSynSpec=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %9.6f %9.6f %9.6f %% %6d\r\n',[evtSynSpec,(1:size(evtSynSpec,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Fault event data\r\n');
|
||||
fprintf(fid,'evtFault=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d\r\n',evtFault');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'evtFaultSpec=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %9.6f %6d %% %6d\r\n',[evtFaultSpec,(1:size(evtFaultSpec,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Dynamic simulation event data\r\n');
|
||||
fprintf(fid,'%% evtId 2pqSt pqEnd 4pvSt pvEnd 6indSt indEnd 8zipSt zipEnd 10shSt shEnd\r\n');
|
||||
fprintf(fid,'%% 12zipRampSt zipRampEnd 14TmechSt TmechEnd 16PmSt PmEnd 18EfSt EfEnd \r\n');
|
||||
fprintf(fid,'%% 20VrefSt VrefEnd 22Eq1St Eq1End\r\n');
|
||||
fprintf(fid,'%% 2 4 6 8 10 12 14 16 18 20 22\r\n');
|
||||
fprintf(fid,'evtDyn=[...\r\n');
|
||||
fprintf(fid,'%6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d \r\n',evtDyn');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% busId pIncr qIncr\r\n');
|
||||
fprintf(fid,'evtDynPQ=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %% %6d\r\n',[evtDynPQ,(1:size(evtDynPQ,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% busId pIncr\r\n');
|
||||
fprintf(fid,'evtDynPV=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynPV,(1:size(evtDynPV,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% indId TmRamp\r\n');
|
||||
fprintf(fid,'evtDynInd=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynInd,(1:size(evtDynInd,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% busId zipRamp\r\n');
|
||||
fprintf(fid,'evtDynZip=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynZip,(1:size(evtDynZip,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% busId shRamp\r\n');
|
||||
fprintf(fid,'evtDynSh=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynSh,(1:size(evtDynSh,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% Bus S V f g Ip P b Iq Q\r\n');
|
||||
fprintf(fid,'evtDynZipRamp=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f %6d %6d %% %6d\r\n',[evtDynZipRamp,(1:size(evtDynZipRamp,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% synId TmechRamp\r\n');
|
||||
fprintf(fid,'evtDynTmech=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynTmech,(1:size(evtDynTmech,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% synId PmRamp\r\n');
|
||||
fprintf(fid,'evtDynPm=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynPm,(1:size(evtDynPm,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% synId Ramp\r\n');
|
||||
fprintf(fid,'evtDynEf=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynEf,(1:size(evtDynEf,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% synId Ramp\r\n');
|
||||
fprintf(fid,'evtDynVref=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynVref,(1:size(evtDynVref,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'%% synId Ramp\r\n');
|
||||
fprintf(fid,'evtDynEq1=[...\r\n');
|
||||
fprintf(fid,'%6d %9.6f %% %6d\r\n',[evtDynEq1,(1:size(evtDynEq1,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fprintf(fid,'intervalEndTimes=[...\r\n');
|
||||
fprintf(fid,'%9.4f %% %6d\r\n',[intervalEndTimes,(1:size(intervalEndTimes,1))']');
|
||||
fprintf(fid,'];\r\n');
|
||||
fprintf(fid,'\r\n');
|
||||
|
||||
fclose(fid);
|
||||
end
|
||||
166
util/writePsatFile.m
Normal file
166
util/writePsatFile.m
Normal file
@@ -0,0 +1,166 @@
|
||||
function writePsatFile(psatfilename,baseMVA, bus, gen, branch,area,dcline, gencost,namebus)
|
||||
% Write PSAT data file from Matpower data
|
||||
%
|
||||
% FUNCTION writePsatFile
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
|
||||
%
|
||||
% ----- write data in MATPOWER format -----
|
||||
fid = fopen(psatfilename, 'w');
|
||||
|
||||
% print out function title, baseMVA, etc.
|
||||
temp = psatfilename(1:length(psatfilename)-2);
|
||||
|
||||
% process gen
|
||||
nbus=size(bus,1);
|
||||
genAccum=zeros(nbus,size(gen,2));
|
||||
for i=2:size(gen,2)
|
||||
genAccum(:,i)=accumarray(gen(:,1),gen(:,i),[nbus,1]);
|
||||
end
|
||||
genAccum(:,1)=(1:nbus)';
|
||||
genCount=accumarray(gen(:,1),ones(size(gen,1),1),[nbus,1]);
|
||||
genTag=zeros(nbus,1);
|
||||
genTag(gen(:,1))=1;
|
||||
genAccumx=genAccum(genTag==1,:);
|
||||
genCountx=genCount(genTag==1);
|
||||
genAccumx(:,6)=genAccumx(:,6)./genCountx;
|
||||
genAccumx(:,8)=genAccumx(:,8)./genCountx;
|
||||
genAccumx(genAccumx(:,8)>0,8)=1;
|
||||
gen=genAccumx;
|
||||
|
||||
newToOld=bus(:,1);
|
||||
oldToNew=zeros(max(newToOld),1);
|
||||
oldToNew(newToOld)=1:nbus;
|
||||
|
||||
bus(:,1)=oldToNew(bus(:,1));
|
||||
gen(:,1)=oldToNew(gen(:,1));
|
||||
branch(:,1)=oldToNew(branch(:,1));
|
||||
branch(:,2)=oldToNew(branch(:,2));
|
||||
|
||||
% print out bus matrix [OK]
|
||||
fprintf(fid, '\n%%bus data');
|
||||
fprintf(fid, '\nBus.con = [...');
|
||||
for i = 1:size(bus, 1)
|
||||
% bus baseKv v theta area region
|
||||
fprintf(fid, '\n%4i %14.10g %14.10g %14.10g %4i %4i', bus(i,[1,10,8,9,7,11]));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out SW matrix [OK]
|
||||
sw=bus((bus(:,2)==3),:);
|
||||
swg=gen(gen(:,1)==sw(1),:);
|
||||
fprintf(fid, '\n%%SW data');
|
||||
fprintf(fid, '\nSW.con = [...');
|
||||
% bus Sn Vn v theta qmax qmin vmax vmin pg_guess loss_part ref u
|
||||
fprintf(fid, '\n%4i %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %4i %4i', [sw(1),baseMVA,sw(10),swg([6,4,5]),sw([12,13]),0.0,1,1,swg(8)]);
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out PV matrix [OK]
|
||||
fprintf(fid, '\n%%PV data');
|
||||
fprintf(fid, '\nPV.con = [...');
|
||||
for i = 1:size(gen, 1)
|
||||
% bus Sn Vn Pg V qmax qmin vmax vmin loss_part u
|
||||
if gen(i,1)~=sw(1)
|
||||
fprintf(fid, '\n%4i %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %4i', [gen(i,1),baseMVA,bus(gen(i,1),10),gen(i,2)/baseMVA,gen(i,6),gen(i,[4,5])/baseMVA,1.05,0.95,1,gen(i,8)]);
|
||||
end
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out PQ matrix [OK]
|
||||
fprintf(fid, '\n%%PQ data');
|
||||
fprintf(fid, '\nPQ.con = [...');
|
||||
for i = 1:size(bus, 1)
|
||||
% bus Sn Vn P Q vmax vmin z u
|
||||
if bus(i,1)~=sw(1)%&&isempty(find(gen(:,1)==bus(i,1), 1))
|
||||
fprintf(fid, '\n%4i %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %4i %4i', [bus(i,1),baseMVA,bus(i,10),bus(i,[3,4])/baseMVA,bus(i,[12,13]),1,1]);
|
||||
end
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
|
||||
% print out Shunt matrix [OK]
|
||||
fprintf(fid, '\n%%Shunt data');
|
||||
fprintf(fid, '\nShunt.con = [...');
|
||||
for i = 1:size(bus, 1)
|
||||
% bus Sn fn Gs Bs z u
|
||||
if bus(i,5)~=0||bus(i,6)~=0
|
||||
fprintf(fid, '\n%4i %14.10g %14.10g %14.10g %14.10g %4i %4i', [bus(i,1),baseMVA,bus(i,10),60.0,bus(i,[5,6])/baseMVA,1]);
|
||||
end
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out Branch matrix [OK]
|
||||
fprintf(fid, '\n%%Line Data');
|
||||
fprintf(fid, '\nLine.con = [...');
|
||||
for i = 1:size(branch, 1)
|
||||
% f t Sn Vn fn ln r x b k phi Im Pm Sm u
|
||||
bi=branch(i,1);
|
||||
bj=branch(i,2);
|
||||
kv=bus(bi,10);
|
||||
if branch(i,9)~=0
|
||||
bratio=bus(bi,10)/bus(bj,10);
|
||||
else
|
||||
bratio=0;
|
||||
end
|
||||
fprintf(fid, '\n%4i %4i %14.10g %14.10g %14.10g %4i %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %4i', [branch(i,[1,2]),baseMVA,kv,60.0,0.0,bratio,branch(i,[3,4,5,9,10]),branch(i,[6,6,6])/baseMVA,branch(i,11)]);
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out Supply matrix [OK]
|
||||
fprintf(fid, '\n%%Supply Data');
|
||||
fprintf(fid, '\nSupply.con = [...');
|
||||
for i = 1:size(gen, 1)
|
||||
% bus Sn * Pmax Pmin * * * * * * * * *
|
||||
fprintf(fid, '\n%4i %14.10g %4i %14.10g %14.10g %4i %4i %14.10g %14.10g %4i %4i %4i %4i %4i %4i %14.10g %14.10g %4i', [gen(i,1),baseMVA,0,gen(i,9)/baseMVA, 0.0 , 0, 0, 9.0, 0.1, 0, 0, 0, 0, 0, 1,gen(i,[4,5])/baseMVA,gen(i,8)]);
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out hvdc matrix
|
||||
% if ~isempty(dcline)
|
||||
fprintf(fid, '\n%%fbus tbus Sn Vrn Vin fn V I Xtr Xti mr mi Ki Kp Rdc Ldc aMax aMin gaMax gaMin yRmax yRmin yiMax yiMin ctype io po vo u');
|
||||
fprintf(fid, '\nHvdc.con = [...');
|
||||
for i = 1:size(dcline, 1)
|
||||
fprintf(fid, '\n%4i %4i %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %14.10g %4i',...
|
||||
[dcline(i, [1,2]),baseMVA,dcline(i,[8,9])*baseMVA,60.0,dcline(i,8)*baseMVA,dcline(i,4)/(dcline(i,8)*baseMVA),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,dcline(i,[11,10])/(dcline(i,8)*baseMVA),dcline(i,[11,10])/(dcline(i,8)*baseMVA),1,1,1,1,1]);
|
||||
end;
|
||||
fprintf(fid, '\n]; \n');
|
||||
% end
|
||||
|
||||
% bus name
|
||||
fprintf(fid, 'Bus.names = {...\n ');
|
||||
for i = 1:length(namebus(:,1))-1
|
||||
tmpName = namebus{i};
|
||||
newName = strrep(tmpName,'''',' ');%loadcase
|
||||
fprintf(fid, '''%s '';',newName);
|
||||
if rem(i,5) == 0; fprintf(fid,'\n '); end
|
||||
end
|
||||
fprintf(fid, '''%s ''};\n',namebus{end});
|
||||
|
||||
fclose(fid);
|
||||
|
||||
end
|
||||
200
util/writePsatFilefromPsat.m
Normal file
200
util/writePsatFilefromPsat.m
Normal file
@@ -0,0 +1,200 @@
|
||||
function writePsatFilefromPsat(psatfilename,bus,sw,pv,pq,shunt,line,sup,busnames,actions,zip,ind,syn,exc,tg)
|
||||
% function for writing PSAT format data
|
||||
%
|
||||
% FUNCTION yr_writePsatFilefromPsat
|
||||
%
|
||||
% Author: Rui Yao <ruiyao@ieee.org>
|
||||
%
|
||||
% Copyright (C) 2021, UChicago Argonne, LLC. All rights reserved.
|
||||
%
|
||||
% OPEN SOURCE LICENSE
|
||||
%
|
||||
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
%
|
||||
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
% 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
%
|
||||
%
|
||||
% ******************************************************************************************************
|
||||
% DISCLAIMER
|
||||
%
|
||||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
% ***************************************************************************************************
|
||||
%
|
||||
|
||||
|
||||
%
|
||||
% ----- write data in MATPOWER format -----
|
||||
fid = fopen(psatfilename, 'w');
|
||||
|
||||
% print out function title, baseMVA, etc.
|
||||
temp = psatfilename(1:length(psatfilename)-2);
|
||||
|
||||
% print out bus matrix [OK]
|
||||
fprintf(fid, '\n%%bus data: %d',size(bus, 1));
|
||||
fprintf(fid, '\nBus.con = [...');
|
||||
for i = 1:size(bus, 1)
|
||||
% bus baseKv v theta area region
|
||||
fprintf(fid, '\n%6i %10.4f %10.4f %10.4f %6i %6i', bus(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out SW matrix [OK]
|
||||
fprintf(fid, '\n%%SW data: %d',size(sw,1));
|
||||
fprintf(fid, '\nSW.con = [...');
|
||||
for i = 1:size(sw,1)
|
||||
% bus Sn Vn v theta qmax qmin vmax vmin pg_guess loss_part ref u
|
||||
fprintf(fid, '\n%6i %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %6i %6i', sw(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out PV matrix [OK]
|
||||
fprintf(fid, '\n%%PV data: %d',size(pv, 1));
|
||||
fprintf(fid, '\nPV.con = [...');
|
||||
for i = 1:size(pv, 1)
|
||||
% bus Sn Vn Pg V qmax qmin vmax vmin loss_part u
|
||||
fprintf(fid, '\n%6i %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %6i', pv(i,:));
|
||||
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out PQ matrix [OK]
|
||||
fprintf(fid, '\n%%PQ data: %d',size(pq, 1));
|
||||
fprintf(fid, '\nPQ.con = [...');
|
||||
for i = 1:size(pq, 1)
|
||||
% bus Sn Vn P Q vmax vmin z u
|
||||
fprintf(fid, '\n%6i %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %6i %6i', pq(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
|
||||
% print out Shunt matrix [OK]
|
||||
fprintf(fid, '\n%%Shunt data: %d',size(shunt, 1));
|
||||
fprintf(fid, '\nShunt.con = [...');
|
||||
for i = 1:size(shunt, 1)
|
||||
% bus Sn fn Gs Bs z u
|
||||
fprintf(fid, '\n%6i %10.4f %10.4f %10.4f %10.4f %10.4f %6i', shunt(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out Branch matrix [OK]
|
||||
fprintf(fid, '\n%%Line Data: %d',size(line, 1));
|
||||
fprintf(fid, '\nLine.con = [...');
|
||||
for i = 1:size(line, 1)
|
||||
% f t Sn Vn fn ln r x b k phi Im Pm Sm u
|
||||
fprintf(fid, '\n%6d %6d %9.5f %9.5f %9.5f %6d %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %6d', line(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
|
||||
% print out Supply matrix [OK]
|
||||
if ~isempty(sup)
|
||||
fprintf(fid, '\n%%Supply Data: %d',size(sup, 1));
|
||||
fprintf(fid, '\nSupply.con = [...');
|
||||
for i = 1:size(sup, 1)
|
||||
% bus Sn * Pmax Pmin * * * * * * * * *
|
||||
fprintf(fid, '\n%6d %10.4f %10.4f %10.4f %10.4f %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %10.4f %10.4f %6d %6d %6d', sup(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
end
|
||||
|
||||
fprintf(fid, '\nHvdc.con = [];\n\n');
|
||||
|
||||
% print out hvdc matrix
|
||||
% if ~isempty(dcline)
|
||||
% fprintf(fid, '\n%%fbus tbus Sn Vrn Vin fn V I Xtr Xti mr mi Ki Kp Rdc Ldc aMax aMin gaMax gaMin yRmax yRmin yiMax yiMin ctype io po vo u');
|
||||
% fprintf(fid, '\nHvdc.con = [...');
|
||||
% for i = 1:size(dcline, 1)
|
||||
% fprintf(fid, '\n%6d %6d %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %6d',...
|
||||
% [dcline(i, [1,2]),baseMVA,dcline(i,[8,9])*baseMVA,60.0,dcline(i,8)*baseMVA,dcline(i,4)/(dcline(i,8)*baseMVA),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,dcline(i,[11,10])/(dcline(i,8)*baseMVA),dcline(i,[11,10])/(dcline(i,8)*baseMVA),1,1,1,1,1]);
|
||||
% end;
|
||||
% fprintf(fid, '\n]; \n');
|
||||
% end
|
||||
|
||||
% bus name
|
||||
fprintf(fid, 'Bus.names = {...\n ');
|
||||
if ~isempty(busnames)
|
||||
for i = 1:length(busnames(:,1))-1
|
||||
tmpName = busnames{i};
|
||||
newName = strrep(tmpName,'''',' ');%loadcase
|
||||
fprintf(fid, '''%s '';',newName);
|
||||
if rem(i,5) == 0; fprintf(fid,'\n '); end
|
||||
end
|
||||
fprintf(fid, '''%s ''',busnames{end});
|
||||
end
|
||||
fprintf(fid, '};\n');
|
||||
|
||||
if nargin>=14&&~isempty(actions)
|
||||
fprintf(fid, '\n%%Manual actions for testing');
|
||||
fprintf(fid, '\naction = [...');
|
||||
for i = 1:size(actions, 1)
|
||||
% bus Sn * Pmax Pmin * * * * * * * * *
|
||||
fprintf(fid, '\n%6d %6d %10.4f %6d', actions(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
end
|
||||
|
||||
if nargin>=15&&~isempty(zip)
|
||||
fprintf(fid, '\n%%ZIP Data: %d',size(zip, 1));
|
||||
fprintf(fid, '\nPl.con = [...');
|
||||
for i = 1:size(zip, 1)
|
||||
fprintf(fid, '\n%6d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %2u %2u', zip(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
else
|
||||
fprintf(fid, '\nPl.con = [];\n');
|
||||
end
|
||||
|
||||
if nargin>=16&&~isempty(ind)
|
||||
fprintf(fid, '\n%%Induction motor Data: %d',size(ind, 1));
|
||||
fprintf(fid, '\nInd.con = [...');
|
||||
for i = 1:size(ind, 1)
|
||||
fprintf(fid, '\n%6d %8.4g %8.4g %8.4g %6d %6d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %2d %2d', ind(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
else
|
||||
fprintf(fid, '\nInd.con = [];\n');
|
||||
end
|
||||
|
||||
if nargin>=17&&~isempty(syn)
|
||||
fprintf(fid, '\n%%Synchronous machine Data: %d',size(syn, 1));
|
||||
fprintf(fid, '\nSyn.con = [...');
|
||||
for i = 1:size(syn, 1)
|
||||
fprintf(fid, '\n%6d %8.4g %8.4g %8.4g %6d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %6d %2u', syn(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
else
|
||||
fprintf(fid, '\nSyn.con = [];\n');
|
||||
end
|
||||
|
||||
if nargin>=18&&~isempty(exc)
|
||||
fprintf(fid, '\n%%Exciter Data: %d',size(exc, 1));
|
||||
fprintf(fid, '\nExc.con = [...');
|
||||
for i = 1:size(exc, 1)
|
||||
fprintf(fid, '\n%6d %6d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %2u', exc(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
else
|
||||
fprintf(fid, '\nExc.con = [];\n');
|
||||
end
|
||||
|
||||
if nargin>=19&&~isempty(tg)
|
||||
fprintf(fid, '\n%%Turbine governor Data: %d',size(tg, 1));
|
||||
fprintf(fid, '\nTg.con = [...');
|
||||
for i = 1:size(tg, 1)
|
||||
fprintf(fid, '\n%6d %6d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %2u', tg(i,:));
|
||||
end
|
||||
fprintf(fid, '\n];\n');
|
||||
else
|
||||
fprintf(fid, '\nTg.con = [];\n');
|
||||
end
|
||||
|
||||
fclose(fid);
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user