Exemple #1
0
 public override double DCDerivative(DCSolver solver, int f, VariableIdentifier var)
 {
     if (f == 0)
     {
         if (var.type == VariableType.NET)
         {
             if (var.net == PinConnections[0])
             {
                 return(1 / Resistance);
             }
             if (var.net == PinConnections[1])
             {
                 return(-1 / Resistance);
             }
         }
         else
         {
             if ((var.component == this) && (var.pin == 0))
             {
                 return(-1);
             }
         }
     }
     return(0.0d);
 }
Exemple #2
0
 public override double DCDerivative(DCSolver solver, int f, VariableIdentifier var)
 {
     if (f == 0)
     {
         if (var.type == VariableType.NET)
         {
             if (var.net == PinConnections[0])
             {
                 return(SaturationCurrent * (1 / (IdealityFactor * Math.vTherm)) * Math.exp_deriv(((solver.GetNetVoltage(PinConnections[0]) - solver.GetNetVoltage(PinConnections[1]) - SeriesResistance * solver.GetPinCurrent(this, 0))) / (IdealityFactor * Math.vTherm)));
             }
             else if (var.net == PinConnections[1])
             {
                 return(-1 * SaturationCurrent * (1 / (IdealityFactor * Math.vTherm)) * Math.exp_deriv(((solver.GetNetVoltage(PinConnections[0]) - solver.GetNetVoltage(PinConnections[1]) - SeriesResistance * solver.GetPinCurrent(this, 0))) / (IdealityFactor * Math.vTherm)));
             }
         }
         else
         {
             if ((var.component == this) && (var.pin == 0))
             {
                 return(-1 * SeriesResistance * SaturationCurrent * (1 / (IdealityFactor * Math.vTherm)) * Math.exp_deriv(((solver.GetNetVoltage(PinConnections[0]) - solver.GetNetVoltage(PinConnections[1]) - SeriesResistance * solver.GetPinCurrent(this, 0))) / (IdealityFactor * Math.vTherm)) - 1);
             }
         }
     }
     return(0.0d);
 }
Exemple #3
0
        /*
         *  Evaluate the partial derivatives for the above functions
         */
        public double DCDerivative(DCSolver solver, VariableIdentifier var)
        {
            if (var.type == VariableType.NET)
            {
                return(0.0d);
            }
            double deriv = 0.0d;

            foreach (NetConnection iter in connections)
            {
                if (var == iter.component.getComponentVariableIdentifier(iter.pin))
                {
                    deriv += -1;
                }
                if (iter.component == var.component)
                {
                    if (iter.pin == iter.component.GetNumberOfPins() - 1)
                    {
                        if (var.pin < iter.component.GetNumberOfPins() - 1)
                        {
                            deriv += 1;
                        }
                    }
                }
            }
            return(deriv);
        }
Exemple #4
0
 public TransientSolver(DCSolver init)
 {
     NetVariables       = init.NetVariables;
     ComponentVariables = init.ComponentVariables;
     VariableData       = init.VariableData;
     VariableValues.Push(init.VariableValues);
     SolverCircuit = init.SolverCircuit;
     times.Push(0);
 }
Exemple #5
0
        /*Evaluate a Kirchoff-based function for the currents in the pins connected to the net,
         * available for both DC and transient simulations
         * (irrelevant for fixed-voltage nets)
         */
        public double DCFunction(DCSolver solver)
        {
            double sum = 0;

            foreach (NetConnection iter in connections)
            {
                sum -= solver.GetPinCurrent(iter.component, iter.pin);
            }
            return(sum);
        }
Exemple #6
0
 // f0: (V1 - V2) / R - I
 public override double DCFunction(DCSolver solver, int f)
 {
     if (f == 0)
     {
         double L = (solver.GetNetVoltage(PinConnections[0]) - solver.GetNetVoltage(PinConnections[1])) / Resistance;
         double R = solver.GetPinCurrent(this, 0);
         return(L - R);
     }
     else
     {
         return(0.0d);
     }
 }
Exemple #7
0
 // f0: Is * (e ^ ((Vd - IRs)/(n*Vt)) - 1) - I
 public override double DCFunction(DCSolver solver, int f)
 {
     if (f == 0)
     {
         double L = SaturationCurrent *
                    (Math.exp_safe(((solver.GetNetVoltage(PinConnections[0]) - solver.GetNetVoltage(PinConnections[1])) - SeriesResistance * solver.GetPinCurrent(this, 0)) / (IdealityFactor * Math.vTherm)) - 1);
         double R = solver.GetPinCurrent(this, 0);
         return(L - R);
     }
     else
     {
         return(0.0d);
     }
 }
Exemple #8
0
 /*
  * Evaluate the partial derivatives for the above functions
  */
 public virtual double DCDerivative(DCSolver solver, int f, VariableIdentifier var)
 {
     return(0.0d);
 }
Exemple #9
0
 /*
  * Returns a function that can be used by the non-linear DC operating point solver
  * to solve as f(x) = 0
  * For components with greater than 2 pins, f is the indentifier of the function 0 <= f < n-1
  */
 public virtual double DCFunction(DCSolver solver, int f)
 {
     return(0.0d);
 }
Exemple #10
0
        static void Main(string[] args)
        {
            string line     = "";
            string netlist  = "";
            double simSpeed = 0;
            int    testid   = 0;

            while (true)
            {
                line = ForTesting[testid++];
                // line = Console.ReadLine();
                if (line.Contains("START"))
                {
                    simSpeed = Convert.ToDouble(line.Substring(6));
                    break;
                }
                netlist += line;
                netlist += "\n";
            }

            circuit.ReadNetlist(netlist);
            Console.Write("VARS t,");

            for (int i = 0; i < circuit.Nets.Count; i++)
            {
                Console.Write("V(" + circuit.Nets[i].NetName + "),");
            }
            for (int i = 0; i < circuit.Components.Count; i++)
            {
                for (int j = 0; j < circuit.Components[i].GetNumberOfPins(); j++)
                {
                    Console.Write("I(" + circuit.Components[i].ComponentID + "." + j + "),");
                }
            }
            Console.WriteLine();

            DCSolver solver = new DCSolver(circuit);
            bool     result = false;

            try
            {
                result = solver.Solve();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to obtain initial operating point");
                circuit.ReportError("EXCEPTION", true);
            }
            if (!result)
            {
                circuit.ReportError("CONVERGENCE", false);
            }

            TransientSolver tranSolver = new TransientSolver(solver);

            tranSolver.InteractiveCallback = interactiveTick;
            Thread updaterThread = new Thread(new ThreadStart(iothread));

            updaterThread.Start();
            tranSolver.RunInteractive(simSpeed);
        }