コード例 #1
0
ファイル: SwitchReader.cs プロジェクト: lulzzz/SpiceSharp
        /// <summary>
        /// Generate
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateVSW(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            VoltageSwitch vsw = new VoltageSwitch(name);

            vsw.ReadNodes(netlist.Path, parameters);

            // Read the model
            if (parameters.Count < 5)
            {
                throw new ParseException(parameters[3], "Model expected", false);
            }
            vsw.SetModel(netlist.FindModel <VoltageSwitchModel>(parameters[4]));

            // Optional ON or OFF
            if (parameters.Count == 6)
            {
                switch (parameters[5].image.ToLower())
                {
                case "on":
                    vsw.SetOn();
                    break;

                case "off":
                    vsw.SetOff();
                    break;

                default:
                    throw new ParseException(parameters[5], "ON or OFF expected");
                }
            }
            return(vsw);
        }
コード例 #2
0
ファイル: RLCMReader.cs プロジェクト: lulzzz/SpiceSharp
        /// <summary>
        /// Generate a capacitor
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateCap(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Capacitor cap = new Capacitor(name);

            cap.ReadNodes(netlist.Path, parameters);

            // Search for a parameter IC, which is common for both types of capacitors
            for (int i = 3; i < parameters.Count; i++)
            {
                if (parameters[i].kind == ASSIGNMENT)
                {
                    AssignmentToken at = parameters[i] as AssignmentToken;
                    if (at.Name.image.ToLower() == "ic")
                    {
                        double ic = netlist.ParseDouble(at.Value);
                        cap.CAPinitCond.Set(ic);
                        parameters.RemoveAt(i);
                        break;
                    }
                }
            }

            // The rest is just dependent on the number of parameters
            if (parameters.Count == 3)
            {
                cap.CAPcapac.Set(netlist.ParseDouble(parameters[2]));
            }
            else
            {
                cap.SetModel(netlist.FindModel <CapacitorModel>(parameters[2]));
                switch (parameters[2].kind)
                {
                case WORD:
                case IDENTIFIER:
                    cap.SetModel(netlist.Path.FindModel <CapacitorModel>(netlist.Circuit.Objects, new CircuitIdentifier(parameters[2].image)));
                    break;

                default:
                    throw new ParseException(parameters[2], "Model name expected");
                }
                netlist.ReadParameters(cap, parameters, 2);
                if (!cap.CAPlength.Given)
                {
                    throw new ParseException(parameters[1], "L needs to be specified", false);
                }
            }

            return(cap);
        }
コード例 #3
0
ファイル: SwitchReader.cs プロジェクト: lulzzz/SpiceSharp
        /// <summary>
        /// Generate a current switch
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateCSW(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            CurrentSwitch csw = new CurrentSwitch(name);

            csw.ReadNodes(netlist.Path, parameters);
            switch (parameters.Count)
            {
            case 2: throw new ParseException(parameters[1], "Voltage source expected", false);

            case 3: throw new ParseException(parameters[2], "Model expected", false);
            }

            // Get the controlling voltage source
            switch (parameters[2].kind)
            {
            case WORD:
                csw.CSWcontName = new CircuitIdentifier(parameters[2].image);
                break;

            default:
                throw new ParseException(parameters[2], "Voltage source name expected");
            }

            // Get the model
            csw.SetModel(netlist.FindModel <CurrentSwitchModel>(parameters[3]));

            // Optional on or off
            if (parameters.Count > 4)
            {
                switch (parameters[4].image.ToLower())
                {
                case "on":
                    csw.SetOn();
                    break;

                case "off":
                    csw.SetOff();
                    break;

                default:
                    throw new ParseException(parameters[4], "ON or OFF expected");
                }
            }
            return(csw);
        }
コード例 #4
0
ファイル: RLCMReader.cs プロジェクト: lulzzz/SpiceSharp
        /// <summary>
        /// Generate a resistor
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateRes(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Resistor res = new Resistor(name);

            res.ReadNodes(netlist.Path, parameters);

            // We have two possible formats:
            // Normal: RXXXXXXX N1 N2 VALUE
            if (parameters.Count == 3)
            {
                res.RESresist.Set(netlist.ParseDouble(parameters[2]));
            }
            else
            {
                // Read the model
                res.SetModel(netlist.FindModel <ResistorModel>(parameters[2]));
                netlist.ReadParameters(res, parameters, 3);
                if (!res.RESlength.Given)
                {
                    throw new ParseException(parameters[parameters.Count - 1], "L needs to be specified", false);
                }
            }
            return(res);
        }
コード例 #5
0
        /// <summary>
        /// Generate a bipolar transistor
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected override ICircuitObject Generate(string type, CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            // I think the BJT definition is ambiguous (eg. QXXXX NC NB NE MNAME OFF can be either substrate = MNAME, model = OFF or model name = MNAME and transistor is OFF
            // We will only allow 3 terminals if there are only 4 parameters
            BJT bjt = new BJT(name);

            // If the component is of the format QXXX NC NB NE MNAME we will insert NE again before the model name
            if (parameters.Count == 4)
            {
                parameters.Insert(3, parameters[2]);
            }
            bjt.ReadNodes(netlist.Path, parameters);

            if (parameters.Count < 5)
            {
                throw new ParseException(parameters[3], "Model expected", false);
            }
            bjt.SetModel(netlist.FindModel <BJTModel>(parameters[4]));

            for (int i = 5; i < parameters.Count; i++)
            {
                switch (parameters[i].kind)
                {
                case WORD:
                    switch (parameters[i].image.ToLower())
                    {
                    case "on": bjt.BJToff = false; break;

                    case "off": bjt.BJToff = true; break;

                    default: throw new ParseException(parameters[i], "ON or OFF expected");
                    }
                    break;

                case ASSIGNMENT:
                    var at = parameters[i] as AssignmentToken;
                    if (at.Name.image.ToLower() == "ic")
                    {
                        bjt.SetIC(netlist.ParseDoubleVector(at.Value));
                    }
                    else
                    {
                        throw new ParseException(parameters[i], "IC expected");
                    }
                    break;

                case VALUE:
                case EXPRESSION:
                    if (!bjt.BJTarea.Given)
                    {
                        bjt.BJTarea.Set(netlist.ParseDouble(parameters[i]));
                    }
                    else if (!bjt.BJTtemp.Given)
                    {
                        bjt.BJT_TEMP = netlist.ParseDouble(parameters[i]);
                    }
                    else
                    {
                        throw new ParseException(parameters[i], "Invalid parameter");
                    }
                    break;

                default:
                    throw new ParseException(parameters[i], "Invalid parameter");
                }
            }

            return(bjt);
        }
コード例 #6
0
ファイル: DiodeReader.cs プロジェクト: lulzzz/SpiceSharp
        /// <summary>
        /// Generate a diode
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected override ICircuitObject Generate(string type, CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Diode dio = new Diode(name);

            dio.ReadNodes(netlist.Path, parameters);

            if (parameters.Count < 3)
            {
                throw new ParseException(parameters[1], "Model expected", false);
            }
            dio.SetModel(netlist.FindModel <DiodeModel>(parameters[2]));

            // Read the rest of the parameters
            for (int i = 3; i < parameters.Count; i++)
            {
                switch (parameters[i].kind)
                {
                case WORD:
                    switch (parameters[i].image.ToLower())
                    {
                    case "on":
                        dio.DIOoff = false;
                        break;

                    case "off":
                        dio.DIOoff = true;
                        break;

                    default:
                        throw new ParseException(parameters[i], "ON or OFF expected");
                    }
                    break;

                case ASSIGNMENT:
                    AssignmentToken at = parameters[i] as AssignmentToken;
                    if (at.Name.image.ToLower() == "ic")
                    {
                        dio.DIOinitCond = netlist.ParseDouble(at.Value);
                    }
                    else
                    {
                        throw new ParseException(parameters[i], "IC expected");
                    }
                    break;

                case VALUE:
                case EXPRESSION:
                    if (!dio.DIOarea.Given)
                    {
                        dio.DIOarea.Set(netlist.ParseDouble(parameters[i]));
                    }
                    else if (!dio.DIOtemp.Given)
                    {
                        dio.DIO_TEMP = netlist.ParseDouble(parameters[i]);
                    }
                    else
                    {
                        throw new ParseException(parameters[i], "Invalid parameter");
                    }
                    break;

                default:
                    throw new ParseException(parameters[i], "Unrecognized parameter");
                }
            }

            return(dio);
        }