@@ -34,8 +34,9 @@ TDSSCktElement = class(TDSSObject)
34
34
procedure Set_Freq (Value : Double); // set freq and recompute YPrim.
35
35
36
36
procedure Set_Nconds (Value : Int8);
37
+ function Get_ActiveTerminal (): Int8; inline;
37
38
procedure Set_ActiveTerminal (value : Int8);
38
- function Get_ConductorClosed (Index: Integer): Boolean;
39
+ function Get_ConductorClosed (Index: Integer): Boolean; inline;
39
40
procedure Set_YprimInvalid (const Value : Boolean);
40
41
function Get_FirstBus : String;
41
42
function Get_NextBus : String;
@@ -133,7 +134,7 @@ TDSSCktElement = class(TDSSObject)
133
134
property MaxPower[idxTerm: Integer]: Complex READ Get_MaxPower; // Total power in active terminal
134
135
property MaxCurrent[idxTerm: Integer]: Double READ Get_MaxCurrent; // Max current in active terminal
135
136
property MaxVoltage[idxTerm: Integer]: Double READ Get_MaxVoltage; // Max voltage in active terminal
136
- property ActiveTerminalIdx: Int8 READ FActiveTerminal WRITE Set_ActiveTerminal;
137
+ property ActiveTerminalIdx: Int8 READ Get_ActiveTerminal WRITE Set_ActiveTerminal;
137
138
property Closed[Index: Integer]: Boolean READ Get_ConductorClosed WRITE Set_ConductorClosed;
138
139
procedure SumCurrents ;
139
140
@@ -190,7 +191,7 @@ constructor TDSSCktElement.Create(ParClass: TDSSClass);
190
191
// Make list for a small number of controls with an increment of 1
191
192
ControlElementList := TDSSPointerList.Create(1 );
192
193
193
- FActiveTerminal := 1 ;
194
+ FActiveTerminal := 0 ;
194
195
// LastTerminalChecked := 0;
195
196
196
197
// Indicates which solution Itemp is computed for
@@ -241,12 +242,17 @@ procedure TDSSCktElement.Set_YprimInvalid(const Value: Boolean);
241
242
ActiveCircuit.Solution.SystemYChanged := TRUE;
242
243
end ;
243
244
245
+ function TDSSCktElement.Get_ActiveTerminal (): Int8; inline;
246
+ begin
247
+ Result := FActiveTerminal + 1 ;
248
+ end ;
249
+
244
250
procedure TDSSCktElement.Set_ActiveTerminal (value : Int8);
245
251
begin
246
252
if (Value > 0 ) and (Value <= fNterms) then
247
253
begin
248
- FActiveTerminal := Value ;
249
- ActiveTerminal := @Terminals[Value - 1 ];
254
+ FActiveTerminal := Value - 1 ;
255
+ ActiveTerminal := @Terminals[FActiveTerminal ];
250
256
end ;
251
257
end ;
252
258
@@ -255,7 +261,7 @@ procedure TDSSCktElement.Set_Handle(value: Integer);
255
261
FHandle := value ;
256
262
end ;
257
263
258
- function TDSSCktElement.Get_ConductorClosed (Index: Integer): Boolean;
264
+ function TDSSCktElement.Get_ConductorClosed (Index: Integer): Boolean; inline;
259
265
// return state of selected conductor
260
266
// if index=0 return true if all phases closed, else false
261
267
var
@@ -266,7 +272,7 @@ function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean;
266
272
Result := TRUE;
267
273
for i := 1 to Fnphases do
268
274
begin
269
- if not Terminals[FActiveTerminal - 1 ].ConductorsClosed[i - 1 ] then
275
+ if not Terminals[FActiveTerminal].ConductorsClosed[i - 1 ] then
270
276
begin
271
277
Result := FALSE;
272
278
Break;
@@ -275,7 +281,7 @@ function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean;
275
281
end
276
282
else
277
283
if (Index > 0 ) and (Index <= Fnconds) then
278
- Result := Terminals[FActiveTerminal - 1 ].ConductorsClosed[Index - 1 ]
284
+ Result := Terminals[FActiveTerminal].ConductorsClosed[Index - 1 ]
279
285
else
280
286
Result := FALSE;
281
287
end ;
@@ -286,16 +292,16 @@ procedure TDSSCktElement.Set_ConductorClosed(Index: Integer; Value: Boolean);
286
292
begin
287
293
if (Index = 0 ) then
288
294
begin // Do all conductors
289
- for i := 1 to Fnphases do
290
- Terminals[FActiveTerminal - 1 ].ConductorsClosed[i - 1 ] := Value ;
295
+ for i := 0 to Fnphases - 1 do
296
+ Terminals[FActiveTerminal].ConductorsClosed[i] := Value ;
291
297
// DSS.ActiveCircuit.Solution.SystemYChanged := TRUE; // force Y matrix rebuild
292
298
YPrimInvalid := TRUE; // this also sets the global SystemYChanged flag
293
299
end
294
300
else
295
301
begin
296
302
if (Index > 0 ) and (Index <= Fnconds) then
297
303
begin
298
- Terminals[FActiveTerminal - 1 ].ConductorsClosed[index - 1 ] := Value ;
304
+ Terminals[FActiveTerminal].ConductorsClosed[index - 1 ] := Value ;
299
305
// DSS.ActiveCircuit.Solution.SystemYChanged := TRUE;
300
306
YPrimInvalid := TRUE;
301
307
end ;
@@ -1054,15 +1060,42 @@ procedure TDSSCktElement.ComputeVterminal;
1054
1060
// Put terminal voltages in an array
1055
1061
var
1056
1062
i: Integer;
1063
+ vterm: PDouble;
1064
+ nref: PInteger;
1065
+ nv0, nv: PDouble;
1057
1066
begin
1058
1067
with ActiveCircuit.solution do
1068
+ begin
1069
+ vterm := PDouble(VTerminal);
1070
+ nref := PInteger(NodeRef);
1071
+ nv0 := PDouble(NodeV);
1059
1072
for i := 1 to Yorder do
1060
- VTerminal^[i] := NodeV^[NodeRef^[i]];
1073
+ begin
1074
+ nv := nv0 + 2 * nref^;
1075
+ vterm^ := nv^;
1076
+ (vterm + 1 )^ := (nv + 1 )^;
1077
+ inc(vterm, 2 );
1078
+ inc(nref);
1079
+ // VTerminal^[i] := NodeV^[NodeRef^[i]];
1080
+ end ;
1081
+ end ;
1061
1082
end ;
1062
1083
1063
1084
procedure TDSSCktElement.ZeroITerminal ; inline;
1085
+ var
1086
+ i: Integer;
1087
+ it: PDouble;
1064
1088
begin
1065
- FillDWord(ITerminal^, Yorder * ((SizeOf(Double) * 2 ) div 4 ), 0 );
1089
+ // Somehow this is slower?! FillDWord(ITerminal^, Yorder * ((SizeOf(Double) * 2) div 4), 0);
1090
+ it := PDouble(Iterminal);
1091
+ for i := 1 to Yorder do
1092
+ begin
1093
+ it^ := 0 ;
1094
+ (it + 1 )^ := 0 ;
1095
+ inc(it, 2 );
1096
+ end ;
1097
+ // for i := 1 to Yorder do
1098
+ // ITerminal[i] := CZERO;
1066
1099
end ;
1067
1100
1068
1101
procedure TDSSCktElement.MakeLike (OtherObj: Pointer);
0 commit comments