Ejemplo n.º 1
0
        public void When_NoiseRerun_Expect_Same()
        {
            // Create the circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 10.0),
                new Resistor("R1", "in", "out", 10),
                new Capacitor("C1", "out", "0", 20)
                );

            // Create the transient analysis
            var noise  = new Noise("noise 1", "V1", "out", new DecadeSweep(1, 1e9, 10));
            var export = new OutputNoiseDensityExport(noise);

            // Run the simulation a first time for building the reference values
            var r = new List <double>();

            void BuildReference(object sender, ExportDataEventArgs args) => r.Add(export.Value);

            noise.ExportSimulationData += BuildReference;
            noise.Run(ckt);
            noise.ExportSimulationData -= BuildReference;

            // Rerun the simulation for building the reference values
            var index = 0;

            void CheckReference(object sender, ExportDataEventArgs args)
            {
                Assert.AreEqual(r[index++], export.Value, 1e-20);
            }

            noise.ExportSimulationData += CheckReference;
            noise.Rerun();
            noise.ExportSimulationData -= CheckReference;
        }
Ejemplo n.º 2
0
        public void When_ResistorNoise_Expect_Reference()
        {
            var ckt = new Circuit(
                new CurrentSource("I1", "in", "0", 1).SetParameter("acmag", 1.0),
                new Resistor("R1", "in", "0", 1e3).SetParameter("temp", 20.0));
            var temp = 20 + Constants.CelsiusKelvin;

            var noise  = new SpiceSharp.Simulations.Noise("noise", "in", new DecadeSweep(10, 10e9, 10));
            var onoise = new OutputNoiseDensityExport(noise);
            var inoise = new InputNoiseDensityExport(noise);

            noise.ExportSimulationData += (sender, args) =>
            {
                // We expect 4*k*T*R noise variance
                Assert.AreEqual(4 * Constants.Boltzmann * temp * 1e3, onoise.Value, 1e-20);
                Assert.AreEqual(4 * Constants.Boltzmann * temp / 1e3, inoise.Value, 1e-20);
            };
            noise.Run(ckt);
        }