Beispiel #1
0
        /// <summary>
        /// Set up the simulation.
        /// </summary>
        /// <param name="entities">Entities that are included in the simulation.</param>
        /// <exception cref="ArgumentNullException">circuit</exception>
        /// <exception cref="CircuitException">{0}: No circuit objects for simulation".FormatString(Name)</exception>
        protected virtual void Setup(EntityCollection entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }
            if (entities.Count == 0)
            {
                throw new CircuitException("{0}: No circuit objects for simulation".FormatString(Name));
            }

            // Use the same comparers as the circuit. This is crucial because they use the same identifiers!
            EntityParameters = new ParameterPool(entities.Comparer);
            EntityBehaviors  = new BehaviorPool(entities.Comparer, BehaviorTypes.ToArray());

            // Create the variables that will need solving
            if (Configurations.TryGet(out CollectionConfiguration cconfig))
            {
                Variables        = new VariableSet(cconfig.VariableComparer ?? EqualityComparer <string> .Default);
                _cloneParameters = cconfig.CloneParameters;
            }
            else
            {
                Variables        = new VariableSet();
                _cloneParameters = false;
            }

            // Setup all entity parameters and behaviors
            SetupParameters(entities);
            SetupBehaviors(entities);
        }
Beispiel #2
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>
 /// Setup the simulation state.
 /// </summary>
 /// <param name="nodes">The unknown variables for which the state is used.</param>
 /// <exception cref="ArgumentNullException">nodes</exception>
 public override void Setup(VariableSet nodes)
 {
     if (nodes == null)
     {
         throw new ArgumentNullException(nameof(nodes));
     }
     Solution = new DenseVector <Complex>(Solver.Order);
     base.Setup(nodes);
 }
Beispiel #4
0
        /// <summary>
        /// Setup the simulation state.
        /// </summary>
        /// <param name="nodes">The unknown variables for which the state is used.</param>
        public override void Setup(VariableSet nodes)
        {
            nodes.ThrowIfNull(nameof(nodes));

            // Initialize all matrices
            Solution    = new DenseVector <double>(Solver.Order);
            OldSolution = new DenseVector <double>(Solver.Order);

            // Initialize all states and parameters
            Init  = InitializationModes.None;
            UseDc = true;
            UseIc = false;

            base.Setup(nodes);
        }
Beispiel #5
0
        /// <summary>
        /// Initialize the state
        /// </summary>
        /// <param name="nodes">Nodes</param>
        public override void Initialize(VariableSet nodes)
        {
            if (nodes == null)
            {
                throw new ArgumentNullException(nameof(nodes));
            }

            // Initialize all matrices
            Solution    = new DenseVector <double>(Solver.Order);
            OldSolution = new DenseVector <double>(Solver.Order);

            // Initialize all states and parameters
            Init         = InitializationStates.None;
            Sparse       = SparseStates.ShouldReorder;
            Domain       = DomainType.None;
            DiagonalGmin = 0;
            UseDc        = true;
            UseIc        = false;

            base.Initialize(nodes);
        }
 /// <summary>
 /// Setup the simulation state.
 /// </summary>
 /// <param name="nodes">The unknown variables for which the state is used.</param>
 /// <exception cref="ArgumentNullException">nodes</exception>
 public override void Setup(VariableSet nodes)
 {
     nodes.ThrowIfNull(nameof(nodes));
     Solution = new DenseVector <Complex>(Solver.Order);
     base.Setup(nodes);
 }