-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrunPFfull.m
68 lines (61 loc) · 2.28 KB
/
runPFfull.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function [V, lineCurrent, loadPower, transPowerTransfer] = runPFfull(DSSObj,P,Q)
DSSText=DSSObj.text;
%adjust loads
nNodes=33;%primary network
% secNodes=55;%secondary network
for ind=2:nNodes
for secInd=56:110
loadIdx=(ind-2)*55+secInd-55;
nodeNumber=num2str(ind*1000+secInd);
DSSText.Command = ['Edit Load.' nodeNumber ' kW=' num2str(P(loadIdx)) ' kvar=' num2str(Q(loadIdx))];
end
end
%solve power flow
DSSCircuit=DSSObj.ActiveCircuit;
DSSText.Command='Set mode=snapshot';
DSSText.Command='solve';
% DSSText.command='show voltages';
% DSSText.command='show Power';
% get bus voltages
vckt = DSSCircuit.YNodeVarray;
% vckt_len = length(vckt);
vpri_len=33*3*2;
V = vckt(1:2:vpri_len)+1i*vckt(2:2:vpri_len);
% vsec = vckt(vpri_len+1:2:end)+1i*vckt(vpri_len+2:2:end);
loadPower=[];
transPowerTransfer=[];
%get transformers power transfer
% transPowerTransfer = zeros(DSSCircuit.Transformers.count,3);
% Tindex = DSSCircuit.Transformers.First();
% transCounter = 0;
% while Tindex ~= 0
% transCounter=transCounter+1;
% EPowers = DSSCircuit.ActiveCktElement.Powers();
% transPowerTransfer(transCounter,1) = str2double(DSSCircuit.ActiveCktElement.BusNames{1});
% transPowerTransfer(transCounter,2:3) = 3e3*EPowers([1,2]);
% Tindex = DSSCircuit.Transformers.Next();
% end
% get power transfer
lineCurrent = zeros(32*2,8);
Lindex = DSSCircuit.Lines.First();
lineCounter = 0;
while Lindex <33
lineCounter=lineCounter+1;
currents = DSSCircuit.ActiveCktElement.Currents();
lineCurrent(2*lineCounter-1,1:2) = [str2double(DSSCircuit.ActiveCktElement.BusNames{1}),str2double(DSSCircuit.ActiveCktElement.BusNames{2})];
lineCurrent(2*lineCounter-1,3:8) = currents(1:6);
lineCurrent(2*lineCounter,1:2) = lineCurrent(2*lineCounter-1,[2,1]);
lineCurrent(2*lineCounter,3:8) = currents(7:12);
Lindex = DSSCircuit.Lines.Next();
end
%get load power
% loadPower = zeros((nNodes-1)*secNodes,3);%bus number, Pload, Qload
% Lindex = DSSCircuit.Loads.First();
% loadCounter = 0;
% while Lindex ~= 0
% loadCounter = loadCounter+1;
% EPowers = DSSCircuit.ActiveCktElement.Powers();
% loadPower(loadCounter,1) = str2double(DSSCircuit.ActiveCktElement.BusNames{1});
% loadPower(loadCounter,2:3) = 3e3*EPowers(1:2);
% Lindex = DSSCircuit.Loads.Next();
% end