Пример #1
0
        /// <summary>
        /// Builds <see cref="WaveformState"/> based on this <see cref="PhasorState"/>. Builds waveforms for each potential and current.
        /// </summary>
        /// <param name="pointsCount"></param>
        /// <param name="timeStep"></param>
        /// <returns></returns>
        public WaveformState ToWaveform(int pointsCount, double timeStep)
        {
            // Create state for result
            var result = new WaveformState(Potentials.Keys, Currents.Keys, SourceDescription);

            // Depending on source type
            switch (SourceDescription.SourceType)
            {
            // For AC sources
            case SourceType.ACVoltageSource:
            {
                // For each potential
                foreach (var potential in Potentials)
                {
                    // Create sine waves based on the phasor
                    result.Potentials[potential.Key] = WaveformBuilder.SineWave(potential.Value.Magnitude, SourceDescription.Frequency,
                                                                                potential.Value.Phase, pointsCount, timeStep).ToList();
                }

                // Similarly for currents
                foreach (var current in Currents)
                {
                    result.Currents[current.Key] = WaveformBuilder.SineWave(current.Value.Magnitude, SourceDescription.Frequency,
                                                                            current.Value.Phase, pointsCount, timeStep).ToList();
                }
            } break;

            // For DC sources
            case SourceType.DCVoltageSource:
            case SourceType.DCCurrentSource:
            {
                // For each potential
                foreach (var potential in Potentials)
                {
                    // Build constant waveforms. For DC sources phasor is a purely real number - just take the real part as value of the
                    // wave.
                    result.Potentials[potential.Key] = WaveformBuilder.ConstantWaveform(potential.Value.Real, pointsCount).ToList();
                }

                // Similarly for currents
                foreach (var current in Currents)
                {
                    result.Currents[current.Key] = WaveformBuilder.ConstantWaveform(current.Value.Real, pointsCount).ToList();
                }
            } break;
            }

            return(result);
        }
Пример #2
0
 /// <summary>
 /// Adds a new waveform to the signal. If one already exists for source described by <paramref name="description"/>, adds them together,
 /// otherwise makes a new entry in <see cref="ITimeDomainSignal.ACWaveforms"/>. or <see cref="ITimeDomainSignal.DCWaveforms"/>.
 /// The waveform is given by a constant value - full
 /// waveform will be constructed from it.
 /// </summary>
 /// <param name="description"></param>
 /// <param name="value"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public void AddWaveform(ISourceDescription description, double value) =>
 AddWaveform(description, WaveformBuilder.ConstantWaveform(value, Samples));