implement DT solvers

pull/6/head
Yang Liu 2 years ago
parent aac199550c
commit a2c73763da

@ -0,0 +1,69 @@
function [LTE,LTE2,LTE3] = Cal_locl_er(x_ori,k,h)
% Calculation of local error
%
% FUNCTION Cal_locl_er
%
% Author: Kaiyang Huang <khuang@anl.gov>
%
% Copyright (C) 2023, 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
% x_ori - Initial system state
% xNew - Updated system state (algebraic variables to be solved)
% SysDataNew - (optional) updated system data
%
% OUTPUT
% Vx, Wx, Qx, fx - Last HE coefficients of algebraic variables
% xx - Solved updated system state
% finalAlpha - The ending length of this segment of simulation
% alphas - Record of alphas
% diffRec - A list of errors
%
x = x_ori(:,k-3:k);
Xh = x.*h.^(k-4:k-1);
x_new = polyvalVec(x_ori,h);
eta = 0.001;
infcof = max(abs(Xh(:,end))./(abs(x_new)+eta));
trc = infcof^(1/k);
LTE = infcof/(1-trc);
LTE3 = max(abs(Xh(:,end-1)./(x_new+eta)));
% relative error used to change order
e1 = abs(Xh(:,end-1)./Xh(:,end));
e2 = abs(Xh(:,end-2)./Xh(:,end));
e3 = abs(Xh(:,end-3)./Xh(:,end-1));
% delete nan induced by zero/zero
f1 = find(Xh(:,end)==0);
f2 = find(Xh(:,end-1)==0);
f2 = f2(:);
e1(f1) = 0;
e2(f1) = 0;
e3(f2) = 0;
LTE2 = infcof/min([norm(e1,Inf), sqrt(norm(e2,Inf)), sqrt(norm(e3,Inf))]);
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,143 @@
function [outputArg1,outputArg2,outputArg3] = VSOO(LTE,LTE2,LTE3,SimData,h,ratio_b4)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
tol = 10^-4;
theta_max = 2;
Kmax = 30;
Kmin = 10;
p = 1;
fac1 = 1;
fac2 = 1;
hmax = SimData.maxAlpha;
hmin = 1*SimData.dAlpha;
K = SimData.nlvl;
ratio = LTE/h;
K_I = 0.03/K;
K_p = 0.04/K;
pf1 = 1;
pf2 = 0;
pf3 = 0;
if isnan(ratio_b4)
else
theta = ((tol/ratio)^(K_I))*((ratio_b4/ratio)^(K_p));
Lin = (pf1*(K+p)^2+pf2*(K+p)+pf3)/(pf1*(K)^2+pf2*(K)+pf3);
Lde = (pf1*(K-p)^2+pf2*(K-p)+pf3)/(pf1*(K)^2+pf2*(K)+pf3);
trc_in =(LTE2)/(1-LTE2^((K+p)));
trc_de= (LTE3)/(1-LTE3^((K-p)));
tol_in = tol;
tol_de = tol;
theta_in =0.9*(h*tol_in/trc_in)^(1/(K+p));
theta_de =0.9*(h*tol_de/trc_de)^(1/(K-p));
if theta> theta_max
h_can = theta_max*h;
else
h_can = theta*h;
end
if h_can > hmax
h_can = hmax;
elseif h < hmin
h_can = hmin;
end
if theta_in> theta_max
theta_in = theta_max;
end
if theta_de> theta_max
theta_de = theta_max;
end
if h*theta_in > hmax
h_inp = hmax;
elseif h*theta_in < hmin
h_inp = hmin;
else
h_inp = h*theta_in;
end
if h*theta_de > hmax
h_dep = hmax;
elseif h*theta_de < hmin
h_dep = hmin;
else
h_dep = h*theta_de;
end
if (Lde<fac2*(h_dep./h_can) &&(h<= h_can||(h==hmin&&KK(1,ite+1)>=K)))&&((h>= h_can||(h==hmax&&KK(1,ite+1)<=K))&&Lin <fac1*(h_inp./h_can))
% check which one is better
cri1 = h_inp/(pf1*(K+p)^2+pf2*(K+p)+pf3);
cri2 = h_can/(pf1*K^2+pf2*K+pf3);
cri3 = h_dep/(pf1*(K-p)^2+pf2*(K-p)+pf3);
od_stratg=[cri1 cri2 cri3;
K+p K K-p
theta_in theta theta_de
tol_in tol tol_de];
[~,opi] = max(od_stratg(1,:));
K = od_stratg(2,opi);
theta = od_stratg(3,opi);
tol = od_stratg(4,opi);
elseif Lde<fac2*(h_dep./h_can) &&(h<= h_can||(h_can==hmin))
K=K-p;
theta =theta_de;
tol = tol_de;
elseif (h>= h_can||(h_can==hmax))&&Lin <fac1*(h_inp./h_can)
K=K+p;
theta =theta_in;
tol = tol_in;
end
% cri1 = h_inp/(pf1*(K+p)^2+pf2*(K+p)+pf3);
% cri2 = h_can/(pf1*K^2+pf2*K+pf3);
% cri3 = h_dep/(pf1*(K-p)^2+pf2*(K-p)+pf3);
% od_stratg=[cri1 cri2 cri3;
% K+p K K-p
% theta_in theta theta_de
% tol_in tol tol_de];
% [~,opi] = max(od_stratg(1,:));
% K = od_stratg(2,opi);
% theta = od_stratg(3,opi);
% tol = od_stratg(4,opi);
%
if theta> theta_max
h = theta_max*h;
else
h = theta*h;
end
end
if h > hmax; h = hmax; end
if h < hmin; h = hmin; end
if K > Kmax; K = Kmax; end
if K < Kmin; K = Kmin; end
% ratio_b4 = ratio;
outputArg1 = K;
outputArg2 = h;
outputArg3 = ratio;
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,138 @@
function [stateCurve,t,finalAlpha,alphaList,diffList,exitFlag]=simulationTimeDomainHem(SimData,SysData,SysPara,x0)
% Numerical integration approach for dynamic simulation
%
%%FUNCTION simulationTimeDomainNI
% 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
% SimData - Simulation parameters
% SysData - System data for simulation
% SysPara - Parameters representing the events happening in the system
% x0 - Initial system state
%
% OUTPUT
% stateCurve - A list of states in the order of time
% t - A list of time points (starting with 0)
% finalAlpha - Final value of alpha
% alphaList - List of alpha (from multi-stage HE)
% exitFlag -
% 0 - Success and normally exit
% -1 - Fail to finish (due to computation errors or failures)
% 1 - System in absolute steady state
% 2 - Generator transients faded away
% 3 - Suggest using error reduction mode
%
% MODES (controlled by SimData.method)
% SimData.method has format X.YZ
% X - Method for solving differential equations (DE)
% 0 - HE
% 1 - Modified Euler
% 2 - RK4
% 3 - Trapezoidal
%
% Y - Method for solving algebraic equations (AE)
% 0 - HE
% 1 - NR
%
% Z - Variable step (only applies to X>1)
% 0 - Fixed step
% 1 - Adaptive step
%
[bus,sw,pv,pq,shunt,line,ind,zip,syn,exc,tg,agc,cac,cluster]=unfoldSysData(SysData);
[nState,idxs]...
=getIndexDyn(SysData);
% [V0,Q0,s0,d0,w0,eq10,eq20,ed10,ed20,psid0,psiq0,Pm0,Ef0,Vavrm0,Vavrr0,Vavrf0,Vavrref0,tgovg0,tgovm0,tgovmech0]=unfoldX(x0,SysData);
% [~,~,sNew,dNew,~,eq1New,eq2New,ed1New,ed2New,psidNew,psiqNew,~,EfNew,~,~,~,~,~,~,~]=unfoldX(xNew,SysData);
[maxTime,segTime,dt,nlvl,taylorN,alphaTol,diffTol,diffTolMax,method,varOpt]=unfoldSimData(SimData);
[pqIncr,pvIncr,Rind0,Rind1,Reind0,Reind1,Rzip0,Rzip1,Ytr0,Ytr1,Ysh0,Ysh1,VspSq2,~,~,~,~,Tmech1,Varref1,Ef1,Pm1,Eq11]=unfoldSysPara(SysPara);
nbus=size(bus,1);
nline=size(line,1);
nInd=size(ind,1);
nZip=size(zip,1);
nSyn=size(syn,1);
nTg=size(tg,1);
nExc=size(exc,1);
if isempty(pqIncr);pqIncr=zeros(size(pq,1),2);end
if isempty(pvIncr);pvIncr=zeros(size(pv,1),1);end
if isempty(Rind0);Rind0=ones(nInd,1);end
if isempty(Rind1);Rind1=zeros(nInd,1);end
if isempty(Reind0);Reind0=ones(nInd,1);end
if isempty(Reind1);Reind1=zeros(nInd,1);end
if isempty(Rzip0);Rzip0=ones(nZip,1);end
if isempty(Rzip1);Rzip1=zeros(nZip,1);end
if isempty(Ytr0)||isempty(Ytr1)||isempty(Ysh0)||isempty(Ysh1)
[~,Ytr0x,Ysh0x,~,~,~,~]=getYMatrix(nbus,line);
if isempty(Ytr0);Ytr0=Ytr0x;end
if isempty(Ytr1);Ytr1=0*Ytr0;end
if isempty(Ysh0);Ysh0=Ysh0x;end
if isempty(Ysh1);Ysh1=0*Ysh0;end
end
if isempty(Tmech1);Tmech1=zeros(nTg,1);end
if isempty(Varref1);Varref1=zeros(nExc,1);end
if isempty(Ef1);Ef1=zeros(nSyn,1);end
if isempty(Pm1);Pm1=zeros(nSyn,1);end
if isempty(Eq11);Eq11=zeros(nSyn,1);end
busType=zeros(nbus,1);
if isempty(pv)
pv=zeros(0,6);
end
if isempty(pq)
pq=zeros(0,6);
end
if isempty(shunt)
shunt=zeros(0,7);
end
if isempty(sw)
sw=zeros(0,13);
end
busType(pv(:,1))=1;
busType(sw(:,1))=2;
isw=find(busType==2);
ipv=find(busType~=0);
ipq=find(busType==0);
npq=size(ipq,1);
npv=size(ipv,1);
% yShunt=zeros(nbus,1);
% yShunt(shunt(:,1))=shunt(:,5)+1j*shunt(:,6);
% Ysh0=Ysh0+yShunt;
if isempty(VspSq2)
V0=x0(idxs.vIdx);
VspSq2=[abs(V0).*abs(V0),zeros(nbus,1)];
end
segAlpha=min([maxTime,segTime]);
SysParax=foldSysPara(pqIncr,pvIncr,Rind0,Rind1,Reind0,Reind1,Rzip0,Rzip1,Ytr0,Ytr1,Ysh0,Ysh1,VspSq2,[],[],[],[],Tmech1,Varref1,Ef1,Pm1,Eq11);
SimDatax=foldSimData(maxTime,segAlpha,dt,nlvl,taylorN,alphaTol,diffTol,diffTolMax,method,varOpt);
[t,stateCurve,finalAlpha,alphaList,diffList,exitFlag]=dtmMachinePFmultiStageDyn(SimDatax,SysData,SysParax,x0);
end
Loading…
Cancel
Save