Example #1
0
        /// <summary>
        /// Returns phasors constructed for source given by <paramref name="sourceDescription"/>
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="sourceDescription"></param>
        private PhasorState GetPhasor(AdmittanceMatrixFactory factory, ISourceDescription sourceDescription)
        {
            var state = new PhasorState(factory.NodesCount, factory.ActiveComponentsCount, sourceDescription);

            // Create an admittance matrix corresponding to the given source
            factory.Construct(sourceDescription).
            // And solve it
            Solve(out var nodePotentials, out var activeComponentsCurrents);

            // Add the results to state
            state.AddValues(nodePotentials, activeComponentsCurrents);

            return(state);
        }
Example #2
0
        /// <summary>
        /// Creates and solves DC admittance matrix for saturated op-amps
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        private PhasorState GetOpAmpSaturationBias(AdmittanceMatrixFactory factory)
        {
            // Create an instantenous state based on node indices and active components indices in factory,
            // use the factory's op amp saturation source as source description
            var result = new PhasorState(factory.Nodes, factory.ActiveComponentsCount, factory.OpAmpSaturationSource);

            // Construct matrix for saturated op-amps and solve it
            factory.ConstructDCForSaturatedOpAmpsOnly().Solve(out var nodePotentials, out var activeComponentsCurrents);

            // Add the results from simulation to state
            result.AddValues(nodePotentials.ToArray(), activeComponentsCurrents.ToArray());

            return(result);
        }
Example #3
0
        /// <summary>
        /// Adds the <paramref name="other"/> to this instance. If keys from <see cref="GenericState{T}.Potentials"/> or
        /// <see cref="GenericState{T}.Currents"/> are not found in this instance, an exception will be thrown.
        /// </summary>
        /// <param name="nodePotentials"></param>
        /// <param name="activeComponentsCurrents"></param>
        public void AddState(PhasorState other)
        {
            // Add node potentials
            foreach (var key in other.Potentials.Keys)
            {
                Potentials[key] += other.Potentials[key];
            }

            // Add active components currents
            foreach (var key in other.Currents.Keys)
            {
                Currents[key] += other.Currents[key];
            }
        }