public void When_ZeroDerivative_Expect_Reference()
        {
            var ckt = new Circuit(
                new VoltageSource("V1", "OUT", "0", 10),
                new BehavioralResistor("R1", "OUT", "0", "V(OUT,0)"));

            var op        = new OP("op");
            var refExport = new RealCurrentExport(op, "V1");

            op.ExportSimulationData += (sender, args) =>
            {
                Assert.AreEqual(10.0, args.GetVoltage("OUT"), 1e-12);
                Assert.AreEqual(-1.0, refExport.Value, 1e-12);
            };
            op.Run(ckt);
        }
        public void When_ComplexResitor_Expect_Reference()
        {
            var ckt = new Circuit(
                new VoltageSource("V1", "2", "0", 0.5),
                new VoltageSource("V2", "1", "0", 10),
                new BehavioralResistor("RSwitch", "1", "0", "v(2, 0) >= 1 ? 10 : (v(2, 0) <= 0 ? 1000000 : (exp(8.05904782547916 + 3 * -11.5129254649702 * (v(2, 0)-0.5)/(2*1) - 2 * -11.5129254649702 * pow(v(2, 0)-0.5, 3)/(pow(1,3)))))"));
            var op        = new OP("Voltage switch simulation");
            var refExport = new RealCurrentExport(op, "V2");

            op.ExportSimulationData += (sender, args) =>
            {
                Assert.AreEqual(-0.00316228, refExport.Value, 1e-8);
            };

            op.Run(ckt);
        }
Exemple #3
0
        public void When_ResistorOperatingPoint_Expect_Reference()
        {
            /*
             * A circuit contains a DC voltage source 10V and resistor 1000 Ohms
             * The test verifies that after OP simulation:
             * 1) a current through resistor is 0.01 A (Ohms law)
             */
            var ckt = CreateResistorDcCircuit(10, 1000);

            // Create simulation, exports and references
            var op      = new OP("op");
            var exports = new Export <double> [1];

            exports[0] = new RealCurrentExport(op, "V1");
            double[] references = { -0.01 };

            // Run
            AnalyzeOp(op, ckt, exports, references);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 1),
                new Resistor("R1", "in", "0", 1),
                new BehavioralVoltageSource("E1", "out", "0", "Pow(V(in),3)"));

            var op     = new DC("dc", "V1", -1, 1, 0.1);
            var export = new RealCurrentExport(op, "V1");

            op.ExportSimulationData += (sender, e) =>
            {
                Console.Write(export.Value);
                Console.Write(" -> ");
                Console.WriteLine(e.GetVoltage("out"));
            };
            op.Run(ckt);
            Console.ReadKey();
        }
        public void When_DerivativeTransient_Expect_Reference()
        {
            var ckt = new Circuit(
                new VoltageSource("Vtmp", "a", "0", new Sine(0, 1, 100)),
                new Capacitor("C1", "a", "0", 1.0), // this will derive the variable
                new BehavioralVoltageSource("V1", "in", "0", "ddt(V(a))"));
            var tran = new Transient("tran", 1e-3, 0.1);

            var expectedExport = new RealCurrentExport(tran, "Vtmp");
            var actualExport   = new RealVoltageExport(tran, "in");

            tran.ExportSimulationData += (sender, args) =>
            {
                if (args.Time > 0)
                {
                    var expected = expectedExport.Value;
                    var actual   = -actualExport.Value;
                    Assert.AreEqual(expected, actual, 1e-9);
                }
            };
            tran.Run(ckt);
        }
        public void When_ExportSwitch_Expect_Reference()
        {
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", new Sine(1, 1, 10)),
                new Resistor("R1", "in", "out", 1e3),
                new Resistor("R2", "out", "0", 1e3));

            var sim1 = new DC("dc", "V1", 0, 2, 0.2);
            var sim2 = new Transient("tran", 1e-3, 0.5);

            var vexport = new RealVoltageExport(sim1, "out");
            var iexport = new RealCurrentExport(sim1, "V1");
            var pexport = new RealPropertyExport(sim1, "R1", "p");

            sim1.ExportSimulationData += (sender, e) =>
            {
                var input = e.GetVoltage("in");
                Assert.AreEqual(input * 0.5, vexport.Value, 1e-9);
                Assert.AreEqual(-input / 2.0e3, iexport.Value, 1e-9);
                Assert.AreEqual(input * input / 4.0 / 1.0e3, pexport.Value, 1e-9);
            };
            sim2.ExportSimulationData += (sender, e) =>
            {
                var input = e.GetVoltage("in");
                Assert.AreEqual(Math.Sin(2 * Math.PI * 10 * e.Time) + 1.0, input, 1e-9);
                Assert.AreEqual(input * 0.5, vexport.Value, 1e-9);
                Assert.AreEqual(-input / 2.0e3, iexport.Value, 1e-9);
                Assert.AreEqual(input * input / 4.0 / 1.0e3, pexport.Value, 1e-9);
            };
            sim1.Run(ckt);

            // Switch exports
            vexport.Simulation = sim2;
            iexport.Simulation = sim2;
            pexport.Simulation = sim2;

            sim2.Run(ckt);
        }