-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCAPI_DSSimComs.pas
94 lines (83 loc) · 2.72 KB
/
CAPI_DSSimComs.pas
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
unit CAPI_DSSimComs;
interface
uses
CAPI_Utils,
CAPI_Types,
UComplex, DSSUcomplex;
procedure DSSimComs_BusVoltagepu(var ResultPtr: PDouble; ResultCount: PAPISize; Index: PtrUInt); CDECL;
procedure DSSimComs_BusVoltagepu_GR(Index: PtrUInt); CDECL;
procedure DSSimComs_BusVoltage(var ResultPtr: PDouble; ResultCount: PAPISize; Index: PtrUInt); CDECL;
procedure DSSimComs_BusVoltage_GR(Index: PtrUInt); CDECL;
implementation
uses
CAPI_Constants,
DSSGlobals,
Executive,
SysUtils,
solution,
CktElement,
DSSClass,
DSSHelper;
procedure DSSimComs_BusVoltagepu(var ResultPtr: PDouble; ResultCount: PAPISize; Index: PtrUInt); CDECL;
var
Result: PDoubleArray0;
i, j: Integer;
Volts, BaseFactor: Double;
begin
if InvalidCircuit(DSSPrime) then
begin
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
with DSSPrime.ActiveCircuit do
begin
i := Index;
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, Buses^[i].NumNodesThisBus);
if Buses^[i].kVBase > 0.0 then
BaseFactor := 1000.0 * Buses^[i].kVBase
else
BaseFactor := 1.0;
for j := 1 to Buses^[i].NumNodesThisBus do
begin
Volts := Cabs(DSSPrime.ActiveCircuit.Solution.NodeV^[Buses^[i].GetRef(j)]);
Result[j - 1] := Volts / BaseFactor;
end;
end
end;
procedure DSSimComs_BusVoltagepu_GR(Index: PtrUInt); CDECL;
// Same as DSSimComs_BusVoltagepu but uses global result (GR) pointers
begin
DSSimComs_BusVoltagepu(DSSPrime.GR_DataPtr_PDouble, DSSPrime.GR_Counts_PDouble, Index)
end;
//------------------------------------------------------------------------------
procedure DSSimComs_BusVoltage(var ResultPtr: PDouble; ResultCount: PAPISize; Index: PtrUInt); CDECL;
var
Result: PDoubleArray0;
i, j, k: Integer;
Volts: Complex;
begin
if InvalidCircuit(DSSPrime) then
begin
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
with DSSPrime.ActiveCircuit do
begin
i := Index;
Result := DSS_RecreateArray_PDouble(ResultPtr, ResultCount, 2 * Buses^[i].NumNodesThisBus);
for j := 1 to Buses^[i].NumNodesThisBus do
begin
Volts := DSSPrime.ActiveCircuit.Solution.NodeV^[Buses^[i].GetRef(j)];
k := (j - 1) * 2;
Result[k] := Volts.re;
Result[k + 1] := Volts.im;
end;
end
end;
procedure DSSimComs_BusVoltage_GR(Index: PtrUInt); CDECL;
// Same as DSSimComs_BusVoltage but uses global result (GR) pointers
begin
DSSimComs_BusVoltage(DSSPrime.GR_DataPtr_PDouble, DSSPrime.GR_Counts_PDouble, Index)
end;
//------------------------------------------------------------------------------
end.