-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCAPI_Solution.pas
1060 lines (1034 loc) · 36.7 KB
/
CAPI_Solution.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 CAPI_Solution;
interface
uses
CAPI_Utils,
CAPI_Types;
function Solution_Get_Frequency(): Double; CDECL;
function Solution_Get_Hour(): Integer; CDECL;
function Solution_Get_Iterations(): Integer; CDECL;
function Solution_Get_LoadMult(): Double; CDECL;
function Solution_Get_MaxIterations(): Integer; CDECL;
function Solution_Get_Mode(): Integer; CDECL;
function Solution_Get_Number(): Integer; CDECL;
function Solution_Get_Random(): Integer; CDECL;
function Solution_Get_Seconds(): Double; CDECL;
function Solution_Get_StepSize(): Double; CDECL;
function Solution_Get_Tolerance(): Double; CDECL;
function Solution_Get_Year(): Integer; CDECL;
procedure Solution_Set_Frequency(Value: Double); CDECL;
procedure Solution_Set_Hour(Value: Integer); CDECL;
procedure Solution_Set_LoadMult(Value: Double); CDECL;
procedure Solution_Set_MaxIterations(Value: Integer); CDECL;
procedure Solution_Set_Mode(Mode: Integer); CDECL;
procedure Solution_Set_Number(Value: Integer); CDECL;
procedure Solution_Set_Random(Random: Integer); CDECL;
procedure Solution_Set_Seconds(Value: Double); CDECL;
procedure Solution_Set_StepSize(Value: Double); CDECL;
procedure Solution_Set_Tolerance(Value: Double); CDECL;
procedure Solution_Set_Year(Value: Integer); CDECL;
procedure Solution_Solve(); CDECL;
function Solution_Get_ModeID(): PAnsiChar; CDECL;
function Solution_Get_LoadModel(): Integer; CDECL;
procedure Solution_Set_LoadModel(Value: Integer); CDECL;
function Solution_Get_LDCurve(): PAnsiChar; CDECL;
procedure Solution_Set_LDCurve(const Value: PAnsiChar); CDECL;
function Solution_Get_pctGrowth(): Double; CDECL;
procedure Solution_Set_pctGrowth(Value: Double); CDECL;
function Solution_Get_AddType(): Integer; CDECL;
procedure Solution_Set_AddType(Value: Integer); CDECL;
function Solution_Get_GenkW(): Double; CDECL;
procedure Solution_Set_GenkW(Value: Double); CDECL;
function Solution_Get_GenPF(): Double; CDECL;
procedure Solution_Set_GenPF(Value: Double); CDECL;
function Solution_Get_Capkvar(): Double; CDECL;
procedure Solution_Set_Capkvar(Value: Double); CDECL;
function Solution_Get_Algorithm(): Integer; CDECL;
procedure Solution_Set_Algorithm(Value: Integer); CDECL;
function Solution_Get_ControlMode(): Integer; CDECL;
procedure Solution_Set_ControlMode(Value: Integer); CDECL;
function Solution_Get_GenMult(): Double; CDECL;
procedure Solution_Set_GenMult(Value: Double); CDECL;
function Solution_Get_DefaultDaily(): PAnsiChar; CDECL;
function Solution_Get_DefaultYearly(): PAnsiChar; CDECL;
procedure Solution_Set_DefaultDaily(const Value: PAnsiChar); CDECL;
procedure Solution_Set_DefaultYearly(const Value: PAnsiChar); CDECL;
procedure Solution_Get_EventLog(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
procedure Solution_Get_EventLog_GR(); CDECL;
function Solution_Get_dblHour(): Double; CDECL;
procedure Solution_Set_dblHour(Value: Double); CDECL;
procedure Solution_Set_StepsizeHr(Value: Double); CDECL;
procedure Solution_Set_StepsizeMin(Value: Double); CDECL;
function Solution_Get_ControlIterations(): Integer; CDECL;
function Solution_Get_MaxControlIterations(): Integer; CDECL;
procedure Solution_Sample_DoControlActions(); CDECL;
procedure Solution_Set_ControlIterations(Value: Integer); CDECL;
procedure Solution_Set_MaxControlIterations(Value: Integer); CDECL;
procedure Solution_CheckFaultStatus(); CDECL;
procedure Solution_SolveDirect(); CDECL;
procedure Solution_SolveNoControl(); CDECL;
procedure Solution_SolvePflow(); CDECL;
procedure Solution_SolvePlusControl(); CDECL;
procedure Solution_SolveSnap(); CDECL;
procedure Solution_CheckControls(); CDECL;
procedure Solution_InitSnap(); CDECL;
function Solution_Get_SystemYChanged(): TAPIBoolean; CDECL;
procedure Solution_BuildYMatrix(BuildOption, AllocateVI: Integer); CDECL;
procedure Solution_DoControlActions(); CDECL;
procedure Solution_SampleControlDevices(); CDECL;
function Solution_Get_Converged(): TAPIBoolean; CDECL;
procedure Solution_Set_Converged(Value: TAPIBoolean); CDECL;
function Solution_Get_Totaliterations(): Integer; CDECL;
function Solution_Get_MostIterationsDone(): Integer; CDECL;
function Solution_Get_ControlActionsDone(): TAPIBoolean; CDECL;
procedure Solution_Set_ControlActionsDone(Value: TAPIBoolean); CDECL;
procedure Solution_Cleanup(); CDECL;
procedure Solution_FinishTimeStep(); CDECL;
function Solution_Get_Process_Time(): Double; CDECL;
function Solution_Get_Total_Time(): Double; CDECL;
procedure Solution_Set_Total_Time(Value: Double); CDECL;
function Solution_Get_Time_of_Step(): Double; CDECL;
function Solution_Get_IntervalHrs(): Double; CDECL;
procedure Solution_Set_IntervalHrs(Value: Double); CDECL;
function Solution_Get_MinIterations(): Integer; CDECL;
procedure Solution_Set_MinIterations(Value: Integer); CDECL;
procedure Solution_SolveAll();cdecl;
procedure Solution_Get_IncMatrix(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
procedure Solution_Get_IncMatrix_GR(); CDECL;
procedure Solution_Get_Laplacian(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
procedure Solution_Get_Laplacian_GR(); CDECL;
procedure Solution_Get_BusLevels(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
procedure Solution_Get_BusLevels_GR(); CDECL;
procedure Solution_Get_IncMatrixRows(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
procedure Solution_Get_IncMatrixRows_GR(); CDECL;
procedure Solution_Get_IncMatrixCols(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
procedure Solution_Get_IncMatrixCols_GR(); CDECL;
implementation
uses
CAPI_Constants,
SysUtils,
DSSGlobals,
Math,
LoadShape,
Utilities,
YMatrix,
Solution,
SolutionAlgs,
ExecOptions,
Dynamics,
DSSClass,
DSSHelper;
//------------------------------------------------------------------------------
function Solution_Get_Frequency(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Frequency
end;
//------------------------------------------------------------------------------
function Solution_Get_Hour(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.DynaVars.intHour
end;
//------------------------------------------------------------------------------
function Solution_Get_Iterations(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Iteration
end;
//------------------------------------------------------------------------------
function Solution_Get_LoadMult(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.LoadMultiplier
end;
//------------------------------------------------------------------------------
function Solution_Get_MaxIterations(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.MaxIterations
end;
//------------------------------------------------------------------------------
function Solution_Get_Mode(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := Ord(DSSPrime.ActiveCircuit.Solution.Mode)
end;
//------------------------------------------------------------------------------
function Solution_Get_Number(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.NumberOfTimes
end;
//------------------------------------------------------------------------------
function Solution_Get_Random(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.RandomType
end;
//------------------------------------------------------------------------------
function Solution_Get_Seconds(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.dynavars.t
end;
//------------------------------------------------------------------------------
function Solution_Get_StepSize(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.dynavars.h
end;
//------------------------------------------------------------------------------
function Solution_Get_Tolerance(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.ConvergenceTolerance
end;
//------------------------------------------------------------------------------
function Solution_Get_Year(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Year
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Frequency(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Frequency := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Hour(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
DynaVars.intHour := Value;
Update_dblHour;
end;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_LoadMult(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.LoadMultiplier := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_MaxIterations(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.MaxIterations := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Mode(Mode: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
if (Mode >= Ord(Low(TSolveMode))) and (Mode <= Ord(High(TSolveMode))) then
DSSPrime.ActiveCircuit.Solution.Mode := TSolveMode(Mode)
else
DoSimpleMsg(DSSPrime, 'Invalid solution mode (%d).', [Mode], 5004);
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Number(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.NumberOfTimes := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Random(Random: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.RandomType := Random;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Seconds(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
DynaVars.t := Value;
Update_dblHour;
end;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_StepSize(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.dynavars.h := Value;
Solution_Set_IntervalHrs(Value / 3600.0); // Keep IntervalHrs in synch with time step size
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Tolerance(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.ConvergenceTolerance := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Year(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Year := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Solve(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Solve;
end;
//------------------------------------------------------------------------------
function Solution_Get_ModeID(): PAnsiChar; CDECL;
begin
Result := NIL;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSS_GetAsPAnsiChar(DSSPrime, DSSPrime.SolveModeEnum.OrdinalToString(ord(DSSPrime.ActiveCircuit.Solution.Mode)))
end;
//------------------------------------------------------------------------------
function Solution_Get_LoadModel(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.LoadModel
end;
//------------------------------------------------------------------------------
procedure Solution_Set_LoadModel(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
LoadModel := Value;
DefaultLoadModel := LoadModel;
end;
end;
//------------------------------------------------------------------------------
function Solution_Get_LDCurve(): PAnsiChar; CDECL;
begin
Result := NIL;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSS_GetAsPAnsiChar(DSSPrime, DSSPrime.ActiveCircuit.LoadDurCurve)
end;
//------------------------------------------------------------------------------
procedure Solution_Set_LDCurve(const Value: PAnsiChar); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit do
begin
LoadDurCurve := Value;
LoadDurCurveObj := DSSPrime.LoadShapeClass.Find(LoadDurCurve);
if LoadDurCurveObj = NIL then
DoSimpleMsg(DSSPrime, _('Load-Duration Curve not found.'), 5001);
end;
end;
//------------------------------------------------------------------------------
function Solution_Get_pctGrowth(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit do
begin
Result := (DefaultGrowthRate - 1.0) * 100.0;
Exit;
end;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_pctGrowth(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit do
begin
DefaultGrowthRate := 1.0 + Value / 100.0;
DefaultGrowthFactor := IntPower(DefaultGrowthRate, (Solution.Year - 1));
end;
end;
//------------------------------------------------------------------------------
function Solution_Get_AddType(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.AutoAddObj.AddType
end;
//------------------------------------------------------------------------------
procedure Solution_Set_AddType(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.AutoAddObj.AddType := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_GenkW(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.AutoAddObj.GenkW
end;
//------------------------------------------------------------------------------
procedure Solution_Set_GenkW(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.AutoAddObj.GenkW := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_GenPF(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.AutoAddObj.GenPF
end;
//------------------------------------------------------------------------------
procedure Solution_Set_GenPF(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.AutoAddObj.GenPF := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_Capkvar(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.AutoAddObj.Capkvar
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Capkvar(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.AutoAddObj.Capkvar := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_Algorithm(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Algorithm
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Algorithm(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Algorithm := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_ControlMode(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.ControlMode
end;
//------------------------------------------------------------------------------
procedure Solution_Set_ControlMode(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
ControlMode := Value;
DefaultControlMode := ControlMode;
end;
end;
//------------------------------------------------------------------------------
function Solution_Get_GenMult(): Double; CDECL;
begin
Result := 0.0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.GenMultiplier
end;
//------------------------------------------------------------------------------
procedure Solution_Set_GenMult(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.GenMultiplier := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_DefaultDaily(): PAnsiChar; CDECL;
begin
Result := NIL;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSS_GetAsPAnsiChar(DSSPrime, DSSPrime.ActiveCircuit.DefaultDailyShapeObj.Name)
end;
//------------------------------------------------------------------------------
function Solution_Get_DefaultYearly(): PAnsiChar; CDECL;
begin
Result := NIL;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSS_GetAsPAnsiChar(DSSPrime, DSSPrime.ActiveCircuit.DefaultYearlyShapeObj.Name)
end;
//------------------------------------------------------------------------------
procedure Solution_Set_DefaultDaily(const Value: PAnsiChar); CDECL;
var
TestLoadShapeObj: TLoadShapeObj;
begin
if InvalidCircuit(DSSPrime) then
Exit;
TestLoadShapeObj := DSSPrime.LoadShapeClass.Find(Value);
if TestLoadShapeObj = NIL then
Exit;
DSSPrime.ActiveCircuit.DefaultDailyShapeObj := TestLoadShapeObj;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_DefaultYearly(const Value: PAnsiChar); CDECL;
var
TestLoadShapeObj: TLoadShapeObj;
begin
if InvalidCircuit(DSSPrime) then
Exit;
TestLoadShapeObj := DSSPrime.LoadShapeClass.Find(Value);
if TestLoadShapeObj = NIL then
Exit;
DSSPrime.ActiveCircuit.DefaultYearlyShapeObj := TestLoadShapeObj;
end;
//------------------------------------------------------------------------------
procedure Solution_Get_EventLog(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
var
Result: PPAnsiCharArray0;
i: Integer;
begin
if InvalidCircuit(DSSPrime) then
begin
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;
Result := DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, DSSPrime.EventStrings.Count);
for i := 0 to DSSPrime.EventStrings.Count - 1 do
begin
Result[i] := DSS_CopyStringAsPChar(DSSPrime.EventStrings.Strings[i]);
end;
end;
procedure Solution_Get_EventLog_GR(); CDECL;
// Same as Solution_Get_EventLog but uses global result (GR) pointers
begin
Solution_Get_EventLog(DSSPrime.GR_DataPtr_PPAnsiChar, @DSSPrime.GR_Counts_PPAnsiChar[0])
end;
//------------------------------------------------------------------------------
function Solution_Get_dblHour(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.DynaVars.dblHour;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_dblHour(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
DynaVars.intHour := Trunc(Value);
DynaVars.dblHour := Value;
Dynavars.t := (Value - DynaVars.intHour) * 3600.0;
end;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_StepsizeHr(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Dynavars.h := Value * 3600.0;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_StepsizeMin(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Dynavars.h := Value * 60.0;
end;
//------------------------------------------------------------------------------
function Solution_Get_ControlIterations(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.ControlIteration;
end;
//------------------------------------------------------------------------------
function Solution_Get_MaxControlIterations(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.MaxControlIterations;
end;
//------------------------------------------------------------------------------
procedure Solution_Sample_DoControlActions(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Sample_DoControlActions;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_ControlIterations(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.ControlIteration := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_MaxControlIterations(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.MaxControlIterations := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_CheckFaultStatus(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Check_Fault_Status;
end;
//------------------------------------------------------------------------------
procedure Solution_SolveDirect(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.SolveDirect;
end;
//------------------------------------------------------------------------------
procedure Solution_SolveNoControl(); CDECL;
{Solves without checking controls}
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.SolveCircuit;
end;
//------------------------------------------------------------------------------
procedure Solution_SolvePflow(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.DoPflowSolution;
end;
//------------------------------------------------------------------------------
procedure Solution_SolvePlusControl(); CDECL;
{One Pass Through the solution and then dispatches controls}
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit.Solution do
begin
SolveCircuit;
CheckControls;
end;
end;
//------------------------------------------------------------------------------
procedure Solution_SolveSnap(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.SolveSnap;
end;
//------------------------------------------------------------------------------
procedure Solution_CheckControls(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.CheckControls;
end;
//------------------------------------------------------------------------------
procedure Solution_InitSnap(); CDECL;
{Initi some things that are done at the beginning of a snapshot solve}
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.SnapShotInit;
end;
//------------------------------------------------------------------------------
function Solution_Get_SystemYChanged(): TAPIBoolean; CDECL;
begin
Result := False;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.SystemYChanged;
end;
//------------------------------------------------------------------------------
procedure Solution_BuildYMatrix(BuildOption, AllocateVI: Integer); CDECL;
{
Build Options
1 = Series elements only
2 = Whole Y matrix
AllocateVI
TRUE: Reallocate VI
FALSE: Do not Reallocate VI; leave as is
}
begin
if InvalidCircuit(DSSPrime) then
Exit;
Ymatrix.BuildYMatrix(DSSPrime, BuildOption, AllocateVI <> 0)
end;
//------------------------------------------------------------------------------
procedure Solution_DoControlActions(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.DoControlActions;
end;
//------------------------------------------------------------------------------
procedure Solution_SampleControlDevices(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.SampleControlDevices;
end;
//------------------------------------------------------------------------------
function Solution_Get_Converged(): TAPIBoolean; CDECL;
begin
Result := False;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Issolved;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Converged(Value: TAPIBoolean); CDECL;
{Set the flag directly to force its setting}
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.ConvergedFlag := Value;
DSSPrime.ActiveCircuit.Issolved := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_Totaliterations(): Integer; CDECL;
// Same as Iterations interface
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Iteration
end;
//------------------------------------------------------------------------------
function Solution_Get_MostIterationsDone(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.MostIterationsDone
end;
//------------------------------------------------------------------------------
function Solution_Get_ControlActionsDone(): TAPIBoolean; CDECL;
begin
Result := False;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.ControlActionsDone;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_ControlActionsDone(Value: TAPIBoolean); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.ControlActionsDone := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_Cleanup(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.EndOfTimeStepCleanup();
end;
//------------------------------------------------------------------------------
procedure Solution_FinishTimeStep(); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
with DSSPrime.ActiveCircuit, DSSPrime.ActiveCircuit.Solution do
begin
DSSPrime.MonitorClass.SampleAll(); // Make all monitors take a sample
EndOfTimeStepCleanup();
Increment_time();
// DefaultHourMult := DefaultDailyShapeObj.getmult(TDynamicsrec.dblHour);
end;
end;
//------------------------------------------------------------------------------
function Solution_Get_Process_Time(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Time_Solve;
end;
//------------------------------------------------------------------------------
function Solution_Get_Total_Time(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Total_Time;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_Total_Time(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.Total_Time := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_Time_of_Step(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.Time_Step;
end;
//------------------------------------------------------------------------------
function Solution_Get_IntervalHrs(): Double; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.IntervalHrs;
end;
//------------------------------------------------------------------------------
procedure Solution_Set_IntervalHrs(Value: Double); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.IntervalHrs := Value;
end;
//------------------------------------------------------------------------------
function Solution_Get_MinIterations(): Integer; CDECL;
begin
Result := 0;
if InvalidCircuit(DSSPrime) then
Exit;
Result := DSSPrime.ActiveCircuit.Solution.MinIterations
end;
//------------------------------------------------------------------------------
procedure Solution_Set_MinIterations(Value: Integer); CDECL;
begin
if InvalidCircuit(DSSPrime) then
Exit;
DSSPrime.ActiveCircuit.Solution.MinIterations := Value;
end;
//------------------------------------------------------------------------------
procedure Solution_SolveAll();cdecl;
{$IFDEF DSS_CAPI_PM}
var
i : Integer;
PMParent: TDSSContext;
begin
PMParent := DSSPrime.GetPrime();
for i := 0 to High(PMParent.Children) do
begin
PMParent.ActiveChild := PMParent.Children[i];
DSSPrime.CmdResult := DoSetCmd(PMParent.Children[i], 1);
end;
{$ELSE}
begin
DoSimpleMsg(DSSPrime, _('Parallel machine functions were not compiled'), 7983);
{$ENDIF}
end;
//------------------------------------------------------------------------------
procedure Solution_Get_Laplacian(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
var
Result: PIntegerArray0;
i,
Counter,
IMIdx,
ArrSize: Integer;
begin
if (not InvalidCircuit(DSSPrime)) and (DSSPrime.ActiveCircuit.Solution.Laplacian <> NIL) then
begin
with DSSPrime.ActiveCircuit.Solution do
begin
ArrSize := Laplacian.NZero * 3;
Result := DSS_RecreateArray_PInteger(ResultPtr, ResultCount, (ArrSize) + 1);
Counter := 0;
IMIdx := 0;
while IMIdx < ArrSize do
begin
for i := 0 to 2 do
begin
Result[IMIdx] := Laplacian.data[Counter][i];
inc(IMIdx)
end;
inc(Counter)
end;
Exit;
end;
end;
DefaultResult(ResultPtr, ResultCount);
end;
procedure Solution_Get_Laplacian_GR(); CDECL;
// Same as Solution_Get_Laplacian but uses global result (GR) pointers
begin
Solution_Get_Laplacian(DSSPrime.GR_DataPtr_PInteger, @DSSPrime.GR_Counts_PInteger[0])
end;
//------------------------------------------------------------------------------
procedure Solution_Get_IncMatrix(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
var
Result: PIntegerArray0;
i,
Counter,
IMIdx,
ArrSize: Integer;
begin
if (not InvalidCircuit(DSSPrime)) and (DSSPrime.ActiveCircuit.Solution.IncMat <> NIL) then
begin
with DSSPrime.ActiveCircuit.Solution do
begin
ArrSize := IncMat.NZero * 3;
Result := DSS_RecreateArray_PInteger(ResultPtr, ResultCount, ArrSize + 1); // TODO: remove +1? Left for compatibility with the official version
Counter := 0;
IMIdx := 0;
while IMIdx < ArrSize do
begin
for i := 0 to 2 do
begin
Result[IMIdx] := IncMat.data[Counter][i];
inc(IMIdx)
end;
inc(Counter)
end;
Exit;
end;
end;
DefaultResult(ResultPtr, ResultCount);
end;
procedure Solution_Get_IncMatrix_GR(); CDECL;
// Same as Solution_Get_IncMatrix but uses global result (GR) pointers
begin
Solution_Get_IncMatrix(DSSPrime.GR_DataPtr_PInteger, @DSSPrime.GR_Counts_PInteger[0])
end;
//------------------------------------------------------------------------------
procedure Solution_Get_BusLevels(var ResultPtr: PInteger; ResultCount: PAPISize); CDECL;
begin
if InvalidCircuit(DSSPrime) then
begin
DefaultResult(ResultPtr, ResultCount);
Exit;
end;
with DSSPrime.ActiveCircuit.Solution do
begin
DSS_RecreateArray_PInteger(ResultPtr, ResultCount, length(Inc_Mat_Levels));
Move(Inc_Mat_levels[0], ResultPtr^, length(Inc_Mat_Levels) * SizeOf(Integer));
Exit;
end;
end;
procedure Solution_Get_BusLevels_GR(); CDECL;
// Same as Solution_Get_BusLevels but uses global result (GR) pointers
begin
Solution_Get_BusLevels(DSSPrime.GR_DataPtr_PInteger, @DSSPrime.GR_Counts_PInteger[0])
end;
//------------------------------------------------------------------------------
procedure Solution_Get_IncMatrixRows(var ResultPtr: PPAnsiChar; ResultCount: PAPISize); CDECL;
var
Result: PPAnsiCharArray0;
IMIdx,
ArrSize: Integer;
begin
if InvalidCircuit(DSSPrime) or (DSSPrime.ActiveCircuit.Solution.Inc_Mat_Rows = NIL) then
begin
DefaultResult(ResultPtr, ResultCount, '');
Exit;
end;
with DSSPrime.ActiveCircuit.Solution do
begin
ArrSize := length(Inc_Mat_Rows);
Result := DSS_RecreateArray_PPAnsiChar(ResultPtr, ResultCount, ArrSize);