示例#1
0
        /// <summary>Initializes print statement for given circuit model and returns set of errors that occured (if any).</summary>
        /// <param name="circuitModel">Current model of the circuit.</param>
        /// <returns>Set of errors that errored (if any).</returns>
        public override IEnumerable <SpiceParserError> Initialize(LargeSignalCircuitModel circuitModel)
        {
            var model = circuitModel.FindDevice(name);

            provider = model.GetDeviceStateProviders().SingleOrDefault(pr => pr.Name == stat);
            var errorInfos = provider == null
                                ? new[]
            {
                SpiceParserError.Create(SpiceParserErrorCode.NoPrintProvider, 0, 0, stat, name)
            }
                                : Enumerable.Empty <SpiceParserError>();

            return(errorInfos);
        }
示例#2
0
        private static CircuitDefinition TryCreateCircuitDefinition(ParsingContext ctx)
        {
            CircuitDefinition circuitDefinition = null;

            try
            {
                circuitDefinition = ctx.CurrentScope.CircuitBuilder.BuildCircuit();
            }
            catch (Exception e)
            {
                // translate node indexes to node names used in the input file
                SpiceParserError error;
                switch (e)
                {
                case NoDcPathToGroundException ex:
                    error = new SpiceParserError(SpiceParserErrorCode.NoDcPathToGround, 0, 0,
                                                 ctx.SymbolTable.GetNodeNames(ex.Nodes).Cast <object>().ToArray());
                    break;

                case NotConnectedSubcircuitException ex:
                    var names = ex.Components.Select(c => ctx.SymbolTable.GetNodeNames(c).ToArray()).Cast <object>()
                                .ToArray();
                    error = new SpiceParserError(SpiceParserErrorCode.SubcircuitNotConnected, 0, 0, names);
                    break;

                case VoltageBranchCycleException ex:
                    error = new SpiceParserError(SpiceParserErrorCode.VoltageBranchCycle, 0, 0,
                                                 ex.Devices.Select(el => el.Tag).ToArray());
                    break;

                case CurrentBranchCutsetException ex:
                    error = new SpiceParserError(SpiceParserErrorCode.CurrentBranchCutset, 0, 0,
                                                 ex.Devices.Select(el => el.Tag).ToArray());
                    break;

                default:
                    throw;
                }

                ctx.Errors.Add(error);
            }

            return(circuitDefinition);
        }