-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathSequenceCalculator.cs
executable file
·587 lines (500 loc) · 27.4 KB
/
SequenceCalculator.cs
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
//******************************************************************************************************
// SequenceCalculator.cs - Gbtc
//
// Copyright © 2012, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 05/16/2012 - J. Ritchie Carroll
// Generated original version of source code.
// 12/13/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using GSF;
using GSF.Collections;
using GSF.TimeSeries;
using GSF.TimeSeries.Adapters;
using GSF.Units;
using GSF.Units.EE;
using PhasorProtocolAdapters;
namespace PowerCalculations;
/// <summary>
/// Calculates positive, negative and zero sequences using A, B and C phase voltage or current magnitude and angle signals input to the adapter.
/// </summary>
[Description("Sequence Calculator: Computes positive, negative and zero sequences for synchrophasor measurements")]
public class SequenceCalculator : CalculatedMeasurementBase
{
#region [ Members ]
// Constants
internal const bool DefaultTrackRecentValues = false;
internal const int DefaultSampleSize = 5;
internal const bool DefaultIncludePositiveSequence = true;
internal const bool DefaultIncludeNegativeSequence = true;
internal const bool DefaultIncludeZeroSequence = true;
internal const BadDataStrategy DefaultBadDataStrategy = BadDataStrategy.FlagAsBad;
private const double Rad120 = 2.0D * Math.PI / 3.0D;
// Fields
private MeasurementKey[] m_angles;
private MeasurementKey[] m_magnitudes;
private string m_magnitudeUnits;
private ConcurrentQueue<double> m_positiveSequenceMagnitudeSample;
private ConcurrentQueue<Angle> m_positiveSequenceAngleSample;
private ConcurrentQueue<double> m_negativeSequenceMagnitudeSample;
private ConcurrentQueue<Angle> m_negativeSequenceAngleSample;
private ConcurrentQueue<double> m_zeroSequenceMagnitudeSample;
private ConcurrentQueue<Angle> m_zeroSequenceAngleSample;
/// <summary>
/// Defines the output measurements for the <see cref="SequenceCalculator"/>.
/// </summary>
/// <remarks>
/// One output measurement should be defined for each enumeration value, in order:
/// </remarks>
public enum Output
{
/// <summary>
/// Positive sequence magnitude measurement.
/// </summary>
PositiveSequenceMagnitude,
/// <summary>
/// Positive sequence angle measurement.
/// </summary>
PositiveSequenceAngle,
/// <summary>
/// Negative sequence magnitude measurement.
/// </summary>
NegativeSequenceMagnitude,
/// <summary>
/// Negative sequence angle measurement.
/// </summary>
NegativeSequenceAngle,
/// <summary>
/// Zero sequence magnitude measurement.
/// </summary>
ZeroSequenceMagnitude,
/// <summary>
/// Zero sequence angle measurement.
/// </summary>
ZeroSequenceAngle
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets or sets flag that determines if the last few values should be monitored for diagnostics.
/// </summary>
[ConnectionStringParameter]
[Description("Flag that determines if the last few values should be monitored for diagnostics.")]
[DefaultValue(DefaultTrackRecentValues)]
public bool TrackRecentValues { get; set; } = DefaultTrackRecentValues;
/// <summary>
/// Gets or sets the sample size of the data to be monitored.
/// </summary>
[ConnectionStringParameter]
[Description("Define the sample size of the data to be monitored when TrackRecentValues is true.")]
[DefaultValue(DefaultSampleSize)]
public int SampleSize { get; set; } = DefaultSampleSize;
/// <summary>
/// Gets or sets flag that determines if positive sequence calculations should be included.
/// </summary>
[ConnectionStringParameter]
[Description("Flag that determines if positive sequence calculations should be included.")]
[DefaultValue(DefaultIncludePositiveSequence)]
public bool IncludePositiveSequence { get; set; } = DefaultIncludePositiveSequence;
/// <summary>
/// Gets or sets flag that determines if negative sequence calculations should be included.
/// </summary>
[ConnectionStringParameter]
[Description("Flag that determines if negative sequence calculations should be included.")]
[DefaultValue(DefaultIncludeNegativeSequence)]
public bool IncludeNegativeSequence { get; set; } = DefaultIncludeNegativeSequence;
/// <summary>
/// Gets or sets flag that determines if zero sequence calculations should be included.
/// </summary>
[ConnectionStringParameter]
[Description("Flag that determines if zero sequence calculations should be included.")]
[DefaultValue(DefaultIncludeZeroSequence)]
public bool IncludeZeroSequence { get; set; } = DefaultIncludeZeroSequence;
/// <summary>
/// Gets or sets the bad data strategy used to when inputs are marked with bad quality.
/// </summary>
[ConnectionStringParameter]
[Description("Defines bad data strategy used to when inputs are marked with bad quality.")]
[DefaultValue(DefaultBadDataStrategy)]
public BadDataStrategy BadDataStrategy { get; set; } = DefaultBadDataStrategy;
/// <summary>
/// Gets the flag indicating if this adapter supports temporal processing.
/// </summary>
public override bool SupportsTemporalProcessing => true;
/// <summary>
/// Returns the detailed status of the <see cref="PowerCalculator"/>.
/// </summary>
public override string Status
{
get
{
StringBuilder status = new();
status.Append(base.Status);
status.AppendLine($" Phase A magnitude: {m_magnitudes[0]}");
status.AppendLine($" Phase B magnitude: {m_magnitudes[1]}");
status.AppendLine($" Phase C magnitude: {m_magnitudes[2]}");
status.AppendLine($" Phase A angle: {m_angles[0]}");
status.AppendLine($" Phase B angle: {m_angles[1]}");
status.AppendLine($" Phase C angle: {m_angles[2]}");
status.AppendLine($" Bad Data Strategy: {BadDataStrategy}");
if (!TrackRecentValues)
{
status.AppendLine();
return status.ToString();
}
if (IncludePositiveSequence)
{
status.AppendLine();
status.Append(" Last positive sequences: ");
status.Append(m_positiveSequenceMagnitudeSample.Any() ?
m_positiveSequenceMagnitudeSample.Zip(m_positiveSequenceAngleSample, (mag, ang) =>
$"{mag:0.00} {m_magnitudeUnits}, {ang.ToDegrees():0.00}°").ToDelimitedString("\r\n ") :
"No values calculated yet...");
}
if (IncludeNegativeSequence)
{
status.AppendLine();
status.Append(" Last negative sequences: ");
status.Append(m_positiveSequenceMagnitudeSample.Any() ?
m_negativeSequenceMagnitudeSample.Zip(m_negativeSequenceAngleSample, (mag, ang) =>
$"{mag:0.00} {m_magnitudeUnits}, {ang.ToDegrees():0.00}°").ToDelimitedString("\r\n ") :
"No values calculated yet...");
}
if (IncludeZeroSequence)
{
status.AppendLine();
status.Append(" Last zero sequences: ");
status.Append(m_zeroSequenceMagnitudeSample.Any() ?
m_zeroSequenceMagnitudeSample.Zip(m_zeroSequenceAngleSample, (mag, ang) =>
$"{mag:0.00} {m_magnitudeUnits}, {ang.ToDegrees():0.00}°").ToDelimitedString("\r\n ") :
"No values calculated yet...");
}
status.AppendLine();
status.AppendLine();
return status.ToString();
}
}
#endregion
#region [ Methods ]
/// <summary>
/// Initializes the <see cref="PowerCalculator"/>.
/// </summary>
public override void Initialize()
{
base.Initialize();
Dictionary<string, string> settings = Settings;
// Load parameters
if (settings.TryGetValue(nameof(TrackRecentValues), out string setting))
TrackRecentValues = setting.ParseBoolean();
// Data sample size to monitor, in seconds
if (settings.TryGetValue(nameof(SampleSize), out setting) && int.TryParse(setting, out int sampleSize))
SampleSize = sampleSize;
if (settings.TryGetValue(nameof(IncludePositiveSequence), out setting))
IncludePositiveSequence = setting.ParseBoolean();
if (settings.TryGetValue(nameof(IncludeNegativeSequence), out setting))
IncludeNegativeSequence = setting.ParseBoolean();
if (settings.TryGetValue(nameof(IncludeZeroSequence), out setting))
IncludeZeroSequence = setting.ParseBoolean();
// Check old setting name for backwards compatibility with existing configurations
if (settings.TryGetValue("UseBadQualityData", out setting))
BadDataStrategy = setting.ParseBoolean() ? BadDataStrategy.FlagAsBad : BadDataStrategy.DropData;
if (settings.TryGetValue(nameof(BadDataStrategy), out setting) && Enum.TryParse(setting, true, out BadDataStrategy badDataStrategy))
BadDataStrategy = badDataStrategy;
// Load needed phase angle measurement keys from defined InputMeasurementKeys
m_angles = InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.VPHA).ToArray();
if (m_angles.Length == 0)
{
// No voltage angles existed, check for current angles
m_angles = InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.IPHA).ToArray();
}
else
{
// Make sure only one kind of angles are defined - not a mixture of voltage and currents
if (InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.IPHA).Any())
throw new InvalidOperationException("Angle input measurements for a single sequence calculator instance should only be for voltages or currents - not both.");
}
// Load needed phase magnitude measurement keys from defined InputMeasurementKeys
m_magnitudes = InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.VPHM).ToArray();
if (m_magnitudes.Length == 0)
{
// No voltage magnitudes existed, check for current magnitudes
m_magnitudes = InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.IPHM).ToArray();
m_magnitudeUnits = "amps";
}
else
{
// Make only one kind of magnitudes are defined - not a mixture of voltage and currents
if (InputMeasurementKeys.Where((_, index) => InputMeasurementKeyTypes[index] == SignalType.IPHM).Any())
throw new InvalidOperationException("Magnitude input measurements for a single sequence calculator instance should only be for voltages or currents - not both.");
m_magnitudeUnits = "volts";
}
if (m_angles.Length < 3)
throw new InvalidOperationException("Three angle input measurements, i.e., A, B and C - in that order, are required for the sequence calculator.");
if (m_magnitudes.Length < 3)
throw new InvalidOperationException("Three magnitude input measurements, i.e., A, B and C - in that order, are required for the sequence calculator.");
if (m_angles.Length != m_magnitudes.Length)
throw new InvalidOperationException("A different number of magnitude and angle input measurement keys were supplied - the angles and magnitudes must be supplied in pairs in A, B, C sequence, i.e., one magnitude input measurement must be supplied for each angle input measurement in a consecutive sequence (e.g., A1;M1; A2;M2; ... An;Mn)");
// Make sure only these phasor measurements are used as input
InputMeasurementKeys = m_angles.Concat(m_magnitudes).ToArray();
// Validate output measurements
if (IncludePositiveSequence && IncludeNegativeSequence && IncludeZeroSequence)
{
if (OutputMeasurements.Length < 6)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Positive Sequence Magnitude\", \"Positive Sequence Angle\", \"Negative Sequence Magnitude\", \"Negative Sequence Angle\", \"Zero Sequence Magnitude\" and \"Zero Sequence Angle\" - in this order.");
}
else if (IncludePositiveSequence && IncludeNegativeSequence)
{
if (OutputMeasurements.Length < 4)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Positive Sequence Magnitude\", \"Positive Sequence Angle\", \"Negative Sequence Magnitude\" and \"Negative Sequence Angle\" - in this order.");
}
else if (IncludePositiveSequence && IncludeZeroSequence)
{
if (OutputMeasurements.Length < 4)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Positive Sequence Magnitude\", \"Positive Sequence Angle\", \"Zero Sequence Magnitude\" and \"Zero Sequence Angle\" - in this order.");
}
else if (IncludeNegativeSequence && IncludeZeroSequence)
{
if (OutputMeasurements.Length < 4)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Negative Sequence Magnitude\", \"Negative Sequence Angle\", \"Zero Sequence Magnitude\" and \"Zero Sequence Angle\" - in this order.");
}
else if (IncludePositiveSequence)
{
if (OutputMeasurements.Length < 2)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Positive Sequence Magnitude\" and \"Positive Sequence Angle\" - in this order.");
}
else if (IncludeNegativeSequence)
{
if (OutputMeasurements.Length < 2)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Negative Sequence Magnitude\" and \"Negative Sequence Angle\" - in this order.");
}
else if (IncludeZeroSequence)
{
if (OutputMeasurements.Length < 2)
throw new InvalidOperationException("Not enough output measurements were specified for the sequence calculator, expecting measurements for the \"Zero Sequence Magnitude\" and \"Zero Sequence Angle\" - in this order.");
}
else
{
throw new InvalidOperationException("At least one of positive, negative or sequence calculations must be included to calculate.");
}
if (TrackRecentValues)
{
m_positiveSequenceMagnitudeSample = new ConcurrentQueue<double>();
m_positiveSequenceAngleSample = new ConcurrentQueue<Angle>();
m_negativeSequenceMagnitudeSample = new ConcurrentQueue<double>();
m_negativeSequenceAngleSample = new ConcurrentQueue<Angle>();
m_zeroSequenceMagnitudeSample = new ConcurrentQueue<double>();
m_zeroSequenceAngleSample = new ConcurrentQueue<Angle>();
}
// Assign a default adapter name to be used if sequence calculator is loaded as part of automated collection
if (string.IsNullOrWhiteSpace(Name))
Name = $"SC!{OutputMeasurements[(int)Output.PositiveSequenceMagnitude].Key}";
}
/// <summary>
/// Publish frame of time-aligned collection of measurement values that arrived within the defined lag time.
/// </summary>
/// <param name="frame">Frame of measurements with the same timestamp that arrived within lag time that are ready for processing.</param>
/// <param name="index">Index of frame within a second ranging from zero to frames per second - 1.</param>
protected override void PublishFrame(IFrame frame, int index)
{
ComplexNumber positiveSequence = nanSeq;
ComplexNumber negativeSequence = nanSeq;
ComplexNumber zeroSequence = nanSeq;
bool badInputDetected = false;
bool includeInput(IMeasurement measurement)
{
bool qualityIsGood = measurement.ValueQualityIsGood();
if (BadDataStrategy == BadDataStrategy.DropData || qualityIsGood)
return qualityIsGood;
badInputDetected = true;
return true;
}
try
{
ConcurrentDictionary<MeasurementKey, IMeasurement> measurements = frame.Measurements;
double mA = 0.0D, aA = 0.0D, mB = 0.0D, aB = 0.0D, mC = 0.0D, aC = 0.0D;
bool allInputsReceived = false;
// Get all needed measurement values from this frame
if (measurements.TryGetValue(m_magnitudes[0], out IMeasurement measurement) && includeInput(measurement))
{
// Get A-phase magnitude value
mA = measurement.AdjustedValue;
if (measurements.TryGetValue(m_angles[0], out measurement) && includeInput(measurement))
{
// Get A-phase angle value
aA = measurement.AdjustedValue;
if (measurements.TryGetValue(m_magnitudes[1], out measurement) && includeInput(measurement))
{
// Get B-phase magnitude value
mB = measurement.AdjustedValue;
if (measurements.TryGetValue(m_angles[1], out measurement) && includeInput(measurement))
{
// Get B-phase angle value
aB = measurement.AdjustedValue;
if (measurements.TryGetValue(m_magnitudes[2], out measurement) && includeInput(measurement))
{
// Get C-phase magnitude value
mC = measurement.AdjustedValue;
if (measurements.TryGetValue(m_angles[2], out measurement) && includeInput(measurement))
{
// Get C-phase angle value
aC = measurement.AdjustedValue;
allInputsReceived = true;
}
}
}
}
}
}
if (!allInputsReceived)
return;
ComplexNumber aPhase = new(Angle.FromDegrees(aA), mA);
ComplexNumber bPhase = new(Angle.FromDegrees(aB), mB);
ComplexNumber cPhase = new(Angle.FromDegrees(aC), mC);
if (IncludePositiveSequence)
positiveSequence = (aPhase + a * bPhase + aSq * cPhase) / 3.0D;
if (IncludeNegativeSequence)
negativeSequence = (aPhase + aSq * bPhase + a * cPhase) / 3.0D;
if (IncludeZeroSequence)
zeroSequence = (aPhase + bPhase + cPhase) / 3.0D;
if (!TrackRecentValues)
return;
// Add latest positive sequence to data sample
if (IncludePositiveSequence)
{
m_positiveSequenceMagnitudeSample.Enqueue(positiveSequence.Magnitude);
while (m_positiveSequenceMagnitudeSample.Count > SampleSize)
m_positiveSequenceMagnitudeSample.TryDequeue(out _);
m_positiveSequenceAngleSample.Enqueue(positiveSequence.Angle);
while (m_positiveSequenceAngleSample.Count > SampleSize)
m_positiveSequenceAngleSample.TryDequeue(out _);
}
// Add latest negative sequence to data sample
if (IncludeNegativeSequence)
{
m_negativeSequenceMagnitudeSample.Enqueue(negativeSequence.Magnitude);
while (m_negativeSequenceMagnitudeSample.Count > SampleSize)
m_negativeSequenceMagnitudeSample.TryDequeue(out _);
m_negativeSequenceAngleSample.Enqueue(negativeSequence.Angle);
while (m_negativeSequenceAngleSample.Count > SampleSize)
m_negativeSequenceAngleSample.TryDequeue(out _);
}
// Add latest zero sequence to data sample
if (IncludeZeroSequence)
{
m_zeroSequenceMagnitudeSample.Enqueue(zeroSequence.Magnitude);
while (m_zeroSequenceMagnitudeSample.Count > SampleSize)
m_zeroSequenceMagnitudeSample.TryDequeue(out _);
m_zeroSequenceAngleSample.Enqueue(zeroSequence.Angle);
while (m_zeroSequenceAngleSample.Count > SampleSize)
m_zeroSequenceAngleSample.TryDequeue(out _);
}
}
finally
{
IMeasurement[] outputMeasurements = OutputMeasurements;
MeasurementStateFlags flags = badInputDetected ? MeasurementStateFlags.BadData : MeasurementStateFlags.Normal;
if (IncludePositiveSequence && IncludeNegativeSequence && IncludeZeroSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], positiveSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], positiveSequence.Angle.ToDegrees(), frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[2], negativeSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[3], negativeSequence.Angle.ToDegrees(), frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[4], zeroSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[5], zeroSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else if (IncludePositiveSequence && IncludeNegativeSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], positiveSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], positiveSequence.Angle.ToDegrees(), frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[2], negativeSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[3], negativeSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else if (IncludePositiveSequence && IncludeZeroSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], positiveSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], positiveSequence.Angle.ToDegrees(), frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[2], zeroSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[3], zeroSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else if (IncludeNegativeSequence && IncludeZeroSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], negativeSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], negativeSequence.Angle.ToDegrees(), frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[2], zeroSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[3], zeroSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else if (IncludePositiveSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], positiveSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], positiveSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else if (IncludeNegativeSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], negativeSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], negativeSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
else // if (IncludeZeroSequence)
{
// Provide calculated measurements for external consumption
OnNewMeasurements(new IMeasurement[]
{
Measurement.Clone(outputMeasurements[0], zeroSequence.Magnitude, frame.Timestamp, flags),
Measurement.Clone(outputMeasurements[1], zeroSequence.Angle.ToDegrees(), frame.Timestamp, flags)
});
}
}
}
#endregion
#region [ Static ]
// Static Fields
// a = e^((2/3) * pi * i)
private static readonly ComplexNumber a = new(Math.Cos(Rad120), Math.Sin(Rad120));
private static readonly ComplexNumber aSq = a * a;
private static readonly ComplexNumber nanSeq = new(double.NaN, double.NaN);
#endregion
}