Beispiel #1
0
            /// <summary>
            /// Tries to construct a current for <paramref name="element"/>, returns true on success
            /// </summary>
            /// <param name="element"></param>
            /// <param name="voltageBA">If true, it means that current was calculated for voltage drop from
            /// <see cref="ITwoTerminal.TerminalA"/> (reference) to <see cref="ITwoTerminal.TerminalB"/>, if false it means that
            /// that direction was reversed</param>
            /// <param name="current">Current constructed if successful, null otherwise</param>
            /// <returns></returns>
            protected override bool TryConstructCurrent(ITwoTerminal element, bool voltageBA, out IPhasorDomainSignal current)
            {
                // Try to get voltage drop across the element
                if (_VoltageDrops.TryGet(element, out var voltageDrop, voltageBA))
                {
                    // If successful, create a new current signal based on it, cache it
                    //current = IoC.Resolve<IPhasorDomainSignal>(
                    //		GetPassiveTwoTerminalDCCurrent(voltageDrop, element),
                    //		GetPassiveTwoTerminalACCurrentPhasors(voltageDrop, element));

                    current = IoC.Resolve <IPhasorDomainSignal>(
                        voltageDrop.Phasors.Select((x) => x.Value * element.GetAdmittance(x.Key.Frequency)));

                    // And return success
                    return(true);
                }
Beispiel #2
0
            /// <summary>
            /// Tries to construct a current for <paramref name="element"/>, returns true on success
            /// </summary>
            /// <param name="element"></param>
            /// <param name="voltageBA">If true, it means that current was calculated for voltage drop from
            /// <see cref="ITwoTerminal.TerminalA"/> (reference) to <see cref="ITwoTerminal.TerminalB"/>, if false it means that
            /// that direction was reversed</param>
            /// <param name="current">Current constructed if successful, null otherwise</param>
            /// <returns></returns>
            protected override bool TryConstructCurrent(ITwoTerminal element, bool voltageBA, out ITimeDomainSignal current)
            {
                // Try to get voltage drop across the element
                if (_VoltageDrops.TryGet(element, out var voltageDrop, voltageBA))
                {
                    // If successful, create a new current signal based on it, cache it
                    var result = IoC.Resolve <ITimeDomainSignalMutable>(voltageDrop.Samples, voltageDrop.TimeStep, voltageDrop.StartTime);

                    // Get the minimum frequency - it is needed for capacitor waveform shifting, check if there are any waveforms, if not
                    // just assign 0 (technically no waveforms result in a zero wave, which is DC)
                    var minACFrequency = voltageDrop.Waveforms.Count > 0 ? voltageDrop.Waveforms.Keys.Min((x) => x.Frequency) : 0;

                    // Current is composed of each voltage waveform times admittance of the element
                    foreach (var waveform in voltageDrop.Waveforms)
                    {
                        // Get magnitude of element's admittance
                        var admittanceMagnitude = element.GetAdmittance(waveform.Key.Frequency).Magnitude;

                        // Current waveform is the product of voltage waveforrm and magnitude
                        var finalWaveform = waveform.Value.Select((x) => x * admittanceMagnitude);

                        // Introduce phase shift for capacitors - but only if minimum AC frequency is greater than 0, if it's not then there were
                        // no AC voltage sources and so no current will flow through any capacitor
                        if (minACFrequency > 0 && element is ICapacitor)
                        {
                            // Each wave has to be shifted by pi / 2 but only in its period.
                            // For example, a wave with frequency 2 times the lowest frequency has to be shifted by total of pi / 4 - because
                            // there are 2 periods of it in the full waveform. This relation is given by minimum frequency / wave frequency
                            finalWaveform = WaveformBuilder.ShiftWaveform(finalWaveform, minACFrequency / waveform.Key.Frequency * Math.PI / 2);
                        }

                        // Add the waveform to the final waveform
                        result.AddWaveform(waveform.Key, finalWaveform);
                    }

                    current = result;

                    // And return success
                    return(true);
                }