📄 fm_wcall.m
字号:
function fm_wcall%FM_WCALL writes the function FM_CALL for the component calls.% and uses the information in Comp.prop for setting% the right calls. Comp.prop is organized as follows:% comp(i,:) = [x1 x2 x3 x4 x5 xi x0 xt]%% if x1 -> call for algebraic equations% if x2 -> call for algebraic Jacobians% if x3 -> call for state equations% if x4 -> call for state Jacobians% if x5 -> call for non-windup limits% if xi -> component used in power flow computations% if x0 -> call for initializations% if xt -> call for current simulation time% (-1 is used for static analysis)%% Comp.prop is stored in the "comp.ini" file.%%FM_WCALL%%Author: Federico Milano%Date: 11-Nov-2002%Update: 22-Aug-2003%Update: 03-Nov-2005%Version: 1.2.0%%E-mail: fmilano@thunderbox.uwaterloo.ca%Web-site: http://thunderbox.uwaterloo.ca/~fmilano%% Copyright (C) 2002-2006 Federico Milanofm_var% ------------------------------------------------------------------------% Opening file "fm_call.m" for writing% ------------------------------------------------------------------------if Settings.local fid = fopen([Path.local,'fm_call.m'], 'wt');else [fid,msg] = fopen([Path.psat,'fm_call.m'], 'wt'); if fid == -1 fm_disp(msg) fid = fopen([Path.local,'fm_call.m'], 'wt'); endendcount = fprintf(fid,'function fm_call(flag)\n\n');count = fprintf(fid,'\n%%FM_CALL calls component equations');count = fprintf(fid,'\n%%');count = fprintf(fid,'\n%%FM_CALL(CASE)');count = fprintf(fid,'\n%% CASE ''1'' algebraic equations');count = fprintf(fid,'\n%% CASE ''pq'' load algebraic equations');count = fprintf(fid,'\n%% CASE ''3'' differential equations');count = fprintf(fid,'\n%% CASE ''1r'' algebraic equations for Rosenbrock method');count = fprintf(fid,'\n%% CASE ''4'' state Jacobians');count = fprintf(fid,'\n%% CASE ''0'' initialization');count = fprintf(fid,'\n%% CASE ''l'' the complete set of equations and Jacobians');count = fprintf(fid,'\n%% CASE ''kg'' as "L" option but for distributed slack bus');count = fprintf(fid,'\n%% CASE ''n'' algebraic equations and Jacobians');count = fprintf(fid,'\n%% CASE ''i'' set initial point');count = fprintf(fid,'\n%% CASE ''5'' non-windup limits');count = fprintf(fid,'\n%%');count = fprintf(fid,'\n%%see also FM_WCALL\n\n');count = fprintf(fid,'global DAE Bus \n');count = fprintf(fid,'switch flag\n\n');% ------------------------------------------------------------------------% look for loaded components% ------------------------------------------------------------------------Comp.prop(:,9) = 0;for i = 1:Comp.n ncompi = eval(Comp.number{i}); if ncompi, Comp.prop(i,9) = 1; endendcidx1 = find(Comp.prop(:,9));prop1 = Comp.prop(cidx1,1:8);func1 = Comp.funct(cidx1);cidx2 = find(Comp.prop(1:end-2,9));prop2 = Comp.prop(cidx2,1:8);func2 = Comp.funct(cidx2);% ------------------------------------------------------------------------% call algebraic equations% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''1''\n\n');idx = find(prod(prop2(:,[1 6]),2));count = fprintf(fid,' %s(1);\n',func2{idx});% ------------------------------------------------------------------------% call algebraic equations of shunt components% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''pq''\n\n');idx = find(prod(prop2(:,[1 6 8]),2));count = fprintf(fid,' %s(1);\n',func2{idx});% ------------------------------------------------------------------------% call differential equations% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''3''\n\n');count = fprintf(fid,' %s(3);\n',func2{find(prop2(:,3))});% ------------------------------------------------------------------------% call algebraic equations for Rosenbrock method% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''1r''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endcount = fprintf(fid,' %s(1);\n',func1{find(prop1(:,1))});count = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');% ------------------------------------------------------------------------% call DAE Jacobians% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''4''\n');writejacs(fid)count = fprintf(fid,' %s(4);\n',func2{find(prop2(:,4))});% ------------------------------------------------------------------------% call initialization functions% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''0''\n\n');idx = find(prop2(:,7));count = fprintf(fid,' %s(0);\n',func2{idx});% ------------------------------------------------------------------------% call the complete set of algebraic equations% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''fdpf''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endidx = find(prod(prop1(:,[1 6]),2));count = fprintf(fid,' %s(1);\n',func1{idx});count = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');% ------------------------------------------------------------------------% call the complete set of equations and Jacobians% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''l''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endidx = find(prod(prop1(:,[1 6]),2));count = fprintf(fid,' %s(1);\n',func1{idx});count = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');if Line.n, count = fprintf(fid,' fm_lf(2);\n'); endcount = fprintf(fid,' DAE.Jlf = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');idx = find(prod(prop1(:,[2 6]),2));count = fprintf(fid,' %s(2);\n',func1{idx});count = fprintf(fid,'\n DAE.Jlfv = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n\n');idx = find(prod(prop1(:,[3 6]),2));count = fprintf(fid,' %s(3);\n',func1{idx});writejacs(fid)idx = find(prod(prop1(:,[4 6]),2));count = fprintf(fid,' %s(4);\n',func1{idx});% ------------------------------------------------------------------------% call the complete set of eqns and Jacs for distributed slack bus% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''kg''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endcount = fprintf(fid,' %s(1);\n',func2{[1:end]});if Comp.prop(end-1,9), count = fprintf(fid,' fm_pv(1);\n'); endcount = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');if Line.n, count = fprintf(fid,' fm_lf(2);\n'); endcount = fprintf(fid,' DAE.Jlf = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');count = fprintf(fid,' %s(2);\n',func2{[1:end]});count = fprintf(fid,'\n DAE.Jlfv = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n\n');count = fprintf(fid,' %s(3);\n',func2{[1:end]});writejacs(fid)count = fprintf(fid,' %s(4);\n',func2{[1:end]});% ------------------------------------------------------------------------% call the complete set of eqns and Jacs for distributed slack bus% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''kgpf''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endidx = find(prod(prop2(:,[1 6]),2));count = fprintf(fid,' %s(1);\n',func2{idx});if Comp.prop(end-1,9), count = fprintf(fid,' fm_pv(1);\n'); endcount = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');if Line.n, count = fprintf(fid,' fm_lf(2);\n'); endcount = fprintf(fid,' DAE.Jlf = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');idx = find(prod(prop2(:,[2 6]),2));count = fprintf(fid,' %s(2);\n',func2{idx});count = fprintf(fid,'\n DAE.Jlfv = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n\n');idx = find(prod(prop2(:,[3 6]),2));count = fprintf(fid,' %s(3);\n',func2{idx});writejacs(fid)idx = find(prod(prop2(:,[4 6]),2));count = fprintf(fid,' %s(4);\n',func2{idx});% ------------------------------------------------------------------------% calling algebraic equations and Jacobians% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''n''\n\n');if Line.n, count = fprintf(fid,' fm_lf(1);\n'); endcount = fprintf(fid,' %s(1);\n',func1{find(prop1(:,1))});count = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');if Line.n, count = fprintf(fid,' fm_lf(2);\n'); endcount = fprintf(fid,' DAE.Jlf = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');count = fprintf(fid,' %s(2);\n',func1{find(prop1(:,2))});count = fprintf(fid,'\n DAE.Jlfv = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');% ------------------------------------------------------------------------% call all the functions for setting initial point% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''i''\n\n');if Line.n > 0, count = fprintf(fid,' fm_lf(1);\n'); endcount = fprintf(fid,' %s(1);\n',func1{find(prop1(:,1))});count = fprintf(fid,'\n DAE.g = [DAE.gp; DAE.gq];\n\n');if Line.n > 0, count = fprintf(fid,' fm_lf(2);\n'); endcount = fprintf(fid,' DAE.Jlf = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n');count = fprintf(fid,' %s(2);\n',func1{find(prop1(:,2))});count = fprintf(fid,'\n DAE.Jlfv = [DAE.J11, DAE.J12; DAE.J21, DAE.J22];\n\n');count = fprintf(fid,' %s(3);\n',func1{find(prop1(:,3))});count = fprintf(fid,'\n if DAE.n > 0');writejacs(fid)count = fprintf(fid,' end \n\n');count = fprintf(fid,' %s(4);\n',func1{find(prop1(:,4))});% ------------------------------------------------------------------------% call saturation functions% ------------------------------------------------------------------------count = fprintf(fid,'\n case ''5''\n\n');count = fprintf(fid,' %s(5);\n',func1{find(prop1(:,5))});% ------------------------------------------------------------------------% close "fm_call.m"% ------------------------------------------------------------------------count = fprintf(fid,'\nend\n');count = fclose(fid);cd(Path.local);% ------------------------------------------------------------------------% function for writing Jacobian initialization% ------------------------------------------------------------------------function writejacs(fid)count = fprintf(fid,'\n DAE.Fx = sparse(DAE.n,DAE.n);');count = fprintf(fid,'\n DAE.Fy = sparse(DAE.n,2*Bus.n);');count = fprintf(fid,'\n DAE.Gx = sparse(2*Bus.n,DAE.n);\n');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -