当前位置: 首页>>代码示例>>C#>>正文


C# Circuit.Watch方法代码示例

本文整理汇总了C#中Circuit.Watch方法的典型用法代码示例。如果您正苦于以下问题:C# Circuit.Watch方法的具体用法?C# Circuit.Watch怎么用?C# Circuit.Watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Circuit的用法示例。


在下文中一共展示了Circuit.Watch方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CapacitorFrequencyTest

        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));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:25,代码来源:ACVoltageTest.cs

示例2: CapacitorCapacitanceTest

        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));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:31,代码来源:ACVoltageTest.cs

示例3: ACWaveTest

        public void ACWaveTest()
        {
            Circuit sim = new Circuit();

            var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);

            var res0 = sim.Create<Resistor>();
            var ground0 = sim.Create<Ground>();

            sim.Connect(voltage0.leadPos, res0.leadIn);
            sim.Connect(res0.leadOut, ground0.leadIn);

            var resScope0 = sim.Watch(res0);

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

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

            double voltageHigh = resScope0.Max((f) => f.voltage);
            int voltageHighNdx = resScope0.FindIndex((f) => f.voltage == voltageHigh);

            TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
            TestUtils.Compare(resScope0[voltageHighNdx].time, quarterCycleTime, 4);

            double voltageLow = resScope0.Min((f) => f.voltage);
            int voltageLowNdx = resScope0.FindIndex((f) => f.voltage == voltageLow);

            TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
            TestUtils.Compare(resScope0[voltageLowNdx].time, quarterCycleTime * 3, 4);

            double currentHigh = resScope0.Max((f) => f.current);
            int currentHighNdx = resScope0.FindIndex((f) => f.current == currentHigh);
            Debug.Log(currentHigh, "currentHigh");

            double currentLow = resScope0.Min((f) => f.current);
            int currentLowNdx = resScope0.FindIndex((f) => f.current == currentLow);
            Debug.Log(Math.Round(currentLow, 4), "currentLow");
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:41,代码来源:VoltageWaveTest.cs

示例4: CMOSTransmissionGateTest

        public void CMOSTransmissionGateTest(bool in0, double out0)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);
            volt0.maxVoltage = 2.5;
            volt0.bias = 2.5;

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

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

            var res0 = sim.Create<Resistor>();
            var grnd0 = sim.Create<Ground>();

            sim.Connect(volt0.leadPos, pmosf0.leadDrain);

            sim.Connect(pmosf0.leadDrain, nmosf0.leadSrc);
            sim.Connect(pmosf0.leadSrc, nmosf0.leadDrain);

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

            sim.Connect(pmosf0.leadSrc, res0.leadIn);
            sim.Connect(res0.leadOut, grnd0.leadIn);

            var res0Scope = sim.Watch(res0);

            if(in0) logicIn0.toggle();

            double cycleTime = 1 / volt0.frequency;
            double quarterCycleTime = cycleTime / 4;
            int steps = (int)(cycleTime / sim.timeStep);
            sim.doTicks(steps);

            Assert.AreEqual(out0, Math.Round(res0Scope.Max((e) => e.voltage), 6));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:40,代码来源:MosfetTest.cs

示例5: CapacitorTest

        public void CapacitorTest()
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<DCVoltageSource>();
            var cap0 = sim.Create<CapacitorElm>(2E-4);
            var res0 = sim.Create<Resistor>();

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

            /*sim.Connect(volt0, 1, switch0, 1);
            sim.Connect(switch0, 1, switch0, 1);
            sim.Connect(switch0, 2, res0, 1);
            sim.Connect(cap0, 1, res0, 0);
            sim.Connect(res0, 1, volt0, 0);*/

            // leadNeg 0
            // leadPos 1

            sim.Connect(volt0, 1, switch0, 1);
            sim.Connect(switch0, 0, cap0, 0);
            sim.Connect(cap0, 1, res0, 0);
            sim.Connect(res0, 1, volt0, 0);
            sim.Connect(switch0, 2, volt0, 0);

            switch0.setPosition(0);

            var capScope0 = sim.Watch(cap0);

            for(int x = 1; x <= 28000; x++)
                sim.doTick();

            Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
            {
                double voltageHigh = capScope0.Max((f) => f.voltage);
                int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);

                Debug.Log("voltageHigh", voltageHigh, voltageHighNdx);

                double voltageLow = capScope0.Min((f) => f.voltage);
                int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);

                Debug.Log("voltageLow ", voltageLow, voltageLowNdx);

                double currentHigh = capScope0.Max((f) => f.current);
                int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
                Debug.Log("currentHigh", currentHigh, currentHighNdx);

                double currentLow = capScope0.Min((f) => f.current);
                int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);

                Debug.Log("currentLow ", currentLow, currentLowNdx);

                Assert.AreEqual(27999, voltageHighNdx);
                Assert.AreEqual(    0, voltageLowNdx);

                Assert.AreEqual(    0, currentHighNdx);
                Assert.AreEqual(27999, currentLowNdx);
            }

            switch0.setPosition(1);
            sim.analyze();
            capScope0.Clear();

            for(int x = 1; x <= 28000; x++)
                sim.doTick();

            Debug.Log();

            Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
            {
                double voltageHigh = capScope0.Max((f) => f.voltage);
                int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);

                Debug.Log("voltageHigh ", voltageHigh, voltageHighNdx);

                double voltageLow = capScope0.Min((f) => f.voltage);
                int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);

                Debug.Log("voltageLow  ", voltageLow, voltageLowNdx);

                double currentHigh = capScope0.Max((f) => f.current);
                int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
                Debug.Log("currentHigh", currentHigh, currentHighNdx);

                double currentLow = capScope0.Min((f) => f.current);
                int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);

                Debug.Log("currentLow ", currentLow, currentLowNdx);

                Assert.AreEqual(voltageHighNdx, currentLowNdx);
                Assert.AreEqual(voltageLowNdx, currentHighNdx);

                Assert.AreEqual(    0, voltageHighNdx);
                Assert.AreEqual(27999, voltageLowNdx);

                Assert.AreEqual(27999, currentHighNdx);
                Assert.AreEqual(    0, currentLowNdx);
            }
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:100,代码来源:DCVoltageTest.cs

示例6: SquareWaveTest

        public void SquareWaveTest()
        {
            Circuit sim = new Circuit();

            var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);

            var res0 = sim.Create<Resistor>();
            var ground0 = sim.Create<Ground>();

            sim.Connect(voltage0.leadPos, res0.leadIn);
            sim.Connect(res0.leadOut, ground0.leadIn);

            var resScope0 = sim.Watch(res0);

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

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

            double voltageHigh = resScope0.Max((f) => f.voltage);
            int voltageHighNdx = resScope0.FindIndex((f) => f.voltage == voltageHigh);

            Assert.AreEqual(voltageHigh, voltage0.dutyCycle);
            Assert.AreEqual(0, voltageHighNdx);

            double voltageLow = resScope0.Min((f) => f.voltage);
            int voltageLowNdx = resScope0.FindIndex((f) => f.voltage == voltageLow);

            Assert.AreEqual(voltageLow, -voltage0.dutyCycle);
            Assert.AreEqual(2501, voltageLowNdx);

            double currentHigh = resScope0.Max((f) => f.current);
            int currentHighNdx = resScope0.FindIndex((f) => f.current == currentHigh);
            Assert.AreEqual(voltageHigh / res0.resistance, currentHigh);

            double currentLow = resScope0.Min((f) => f.current);
            int currentLowNdx = resScope0.FindIndex((f) => f.current == currentLow);
            Assert.AreEqual(voltageLow / res0.resistance, currentLow);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:41,代码来源:VoltageWaveTest.cs

示例7: GyratorTest

        public void GyratorTest()
        {
            Circuit sim = new Circuit();

            var square0 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);
            square0.frequency = 20;

            var res0 = sim.Create<Resistor>(1000);
            var res1 = sim.Create<Resistor>(20000);
            var cap0 = sim.Create<CapacitorElm>(2.5E-7);
            var opAmp0 = sim.Create<OpAmp>();
            var grnd0 = sim.Create<Ground>();

            sim.Connect(square0.leadPos, res0.leadIn);
            sim.Connect(opAmp0.leadNeg, res0.leadOut);
            sim.Connect(opAmp0.leadOut, opAmp0.leadNeg);

            sim.Connect(square0.leadPos, cap0.leadIn);
            sim.Connect(opAmp0.leadPos, cap0.leadOut);
            sim.Connect(cap0.leadOut, res1.leadIn);
            sim.Connect(res1.leadOut, grnd0.leadIn);

            var square1 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);
            square1.frequency = 20;

            var res3 = sim.Create<Resistor>(1000);
            var induct0 = sim.Create<InductorElm>(5);
            var grnd1 = sim.Create<Ground>();

            sim.Connect(square1.leadPos, res3.leadIn);
            sim.Connect(res3.leadOut, induct0.leadIn);
            sim.Connect(induct0.leadOut, grnd0.leadIn);

            var scope0 = sim.Watch(square0);
            var scope1 = sim.Watch(square1);

            double cycleTime = 1 / square0.frequency;
            double quarterCycleTime = cycleTime / 4;
            int steps = (int)(cycleTime / sim.timeStep);
            sim.doTicks(steps);

            for(int x = 0; x < scope0.Count; x++) {
                Assert.AreEqual(scope0[x].voltage, scope1[x].voltage);
                Assert.AreEqual(0, Math.Round(scope0[x].current - scope1[x].current, 3));
            }
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:46,代码来源:OpAmpTest.cs

示例8: CapacitanceMultiplierTest

        public void CapacitanceMultiplierTest()
        {
            Circuit sim = new Circuit();

            var square0 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);
            square0.frequency = 30;

            var res0 = sim.Create<Resistor>(100000);
            var res1 = sim.Create<Resistor>(1000);
            var cap0 = sim.Create<CapacitorElm>(1E-7);
            var opAmp0 = sim.Create<OpAmp>();
            var grnd0 = sim.Create<Ground>();

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

            sim.Connect(opAmp0.leadNeg, res1.leadOut);
            sim.Connect(opAmp0.leadNeg, opAmp0.leadOut);

            sim.Connect(opAmp0.leadPos, res0.leadOut);
            sim.Connect(opAmp0.leadPos, cap0.leadIn);

            sim.Connect(cap0.leadOut, grnd0.leadIn);

            var square1 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);
            square1.frequency = 30;

            var cap1 = sim.Create<CapacitorElm>(1E-5);
            var res2 = sim.Create<Resistor>(1000);
            var grnd1 = sim.Create<Ground>();

            sim.Connect(square1.leadPos, cap1.leadIn);
            sim.Connect(cap1.leadOut, res2.leadIn);
            sim.Connect(res2.leadOut, grnd1.leadIn);

            var scope0 = sim.Watch(cap0);
            var scope1 = sim.Watch(cap1);

            double cycleTime = 1 / square0.frequency;
            double quarterCycleTime = cycleTime / 4;
            int steps = (int)(cycleTime / sim.timeStep);
            sim.doTicks(steps);

            /*Assert.AreEqual( 4.06, Math.Round(scope0.Max((f) => f.voltage), 2));
            Assert.AreEqual(-3.29, Math.Round(scope0.Min((f) => f.voltage), 2));
            Assert.AreEqual( 4.06, Math.Round(scope1.Max((f) => f.voltage), 2));
            Assert.AreEqual(-3.29, Math.Round(scope1.Min((f) => f.voltage), 2));

            Assert.AreEqual( 0.004999, Math.Round(scope0.Max((f) => f.current) * 100, 6));
            Assert.AreEqual(-0.009054, Math.Round(scope0.Min((f) => f.current) * 100, 6));
            Assert.AreEqual( 0.004999, Math.Round(scope1.Max((f) => f.current), 6));
            Assert.AreEqual(-0.009054, Math.Round(scope1.Min((f) => f.current), 6));*/

            for(int x = 0; x < scope0.Count; x++) {
                Assert.AreEqual(Math.Round(scope0[x].voltage, 6), Math.Round(scope1[x].voltage, 6));
                Assert.AreEqual(Math.Round(scope0[x].current * 100, 6), Math.Round(scope1[x].current, 6));
            }

            scope0.Clear();
            scope1.Clear();
            sim.doTicks(steps);

            /*Assert.AreEqual( 3.43, Math.Round(scope0.Max((f) => f.voltage), 2));
            Assert.AreEqual(-3.41, Math.Round(scope0.Min((f) => f.voltage), 2));
            Assert.AreEqual( 3.43, Math.Round(scope1.Max((f) => f.voltage), 2));
            Assert.AreEqual(-3.41, Math.Round(scope1.Min((f) => f.voltage), 2));

            Assert.AreEqual( 0.008287, Math.Round(scope0.Max((f) => f.current) * 100, 6));
            Assert.AreEqual(-0.008432, Math.Round(scope0.Min((f) => f.current) * 100, 6));
            Assert.AreEqual( 0.008287, Math.Round(scope1.Max((f) => f.current), 6));
            Assert.AreEqual(-0.008432, Math.Round(scope1.Min((f) => f.current), 6));*/

            for(int x = 0; x < scope0.Count; x++) {
                Assert.AreEqual(Math.Round(scope0[x].voltage, 6), Math.Round(scope1[x].voltage, 6));
                Assert.AreEqual(Math.Round(scope0[x].current * 100, 6), Math.Round(scope1[x].current, 6));
            }
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:77,代码来源:OpAmpTest.cs

示例9: InductorFrequencyTest

        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));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:26,代码来源:ACVoltageTest.cs

示例10: SimpleACVoltageTest

        public void SimpleACVoltageTest(double frequency)
        {
            Circuit sim = new Circuit();

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

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

            sim.Connect(voltage0.leadPos, resistor.leadIn);
            sim.Connect(resistor.leadOut, ground.leadIn);

            var voltScope = sim.Watch(voltage0);

            // Cycle time is:
            //  1s
            // ---
            // (X)Hz
            double cycleTime = 1 / voltage0.frequency;

            // Peak values of the wave occur on
            // quarter values of the cycle time
            double quarterCycleTime = cycleTime / 4;

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

            double voltageHigh = voltScope.Max((f) => f.voltage);
            int voltageHighNdx = voltScope.FindIndex((f) => f.voltage == voltageHigh);

            TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
            TestUtils.Compare(voltScope[voltageHighNdx].time, quarterCycleTime, 4); // Max voltage is reached by 1/4 of a cycle

            double voltageLow = voltScope.Min((f) => f.voltage);
            int voltageLowNdx = voltScope.FindIndex((f) => f.voltage == voltageLow);

            TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
            TestUtils.Compare(voltScope[voltageLowNdx].time, quarterCycleTime * 3, 4); // Min voltage is reached by 3/4 of a cycle

            double currentHigh = voltScope.Max((f) => f.current);
            int currentHighNdx = voltScope.FindIndex((f) => f.current == currentHigh);
            Debug.Log(currentHigh, "currentHigh");

            double currentLow = voltScope.Min((f) => f.current);
            int currentLowNdx = voltScope.FindIndex((f) => f.current == currentLow);
            Debug.Log(Math.Round(currentLow, 4), "currentLow");
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:49,代码来源:ACVoltageTest.cs

示例11: SimpleDiodeTest

        public void SimpleDiodeTest()
        {
            Circuit sim = new Circuit();

            var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);
            var diode = sim.Create<DiodeElm>();
            var ground = sim.Create<Ground>();

            sim.Connect(voltage0.leadPos, diode.leadIn);
            sim.Connect(diode.leadOut, ground.leadIn);

            var diodeScope = sim.Watch(diode);

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

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

            double voltageHigh = diodeScope.Max((f) => f.voltage);
            int voltageHighNdx = diodeScope.FindIndex((f) => f.voltage == voltageHigh);

            TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
            TestUtils.Compare(diodeScope[voltageHighNdx].time, quarterCycleTime, 4);

            double voltageLow = diodeScope.Min((f) => f.voltage);
            int voltageLowNdx = diodeScope.FindIndex((f) => f.voltage == voltageLow);

            TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
            TestUtils.Compare(diodeScope[voltageLowNdx].time, quarterCycleTime * 3, 4);

            double currentHigh = diodeScope.Max((f) => f.current);
            int currentHighNdx = diodeScope.FindIndex((f) => f.current == currentHigh);
            TestUtils.Compare(diodeScope[voltageHighNdx].time, diodeScope[currentHighNdx].time, 5);

            double currentLow = diodeScope.Min((f) => f.current);
            int currentLowNdx = diodeScope.FindIndex((f) => f.current == currentLow);

            TestUtils.Compare(currentLow, 0, 8);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:41,代码来源:DiodeTest.cs

示例12: HalfWaveRectifierTest

        public void HalfWaveRectifierTest()
        {
            /*string nm = TestContext.CurrentContext.Test.Name;
            string js = System.IO.File.ReadAllText(string.Format("./{0}.json", nm));
            Circuit sim = JsonSerializer.DeserializeFromString<Circuit>(js);
            sim.needAnalyze();

            var source0 = sim.getElm(0) as VoltageElm;
            var sourceScope = sim.Watch(sim.getElm(0));
            var resScope = sim.Watch(sim.getElm(2));*/

            Circuit sim = new Circuit();

            Voltage voltage0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            DiodeElm diode0 = sim.Create<DiodeElm>();
            Resistor res0 = sim.Create<Resistor>(640);
            Wire wire0 = sim.Create<Wire>();

            sim.Connect(voltage0, 1, diode0, 0);
            sim.Connect(diode0, 1, res0, 0);
            sim.Connect(res0, 1, wire0, 0);
            sim.Connect(wire0, 1, voltage0, 0);

            var voltScope = sim.Watch(voltage0);
            var resScope = sim.Watch(res0);

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

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

            // A/C Voltage Source
            {
                double voltageHigh = voltScope.Max((f) => f.voltage);
                int voltageHighNdx = voltScope.FindIndex((f) => f.voltage == voltageHigh);

                TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
                TestUtils.Compare(voltScope[voltageHighNdx].time, quarterCycleTime, 4);

                double voltageLow = voltScope.Min((f) => f.voltage);
                int voltageLowNdx = voltScope.FindIndex((f) => f.voltage == voltageLow);

                TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
                TestUtils.Compare(voltScope[voltageLowNdx].time, quarterCycleTime * 3, 4);
            }

            // Resistor
            {
                double voltageHigh = resScope.Max((f) => f.voltage);
                int voltageHighNdx = resScope.FindIndex((f) => f.voltage == voltageHigh);

                TestUtils.Compare(resScope[voltageHighNdx].time, quarterCycleTime, 4);

                double voltageLow = resScope.Min((f) => f.voltage);
                int voltageLowNdx = resScope.FindIndex((f) => f.voltage == voltageLow);

                TestUtils.Compare(voltageLow, 0, 8);
            }

            /*string js = JsonSerializer.SerializeToString(sim);
            string nm = TestContext.CurrentContext.Test.Name;
            Debug.Log(nm);
            Debug.Log(js);
            System.IO.File.WriteAllText(string.Format("./{0}.json", nm), js);*/
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:67,代码来源:DiodeTest.cs


注:本文中的Circuit.Watch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。