-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathLoad.pas
2051 lines (1816 loc) · 68.6 KB
/
Load.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Load;
{
----------------------------------------------------------
Copyright (c) 2008-2015, Electric Power Research Institute, Inc.
All rights reserved.
----------------------------------------------------------
}
// The load is assumed balanced over the no. of phases defined
// To model unbalanced loads, define separate single-phase loads
// IF you do not specify load shapes defaults are:
// Yearly: Defaults to No variation or Daily when Daily is defined
// Daily: Defaults to No variation (i.e. multiplier = 1.0 always)
// Dutycycle: Defaults to Daily shape
// Growth: Circuit default growth factor
// Change Log
// 4/1/14 Added Vlowpu property to make solution converge better at very low voltages
// 1/7/15 Added puXHarm and XRHarm properties to help model motor load for harmonic studies
// 3/16/16 Added PFSpecified to account for problems when UseActual is specified and no Qmult specified
// 1/10/18 Celso/Paulo mods for low-voltage transition for Model 5
interface
uses
Classes,
DSSClass,
PCClass,
PCElement,
ucmatrix,
UComplex, DSSUcomplex,
LoadShape,
GrowthShape,
Spectrum,
ArrayDef;
type
{$SCOPEDENUMS ON}
{$PUSH}
{$Z4} // keep enums as int32 values
TLoadModel = (
// INVALID = 0,
ConstPQ = 1, // Constant kVA (P,Q always in same ratio)
ConstZ = 2, // Constant impedance
Motor = 3, // Constant P, Quadratic Q (Mostly motor)
CVR = 4, // Linear P, Quadratic Q (Mixed motor/resistive Use this for CVR studies
ConstI = 5, // Constant |I|
ConstPFixedQ = 6, // Constant P (Variable); Q is fixed value (not variable)
ConstPFixedX = 7, // Constant P (Variable); Q is fixed Z (not variable)
ZIPV = 8 // ZIPV (3 real power coefficients, 3 reactive, Vcutoff)
);
TLoadStatus = (
Variable = 0,
Fixed,
Exempt
);
{$SCOPEDENUMS OFF}
{$POP}
TLoadConnection = TGeneralConnection;
TLoadSpec = (
kW_PF = 0,
kW_kvar = 1,
kVA_PF = 2,
ConnectedkVA_PF = 3,
kWh_PF = 4
);
TLoadProp = (
INVALID = 0,
phases = 1,
bus1 = 2,
kV = 3,
kW = 4,
pf = 5,
model = 6,
yearly = 7,
daily = 8,
duty = 9,
growth = 10,
conn = 11,
kvar = 12,
Rneut = 13, // IF entered -, assume open
Xneut = 14,
status = 15, // fixed or variable
cls = 16, // integer
Vminpu = 17, // Min pu voltage for which model applies
Vmaxpu = 18, // Max pu voltage for which model applies
Vminnorm = 19, // Min pu voltage normal load
Vminemerg = 20, // Min pu voltage emergency rating
xfkVA = 21, // Service transformer rated kVA
allocationfactor = 22, // allocation factor for xfkVA
kVA = 23, // specify load in kVA and PF
pctmean = 24, // per cent default mean
pctstddev = 25, // per cent default standard deviation
CVRwatts = 26, // Percent watts reduction per 1% reduction in voltage from nominal
CVRvars = 27, // Percent vars reduction per 1% reduction in voltage from nominal
kwh = 28, // kwh billing
kwhdays = 29, // kwh billing period (24-hr days)
Cfactor = 30, // multiplier from kWh avg to peak kW
CVRcurve = 31, // name of curve to use for yearly CVR simulations
NumCust = 32, // Number of customers, this load
ZIPV = 33, // array of 7 coefficients
pctSeriesRL = 34, // pct of Load that is series R-L
RelWeight = 35, // Weighting factor for reliability
Vlowpu = 36, // Below this value resort to constant Z model = Yeq
puXharm = 37, // pu Reactance for Harmonics, if specifies
XRharm = 38 // X/R at fundamental for series R-L model for hamonics
);
{$SCOPEDENUMS OFF}
TLoad = class(TPCClass)
PROTECTED
procedure DefineProperties; override; // Add Properties of this class to propName
PUBLIC
constructor Create(dssContext: TDSSContext);
destructor Destroy; OVERRIDE;
function EndEdit(ptr: Pointer; const NumChanges: integer): Boolean; override;
Function NewObject(const ObjName: String; Activate: Boolean = True): Pointer; OVERRIDE;
end;
TLoadObj = class(TPCElement)
PUBLIC
FAllocationFactor: Double; // For all types of allocation
FkVAAllocationFactor: Double; // for connected kVA specification
FConnectedkVA: Double;
FkWh: Double;
FkWhDays: Double;
FCFactor: Double; // For kWh billed spec
FAvgkW: Double;
FPhaseCurr: pComplexArray; // this is the intermediate current computed in each power flow mode.
HarmAng: pDoubleArray; // References for Harmonics mode
HarmMag: pDoubleArray;
LastGrowthFactor: Double;
LastYear: Integer; // added FOR speedup so we don't have to search FOR growth factor a lot
LoadFundamental: Double;
LoadSolutionCount: Integer;
OpenLoadSolutionCount: Integer;
RandomMult: Double;
ShapeFactor: Complex;
varBase: Double; // Base vars per phase
varNominal: Double;
VBase: Double; // Base volts suitable for computing currents
VBase105: Double;
VBase95: Double;
VBaseLow: Double;
WNominal: Double; // Nominal Watts per phase
Yeq: Complex; // at nominal
Yeq105: Complex;
Yeq105I: Complex; // ***Added by Celso & Paulo
Yeq95: Complex;
Yneut: Complex;
YPrimOpenCond: TCmatrix; // To handle cases where one conductor of load is open
YQFixed: Double; // Fixed value of y FOR type 7 load
FpuXHarm: Double; // puX for harmonics solution.
FXRHarmRatio: Double; // X/R at fundamental
// formerly private, now read-only properties for COM access
FpuMean: Double;
FpuStdDev: Double;
FCVRwattFactor: Double;
FCVRvarFactor: Double;
Vmaxpu: Double;
VminEmerg: Double; // overrides system settings IF <> 0.0
VminNormal: Double;
Vminpu: Double;
VLowpu: Double; // below this voltage, resorts to linear @ Yeq
// For interpolating currents between VbaseLow and Vbase95
ILow: Complex;
I95: Complex;
IBase: Complex; // at nominal ***Added by Celso & Paulo
M95: Complex; // complex slope of line between Low and 95
M95I: Complex; // complex slope of line between Low and 95 for Constant I **Added by Celso & Paulo
status: TLoadStatus;
ShapeIsActual: Boolean;
PFSpecified: Boolean; // Added 3-16-16 to fix problem with UseActual
PFChanged: Boolean;
function AllTerminalsClosed: Boolean;
procedure CalcDailyMult(Hr: Double);
procedure CalcDutyMult(Hr: Double);
procedure CalcInjCurrentArray;
procedure CalcLoadModelContribution;
procedure CalcVTerminalPhase;
procedure CalcYearlyMult(Hr: Double);
procedure CalcCVRMult(Hr: Double);
procedure CalcYPrimMatrix(Ymatrix: TcMatrix);
procedure DoConstantILoad;
procedure DoConstantPQLoad;
procedure DoConstantZLoad;
procedure DoFixedQ;
procedure DoFixedQZ;
procedure DoHarmonicMode;
procedure DoCVRModel;
procedure DoZIPVModel;
procedure DoMotorTypeLoad;
function GrowthFactor(Year: Integer): Double;
procedure StickCurrInTerminalArray(TermArray: pComplexArray; const Curr: Complex; i: Integer); inline;
function InterpolateY95_YLow(const Vmag: Double): Complex; inline;
function InterpolateY95I_YLow(const Vmag: Double): Complex; inline; // ***Added by Celso & Paulo
function Get_Unserved: Boolean;
function Get_ExceedsNormal: Boolean;
procedure Set_kVAAllocationFactor(const Value: Double);
procedure ComputeAllocatedLoad;
// Set kWh properties ...
procedure Set_CFactor(const Value: Double);
procedure Set_AllocationFactor(const Value: Double);
procedure SetkWkvar(const PkW, Qkvar: Double);
PROTECTED
procedure GetTerminalCurrents(Curr: pComplexArray); OVERRIDE;
PUBLIC
Connection: TLoadConnection;
DailyShapeObj: TLoadShapeObj; // Daily load Shape FOR this load
DutyShapeObj: TLoadShapeObj; // Shape for this load
EEN_Factor: Double; // is overloaded Factor is the amount of overload
GrowthShapeObj: TGrowthShapeObj; // Shape for this Growth Curve
HasBeenAllocated: Boolean;
kWBase: Double;
kVABase: Double;
kWref: Double;
kVARref: Double;
kvarBase: Double;
kVLoadBase: Double;
LoadClass: Integer;
NumCustomers: Integer;
LoadSpecType: TLoadSpec; // 0=kW, PF; 1= kw, kvar; 2=kva, PF
PFNominal: Double;
Rneut: Double;
UE_Factor: Double; // These are set to > 0 IF a line in the critical path
Xneut: Double; // Neutral impedance
YearlyShapeObj: TLoadShapeObj; // Shape for this load
CVRShapeObj: TLoadShapeObj;
ZIPV: Array[1..7] of Double; // Made public 5-20-2013
ZIPVset: Boolean;
puSeriesRL: Double;
RelWeighting: Double;
FLoadModel: TLoadModel; // Variation with voltage
constructor Create(ParClass: TDSSClass; const SourceName: String);
destructor Destroy; OVERRIDE;
procedure PropertySideEffects(Idx: Integer; previousIntVal: Integer = 0); override;
procedure MakeLike(OtherPtr: Pointer); override;
procedure RecalcElementData; OVERRIDE;
procedure CalcYPrim; OVERRIDE;
function InjCurrents: Integer; OVERRIDE;
procedure InitHarmonics; OVERRIDE;
procedure MakePosSequence(); OVERRIDE; // Make a positive Sequence Model
procedure SetNominalLoad;
procedure Randomize(Opt: Integer);
// 0 = reset to 1.0
// 1 = Gaussian around mean and std Dev
// 2 = uniform
property Unserved: Boolean READ Get_Unserved;
property ExceedsNormal: Boolean READ Get_ExceedsNormal;
// AllocationFactor adjusts either connected kVA allocation factor or kWh CFactor
property AllocationFactor: Double READ FAllocationFactor WRITE Set_AllocationFactor;
// Allocate load from connected kva or kWh billing
//TODO: remove these properties, use plain DSS properties
// instead to ease the code transition?
property kVAAllocationFactor: Double READ FkVAAllocationFactor WRITE Set_kVAAllocationFactor;
property ConnectedkVA: Double READ FConnectedkVA;
property kWh: Double READ FkWh;// WRITE Set_kWh;
property kWhDays: Double READ FkWhDays;
property CFactor: Double READ FCFactor WRITE Set_CFactor;
property puMean: Double READ FpuMean;
property puStdDev: Double READ FpuStdDev;
property CVRwatts: Double READ FCVRwattFactor;
property CVRvars: Double READ FCVRvarFactor;
property MaxPU: Double READ Vmaxpu;
property MinEmerg: Double READ VminEmerg;
property MinNormal: Double READ VminNormal;
property MinPU: Double READ Vminpu;
Property IsPFSpecified: Boolean read PFSpecified;
const
nZIPV = 7;
end;
implementation
uses
Circuit,
DSSClassDefs,
DSSGlobals,
Dynamics,
Sysutils,
Command,
Math,
MathUtil,
Utilities,
TypInfo,
DSSHelper,
DSSObjectHelper;
type
TObj = TLoadObj;
TProp = TLoadProp;
const
NumPropsThisClass = Ord(High(TProp));
var
PropInfo: Pointer = NIL;
LoadStatusEnum, LoadModelEnum: TDSSEnum;
constructor TLoad.Create(dssContext: TDSSContext);
begin
if PropInfo = NIL then
begin
PropInfo := TypeInfo(TProp);
LoadModelEnum := TDSSEnum.Create('Load: Model', True, 0, 0, [
'Constant PQ', 'Constant Z', 'Motor (constant P, quadratic Q)', 'CVR (linear P, quadratic Q)',
'Constant I', 'Constant P, fixed Q', 'Constant P, fixed X', 'ZIPV'],
[1, 2, 3, 4, 5, 6, 7, 8]);
LoadStatusEnum := TDSSEnum.Create('Load: Status', True, 1, 1,
['Variable', 'Fixed', 'Exempt'], [0, 1, 2]);
LoadStatusEnum.DefaultValue := 0;
end;
inherited Create(dssContext, LOAD_ELEMENT, 'Load');
end;
destructor TLoad.Destroy;
begin
inherited Destroy;
end;
procedure TLoad.DefineProperties;
type
P = TProp;
var
obj: TObj = NIL; // NIL (0) on purpose
begin
Numproperties := NumPropsThisClass;
CountPropertiesAndAllocate();
PopulatePropertyNames(0, NumPropsThisClass, PropInfo);
// enum properties
PropertyType[ord(TProp.conn)] := TPropertyType.MappedStringEnumProperty;
PropertyOffset[ord(TProp.conn)] := ptruint(@obj.Connection);
PropertyOffset2[ord(TProp.conn)] := PtrInt(DSS.ConnectionEnum);
PropertyType[ord(TProp.model)] := TPropertyType.MappedIntEnumProperty;
PropertyOffset[ord(TProp.model)] := ptruint(@obj.FLoadModel);
PropertyOffset2[ord(TProp.model)] := PtrInt(LoadModelEnum);
PropertyType[ord(TProp.status)] := TPropertyType.MappedStringEnumProperty;
PropertyOffset[ord(TProp.status)] := ptruint(@obj.status);
PropertyOffset2[ord(TProp.status)] := PtrInt(LoadStatusEnum);
// array property
PropertyType[ord(TProp.ZIPV)] := TPropertyType.DoubleFArrayProperty;
PropertyOffset[ord(TProp.ZIPV)] := ptruint(@obj.ZIPV[1]);
PropertyOffset2[ord(TProp.ZIPV)] := 7;
// bus properties
PropertyType[ord(TProp.bus1)] := TPropertyType.BusProperty;
PropertyOffset[ord(TProp.bus1)] := 1;
// pct properties
PropertyScale[ord(TProp.pctmean)] := 0.01;
PropertyScale[ord(TProp.pctstddev)] := 0.01;
PropertyScale[ord(TProp.pctSeriesRL)] := 0.01;
PropertyOffset[ord(TProp.pctmean)] := ptruint(@obj.FpuMean);
PropertyOffset[ord(TProp.pctstddev)] := ptruint(@obj.FpuStdDev);
PropertyOffset[ord(TProp.pctSeriesRL)] := ptruint(@obj.puSeriesRL);
// integer properties
PropertyOffset[ord(TProp.cls)] := ptruint(@obj.LoadClass);
PropertyOffset[ord(TProp.NumCust)] := ptruint(@obj.NumCustomers);
PropertyType[ord(TProp.cls)] := TPropertyType.IntegerProperty;
PropertyType[ord(TProp.NumCust)] := TPropertyType.IntegerProperty;
PropertyType[ord(TProp.phases)] := TPropertyType.IntegerProperty;
PropertyOffset[ord(TProp.phases)] := ptruint(@obj.FNPhases);
PropertyFlags[ord(TProp.phases)] := [TPropertyFlag.NonNegative, TPropertyFlag.NonZero];
// object properties
AddProperties_Object(
[ord(P.yearly), ord(P.daily), ord(P.duty), ord(P.CVRcurve), ord(P.growth)],
[@obj.YearlyShapeObj, @obj.DailyShapeObj, @obj.DutyShapeObj, @obj.CVRShapeObj, @obj.GrowthShapeObj],
[DSS.LoadShapeClass, DSS.LoadShapeClass, DSS.LoadShapeClass, DSS.LoadShapeClass, DSS.GrowthShapeClass]
);
// double properties (default type)
AddProperties_Double(
[ord(P.Rneut), ord(P.Xneut), ord(P.kV), ord(P.kW), ord(P.pf), ord(P.kvar), ord(P.kVA),
ord(P.RelWeight), ord(P.Vlowpu), ord(P.puXharm), ord(P.XRharm), ord(P.Vminpu), ord(P.VMaxPu), ord(P.Vminnorm),
ord(P.Vminemerg), ord(P.CVRwatts), ord(P.CVRvars), ord(P.kwh), ord(P.xfkVA), ord(P.kwhdays),
ord(P.Cfactor), ord(P.allocationfactor)],
[@obj.Rneut, @obj.Xneut, @obj.kVLoadBase, @obj.kwBase, @obj.PFNominal, @obj.kvarBase, @obj.kVABase,
@obj.RelWeighting, @obj.VLowpu, @obj.FpuXHarm, @obj.FXRHarmRatio, @obj.VMinPu, @obj.VMaxPu, @obj.VminNormal,
@obj.VminEmerg, @obj.FCVRwattFactor, @obj.FCVRvarFactor, @obj.kWh, @obj.FConnectedkVA, @obj.kWhdays,
@obj.FCFactor, @obj.FkVAAllocationFactor]
);
ActiveProperty := NumPropsThisClass;
inherited DefineProperties;
end;
function TLoad.NewObject(const ObjName: String; Activate: Boolean): Pointer;
var
Obj: TObj;
begin
Obj := TObj.Create(Self, ObjName);
if Activate then
ActiveCircuit.ActiveCktElement := Obj;
Obj.ClassIndex := AddObjectToList(Obj, Activate);
Result := Obj;
end;
procedure SetNcondsForConnection(Obj: TObj);
begin
with Obj do
case Connection of
TLoadConnection.Wye:
NConds := Fnphases + 1;
TLoadConnection.Delta:
case Fnphases of
1, 2:
NConds := Fnphases + 1; // L-L and Open-delta
else
NConds := Fnphases;
end;
end;
end;
procedure TLoadObj.PropertySideEffects(Idx: Integer; previousIntVal: Integer);
begin
case Idx of
ord(TProp.conn):
begin
SetNCondsForConnection(self);
case Connection of
TLoadConnection.Delta:
VBase := kVLoadBase * 1000.0;
else
case Fnphases of
2, 3:
VBase := kVLoadBase * InvSQRT3x1000;
else
VBase := kVLoadBase * 1000.0;
end;
end;
VBase95 := Vminpu * VBase;
VBase105 := Vmaxpu * VBase;
VBaseLow := VLowpu * VBase;
Yorder := Fnconds * Fnterms;
Reallocmem(InjCurrent, SizeOf(InjCurrent^[1]) * Yorder);
YPrimInvalid := TRUE;
end;
ord(TProp.kV), ord(TProp.phases):
begin
if Idx = ord(TProp.phases) then
begin
Reallocmem(FPhaseCurr, SizeOf(FPhaseCurr^[1]) * FNphases);
SetNCondsForConnection(self); // Force Reallocation of terminal info
end;
case Connection of
TLoadConnection.Delta:
VBase := kVLoadBase * 1000.0;
else // wye
case Fnphases of
2, 3:
VBase := kVLoadBase * InvSQRT3x1000;
else
VBase := kVLoadBase * 1000.0; // 1-phase or unknown
end;
end;
end;
ord(TProp.kW):
begin
LoadSpecType := TLoadSpec.kW_PF;
kWRef := kWBase;
end;
ord(TProp.pf):
begin
PFChanged := TRUE;
PFSpecified := TRUE;
end;
ord(TProp.allocationfactor):
begin
FAllocationFactor := FkVAAllocationFactor;
LoadSpecType := TLoadSpec.ConnectedkVA_PF;
ComputeAllocatedLoad;
HasBeenAllocated := TRUE;
end;
ord(TProp.Cfactor):
begin
FAllocationFactor := FCFactor;
LoadSpecType := TLoadSpec.kWh_PF;
ComputeAllocatedLoad;
HasBeenAllocated := TRUE;
end;
// Set shape objects; returns nil if not valid
// Sets the kW and kvar properties to match the peak kW demand from the Loadshape
ord(TProp.Yearly):
begin
if Assigned(YearlyShapeObj) then
with YearlyShapeObj do
if UseActual then
begin
kWref := kWBase;
kVARref := kVARbase;
SetkWkvar(MaxP, MaxQ);
end;
end;
ord(TProp.daily):
begin
if Assigned(DailyShapeObj) then
with DailyShapeObj do
if UseActual then
SetkWkvar(MaxP, MaxQ);
// If Yearly load shape is not yet defined, make it the same as Daily
if YearlyShapeObj = NIL then
YearlyShapeObj := DailyShapeObj;
end;
ord(TProp.duty):
begin
if Assigned(DutyShapeObj) then
with DutyShapeObj do
if UseActual then
SetkWkvar(MaxP, MaxQ);
end;
ord(TProp.kwh):
begin
LoadSpecType := TLoadSpec.kWh_PF;
FAllocationFactor := FCFactor;
ComputeAllocatedLoad;
end;
ord(TProp.kvar):
begin
LoadSpecType := TLoadSpec.kW_kvar;
PFSpecified := FALSE;
kVARref := kVARbase;
end;// kW, kvar
{*** see set_xfkva, etc 21, 22: LoadSpectype := 3; // XFKVA*AllocationFactor, PF }
ord(TProp.xfkVA):
begin
LoadSpecType := TLoadSpec.ConnectedkVA_PF;
FAllocationFactor := FkVAAllocationFactor;
ComputeAllocatedLoad;
end;
ord(TProp.kwhdays):
begin
LoadSpecType := TLoadSpec.kWh_PF;
ComputeAllocatedLoad;
end;
ord(TProp.kVA):
LoadSpecType := TLoadSpec.kVA_PF; // kVA, PF
{*** see set_kwh, etc 28..30: LoadSpecType := 4; // kWh, days, cfactor, PF }
ord(TProp.ZIPV):
ZIPVset := True;
end;
inherited PropertySideEffects(Idx, previousIntVal);
end;
function TLoad.EndEdit(ptr: Pointer; const NumChanges: integer): Boolean;
begin
with TObj(ptr) do
begin
RecalcElementData;
YPrimInvalid := TRUE;
Exclude(Flags, Flg.EditionActive);
end;
Result := True;
end;
procedure TLoadObj.MakeLike(OtherPtr: Pointer);
var
Other: TObj;
i: Integer;
begin
inherited MakeLike(OtherPtr); // Take care of inherited class properties
Other := TObj(OtherPtr);
Connection := Other.Connection;
if Fnphases <> Other.Fnphases then
begin
FNphases := Other.Fnphases;
SetNCondsForConnection(self); // Forces reallocation of terminal stuff
Yorder := Fnconds * Fnterms;
YPrimInvalid := TRUE;
end;
kVLoadBase := Other.kVLoadBase;
Vbase := Other.Vbase;
VLowpu := Other.VLowpu;
Vminpu := Other.Vminpu;
Vmaxpu := Other.Vmaxpu;
VBaseLow := Other.VBaseLow;
Vbase95 := Other.Vbase95;
Vbase105 := Other.Vbase105;
kWBase := Other.kWBase;
kVAbase := Other.kVABase;
kvarBase := Other.kvarBase;
LoadSpecType := Other.LoadSpecType;
WNominal := Other.WNominal;
PFNominal := Other.PFNominal;
varNominal := Other.varNominal;
Rneut := Other.Rneut;
Xneut := Other.Xneut;
CVRshapeObj := Other.CVRshapeObj;
DailyShapeObj := Other.DailyShapeObj;
DutyShapeObj := Other.DutyShapeObj;
YearlyShapeObj := Other.YearlyShapeObj;
GrowthShapeObj := Other.GrowthShapeObj;
LoadClass := Other.LoadClass;
NumCustomers := Other.NumCustomers;
FLoadModel := Other.FLoadModel;
status := Other.status;
FkVAAllocationFactor := Other.FkVAAllocationFactor;
FConnectedkVA := Other.FConnectedkVA;
FCVRwattFactor := Other.FCVRwattFactor;
FCVRvarFactor := Other.FCVRvarFactor;
ShapeIsActual := Other.ShapeIsActual;
puSeriesRL := Other.puSeriesRL;
RelWeighting := Other.RelWeighting;
Reallocmem(InjCurrent, SizeOf(InjCurrent^[1]) * Yorder);
Reallocmem(FPhaseCurr, SizeOf(FPhaseCurr^[1]) * FNphases);
ZIPVset := Other.ZIPVset;
if ZIPVset then
for i := 1 to nZIPV do
ZIPV[i] := Other.ZIPV[i];
end;
constructor TLoadObj.Create(ParClass: TDSSClass; const SourceName: String);
begin
if ParClass = nil then Exit;
inherited create(ParClass);
Name := AnsiLowerCase(SourceName);
DSSObjType := ParClass.DSSClassType;
Fnphases := 3;
Fnconds := 4; // defaults to wye so it has a 4th conductor
Yorder := 0; // To trigger an initial allocation
Nterms := 1; // forces allocations
kWBase := 10.0;
kvarBase := 5.0;
PFNominal := 0.88;
kVABase := kWBase / PFNominal;
LoadSpecType := TLoadSpec.kW_PF;
Rneut := -1.0; // signify neutral is open
Xneut := 0.0;
YearlyShapeObj := NIL; // IF YearlyShapeobj = nil THEN the load alway stays nominal * global multipliers
DailyShapeObj := NIL; // IF DaillyShapeobj = nil THEN the load alway stays nominal * global multipliers
DutyShapeObj := NIL; // IF DutyShapeobj = nil THEN the load alway stays nominal * global multipliers
GrowthShapeObj := NIL; // IF grwothshapeobj = nil THEN the load alway stays nominal * global multipliers
CVRShapeObj := NIL;
Connection := TLoadConnection.Wye; // Wye (star)
FLoadModel := TLoadModel.ConstPQ; // changed from 2 RCD {easiest to solve}
LoadClass := 1;
NumCustomers := 1;
LastYear := 0;
FCVRwattFactor := 1.0;
FCVRvarFactor := 2.0;
RelWeighting := 1.0;
LastGrowthFactor := 1.0;
FkVAAllocationFactor := 0.5;
FAllocationFactor := FkVAAllocationFactor;
HasBeenAllocated := FALSE;
PFChanged := FALSE;
ShapeIsActual := FALSE;
PFSpecified := FALSE; // default to not specified by PF property
LoadSolutionCount := -1; // for keeping track of the present solution in Injcurrent calcs
OpenLoadSolutionCount := -1;
YPrimOpenCond := NIL;
FConnectedkVA := 0.0; // Loadspectype=3
FkWh := 0.0; // Loadspectype=4
FCfactor := 4.0;
FkWhDays := 30.0;
VminNormal := 0.0; // indicates for program to use Circuit quantities
VminEmerg := 0.0;
kVLoadBase := 12.47;
VBase := 7200.0;
VLowpu := 0.50;
VminPu := 0.95;
VMaxPU := 1.05;
VBaseLow := VLowpu * Vbase;
VBase95 := VminPu * Vbase;
VBase105 := VMaxPU * Vbase;
Yorder := Fnterms * Fnconds;
RandomMult := 1.0;
status := TLoadStatus.Variable;
FpuXHarm := 0.0; // zero signifies not specified.
FXRHarmRatio := 6.0;
FpuMean := 0.5;
FpuStdDev := 0.1;
UE_Factor := 0.0;
EEN_Factor := 0.0;
SpectrumObj := DSS.SpectrumClass.DefaultLoad; // override base class definition
HarmMag := NIL;
HarmAng := NIL;
puSeriesRL := 0.50;
FPhaseCurr := NIL; // storage for intermediate current computation
// allocated in Recalcelementdata
ZIPVset := False;
Reallocmem(InjCurrent, SizeOf(InjCurrent^[1]) * Yorder);
Reallocmem(FPhaseCurr, SizeOf(FPhaseCurr^[1]) * FNphases);
RecalcElementData;
end;
destructor TLoadObj.Destroy;
begin
if ParentClass = nil then Exit;
YPrimOpenCond.Free;
ReallocMem(HarmMag, 0);
ReallocMem(HarmAng, 0);
Reallocmem(FPhaseCurr, 0);
inherited Destroy;
end;
procedure TLoadObj.Randomize(Opt: Integer);
begin
case Opt of
0:
RandomMult := 1.0;
GAUSSIAN:
if Assigned(YearlyShapeObj) then
RandomMult := Gauss(YearlyShapeObj.Mean, YearlyShapeObj.StdDev)
else
RandomMult := Gauss(FpuMean, FpuStdDev);
UNIFORM:
RandomMult := Random; // number between 0 and 1.0
LOGNORMAL:
if Assigned(YearlyShapeObj) then
RandomMult := QuasiLognormal(YearlyShapeObj.Mean)
else
RandomMult := QuasiLognormal(FpuMean);
end;
end;
procedure TLoadObj.CalcDailyMult(Hr: Double);
begin
if DailyShapeObj <> NIL then
begin
ShapeFactor := DailyShapeObj.GetMultAtHour(Hr);
ShapeIsActual := DailyShapeObj.UseActual;
end
else
ShapeFactor := Cmplx(1.0, 1.0); // Default to no daily variation
end;
procedure TLoadObj.CalcDutyMult(Hr: Double);
begin
if DutyShapeObj <> NIL then
begin
ShapeFactor := DutyShapeObj.GetMultAtHour(Hr);
ShapeIsActual := DutyShapeObj.UseActual;
end
else
CalcDailyMult(Hr); // Default to Daily Mult IF no duty curve specified
end;
procedure TLoadObj.CalcYearlyMult(Hr: Double);
begin
// Yearly curve is assumed to be hourly only
if YearlyShapeObj <> NIL then
begin
ShapeFactor := YearlyShapeObj.GetMultAtHour(Hr);
ShapeIsActual := YearlyShapeObj.UseActual;
end
else
// Defaults to no variation
ShapeFactor := Cmplx(1.0, 1.0);
end;
procedure TLoadObj.CalcCVRMult(Hr: Double);
var
CVRFactor: Complex;
begin
// CVR curve is assumed to be used in a yearly simulation
if CVRShapeObj <> NIL then
begin
CVRFactor := CVRShapeObj.GetMultAtHour(Hr); {Complex}
FCVRWattFactor := CVRFactor.re;
FCVRvarFactor := CVRFactor.im;
end;
// Else FCVRWattFactor, etc. remain unchanged
end;
function TLoadObj.GrowthFactor(Year: Integer): Double;
begin
if Year = 0 then
LastGrowthFactor := 1.0 // default all to 1 in year 0 ; use base values
else
begin
if GrowthShapeObj = NIL then
LastGrowthFactor := Activecircuit.DefaultGrowthFactor
else
if Year <> LastYear then // Search growthcurve
LastGrowthFactor := GrowthShapeObj.GetMult(Year);
end;
Result := LastGrowthFactor; // for Now
end;
procedure TLoadObj.SetkWkvar(const PkW, Qkvar: Double);
begin
kWBase := PkW;
kvarbase := Qkvar;
if PFSpecified then
LoadSpecType := TLoadSpec.kW_PF
else
LoadSpecType := TLoadSpec.kW_kvar;
end;
procedure TLoadObj.SetNominalLoad;
var
Factor: Double;
begin
ShapeFactor := CDOUBLEONE;
ShapeIsActual := FALSE;
with ActiveCircuit.Solution do
if status = TLoadStatus.Fixed then
begin
Factor := GrowthFactor(Year); // For fixed loads, consider only growth factor
end
else
case Mode of
TSolveMode.SNAPSHOT,
TSolveMode.HARMONICMODE:
if status = TLoadStatus.Exempt then
Factor := GrowthFactor(Year)
else
Factor := ActiveCircuit.LoadMultiplier * GrowthFactor(Year);
TSolveMode.DAILYMODE:
begin
Factor := GrowthFactor(Year);
if status <> TLoadStatus.Exempt then
Factor := Factor * ActiveCircuit.LoadMultiplier;
CalcDailyMult(DynaVars.dblHour);
end;
TSolveMode.YEARLYMODE:
begin
Factor := ActiveCircuit.LoadMultiplier * GrowthFactor(Year);
CalcYearlyMult(DynaVars.dblHour);
if FLoadModel = TLoadModel.CVR then
CalcCVRMult(DynaVars.dblHour);
end;
TSolveMode.DUTYCYCLE:
begin
Factor := GrowthFactor(Year);
if status <> TLoadStatus.Exempt then
Factor := Factor * ActiveCircuit.LoadMultiplier;
CalcDutyMult(DynaVars.dblHour);
end;
TSolveMode.GENERALTIME,
TSolveMode.DYNAMICMODE:
begin
Factor := GrowthFactor(Year);
if status <> TLoadStatus.Exempt then
Factor := Factor * ActiveCircuit.LoadMultiplier;
// This mode allows use of one class of load shape
case ActiveCircuit.ActiveLoadShapeClass of
USEDAILY:
CalcDailyMult(DynaVars.dblHour);
USEYEARLY:
CalcYearlyMult(DynaVars.dblHour);
USEDUTY:
CalcDutyMult(DynaVars.dblHour);
else
ShapeFactor := CDOUBLEONE // default to 1 + j1 if not known
end;
end;
TSolveMode.MONTECARLO1:
begin
Randomize(RandomType);
Factor := RandomMult * GrowthFactor(Year);
if status <> TLoadStatus.Exempt then
Factor := Factor * ActiveCircuit.LoadMultiplier;
end;
TSolveMode.MONTECARLO2,
TSolveMode.MONTECARLO3,
TSolveMode.LOADDURATION1,
TSolveMode.LOADDURATION2:
begin
Factor := GrowthFactor(Year);
CalcDailyMult(DynaVars.dblHour);
if status <> TLoadStatus.Exempt then
Factor := Factor * ActiveCircuit.LoadMultiplier;
end;
TSolveMode.PEAKDAY:
begin
Factor := GrowthFactor(Year);
CalcDailyMult(DynaVars.dblHour);
end;
TSolveMode.AUTOADDFLAG:
Factor := GrowthFactor(Year); // Loadmult = 1.0 by default
else
Factor := GrowthFactor(Year) // defaults to Base kW * growth
end;
if ShapeIsActual then
begin
WNominal := 1000.0 * ShapeFactor.re / Fnphases;
varNominal := 0.0; // initialize for unity PF and check for change
if ShapeFactor.im <> 0.0 then // Qmult was specified
varNominal := 1000.0 * ShapeFactor.im / Fnphases
else
if PFSpecified and (PFNominal <> 1.0) then // Qmult not specified but PF was
begin // user specified the PF for this load
varNominal := WNominal * SQRT((1.0 / SQR(PFNominal) - 1));
if PFNominal < 0.0 then // watts and vare are in opposite directions
varNominal := -varNominal;
end;
end
else
begin
WNominal := 1000.0 * kWBase * Factor * ShapeFactor.re / Fnphases;
varNominal := 1000.0 * kvarBase * Factor * ShapeFactor.im / Fnphases;
end;
Yeq := Cmplx(WNominal, -VarNominal) / Sqr(Vbase);
if (Vminpu <> 0.0) then
Yeq95 := Yeq / sqr(Vminpu) // at 95% voltage
else
Yeq95 := CZERO;
if (Vmaxpu <> 0.0) then
Yeq105 := Yeq / sqr(Vmaxpu) // at 105% voltage
else
Yeq105 := Yeq;
if (Vmaxpu <> 0.0) then
Yeq105I := Yeq / Vmaxpu // at 105% voltage for Constant I ***Added by Celso & Paulo
else
Yeq105I := Yeq; // **Added by Celso & Paulo
// New code to help with convergence at low voltages
ILow := (Yeq * VbaseLow);
I95 := (Yeq95 * Vbase95);
M95 := (I95 - ILow) / (VBase95 - VBaseLow); // (I95 - ILow)/(Vbase95 - VbaseLow); ***Added by Celso & Paulo
IBase := (Yeq * VBase); // ***Added by Celso & Paulo
M95I := (IBase - ILow) / (VBase95 - VBaseLow); // (IBase - ILow)/(Vbase95 - VbaseLow); ***Added by Celso & Paulo
end;
procedure TLoadObj.RecalcElementData;
begin
VBaseLow := VLowpu * VBase;
VBase95 := VMinPu * VBase;
VBase105 := VMaxPu * VBase;
// Set kW and kvar from root values of kVA and PF
case LoadSpecType of
TLoadSpec.kW_PF:
begin
kvarBase := kWBase * SQRT(1.0 / SQR(PFNominal) - 1.0);
if PFNominal < 0.0 then
kvarBase := -kvarBase;
kVABase := SQRT(SQR(kWbase) + SQR(kvarBase));
end;
TLoadSpec.kW_kvar:
begin // need to set PFNominal
kVABase := SQRT(SQR(kWbase) + SQR(kvarBase));
if kVABase > 0.0 then
begin
PFNominal := kWBase / kVABase;
// If kW and kvar are different signs, PF is negative
if kvarbase <> 0.0 then
PFNominal := PFNominal * Sign(kWbase * kvarbase);