Ejemplo n.º 1
0
        /// <summary>
        /// Converts specific <see cref="ISignalData"/> to viewmodels
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            object result = null;

            TypeSwitch.Construct().
            LazyCase <IPhasorDomainSignal>((x) => result = new PhasorDomainSignalViewModel(x, IoC.Resolve <ISIUnits>().VoltageShort)).
            LazyCase <ITimeDomainSignal>((x) => result   = new TimeDomainSignalViewModel(x, IoC.Resolve <ISIUnits>().VoltageShort)).
            Switch(value);

            return(result);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Tries to construct power for <paramref name="component"/>, on success assigns it to <paramref name="power"/> and
            /// true, on failure assigns null to <paramref name="power"/> and returns false.
            /// </summary>
            /// <param name="component"></param>
            /// <param name="power"></param>
            /// <returns></returns>
            protected override bool TryConstructPower(IBaseComponent component, out ITimeDomainSignal power, bool voltageBA)
            {
                ITimeDomainSignal constructedPower = null;

                TypeSwitch.Construct().
                LazyCase <ITwoTerminal>((x) => TryConstructPower(x, out constructedPower, voltageBA)).
                Switch(component);

                power = constructedPower;
                return(power != null);
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Gets a current flow
            /// </summary>
            /// <param name="target"></param>
            /// <returns></returns>
            protected override ISignalInformation GetSignalInformation(IBaseComponent target)
            {
                // Get currents
                var results = IoC.Resolve <ISimulationResultsProvider>().Value.Current;

                // The info to get
                ISignalInformation info = null;

                // Get the results from provider and return its return value (lazy cases because we operate on interfaces)
                TypeSwitch.Construct().
                // For resistors no change in VI directions means that current flow is taken for voltage from node A (reference) to node B
                LazyCase <IResistor>((x) => info = results.Get(x, !target.ChangeVIDirections)).
                // For capacitors no change in VI directions means that current flow is taken for voltage from node A (reference) to node B
                LazyCase <ICapacitor>((x) => info = results.Get(x, !target.ChangeVIDirections)).
                // For active components no change in VI directions means that current flow is taken for voltage from node A (reference) to node B
                LazyCase <IActiveComponent>((x) => info = results.Get(x.Index, !target.ChangeVIDirections)).
                Switch(target);

                return(info);
            }
Ejemplo n.º 4
0
            /// <summary>
            /// Gets a power on a component
            /// </summary>
            /// <param name="target"></param>
            /// <returns></returns>
            protected override ISignalInformation GetSignalInformation(IBaseComponent target)
            {
                // Get currents
                var results = IoC.Resolve <ISimulationResultsProvider>().Value.Power;

                // The info to get
                ISignalInformation info = null;

                // Get the results from provider and return its return value (lazy cases because we operate on interfaces)
                TypeSwitch.Construct().
                LazyCase <IResistor>((x) => info      = results.Get(x, target.ChangeVIDirections)).
                LazyCase <ICapacitor>((x) => info     = results.Get(x, target.ChangeVIDirections)).
                LazyCase <ICurrentSource>((x) => info = results.Get(x, target.ChangeVIDirections)).
                // Because IACVoltageSource extens IVoltageSource the check for that needs to be done manually so as not to
                // fetch the result twice (first only for IVoltageSource then for IACVoltageSource)
                LazyCase <IDCVoltageSource>((x) => info = results.Get(x, target.ChangeVIDirections)).
                LazyCase <IACVoltageSource>((x) => info = results.Get(x, target.ChangeVIDirections)).
                Switch(target);

                return(info);
            }
Ejemplo n.º 5
0
            /// <summary>
            /// Tries to constract a power for an <see cref="ITwoTerminal"/>
            /// </summary>
            /// <param name="twoTerminal"></param>
            /// <param name="power"></param>
            /// <returns></returns>
            private bool TryConstructPower(ITwoTerminal twoTerminal, out ITimeDomainSignal power, bool voltageBA)
            {
                power = null;

                if (_VoltageDrops.TryGet(twoTerminal, out var voltage, voltageBA))
                {
                    ITimeDomainSignal current = null;

                    // Call different method depending on the type of the two terminal
                    TypeSwitch.Construct().
                    LazyCase <IResistor>((x) => _Currents.TryGet(x, out current)).
                    LazyCase <ICapacitor>((x) => _Currents.TryGet(x, out current)).
                    LazyCase <IActiveComponent>((x) => _Currents.TryGet(x.Index, out current)).
                    Switch(twoTerminal);

                    // If both voltage and current were obtained
                    if (current != null)
                    {
                        var result = IoC.Resolve <ITimeDomainSignalMutable>(voltage.Samples, voltage.TimeStep, voltage.StartTime);

                        // The result is a product of voltage and current waveforms, calculate power generated by each source separately
                        foreach (var waveform in voltage.Waveforms)
                        {
                            // Add new power waveform, use voltage drop's source as its source and use the final current waveform.
                            // If only the waveform for the considered source would be used then the result wouldbe incorrect.
                            // Power is a product of voltage and current, we can't superposition both quantities because power is not
                            // a linear relationship in that case. However if we take the total current then only superimposing voltage is correct
                            // since it's just a linear relationship P = U * I (I is independent of the source - it can be considered as a scalar).
                            result.AddWaveform(waveform.Key, waveform.Value.MergeSelect(current.FinalWaveform, (x, y) => x * y));
                        }

                        power = result;
                    }
                }

                // If power is not null it means that it was successfully constructed
                return(power != null);
            }