-
Notifications
You must be signed in to change notification settings - Fork 109
/
underground_line.cpp
1522 lines (1310 loc) · 46.5 KB
/
underground_line.cpp
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
/** $Id: underground_line.cpp 1182 2008-12-22 22:08:36Z dchassin $
Copyright (C) 2008 Battelle Memorial Institute
@file underground_line.cpp
@addtogroup underground_line
@ingroup line
@{
**/
//3.2
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#include "line.h"
CLASS* underground_line::oclass = nullptr;
CLASS* underground_line::pclass = nullptr;
underground_line::underground_line(MODULE *mod) : line(mod)
{
if(oclass == nullptr)
{
pclass = line::oclass;
oclass = gl_register_class(mod,"underground_line",sizeof(underground_line),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT|PC_AUTOLOCK);
if (oclass==nullptr)
throw "unable to register class underground_line";
else
oclass->trl = TRL_PROVEN;
if(gl_publish_variable(oclass,
PT_INHERIT, "line",
NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
if (gl_publish_function(oclass, "create_fault", (FUNCTIONADDR)create_fault_ugline)==nullptr)
GL_THROW("Unable to publish fault creation function");
if (gl_publish_function(oclass, "fix_fault", (FUNCTIONADDR)fix_fault_ugline)==nullptr)
GL_THROW("Unable to publish fault restoration function");
if (gl_publish_function(oclass, "clear_fault", (FUNCTIONADDR)clear_fault_ugline)==nullptr)
GL_THROW("Unable to publish fault clearing function");
//Publish deltamode functions
if (gl_publish_function(oclass, "interupdate_pwr_object", (FUNCTIONADDR)interupdate_link)==nullptr)
GL_THROW("Unable to publish underground line deltamode function");
if (gl_publish_function(oclass, "recalc_distribution_line", (FUNCTIONADDR)recalc_underground_line)==nullptr)
GL_THROW("Unable to publish underground line recalc function");
//Publish restoration-related function (current update)
if (gl_publish_function(oclass, "update_power_pwr_object", (FUNCTIONADDR)updatepowercalc_link)==nullptr)
GL_THROW("Unable to publish underground line external power calculation function");
if (gl_publish_function(oclass, "check_limits_pwr_object", (FUNCTIONADDR)calculate_overlimit_link)==nullptr)
GL_THROW("Unable to publish underground line external power limit calculation function");
if (gl_publish_function(oclass, "perform_current_calculation_pwr_link", (FUNCTIONADDR)currentcalculation_link)==nullptr)
GL_THROW("Unable to publish underground line external current calculation function");
}
}
int underground_line::create(void)
{
int result = line::create();
return result;
}
int underground_line::init(OBJECT *parent)
{
double *temp_rating_value = nullptr;
double temp_rating_continuous = 10000.0;
double temp_rating_emergency = 20000.0;
char index;
int type_A, type_B, type_C, type_N;
int cond_present, cond_present_CN, cable_types_value;
OBJECT *temp_obj;
OBJECT *obj = OBJECTHDR(this);
int result = line::init(parent);
//Check for deferred
if (result == 2)
return 2; //Return the deferment - no sense doing everything else!
if (!configuration)
throw "no underground line configuration specified.";
/* TROUBLESHOOT
No underground line configuration was specified. Please use object line_configuration
with appropriate values to specify an underground line configuration
*/
if (!gl_object_isa(configuration, "line_configuration"))
throw "invalid line configuration for underground line";
/* TROUBLESHOOT
The object specified as the configuration for the underground line is not a valid
configuration object. Please ensure you have a line_configuration object selected.
*/
//Test the phases
line_configuration *config = OBJECTDATA(configuration, line_configuration);
type_A = test_phases(config,'A');
type_B = test_phases(config,'B');
type_C = test_phases(config,'C');
type_N = test_phases(config,'N'); //Return value not used right now
//Figure out how many conductors we expected
cond_present = 0;
if (config->phaseA_conductor != nullptr)
cond_present++;
if (config->phaseB_conductor != nullptr)
cond_present++;
if (config->phaseC_conductor != nullptr)
cond_present++;
//Form the cable-types value (add up tests)
cable_types_value = type_A + type_B + type_C;
//Form the "CN test value"
cond_present_CN = cond_present * 10;
//Check for "consistency"
if ((cable_types_value != cond_present) && (cable_types_value != cond_present_CN))
{
GL_THROW("Underground_line:%d %s - Cable types specified in configuration are not consistent!",obj->id,(obj->name ? obj->name : "Unnamed"));
/* TROUBLESHOOT
An underground_line object needs to have all the same cable-tpe in the configuration (e.g., tape-sheild or concentric neutral). Please
correct this.
*/
}
if ((!config->line_spacing || !gl_object_isa(config->line_spacing,const_cast<char*>( "line_spacing"))) && config->impedance11 == 0.0 && config->impedance22 == 0.0 && config->impedance33 == 0.0)
throw "invalid or missing line spacing on underground line";
/* TROUBLESHOOT
The configuration object for the underground line is missing the line_spacing configuration
or the item specified in that location is invalid.
*/
recalc();
//Values are populated now - populate link ratings parameter
if (config->phaseA_conductor != nullptr || config->phaseB_conductor != nullptr || config->phaseC_conductor != nullptr) {
for (index=0; index<3; index++)
{
if (index==0)
{
temp_obj = config->phaseA_conductor;
}
else if (index==1)
{
temp_obj = config->phaseB_conductor;
}
else //Must be 2
{
temp_obj = config->phaseC_conductor;
}
//See if Phase exists
if (temp_obj != nullptr)
{
//Get continuous - summer
temp_rating_value = get_double(temp_obj,"rating.summer.continuous");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_continuous > *temp_rating_value)
{
temp_rating_continuous = *temp_rating_value;
}
}
//Get continuous - winter
temp_rating_value = get_double(temp_obj,"rating.winter.continuous");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_continuous > *temp_rating_value)
{
temp_rating_continuous = *temp_rating_value;
}
}
//Now get emergency - summer
temp_rating_value = get_double(temp_obj,"rating.summer.emergency");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_emergency > *temp_rating_value)
{
temp_rating_emergency = *temp_rating_value;
}
}
//Now get emergency - winter
temp_rating_value = get_double(temp_obj,"rating.winter.emergency");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_emergency > *temp_rating_value)
{
temp_rating_emergency = *temp_rating_value;
}
}
//Populate link array
link_rating[0][index] = temp_rating_continuous;
link_rating[1][index] = temp_rating_emergency;
}//End Phase valid
}//End FOR
}
else {
temp_obj = configuration;
//See if configuration exists
if (temp_obj != nullptr)
{
//Get continuous - summer
temp_rating_value = get_double(temp_obj,"rating.summer.continuous");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_continuous > *temp_rating_value)
{
temp_rating_continuous = *temp_rating_value;
}
}
//Get continuous - winter
temp_rating_value = get_double(temp_obj,"rating.winter.continuous");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_continuous > *temp_rating_value)
{
temp_rating_continuous = *temp_rating_value;
}
}
//Now get emergency - summer
temp_rating_value = get_double(temp_obj,"rating.summer.emergency");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_emergency > *temp_rating_value)
{
temp_rating_emergency = *temp_rating_value;
}
}
//Now get emergency - winter
temp_rating_value = get_double(temp_obj,"rating.winter.emergency");
//Check if NULL
if (temp_rating_value != nullptr)
{
//Update - if necessary
if (temp_rating_emergency > *temp_rating_value)
{
temp_rating_emergency = *temp_rating_value;
}
}
//Populate link array
link_rating[0][0] = link_rating[0][1] = link_rating[0][2] = temp_rating_continuous;
link_rating[1][0] = link_rating[1][1] = link_rating[1][2] = temp_rating_emergency;
}
}
return result;
}
void underground_line::recalc(void)
{
line_configuration *config = OBJECTDATA(configuration, line_configuration);
gld::complex Zabc_mat[3][3], Yabc_mat[3][3];
bool not_TS_CN = false;
bool is_CN_ug_line = false;
OBJECT *obj = OBJECTHDR(this);
// Zero out Zabc_mat and Yabc_mat. Un-needed phases will be left zeroed.
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Zabc_mat[i][j] = 0.0;
Yabc_mat[i][j] = 0.0;
}
}
// Set auxillary matrices
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
a_mat[i][j] = 0.0;
d_mat[i][j] = 0.0;
A_mat[i][j] = 0.0;
c_mat[i][j] = 0.0;
B_mat[i][j] = b_mat[i][j];
}
}
if (config->impedance11 != 0 || config->impedance22 != 0 || config->impedance33 != 0)
{
// Load Zabc_mat and Yabc_mat based on the z11-z33 and c11-c33 line config parameters
load_matrix_based_configuration(Zabc_mat, Yabc_mat);
//Other auxilliary by phase
if (has_phase(PHASE_A))
{
a_mat[0][0] = 1.0;
d_mat[0][0] = 1.0;
A_mat[0][0] = 1.0;
}
if (has_phase(PHASE_B))
{
a_mat[1][1] = 1.0;
d_mat[1][1] = 1.0;
A_mat[1][1] = 1.0;
}
if (has_phase(PHASE_C))
{
a_mat[2][2] = 1.0;
d_mat[2][2] = 1.0;
A_mat[2][2] = 1.0;
}
}
else
{
double dia_od1, dia_od2, dia_od3;
int16 strands_4, strands_5, strands_6;
double rad_14, rad_25, rad_36;
double dia[7], res[7], gmr[7], gmrcn[3], rcn[3], gmrs[3], ress[3], tap[8];
double d[7][7];
double perm_A, perm_B, perm_C, c_an, c_bn, c_cn, temp_denom;
gld::complex cap_freq_coeff;
gld::complex z[7][7],z_ts[3][3]; //, z_ij[3][3], z_in[3][3], z_nj[3][3], z_nn[3][3], z_abc[3][3];
double freq_coeff_real, freq_coeff_imag, freq_additive_term;
double miles = length / 5280.0;
gld::complex test;///////////////
//Calculate coefficients for self and mutual impedance - incorporates frequency values
//Per Kersting (4.39) and (4.40) - coefficients end up same as OHLs
if (enable_frequency_dependence) //See which frequency to use
{
freq_coeff_real = 0.00158836*current_frequency;
freq_coeff_imag = 0.00202237*current_frequency;
freq_additive_term = log(EARTH_RESISTIVITY/current_frequency)/2.0 + 7.6786;
}
else
{
freq_coeff_real = 0.00158836*nominal_frequency;
freq_coeff_imag = 0.00202237*nominal_frequency;
freq_additive_term = log(EARTH_RESISTIVITY/nominal_frequency)/2.0 + 7.6786;
}
#define DIA(i) (dia[i - 1])
#define RES(i) (res[i - 1])
#define RES_S(i) (ress[i - 4])
#define GMR_S(i) (gmrs[i - 4])
#define GMR(i) (gmr[i - 1])
#define GMRCN(i) (gmrcn[i - 4])
#define RCN(i) (rcn[i - 4])
#define D(i, j) (d[i - 1][j - 1])
#define Z(i, j) (z[i - 1][j - 1])
#define Z_TS(i, j) (z_ts[i - 1][j - 1])
#define TAP(i) (tap[i - 1])
#define UG_GET(ph, name) (has_phase(PHASE_##ph) && config->phase##ph##_conductor ? \
OBJECTDATA(config->phase##ph##_conductor, underground_line_conductor)->name : 0)
dia_od1 = UG_GET(A, outer_diameter);
dia_od2 = UG_GET(B, outer_diameter);
dia_od3 = UG_GET(C, outer_diameter);
GMR(1) = UG_GET(A, conductor_gmr);
GMR(2) = UG_GET(B, conductor_gmr);
GMR(3) = UG_GET(C, conductor_gmr);
GMR(7) = UG_GET(N, conductor_gmr);
DIA(1) = UG_GET(A, conductor_diameter);
DIA(2) = UG_GET(B, conductor_diameter);
DIA(3) = UG_GET(C, conductor_diameter);
DIA(7) = UG_GET(N, conductor_diameter);
RES(1) = UG_GET(A, conductor_resistance);
RES(2) = UG_GET(B, conductor_resistance);
RES(3) = UG_GET(C, conductor_resistance);
RES(7) = UG_GET(N, conductor_resistance);
GMR(4) = UG_GET(A, neutral_gmr);
GMR(5) = UG_GET(B, neutral_gmr);
GMR(6) = UG_GET(C, neutral_gmr);
GMR_S(4) = UG_GET(A, shield_gmr);
GMR_S(5) = UG_GET(B, shield_gmr);
GMR_S(6) = UG_GET(C, shield_gmr);
DIA(4) = UG_GET(A, neutral_diameter);
DIA(5) = UG_GET(B, neutral_diameter);
DIA(6) = UG_GET(C, neutral_diameter);
RES(4) = UG_GET(A, neutral_resistance);
RES(5) = UG_GET(B, neutral_resistance);
RES(6) = UG_GET(C, neutral_resistance);
RES_S(4) = UG_GET(A, shield_resistance);
RES_S(5) = UG_GET(B, shield_resistance);
RES_S(6) = UG_GET(C, shield_resistance);
TAP(1) = UG_GET(A, shield_thickness);
TAP(2) = UG_GET(B, shield_thickness);
TAP(3) = UG_GET(C, shield_thickness);
TAP(4) = UG_GET(N, shield_thickness);
TAP(5) = UG_GET(A, shield_diameter);
TAP(6) = UG_GET(B, shield_diameter);
TAP(7) = UG_GET(C, shield_diameter);
TAP(8) = UG_GET(N, shield_diameter);
strands_4 = UG_GET(A, neutral_strands);
strands_5 = UG_GET(B, neutral_strands);
strands_6 = UG_GET(C, neutral_strands);
if(GMR_S(4) == 0 && GMR_S(5) == 0 && GMR_S(6) == 0){
rad_14 = (dia_od1 - DIA(4)) / 24.0;
rad_25 = (dia_od2 - DIA(5)) / 24.0;
rad_36 = (dia_od3 - DIA(6)) / 24.0;
}
else
{
rad_14 = 0.0;
rad_25 = 0.0;
rad_36 = 0.0;
}
RCN(4) = has_phase(PHASE_A) && strands_4 > 0 ? RES(4) / strands_4 : 0.0;
RCN(5) = has_phase(PHASE_B) && strands_5 > 0 ? RES(5) / strands_5 : 0.0;
RCN(6) = has_phase(PHASE_C) && strands_6 > 0 ? RES(6) / strands_6 : 0.0;
//Concentric neutral code
GMRCN(4) = !(has_phase(PHASE_A) && strands_4 > 0) ? 0.0 :
pow(GMR(4) * strands_4 * pow(rad_14, (strands_4 - 1)), (1.0 / strands_4));
GMRCN(5) = !(has_phase(PHASE_B) && strands_5 > 0) ? 0.0 :
pow(GMR(5) * strands_5 * pow(rad_25, (strands_5 - 1)), (1.0 / strands_5));
GMRCN(6) = !(has_phase(PHASE_C) && strands_6 > 0) ? 0.0 :
pow(GMR(6) * strands_6 * pow(rad_36, (strands_6 - 1)), (1.0 / strands_6));
//Check to see if this is not a tape-shielded line or a concentric neutral line
if (GMR(4) == 0.0 && GMR(5) == 0.0 && GMR(6) == 0.0 && GMR_S(4) == 0.0 && GMR_S(5) == 0.0 && GMR_S(6) == 0.0){// the gmr for the neutral strands and the tape shield is zero this is just an insulated underground cable
not_TS_CN = true;
}
else //Implies it IS a CN or TS version, figure out which
{
if ((GMR_S(4) == 0.0) && (GMR_S(5) == 0.0) && (GMR_S(6) == 0.0))
{
is_CN_ug_line = true;
}
else //Just assume tape shield
{
is_CN_ug_line = false;
rad_14 = (TAP(5) - TAP(1))/2;
rad_25 = (TAP(6) - TAP(2))/2;
rad_36 = (TAP(7) - TAP(3))/2;
}
}
//Capacitance stuff, if desired
if (use_line_cap && !not_TS_CN)
{
//Extract relative permitivitty
perm_A = UG_GET(A, insulation_rel_permitivitty);
perm_B = UG_GET(B, insulation_rel_permitivitty);
perm_C = UG_GET(C, insulation_rel_permitivitty);
//Define the scaling constant for frequency, distance, and microS
if (enable_frequency_dependence) //See which frequency to use
{
cap_freq_coeff = gld::complex(0,(2.0*PI*current_frequency*0.000001*miles));
}
else
{
cap_freq_coeff = gld::complex(0,(2.0*PI*nominal_frequency*0.000001*miles));
}
}
#define DIST(ph1, ph2) (has_phase(PHASE_##ph1) && has_phase(PHASE_##ph2) && config->line_spacing ? \
OBJECTDATA(config->line_spacing, line_spacing)->distance_##ph1##to##ph2 : 0.0)
D(1, 2) = DIST(A, B);
D(1, 3) = DIST(A, C);
D(1, 4) = rad_14;
if(GMR_S(4) > 0)
D(1, 4) = GMR_S(4);
D(1, 5) = D(1, 2);
D(1, 6) = D(1, 3);
D(1, 7) = DIST(A, N);
D(2, 1) = D(1, 2);
D(2, 3) = DIST(B, C);
D(2, 4) = D(2, 1);
D(2, 5) = rad_25;
if(GMR_S(5) > 0)
D(2, 5) = GMR_S(5);
D(2, 6) = D(2, 3);
D(2, 7) = DIST(B, N);
D(3, 1) = D(1, 3);
D(3, 2) = D(2, 3);
D(3, 4) = D(3, 1);
D(3, 5) = D(3, 2);
D(3, 6) = rad_36;
if(GMR_S(6) > 0)
D(3, 6) = GMR_S(6);
D(3, 7) = DIST(C, N);
D(4, 1) = D(1, 4);
D(4, 2) = D(2, 4);
D(4, 3) = D(3, 4);
D(4, 5) = D(1, 2);
D(4, 6) = D(1, 3);
D(4, 7) = D(1, 7);
D(5, 1) = D(1, 5);
D(5, 2) = D(2, 5);
D(5, 3) = D(3, 5);
D(5, 4) = D(4, 5);
D(5, 6) = D(2, 3);
D(5, 7) = D(2, 7);
D(6, 1) = D(1, 6);
D(6, 2) = D(2, 6);
D(6, 3) = D(3, 6);
D(6, 4) = D(4, 6);
D(6, 5) = D(5, 6);
D(6, 7) = D(3, 7);
D(7, 1) = D(1, 7);
D(7, 2) = D(2, 7);
D(7, 3) = D(3, 7);
D(7, 4) = D(1, 7);
D(7, 5) = D(2, 7);
D(7, 6) = D(3, 7);
#undef DIST
#undef DIA
#undef UG_GET
if (is_CN_ug_line) {
#define Z_GMR(i) (GMR(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real + RES(i), freq_coeff_imag * (log(1.0 / GMR(i)) + freq_additive_term)))
#define Z_GMRCN(i) (GMRCN(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real + RCN(i), freq_coeff_imag * (log(1.0 / GMRCN(i)) + freq_additive_term)))
#define Z_GMR_S(i) (GMR_S(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real + RES_S(i), freq_coeff_imag*(log(1.0/GMR_S(i)) + freq_additive_term)))
#define Z_DIST(i, j) (D(i, j) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real, freq_coeff_imag * (log(1.0 / D(i, j)) + freq_additive_term)))
for (int i = 1; i < 8; i++) {
for (int j = 1; j < 8; j++) {
if (i == j) {
if (i > 3 && i != 7){
Z(i, j) = Z_GMRCN(i);
if(Z_GMR_S(i) > 0 && Z(i, j) == 0)
Z(i, j) = Z_GMR_S(i);
test=Z_GMRCN(i);
}
else
Z(i, j) = Z_GMR(i);
}
else
Z(i, j) = Z_DIST(i, j);
}
}
#undef Z_GMR_S //Make the compiler happy
} else {
// see example: 4.4
#define Z_GMR(i) (GMR(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real + RES(i), freq_coeff_imag * (log(1.0 / GMR(i)) + freq_additive_term)))
//Notes for above #define: z11, z22, z33 - self conductor; z77 - self neutral. RES(i=4,5,6) is neutral_resitance, GMR(i=4,5,6) is neutral GMR. For z77, neutral_resistance to be added in real term
//so pick RES(i) such that is is neutral_resistance. For imaginaray temrm, neutral_gmr to be used in ln(1/GMRn) so pick GMR(i) such that it is neutral GMR
#define Z_GMR_S_SELF(i) (GMR_S(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real+RES_S(i), freq_coeff_imag*(log(1.0/GMR_S(i)) + freq_additive_term))) //z44, z55, z66 - self tape
#ifdef Z_GMR_S
#undef Z_GMR_S
#endif
#define Z_GMR_S(i) (GMR_S(i) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real, freq_coeff_imag*(log(1.0/GMR_S(i)) + freq_additive_term))) //z14, z25, z36 - mutual - conductor-tape
#define Z_DIST(i, j) (D(i, j) == 0.0 ? gld::complex(0.0) : gld::complex(freq_coeff_real, freq_coeff_imag * (log(1.0 / D(i, j)) + freq_additive_term)))
//Notes for above #define: z12,z13,z15,z16,z17,z21,z23,z24,z26,z27,z31,z32,z34,z35,z37,z41,z42,z43,z45,z46,z47,z51-z54,z36,z57,z61-z65,z67,z71-z76 mutual/coupling
for (int i = 1; i < 8; i++) {
for (int j = 1; j < 8; j++) {
if (i == j) {
if (i > 3 && i != 7){
Z(i, j) = Z_GMR_S_SELF(i); //44,55,66 //there is 'test' in this if for CN Z formation. is it needed here?
}
//else if (i == 7) {
//if (has_phase(PHASE_A)) {
//Z(i, j) = Z_GMR(4); //z77 for phase-A conductor
//}
//else if (has_phase(PHASE_B)) {
//Z(i, j) = Z_GMR(5); //z77 for phase-B conductor
//}
//else if (has_phase(PHASE_C)) {
//Z(i, j) = Z_GMR(6); //z77 for phase-C conductor
//}
//}
else
Z(i, j) = Z_GMR(i); //11,22,33,77
}
else {
if ((i == 1 && j == 4) || (i == 2 && j == 5) || (i == 3 && j == 6)) {
Z(i, j) = Z_GMR_S(j); //14,25,36
}
else
Z(i, j) = Z_DIST(i, j);//all remaining elements. see Notes below #define Z_DIST
}
}
}
/* //this was a test based on example 4.4 in Kersting's book
Z(1,1) = Z_GMR(1);
Z(1,2) = Z_GMR_S(4);//Does it work for all phases? dont know yet
Z(1,3) = Z_DIST(1,7);
Z(2,1) = Z_GMR_S(4);// it is Z(1,2);
Z(2,2) = Z_GMR_S_M(4);
Z(2,3) = Z_DIST(1,7);
Z(3,1) = Z_DIST(1,7);// it is Z(1,3);
Z(3,2) = Z_DIST(1,7);// it is Z(2,3);
Z(3,3) = Z_GMR_F_N(1);
*/
}
#undef RES
#undef GMR
#undef GMRCN
#undef RCN
#undef D
#undef Z_GMR
#undef Z_GMRCN
#undef Z_DIST
#undef Z_GMR_S
if (!not_TS_CN){
if (is_CN_ug_line) {
gld::complex z_ij_cn[3][3] = {{Z(1, 1), Z(1, 2), Z(1, 3)},
{Z(2, 1), Z(2, 2), Z(2, 3)},
{Z(3, 1), Z(3, 2), Z(3, 3)}};
gld::complex z_in_cn[3][4] = {{Z(1, 4), Z(1, 5), Z(1, 6),Z(1, 7)},
{Z(2, 4), Z(2, 5), Z(2, 6),Z(2, 7)},
{Z(3, 4), Z(3, 5), Z(3, 6),Z(3, 7)}};
gld::complex z_nj_cn[4][3] = {{Z(4, 1), Z(4, 2), Z(4, 3)},
{Z(5, 1), Z(5, 2), Z(5, 3)},
{Z(6, 1), Z(6, 2), Z(6, 3)},
{Z(7, 1), Z(7, 2), Z(7, 3)}};
gld::complex z_nn_cn[4][4] = {{Z(4, 4), Z(4, 5), Z(4, 6), Z(4, 7)},
{Z(5, 4), Z(5, 5), Z(5, 6), Z(5, 7)},
{Z(6, 4), Z(6, 5), Z(6, 6), Z(6, 7)},
{Z(7, 4), Z(7, 5), Z(7, 6), Z(7, 7)}};
if (!(has_phase(PHASE_A)&&has_phase(PHASE_B)&&has_phase(PHASE_C)&&has_phase(PHASE_N))){
if (!has_phase(PHASE_A))
z_nn_cn[0][0]=gld::complex(1.0);
if (!has_phase(PHASE_B))
z_nn_cn[1][1]=gld::complex(1.0);
if (!has_phase(PHASE_C))
z_nn_cn[2][2]=gld::complex(1.0);
if (!has_phase(PHASE_N))
z_nn_cn[3][3]=gld::complex(1.0);
} //add phase_N here
gld::complex z_nn_inv_cn[4][4], z_p1_cn[3][4], z_p2_cn[3][3], z_abc_cn[3][3];
lu_matrix_inverse(&z_nn_cn[0][0],&z_nn_inv_cn[0][0],4);
//inverse(z_nn_cn,z_nn_inv_cn);
//multiply(z_in_cn, z_nn_inv_cn, z_p1_cn);
//multiply(z_p1_cn, z_nj_cn, z_p2_cn);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 4; col++) {
// Multiply the row of A by the column of B to get the row, column of product.
for (int inner = 0; inner < 4; inner++) {
z_p1_cn[row][col] += z_in_cn[row][inner] * z_nn_inv_cn[inner][col];
}
}
}
//multiply(z_in, z_nn_inv, z_p1);
for (int roww = 0; roww < 3; roww++) {
for (int coll = 0; coll < 3; coll++) {
// Multiply the row of A by the column of B to get the row, column of product.
for (int innerr = 0; innerr < 4; innerr++) {
z_p2_cn[roww][coll] += z_p1_cn[roww][innerr] * z_nj_cn[innerr][coll];
}
}
}
//multiply(z_p1, z_nj, z_p2);
subtract(z_ij_cn, z_p2_cn, z_abc_cn);
multiply(miles, z_abc_cn, Zabc_mat);
}
else {
gld::complex z_ij_ts[3][3] = {{Z(1, 1), Z(1, 2), Z(1, 3)},
{Z(2, 1), Z(2, 2), Z(2, 3)},
{Z(3, 1), Z(3, 2), Z(3, 3)}};
gld::complex z_in_ts[3][4] = {{Z(1, 4), Z(1, 5), Z(1, 6), Z(1,7)},
{Z(2, 4), Z(2, 5), Z(2, 6), Z(2,7)},
{Z(3, 4), Z(3, 5), Z(3, 6), Z(3,7)}};
gld::complex z_nj_ts[4][3] = {{Z(4, 1), Z(4, 2), Z(4, 3)},
{Z(5, 1), Z(5, 2), Z(5, 3)},
{Z(6, 1), Z(6, 2), Z(6, 3)},
{Z(7, 1), Z(7, 2), Z(7, 3)}};
gld::complex z_nn_ts[4][4] = {{Z(4, 4), Z(4, 5), Z(4, 6), Z(4, 7)},
{Z(5, 4), Z(5, 5), Z(5, 6), Z(5, 7)},
{Z(6, 4), Z(6, 5), Z(6, 6), Z(6, 7)},
{Z(7, 4), Z(7, 5), Z(7, 6), Z(7, 7)}};
if (!(has_phase(PHASE_A)&&has_phase(PHASE_B)&&has_phase(PHASE_C)&&has_phase(PHASE_N))){
if (!has_phase(PHASE_A))
z_nn_ts[0][0]=gld::complex(1.0);
if (!has_phase(PHASE_B))
z_nn_ts[1][1]=gld::complex(1.0);
if (!has_phase(PHASE_C))
z_nn_ts[2][2]=gld::complex(1.0);
if(!has_phase(PHASE_N))
{
z_nn_ts[3][3]=gld::complex(1.0);
gl_warning("Underground_line:%d - %s is a tape-shielded cable and may need an explicit phase N conductor",obj->id,(obj->name ? obj->name : "Unnamed"));
/* TROUBLESHOOT
The underground cable is set up as a tape-shielded cable. For neutral currents, it may require an explicit neutral to be connected, unless it represents a
delta-connected system.
*/
}
} //add phase_N here
gld::complex z_nn_inv_ts[4][4], z_p1_ts[3][4], z_p2_ts[3][3], z_abc_ts[3][3];
lu_matrix_inverse(&z_nn_ts[0][0],&z_nn_inv_ts[0][0],4);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 4; col++) {
// Multiply the row of A by the column of B to get the row, column of product.
for (int inner = 0; inner < 4; inner++) {
z_p1_ts[row][col] += z_in_ts[row][inner] * z_nn_inv_ts[inner][col];
}
}
}
//multiply(z_in, z_nn_inv, z_p1);
for (int roww = 0; roww < 3; roww++) {
for (int coll = 0; coll < 3; coll++) {
// Multiply the row of A by the column of B to get the row, column of product.
for (int innerr = 0; innerr < 4; innerr++) {
z_p2_ts[roww][coll] += z_p1_ts[roww][innerr] * z_nj_ts[innerr][coll];
}
}
}
//multiply(z_p1, z_nj, z_p2);
subtract(z_ij_ts, z_p2_ts, z_abc_ts);
multiply(miles, z_abc_ts, Zabc_mat);
/* //This is a test example based on example 4.4 in Kersting's
gld::complex z_ij_ts[1][1] = {Z(1, 1)};
gld::complex z_in_ts[1][2] = {Z(1, 2), Z(1, 3)};
gld::complex z_nj_ts[2][1] = {{Z(1, 2)},
{Z(1, 3)}};
gld::complex z_nn_ts[2][2] = {{Z(2, 2), Z(2, 3)},
{Z(3, 2), Z(3, 3)}};
if (!(has_phase(PHASE_A)&&has_phase(PHASE_B)&&has_phase(PHASE_C))){
if (!has_phase(PHASE_A))
z_nn_ts[0][0]=gld::complex(1.0);
if (!has_phase(PHASE_B))
z_nn_ts[1][1]=gld::complex(1.0);
if (!has_phase(PHASE_C))
z_nn_ts[2][2]=gld::complex(1.0);
}
gld::complex z_nn_inv_ts[2][2], z_p1_ts[1][2], z_p2_ts[1][1], z_abc_ts[1][1];
//lu_matrix_inverse(&z_nn_ts[0][0],&z_nn_inv_ts[0][0],2);
z_nn_inv_ts[0][0] = z_nn_ts[1][1]/((z_nn_ts[0][0] * z_nn_ts[1][1]) - (z_nn_ts[0][1] * z_nn_ts[1][0]));
z_nn_inv_ts[1][1] = z_nn_ts[0][0]/((z_nn_ts[0][0] * z_nn_ts[1][1]) - (z_nn_ts[0][1] * z_nn_ts[1][0]));
z_nn_inv_ts[0][1] = -z_nn_ts[0][1]/((z_nn_ts[0][0] * z_nn_ts[1][1]) - (z_nn_ts[0][1] * z_nn_ts[1][0]));
z_nn_inv_ts[1][0] = -z_nn_ts[1][0]/((z_nn_ts[0][0] * z_nn_ts[1][1]) - (z_nn_ts[0][1] * z_nn_ts[1][0]));
z_p1_ts[0][0] = (z_in_ts[0][0] * z_nn_inv_ts[0][0]) + (z_in_ts[0][1] * z_nn_inv_ts[1][0]);
z_p1_ts[0][1] = (z_in_ts[0][0] * z_nn_inv_ts[1][0]) + (z_in_ts[0][1] * z_nn_inv_ts[1][1]);
z_p2_ts[0][0] = (z_p1_ts[0][0] * z_nj_ts[0][0]) + (z_p1_ts[0][1] * z_nj_ts[1][0]);
z_abc_ts[0][0] = z_ij_ts[0][0] - z_p2_ts[0][0];
Zabc_mat[0][0] = (z_abc_ts[0][0]) * miles;
Zabc_mat[0][1] = gld::complex(0,0);
Zabc_mat[0][2] = gld::complex(0,0);
Zabc_mat[1][0] = gld::complex(0,0);
Zabc_mat[1][1] = gld::complex(0,0);
Zabc_mat[1][2] = gld::complex(0,0);
Zabc_mat[2][0] = gld::complex(0,0);
Zabc_mat[2][1] = gld::complex(0,0);
Zabc_mat[2][2] = gld::complex(0,0);
//multiply(miles, z_abc_ts, Zabc_mat);
*/
}
} else {
gld::complex z_nn_inv = 0;
if(Z(7, 7) != 0.0){
z_nn_inv = Z(7, 7)^(-1.0);
}
Zabc_mat[0][0] = (Z(1, 1) - Z(1, 7) * Z(1, 7) * z_nn_inv) * miles;
Zabc_mat[0][1] = (Z(1, 2) - Z(1, 7) * Z(2, 7) * z_nn_inv) * miles;
Zabc_mat[0][2] = (Z(1, 3) - Z(1, 7) * Z(3, 7) * z_nn_inv) * miles;
Zabc_mat[1][0] = (Z(2, 1) - Z(2, 7) * Z(1, 7) * z_nn_inv) * miles;
Zabc_mat[1][1] = (Z(2, 2) - Z(2, 7) * Z(2, 7) * z_nn_inv) * miles;
Zabc_mat[1][2] = (Z(2, 3) - Z(2, 7) * Z(3, 7) * z_nn_inv) * miles;
Zabc_mat[2][0] = (Z(3, 1) - Z(3, 7) * Z(1, 7) * z_nn_inv) * miles;
Zabc_mat[2][1] = (Z(3, 2) - Z(3, 7) * Z(2, 7) * z_nn_inv) * miles;
Zabc_mat[2][2] = (Z(3, 3) - Z(3, 7) * Z(3, 7) * z_nn_inv) * miles;
}
#undef Z
if (use_line_cap && !not_TS_CN)
{
//Concentric neutral code
if (is_CN_ug_line)
{
//Compute base capacitances - split denominator to handle
if (has_phase(PHASE_A))
{
if ((dia[0]==0.0) || (rad_14==0.0) || (strands_4 == 0)) //Make sure conductor or "neutral ring" radius are not zero
{
gl_warning("Unable to compute capacitance for %s",OBJECTHDR(this)->name);
/* TROUBLESHOOT
One phase of an underground line has either a conductor diameter, a concentric-neutral location diameter, or a neutral
strand count of zero. This will lead to indeterminant values in the analysis. Please fix these values, or run the simulation
with line capacitance disabled.
*/
c_an = 0.0;
}
else //All should be OK
{
//Compute the denominator (make sure it isn't zero)
temp_denom = log(rad_14/(dia[0] / 24.0)) - (1.0 / ((double)(strands_4))) * log(((double)(strands_4))*dia[3] / 24.0 / rad_14);
if (temp_denom == 0.0)
{
gl_warning("Capacitance calculation failure for %s",OBJECTHDR(this)->name);
/* TROUBLESHOOT
While computing the capacitance, a zero-value denominator was encountered. Please check
your underground_conductor parameter values and try again.
*/
c_an = 0.0;
}
else //Valid, continue
{
//Calculate capacitance value for A
c_an = (2.0 * PI * PERMITIVITTY_FREE * perm_A) / temp_denom;
}
}
}
else //No phase A
{
c_an = 0.0; //No capacitance
}
//Compute base capacitances - split denominator to handle
if (has_phase(PHASE_B))
{
if ((dia[1]==0.0) || (rad_25==0.0) || (strands_5 == 0)) //Make sure conductor or "neutral ring" radius are not zero
{
gl_warning("Unable to compute capacitance for %s",OBJECTHDR(this)->name);
//Defined above
c_bn = 0.0;
}
else //All should be OK
{
//Compute the denominator (make sure it isn't zero)
temp_denom = log(rad_25/(dia[1] / 24.0)) - (1.0 / ((double)(strands_5))) * log(((double)(strands_5))*dia[4] / 24.0 / rad_25);
if (temp_denom == 0.0)
{
gl_warning("Capacitance calculation failure for %s",OBJECTHDR(this)->name);
//Defined above
c_bn = 0.0;
}
else //Valid, continue
{
//Calculate capacitance value for A
c_bn = (2.0 * PI * PERMITIVITTY_FREE * perm_B) / temp_denom;
}
}
}
else //No phase B
{
c_bn = 0.0; //No capacitance
}
//Compute base capacitances - split denominator to handle
if (has_phase(PHASE_C))
{
if ((dia[2]==0.0) || (rad_36==0.0) || (strands_6 == 0)) //Make sure conductor or "neutral ring" radius are not zero
{
gl_warning("Unable to compute capacitance for %s",OBJECTHDR(this)->name);
//Defined above
c_cn = 0.0;
}
else //All should be OK
{
//Compute the denominator (make sure it isn't zero)
temp_denom = log(rad_36/(dia[2] / 24.0)) - (1.0 / ((double)(strands_6))) * log(((double)(strands_6))*dia[5] / 24.0 / rad_36);
if (temp_denom == 0.0)
{
gl_warning("Capacitance calculation failure for %s",OBJECTHDR(this)->name);
//Defined above
c_cn = 0.0;
}
else //Valid, continue
{
//Calculate capacitance value for C
c_cn = (2.0 * PI * PERMITIVITTY_FREE * perm_C) / temp_denom;
}
}
}
else //No phase C
{
c_cn = 0.0; //No capacitance
}
}//End concentric neutral calculations
else //Implies tape-shielded
{
//*************** THIS HAS NOT BEEN FIXED --- Tape Shield Capacitor Code would go down here ************************//
//Compute base capacitances - split denominator to handle
if (has_phase(PHASE_A))
{
if ((dia[0]==0.0) || (rad_14==0.0)) //Make sure conductor or "neutral ring" radius are not zero
{
gl_warning("Unable to compute capacitance for %s",OBJECTHDR(this)->name);
/* TROUBLESHOOT
One phase of an underground line has either a conductor diameter, a concentric-neutral location diameter, or a neutral
strand count of zero. This will lead to indeterminant values in the analysis. Please fix these values, or run the simulation
with line capacitance disabled.
*/
c_an = 0.0;
}
else //All should be OK
{
//Compute the denominator (make sure it isn't zero)
temp_denom = log(rad_14/(dia[0] / 2.0));
if (temp_denom == 0.0)
{
gl_warning("Capacitance calculation failure for %s",OBJECTHDR(this)->name);
/* TROUBLESHOOT
While computing the capacitance, a zero-value denominator was encountered. Please check
your underground_conductor parameter values and try again.
*/
c_an = 0.0;
}
else //Valid, continue
{
//Calculate capacitance value for A
c_an = (2.0 * PI * PERMITIVITTY_FREE * perm_A) / temp_denom;
}
}
}
else //No phase A
{
c_an = 0.0; //No capacitance
}
//Compute base capacitances - split denominator to handle