/// <inheritdoc/> protected override void Execute() { base.Execute(); var cstate = (ComplexSimulationState)GetState <IComplexSimulationState>(); var noiseconfig = NoiseParameters; var exportargs = new ExportDataEventArgs(this); // Find the output nodes var posOutNode = noiseconfig.Output != null ? cstate.Map[cstate.GetSharedVariable(noiseconfig.Output)] : 0; var negOutNode = noiseconfig.OutputRef != null ? cstate.Map[cstate.GetSharedVariable(noiseconfig.OutputRef)] : 0; // Initialize var freq = FrequencyParameters.Frequencies.GetEnumerator(); if (!freq.MoveNext()) { return; } cstate.Laplace = 0; Op(BiasingParameters.DcMaxIterations); // Initialize all devices for small-signal analysis and reset all noise contributions InitializeAcParameters(); foreach (var behavior in _noiseBehaviors) { behavior.Initialize(); } // Loop through noise figures do { // First compute the AC gain cstate.Laplace = new Complex(0.0, 2.0 * Math.PI * freq.Current); AcIterate(); var val = cstate.Solution[posOutNode] - cstate.Solution[negOutNode]; var inverseGainSquared = 1.0 / Math.Max(val.Real * val.Real + val.Imaginary * val.Imaginary, 1e-20); _state.SetCurrentPoint(new NoisePoint(freq.Current, inverseGainSquared)); // Solve the adjoint system NzIterate(posOutNode, negOutNode); // Now we use the adjoint system to calculate the noise // contributions of each generator in the circuit foreach (var behavior in _noiseBehaviors) { behavior.Compute(); _state.Add(behavior); } // Export the data OnExport(exportargs); }while (freq.MoveNext()); }
/// <inheritdoc/> protected override void Execute() { base.Execute(); var cstate = (ComplexSimulationState)GetState <IComplexSimulationState>(); var noiseconfig = NoiseParameters; var exportargs = new ExportDataEventArgs(this); // Find the output nodes var posOutNode = noiseconfig.Output != null ? cstate.Map[cstate.GetSharedVariable(noiseconfig.Output)] : 0; var negOutNode = noiseconfig.OutputRef != null ? cstate.Map[cstate.GetSharedVariable(noiseconfig.OutputRef)] : 0; // We only want to enable the source that is flagged as the input var source = EntityBehaviors[NoiseParameters.InputSource]; var originalParameters = new List <Tuple <IndependentSourceParameters, double, double> >(); foreach (var container in EntityBehaviors) { if (container.TryGetParameterSet(out IndependentSourceParameters parameters)) { originalParameters.Add(Tuple.Create(parameters, parameters.AcMagnitude, parameters.AcPhase)); if (ReferenceEquals(container, source)) { parameters.AcMagnitude = 1.0; parameters.AcPhase = 0.0; } else { parameters.AcMagnitude = 0.0; parameters.AcPhase = 0.0; } } } try { // Initialize var freq = FrequencyParameters.Frequencies.GetEnumerator(); if (!freq.MoveNext()) { return; } cstate.Laplace = 0; Op(BiasingParameters.DcMaxIterations); // Initialize all devices for small-signal analysis and reset all noise contributions InitializeAcParameters(); foreach (var behavior in _noiseBehaviors) { behavior.Initialize(); } // Loop through noise figures do { // First compute the AC gain cstate.Laplace = new Complex(0.0, 2.0 * Math.PI * freq.Current); AcIterate(); var val = cstate.Solution[posOutNode] - cstate.Solution[negOutNode]; var inverseGainSquared = 1.0 / Math.Max(val.Real * val.Real + val.Imaginary * val.Imaginary, 1e-20); _state.SetCurrentPoint(new NoisePoint(freq.Current, inverseGainSquared)); // Solve the adjoint system NzIterate(posOutNode, negOutNode); // Now we use the adjoint system to calculate the noise // contributions of each generator in the circuit foreach (var behavior in _noiseBehaviors) { behavior.Compute(); _state.Add(behavior); } // Export the data OnExport(exportargs); }while (freq.MoveNext()); } finally { foreach (var parameters in originalParameters) { parameters.Item1.AcMagnitude = parameters.Item2; parameters.Item1.AcPhase = parameters.Item3; } } }