Exemplo n.º 1
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            Transient tran = new Transient("Transient " + (netlist.Simulations.Count + 1));

            switch (st.Parameters.Count)
            {
            case 0: throw new ParseException(st.Name, "Step expected", false);

            case 1: throw new ParseException(st.Parameters[0], "Maximum time expected", false);
            }

            // Standard st.Parameters
            tran.Step      = netlist.ParseDouble(st.Parameters[0]);
            tran.FinalTime = netlist.ParseDouble(st.Parameters[1]);

            // Optional st.Parameters
            if (st.Parameters.Count > 2)
            {
                tran.InitTime = netlist.ParseDouble(st.Parameters[2]);
            }
            if (st.Parameters.Count > 3)
            {
                tran.MaxStep = netlist.ParseDouble(st.Parameters[3]);
            }

            netlist.Simulations.Add(tran);
            Generated = tran;
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find the parameters
        /// </summary>
        /// <param name="definition">Subcircuit definition</param>
        /// <param name="parameters">Parameters</param>
        /// <returns></returns>
        private Dictionary <CircuitIdentifier, double> GenerateParameters(Netlist netlist, SubcircuitDefinition definition, Dictionary <CircuitIdentifier, Token> parameters)
        {
            // Our new parameters
            Dictionary <CircuitIdentifier, double> np = new Dictionary <CircuitIdentifier, double>();

            // Add local parameters
            if (parameters != null)
            {
                foreach (var item in parameters)
                {
                    np.Add(item.Key, netlist.ParseDouble(item.Value));
                }
            }

            // Add default parameters
            if (definition.Defaults != null)
            {
                foreach (var item in definition.Defaults)
                {
                    if (!np.ContainsKey(item.Key))
                    {
                        np.Add(item.Key, netlist.ParseDouble(item.Value));
                    }
                }
            }

            // Other parameters
            if (Parameters != null)
            {
                switch (ParameterScope)
                {
                case ScopeRule.Descend:

                    // Copy all parameters from the previous node
                    foreach (var item in Parameters)
                    {
                        if (!np.ContainsKey(item.Key))
                        {
                            np.Add(item.Key, item.Value);
                        }
                    }
                    break;

                case ScopeRule.GlobalLocal:

                    // Only copy the global parameters
                    foreach (var item in globalparameters)
                    {
                        if (!np.ContainsKey(item.Key))
                        {
                            np.Add(item.Key, item.Value);
                        }
                    }
                    break;
                }
            }

            // Return results
            return(np);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate a current source
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateISRC(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Currentsource isrc = new Currentsource(name);

            isrc.ReadNodes(netlist.Path, parameters);

            // We can have a value or just DC
            for (int i = 2; i < parameters.Count; i++)
            {
                // DC specification
                if (i == 2 && parameters[i].image.ToLower() == "dc")
                {
                    i++;
                    isrc.ISRCdcValue.Set(netlist.ParseDouble(parameters[i]));
                }
                else if (i == 2 && ReaderExtension.IsValue(parameters[i]))
                {
                    isrc.ISRCdcValue.Set(netlist.ParseDouble(parameters[i]));
                }

                // AC specification
                else if (parameters[i].image.ToLower() == "ac")
                {
                    i++;
                    isrc.ISRCacMag.Set(netlist.ParseDouble(parameters[i]));

                    // Look forward for one more value
                    if (i + 1 < parameters.Count && ReaderExtension.IsValue(parameters[i + 1]))
                    {
                        i++;
                        isrc.ISRCacPhase.Set(netlist.ParseDouble(parameters[i]));
                    }
                }

                // Waveforms
                else if (parameters[i].kind == BRACKET)
                {
                    // Find the reader
                    BracketToken bt = parameters[i] as BracketToken;
                    Statement    st = new Statement(StatementType.Waveform, bt.Name, bt.Parameters);
                    isrc.ISRCwaveform = (IWaveform)netlist.Readers.Read(st, netlist);
                }
                else
                {
                    throw new ParseException(parameters[i], "Unrecognized parameter");
                }
            }

            return(isrc);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generate a mutual inductance
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateMut(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            MutualInductance mut = new MutualInductance(name);

            switch (parameters.Count)
            {
            case 0: throw new ParseException($"Inductor name expected for mutual inductance \"{name}\"");

            case 1: throw new ParseException(parameters[0], "Inductor name expected", false);

            case 2: throw new ParseException(parameters[1], "Coupling factor expected", false);
            }

            // Read two inductors
            if (!ReaderExtension.IsName(parameters[0]))
            {
                throw new ParseException(parameters[0], "Component name expected");
            }
            mut.MUTind1 = new CircuitIdentifier(parameters[0].image);
            if (!ReaderExtension.IsName(parameters[1]))
            {
                throw new ParseException(parameters[1], "Component name expected");
            }
            mut.MUTind2 = new CircuitIdentifier(parameters[1].image);
            mut.MUTcoupling.Set(netlist.ParseDouble(parameters[2]));
            return(mut);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Generate
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateVCCS(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            VoltageControlledCurrentsource vccs = new VoltageControlledCurrentsource(name);

            vccs.ReadNodes(netlist.Path, parameters);

            if (parameters.Count < 5)
            {
                throw new ParseException(parameters[3], "Value expected", false);
            }
            vccs.VCCScoeff.Set(netlist.ParseDouble(parameters[4]));
            return(vccs);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Parse a vector of double values
 /// </summary>
 /// <param name="netlist">The netlist</param>
 /// <param name="t">The token</param>
 /// <returns></returns>
 public static double[] ParseDoubleVector(this Netlist netlist, Token t)
 {
     if (t.kind == TokenConstants.VECTOR)
     {
         var      vt     = t as VectorToken;
         double[] values = new double[vt.Tokens.Length];
         for (int i = 0; i < values.Length; i++)
         {
             values[i] = netlist.ParseDouble(vt.Tokens[i]);
         }
         return(values);
     }
     else if (t.kind == VALUE || t.kind == EXPRESSION)
     {
         return new double[] { netlist.ParseDouble(t) }
     }
     ;
     else
     {
         throw new ParseException(t, "Vector expected");
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            Interpolated ip = new Interpolated();

            if (st.Parameters.Count < 4)
            {
                throw new ParseException(st.Parameters[st.Parameters.Count - 1], "At least 2 points expected", false);
            }
            if (st.Parameters.Count % 2 != 0)
            {
                throw new ParseException(st.Parameters[st.Parameters.Count - 1], "Value expected", false);
            }
            ip.Time  = new double[st.Parameters.Count / 2];
            ip.Value = new double[st.Parameters.Count / 2];
            for (int i = 0; i < st.Parameters.Count / 2; i++)
            {
                ip.Time[i]  = netlist.ParseDouble(st.Parameters[i * 2]);
                ip.Value[i] = netlist.ParseDouble(st.Parameters[i * 2 + 1]);
            }

            Generated = ip;
            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            DC  dc    = new DC("DC " + (netlist.Simulations.Count + 1));
            int count = st.Parameters.Count / 4;

            switch (st.Parameters.Count - 4 * count)
            {
            case 0:
                if (st.Parameters.Count == 0)
                {
                    throw new ParseException(st.Name, "Source st.Name expected");
                }
                break;

            case 1: throw new ParseException(st.Parameters[count * 4], "Start value expected");

            case 2: throw new ParseException(st.Parameters[count * 4 + 1], "Stop value expected");

            case 3: throw new ParseException(st.Parameters[count * 4 + 2], "Step value expected");
            }

            // Format: .DC SRCNAM VSTART VSTOP VINCR [SRC2 START2 STOP2 INCR2]
            for (int i = 0; i < count; i++)
            {
                DC.Sweep sweep = new DC.Sweep(
                    new CircuitIdentifier(st.Parameters[i * 4].image),
                    netlist.ParseDouble(st.Parameters[i * 4 + 1]),
                    netlist.ParseDouble(st.Parameters[i * 4 + 2]),
                    netlist.ParseDouble(st.Parameters[i * 4 + 3]));
                dc.Sweeps.Insert(0, sweep);
            }

            netlist.Simulations.Add(dc);
            Generated = dc;
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">The type of the waveform</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">The netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            IParameterized w = Generate(type);

            if (st.Parameters.Count > keys.Length)
            {
                throw new ParseException(st.Name, $"Too many arguments for waveform \"{st.Name.image}\"");
            }
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                w.Set(keys[i], netlist.ParseDouble(st.Parameters[i]));
            }

            Generated = w;
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Generate an inductor
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateInd(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Inductor ind = new Inductor(name);

            ind.ReadNodes(netlist.Path, parameters);

            // Read the value
            if (parameters.Count < 3)
            {
                throw new ParseException(parameters[1], "Inductance expected", false);
            }
            ind.INDinduct.Set(netlist.ParseDouble(parameters[2]));

            // Read initial conditions
            netlist.ReadParameters(ind, parameters, 3);
            return(ind);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Generate a CCCS
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateCCCS(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            CurrentControlledCurrentsource cccs = new CurrentControlledCurrentsource(name);

            cccs.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], "Value expected", false);
            }

            if (!ReaderExtension.IsName(parameters[2]))
            {
                throw new ParseException(parameters[2], "Component name expected");
            }
            cccs.CCCScontName = new CircuitIdentifier(parameters[2].image);
            cccs.CCCScoeff.Set(netlist.ParseDouble(parameters[3]));
            return(cccs);
        }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            // Only assignments are possible
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                switch (st.Parameters[i].kind)
                {
                case ASSIGNMENT:
                    AssignmentToken at = st.Parameters[i] as AssignmentToken;
                    switch (at.Name.kind)
                    {
                    case BRACKET:
                        BracketToken bt = at.Name as BracketToken;
                        if (bt.Name.image.ToLower() == "v" && bt.Parameters.Length == 1 && ReaderExtension.IsNode(bt.Parameters[0]))
                        {
                            netlist.Circuit.Nodes.Nodeset.Add(new CircuitIdentifier(bt.Parameters[0].image), netlist.ParseDouble(at.Value));
                        }
                        else
                        {
                            throw new ParseException(st.Parameters[i], "Invalid format, v(<node>)=<ic> expected");
                        }
                        break;

                    default:
                        if (ReaderExtension.IsNode(at.Name))
                        {
                            netlist.Circuit.Nodes.Nodeset.Add(new CircuitIdentifier(at.Name.image), netlist.ParseDouble(at.Value));
                        }
                        else
                        {
                            throw new ParseException(st.Parameters[i], "Invalid format, <node>=<ic> expected");
                        }
                        break;
                    }
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Read the parameter
        /// </summary>
        /// <param name="st"></param>
        /// <param name="netlist"></param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            // Read all assignments
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                switch (st.Parameters[i].kind)
                {
                case ASSIGNMENT:
                    AssignmentToken at = st.Parameters[i] as AssignmentToken;
                    switch (at.Name.kind)
                    {
                    case WORD:
                        netlist.Path.Parameters.Add(new CircuitIdentifier(at.Name.image), netlist.ParseDouble(at.Value));
                        break;

                    default:
                        throw new ParseException(at.Name, "Parameter expected");
                    }
                    break;

                default:
                    throw new ParseException(st.Parameters[i], "Assignment expected");
                }
            }

            Generated = null;
            return(true);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            Noise noise = new Noise("Noise " + (netlist.Simulations.Count + 1));

            // Check parameter count
            switch (st.Parameters.Count)
            {
            case 0: throw new ParseException("Output expected for .NOISE");

            case 1: throw new ParseException(st.Parameters[0], "Source expected", false);

            case 2: throw new ParseException(st.Parameters[1], "Step type expected", false);

            case 3: throw new ParseException(st.Parameters[2], "Number of points expected", false);

            case 4: throw new ParseException(st.Parameters[3], "Starting frequency expected", false);

            case 5: throw new ParseException(st.Parameters[4], "Stopping frequency expected", false);

            case 6: break;

            case 7: break;

            default:
                throw new ParseException(st.Parameters[7], "Too many parameter");
            }

            // The first parameters needs to specify the output voltage
            if (st.Parameters[0].kind == BRACKET)
            {
                var bracket = st.Parameters[0] as BracketToken;
                if (bracket.Name.image.ToLower() == "v")
                {
                    Token t;
                    switch (bracket.Parameters.Length)
                    {
                    // V(A, B)
                    case 2:
                        t               = bracket.Parameters[0];
                        noise.Output    = IsNode(t) ? new CircuitIdentifier(t.image) : throw new ParseException(t, "Node expected");
                        t               = bracket.Parameters[1];
                        noise.OutputRef = IsNode(t) ? new CircuitIdentifier(t.image) : throw new ParseException(t, "Node expected");
                        break;

                    // V(A)
                    case 1:
                        t            = bracket.Parameters[0];
                        noise.Output = IsNode(t) ? new CircuitIdentifier(t.image) : throw new ParseException(t, "Node expected");
                        break;

                    default:
                        throw new ParseException(bracket.Name, "1 or 2 nodes expected", false);
                    }
                }
                else
                {
                    throw new ParseException(bracket.Name, "Invalid output");
                }
            }
            else
            {
                throw new ParseException(st.Parameters[0], "Invalid output");
            }

            // The second parameter needs to be source
            if (!IsName(st.Parameters[1]))
            {
                throw new ParseException(st.Parameters[1], "Invalid source");
            }
            noise.Input = new CircuitIdentifier(st.Parameters[1].image);

            // Sweep parameters
            switch (st.Parameters[2].image.ToLower())
            {
            case "lin": noise.StepType = Noise.StepTypes.Linear; break;

            case "dec": noise.StepType = Noise.StepTypes.Decade; break;

            case "oct": noise.StepType = Noise.StepTypes.Octave; break;

            default:
                throw new ParseException(st.Parameters[2], "Invalid step type");
            }
            noise.NumberSteps = (int)(netlist.ParseDouble(st.Parameters[3]) + 0.25);
            noise.StartFreq   = netlist.ParseDouble(st.Parameters[4]);
            noise.StopFreq    = netlist.ParseDouble(st.Parameters[5]);

            Generated = noise;
            netlist.Simulations.Add(noise);
            return(true);
        }
Exemplo n.º 18
0
        /// <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);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            // Read all options
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                switch (st.Parameters[i].kind)
                {
                case ASSIGNMENT:
                    AssignmentToken at  = st.Parameters[i] as AssignmentToken;
                    string          key = at.Name.image.ToLower();
                    switch (key)
                    {
                    case "abstol": SimulationConfiguration.Default.AbsTol = netlist.ParseDouble(at.Value); break;

                    case "reltol": SimulationConfiguration.Default.RelTol = netlist.ParseDouble(at.Value); break;

                    case "gmin": SimulationConfiguration.Default.Gmin = netlist.ParseDouble(at.Value); break;

                    case "itl1": SimulationConfiguration.Default.DcMaxIterations = (int)Math.Round(netlist.ParseDouble(at.Value)); break;

                    case "itl2": SimulationConfiguration.Default.SweepMaxIterations = (int)Math.Round(netlist.ParseDouble(at.Value)); break;

                    case "itl4": SimulationConfiguration.Default.TranMaxIterations = (int)Math.Round(netlist.ParseDouble(at.Value)); break;

                    case "temp": netlist.Circuit.State.Temperature = netlist.ParseDouble(at.Value) + Circuit.CONSTCtoK; break;

                    case "tnom": netlist.Circuit.State.NominalTemperature = netlist.ParseDouble(at.Value) + Circuit.CONSTCtoK; break;

                    case "method":
                        switch (at.Value.image.ToLower())
                        {
                        case "trap":
                        case "trapezoidal":
                            SimulationConfiguration.Default.Method = new IntegrationMethods.Trapezoidal();
                            break;
                        }
                        break;

                    default:
                        throw new ParseException(st.Parameters[i], "Unrecognized option");
                    }
                    break;

                case WORD:
                    key = st.Parameters[i].image.ToLower();
                    switch (key)
                    {
                    case "keepopinfo": SimulationConfiguration.Default.KeepOpInfo = true; break;

                    default:
                        throw new ParseException(st.Parameters[i], "Unrecognized option");
                    }
                    break;

                default:
                    throw new ParseException(st.Parameters[i], "Unrecognized option");
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Read a transistor model
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            // Errors
            switch (st.Parameters.Count)
            {
            case 0: throw new ParseException(st.Name, "Model name and type expected", false);
            }

            // The model depends on the model level, find the model statement
            int level = 0; string version = null;
            int lindex = -1, vindex = -1;

            for (int i = 0; i < st.Parameters.Count; i++)
            {
                if (st.Parameters[i].kind == ASSIGNMENT)
                {
                    AssignmentToken at = st.Parameters[i] as AssignmentToken;
                    if (at.Name.image.ToLower() == "level")
                    {
                        lindex = i;
                        level  = (int)Math.Round(netlist.ParseDouble(at.Value));
                    }
                    if (at.Name.image.ToLower() == "version")
                    {
                        vindex  = i;
                        version = at.Value.image.ToLower();
                    }
                    if (vindex >= 0 && lindex >= 0)
                    {
                        break;
                    }
                }
            }
            if (lindex >= 0)
            {
                st.Parameters.RemoveAt(lindex);
            }
            if (vindex >= 0)
            {
                st.Parameters.RemoveAt(vindex < lindex ? vindex : vindex - 1);
            }

            // Generate the model
            ICircuitObject model = null;

            if (Levels.ContainsKey(level))
            {
                model = Levels[level].Invoke(new CircuitIdentifier(st.Name.image), type, version);
            }
            else
            {
                throw new ParseException(st.Name, $"Unknown mosfet model level {level}");
            }

            // Read all the parameters
            netlist.ReadParameters((IParameterized)model, st.Parameters);

            // Output
            netlist.Circuit.Objects.Add(model);
            Generated = model;
            return(true);
        }