Ejemplo n.º 1
0
        /// <summary>
        /// Reset the row to 0.0 and return true if the row is a current equation
        /// </summary>
        /// <param name="solver">Solver</param>
        /// <param name="variables">List of unknowns/variables</param>
        /// <param name="rowIndex">Row number</param>
        /// <returns></returns>
        protected static bool ZeroNoncurrentRow(SparseLinearSystem <double> solver, VariableSet variables, int rowIndex)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }

            bool currents = false;

            for (int n = 0; n < variables.Count; n++)
            {
                var node = variables[n];
                MatrixElement <double> x = solver.FindMatrixElement(rowIndex, node.Index);
                if (x != null && !x.Value.Equals(0.0))
                {
                    if (node.UnknownType == VariableType.Current)
                    {
                        currents = true;
                    }
                    else
                    {
                        x.Value = 0.0;
                    }
                }
            }
            return(currents);
        }
        /// <summary>
        /// Apply an additional conductance to the diagonal elements of a matrix that is typically constructed using Modified Nodal Analysis (MNA).
        /// </summary>
        /// <param name="solver">The solver.</param>
        /// <param name="gmin">The conductance to be added.</param>
        /// <exception cref="ArgumentNullException">solver</exception>
        public static void ApplyDiagonalGmin(this SparseLinearSystem <double> solver, double gmin)
        {
            solver.ThrowIfNull(nameof(solver));

            // Skip if not necessary
            if (gmin <= 0.0)
            {
                return;
            }

            // Add to the diagonal
            for (var i = 1; i <= solver.Order; i++)
            {
                var diagonal = solver.ReorderedDiagonal(i);
                if (diagonal != null)
                {
                    diagonal.Value += gmin;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Apply a gmin to the diagonal elements
        /// </summary>
        /// <param name="solver">Solver</param>
        /// <param name="gmin">Conductance</param>
        public static void ApplyDiagonalGmin(this SparseLinearSystem <double> solver, double gmin)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            // Skip if not necessary
            if (gmin <= 0.0)
            {
                return;
            }

            // Add to the diagonal
            for (int i = 1; i <= solver.Order; i++)
            {
                var diagonal = solver.ReorderedDiagonal(i);
                if (diagonal != null)
                {
                    diagonal.Value += gmin;
                }
            }
        }