public override void MouseUp(Circuit.Coord At)
 {
     b = At;
     if (a == b)
         if (Clicked != null)
             Clicked(RelevantOf(Target.AtPoint(a)));
 }
 public override void step(Circuit sim)
 {
     double v0 = lead_volt[1];
     double @out;
     if(state) {
         // Output is high
         if(lead_volt[0] > upperTrigger) {
             // Input voltage high enough to set output high
             state = false;
             @out = 5;
         } else {
             @out = 0;
         }
     } else {
         // Output is low
         if(lead_volt[0] < lowerTrigger) {
             // Input voltage low enough to set output low
             state = true;
             @out = 0;
         } else {
             @out = 5;
         }
     }
     double maxStep = slewRate * sim.timeStep * 1e9;
     @out = Math.Max(Math.Min(v0 + maxStep, @out), v0 - maxStep);
     sim.updateVoltageSource(0, lead_node[1], voltSource, @out);
 }
Exemple #3
0
        /// <summary>
        /// Define an IC based on a circuit with identified input and output ports.
        /// Ports must be a member of the circuit.
        /// </summary>
        /// <param name="circuit"></param>
        /// <param name="inputs"></param>
        /// <param name="outputs"></param>
        /// <param name="name"></param>
        public IC(Circuit circuit, UserInput[] inputs, UserOutput[] outputs, string name)
            : base(inputs.Length, outputs.Length)
        {
            foreach (UserInput p in inputs)
                if (!circuit.Contains(p))
                    throw new ArgumentException("not all inputs part of circuit");

            // we wire up the output ports so that any internal
            // change in the circuit results in
            // passing notification up the chain
            // this is not needed for input because
            // any input change will cause compute to be called
            // automatically
            foreach (UserOutput p in outputs)
            {
                p.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(p_PropertyChanged);
                if (!circuit.Contains(p))
                    throw new ArgumentException("not all outputs part of circuit");
            }
            _inputs = inputs;
            _outputs = outputs;
            _circuit = circuit;
            _name = name;

            RunCompute();
        }
        public SchematicEditor(Circuit.Schematic Schematic)
            : base(Schematic)
        {
            InitializeComponent();

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.SaveAs, SaveAs_Executed));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete_Executed, Delete_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, Cut_Executed, Cut_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, Copy_Executed, Copy_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, Paste_Executed, Paste_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAll_Executed, SelectAll_CanExecute));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, Undo_Executed, Undo_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, Redo_Executed, Redo_CanExecute));

            Focusable = true;
            Cursor = Cursors.Cross;

            edits = new EditStack();

            Tool = new SelectionTool(this);

            Width = 1600;
            Height = 1600;

            Origin = SnapToGrid(new Circuit.Coord((int)Width / 2, (int)Height / 2));
        }
        public void LawOfResistorsInSeriesTest(int in0)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<DCVoltageSource>();
            var volt1 = sim.Create<DCVoltageSource>();
            var resCompare = sim.Create<Resistor>(in0 * 100);

            List<Resistor> resistors = new List<Resistor>();
            for(int i = 0; i < in0; i++)
                resistors.Add(sim.Create<Resistor>());

            sim.Connect(volt0.leadPos, resistors.First().leadIn);

            for(int i = 1; i < in0 - 1; i++)
                sim.Connect(resistors[i - 1].leadOut, resistors[i].leadIn);

            sim.Connect(volt0.leadNeg, resistors.Last().leadOut);

            sim.Connect(volt1.leadPos, resCompare.leadIn);
            sim.Connect(resCompare.leadOut, volt1.leadNeg);

            sim.doTicks(100);

            Assert.AreEqual(Math.Round(resistors.Last().getCurrent(), 12), Math.Round(resCompare.getCurrent(), 12));
        }
 public override void stamp(Circuit sim)
 {
     int vn = sim.nodeCount + pins[2].voltSource;
     sim.stampNonLinear(vn);
     sim.stampNonLinear(0);
     sim.stampNonLinear(lead_node[2]);
 }
        public void CapacitorFrequencyTest(double frequency, double current)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            source0.frequency = frequency;

            var resistor0 = sim.Create<Resistor>(200);
            var cap0 = sim.Create<CapacitorElm>(3E-5);

            sim.Connect(source0, 1, resistor0, 0);
            sim.Connect(resistor0, 1, cap0, 0);
            sim.Connect(cap0, 1, source0, 0);

            var capScope = sim.Watch(cap0);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
        }
        public virtual CircuitStatistics GetCircuitStatistics(Circuit circuit)
        {
            var races = _raceRepository.GetRacesAllAtCircuit(circuit);

            var lastRace = races.OrderBy(x => x.StartDate).LastOrDefault(x => x.Entries.Count() > 0);
            var previousWinner = new DriverContract { Driver = new Driver() { AtomicName = "* None *", Name = "* None *" } };
            if (lastRace != null) {
                var previousWinningResult = lastRace.GetRaceResults().FirstOrDefault(x => x.Position == 1);
                if (previousWinningResult != null) {
                    previousWinner = previousWinningResult.Entrant;
                }
            }

            // Qualifying Record
            var record = decimal.MaxValue;
            var qualifyingRecordHolder = new DriverContract { Driver = new Driver() { AtomicName = "* None *", Name = "* None *" } };
            foreach (var race in races) {
                var polePosition = race.GetQualificationResults().Where(x => x.LapTime > 0).OrderBy(x => x.LapTime).FirstOrDefault();
                if (polePosition != null) {
                    if (polePosition.LapTime < record) {
                        record = polePosition.LapTime;
                        qualifyingRecordHolder = polePosition.Entrant;
                    }
                }
            }

            return new CircuitStatistics(circuit, previousWinner, record, qualifyingRecordHolder);
        }
Exemple #9
0
        public void doStep(Circuit sim, double voltdiff)
        {
            // used to have .1 here, but needed .01 for peak detector
            if(Math.Abs(voltdiff - lastvoltdiff) > 0.01)
                sim.converged = false;

            voltdiff = limitStep(sim, voltdiff, lastvoltdiff);
            lastvoltdiff = voltdiff;

            if(voltdiff >= 0 || zvoltage == 0) {
                // regular diode or forward-biased zener
                double eval = Math.Exp(voltdiff * vdcoef);
                // make diode linear with negative voltages; aids convergence
                if(voltdiff < 0)
                    eval = 1;

                double geq = vdcoef * leakage * eval;
                double nc = (eval - 1) * leakage - geq * voltdiff;
                sim.stampConductance(nodes[0], nodes[1], geq);
                sim.stampCurrentSource(nodes[0], nodes[1], nc);
            } else {
                // Zener diode
                // I(Vd) = Is * (exp[Vd*C] - exp[(-Vd-Vz)*C] - 1 )
                // geq is I'(Vd) nc is I(Vd) + I'(Vd)*(-Vd)
                double geq = leakage * vdcoef * (Math.Exp(voltdiff * vdcoef) + Math.Exp((-voltdiff - zoffset) * vdcoef));
                double nc = leakage * (Math.Exp(voltdiff * vdcoef) - Math.Exp((-voltdiff - zoffset) * vdcoef) - 1) + geq * (-voltdiff);
                sim.stampConductance(nodes[0], nodes[1], geq);
                sim.stampCurrentSource(nodes[0], nodes[1], nc);
            }
        }
Exemple #10
0
        public void NANDTest(bool in0, bool in1, bool in2, double in3)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<VoltageInput>();
            var res0 = sim.Create<Resistor>(5000);
            var nmos0 = sim.Create<NMosfet>();
            var nmos1 = sim.Create<NMosfet>();
            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicOut0 = sim.Create<LogicOutput>();
            var grnd0 = sim.Create<Ground>();

            sim.Connect(volt0.leadPos, res0.leadIn);
            sim.Connect(res0.leadOut, nmos0.leadDrain);

            sim.Connect(logicOut0.leadIn, nmos0.leadDrain);
            sim.Connect(nmos0.leadGate, logicIn0.leadOut);

            sim.Connect(nmos0.leadSrc, nmos1.leadDrain);

            sim.Connect(nmos1.leadGate, logicIn1.leadOut);
            sim.Connect(nmos1.leadSrc, grnd0.leadIn);

            if(in0) logicIn0.toggle();
            if(in1) logicIn1.toggle();

            sim.doTicks(100);

            Assert.AreEqual(in2, logicOut0.isHigh());
            Assert.AreEqual(in3, Math.Round(grnd0.getCurrent(), 3));
        }
        public void DarlingtonPairTest(bool In0, double i0)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<VoltageInput>();

            var res0 = sim.Create<Resistor>(2000000);
            var res1 = sim.Create<Resistor>(300);

            var switch0 = sim.Create<SwitchSPST>();

            var npn0 = sim.Create<Transistor>(false);
            var npn1 = sim.Create<Transistor>(false);

            var groun0 = sim.Create<Ground>();

            sim.Connect(volt0.leadPos, res0.leadIn);
            sim.Connect(volt0.leadPos, res1.leadIn);

            sim.Connect(switch0, 0, res0, 1);

            sim.Connect(npn0, 0, switch0, 1);
            sim.Connect(npn0.leadCollector, res1.leadOut);
            sim.Connect(npn0.leadEmitter, npn1.leadBase);

            sim.Connect(npn1.leadCollector, res1.leadOut);
            sim.Connect(npn1.leadEmitter, groun0.leadIn);

            if(In0) switch0.toggle();

            sim.doTicks(100);

            Assert.AreEqual(i0, Math.Round(groun0.getCurrent(), 12));
        }
        public void AnalogSwitchTest()
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var analogSwitch0 = sim.Create<AnalogSwitch>();

            var grnd = sim.Create<Ground>();

            sim.Connect(logicIn0.leadOut, analogSwitch0.leadIn);
            sim.Connect(logicIn1.leadOut, analogSwitch0.leadSwitch);
            sim.Connect(analogSwitch0.leadOut, grnd.leadIn);

            logicIn0.toggle();
            logicIn1.toggle();

            sim.doTicks(100);
            Assert.AreEqual(0.25, Math.Round(grnd.getCurrent(), 12));

            logicIn1.toggle();
            sim.analyze();
            sim.doTicks(100);
            Assert.AreEqual(5E-10, Math.Round(grnd.getCurrent(), 12));
        }
        public void NPNTransistorTest()
        {
            Circuit sim = new Circuit();

            var npn0 = sim.Create<Transistor>(false);

            var baseVoltage = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            baseVoltage.maxVoltage = 0.7025;

            var collectorVoltage = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            collectorVoltage.maxVoltage = 2;

            var ground = sim.Create<Ground>();

            var baseWire = sim.Create<Wire>();
            var collectorWire = sim.Create<Wire>();
            var emitterWire = sim.Create<Wire>();

            sim.Connect(baseVoltage.leadPos, baseWire.leadIn);
            sim.Connect(baseWire.leadOut, npn0.leadBase);

            sim.Connect(collectorVoltage.leadPos, collectorWire.leadIn);
            sim.Connect(collectorWire.leadOut, npn0.leadCollector);

            sim.Connect(ground.leadIn, emitterWire.leadIn);
            sim.Connect(emitterWire.leadOut, npn0.leadEmitter);

            sim.doTicks(100);

            TestUtils.Compare(baseWire.getCurrent(), 0.00158254, 8);
            TestUtils.Compare(collectorWire.getCurrent(), 0.15825359, 8);
            TestUtils.Compare(emitterWire.getCurrent(), -0.15983612, 8);
        }
 public override void stamp(Circuit sim)
 {
     resistance1 = maxResistance * position;
     resistance2 = maxResistance * (1 - position);
     sim.stampResistor(lead_node[0], lead_node[2], resistance1);
     sim.stampResistor(lead_node[2], lead_node[1], resistance2);
 }
        public void CMOSInverterTest(bool in0, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicOut0 = sim.Create<LogicOutput>();

            var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            var grnd0 = sim.Create<Ground>();

            var pmosf0 = sim.Create<PMosfet>();
            var nmosf0 = sim.Create<NMosfet>();

            sim.Connect(logicIn0.leadOut, pmosf0.leadGate);
            sim.Connect(logicIn0.leadOut, nmosf0.leadGate);

            sim.Connect(pmosf0.leadSrc, volt0.leadPos);
            sim.Connect(pmosf0.leadDrain, nmosf0.leadDrain);
            sim.Connect(nmosf0.leadSrc, grnd0.leadIn);

            sim.Connect(logicOut0.leadIn, pmosf0.leadDrain);

            if(in0) logicIn0.toggle();

            sim.doTicks(1000);

            Assert.AreEqual(out0, logicOut0.isHigh());
        }
        public void TwoToOneMuxTest(int int0, int int1, int int2, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicIn2 = sim.Create<LogicInput>();
            var logicOut0 = sim.Create<LogicOutput>();

            var tri0 = sim.Create<TriStateBuffer>();
            var tri1 = sim.Create<TriStateBuffer>();

            var invert0 = sim.Create<Inverter>();

            sim.Connect(logicIn0.leadOut, tri0.leadIn);
            sim.Connect(logicIn1.leadOut, tri1.leadIn);

            sim.Connect(logicIn2.leadOut, tri0.leadGate);
            sim.Connect(logicIn2.leadOut, invert0.leadIn);
            sim.Connect(invert0.leadOut, tri1.leadGate);

            sim.Connect(tri0.leadOut, tri1.leadOut);

            logicIn0.setPosition(int0);
            logicIn1.setPosition(int1);
            logicIn2.setPosition(int2);

            sim.doTicks(100);

            Debug.Log(out0, tri0.getLeadVoltage(1), tri1.getLeadVoltage(1));
            Assert.AreEqual(out0, logicOut0.isHigh());
        }
Exemple #17
0
 public Game(Board board, Circuit<Player> players, FinishSquare finish)
 {
     this.board = board;
     this.players = players;
     currentPlayer = players.peek();
     _finishSquare = finish;
 }
        public override void execute(Circuit sim)
        {
            if(!pins[1].value && lastClock) {
                bool q = pins[3].value;
                if(pins[0].value) {
                    if(pins[2].value) {
                        q = !q;
                    } else {
                        q = true;
                    }
                } else if(pins[2].value) {
                    q = false;
                }
                pins[3].value = q;
                pins[4].value = !q;
            }
            lastClock = pins[1].value;

            if(hasResetPin) {
                if(pins[5].value) {
                    pins[3].value = false;
                    pins[4].value = true;
                }
            }
        }
Exemple #19
0
        public void AndGateTest(int in0, int in1, bool out0)
        {
            /*string js = System.IO.File.ReadAllText(string.Format("./{0}.json", "AndGateTest"));
            Circuit sim = JsonSerializer.DeserializeFromString<Circuit>(js);
            var voltage0 = sim.getElm(0) as LogicInputElm;
            var voltage1 = sim.getElm(1) as LogicInputElm;
            var logicOut = sim.getElm(2) as LogicOutputElm;*/

            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicOut = sim.Create<LogicOutput>();

            var gate = sim.Create<AndGate>();

            sim.Connect(logicIn0, 0, gate, 0);
            sim.Connect(logicIn1, 0, gate, 1);
            sim.Connect(logicOut.leadIn, gate.leadOut);

            //string js = JsonSerializer.SerializeToString(sim);
            //System.IO.File.WriteAllText(string.Format("./{0}.json", "AndGateTest"), js);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
        public void InductorFrequencyTest(double frequency, double current)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            source0.frequency = frequency;
            source0.phaseShift = 90;

            var resistor0 = sim.Create<Resistor>(100);
            var induct0 = sim.Create<InductorElm>(0.4);

            sim.Connect(source0, 1, resistor0, 0);
            sim.Connect(resistor0, 1, induct0, 0);
            sim.Connect(induct0, 1, source0, 0);

            var inductScope = sim.Watch(induct0);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            Assert.AreEqual(current, Math.Round(inductScope.Max((f) => f.current), 12));
        }
Exemple #21
0
 public override void execute(Circuit sim)
 {
     if(pins[loadPin].value && !lastLoad)
         for(int i = 0; i != bits; i++)
             pins[i + bits].value = pins[i].value;
     lastLoad = pins[loadPin].value;
 }
        public void CapacitorCapacitanceTest(double capacitance, double current)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            source0.frequency = 80;

            var resistor0 = sim.Create<Resistor>(200);
            var cap0 = sim.Create<CapacitorElm>(capacitance);

            sim.Connect(source0, 1, resistor0, 0);
            sim.Connect(resistor0, 1, cap0, 0);
            sim.Connect(cap0, 1, source0, 0);

            var capScope = sim.Watch(cap0);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            double charge = cap0.capacitance * cap0.getVoltageDelta();

            Debug.Log(charge); // F = I x L
            Debug.Log(cap0.getCurrent(), charge / cap0.capacitance); // I = F / L
            Debug.Log(cap0.capacitance, charge / cap0.getCurrent()); // L = F / I

            Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
        }
Exemple #23
0
 public override void MouseUp(Circuit.Coord At)
 {
     b = At;
     Target.Select();
     if (a == b)
     {
         Circuit.Node node = Simulation.NodeAt(At);
         IEnumerable<Circuit.Element> at = Target.AtPoint(a);
         IEnumerable<Circuit.Symbol> probes = ProbesOf(at);
         if (!probes.Any() && node != null)
         {
             Probe probe = Simulation.Probes.FirstOrDefault(i => i.ConnectedTo == node);
             if (probe != null)
             {
                 // There's already a probe on this node, move the probe here.
                 ((Circuit.Symbol)probe.Tag).Position = a;
             }
             else
             {
                 // Make a new probe connected to this node.
                 probe = new Probe(Colors.ArgMin(i => Simulation.Probes.Count(j => j.Color == i)));
                 Target.Schematic.Add(new Circuit.Symbol(probe) { Position = a });
             }
         }
         else
         {
             Target.Select(probes.FirstOrDefault());
         }
     }
 }
 public override void execute(Circuit sim)
 {
     if(pins[0].value && !modestate) {
         modestate = true;
         data = 0;
         if(pins[2].value) data += 128;
         if(pins[3].value) data += 64;
         if(pins[4].value) data += 32;
         if(pins[5].value) data += 16;
         if(pins[6].value) data += 8;
         if(pins[7].value) data += 4;
         if(pins[8].value) data += 2;
         if(pins[9].value) data += 1;
     } else if(pins[1].value && !clockstate) {
         clockstate = true;
         if((data & 1) == 0) {
             pins[10].value = false;
         } else {
             pins[10].value = true;
         }
         data = (byte)(data >> 1);
     }
     if(!pins[0].value)
         modestate = false;
     if(!pins[1].value)
         clockstate = false;
 }
Exemple #25
0
 public override void MouseMove(Circuit.Coord At)
 {
     Circuit.Coord dx = At - x;
     if (dx.x != 0 || dx.y != 0)
         Editor.Edits.Do(new MoveElements(Target.Selected, dx));
     x = At;
 }
        public override TelemetryLap Get(Circuit circuit, string lapType)
        {
            try
            {
                var filename = GetFileName(circuit, lapType);
                if (!File.Exists(filename))
                    return null;

                string fastestLapData = File.ReadAllText(filename);

                using (var reader = new StringReader(fastestLapData))
                {
                    var serializer = new XmlSerializer(typeof (TelemetryLap));
                    using (var xmlReader = new XmlTextReader(reader))
                    {
                        try
                        {
                            var fastestLap = (TelemetryLap) serializer.Deserialize(xmlReader);
                            return fastestLap;
                        }
                        catch
                        {
                        }
                        return null;
                    }
                }
            } catch (Exception ex)
            {
                logger.Error("Could not retreive csv telemetry lap", ex);
                throw ex;
            }
        }
        public SimulationSchematic(Circuit.Schematic Schematic)
            : base(Schematic)
        {
            InitializeComponent();

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete_Executed, Delete_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAll_Executed, SelectAll_CanExecute));

            Focusable = true;
            Cursor = Cursors.Cross;

            Tool = new ProbeTool(this);

            int pad = Grid * 2;
            int align = Grid * 10;

            Circuit.Coord lb = Schematic.LowerBound;
            Circuit.Coord ub = Schematic.UpperBound;
            lb = Floor(lb - pad, align);
            ub = Ceiling(ub + pad, align);

            Width = ub.x - lb.x;
            Height = ub.y - lb.y;
            Origin = -lb;
        }
 public override void stamp(Circuit sim)
 {
     if (waveform == WaveType.DC) {
         sim.stampVoltageSource(0, lead_node[0], voltSource, getVoltage(sim));
     } else {
         sim.stampVoltageSource(0, lead_node[0], voltSource);
     }
 }
Exemple #29
0
 public override void beginStep(Circuit sim)
 {
     if(Math.Abs(current) < holdcurrent)
         state = false;
     double vd = lead_volt[0] - lead_volt[1];
     if(Math.Abs(vd) > breakdown)
         state = true;
 }
Exemple #30
0
 public override void step(Circuit sim)
 {
     double v0 = lead_volt[1];
     double @out = lead_volt[0] > 2.5 ? 0 : 5;
     double maxStep = slewRate * sim.timeStep * 1e9;
     @out = Math.Max(Math.Min(v0 + maxStep, @out), v0 - maxStep);
     sim.updateVoltageSource(0, lead_node[1], voltSource, @out);
 }
        /// <summary>
        /// Execute behaviour
        /// </summary>
        /// <param name="ckt"></param>
        public override void Load(Circuit ckt)
        {
            var    bsim3 = ComponentTyped <BSIM3v24>();
            var    model = bsim3.Model as BSIM3v24Model;
            var    state = ckt.State;
            var    cstate = state;
            double Gm, Gmbs, FwdSum, RevSum, gbbdp, gbbsp, gbdpg, gbdpb, gbdpdp, gbdpsp, gbspdp, gbspg, gbspb, gbspsp, cggb, cgsb, cgdb,
                   cbgb, cbsb, cbdb, cdgb, cdsb, cddb, xgtg, sxpart, dxpart, ddxpart_dVd, dsxpart_dVd, xgtd, xgts, xgtb, xcqgb = 0.0, xcqdb = 0.0, xcqsb = 0.0,
                   xcqbb = 0.0, CoxWL, qcheq, Cdd, Csd, Cdg, Csg, ddxpart_dVg, Cds, Css, ddxpart_dVs, ddxpart_dVb, dsxpart_dVg, dsxpart_dVs,
                   dsxpart_dVb, T1, gdpr, gspr, gds, gbd, gbs, capbd, capbs, GSoverlapCap, GDoverlapCap, GBoverlapCap, xcdgb, xcddb, xcdsb, xcsgb,
                   xcsdb, xcssb, xcggb, xcgdb, xcgsb, xcbgb, xcbdb, xcbsb;
            double omega = cstate.Laplace.Imaginary;

            if (bsim3.BSIM3mode >= 0)
            {
                Gm     = bsim3.BSIM3gm;
                Gmbs   = bsim3.BSIM3gmbs;
                FwdSum = Gm + Gmbs;
                RevSum = 0.0;

                gbbdp = -bsim3.BSIM3gbds;
                gbbsp = bsim3.BSIM3gbds + bsim3.BSIM3gbgs + bsim3.BSIM3gbbs;

                gbdpg  = bsim3.BSIM3gbgs;
                gbdpb  = bsim3.BSIM3gbbs;
                gbdpdp = bsim3.BSIM3gbds;
                gbdpsp = -(gbdpg + gbdpb + gbdpdp);

                gbspdp = 0.0;
                gbspg  = 0.0;
                gbspb  = 0.0;
                gbspsp = 0.0;

                if (bsim3.BSIM3nqsMod.Value == 0)
                {
                    cggb = bsim3.BSIM3cggb;
                    cgsb = bsim3.BSIM3cgsb;
                    cgdb = bsim3.BSIM3cgdb;

                    cbgb = bsim3.BSIM3cbgb;
                    cbsb = bsim3.BSIM3cbsb;
                    cbdb = bsim3.BSIM3cbdb;

                    cdgb = bsim3.BSIM3cdgb;
                    cdsb = bsim3.BSIM3cdsb;
                    cddb = bsim3.BSIM3cddb;

                    xgtg        = xgtd = xgts = xgtb = 0.0;
                    sxpart      = 0.6;
                    dxpart      = 0.4;
                    ddxpart_dVd = ddxpart_dVg = ddxpart_dVb = ddxpart_dVs = 0.0;
                    dsxpart_dVd = dsxpart_dVg = dsxpart_dVb = dsxpart_dVs = 0.0;
                }
                else
                {
                    cggb = cgdb = cgsb = 0.0;
                    cbgb = cbdb = cbsb = 0.0;
                    cdgb = cddb = cdsb = 0.0;

                    xgtg = bsim3.BSIM3gtg;
                    xgtd = bsim3.BSIM3gtd;
                    xgts = bsim3.BSIM3gts;
                    xgtb = bsim3.BSIM3gtb;

                    xcqgb = bsim3.BSIM3cqgb * omega;
                    xcqdb = bsim3.BSIM3cqdb * omega;
                    xcqsb = bsim3.BSIM3cqsb * omega;
                    xcqbb = bsim3.BSIM3cqbb * omega;

                    CoxWL = model.BSIM3cox * bsim3.pParam.BSIM3weffCV * bsim3.pParam.BSIM3leffCV;
                    qcheq = -(bsim3.BSIM3qgate + bsim3.BSIM3qbulk);
                    if (Math.Abs(qcheq) <= 1.0e-5 * CoxWL)
                    {
                        if (model.BSIM3xpart < 0.5)
                        {
                            dxpart = 0.4;
                        }
                        else if (model.BSIM3xpart > 0.5)
                        {
                            dxpart = 0.0;
                        }
                        else
                        {
                            dxpart = 0.5;
                        }
                        ddxpart_dVd = ddxpart_dVg = ddxpart_dVb = ddxpart_dVs = 0.0;
                    }
                    else
                    {
                        dxpart      = bsim3.BSIM3qdrn / qcheq;
                        Cdd         = bsim3.BSIM3cddb;
                        Csd         = -(bsim3.BSIM3cgdb + bsim3.BSIM3cddb + bsim3.BSIM3cbdb);
                        ddxpart_dVd = (Cdd - dxpart * (Cdd + Csd)) / qcheq;
                        Cdg         = bsim3.BSIM3cdgb;
                        Csg         = -(bsim3.BSIM3cggb + bsim3.BSIM3cdgb + bsim3.BSIM3cbgb);
                        ddxpart_dVg = (Cdg - dxpart * (Cdg + Csg)) / qcheq;

                        Cds         = bsim3.BSIM3cdsb;
                        Css         = -(bsim3.BSIM3cgsb + bsim3.BSIM3cdsb + bsim3.BSIM3cbsb);
                        ddxpart_dVs = (Cds - dxpart * (Cds + Css)) / qcheq;

                        ddxpart_dVb = -(ddxpart_dVd + ddxpart_dVg + ddxpart_dVs);
                    }
                    sxpart      = 1.0 - dxpart;
                    dsxpart_dVd = -ddxpart_dVd;
                    dsxpart_dVg = -ddxpart_dVg;
                    dsxpart_dVs = -ddxpart_dVs;
                    dsxpart_dVb = -(dsxpart_dVd + dsxpart_dVg + dsxpart_dVs);
                }
            }
            else
            {
                Gm     = -bsim3.BSIM3gm;
                Gmbs   = -bsim3.BSIM3gmbs;
                FwdSum = 0.0;
                RevSum = -(Gm + Gmbs);

                gbbsp = -bsim3.BSIM3gbds;
                gbbdp = bsim3.BSIM3gbds + bsim3.BSIM3gbgs + bsim3.BSIM3gbbs;

                gbdpg  = 0.0;
                gbdpsp = 0.0;
                gbdpb  = 0.0;
                gbdpdp = 0.0;

                gbspg  = bsim3.BSIM3gbgs;
                gbspsp = bsim3.BSIM3gbds;
                gbspb  = bsim3.BSIM3gbbs;
                gbspdp = -(gbspg + gbspsp + gbspb);

                if (bsim3.BSIM3nqsMod.Value == 0)
                {
                    cggb = bsim3.BSIM3cggb;
                    cgsb = bsim3.BSIM3cgdb;
                    cgdb = bsim3.BSIM3cgsb;

                    cbgb = bsim3.BSIM3cbgb;
                    cbsb = bsim3.BSIM3cbdb;
                    cbdb = bsim3.BSIM3cbsb;

                    cdgb = -(bsim3.BSIM3cdgb + cggb + cbgb);
                    cdsb = -(bsim3.BSIM3cddb + cgsb + cbsb);
                    cddb = -(bsim3.BSIM3cdsb + cgdb + cbdb);

                    xgtg        = xgtd = xgts = xgtb = 0.0;
                    sxpart      = 0.4;
                    dxpart      = 0.6;
                    ddxpart_dVd = ddxpart_dVg = ddxpart_dVb = ddxpart_dVs = 0.0;
                    dsxpart_dVd = dsxpart_dVg = dsxpart_dVb = dsxpart_dVs = 0.0;
                }
                else
                {
                    cggb = cgdb = cgsb = 0.0;
                    cbgb = cbdb = cbsb = 0.0;
                    cdgb = cddb = cdsb = 0.0;

                    xgtg = bsim3.BSIM3gtg;
                    xgtd = bsim3.BSIM3gts;
                    xgts = bsim3.BSIM3gtd;
                    xgtb = bsim3.BSIM3gtb;

                    xcqgb = bsim3.BSIM3cqgb * omega;
                    xcqdb = bsim3.BSIM3cqsb * omega;
                    xcqsb = bsim3.BSIM3cqdb * omega;
                    xcqbb = bsim3.BSIM3cqbb * omega;

                    CoxWL = model.BSIM3cox * bsim3.pParam.BSIM3weffCV * bsim3.pParam.BSIM3leffCV;
                    qcheq = -(bsim3.BSIM3qgate + bsim3.BSIM3qbulk);
                    if (Math.Abs(qcheq) <= 1.0e-5 * CoxWL)
                    {
                        if (model.BSIM3xpart < 0.5)
                        {
                            sxpart = 0.4;
                        }
                        else if (model.BSIM3xpart > 0.5)
                        {
                            sxpart = 0.0;
                        }
                        else
                        {
                            sxpart = 0.5;
                        }
                        dsxpart_dVd = dsxpart_dVg = dsxpart_dVb = dsxpart_dVs = 0.0;
                    }
                    else
                    {
                        sxpart      = bsim3.BSIM3qdrn / qcheq;
                        Css         = bsim3.BSIM3cddb;
                        Cds         = -(bsim3.BSIM3cgdb + bsim3.BSIM3cddb + bsim3.BSIM3cbdb);
                        dsxpart_dVs = (Css - sxpart * (Css + Cds)) / qcheq;
                        Csg         = bsim3.BSIM3cdgb;
                        Cdg         = -(bsim3.BSIM3cggb + bsim3.BSIM3cdgb + bsim3.BSIM3cbgb);
                        dsxpart_dVg = (Csg - sxpart * (Csg + Cdg)) / qcheq;

                        Csd         = bsim3.BSIM3cdsb;
                        Cdd         = -(bsim3.BSIM3cgsb + bsim3.BSIM3cdsb + bsim3.BSIM3cbsb);
                        dsxpart_dVd = (Csd - sxpart * (Csd + Cdd)) / qcheq;

                        dsxpart_dVb = -(dsxpart_dVd + dsxpart_dVg + dsxpart_dVs);
                    }
                    dxpart      = 1.0 - sxpart;
                    ddxpart_dVd = -dsxpart_dVd;
                    ddxpart_dVg = -dsxpart_dVg;
                    ddxpart_dVs = -dsxpart_dVs;
                    ddxpart_dVb = -(ddxpart_dVd + ddxpart_dVg + ddxpart_dVs);
                }
            }

            T1    = state.States[0][bsim3.BSIM3states + BSIM3v24.BSIM3qdef] * bsim3.BSIM3gtau;
            gdpr  = bsim3.BSIM3drainConductance;
            gspr  = bsim3.BSIM3sourceConductance;
            gds   = bsim3.BSIM3gds;
            gbd   = bsim3.BSIM3gbd;
            gbs   = bsim3.BSIM3gbs;
            capbd = bsim3.BSIM3capbd;
            capbs = bsim3.BSIM3capbs;

            GSoverlapCap = bsim3.BSIM3cgso;
            GDoverlapCap = bsim3.BSIM3cgdo;
            GBoverlapCap = bsim3.pParam.BSIM3cgbo;

            xcdgb = (cdgb - GDoverlapCap) * omega;
            xcddb = (cddb + capbd + GDoverlapCap) * omega;
            xcdsb = cdsb * omega;
            xcsgb = -(cggb + cbgb + cdgb + GSoverlapCap) * omega;
            xcsdb = -(cgdb + cbdb + cddb) * omega;
            xcssb = (capbs + GSoverlapCap - (cgsb + cbsb + cdsb)) * omega;
            xcggb = (cggb + GDoverlapCap + GSoverlapCap + GBoverlapCap) * omega;
            xcgdb = (cgdb - GDoverlapCap) * omega;
            xcgsb = (cgsb - GSoverlapCap) * omega;
            xcbgb = (cbgb - GBoverlapCap) * omega;
            xcbdb = (cbdb - capbd) * omega;
            xcbsb = (cbsb - capbs) * omega;

            // cstate.Matrix[bsim3.BSIM3gNode, bsim3.BSIM3gNode] -= new Complex(xgtg, -xcggb);
            // cstate.Matrix[bsim3.BSIM3bNode, bsim3.BSIM3bNode] += new Complex(gbd + gbs - bsim3.BSIM3gbbs, -(xcbgb + xcbdb + xcbsb));
            // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3dNodePrime] += new Complex(gdpr + gds + gbd + RevSum + dxpart * xgtd + T1 * ddxpart_dVd + gbdpdp, xcddb);
            // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3sNodePrime] += new Complex(gspr + gds + gbs + FwdSum + sxpart * xgts + T1 * dsxpart_dVs + gbspsp, xcssb);
            // cstate.Matrix[bsim3.BSIM3gNode, bsim3.BSIM3bNode] -= new Complex(xgtb, xcggb + xcgdb + xcgsb);
            // cstate.Matrix[bsim3.BSIM3gNode, bsim3.BSIM3dNodePrime] -= new Complex(xgtd, -xcgdb);
            // cstate.Matrix[bsim3.BSIM3gNode, bsim3.BSIM3sNodePrime] -= new Complex(xgts, -xcgsb);
            // cstate.Matrix[bsim3.BSIM3bNode, bsim3.BSIM3gNode] -= new Complex(bsim3.BSIM3gbgs, -xcbgb);
            // cstate.Matrix[bsim3.BSIM3bNode, bsim3.BSIM3dNodePrime] -= new Complex(gbd - gbbdp, -xcbdb);
            // cstate.Matrix[bsim3.BSIM3bNode, bsim3.BSIM3sNodePrime] -= new Complex(gbs - gbbsp, -xcbsb);
            // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3gNode] += new Complex(Gm + dxpart * xgtg + T1 * ddxpart_dVg + gbdpg, xcdgb);
            // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3bNode] -= new Complex(gbd - Gmbs - dxpart * xgtb - T1 * ddxpart_dVb - gbdpb, xcdgb + xcddb + xcdsb);
            // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3sNodePrime] -= new Complex(gds + FwdSum - dxpart * xgts - T1 * ddxpart_dVs - gbdpsp, - xcdsb);
            // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3gNode] -= new Complex(Gm - sxpart * xgtg - T1 * dsxpart_dVg - gbspg, -xcsgb);
            // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3bNode] -= new Complex(gbs + Gmbs - sxpart * xgtb - T1 * dsxpart_dVb - gbspb, xcsgb + xcsdb + xcssb);
            // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3dNodePrime] -= new Complex(gds + RevSum - sxpart * xgtd - T1 * dsxpart_dVd - gbspdp, - xcsdb);

            // cstate.Matrix[bsim3.BSIM3dNode, bsim3.BSIM3dNode] += gdpr;
            // cstate.Matrix[bsim3.BSIM3sNode, bsim3.BSIM3sNode] += gspr;

            // cstate.Matrix[bsim3.BSIM3dNode, bsim3.BSIM3dNodePrime] -= gdpr;
            // cstate.Matrix[bsim3.BSIM3sNode, bsim3.BSIM3sNodePrime] -= gspr;

            // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3dNode] -= gdpr;

            // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3sNode] -= gspr;

            if (bsim3.BSIM3nqsMod != 0)
            {
                // cstate.Matrix[bsim3.BSIM3qNode, bsim3.BSIM3qNode] += new Complex(bsim3.BSIM3gtau, omega * BSIM3v24.ScalingFactor);
                // cstate.Matrix[bsim3.BSIM3qNode, bsim3.BSIM3gNode] += new Complex(xgtg, -xcqgb);
                // cstate.Matrix[bsim3.BSIM3qNode, bsim3.BSIM3dNodePrime] += new Complex(xgtd, -xcqdb);
                // cstate.Matrix[bsim3.BSIM3qNode, bsim3.BSIM3sNodePrime] += new Complex(xgts, -xcqsb);
                // cstate.Matrix[bsim3.BSIM3qNode, bsim3.BSIM3bNode] += new Complex(xgtb, -xcqbb);

                // cstate.Matrix[bsim3.BSIM3dNodePrime, bsim3.BSIM3qNode] += dxpart * bsim3.BSIM3gtau;
                // cstate.Matrix[bsim3.BSIM3sNodePrime, bsim3.BSIM3qNode] += sxpart * bsim3.BSIM3gtau;
                // cstate.Matrix[bsim3.BSIM3gNode, bsim3.BSIM3qNode] -= bsim3.BSIM3gtau;
            }
        }
Exemple #32
0
        public void When_CommonSourceAmplifierNoise_Expect_Spice3f5Reference()
        {
            // Create circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0).SetParameter("acmag", 1.0),
                new VoltageSource("V2", "vdd", "0", 5.0),
                new Resistor("R1", "vdd", "out", 10e3),
                new Resistor("R2", "out", "g", 10e3),
                new Capacitor("C1", "in", "g", 1e-6),
                CreateMOS2("M1", "out", "g", "0", "0", "NFET").SetParameter("l", 6e-6).SetParameter("w", 1e-6),
                CreateMOS2Model("NFET", "VTO=-1.44 KP=8.64E-6 NSUB=1e17 TOX=20e-9 KF=0.5e-25")
                );

            // Create simulation, exports and references
            var noise = new Noise("noise", "out", new DecadeSweep(10, 10e9, 10));

            IExport <double>[] exports = { new InputNoiseDensityExport(noise), new OutputNoiseDensityExport(noise) };
            var references             = new double[2][];

            references[0] = new[]
            {
                2.362277630616173e-06, 1.379945267414784e-06, 8.473007758572772e-07, 5.483251555734933e-07,
                3.730472062832258e-07, 2.649962499739830e-07, 1.947939731585481e-07, 1.468616981231575e-07,
                1.127127241713318e-07, 8.755438258118984e-08, 6.855631329051349e-08, 5.395973684199731e-08,
                4.261291387932214e-08, 3.372393096425626e-08, 2.672536768434284e-08, 2.119738853640898e-08,
                1.682198426685170e-08, 1.335430849281782e-08, 1.060376070211410e-08, 8.420890083617284e-09,
                6.687960230375347e-09, 5.311939245547357e-09, 4.219174575568831e-09, 3.351284863236070e-09,
                2.661957766932026e-09, 2.114436968645719e-09, 1.679541365117180e-09, 1.334099339452888e-09,
                1.059708909993047e-09, 8.417548116877004e-10, 6.686287034417421e-10, 5.311102416204870e-10,
                4.218756922498825e-10, 3.351077295963854e-10, 2.661855491980500e-10, 2.114387464861675e-10,
                1.679518309568926e-10, 1.334089539422986e-10, 1.059705753459854e-10, 8.417549847903336e-11,
                6.686305453153985e-11, 5.311129198609113e-11, 4.218787896666749e-11, 3.351110370990360e-11,
                2.661889619930598e-11, 2.114422120523689e-11, 1.679553229713451e-11, 1.334124592122790e-11,
                1.059740872594686e-11, 8.417901372215624e-12, 6.686657144343612e-12, 5.311480973435567e-12,
                4.219139713410938e-12, 3.351462208743194e-12, 2.662241468212711e-12, 2.114773974082943e-12,
                1.679905085917544e-12, 1.334476449652446e-12, 1.060092730788699e-12, 8.421419957485428e-13,
                6.690175731282215e-13, 5.314999561210558e-13, 4.222658301605114e-13, 3.354980797147467e-13,
                2.665760056722277e-13, 2.118292562645285e-13, 1.683423674506338e-13, 1.337995038254496e-13,
                1.063611319397393e-13, 8.456605843605668e-14, 6.725361617419147e-14, 5.350185447355857e-14,
                4.257844187754605e-14, 3.390166683299062e-14, 2.700945942874924e-14, 2.153478448798461e-14,
                1.718609560659779e-14, 1.373180924408069e-14, 1.098797205551033e-14, 8.808464705142402e-15,
                7.077220478956046e-15, 5.702044308892841e-15, 4.609703049291635e-15, 3.742025544836112e-15,
                3.052804804411985e-15, 2.505337310335527e-15, 2.070468422196848e-15, 1.725039785945140e-15,
                1.450656067088105e-15, 1.232705332051313e-15, 1.059580909432678e-15
            };
            references[1] = new[]
            {
                2.970552105465777e-07, 2.053392001294538e-07, 1.425716401150457e-07, 1.005637052541777e-07,
                7.253421438447867e-08, 5.355847444717597e-08, 4.037521102279383e-08, 3.093870755193646e-08,
                2.399259594639712e-08, 1.876085041593681e-08, 1.475173003376309e-08, 1.164174697973875e-08,
                9.209128460130984e-09, 7.295852862170559e-09, 5.785653492254035e-09, 4.590866976751766e-09,
                3.644227374777685e-09, 2.893495350636724e-09, 2.297774776401085e-09, 1.824881474232857e-09,
                1.449401554896117e-09, 1.151223737306888e-09, 9.144110142143362e-10, 7.263231967747751e-10,
                5.769293633775424e-10, 4.582664502662651e-10, 3.640115671591474e-10, 2.891434647260522e-10,
                2.296742247661058e-10, 1.824364329323833e-10, 1.449142737768106e-10, 1.151094398350513e-10,
                9.143465704637279e-11, 7.262912784315901e-11, 5.769137465933203e-11, 4.582590036912043e-11,
                3.640082154126390e-11, 2.891421652629465e-11, 2.296739538836536e-11, 1.824366775621906e-11,
                1.449147767750264e-11, 1.151100723242943e-11, 9.143535443489147e-12, 7.262985775837507e-12,
                5.769212087651685e-12, 4.582665475664515e-12, 3.640158002365927e-12, 2.891497706098719e-12,
                2.296815695164321e-12, 1.824442983501082e-12, 1.449224001466344e-12, 1.151176969908153e-12,
                9.144297975040658e-13, 7.263748339915787e-13, 5.769974668031978e-13, 4.583428064215170e-13,
                3.640920595011466e-13, 2.892260300796565e-13, 2.297578290890759e-13, 1.825205579743038e-13,
                1.449986597966671e-13, 1.151939566537973e-13, 9.151923941987867e-14, 7.271374307188275e-14,
                5.777600635467486e-14, 4.591054031732387e-14, 3.648546562569634e-14, 2.899886268375259e-14,
                2.305204258479738e-14, 1.832831547337173e-14, 1.457612565563390e-14, 1.159565534135988e-14,
                9.228183617974503e-15, 7.347633983178169e-15, 5.853860311459011e-15, 4.667313707724732e-15,
                3.724806238562389e-15, 2.976145944368217e-15, 2.381463934472801e-15, 1.909091223330287e-15,
                1.533872241556531e-15, 1.235825210129142e-15, 9.990780377906112e-16, 8.110230743109810e-16,
                6.616457071390669e-16, 5.429910467656397e-16, 4.487402998494061e-16, 3.738742704299892e-16,
                3.144060694404477e-16, 2.671687983261964e-16, 2.296469001488209e-16
            };

            // Run test
            AnalyzeNoise(noise, ckt, exports, references);
            DestroyExports(exports);
        }
Exemple #33
0
        public void When_VSWSwitchTransient_Expect_Spice3f5Reference()
        {
            // Build the switch
            Circuit ckt = new Circuit(
                CreateVoltageSwitch("S1", "0", "OUT", "IN", "0", "MYSW", "Ron=1 Roff=1e6 Vt=0.5 Vh=-0.4"),
                new VoltageSource("V1", "IN", "0", new Pulse(0, 1, 0.0, 0.4e-3, 0.4e-3, 0.1e-3, 1e-3)),
                new VoltageSource("V2", "N001", "0", 3.3),
                new Resistor("R1", "N001", "OUT", 1e3)
                );

            // Build simulation, exports and references
            var transient = new Transient("Tran 1", 0.1e-3, 3e-3);

            Export <double>[] exports    = { new GenericExport <double>(transient, () => transient.Method.Time), new RealVoltageExport(transient, "OUT") };
            double[][]        references =
            {
                new[]
                {
                    0.000000000000000e+00, 6.000000000000000e-07, 1.200000000000000e-06, 2.400000000000000e-06,
                    4.800000000000000e-06, 9.600000000000000e-06, 1.920000000000000e-05, 3.840000000000000e-05,
                    7.680000000000000e-05, 1.368000000000000e-04, 1.968000000000000e-04, 2.568000000000000e-04,
                    3.168000000000000e-04, 3.768000000000000e-04, 4.000000000000000e-04, 4.060000000000000e-04,
                    4.180000000000000e-04, 4.420000000000000e-04, 4.900000000000000e-04, 5.000000000000000e-04,
                    5.060000000000000e-04, 5.180000000000000e-04, 5.420000000000001e-04, 5.900000000000000e-04,
                    6.500000000000001e-04, 7.100000000000001e-04, 7.700000000000002e-04, 8.300000000000002e-04,
                    8.900000000000003e-04, 9.000000000000000e-04, 9.060000000000000e-04, 9.180000000000000e-04,
                    9.420000000000000e-04, 9.900000000000000e-04, 1.000000000000000e-03, 1.006000000000000e-03,
                    1.018000000000000e-03, 1.042000000000000e-03, 1.090000000000000e-03, 1.150000000000000e-03,
                    1.210000000000000e-03, 1.270000000000000e-03, 1.330000000000000e-03, 1.390000000000000e-03,
                    1.400000000000000e-03, 1.406000000000000e-03, 1.418000000000000e-03, 1.442000000000000e-03,
                    1.490000000000000e-03, 1.500000000000000e-03, 1.506000000000000e-03, 1.518000000000000e-03,
                    1.542000000000000e-03, 1.590000000000000e-03, 1.650000000000000e-03, 1.710000000000000e-03,
                    1.770000000000000e-03, 1.830000000000000e-03, 1.890000000000000e-03, 1.900000000000000e-03,
                    1.906000000000000e-03, 1.918000000000000e-03, 1.942000000000000e-03, 1.990000000000000e-03,
                    2.000000000000000e-03, 2.006000000000000e-03, 2.018000000000000e-03, 2.042000000000000e-03,
                    2.090000000000000e-03, 2.150000000000000e-03, 2.210000000000000e-03, 2.270000000000000e-03,
                    2.330000000000000e-03, 2.390000000000001e-03, 2.400000000000000e-03, 2.406000000000000e-03,
                    2.418000000000000e-03, 2.442000000000000e-03, 2.490000000000000e-03, 2.500000000000000e-03,
                    2.506000000000000e-03, 2.518000000000000e-03, 2.542000000000000e-03, 2.590000000000000e-03,
                    2.650000000000000e-03, 2.710000000000000e-03, 2.770000000000000e-03, 2.830000000000000e-03,
                    2.890000000000001e-03, 2.900000000000000e-03, 2.906000000000000e-03, 2.918000000000000e-03,
                    2.942000000000000e-03, 2.990000000000000e-03, 3.000000000000000e-03
                },
                new[]
                {
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03, 3.296703296703298e-03,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00,
                    3.296703296703297e+00, 3.296703296703297e+00, 3.296703296703297e+00
                }
            };
            AnalyzeTransient(transient, ckt, exports, references);
        }
Exemple #34
0
 public double GetCurrent(Circuit ckt) => ckt.State.Real.Solution[VCVSbranch];
Exemple #35
0
 /// <summary>
 /// Temperature-dependent calculations
 /// </summary>
 /// <param name="ckt">The circuit</param>
 public override void Temperature(Circuit ckt)
 {
 }
Exemple #36
0
        static void HalfAdderTest()
        {
            var signalGenerator1 = new SignalGenerator();
            var signalGenerator2 = new SignalGenerator();

            bool signalHigh     = true;
            bool longSignalHigh = true;

            for (int i = 0; i < 200; i++)
            {
                if (i % 20 == 0)
                {
                    signalHigh = !signalHigh;
                }

                if (i % 40 == 0)
                {
                    longSignalHigh = !longSignalHigh;
                }

                signalGenerator1.AddSample(signalHigh ? 5 : 0);
                signalGenerator2.AddSample(longSignalHigh ? 5 : 0);
            }

            var xorGate = new XorGate(TTLGateTypeEnum.Normal, 2);
            var andGate = new AndGate(TTLGateTypeEnum.Normal, 2);

            var circuit = new Circuit();

            circuit.Gates.Add(xorGate);
            circuit.Gates.Add(andGate);
            circuit.Gates.Add(signalGenerator1);
            circuit.Gates.Add(signalGenerator2);

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = xorGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = xorGate.Inputs[1]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = andGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = andGate.Inputs[1]
            });

            circuit.RunCircuit();

            for (int i = 0; i < 200; i++)
            {
                _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)}  S:{xorGate.Output(i)}  C:{andGate.Output(i)}");
            }
        }
Exemple #37
0
 public double GetPower(Circuit ckt) => ckt.State.Real.Solution[VCVSbranch] * (ckt.State.Real.Solution[VCVSposNode] - ckt.State.Real.Solution[VCVSnegNode]);
Exemple #38
0
 public override Task OnConnectionDownAsync(Circuit circuit, CancellationToken cancellationToken)
 {
     return(scopedCircuitHandler.OnConnectionDownAsync(cancellationToken));
 }
        /// <summary>
        /// Load the circuit for simulation
        /// </summary>
        /// <param name="ckt">The circuit</param>
        public static void Load(this Circuit ckt)
        {
            var state  = ckt.State;
            var rstate = state.Real;
            var nodes  = ckt.Nodes;

            // Start the stopwatch
            ckt.Statistics.LoadTime.Start();

            // Clear rhs and matrix
            rstate.Clear();

            // Load all devices
            // ckt.Load(this, state);
            foreach (var c in ckt.Objects)
            {
                c.Load(ckt);
            }

            // Check modes
            if (state.UseDC)
            {
                // Consider doing nodeset & ic assignments
                if ((state.Init & (CircuitState.InitFlags.InitJct | CircuitState.InitFlags.InitFix)) != 0)
                {
                    // Do nodesets
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        var node = nodes[i];
                        if (nodes.Nodeset.ContainsKey(node.Name))
                        {
                            double ns = nodes.Nodeset[node.Name];
                            if (ZeroNoncurRow(rstate.Matrix, nodes, node.Index))
                            {
                                rstate.Rhs[node.Index] = 1.0e10 * ns;
                                rstate.Matrix[node.Index, node.Index] = 1.0e10;
                            }
                            else
                            {
                                rstate.Rhs[node.Index]                = ns;
                                rstate.Solution[node.Index]           = ns;
                                rstate.Matrix[node.Index, node.Index] = 1.0;
                            }
                        }
                    }
                }

                if (state.Domain == CircuitState.DomainTypes.Time && !state.UseIC)
                {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        var node = nodes[i];
                        if (nodes.IC.ContainsKey(node.Name))
                        {
                            double ic = nodes.IC[node.Name];
                            if (ZeroNoncurRow(rstate.Matrix, nodes, node.Index))
                            {
                                rstate.Rhs[node.Index] = 1.0e10 * ic;
                                rstate.Matrix[node.Index, node.Index] = 1.0e10;
                            }
                            else
                            {
                                rstate.Rhs[node.Index]                = ic;
                                rstate.Solution[node.Index]           = ic;
                                rstate.Matrix[node.Index, node.Index] = 1.0;
                            }
                        }
                    }
                }
            }

            // Keep statistics
            ckt.Statistics.LoadTime.Stop();
        }
Exemple #40
0
 public Gate_NOR(Circuit ckt, string Label) : base(ckt, "NOR", Label)
 {
 }
Exemple #41
0
 private void Awake()
 {
     maps    = maplist.GetAllMaps();
     circuit = FindObjectOfType <Circuit>();
 }
Exemple #42
0
        public void When_CommonSourceAmplifierSmallSignal_Expect_Spice3f5Reference()
        {
            /*
             * MOS2 amplifier biased as a diode-connected transistor, AC coupled
             * Current is expected to match the reference. Reference is simulated by Spice 3f5.
             */
            // Create circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0)
                .SetParameter("acmag", 1.0),
                new VoltageSource("V2", "vdd", "0", 5.0),
                new Resistor("R1", "vdd", "out", 10e3),
                new Resistor("R2", "out", "g", 10e3),
                new Capacitor("C1", "in", "g", 1e-6),
                CreateMOS2("M1", "out", "g", "0", "0", "NFET")
                .SetParameter("l", 6e-6)
                .SetParameter("w", 1e-6),
                CreateMOS2Model("NFET", "VTO = -1.44 KP = 8.64E-6 NSUB = 1e17 TOX = 20e-9")
                );

            // Create simulation
            var ac = new AC("ac", new DecadeSweep(10, 10e9, 5));

            // Create exports
            IExport <Complex>[] exports = { new ComplexVoltageExport(ac, "out") };

            // Create references
            double[] riref =
            {
                2.701114568959397e-01, 2.297592026993491e-01, 3.614367501477384e-01, 1.939823511070750e-01,
                4.176532699259306e-01, 1.414313855763639e-01, 4.452214249772693e-01, 9.512747415960789e-02,
                4.572366767698547e-01, 6.164118367404970e-02, 4.622024752123699e-01, 3.931535278467341e-02,
                4.642095432402752e-01, 2.491402951340239e-02, 4.650134308270042e-01, 1.574691222820917e-02,
                4.653342396231024e-01, 9.942484429536930e-03, 4.654620791267926e-01, 6.275007008504113e-03,
                4.655129925001772e-01, 3.959694832353351e-03, 4.655332645790356e-01, 2.498507336198679e-03,
                4.655413355303657e-01, 1.576478884956591e-03, 4.655445487118463e-01, 9.946977962705516e-04,
                4.655458279147781e-01, 6.276136046196179e-04, 4.655463371765942e-01, 3.959978465130569e-04,
                4.655465399176849e-01, 2.498578584664746e-04, 4.655466206304160e-01, 1.576496782075489e-04,
                4.655466527627409e-01, 9.947022918549027e-05, 4.655466655548509e-01, 6.276147338624847e-05,
                4.655466706474820e-01, 3.959981301663537e-05, 4.655466726748949e-01, 2.498579297169927e-05,
                4.655466734820225e-01, 1.576496961048729e-05, 4.655466738033459e-01, 9.947023368109509e-06,
                4.655466739312669e-01, 6.276147451549338e-06, 4.655466739821933e-01, 3.959981330028886e-06,
                4.655466740024674e-01, 2.498579304294980e-06, 4.655466740105386e-01, 1.576496962838461e-06,
                4.655466740137518e-01, 9.947023372605108e-07, 4.655466740150311e-01, 6.276147452678582e-07,
                4.655466740155403e-01, 3.959981330312538e-07, 4.655466740157432e-01, 2.498579304366230e-07,
                4.655466740158237e-01, 1.576496962856358e-07, 4.655466740158559e-01, 9.947023372650060e-08,
                4.655466740158686e-01, 6.276147452689869e-08, 4.655466740158738e-01, 3.959981330315371e-08,
                4.655466740158758e-01, 2.498579304366941e-08, 4.655466740158766e-01, 1.576496962856536e-08,
                4.655466740158769e-01, 9.947023372650503e-09, 4.655466740158770e-01, 6.276147452689979e-09,
                4.655466740158772e-01, 3.959981330315399e-09, 4.655466740158772e-01, 2.498579304366946e-09,
                4.655466740158771e-01, 1.576496962856537e-09, 4.655466740158772e-01, 9.947023372650507e-10,
                4.655466740158772e-01, 6.276147452689978e-10, 4.655466740158771e-01, 3.959981330315396e-10
            };
            var references = new Complex[1][];

            references[0] = new Complex[riref.Length / 2];
            for (var i = 0; i < riref.Length; i += 2)
            {
                references[0][i / 2] = new Complex(riref[i], riref[i + 1]);
            }

            // Run test
            AnalyzeAC(ac, ckt, exports, references);
            DestroyExports(exports);
        }
Exemple #43
0
        public void When_MOS1CommonSourceAmplifierSmallSignal_Expect_Spice3f5Reference()
        {
            /*
             * Simple common source amplifier
             * Output voltage gain is expected to match reference. Reference by Spice 3f5.
             */
            // Build circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0),
                new VoltageSource("V2", "vdd", "0", 5.0),
                new Resistor("R1", "vdd", "out", 10.0e3),
                new Resistor("R2", "out", "g", 10.0e3),
                new Capacitor("Cin", "in", "g", 1e-6),
                CreateMOS1("M1", "out", "g", "0", "0",
                           "MM", "IS=1e-32 VTO=3.03646 LAMBDA=0 KP=5.28747 CGSO=6.5761e-06 CGDO=1e-11")
                );

            ckt.Entities["V1"].SetParameter("acmag", 1.0);

            // Create simulation
            var ac = new AC("ac", new DecadeSweep(10, 10e9, 5));

            // Create exports
            Export <Complex>[] exports = { new ComplexVoltageExport(ac, "out") };

            // Create references
            double[] riref =
            {
                -1.725813644006744e-03, -6.255567388468394e-01, -4.334997991949969e-03, -9.914292083082819e-01,
                -1.088870790416865e-02, -1.571263986482406e+00, -2.734921201531804e-02, -2.490104807455213e+00,
                -6.868558931531524e-02, -3.945830610208745e+00, -1.724514213823252e-01, -6.250857335307440e+00,
                -4.326808652667278e-01, -9.895562775467608e+00, -1.083718679773610e+00, -1.563829379084251e+01,
                -2.702649136180583e+00, -2.460721571760895e+01, -6.668576859467226e+00, -3.830945453134210e+01,
                -1.603760999419659e+01, -5.813162362216580e+01, -3.639300462484001e+01, -8.323207309729999e+01,
                -7.356417703660050e+01, -1.061546849651946e+02, -1.239747410542734e+02, -1.128771300396776e+02,
                -1.704839090551324e+02, -9.793908744049646e+01, -2.004160562764431e+02, -7.264486862286662e+01,
                -2.154771197776309e+02, -4.928026345664456e+01, -2.221224344754558e+02, -3.205256931555954e+01,
                -2.248834695491267e+02, -2.047502071380190e+01, -2.260018549839163e+02, -1.298284168009341e+01,
                -2.264501941354974e+02, -8.207439641802505e+00, -2.266291765967058e+02, -5.181955183396055e+00,
                -2.267005095543059e+02, -3.269540294698130e+00, -2.267289201967292e+02, -2.061484698952238e+00,
                -2.267402326137311e+02, -1.298056697906094e+00, -2.267447363683708e+02, -8.147282590010622e-01,
                -2.267465291092059e+02, -5.072375792911769e-01, -2.267472421017376e+02, -3.092289341889395e-01,
                -2.267475241460346e+02, -1.779661469529321e-01, -2.267476318976589e+02, -8.511710389733645e-02,
                -2.267476634094340e+02, -1.064055031339878e-02, -2.267476473568060e+02,  6.153924230708851e-02,
                -2.267475691320166e+02,  1.470022622053010e-01, -2.267473575512703e+02,  2.641955750327690e-01,
                -2.267468200791099e+02,  4.384147465157958e-01, -2.267454676298356e+02,  7.072623998910071e-01,
                -2.267420695496819e+02,  1.128758783561459e+00, -2.267335340265157e+02,  1.793841675558252e+00,
                -2.267120964325891e+02,  2.845900637604031e+00, -2.266582653689669e+02,  4.511350906221913e+00,
                -2.265231600192664e+02,  7.147007490994596e+00, -2.261844969618107e+02,  1.131116522055704e+01,
                -2.253382440974266e+02,  1.786070290176738e+01, -2.232401028216283e+02,  2.804520605312238e+01,
                -2.181374806913368e+02,  4.343740586524000e+01, -2.062891648647118e+02, 6.512151536164929e+01
            };
            var references = new Complex[1][];

            references[0] = new Complex[riref.Length / 2];
            for (var i = 0; i < riref.Length; i += 2)
            {
                references[0][i / 2] = new Complex(riref[i], riref[i + 1]);
            }

            // Run test
            AnalyzeAC(ac, ckt, exports, references);
        }
 public override Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cts)
 {
     _circuitClosed(_logger, circuit.Id, null);
     return(base.OnCircuitClosedAsync(circuit, cts));
 }
Exemple #45
0
        //Tradução da função executaFluxoDiarioOpenDSSNativoOpenDSS
        private bool ExecutaFluxoDiarioOpenDSSPvt(string hora)
        {
            //% Interfaces
            Circuit  DSSCircuit  = _oDSS._DSSObj.ActiveCircuit;
            Solution DSSSolution = _oDSS.GetActiveCircuit().Solution;

            //get loadMult da struct paramGerais
            double loadMult = _paramGerais.GetLoadMult();

            if (loadMult == 0)
            {
                _janela.ExibeMsgDisplayMW("LoadMult igual a 0");
                return(false);
            }

            DSSSolution.LoadMult = loadMult;

            // usuario escolheu tensao barramento
            if (_paramGerais._parGUI._usarTensoesBarramento)
            {
                DSSCircuit.Vsources.pu = double.Parse(_paramGerais._parGUI._tensaoSaidaBarUsuario);
            }

            // TODO da erro no modulo reconfiguracao
            // TODO da erro caso tente rodar em alim inexistente.
            switch (_paramGerais._parGUI._tipoFluxo)
            {
            case "Hourly":
                _oDSS._DSSText.Command = "Set mode=daily hour=" + hora + " number=1 stepsize=1h";
                break;

            default:     // "daily"
                _oDSS._DSSText.Command = "Set mode=daily  hour=0 number=24 stepsize=1h";
                break;
            }

            // resolve circuito
            DSSSolution.Solve();

            // se nao convergiu, retorna
            if (!DSSCircuit.Solution.Converged)
            {
                return(false);
            }

            // grava valores do EnergyMeter
            bool ret = GetValoresEnergyMeter();

            // se valores EnergyMeter estao consistentes
            if (ret)
            {
                _resFluxo._energyMeter.GravaLoadMult(loadMult);

                // verifica saida e grava perdas em arquivo OU alimentador que nao tenha convergido
                GravaPerdasArquivo();

                // verifica geracao de relatorios
                GeraRelatorios();
            }
            return(ret);
        }
Exemple #46
0
        /// <summary>
        /// Dump transient information in the console (used for debugging).
        /// </summary>
        /// <param name="tran">The transient analysis.</param>
        /// <param name="ckt">The circuit.</param>
        protected static void DumpTransientState(Transient tran, Circuit ckt)
        {
            var state  = tran.GetState <IIntegrationMethod>();
            var rstate = tran.GetState <IBiasingSimulationState>();

            Console.WriteLine("----------- Dumping transient information -------------");
            Console.WriteLine($"Base time: {state.BaseTime}");
            Console.WriteLine($"Target time: {state.Time}");
            Console.Write($"Last timesteps (current first):");
            for (var i = 0; i <= state.MaxOrder; i++)
            {
                Console.Write("{0}{1}", i > 0 ? ", " : "", state.GetPreviousTimestep(i));
            }
            Console.WriteLine();
            Console.WriteLine("Problem variable: {0}", tran.ProblemVariable);
            Console.WriteLine("Problem variable value: {0}", rstate.Solution[rstate.Map[tran.ProblemVariable]]);
            Console.WriteLine();

            // Dump the circuit contents
            Console.WriteLine("- Circuit contents");
            foreach (var entity in ckt)
            {
                Console.Write(entity.Name);
                if (entity is Component c)
                {
                    foreach (var node in c.Nodes)
                    {
                        Console.Write($"{node} ");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            // Dump the current iteration solution
            Console.WriteLine("- Solutions");
            Dictionary <int, string> variables = new Dictionary <int, string>();

            foreach (var variable in rstate.Map)
            {
                variables.Add(variable.Value, $"{variable.Value} - {variable.Key.Name} ({variable.Key.Unit}): {rstate.Solution[variable.Value]}");
            }
            for (var i = 0; i <= state.MaxOrder; i++)
            {
                var oldsolution = state.GetPreviousSolution(i);
                for (var k = 1; k <= variables.Count; k++)
                {
                    variables[k] += $", {oldsolution[k]}";
                }
            }
            for (var i = 0; i <= variables.Count; i++)
            {
                if (variables.TryGetValue(i, out var value))
                {
                    Console.WriteLine(value);
                }
                else
                {
                    Console.WriteLine($"Could not find variable for index {i}");
                }
            }
            Console.WriteLine();

            /*
             * // Dump the states used by the transient
             #if DEBUG
             * Console.WriteLine("- States");
             * var intstate = state.GetPreviousStates(0);
             * string[] output = new string[intstate.Length];
             * for (var i = 0; i < intstate.Length; i++)
             *  output[i] = $"{intstate[i]}";
             * for (var k = 1; k <= state.MaxOrder; k++)
             * {
             *  intstate = state.GetPreviousStates(k);
             *  for (var i = 0; i < intstate.Length; i++)
             *      output[i] += $", {intstate[i]}";
             * }
             * for (var i = 0; i < output.Length; i++)
             *  Console.WriteLine(output[i]);
             * Console.WriteLine();
             #endif
             */

            Console.WriteLine("------------------------ End of information ------------------------");
        }
Exemple #47
0
 public override Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cancellationToken)
 {
     return(scopedCircuitHandler.OnCircuitClosedAsync(cancellationToken));
 }
Exemple #48
0
        public void When_SwitchTransient_Expect_Spice3f5Reference()
        {
            /*
             * Simple MOS switch
             * The output voltage is expected to match the reference. Reference as simulated by Spice 3f5.
             */
            // Build circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", new Pulse(1, 5, 1e-6, 1e-9, 0.5e-6, 2e-6, 6e-6)),
                new VoltageSource("Vsupply", "vdd", "0", 3.3),
                new Resistor("R1", "out", "vdd", 100e3),
                CreateMOS2("M1", "out", "in", "0", "0", "NFET")
                .SetParameter("w", 1e-6)
                .SetParameter("l", 6e-6),
                CreateMOS2Model("NFET", "VTO = -1.44 KP = 8.64E-6 NSUB = 1e17 TOX = 20e-9")
                );

            // Create simulation
            var tran = new Transient("tran", 1e-9, 10e-6);

            // Create exports
            IExport <double>[] exports = { new GenericExport <double>(tran, () => tran.GetState <IIntegrationMethod>().Time), new RealVoltageExport(tran, "out") };

            // Create references
            var references = new double[2][];

            references[0] = new[]
            {
                0.000000000000000e+00, 1.000000000000000e-11, 2.000000000000000e-11, 4.000000000000000e-11,
                8.000000000000001e-11, 1.600000000000000e-10, 3.200000000000000e-10, 6.400000000000001e-10,
                1.280000000000000e-09, 2.560000000000000e-09, 5.120000000000001e-09, 1.024000000000000e-08,
                2.048000000000000e-08, 4.096000000000000e-08, 8.192000000000001e-08, 1.638400000000000e-07,
                3.276800000000000e-07, 5.276800000000000e-07, 7.276800000000000e-07, 9.276800000000000e-07,
                1.000000000000000e-06, 1.000100000000000e-06, 1.000125000000000e-06, 1.000175000000000e-06,
                1.000275000000000e-06, 1.000278125000000e-06, 1.000284375000000e-06, 1.000296875000000e-06,
                1.000300000000000e-06, 1.000306250000000e-06, 1.000318750000000e-06, 1.000343750000000e-06,
                1.000393750000000e-06, 1.000493750000000e-06, 1.000693750000000e-06, 1.001000000000000e-06,
                1.001040000000000e-06, 1.001120000000000e-06, 1.001280000000000e-06, 1.001600000000000e-06,
                1.002040869607452e-06, 1.002630387377420e-06, 1.003503894605074e-06, 1.005250909060382e-06,
                1.008744937970999e-06, 1.015732995792233e-06, 1.029709111434701e-06, 1.057661342719636e-06,
                1.113565805289506e-06, 1.225374730429247e-06, 1.425374730429247e-06, 1.625374730429247e-06,
                1.825374730429247e-06, 2.025374730429247e-06, 2.225374730429247e-06, 2.425374730429247e-06,
                2.625374730429247e-06, 2.825374730429246e-06, 3.001000000000000e-06, 3.021000000000000e-06,
                3.061000000000000e-06, 3.141000000000000e-06, 3.301000000000000e-06, 3.501000000000000e-06,
                3.520999999999999e-06, 3.560999999999999e-06, 3.641000000000000e-06, 3.801000000000000e-06,
                4.000999999999999e-06, 4.200999999999999e-06, 4.400999999999999e-06, 4.600999999999999e-06,
                4.800999999999999e-06, 5.000999999999998e-06, 5.200999999999998e-06, 5.400999999999998e-06,
                5.600999999999998e-06, 5.800999999999997e-06, 6.000999999999997e-06, 6.200999999999997e-06,
                6.400999999999997e-06, 6.600999999999997e-06, 6.800999999999996e-06, 7.000000000000000e-06,
                7.000100000000000e-06, 7.000125000000000e-06, 7.000175000000000e-06, 7.000275000000000e-06,
                7.000278125000001e-06, 7.000284375000000e-06, 7.000296875000000e-06, 7.000300000000001e-06,
                7.000306250000000e-06, 7.000318750000000e-06, 7.000343750000000e-06, 7.000393750000000e-06,
                7.000493750000001e-06, 7.000693750000000e-06, 7.001000000000000e-06, 7.001040000000000e-06,
                7.001119999999999e-06, 7.001280000000000e-06, 7.001599999999999e-06, 7.002040869607450e-06,
                7.002630387377417e-06, 7.003503894605071e-06, 7.005250909060378e-06, 7.008744937970990e-06,
                7.015732995792216e-06, 7.029709111434669e-06, 7.057661342719574e-06, 7.113565805289383e-06,
                7.225374730429002e-06, 7.425374730429002e-06, 7.625374730429001e-06, 7.825374730429001e-06,
                8.025374730429001e-06, 8.225374730429001e-06, 8.425374730429000e-06, 8.625374730429000e-06,
                8.825374730429000e-06, 9.000999999999999e-06, 9.020999999999999e-06, 9.060999999999998e-06,
                9.140999999999998e-06, 9.300999999999998e-06, 9.500999999999998e-06, 9.520999999999997e-06,
                9.560999999999997e-06, 9.640999999999996e-06, 9.800999999999996e-06, 9.999999999999999e-06
            };
            references[1] = new[]
            {
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 2.890995883050182e+00, 2.860889788871183e+00, 2.797358759613117e+00,
                2.656952623694448e+00, 2.652277000742125e+00, 2.642873246891359e+00, 2.623855584042447e+00,
                2.625531810664886e+00, 2.634981266431170e+00, 2.650057650004957e+00, 2.677324477875249e+00,
                2.727679218653770e+00, 2.807709256115712e+00, 2.895453785010935e+00, 2.890386972407389e+00,
                2.747482253586531e+00, 2.511507415947686e+00, 2.222521734973983e+00, 1.980842807129200e+00,
                1.907033664434709e+00, 1.897814592838963e+00, 1.898216736456195e+00, 1.898102476804415e+00,
                1.898170304423054e+00, 1.898117262851848e+00, 1.898164305207494e+00, 1.898119974323293e+00,
                1.898163015226234e+00, 1.898120603598022e+00, 1.898162692291108e+00, 1.898120833431374e+00,
                1.898162463711884e+00, 1.898121060761244e+00, 1.898162237622255e+00, 1.898121285615139e+00,
                1.898162013995106e+00, 1.898121508020025e+00, 1.898161777543783e+00, 1.924482579560164e+00,
                1.985322321439621e+00, 2.121613755164430e+00, 2.474985118851241e+00, 3.000536619998078e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00,
                2.890995883049932e+00, 2.860889788870923e+00, 2.797358759612839e+00, 2.656952623693816e+00,
                2.652277000741173e+00, 2.642873246891039e+00, 2.623855584042123e+00, 2.625531810665268e+00,
                2.634981266430673e+00, 2.650057650004801e+00, 2.677324477875317e+00, 2.727679218654353e+00,
                2.807709256116441e+00, 2.895453785010313e+00, 2.890386972407629e+00, 2.747482253587951e+00,
                2.511507415948750e+00, 2.222521734974616e+00, 1.980842807129419e+00, 1.907033664434766e+00,
                1.897814592838963e+00, 1.898216736456194e+00, 1.898102476804415e+00, 1.898170304423053e+00,
                1.898117262851849e+00, 1.898164305207493e+00, 1.898119974323294e+00, 1.898163015226234e+00,
                1.898120603598022e+00, 1.898162692291108e+00, 1.898120833431375e+00, 1.898162463711884e+00,
                1.898121060761244e+00, 1.898162237622255e+00, 1.898121285615139e+00, 1.898162013995105e+00,
                1.898121508020025e+00, 1.898161777543783e+00, 1.924482579560162e+00, 1.985322321439618e+00,
                2.121613755164425e+00, 2.474985118851233e+00, 3.000536619998073e+00, 3.000419418896398e+00,
                3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00, 3.000419418896398e+00
            };

            // Run test
            AnalyzeTransient(tran, ckt, exports, references);
            DestroyExports(exports);
        }
Exemple #49
0
    private void OnMouseDown()
    {
        // Debug.Log("OnMouseDown()");
        Vector3    worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int location      = grid.WorldToCell(worldPosition);

        if (tutorialMode)
        {
            TileBase selectedTile = tilemap.GetTile(location);
            if (selectedTile is InputTile)
            {
                if (selectedTile is InputOnTile)
                {
                    InputOffTile newTile = ScriptableObject.CreateInstance <InputOffTile>();
                    newTile.sprite = allSprites.inputOffSprite;
                    tilemap.SetTile(new Vector3Int(location.x, location.y, 0), newTile);
                }
                else
                {
                    InputOnTile newTile = ScriptableObject.CreateInstance <InputOnTile>();
                    newTile.sprite = allSprites.inputOnSprite;
                    tilemap.SetTile(new Vector3Int(location.x, location.y, 0), newTile);
                }
            }
        }
        else if (sandBoxMode)
        {
            switch (index)
            {
            case 0: {
                WireTile tile = ScriptableObject.CreateInstance <WireTile>();
                tile.sprites = allSprites;
                tilemap.SetTile(location, tile);
                break;
            }

            case 1: {
                AndTile tile = ScriptableObject.CreateInstance <AndTile>();
                tile.sprites = allSprites;
                tile.sprite  = allSprites.andSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            case 2: {
                OrTile tile = ScriptableObject.CreateInstance <OrTile>();
                tile.sprites = allSprites;
                tile.sprite  = allSprites.orSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            case 3: {
                NotTile tile = ScriptableObject.CreateInstance <NotTile>();
                tile.sprite = allSprites.notSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            case 4: {
                InputOffTile tile = ScriptableObject.CreateInstance <InputOffTile>();
                tile.sprite = allSprites.inputOffSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            case 5: {
                InputOnTile tile = ScriptableObject.CreateInstance <InputOnTile>();
                tile.sprite = allSprites.inputOnSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            case 6: {
                OutputTile tile = ScriptableObject.CreateInstance <OutputTile>();
                tile.sprites = allSprites;
                tilemap.SetTile(location, tile);
                break;
            }

            case 7: {
                Circuit.RemoveComponent(location);
                tilemap.SetTile(location, null);
                break;
            }

            case 8: {
                BufferTile tile = ScriptableObject.CreateInstance <BufferTile>();
                tile.sprite = allSprites.bufferSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            default: break;
            }
        }
        else if (gameObject.GetComponent <LevelUI>().victory.activeSelf)
        {
            return;
        }
        else if (placeholders.Contains(location))
        {
            switch (index)
            {
            case 1: {
                AndTile tile = ScriptableObject.CreateInstance <AndTile>();
                tile.sprites = allSprites;
                tile.sprite  = allSprites.andSprite;
                tilemap.SetTile(location, tile);

                gameObject.GetComponent <LevelUI>().updateScore();
                break;
            }

            case 2: {
                OrTile tile = ScriptableObject.CreateInstance <OrTile>();
                tile.sprites = allSprites;
                tile.sprite  = allSprites.orSprite;
                tilemap.SetTile(location, tile);

                gameObject.GetComponent <LevelUI>().updateScore();
                break;
            }

            case 7: {
                PlaceholderTile tile = ScriptableObject.CreateInstance <PlaceholderTile>();
                tile.sprite  = allSprites.placeholderSprite;
                tile.sprites = allSprites;
                tilemap.SetTile(location, tile);
                break;
            }

            default: break;
            }
        }
        else if (placeholderBuffers.Contains(location))
        {
            switch (index)
            {
            case 3: {
                NotTile tile = ScriptableObject.CreateInstance <NotTile>();
                tile.sprite = allSprites.notSprite;
                tilemap.SetTile(location, tile);

                gameObject.GetComponent <LevelUI>().updateScore();
                break;
            }

            case 8: {
                BufferTile tile = ScriptableObject.CreateInstance <BufferTile>();
                tile.sprite = allSprites.bufferSprite;
                tilemap.SetTile(location, tile);

                gameObject.GetComponent <LevelUI>().updateScore();
                break;
            }

            case 7: {
                PlaceholderBufferTile tile = ScriptableObject.CreateInstance <PlaceholderBufferTile>();
                tile.sprite = allSprites.placeholderBufferSprite;
                tilemap.SetTile(location, tile);
                break;
            }

            default: break;
            }
        }
        if (!sandBoxMode && !tutorialMode && Circuit.circuitComponents[outputLocation].on)
        {
            bool slotsCovered = true;
            foreach (Vector3Int slot in placeholders)
            {
                slotsCovered = !tilemap.GetTile <PlaceholderTile>(slot) ? slotsCovered : false;
            }
            if (slotsCovered)
            {
                gameObject.GetComponent <LevelUI>().LevelCompleted();
            }
        }
        else if (tutorialMode && Circuit.circuitComponents[outputLocation].on)
        {
            gameObject.GetComponent <TutorialUI>().LevelCompleted();
        }
    }
        public void When_TerminatedTransient_Expect_Reference()
        {
            // Build the circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", new Pulse(1, 5, 2e-6, 1e-9, 1e-9, 5e-6, 10e-6)),
                new Resistor("Rsource", "in", "a", 100),
                new LosslessTransmissionLine("T1", "a", "0", "b", "0", 50.0, 1e-6)
                .SetParameter("reltol", 0.5),
                new Resistor("Rload", "b", "0", 25)
                );

            // Build the simulation
            var tran    = new Transient("tran", 1e-6, 20e-6);
            var exports = new IExport <double>[]
            {
                new GenericExport <double>(tran, () => tran.GetState <IIntegrationMethod>().Time),
                new RealVoltageExport(tran, "a"),
                new RealVoltageExport(tran, "b")
            };

            // Reference inspected 2018-12-05
            var references = new[]
            {
                new[]
                {
                    0, 4E-09, 8E-09, 1.6E-08, 3.2E-08, 6.4E-08, 1.28E-07, 2.56E-07, 5.12E-07, 9.12E-07, 1.312E-06,
                    1.712E-06, 2E-06, 2.0001E-06, 2.0003E-06, 2.0007E-06, 2.001E-06, 2.00108E-06, 2.00124E-06,
                    2.00156E-06, 2.0022E-06, 2.00348E-06, 2.00604E-06, 2.01116E-06, 2.0214E-06, 2.04188E-06,
                    2.08284000000001E-06, 2.16476000000001E-06, 2.32860000000002E-06, 2.65628000000005E-06, 3E-06,
                    3.0001E-06, 3.0003E-06, 3.0007E-06, 3.001E-06, 3.00108E-06, 3.00124E-06, 3.00156E-06, 3.0022E-06,
                    3.00348E-06, 3.00604E-06, 3.01116E-06, 3.02139999999999E-06, 3.04187999999999E-06,
                    3.08283999999997E-06, 3.16475999999994E-06, 3.32859999999989E-06, 3.65627999999977E-06, 4E-06,
                    4.0001E-06, 4.0003E-06, 4.0007E-06, 4.001E-06, 4.00108E-06, 4.00124E-06, 4.00156E-06, 4.0022E-06,
                    4.00348E-06, 4.00604E-06, 4.01116E-06, 4.02139999999999E-06, 4.04187999999999E-06,
                    4.08283999999997E-06, 4.16475999999994E-06, 4.32859999999989E-06, 4.65627999999977E-06, 5E-06,
                    5.0001E-06, 5.0003E-06, 5.0007E-06, 5.001E-06, 5.00108E-06, 5.00124E-06, 5.00156E-06, 5.0022E-06,
                    5.00348E-06, 5.00604E-06, 5.01116E-06, 5.02139999999999E-06, 5.04187999999999E-06,
                    5.08283999999997E-06, 5.16475999999994E-06, 5.32859999999988E-06, 5.65627999999977E-06, 6E-06,
                    6.0001E-06, 6.0003E-06, 6.0007E-06, 6.001E-06, 6.00108E-06, 6.00124E-06, 6.00156E-06, 6.0022E-06,
                    6.00348E-06, 6.00604E-06, 6.01116E-06, 6.02139999999999E-06, 6.04187999999998E-06,
                    6.08283999999997E-06, 6.16475999999994E-06, 6.32859999999988E-06, 6.65627999999977E-06, 7E-06,
                    7.0001E-06, 7.0003E-06, 7.0007E-06, 7.001E-06, 7.0010000008E-06, 7.0010000024E-06, 7.0010000056E-06,
                    7.001000012E-06, 7.0010000248E-06, 7.0010000504E-06, 7.0010001016E-06, 7.001000204E-06,
                    7.0010004088E-06, 7.0010008184E-06, 7.0010016376E-06, 7.001003276E-06, 7.0010065528E-06,
                    7.0010131064E-06, 7.0010262136E-06, 7.001052428E-06, 7.0011048568E-06, 7.0012097144E-06,
                    7.0014194296E-06, 7.00183886E-06, 7.002E-06, 7.00208388608E-06, 7.00225165824E-06,
                    7.00258720256E-06, 7.0032582912E-06, 7.00460046848E-06, 7.00728482304E-06, 7.01265353216E-06,
                    7.0233909504E-06, 7.04486578688E-06, 7.08781545984E-06, 7.17371480576E-06, 7.3455134976E-06,
                    7.68911088128E-06, 8E-06, 8.0001E-06, 8.0003E-06, 8.0007E-06, 8.001E-06, 8.00108E-06, 8.00124E-06,
                    8.00156E-06, 8.002E-06, 8.002064E-06, 8.002192E-06, 8.002448E-06, 8.00296E-06, 8.003984E-06,
                    8.006032E-06, 8.01012799999999E-06, 8.01831999999998E-06, 8.03470399999996E-06,
                    8.06747199999992E-06, 8.13300799999984E-06, 8.26407999999969E-06, 8.52622399999938E-06,
                    8.92622399999937E-06, 9E-06, 9.0001E-06, 9.0003E-06, 9.0007E-06, 9.001E-06, 9.00108E-06,
                    9.00124E-06, 9.00156E-06, 9.002E-06, 9.002064E-06, 9.002192E-06, 9.002448E-06, 9.00296E-06,
                    9.003984E-06, 9.006032E-06, 9.01012799999999E-06, 9.01831999999998E-06, 9.03470399999996E-06,
                    9.06747199999992E-06, 9.13300799999984E-06, 9.26407999999969E-06, 9.52622399999938E-06,
                    9.92622399999938E-06, 1E-05, 1.00001E-05, 1.00003E-05, 1.00007E-05, 1.0001E-05, 1.000108E-05,
                    1.000124E-05, 1.000156E-05, 1.0002E-05, 1.0002064E-05, 1.0002192E-05, 1.0002448E-05, 1.000296E-05,
                    1.0003984E-05, 1.0006032E-05, 1.0010128E-05, 1.001832E-05, 1.0034704E-05, 1.00674719999999E-05,
                    1.01330079999998E-05, 1.02640799999997E-05, 1.05262239999994E-05, 1.09262239999994E-05, 1.1E-05,
                    1.10001E-05, 1.10003E-05, 1.10007E-05, 1.1001E-05, 1.100108E-05, 1.100124E-05, 1.100156E-05,
                    1.1002E-05, 1.1002064E-05, 1.1002192E-05, 1.1002448E-05, 1.100296E-05, 1.1003984E-05, 1.1006032E-05,
                    1.1010128E-05, 1.101832E-05, 1.1034704E-05, 1.10674719999999E-05, 1.11330079999998E-05,
                    1.12640799999997E-05, 1.15262239999994E-05, 1.19262239999994E-05, 1.2E-05, 1.20000000008E-05,
                    1.20000000024E-05, 1.20000000056E-05, 1.2000000012E-05, 1.20000000248E-05, 1.20000000504E-05,
                    1.20000001016E-05, 1.2000000204E-05, 1.20000004088E-05, 1.20000008184E-05, 1.20000016376E-05,
                    1.2000003276E-05, 1.20000065528E-05, 1.20000131064E-05, 1.20000262136E-05, 1.2000052428E-05,
                    1.20001048568E-05, 1.20002097144E-05, 1.20004194296E-05, 1.200083886E-05, 1.2001E-05,
                    1.200108388608E-05, 1.200125165824E-05, 1.200158720256E-05, 1.2002E-05, 1.2002067108864E-05,
                    1.2002201326592E-05, 1.2002469762048E-05, 1.200300663296E-05, 1.2004080374784E-05,
                    1.2006227858432E-05, 1.2010522825728E-05, 1.201911276032E-05, 1.2036292629504E-05,
                    1.2070652367872E-05, 1.2139371844608E-05, 1.227681079808E-05, 1.2551688705024E-05,
                    1.2951688705024E-05, 1.3E-05, 1.30001E-05, 1.30003E-05, 1.30007E-05, 1.3001E-05, 1.300108E-05,
                    1.300124E-05, 1.300156E-05, 1.3002E-05, 1.3002064E-05, 1.3002192E-05, 1.3002448E-05, 1.300296E-05,
                    1.3003984E-05, 1.3006032E-05, 1.3010128E-05, 1.301832E-05, 1.3034704E-05, 1.3067472E-05,
                    1.31330080000001E-05, 1.32640800000001E-05, 1.35262240000003E-05, 1.39262240000003E-05, 1.4E-05,
                    1.40001E-05, 1.40003E-05, 1.40007E-05, 1.4001E-05, 1.400108E-05, 1.400124E-05, 1.400156E-05,
                    1.4002E-05, 1.4002064E-05, 1.4002192E-05, 1.4002448E-05, 1.400296E-05, 1.4003984E-05, 1.4006032E-05,
                    1.4010128E-05, 1.401832E-05, 1.4034704E-05, 1.4067472E-05, 1.41330080000001E-05,
                    1.42640800000001E-05, 1.45262240000003E-05, 1.49262240000003E-05, 1.5E-05, 1.50001E-05, 1.50003E-05,
                    1.50007E-05, 1.5001E-05, 1.500108E-05, 1.500124E-05, 1.500156E-05, 1.5002E-05, 1.5002064E-05,
                    1.5002192E-05, 1.5002448E-05, 1.500296E-05, 1.5003984E-05, 1.5006032E-05, 1.5010128E-05,
                    1.501832E-05, 1.5034704E-05, 1.5067472E-05, 1.51330080000001E-05, 1.52640800000001E-05,
                    1.55262240000003E-05, 1.59262240000003E-05, 1.6E-05, 1.60001E-05, 1.60003E-05, 1.60007E-05,
                    1.6001E-05, 1.600108E-05, 1.600124E-05, 1.600156E-05, 1.6002E-05, 1.6002064E-05, 1.6002192E-05,
                    1.6002448E-05, 1.600296E-05, 1.6003984E-05, 1.6006032E-05, 1.6010128E-05, 1.601832E-05,
                    1.6034704E-05, 1.60674719999999E-05, 1.61330079999998E-05, 1.62640799999997E-05,
                    1.65262239999994E-05, 1.69262239999994E-05, 1.7E-05, 1.70001E-05, 1.70003E-05, 1.70007E-05,
                    1.7001E-05, 1.700108E-05, 1.700124E-05, 1.700156E-05, 1.7002E-05, 1.70020000008E-05,
                    1.70020000024E-05, 1.70020000056E-05, 1.7002000012E-05, 1.70020000248E-05, 1.70020000504E-05,
                    1.70020001016E-05, 1.7002000204E-05, 1.70020004088E-05, 1.70020008184E-05, 1.70020016376E-05,
                    1.7002003276E-05, 1.70020065528E-05, 1.70020131064E-05, 1.70020262136E-05, 1.7002052428E-05,
                    1.70021048568E-05, 1.70022097144E-05, 1.70024194296E-05, 1.700283886E-05, 1.70036777208E-05,
                    1.70053554424E-05, 1.70087108856E-05, 1.7015421772E-05, 1.70288435448E-05, 1.70556870904E-05,
                    1.71093741816E-05, 1.7216748364E-05, 1.74314967288E-05, 1.78314967288E-05, 1.8E-05, 1.80001E-05,
                    1.80003E-05, 1.80007E-05, 1.8001E-05, 1.800108E-05, 1.800124E-05, 1.800156E-05, 1.8002E-05,
                    1.8002064E-05, 1.8002192E-05, 1.8002448E-05, 1.800296E-05, 1.8003984E-05, 1.8006032E-05,
                    1.8010128E-05, 1.801832E-05, 1.8034704E-05, 1.80674719999999E-05, 1.81330079999998E-05,
                    1.82640799999997E-05, 1.85262239999994E-05, 1.89262239999994E-05, 1.9E-05, 1.90001E-05, 1.90003E-05,
                    1.90007E-05, 1.9001E-05, 1.900108E-05, 1.900124E-05, 1.900156E-05, 1.9002E-05, 1.9002064E-05,
                    1.9002192E-05, 1.9002448E-05, 1.900296E-05, 1.9003984E-05, 1.9006032E-05, 1.9010128E-05,
                    1.901832E-05, 1.9034704E-05, 1.90674719999999E-05, 1.91330079999998E-05, 1.92640799999997E-05,
                    1.95262239999994E-05, 1.99262239999994E-05, 2E-05
                },
                new[]
                {
                    0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.333333333333061,
                    0.599999999999747, 1.13333333333312, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333,
                    1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333333, 1.53333333333308,
                    1.47407407407394, 1.35555555555542, 1.11851851851836, 0.940740740740741, 0.940740740740741,
                    0.940740740740741, 0.940740740740741, 0.940740740740741, 0.94074074074074, 0.940740740740741,
                    0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741,
                    0.940740740740741, 0.940740740740741, 0.940740740740741, 0.94074074074074, 0.940740740740741,
                    0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741,
                    0.94074074074074, 0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741,
                    0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741, 0.940740740740741,
                    0.940740740740768, 0.947325102880672, 0.960493827160509, 0.986831275720182, 1.00658436213992,
                    1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992,
                    1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992,
                    1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658436213992,
                    1.00658436213992, 1.00658436213992, 1.00658436213992, 1.00658329547472, 1.00658116214205,
                    1.00657689547447, 1.00656836214155, 1.00655129547573, 1.00651716214182, 1.00644889547626,
                    1.00631236214288, 1.00603929547613, 1.00549316214262, 1.00440089547561, 1.00221636214158,
                    0.997847295475777, 0.989109162141918, 0.971632895474197, 0.936680362141015, 0.866775295474653,
                    0.726965162141927, 0.447344895474217, -0.111895637858944, -0.326748971193416, -0.326748971193416,
                    -0.326748971193416, -0.326748971193416, -0.326748971193416, -0.326748971193416, -0.326748971193416,
                    -0.326748971193416, -0.326748971193416, -0.326748971193416, -0.326748971193416, -0.326748971193416,
                    -0.326748971193416, -0.326748971193416, -0.326748971193425, -0.327480566986748, -0.328943758573402,
                    -0.331870141746693, -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658,
                    -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658,
                    -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658,
                    -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658,
                    -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658, -0.334064929126658,
                    -0.286657521719447, -0.19184270690558, -0.00221307727503345, 0.258527663465935, 0.258527663465935,
                    0.258527663465935, 0.258527663465935, 0.258527663465935, 0.258527663465935, 0.258527663465935,
                    0.258527663465935, 0.258527663465935, 0.258527663465935, 0.258527663465935, 0.258527663465935,
                    0.258527663465935, 0.258527663465935, 0.258527663465936, 0.258527663465936, 0.258608951887417,
                    0.258771528730378, 0.259096682416299, 0.25934054768074, 0.25934054768074, 0.25934054768074,
                    0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074,
                    0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074,
                    0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074,
                    0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074, 0.25934054768074,
                    0.25934054768074, 0.254073057968828, 0.243538078545065, 0.222468119697226, 0.193496926281563,
                    0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563,
                    0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563,
                    0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563, 0.193496926281563,
                    0.193497992876768, 0.193500126065211, 0.193504392444163, 0.193512925199807, 0.193529990711094,
                    0.193564121735927, 0.193632383783328, 0.19376890788037, 0.194041956074377, 0.194588052462084,
                    0.195680245236266, 0.197864630779708, 0.202233401844642, 0.210970943898004, 0.228446027689667,
                    0.263396190961211, 0.333296522233804, 0.473097184778992, 0.752698509871626, 1.31190116005464,
                    1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658,
                    1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658,
                    1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658,
                    1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658,
                    1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52673993914658, 1.52732521578124,
                    1.52849576905055, 1.5308368755892, 1.53405589707983, 1.53405589707983, 1.53405589707983,
                    1.53405589707983, 1.53405589707983, 1.53405589707983, 1.53405589707983, 1.53405589707983,
                    1.53405589707983, 1.53405589707983, 1.53405589707983, 1.53405589707983, 1.53405589707983,
                    1.53405589707983, 1.53405589707983, 1.53405589707983, 1.4747976413812, 1.35628112998394,
                    1.11924810718941, 0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824,
                    0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824,
                    0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824,
                    0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824,
                    0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824, 0.941473340094824,
                    0.941408309357639, 0.941278247883273, 0.941018124934534, 0.94066045588002, 0.94066045588002,
                    0.94066045588002, 0.94066045588002, 0.94066045588002, 0.94066045588002, 0.94066045588002,
                    0.94066045588002, 0.94066045588002, 0.94066045588002, 0.94066045588002, 0.94066045588002,
                    0.94066045588002, 0.94066045588002, 0.94066045588002, 0.94066045588002, 0.9472447065132,
                    0.960413207779563, 0.986750210312288, 1.00650296221157, 1.00650296221169, 1.00650296221169,
                    1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169,
                    1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169,
                    1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169,
                    1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169, 1.00650296221169,
                    1.00650296220943, 0.899843521181798, 0.686524639122024, 0.259886875006992, -0.326740050653336,
                    -0.326740050653336, -0.32674005062581, -0.326740050589114, -0.32674005051573, -0.326740050369008,
                    -0.32674005007574, -0.326740049489908, -0.326740048321064, -0.326740045994649, -0.326740041386918,
                    -0.326740032351852, -0.326740015003305, -0.326739983192546, -0.326739931116368, -0.326739873145377,
                    -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336,
                    -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336,
                    -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336, -0.326740050653336,
                    -0.326740050653336, -0.327471634057022, -0.328934800864396, -0.331861134479143, -0.334055884690175,
                    -0.334055884690188, -0.334055884690188, -0.334055884690188, -0.334055884690188, -0.334055884690188,
                    -0.334055884690187, -0.334055884690188, -0.334055884690188, -0.334055884690188, -0.334055884690187,
                    -0.334055884690188, -0.334055884690188, -0.334055884690188, -0.334055884690188, -0.334055884690187,
                    -0.334055884690188, -0.334055884690187, -0.334055884690188, -0.334055884690188, -0.334055884690188,
                    -0.334055884690188, -0.334055884690188, -0.334055884689184, -0.286649280131082, -0.191836071012873,
                    -0.00220965277846058, 0.258526672294815, 0.258526672294815, 0.258526672294815, 0.258526672294815,
                    0.258526672294815, 0.258526672294815, 0.258526672294815, 0.258526672294815, 0.258526672294815,
                    0.258526672294815, 0.258526672294815, 0.258526672294815, 0.258526672294815, 0.258526672294815,
                    0.258526672294815, 0.258526672294815
                },
                new[]
                {
                    0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
                    0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.200000000000376, 0.288888888888707,
                    0.466666666666875, 0.822222222222457, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889,
                    1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888889, 1.08888888888885,
                    1.07901234567899, 1.05925925925924, 1.01975308641973, 0.990123456790124, 0.990123456790124,
                    0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790123, 0.990123456790124,
                    0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124,
                    0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790123, 0.990123456790124,
                    0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124,
                    0.990123456790123, 0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124,
                    0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124, 0.990123456790124,
                    0.990123456790128, 0.991220850480112, 0.993415637860085, 0.997805212620031, 1.00109739368999,
                    1.00109739368999, 1.00109739923455, 1.00109740662677, 1.00109742140946, 1.00109745096773,
                    1.00109751005587, 1.00109762811862, 1.00109786378988, 1.0010983333155, 1.00109926509917,
                    1.00110109959617, 1.00110465230883, 1.00111129260883, 1.0011227127075, 1.00113811089958,
                    1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999,
                    1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999,
                    1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999,
                    1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999,
                    1.00109739368999, 1.00109739368999, 1.00109739368999, 1.00109739368999, 0.929986282579171,
                    0.787764060358371, 0.50331961591255, 0.112208504801097, 0.112208504801097, 0.112208504801097,
                    0.112208504801097, 0.112208504801097, 0.112208504801097, 0.112208504801097, 0.112208504801097,
                    0.112208504801097, 0.112208504801097, 0.112208504801097, 0.112208504801097, 0.112208504801097,
                    0.112208504801097, 0.112208504801096, 0.112208504801096, 0.112086572168875, 0.111842706904433,
                    0.111354976375551, 0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889,
                    0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889,
                    0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889,
                    0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889,
                    0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889, 0.11098917847889,
                    0.118890413046759, 0.134692882182403, 0.166297820454161, 0.209754610577656, 0.209754610577656,
                    0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209754610577656,
                    0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209754610577656,
                    0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209754610577656, 0.209768158647903,
                    0.209795254788396, 0.209849447069383, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123, 0.209890091280123,
                    0.209890091280123, 0.209890091280123, 0.209890091280123, 0.208969530731444, 0.207128409634057,
                    0.20344616743925, 0.198916154380261, 0.198916154380261, 0.198916154380261, 0.198916154380261,
                    0.198916154380261, 0.198916154380261, 0.198916154380261, 0.198916154380261, 0.198916154380261,
                    0.198916154380261, 0.198916154380261, 0.198916154380261, 0.198916154380261, 0.198916154380261,
                    0.198916154380261, 0.198916154380261, 0.287803537928206, 0.465578305024096, 0.821127839215878,
                    1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776,
                    1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776,
                    1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776,
                    1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776,
                    1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08778998985776, 1.08788753596354,
                    1.08808262817509, 1.0884728125982, 1.08900931617997, 1.08900931617997, 1.08900931617997,
                    1.08900931617997, 1.08900931617997, 1.08900931617997, 1.08900931617997, 1.08900931617997,
                    1.08900931617997, 1.08900931617997, 1.08900931617997, 1.08900931617997, 1.08900931617997,
                    1.08900931617997, 1.08900931617997, 1.08900931617997, 1.0791329402302, 1.05938018833066,
                    1.01987468453157, 0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471,
                    0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471,
                    0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471,
                    0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471,
                    0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471, 0.990245556682471,
                    0.990234718226274, 0.990213041313879, 0.99016968748909, 0.990110075980004, 0.990110075980003,
                    0.990110075980003, 0.990110075980003, 0.990110075980003, 0.990110075980003, 0.990110075980003,
                    0.990110075980003, 0.990110075980003, 0.990110075980003, 0.990110075980003, 0.990110075980003,
                    0.990110075980003, 0.990110075980003, 0.990110075980003, 0.990110075980003, 0.991207451085534,
                    0.993402201296594, 0.997791701718715, 1.00108382703526, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528, 1.00108382703528,
                    1.00108382703528, 1.00108382703378, 0.929973920196624, 0.787754106519309, 0.503314479167691,
                    0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777,
                    0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777,
                    0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777, 0.112209991557777,
                    0.112209991557777, 0.112088060990496, 0.111844199855934, 0.111356477586809, 0.110990685884971,
                    0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969,
                    0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969,
                    0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969,
                    0.110990685884969, 0.110990685884969, 0.110990685884969, 0.110990685884969
                }
            };

            // Analyze
            AnalyzeTransient(tran, ckt, exports, references);
            DestroyExports(exports);
        }
Exemple #51
0
        public override Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
        {
            Interlocked.Increment(ref refCoutner);

            return(base.OnCircuitOpenedAsync(circuit, cancellationToken));
        }
Exemple #52
0
 public void NextLevel()
 {
     Circuit.ClearCricuit();
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
 }
Exemple #53
0
 public double GetVoltage(Circuit ckt) => ckt.State.Real.Solution[VCVSposNode] - ckt.State.Real.Solution[VCVSnegNode];
Exemple #54
0
        /// <summary>
        /// Do temperature-dependent calculations
        /// </summary>
        /// <param name="ckt">The circuit</param>
        public override void Temperature(Circuit ckt)
        {
            double kt1;
            double arg1;
            double fermis;
            double wkfng;
            double fermig;
            double wkfngs;
            double vfb;

            if (!MOS3tnom.Given)
            {
                MOS3tnom.Value = ckt.State.NominalTemperature;
            }
            fact1   = MOS3tnom / Circuit.CONSTRefTemp;
            vtnom   = MOS3tnom * Circuit.CONSTKoverQ;
            kt1     = Circuit.CONSTBoltz * MOS3tnom;
            egfet1  = 1.16 - (7.02e-4 * MOS3tnom * MOS3tnom) / (MOS3tnom + 1108);
            arg1    = -egfet1 / (kt1 + kt1) + 1.1150877 / (Circuit.CONSTBoltz * (Circuit.CONSTRefTemp + Circuit.CONSTRefTemp));
            pbfact1 = -2 * vtnom * (1.5 * Math.Log(fact1) + Circuit.CHARGE * arg1);

            MOS3oxideCapFactor = 3.9 * 8.854214871e-12 / MOS3oxideThickness;
            if (!MOS3surfaceMobility.Given)
            {
                MOS3surfaceMobility.Value = 600;
            }
            if (!MOS3transconductance.Given)
            {
                MOS3transconductance.Value = MOS3surfaceMobility * MOS3oxideCapFactor * 1e-4;
            }
            if (MOS3substrateDoping.Given)
            {
                if (MOS3substrateDoping * 1e6 /*(cm**3/m**3)*/ > 1.45e16)
                {
                    if (!MOS3phi.Given)
                    {
                        MOS3phi.Value = 2 * vtnom * Math.Log(MOS3substrateDoping * 1e6 /*(cm**3/m**3)*/ / 1.45e16);
                        MOS3phi.Value = Math.Max(.1, MOS3phi);
                    }
                    fermis = MOS3type * .5 * MOS3phi;
                    wkfng  = 3.2;
                    if (MOS3type != 0)
                    {
                        fermig = MOS3type * MOS3type * .5 * egfet1;
                        wkfng  = 3.25 + .5 * egfet1 - fermig;
                    }
                    wkfngs = wkfng - (3.25 + .5 * egfet1 + fermis);
                    if (!MOS3gamma.Given)
                    {
                        MOS3gamma.Value = Math.Sqrt(2 * EPSSIL * Circuit.CHARGE * MOS3substrateDoping * 1e6 /*(cm**3/m**3)*/) / MOS3oxideCapFactor;
                    }
                    if (!MOS3vt0.Given)
                    {
                        if (!MOS3surfaceStateDensity.Given)
                        {
                            MOS3surfaceStateDensity.Value = 0;
                        }
                        vfb           = wkfngs - MOS3surfaceStateDensity * 1e4 * Circuit.CHARGE / MOS3oxideCapFactor;
                        MOS3vt0.Value = vfb + MOS3type * (MOS3gamma * Math.Sqrt(MOS3phi) + MOS3phi);
                    }
                    else
                    {
                        vfb = MOS3vt0 - MOS3type * (MOS3gamma * Math.Sqrt(MOS3phi) + MOS3phi);
                    }
                    MOS3alpha            = (EPSSIL + EPSSIL) / (Circuit.CHARGE * MOS3substrateDoping * 1e6 /*(cm**3/m**3)*/);
                    MOS3coeffDepLayWidth = Math.Sqrt(MOS3alpha);
                }
                else
                {
                    MOS3substrateDoping.Value = 0;
                    throw new CircuitException($"{Name}: Nsub < Ni");
                }
            }
            /* now model parameter preprocessing */
            MOS3narrowFactor = MOS3delta * 0.5 * Circuit.CONSTPI * EPSSIL / MOS3oxideCapFactor;

            /* loop through all instances of the model */
        }
Exemple #55
0
 /// <summary>
 /// Do temperature-dependent calculations
 /// </summary>
 /// <param name="ckt">The circuit</param>
 public override void Temperature(Circuit ckt)
 {
     MUTfactor = MUTcoupling * Math.Sqrt(ind1.INDinduct * ind2.INDinduct);
 }
Exemple #56
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ckt"></param>
 public override void Load(Circuit ckt)
 {
     // Don't need to do anything here
 }
 public override Task OnConnectionDownAsync(Circuit circuit, CancellationToken cts)
 {
     _connectionDown(_logger, circuit.Id, null);
     return(base.OnConnectionDownAsync(circuit, cts));
 }
Exemple #58
0
        public void When_SimpleDC_Expect_Spice3f5Reference()
        {
            /*
             * MOS2 shunted by voltage sources
             * Current is expected to match the reference. Reference is simulated by Spice 3f5.
             */
            // Create circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0),
                new VoltageSource("V2", "out", "0", 0.0),
                CreateMOS2("M1", "out", "in", "0", "0", "NFET")
                .SetParameter("l", 6e-6)
                .SetParameter("w", 1e-6),
                CreateMOS2Model("NFET", "VTO = -1.44 KP = 8.64E-6 NSUB = 1e17 TOX = 20e-9")
                );

            // Create simulation
            var dc = new DC("dc", new[] {
                new ParameterSweep("V2", new LinearSweep(0, 3.3, 0.3)),
                new ParameterSweep("V1", new LinearSweep(0, 3.3, 0.3))
            });

            // Create exports
            IExport <double>[] exports = { new RealPropertyExport(dc, "V2", "i") };

            // Create references
            var references = new double[1][];

            references[0] = new[]
            {
                0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00,
                0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00,
                0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00,
                -5.306938374762972e-07, -6.622829041640560e-07, -7.937581773977502e-07, -9.251256793208626e-07,
                -1.056391893430447e-06, -1.187563541271432e-06, -1.318647392836713e-06, -1.449650112001313e-06,
                -1.580578136718209e-06, -1.711437591907900e-06, -1.842234231506578e-06, -1.972973405226006e-06,
                -8.638458189766005e-07, -1.127266444634827e-06, -1.390443306657313e-06, -1.653387842188881e-06,
                -1.916112823385289e-06, -2.178631872717426e-06, -2.440959028691271e-06, -2.703108371482166e-06,
                -2.965093715016955e-06, -3.226928367443185e-06, -3.488624957291339e-06, -3.750195318941171e-06,
                -1.006642980508283e-06, -1.402162238528042e-06, -1.797292612754292e-06, -2.192049695953252e-06,
                -2.586451725095741e-06, -2.980518839976069e-06, -3.374272380032708e-06, -3.767734241737990e-06,
                -4.160926317516499e-06, -4.553870030753595e-06, -4.946585972966656e-06, -5.339093640940220e-06,
                -1.013799629686942e-06, -1.492058405858433e-06, -2.019403706665254e-06, -2.546235206750328e-06,
                -3.072559603046376e-06, -3.598402479001807e-06, -4.123791871424482e-06, -4.648757350976099e-06,
                -5.173329167535178e-06, -5.697537495654653e-06, -6.221411805023045e-06, -6.744980367812900e-06,
                -1.014566859581403e-06, -1.493160556051296e-06, -2.067521923824644e-06, -2.719762043312447e-06,
                -3.378280908481190e-06, -4.036155046468613e-06, -4.693417839623045e-06, -5.350105680759867e-06,
                -6.006256834174742e-06, -6.661910361168374e-06, -7.317105161899917e-06, -7.971879170944456e-06,
                -1.015356741659893e-06, -1.494299909660686e-06, -2.069063097873367e-06, -2.740840251690813e-06,
                -3.506586652651430e-06, -4.296774575599588e-06, -5.086176728084939e-06, -5.874834670198922e-06,
                -6.662793553470293e-06, -7.450100756193913e-06, -8.236804578683890e-06, -9.022953068962966e-06,
                -1.016165437476091e-06, -1.495471083771302e-06, -2.070653897845618e-06, -2.742900593322288e-06,
                -3.513262901776043e-06, -4.382683065140698e-06, -5.304470813563661e-06, -6.225375503988383e-06,
                -7.145400341215117e-06, -8.064599592900621e-06, -8.983030137568078e-06, -9.900749917551870e-06,
                -1.016989023485014e-06, -1.496668363213843e-06, -2.072286704485665e-06, -2.745024194610477e-06,
                -3.515924552362666e-06, -4.385920816155342e-06, -5.355855832487864e-06, -6.403691255248455e-06,
                -7.456069595713784e-06, -8.507429881427832e-06, -9.557835816840147e-06, -1.060735413910678e-05,
                -1.017823668891155e-06, -1.497885983840097e-06, -2.073953544717280e-06, -2.747200785959000e-06,
                -3.518664091102590e-06, -4.389267691949250e-06, -5.359844436218669e-06, -6.431152584792028e-06,
                -7.596428673614574e-06, -8.780248653652516e-06, -9.962909998812256e-06, -1.114448614086207e-05,
                -1.018665778845741e-06, -1.499118382335761e-06, -2.075646475814351e-06, -2.749419763651192e-06,
                -3.521468187712419e-06, -4.392707866929063e-06, -5.363962030875167e-06, -6.435978121313036e-06,
                -7.609441818854552e-06, -8.884419035140827e-06, -1.019964577331805e-05, -1.151357106530835e-05,
                -1.019512094513571e-06, -1.500360390171152e-06, -2.077357913157599e-06, -2.751670684538682e-06,
                -3.524323247900116e-06, -4.396224548237776e-06, -5.368188911914150e-06, -6.440953329762988e-06,
                -7.615191814315274e-06, -8.891527316636293e-06, -1.027054150786247e-05, -1.171578914356212e-05
            };

            // Run test
            AnalyzeDC(dc, ckt, exports, references);
            DestroyExports(exports);
        }
 public Race()
 {
     circuit = new Circuit();
     grid    = new Grid();
 }
Exemple #60
0
        /// <summary>
        /// Execute the DC simulation
        /// </summary>
        /// <param name="ckt">The circuit</param>
        public override void Execute(Circuit ckt)
        {
            // Setup the state
            var state  = ckt.State;
            var rstate = state.Real;
            var config = CurrentConfig;

            state.Initialize(ckt);
            state.UseIC          = false; // UseIC is only used in transient simulations
            state.UseDC          = true;
            state.UseSmallSignal = false;
            state.Domain         = CircuitState.DomainTypes.None;
            state.Gmin           = config.Gmin;

            // Initialize
            IParameterized[] components = new IParameterized[Sweeps.Count];
            Parameter[]      parameters = new Parameter[Sweeps.Count];

            // Initialize first time
            for (int i = 0; i < Sweeps.Count; i++)
            {
                // Get the component to be swept
                var sweep = Sweeps[i];
                if (!ckt.Objects.Contains(sweep.ComponentName))
                {
                    throw new CircuitException($"Could not find source {sweep.ComponentName}");
                }
                components[i] = (IParameterized)ckt.Objects[sweep.ComponentName];

                // Get the parameter and save it for restoring later
                parameters[i] = (Parameter)GetDcParameter(components[i]).Clone();

                // Start with the original values
                sweep.SetCurrentStep(0);
                components[i].Set("dc", sweep.CurrentValue);
            }

            Initialize(ckt);

            // Execute the sweeps
            int level = Sweeps.Count - 1;

            while (level >= 0)
            {
                // Fill the values with start values
                while (level < Sweeps.Count - 1)
                {
                    level++;
                    Sweeps[level].SetCurrentStep(0);
                    components[level].Set("dc", Sweeps[level].CurrentValue);
                }

                // Calculate the solution
                if (!Iterate(config, ckt, config.SweepMaxIterations))
                {
                    IterationFailed?.Invoke(this, ckt);
                    Op(config, ckt, config.DcMaxIterations);
                }

                // Export data
                Export(ckt);

                // Remove all values that are greater or equal to the maximum value
                while (level >= 0 && Sweeps[level].CurrentStep >= Sweeps[level].Limit)
                {
                    level--;
                }

                // Go to the next step for the top level
                if (level >= 0)
                {
                    Sweeps[level].SetCurrentStep(Sweeps[level].CurrentStep + 1);
                    components[level].Set("dc", Sweeps[level].CurrentValue);
                }
            }

            // Restore all the parameters of the swept components
            for (int i = 0; i < Sweeps.Count; i++)
            {
                SetDcParameter(components[i], parameters[i]);
            }

            Finalize(ckt);
        }